Browse files

[FIX] A few minor qname checks in the custom Sirix translator.

[ADD] Namespace filter.
  • Loading branch information...
1 parent 98f43cf commit 6e8bff4c75e3dc6957204de2bccc8e92066cbf33 @JohannesLichtenberger JohannesLichtenberger committed Jan 3, 2014
View
10 bundles/sirix-core/src/main/java/org/sirix/axis/filter/AttributeFilter.java
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2011, University of Konstanz, Distributed Systems Group
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -12,7 +12,7 @@
* * Neither the name of the University of Konstanz nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -31,8 +31,8 @@
import org.sirix.node.Kind;
/**
- * <h1>AttributeAxisTest</h1>
- *
+ * <h1>AttributeFilter</h1>
+ *
* <p>
* Only match ATTRIBUTE nodes.
* </p>
@@ -41,7 +41,7 @@
/**
* Default constructor.
- *
+ *
* @param rtx
* Transaction this filter is bound to.
*/
View
56 bundles/sirix-core/src/main/java/org/sirix/axis/filter/NamespaceFilter.java
@@ -0,0 +1,56 @@
+/**
+ * Copyright (c) 2011, University of Konstanz, Distributed Systems Group
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the University of Konstanz nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.sirix.axis.filter;
+
+import org.sirix.api.NodeReadTrx;
+
+/**
+ * <h1>NamespaceFilter</h1>
+ *
+ * <p>
+ * Only match NAMESPACE nodes.
+ * </p>
+ */
+public class NamespaceFilter extends AbstractFilter {
+
+ /**
+ * Default constructor.
+ *
+ * @param rtx
+ * Transaction this filter is bound to.
+ */
+ public NamespaceFilter(final NodeReadTrx rtx) {
+ super(rtx);
+ }
+
+ @Override
+ public final boolean filter() {
+ return getTrx().isNamespace();
+ }
+
+}
View
38 bundles/sirix-core/src/main/java/org/sirix/axis/filter/ValueFilter.java
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2011, University of Konstanz, Distributed Systems Group
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -12,7 +12,7 @@
* * Neither the name of the University of Konstanz nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -35,9 +35,9 @@
/**
* <h1>ValueAxisTest</h1>
- *
+ *
* <p>
- * Only match nodes of kind TEXT whoms value matches.
+ * Only match nodes of kind TEXT or ATTRIBUTE whoe's value matches.
* </p>
*/
public class ValueFilter extends AbstractFilter {
@@ -47,44 +47,44 @@
/**
* Constructor initializing internal state.
- *
- * @param pRtx
+ *
+ * @param rtx
* transaction this filter is bound to
- * @param pValue
+ * @param value
* value to find
*/
- public ValueFilter(final NodeReadTrx pRtx, final byte[] pValue) {
- super(pRtx);
- mValue = checkNotNull(pValue);
+ public ValueFilter(final NodeReadTrx rtx, final byte[] value) {
+ super(rtx);
+ mValue = checkNotNull(value);
}
/**
* Constructor initializing internal state.
- *
+ *
* @param rtx
* Transaction to bind filter to.
- * @param mValue
+ * @param value
* Value to find.
*/
- public ValueFilter(final NodeReadTrx rtx, final String mValue) {
- this(rtx, TypedValue.getBytes(mValue));
+ public ValueFilter(final NodeReadTrx rtx, final String value) {
+ this(rtx, TypedValue.getBytes(value));
}
/**
* Constructor initializing internal state.
- *
+ *
* @param rtx
* Transaction to bind filter to.
- * @param mValue
+ * @param value
* Value to find.
*/
- public ValueFilter(final NodeReadTrx rtx, final int mValue) {
- this(rtx, TypedValue.getBytes(mValue));
+ public ValueFilter(final NodeReadTrx rtx, final int value) {
+ this(rtx, TypedValue.getBytes(value));
}
/**
* Constructor initializing internal state.
- *
+ *
* @param rtx
* Transaction to bind filter to.
* @param mValue
View
68 bundles/sirix-core/src/main/java/org/sirix/page/interfaces/KeyValuePage.java
@@ -16,51 +16,51 @@
/**
* Key/Value page.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
public interface KeyValuePage<K extends Comparable<? super K>, V extends Record>
extends Page {
/**
- * Entry set of all nodes in the page. Changes to the set are reflected in the
- * internal data structure
- *
+ * Entry set of all nodes in the page. Changes to the set are reflected in
+ * the internal data structure
+ *
* @return an entry set
*/
Set<Entry<K, V>> entrySet();
/**
* All available records.
- *
+ *
* @return all records
*/
Collection<V> values();
/**
* Get the unique page record identifier.
- *
+ *
* @return page record key/identifier
*/
long getPageKey();
/**
* Get value with the specified key.
- *
+ *
* @param key
- * the key
+ * the key
* @return value with given key, or {@code null} if not present
*/
V getValue(K key);
/**
- * Store or overwrite a single entry. The implementation must make sure if the
- * key must be permitted, the value or none.
- *
+ * Store or overwrite a single entry. The implementation must make sure if
+ * the key must be permitted, the value or none.
+ *
* @param key
- * key to store
+ * key to store
* @param value
- * value to store
+ * value to store
*/
void setEntry(K key, @Nonnull V value);
@@ -69,62 +69,62 @@
/**
* Store or overwrite a single reference associated with a key for overlong
* entries. That is entries which are larger than a predefined threshold are
- * written to OverflowPages and thus are just referenced and not deserialized
- * during the deserialization of a page.
- *
+ * written to OverflowPages and thus are just referenced and not
+ * deserialized during the deserialization of a page.
+ *
* @param key
- * key to store
+ * key to store
* @param reference
- * reference to store
+ * reference to store
*/
void setPageReference(K key, @Nonnull PageReference reference);
PageReference getPageReference(K key);
/**
* Create a new instance.
- *
+ *
* @param recordPageKey
- * the record page key
+ * the record page key
* @param pageKind
- * the kind of page (in which subtree it is (NODEPAGE,
- * PATHSUMMARYPAGE, TEXTVALUEPAGE, ATTRIBUTEVALUEPAGE))
+ * the kind of page (in which subtree it is (NODEPAGE,
+ * PATHSUMMARYPAGE, TEXTVALUEPAGE, ATTRIBUTEVALUEPAGE))
* @param pageReadTrx
- * transaction to read pages
+ * transaction to read pages
* @return a new {@link KeyValuePage} instance
*/
- <C extends KeyValuePage<K, V>> C newInstance(@Nonnegative long recordPageKey,
- @Nonnull PageKind pageKind,
+ <C extends KeyValuePage<K, V>> C newInstance(
+ @Nonnegative long recordPageKey, @Nonnull PageKind pageKind,
@Nonnull Optional<PageReference> previousPageRef,
@Nonnull PageReadTrx pageReadTrx);
/**
* Get the {@link PageReadTrx}.
- *
+ *
* @return page reading transaction
*/
PageReadTrx getPageReadTrx();
/**
* Get the page kind.
- *
+ *
* @return page kind
*/
PageKind getPageKind();
/**
* Get the number of entries/slots/page references filled.
- *
+ *
* @return number of entries/slots/page references filled
*/
int size();
/**
- * Get the optional {@link PageReference} pointing to the previous version of
- * the page
- *
- * @return optional {@link PageReference} pointing to the previous version of
- * the page
+ * Get the optional {@link PageReference} pointing to the previous version
+ * of the page
+ *
+ * @return optional {@link PageReference} pointing to the previous version
+ * of the page
*/
Optional<PageReference> getPreviousReference();
}
View
36 bundles/sirix-core/src/main/java/org/sirix/page/interfaces/Page.java
@@ -1,7 +1,7 @@
/**
* Copyright (c) 2011, University of Konstanz, Distributed Systems Group
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -12,7 +12,7 @@
* * Neither the name of the University of Konstanz nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -39,67 +39,63 @@
/**
* Page interface all pages have to implement.
- *
+ *
* @author Sebastian Graf, University of Konstanz
* @author Johannes Lichtenberger
- *
+ *
*/
public interface Page {
/**
* Serialize a page
- *
+ *
* @param out
- * {@link DataOutput} to serialize to
+ * {@link DataOutput} to serialize to
* @throws IOException
- * if serialization fails
+ * if serialization fails
*/
void serialize(final DataOutput out) throws IOException;
/**
* Get all page references.
- *
+ *
* @return all page references
*/
PageReference[] getReferences();
/**
* Commit page.
- *
+ *
* @param pageWriteTrx
- * {@link PageWriteTrx} implementation
+ * {@link PageWriteTrx} implementation
* @throws SirixException
- * if something went wrong
+ * if something went wrong
*/
<K extends Comparable<? super K>, V extends Record, S extends KeyValuePage<K, V>> void commit(
@Nonnull PageWriteTrx<K, V, S> pageWriteTrx) throws SirixException;
/**
* Get the {@link PageReference} at the specified offset
- *
+ *
* @param offset
- * the offset
+ * the offset
* @return the {@link PageReference} at the specified offset
*/
PageReference getReference(@Nonnegative int offset);
/**
* Determines if a page is dirty meaning if it has been changed.
- *
+ *
* @return {@code true} if it has been changed, {@code false} otherwise
*/
boolean isDirty();
/**
* Set dirty flag (if page has been modified).
- *
+ *
* @param dirty
- * dirty or not
+ * dirty or not
* @return the page instance
*/
Page setDirty(boolean dirty);
-
-// boolean isFullDump();
-//
-// Page setFullDump(boolean isFullDump);
}
View
BIN bundles/sirix-core/src/test/resources/cf-packed/tmp/tt/tt.tnk
Binary file not shown.
View
0 bundles/sirix-core/src/test/resources/tmp/tt/tt.tnk
No changes.
View
2 bundles/sirix-jax-rx/pom.xml
@@ -56,7 +56,7 @@
<!-- the client implementation of JAX-RS for testing purposes -->
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
- <version>1.4</version>
+ <version>1.18</version>
</dependency>
</dependencies>
<build>
View
312 bundles/sirix-xquery/src/main/java/org/sirix/xquery/compiler/translator/SirixTranslator.java
@@ -36,10 +36,13 @@
import org.sirix.axis.ParentAxis;
import org.sirix.axis.PrecedingSiblingAxis;
import org.sirix.axis.SelfAxis;
+import org.sirix.axis.filter.AttributeFilter;
import org.sirix.axis.filter.CommentFilter;
+import org.sirix.axis.filter.DocumentRootNodeFilter;
import org.sirix.axis.filter.ElementFilter;
import org.sirix.axis.filter.FilterAxis;
import org.sirix.axis.filter.NameFilter;
+import org.sirix.axis.filter.NamespaceFilter;
import org.sirix.axis.filter.PIFilter;
import org.sirix.axis.filter.TemporalFilterAxis;
import org.sirix.axis.filter.TextFilter;
@@ -63,9 +66,9 @@
/**
* Translates queries (optimizes currently path-expressions if {@code OPTIMIZE}
* is set to true).
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
public final class SirixTranslator extends TopDownTranslator {
@@ -82,9 +85,9 @@
/**
* Constructor.
- *
+ *
* @param options
- * options map
+ * options map
*/
public SirixTranslator(final Map<QNm, Str> options) {
super(options);
@@ -141,16 +144,16 @@ protected Accessor axis(final AST node) throws QueryException {
/**
* {@code first::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Last extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Last(final Axis axis) {
super(axis);
@@ -162,8 +165,9 @@ public Last(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new LastAxis(rtx);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -178,16 +182,16 @@ public Last(final Axis axis) {
/**
* {@code first::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class First extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public First(final Axis axis) {
super(axis);
@@ -199,8 +203,9 @@ public First(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new FirstAxis(rtx);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -215,16 +220,16 @@ public First(final Axis axis) {
/**
* {@code next::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Next extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Next(final Axis axis) {
super(axis);
@@ -236,8 +241,9 @@ public Next(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new NextAxis(rtx);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -252,16 +258,16 @@ public Next(final Axis axis) {
/**
* {@code previous::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Previous extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Previous(final Axis axis) {
super(axis);
@@ -273,8 +279,9 @@ public Previous(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new PreviousAxis(rtx);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -289,16 +296,16 @@ public Previous(final Axis axis) {
/**
* {@code all-time::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class AllTime extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public AllTime(final Axis axis) {
super(axis);
@@ -310,8 +317,9 @@ public AllTime(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new AllTimeAxis(rtx);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -326,19 +334,19 @@ public AllTime(final Axis axis) {
/**
* {@code past::} and {@code past-or-self::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Past extends Accessor {
/** Determine if self is included or not. */
- private IncludeSelf mSelf;
+ private final IncludeSelf mSelf;
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Past(final Axis axis) {
super(axis);
@@ -351,8 +359,9 @@ public Past(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new PastAxis(rtx, mSelf);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -367,19 +376,19 @@ public Past(final Axis axis) {
/**
* {@code future::} and {@code future-or-self::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Future extends Accessor {
/** Determine if self is included or not. */
- private IncludeSelf mSelf;
+ private final IncludeSelf mSelf;
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Future(final Axis axis) {
super(axis);
@@ -392,8 +401,9 @@ public Future(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
final AbstractTemporalAxis axis = new FutureAxis(rtx, mSelf);
- return new TemporalSirixStream(SirixTranslator.this.getTemporalAxis(test,
- rtx, axis), dbNode.getCollection());
+ return new TemporalSirixStream(
+ SirixTranslator.this.getTemporalAxis(test, rtx, axis),
+ dbNode.getCollection());
}
@Override
@@ -408,16 +418,16 @@ public Future(final Axis axis) {
/**
* {@code preceding-sibling::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class PrecedingSibling extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public PrecedingSibling(final Axis axis) {
super(axis);
@@ -444,16 +454,16 @@ public PrecedingSibling(final Axis axis) {
/**
* {@code following-sibling::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class FollowingSibling extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public FollowingSibling(final Axis axis) {
super(axis);
@@ -480,16 +490,16 @@ public FollowingSibling(final Axis axis) {
/**
* {@code following::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Following extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Following(final Axis axis) {
super(axis);
@@ -509,25 +519,26 @@ public Following(final Axis axis) {
throws QueryException {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
- return new SirixStream(new FollowingAxis(rtx), dbNode.getCollection());
+ return new SirixStream(new FollowingAxis(rtx),
+ dbNode.getCollection());
}
}
/**
* {@code ancestor::} and {@code ancestor-or-self::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class AncestorOrSelf extends Accessor {
/** Determine if self is included or not. */
- private IncludeSelf mSelf;
+ private final IncludeSelf mSelf;
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public AncestorOrSelf(final Axis axis) {
super(axis);
@@ -555,16 +566,16 @@ public AncestorOrSelf(final Axis axis) {
/**
* {@code attribute::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Parent extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Parent(final Axis axis) {
super(axis);
@@ -590,16 +601,16 @@ public Parent(final Axis axis) {
/**
* {@code attribute::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Attribute extends Accessor {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Attribute(final Axis axis) {
super(axis);
@@ -611,23 +622,25 @@ public Attribute(final Axis axis) {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
return new SirixStream(new FilterAxis(new AttributeAxis(rtx),
- new NameFilter(rtx, test.getQName())), dbNode.getCollection());
+ new NameFilter(rtx, test.getQName())),
+ dbNode.getCollection());
}
@Override
public Stream<? extends Node<?>> performStep(Node<?> node)
throws QueryException {
final DBNode dbNode = (DBNode) node;
final NodeReadTrx rtx = dbNode.getTrx();
- return new SirixStream(new AttributeAxis(rtx), dbNode.getCollection());
+ return new SirixStream(new AttributeAxis(rtx),
+ dbNode.getCollection());
}
}
/**
* {@code child::} optimization.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class Child extends Accessor {
/**
@@ -637,9 +650,9 @@ public Attribute(final Axis axis) {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public Child(final Axis axis) {
super(axis);
@@ -656,8 +669,8 @@ public Child(final Axis axis) {
try {
final long pcr = dbNode.getPCR();
BitSet matches = mFilterMap.get(pcr);
- final PathSummaryReader reader = rtx.getSession().openPathSummary(
- rtx.getRevisionNumber());
+ final PathSummaryReader reader = rtx.getSession()
+ .openPathSummary(rtx.getRevisionNumber());
if (matches == null) {
reader.moveTo(pcr);
final int level = reader.getLevel() + 1;
@@ -691,15 +704,15 @@ public Child(final Axis axis) {
/**
* {@code descendant::} and {@code descendant-or-self::} path-optimizations.
- *
+ *
* @author Johannes Lichtenberger
- *
+ *
*/
private class DescOrSelf extends Accessor {
/**
* Determines if current node is included (-or-self part).
*/
- private IncludeSelf mSelf;
+ private final IncludeSelf mSelf;
/**
* Map with PCR <=> matching nodes.
@@ -708,9 +721,9 @@ public Child(final Axis axis) {
/**
* Constructor.
- *
+ *
* @param axis
- * the axis to evaluate
+ * the axis to evaluate
*/
public DescOrSelf(final Axis axis) {
super(axis);
@@ -728,12 +741,12 @@ public DescOrSelf(final Axis axis) {
final long pcr = dbNode.getPCR();
BitSet matches = mFilterMap.get(pcr);
final NodeReadTrx rtx = dbNode.getTrx();
- final PathSummaryReader reader = rtx.getSession().openPathSummary(
- rtx.getRevisionNumber());
+ final PathSummaryReader reader = rtx.getSession()
+ .openPathSummary(rtx.getRevisionNumber());
if (matches == null) {
reader.moveTo(pcr);
- final int level = mSelf == IncludeSelf.YES ? reader.getLevel()
- : reader.getLevel() + 1;
+ final int level = mSelf == IncludeSelf.YES ? reader
+ .getLevel() : reader.getLevel() + 1;
final QNm name = test.getQName();
matches = reader.match(name, level);
mFilterMap.put(pcr, matches);
@@ -752,17 +765,21 @@ public DescOrSelf(final Axis axis) {
// Match at the same level.
if (mSelf == IncludeSelf.YES && matchLevel == level) {
reader.close();
- return new SirixStream(new SelfAxis(rtx), dbNode.getCollection());
+ return new SirixStream(new SelfAxis(rtx),
+ dbNode.getCollection());
}
// Match at the next level (single child-path).
if (matchLevel == level + 1) {
reader.close();
- return new SirixStream(new FilterAxis(new ChildAxis(rtx),
- new ElementFilter(rtx), new NameFilter(rtx, test.getQName()
- .toString())), dbNode.getCollection());
+ return new SirixStream(new FilterAxis(
+ new ChildAxis(rtx), new ElementFilter(rtx),
+ new NameFilter(rtx, test.getQName()
+ .toString())),
+ dbNode.getCollection());
}
// Match at a level below the child level.
- final Deque<QNm> names = getNames(matchLevel, level, reader);
+ final Deque<QNm> names = getNames(matchLevel, level,
+ reader);
reader.close();
return new SirixStream(buildQuery(rtx, names),
dbNode.getCollection());
@@ -786,10 +803,12 @@ public DescOrSelf(final Axis axis) {
if (onSameLevel) {
final Deque<org.sirix.api.Axis> axisQueue = new ArrayDeque<>(
matches.cardinality());
- for (int j = level, nodeLevel = dbNode.getDeweyID().get()
- .getLevel(); j > nodeLevel; j--) {
- // Build an immutable set and turn it into a list for sorting.
- Builder<QNm> pathNodeQNmBuilder = ImmutableSet.<QNm> builder();
+ for (int j = level, nodeLevel = dbNode.getDeweyID()
+ .get().getLevel(); j > nodeLevel; j--) {
+ // Build an immutable set and turn it into a list
+ // for sorting.
+ Builder<QNm> pathNodeQNmBuilder = ImmutableSet
+ .<QNm> builder();
for (i = matches.nextSetBit(0); i >= 0; i = matches
.nextSetBit(i + 1)) {
reader.moveTo(i);
@@ -798,8 +817,8 @@ public DescOrSelf(final Axis axis) {
}
pathNodeQNmBuilder.add(reader.getName());
}
- final List<QNm> pathNodeQNmsList = pathNodeQNmBuilder.build()
- .asList();
+ final List<QNm> pathNodeQNmsList = pathNodeQNmBuilder
+ .build().asList();
final QNm name = pathNodeQNmsList.get(0);
boolean sameName = true;
for (int k = 1; k < pathNodeQNmsList.size(); k++) {
@@ -809,9 +828,11 @@ public DescOrSelf(final Axis axis) {
}
}
- axisQueue.push(sameName ? new FilterAxis(new ChildAxis(rtx),
- new ElementFilter(rtx), new NameFilter(rtx, name))
- : new FilterAxis(new ChildAxis(rtx), new ElementFilter(rtx)));
+ axisQueue.push(sameName ? new FilterAxis(
+ new ChildAxis(rtx), new ElementFilter(rtx),
+ new NameFilter(rtx, name))
+ : new FilterAxis(new ChildAxis(rtx),
+ new ElementFilter(rtx)));
}
org.sirix.api.Axis axis = axisQueue.pop();
@@ -820,9 +841,11 @@ public DescOrSelf(final Axis axis) {
}
reader.close();
return new SirixStream(axis, dbNode.getCollection());
- // return new SirixStream(new FilterAxis(new DescendantAxis(rtx,
+ // return new SirixStream(new FilterAxis(new
+ // DescendantAxis(rtx,
// mSelf),
- // new ElementFilter(rtx), new NameFilter(rtx, test.getQName()
+ // new ElementFilter(rtx), new NameFilter(rtx,
+ // test.getQName()
// .toString())), dbNode.getCollection());
} else {
// Matches on different levels.
@@ -833,29 +856,33 @@ public DescOrSelf(final Axis axis) {
for (i = matches.nextSetBit(0); i >= 0; i = matches
.nextSetBit(i + 1)) {
reader.moveTo(i);
- final int matchLevel = reader.getPathNode().getLevel();
+ final int matchLevel = reader.getPathNode()
+ .getLevel();
// Match at the same level.
if (mSelf == IncludeSelf.YES && matchLevel == level) {
axisQueue.addLast(new SelfAxis(rtx));
}
// Match at the next level (single child-path).
else if (matchLevel == level + 1) {
- axisQueue.addLast(new FilterAxis(new ChildAxis(rtx),
- new ElementFilter(rtx), new NameFilter(rtx, test.getQName()
+ axisQueue.addLast(new FilterAxis(new ChildAxis(
+ rtx), new ElementFilter(rtx),
+ new NameFilter(rtx, test.getQName()
.toString())));
}
// Match at a level below the child level.
else {
- final Deque<QNm> names = getNames(matchLevel, level, reader);
+ final Deque<QNm> names = getNames(matchLevel,
+ level, reader);
axisQueue.addLast(buildQuery(rtx, names));
}
}
- org.sirix.api.Axis axis = new UnionAxis(rtx, axisQueue.pollFirst(),
- axisQueue.pollFirst());
+ org.sirix.api.Axis axis = new UnionAxis(rtx,
+ axisQueue.pollFirst(), axisQueue.pollFirst());
final int size = axisQueue.size();
for (i = 0; i < size; i++) {
- axis = new UnionAxis(rtx, axis, axisQueue.pollFirst());
+ axis = new UnionAxis(rtx, axis,
+ axisQueue.pollFirst());
}
reader.close();
return new SirixStream(axis, dbNode.getCollection());
@@ -886,7 +913,8 @@ else if (matchLevel == level + 1) {
new ElementFilter(rtx), new NameFilter(rtx, names.pop()));
for (int i = 0, size = names.size(); i < size; i++) {
axis = new NestedAxis(axis, new FilterAxis(new ChildAxis(rtx),
- new ElementFilter(rtx), new NameFilter(rtx, names.pop())));
+ new ElementFilter(rtx),
+ new NameFilter(rtx, names.pop())));
}
return axis;
}
@@ -910,23 +938,46 @@ else if (matchLevel == level + 1) {
axis = new TemporalFilterAxis(innerAxis, new CommentFilter(trx));
break;
case PROCESSING_INSTRUCTION:
- axis = new TemporalFilterAxis(innerAxis, new PIFilter(trx));
+ if (test.getQName() == null) {
+ axis = new TemporalFilterAxis(innerAxis, new PIFilter(trx));
+ } else {
+ axis = new TemporalFilterAxis(innerAxis, new PIFilter(trx),
+ new NameFilter(trx, test.getQName()));
+ }
break;
case ELEMENT:
if (test.getQName() == null) {
axis = new TemporalFilterAxis(innerAxis, new ElementFilter(trx));
} else {
- axis = new TemporalFilterAxis(innerAxis, new ElementFilter(trx),
- new NameFilter(trx, test.getQName()));
+ axis = new TemporalFilterAxis(innerAxis,
+ new ElementFilter(trx), new NameFilter(trx,
+ test.getQName()));
}
break;
case TEXT:
axis = new TemporalFilterAxis(innerAxis, new TextFilter(trx));
break;
case NAMESPACE:
+ if (test.getQName() == null) {
+ axis = new TemporalFilterAxis(innerAxis, new NamespaceFilter(
+ trx));
+ } else {
+ axis = new TemporalFilterAxis(innerAxis, new NamespaceFilter(
+ trx), new NameFilter(trx, test.getQName()));
+ }
+ break;
case ATTRIBUTE:
+ if (test.getQName() == null) {
+ axis = new TemporalFilterAxis(innerAxis, new AttributeFilter(
+ trx));
+ } else {
+ axis = new TemporalFilterAxis(innerAxis, new AttributeFilter(
+ trx), new NameFilter(trx, test.getQName()));
+ }
+ break;
case DOCUMENT:
- throw new AssertionError("May never happen!");
+ axis = new TemporalFilterAxis(innerAxis,
+ new DocumentRootNodeFilter(trx));
}
return axis;
}
@@ -939,7 +990,12 @@ else if (matchLevel == level + 1) {
axis = new FilterAxis(innerAxis, new CommentFilter(trx));
break;
case PROCESSING_INSTRUCTION:
- axis = new FilterAxis(innerAxis, new PIFilter(trx));
+ if (test.getQName() == null) {
+ axis = new FilterAxis(innerAxis, new PIFilter(trx));
+ } else {
+ axis = new FilterAxis(innerAxis, new PIFilter(trx),
+ new NameFilter(trx, test.getQName()));
+ }
break;
case ELEMENT:
if (test.getQName() == null) {
@@ -953,9 +1009,23 @@ else if (matchLevel == level + 1) {
axis = new FilterAxis(innerAxis, new TextFilter(trx));
break;
case NAMESPACE:
+ if (test.getQName() == null) {
+ axis = new FilterAxis(innerAxis, new NamespaceFilter(trx));
+ } else {
+ axis = new FilterAxis(innerAxis, new NamespaceFilter(trx),
+ new NameFilter(trx, test.getQName()));
+ }
+ break;
case ATTRIBUTE:
+ if (test.getQName() == null) {
+ axis = new FilterAxis(innerAxis, new AttributeFilter(trx));
+ } else {
+ axis = new FilterAxis(innerAxis, new AttributeFilter(trx),
+ new NameFilter(trx, test.getQName()));
+ }
+ break;
case DOCUMENT:
- throw new AssertionError("May never happen!");
+ axis = new FilterAxis(innerAxis, new DocumentRootNodeFilter(trx));
}
return axis;
}

0 comments on commit 6e8bff4

Please sign in to comment.