Returns the common default namespace of all documents of the database. @param ndocs number of documents @return namespace, or null if there is no common namespace
(final int ndocs)
| 121 | * @return namespace, or {@code null} if there is no common namespace |
| 122 | */ |
| 123 | byte[] defaultNs(final int ndocs) { |
| 124 | // no namespaces defined: default namespace is empty |
| 125 | final int ch = root.children(); |
| 126 | if(ch == 0) return Token.EMPTY; |
| 127 | // give up if number of default namespaces differs from number of documents |
| 128 | if(ch != ndocs) return null; |
| 129 | |
| 130 | int id = 0; |
| 131 | for(int c = 0; c < ch; c++) { |
| 132 | final NSNode child = root.child(c); |
| 133 | final int[] values = child.values(); |
| 134 | // give up if child node has more children or more than one namespace |
| 135 | // give up if namespace has a non-empty prefix |
| 136 | if(child.children() > 0 || child.pre() != 1 || values.length != 2 || |
| 137 | prefix(values[0]).length != 0) return null; |
| 138 | // check if all documents have the same default namespace |
| 139 | if(c == 0) { |
| 140 | id = values[1]; |
| 141 | } else if(id != values[1]) { |
| 142 | return null; |
| 143 | } |
| 144 | } |
| 145 | // return common default namespace |
| 146 | return uri(id); |
| 147 | } |
| 148 | |
| 149 | // Requesting Namespaces Based on Context ======================================================= |
| 150 |