http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/QueryFilter.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/QueryFilter.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/QueryFilter.java deleted file mode 100644 index bbfdf14..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/QueryFilter.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter; - -//JDK imports -import java.util.List; - -//OODT imports -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A Filter interface for filtering queries - * <p> - */ -public abstract class QueryFilter<FilterType> { - - protected FilterAlgorithm<FilterType> filterAlgorithm; - - public QueryFilter() {} - - public QueryFilter(FilterAlgorithm<FilterType> filterAlgorithm) { - super(); - this.filterAlgorithm = filterAlgorithm; - } - - public void setFilterAlgorithm(FilterAlgorithm<FilterType> filterAlgorithm) { - this.filterAlgorithm = filterAlgorithm; - } - - public FilterAlgorithm<FilterType> getFilterAlgorithm() { - return this.filterAlgorithm; - } - - public List<TransactionalMetadata> filterMetadataList(List<TransactionalMetadata> metadataToFilter) { - return this.filterTypeToMetadata(this.filterAlgorithm.filter(this.metadataToFilterType(metadataToFilter))); - } - - protected abstract List<FilterType> metadataToFilterType(List<TransactionalMetadata> metadataList); - - protected abstract List<TransactionalMetadata> filterTypeToMetadata(List<FilterType> filterObjects); - -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEvent.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEvent.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEvent.java deleted file mode 100644 index aa8eaaf..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEvent.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter.time; - -//OODT imports -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; -import org.apache.oodt.commons.filter.ObjectTimeEvent; - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A ObjectTimeEvent that holds TermBuckets - * <p> - */ -public class MetadataTimeEvent extends ObjectTimeEvent<TransactionalMetadata> { - - public MetadataTimeEvent(long startTime, long endTime, TransactionalMetadata timeObj) { - super(startTime, endTime, timeObj); - } - - public MetadataTimeEvent(long startTime, long endTime, double priority, TransactionalMetadata timeObj) { - super(startTime, endTime, priority, timeObj); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventFilterAlgorithm.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventFilterAlgorithm.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventFilterAlgorithm.java deleted file mode 100644 index 114a4d5..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventFilterAlgorithm.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter.time; - -//JDK imports -import java.util.Collections; -import java.util.List; - -//OODT imports -import org.apache.oodt.cas.catalog.query.filter.FilterAlgorithm; -import org.apache.oodt.commons.filter.TimeEventWeightedHash; - -/** - * @author bfoster - * @version $Revision$ - */ -public class MetadataTimeEventFilterAlgorithm extends FilterAlgorithm<MetadataTimeEvent> { - - protected long epsilon; - - public MetadataTimeEventFilterAlgorithm() { - this.epsilon = 0; - } - - public MetadataTimeEventFilterAlgorithm(long epsilon) { - this.epsilon = epsilon; - } - - public void setEpsilon(long epsilon) { - this.epsilon = epsilon; - } - - public long getEpsilon() { - return this.epsilon; - } - - @Override - public List<MetadataTimeEvent> filter(List<MetadataTimeEvent> events) { - TimeEventWeightedHash timeEventHash = TimeEventWeightedHash.buildHash(events, this.epsilon); - return Collections.unmodifiableList((List<MetadataTimeEvent>) timeEventHash.getGreatestWeightedPathAsOrderedList()); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventQueryFilter.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventQueryFilter.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventQueryFilter.java deleted file mode 100644 index 0802a9f..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/MetadataTimeEventQueryFilter.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter.time; - -//JDK imports -import java.util.Collections; -import java.util.List; -import java.util.Vector; - -//OODT imports -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; -import org.apache.oodt.cas.catalog.query.filter.QueryFilter; -import org.apache.oodt.cas.catalog.query.filter.time.conv.AsciiSortableVersionConverter; -import org.apache.oodt.cas.catalog.query.filter.time.conv.VersionConverter; - -//OODT imports - -/** - * @author bfoster - * @version $Revision$ - * - * <p> - * A query filter that allows user to filter results in a complex query - * <p> - */ -public class MetadataTimeEventQueryFilter extends QueryFilter<MetadataTimeEvent> { - - private String startDateTimeMetKey, endDateTimeMetKey, priorityMetKey; - private VersionConverter converter; - - public MetadataTimeEventQueryFilter() { - super(); - this.converter = new AsciiSortableVersionConverter(); - } - - public String getStartDateTimeMetKey() { - return startDateTimeMetKey; - } - - public void setStartDateTimeMetKey(String startDateTimeMetKey) { - this.startDateTimeMetKey = startDateTimeMetKey; - } - - public String getEndDateTimeMetKey() { - return endDateTimeMetKey; - } - - public void setEndDateTimeMetKey(String endDateTimeMetKey) { - this.endDateTimeMetKey = endDateTimeMetKey; - } - - public String getPriorityMetKey() { - return priorityMetKey; - } - - public void setPriorityMetKey(String priorityMetKey) { - this.priorityMetKey = priorityMetKey; - } - - public VersionConverter getConverter() { - return converter; - } - - public void setConverter(VersionConverter converter) { - if (converter != null) { - this.converter = converter; - } - } - - @Override - protected List<MetadataTimeEvent> metadataToFilterType(List<TransactionalMetadata> metadataList) { - List<MetadataTimeEvent> timeEvents = new Vector<MetadataTimeEvent>(); - for (TransactionalMetadata transactionalMetadata : metadataList) { - double priority = 0; - if (this.getPriorityMetKey() != null) { - priority = Double.parseDouble(transactionalMetadata.getMetadata().getMetadata(this.priorityMetKey)); - } - long startTime = Long.parseLong(transactionalMetadata.getMetadata().getMetadata(this.startDateTimeMetKey)); - String endTimeString = transactionalMetadata.getMetadata().getMetadata(this.endDateTimeMetKey); - long endTime = startTime; - if (endTimeString != null) { - endTime = Long.parseLong(endTimeString); - } - timeEvents.add(new MetadataTimeEvent(startTime, endTime, priority, transactionalMetadata)); - } - return Collections.unmodifiableList(timeEvents); - } - - @Override - protected List<TransactionalMetadata> filterTypeToMetadata(List<MetadataTimeEvent> filterObjects) { - List<TransactionalMetadata> metadataList = new Vector<TransactionalMetadata>(); - for (MetadataTimeEvent timeEvent : filterObjects) { - metadataList.add(timeEvent.getTimeObject()); - } - return Collections.unmodifiableList(metadataList); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/AsciiSortableVersionConverter.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/AsciiSortableVersionConverter.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/AsciiSortableVersionConverter.java deleted file mode 100644 index 855454b..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/AsciiSortableVersionConverter.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter.time.conv; - -/** - * - * @author bfoster - * @version $Revision$ - * - * <p> - * Converts a ascii sortable String version into a priority number - * <p> - */ -public class AsciiSortableVersionConverter implements VersionConverter { - - public double convertToPriority(String version) { - double priority = 0; - char[] versionCharArray = version.toCharArray(); - for (int i = 0, j = versionCharArray.length - 1; i < versionCharArray.length; i++, j--) { - priority += (((int) versionCharArray[i]) * Math.pow(10, j)); - } - return priority; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/VersionConverter.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/VersionConverter.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/VersionConverter.java deleted file mode 100644 index 69ac864..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/filter/time/conv/VersionConverter.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.oodt.cas.catalog.query.filter.time.conv; - -/** - * - * @author bfoster - * @version $Revision$ - * - * <p> - * An interface for converting a String version into a priority number - * <p> - */ -public interface VersionConverter { - - double convertToPriority(String version); - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/JJTQueryParserState.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/JJTQueryParserState.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/JJTQueryParserState.java deleted file mode 100644 index 7e9b0a0..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/JJTQueryParserState.java +++ /dev/null @@ -1,123 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. JJTQueryParserState.java Version 5.0 */ -package org.apache.oodt.cas.catalog.query.parser; - -public class JJTQueryParserState { - private java.util.List<Node> nodes; - private java.util.List<Integer> marks; - - private int sp; // number of nodes on stack - private int mk; // current mark - private boolean node_created; - - public JJTQueryParserState() { - nodes = new java.util.ArrayList<Node>(); - marks = new java.util.ArrayList<Integer>(); - sp = 0; - mk = 0; - } - - /* Determines whether the current node was actually closed and - pushed. This should only be called in the final user action of a - node scope. */ - public boolean nodeCreated() { - return node_created; - } - - /* Call this to reinitialize the node stack. It is called - automatically by the parser's ReInit() method. */ - public void reset() { - nodes.clear(); - marks.clear(); - sp = 0; - mk = 0; - } - - /* Returns the root node of the AST. It only makes sense to call - this after a successful parse. */ - public Node rootNode() { - return nodes.get(0); - } - - /* Pushes a node on to the stack. */ - public void pushNode(Node n) { - nodes.add(n); - ++sp; - } - - /* Returns the node on the top of the stack, and remove it from the - stack. */ - public Node popNode() { - if (--sp < mk) { - mk = marks.remove(marks.size()-1); - } - return nodes.remove(nodes.size()-1); - } - - /* Returns the node currently on the top of the stack. */ - public Node peekNode() { - return nodes.get(nodes.size()-1); - } - - /* Returns the number of children on the stack in the current node - scope. */ - public int nodeArity() { - return sp - mk; - } - - - public void clearNodeScope(Node n) { - while (sp > mk) { - popNode(); - } - mk = marks.remove(marks.size()-1); - } - - - public void openNodeScope(Node n) { - marks.add(mk); - mk = sp; - n.jjtOpen(); - } - - - /* A definite node is constructed from a specified number of - children. That number of nodes are popped from the stack and - made the children of the definite node. Then the definite node - is pushed on to the stack. */ - public void closeNodeScope(Node n, int num) { - mk = marks.remove(marks.size()-1); - while (num-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, num); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } - - - /* A conditional node is constructed if its condition is true. All - the nodes that have been pushed since the node was opened are - made children of the conditional node, which is then pushed - on to the stack. If the condition is false the node is not - constructed and they are left on the stack. */ - public void closeNodeScope(Node n, boolean condition) { - if (condition) { - int a = nodeArity(); - mk = marks.remove(marks.size()-1); - while (a-- > 0) { - Node c = popNode(); - c.jjtSetParent(n); - n.jjtAddChild(c, a); - } - n.jjtClose(); - pushNode(n); - node_created = true; - } else { - mk = marks.remove(marks.size()-1); - node_created = false; - } - } -} -/* JavaCC - OriginalChecksum=a225ad3a5c4857e9f64392e47d6acfb8 (do not edit this line) */ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/Node.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/Node.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/Node.java deleted file mode 100644 index a2e88e7..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/Node.java +++ /dev/null @@ -1,36 +0,0 @@ -/* Generated By:JJTree: Do not edit this line. Node.java Version 4.3 */ -/* JavaCCOptions:MULTI=false,NODE_USES_PARSER=false,VISITOR=false,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ -package org.apache.oodt.cas.catalog.query.parser; - -/* All AST nodes must implement this interface. It provides basic - machinery for constructing the parent and child relationships - between nodes. */ - -public -interface Node { - - /** This method is called after the node has been made the current - node. It indicates that child nodes can now be added to it. */ - void jjtOpen(); - - /** This method is called after all the child nodes have been - added. */ - void jjtClose(); - - /** This pair of methods are used to inform the node of its - parent. */ - void jjtSetParent(Node n); - Node jjtGetParent(); - - /** This method tells the node to add its argument to the node's - list of children. */ - void jjtAddChild(Node n, int i); - - /** This method returns a child node. The children are numbered - from zero, left to right. */ - Node jjtGetChild(int i); - - /** Return the number of children the node has. */ - int jjtGetNumChildren(); -} -/* JavaCC - OriginalChecksum=d803b99b9dbe9f48568711ddba598d1d (do not edit this line) */ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/ParseException.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/ParseException.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/ParseException.java deleted file mode 100644 index c892ccf..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/ParseException.java +++ /dev/null @@ -1,190 +0,0 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ -/* JavaCCOptions:KEEP_LINE_COL=null */ -package org.apache.oodt.cas.catalog.query.parser; - -/** - * This exception is thrown when parse errors are encountered. - * You can explicitly create objects of this exception type by - * calling the method generateParseException in the generated - * parser. - * - * You can modify this class to customize your error reporting - * mechanisms so long as you retain the public fields. - */ -public class ParseException extends Exception { - - /** - * The version identifier for this Serializable class. - * Increment only if the <i>serialized</i> form of the - * class changes. - */ - private static final long serialVersionUID = 1L; - - /** - * This constructor is used by the method "generateParseException" - * in the generated parser. Calling this constructor generates - * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. - */ - public ParseException(Token currentTokenVal, - int[][] expectedTokenSequencesVal, - String[] tokenImageVal - ) - { - super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); - currentToken = currentTokenVal; - expectedTokenSequences = expectedTokenSequencesVal; - tokenImage = tokenImageVal; - } - - /** - * The following constructors are for use by you for whatever - * purpose you can think of. Constructing the exception in this - * manner makes the exception behave in the normal way - i.e., as - * documented in the class "Throwable". The fields "errorToken", - * "expectedTokenSequences", and "tokenImage" do not contain - * relevant information. The JavaCC generated code does not use - * these constructors. - */ - - public ParseException() { - super(); - } - - /** Constructor with message. */ - public ParseException(String message) { - super(message); - } - - - /** - * This is the last token that has been consumed successfully. If - * this object has been created due to a parse error, the token - * followng this token will (therefore) be the first error token. - */ - public Token currentToken; - - /** - * Each entry in this array is an array of integers. Each array - * of integers represents a sequence of tokens (by their ordinal - * values) that is expected at this point of the parse. - */ - public int[][] expectedTokenSequences; - - /** - * This is a reference to the "tokenImage" array of the generated - * parser within which the parse error occurred. This array is - * defined in the generated ...Constants interface. - */ - public String[] tokenImage; - - /** - * It uses "currentToken" and "expectedTokenSequences" to generate a parse - * error message and returns it. If this object has been created - * due to a parse error, and you do not catch it (it gets thrown - * from the parser) the correct error message - * gets displayed. - */ - private static String initialise(Token currentToken, - int[][] expectedTokenSequences, - String[] tokenImage) { - String eol = System.getProperty("line.separator", "\n"); - StringBuilder expected = new StringBuilder(); - int maxSize = 0; - for (int[] expectedTokenSequence : expectedTokenSequences) { - if (maxSize < expectedTokenSequence.length) { - maxSize = expectedTokenSequence.length; - } - for (int anExpectedTokenSequence : expectedTokenSequence) { - expected.append(tokenImage[anExpectedTokenSequence]).append(' '); - } - if (expectedTokenSequence[expectedTokenSequence.length - 1] != 0) { - expected.append("..."); - } - expected.append(eol).append(" "); - } - StringBuilder retval = new StringBuilder(); - retval.append("Encountered \""); - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) { - retval.append(" "); - } - if (tok.kind == 0) { - retval.append(tokenImage[0]); - break; - } - retval.append(" ").append(tokenImage[tok.kind]); - retval.append(" \""); - retval.append(add_escapes(tok.image)); - retval.append(" \""); - tok = tok.next; - } - retval.append("\" at line ").append(currentToken.next.beginLine).append(", column ") - .append(currentToken.next.beginColumn); - retval.append(".").append(eol); - if (expectedTokenSequences.length == 1) { - retval.append("Was expecting:").append(eol).append(" "); - } else { - retval.append("Was expecting one of:").append(eol).append(" "); - } - retval.append(expected.toString()); - return retval.toString(); - } - - /** - * The end of line string for this machine. - */ - protected String eol = System.getProperty("line.separator", "\n"); - - /** - * Used to convert raw characters to their escaped version - * when these raw version cannot be used as part of an ASCII - * string literal. - */ - static String add_escapes(String str) { - StringBuilder retval = new StringBuilder(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u").append(s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - } - } - return retval.toString(); - } - -} -/* JavaCC - OriginalChecksum=2dc94ec6e6c4be52e333891b220b8ef1 (do not edit this line) */ http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.java deleted file mode 100644 index 1c6311e..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.java +++ /dev/null @@ -1,1000 +0,0 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. QueryParser.java */ - package org.apache.oodt.cas.catalog.query.parser; - - import org.apache.oodt.cas.catalog.query.*; -import org.apache.oodt.cas.catalog.term.Term; - -import java.io.ByteArrayInputStream; -import java.util.HashSet; -import java.util.Properties; -import java.util.Vector; -@SuppressWarnings("all") - public class QueryParser/*@bgen(jjtree)*/implements QueryParserTreeConstants, QueryParserConstants {/*@bgen(jjtree)*/ - protected JJTQueryParserState jjtree = new JJTQueryParserState(); - public static QueryExpression parseQueryExpression(String queryExpressionString) throws ParseException, TokenMgrError { - return new QueryParser(new ByteArrayInputStream(queryExpressionString.getBytes())).parseInput(); - } - - public static void main( String[] args ) throws ParseException, TokenMgrError { - System.out.println(new QueryParser( System.in ).parseInput()); - } - - final public QueryExpression parseInput() throws ParseException { - /*@bgen(jjtree) parseInput */ - SimpleNode jjtn000 = new SimpleNode(JJTPARSEINPUT); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);QueryExpression qe; - try { - qe = Query(null); - jj_consume_token(0); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return qe;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression Query(Vector<String> bucketNames) throws ParseException { - /*@bgen(jjtree) Query */ - SimpleNode jjtn000 = new SimpleNode(JJTQUERY); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);QueryExpression qe1; - QueryExpression qe2 = null; - Token operator = null; - try { - qe1 = QueryExpression(bucketNames); - label_1: - while (true) { - if (jj_2_1(2147483647)) { - } else { - break label_1; - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case AND: - operator = jj_consume_token(AND); - break; - case OR: - operator = jj_consume_token(OR); - break; - default: - jj_la1[0] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - qe2 = Query(bucketNames); - } - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - if (qe2 == null) { - {if (true) return qe1;} - }else { - QueryLogicalGroup queryLogicalGroup = new QueryLogicalGroup(); - if (bucketNames != null) - queryLogicalGroup.setBucketNames(new HashSet<String>(bucketNames)); - queryLogicalGroup.setOperator(QueryLogicalGroup.Operator.valueOf(operator.image.trim().toUpperCase())); - queryLogicalGroup.addExpression(qe1); - queryLogicalGroup.addExpression(qe2); - {if (true) return queryLogicalGroup;} - } - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression QueryExpression(Vector<String> bucketNames) throws ParseException { - /*@bgen(jjtree) QueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);QueryExpression qe; - try { - if (jj_2_2(2147483647)) { - qe = PriorityQueryExpression(bucketNames); - } else if (jj_2_3(2147483647)) { - qe = StdQueryExpression(); - } else if (jj_2_4(2147483647)) { - qe = CustomQueryExpression(bucketNames); - } else if (jj_2_5(2147483647)) { - qe = ComparisonQueryExpression(bucketNames); - } else { - jj_consume_token(-1); - throw new ParseException(); - } - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return qe;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression StdQueryExpression() throws ParseException { - /*@bgen(jjtree) StdQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTSTDQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);QueryExpression qe = null; - Vector<String> bucketNames = new Vector<String>(); - try { - jj_consume_token(OPEN_BRACES); - label_2: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[1] = jj_gen; - break label_2; - } - jj_consume_token(SPACE); - } - jj_consume_token(BUCKET_NAME_KEY); - label_3: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[2] = jj_gen; - break label_3; - } - jj_consume_token(SPACE); - } - jj_consume_token(EQUALS); - label_4: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[3] = jj_gen; - break label_4; - } - jj_consume_token(SPACE); - } - getValues(bucketNames); - label_5: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[4] = jj_gen; - break label_5; - } - jj_consume_token(SPACE); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SEMI_COLON: - jj_consume_token(SEMI_COLON); - label_6: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[5] = jj_gen; - break label_6; - } - jj_consume_token(SPACE); - } - qe = Query(bucketNames); - break; - default: - jj_la1[6] = jj_gen; - } - label_7: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[7] = jj_gen; - break label_7; - } - jj_consume_token(SPACE); - } - jj_consume_token(CLOSE_BRACES); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - if (qe == null) { - {if (true) return new StdQueryExpression(new HashSet<String>(bucketNames));} - }else { - {if (true) return qe;} - } - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression ComparisonQueryExpression(Vector<String> bucketNames) throws ParseException { - /*@bgen(jjtree) ComparisonQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTCOMPARISONQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token termName; - Token operator; - Vector<String> values = new Vector<String>(); - try { - termName = jj_consume_token(TERM); - label_8: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[8] = jj_gen; - break label_8; - } - jj_consume_token(SPACE); - } - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case EQ: - operator = jj_consume_token(EQ); - break; - case GT: - operator = jj_consume_token(GT); - break; - case GE: - operator = jj_consume_token(GE); - break; - case LT: - operator = jj_consume_token(LT); - break; - case LE: - operator = jj_consume_token(LE); - break; - default: - jj_la1[9] = jj_gen; - jj_consume_token(-1); - throw new ParseException(); - } - label_9: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[10] = jj_gen; - break label_9; - } - jj_consume_token(SPACE); - } - getValues(values); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - Term term = new Term(termName.image); - term.setValues(values); //Arrays.asList(termValues.image.split(","))); - ComparisonQueryExpression comparisonQueryExpression = new ComparisonQueryExpression(); - if (bucketNames != null) - comparisonQueryExpression.setBucketNames(new HashSet<String>(bucketNames)); - comparisonQueryExpression.setTerm(term); - comparisonQueryExpression.setOperator(ComparisonQueryExpression.Operator.getOperatorBySign(operator.image)); - {if (true) return comparisonQueryExpression;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression PriorityQueryExpression(Vector<String> bucketNames) throws ParseException { - /*@bgen(jjtree) PriorityQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTPRIORITYQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);QueryExpression qe; - try { - jj_consume_token(OPEN_PARENS); - qe = Query(bucketNames); - jj_consume_token(CLOSE_PARENS); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - {if (true) return qe;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public QueryExpression CustomQueryExpression(Vector<String> bucketNames) throws ParseException { - /*@bgen(jjtree) CustomQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTCUSTOMQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token customNameToken; - Properties p = new Properties(); - try { - jj_consume_token(OPEN_BRACES); - label_10: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[11] = jj_gen; - break label_10; - } - jj_consume_token(SPACE); - } - jj_consume_token(CUSTOM_NAME_KEY); - label_11: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[12] = jj_gen; - break label_11; - } - jj_consume_token(SPACE); - } - jj_consume_token(EQUALS); - label_12: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[13] = jj_gen; - break label_12; - } - jj_consume_token(SPACE); - } - jj_consume_token(QUOTE); - customNameToken = jj_consume_token(TERM); - jj_consume_token(QUOTE); - if (jj_2_6(2147483647)) { - label_13: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[14] = jj_gen; - break label_13; - } - jj_consume_token(SPACE); - } - jj_consume_token(SEMI_COLON); - getProperties(p); - } else { - } - label_14: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[15] = jj_gen; - break label_14; - } - jj_consume_token(SPACE); - } - jj_consume_token(CLOSE_BRACES); - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - CustomQueryExpression cqe = new CustomQueryExpression(customNameToken.image, p); - if (bucketNames != null) - cqe.setBucketNames(new HashSet<String>(bucketNames)); - {if (true) return cqe;} - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - throw new Error("Missing return statement in function"); - } - - final public void getValues(Vector<String> values) throws ParseException { - /*@bgen(jjtree) getValues */ - SimpleNode jjtn000 = new SimpleNode(JJTGETVALUES); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token value; - try { - value = jj_consume_token(VALUE); - label_15: - while (true) { - if (jj_2_7(2147483647)) { - } else { - break label_15; - } - jj_consume_token(COMMA); - getValues(values); - } - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - values.add(0, value.image.replaceAll("'", "")); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - } - - final public void getProperties(Properties p) throws ParseException { - /*@bgen(jjtree) getProperties */ - SimpleNode jjtn000 = new SimpleNode(JJTGETPROPERTIES); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000);Token propertyKey; - Token propertyVal; - try { - propertyKey = jj_consume_token(P_KEY); - label_16: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[16] = jj_gen; - break label_16; - } - jj_consume_token(SPACE); - } - jj_consume_token(EQUALS); - label_17: - while (true) { - switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { - case SPACE: - break; - default: - jj_la1[17] = jj_gen; - break label_17; - } - jj_consume_token(SPACE); - } - propertyVal = jj_consume_token(VALUE); - label_18: - while (true) { - if (jj_2_8(2147483647)) { - } else { - break label_18; - } - jj_consume_token(COMMA); - getProperties(p); - } - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - p.put(propertyKey.image.substring(2), propertyVal.image.replaceAll("'", "")); - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - {if (true) throw (RuntimeException)jjte000;} - } - if (jjte000 instanceof ParseException) { - {if (true) throw (ParseException)jjte000;} - } - {if (true) throw (Error)jjte000;} - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } - } - - private boolean jj_2_1(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_1(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(0, xla); } - } - - private boolean jj_2_2(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_2(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(1, xla); } - } - - private boolean jj_2_3(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_3(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(2, xla); } - } - - private boolean jj_2_4(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_4(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(3, xla); } - } - - private boolean jj_2_5(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_5(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(4, xla); } - } - - private boolean jj_2_6(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_6(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(5, xla); } - } - - private boolean jj_2_7(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_7(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(6, xla); } - } - - private boolean jj_2_8(int xla) { - jj_la = xla; jj_lastpos = jj_scanpos = token; - try { return !jj_3_8(); } - catch(LookaheadSuccess ls) { return true; } - finally { jj_save(7, xla); } - } - - private boolean jj_3_8() { - if (jj_scan_token(COMMA)) return true; - return false; - } - - private boolean jj_3_3() { - if (jj_scan_token(OPEN_BRACES)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_scan_token(4)) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(BUCKET_NAME_KEY)) return true; - return false; - } - - private boolean jj_3_2() { - if (jj_scan_token(OPEN_PARENS)) return true; - return false; - } - - private boolean jj_3_7() { - if (jj_scan_token(COMMA)) return true; - return false; - } - - private boolean jj_3_1() { - Token xsp; - xsp = jj_scanpos; - if (jj_scan_token(5)) { - jj_scanpos = xsp; - if (jj_scan_token(6)) return true; - } - return false; - } - - private boolean jj_3_5() { - if (jj_scan_token(TERM)) return true; - return false; - } - - private boolean jj_3_6() { - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_scan_token(4)) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(SEMI_COLON)) return true; - return false; - } - - private boolean jj_3_4() { - if (jj_scan_token(OPEN_BRACES)) return true; - Token xsp; - while (true) { - xsp = jj_scanpos; - if (jj_scan_token(4)) { jj_scanpos = xsp; break; } - } - if (jj_scan_token(CUSTOM_NAME_KEY)) return true; - return false; - } - - public QueryParserTokenManager token_source; - SimpleCharStream jj_input_stream; - public Token token, jj_nt; - private int jj_ntk; - private Token jj_scanpos, jj_lastpos; - private int jj_la; - public boolean lookingAhead = false; - private boolean jj_semLA; - private int jj_gen; - final private int[] jj_la1 = new int[18]; - static private int[] jj_la1_0; - static { - jj_la1_0(); - } - private static void jj_la1_0() { - jj_la1_0 = new int[] {0x60,0x10,0x10,0x10,0x10,0x10,0x200,0x10,0x10,0x7c0000,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,}; - } - final private JJCalls[] jj_2_rtns = new JJCalls[8]; - private boolean jj_rescan = false; - private int jj_gc = 0; - - public QueryParser(java.io.InputStream stream) { - this(stream, null); - } - public QueryParser(java.io.InputStream stream, String encoding) { - try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source = new QueryParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(java.io.InputStream stream) { - ReInit(stream, null); - } - public void ReInit(java.io.InputStream stream, String encoding) { - try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jjtree.reset(); - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public QueryParser(java.io.Reader stream) { - jj_input_stream = new SimpleCharStream(stream, 1, 1); - token_source = new QueryParserTokenManager(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(java.io.Reader stream) { - jj_input_stream.ReInit(stream, 1, 1); - token_source.ReInit(jj_input_stream); - token = new Token(); - jj_ntk = -1; - jjtree.reset(); - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public QueryParser(QueryParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - public void ReInit(QueryParserTokenManager tm) { - token_source = tm; - token = new Token(); - jj_ntk = -1; - jjtree.reset(); - jj_gen = 0; - for (int i = 0; i < 18; i++) jj_la1[i] = -1; - for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls(); - } - - private Token jj_consume_token(int kind) throws ParseException { - Token oldToken; - if ((oldToken = token).next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - if (token.kind == kind) { - jj_gen++; - if (++jj_gc > 100) { - jj_gc = 0; - for (JJCalls jj_2_rtn : jj_2_rtns) { - JJCalls c = jj_2_rtn; - while (c != null) { - if (c.gen < jj_gen) { - c.first = null; - } - c = c.next; - } - } - } - return token; - } - token = oldToken; - jj_kind = kind; - throw generateParseException(); - } - - static private final class LookaheadSuccess extends java.lang.Error { } - final private LookaheadSuccess jj_ls = new LookaheadSuccess(); - private boolean jj_scan_token(int kind) { - if (jj_scanpos == jj_lastpos) { - jj_la--; - if (jj_scanpos.next == null) { - jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken(); - } else { - jj_lastpos = jj_scanpos = jj_scanpos.next; - } - } else { - jj_scanpos = jj_scanpos.next; - } - if (jj_rescan) { - int i = 0; Token tok = token; - while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; } - if (tok != null) jj_add_error_token(kind, i); - } - if (jj_scanpos.kind != kind) return true; - if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls; - return false; - } - - final public Token getNextToken() { - if (token.next != null) token = token.next; - else token = token.next = token_source.getNextToken(); - jj_ntk = -1; - jj_gen++; - return token; - } - - final public Token getToken(int index) { - Token t = lookingAhead ? jj_scanpos : token; - for (int i = 0; i < index; i++) { - if (t.next != null) t = t.next; - else t = t.next = token_source.getNextToken(); - } - return t; - } - - private int jj_ntk() { - if ((jj_nt=token.next) == null) - return (jj_ntk = (token.next=token_source.getNextToken()).kind); - else - return (jj_ntk = jj_nt.kind); - } - - private java.util.Vector<int[]> jj_expentries = new java.util.Vector<int[]>(); - private int[] jj_expentry; - private int jj_kind = -1; - private int[] jj_lasttokens = new int[100]; - private int jj_endpos; - - private void jj_add_error_token(int kind, int pos) { - if (pos >= 100) return; - if (pos == jj_endpos + 1) { - jj_lasttokens[jj_endpos++] = kind; - } else if (jj_endpos != 0) { - jj_expentry = new int[jj_endpos]; - for (int i = 0; i < jj_endpos; i++) { - jj_expentry[i] = jj_lasttokens[i]; - } - boolean exists = false; - for (java.util.Enumeration e = jj_expentries.elements(); e.hasMoreElements();) { - int[] oldentry = (int[])(e.nextElement()); - if (oldentry.length == jj_expentry.length) { - exists = true; - for (int i = 0; i < jj_expentry.length; i++) { - if (oldentry[i] != jj_expentry[i]) { - exists = false; - break; - } - } - if (exists) break; - } - } - if (!exists) jj_expentries.addElement(jj_expentry); - if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind; - } - } - - public ParseException generateParseException() { - jj_expentries.removeAllElements(); - boolean[] la1tokens = new boolean[28]; - for (int i = 0; i < 28; i++) { - la1tokens[i] = false; - } - if (jj_kind >= 0) { - la1tokens[jj_kind] = true; - jj_kind = -1; - } - for (int i = 0; i < 18; i++) { - if (jj_la1[i] == jj_gen) { - for (int j = 0; j < 32; j++) { - if ((jj_la1_0[i] & (1<<j)) != 0) { - la1tokens[j] = true; - } - } - } - } - for (int i = 0; i < 28; i++) { - if (la1tokens[i]) { - jj_expentry = new int[1]; - jj_expentry[0] = i; - jj_expentries.addElement(jj_expentry); - } - } - jj_endpos = 0; - jj_rescan_token(); - jj_add_error_token(0, 0); - int[][] exptokseq = new int[jj_expentries.size()][]; - for (int i = 0; i < jj_expentries.size(); i++) { - exptokseq[i] = jj_expentries.elementAt(i); - } - return new ParseException(token, exptokseq, tokenImage); - } - - final public void enable_tracing() { - } - - final public void disable_tracing() { - } - - private void jj_rescan_token() { - jj_rescan = true; - for (int i = 0; i < 8; i++) { - try { - JJCalls p = jj_2_rtns[i]; - do { - if (p.gen > jj_gen) { - jj_la = p.arg; jj_lastpos = jj_scanpos = p.first; - switch (i) { - case 0: jj_3_1(); break; - case 1: jj_3_2(); break; - case 2: jj_3_3(); break; - case 3: jj_3_4(); break; - case 4: jj_3_5(); break; - case 5: jj_3_6(); break; - case 6: jj_3_7(); break; - case 7: jj_3_8(); break; - } - } - p = p.next; - } while (p != null); - } catch(LookaheadSuccess ls) { } - } - jj_rescan = false; - } - - private void jj_save(int index, int xla) { - JJCalls p = jj_2_rtns[index]; - while (p.gen > jj_gen) { - if (p.next == null) { p = p.next = new JJCalls(); break; } - p = p.next; - } - p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla; - } - - static final class JJCalls { - int gen; - Token first; - int arg; - JJCalls next; - } - - } http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jj ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jj b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jj deleted file mode 100644 index 2537616..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jj +++ /dev/null @@ -1,497 +0,0 @@ -/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. ./QueryParser.jj */ -/*@egen*//* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -options { - JDK_VERSION = "1.5"; - STATIC = false; -} - -PARSER_BEGIN(QueryParser) - package org.apache.oodt.cas.catalog.query.parser; - - import java.io.ByteArrayInputStream; - import java.util.Arrays; - import java.util.HashSet; - import java.util.Vector; - import java.util.Properties; - import org.apache.oodt.cas.catalog.query.QueryExpression; - import org.apache.oodt.cas.catalog.query.QueryLogicalGroup; - import org.apache.oodt.cas.catalog.query.StdQueryExpression; - import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression; - import org.apache.oodt.cas.catalog.query.CustomQueryExpression; - import org.apache.oodt.cas.catalog.term.Term; - - public class QueryParser/*@bgen(jjtree)*/implements QueryParserTreeConstants/*@egen*/ {/*@bgen(jjtree)*/ - protected JJTQueryParserState jjtree = new JJTQueryParserState(); - -/*@egen*/ - - public static QueryExpression parseQueryExpression(String queryExpressionString) throws ParseException, TokenMgrError { - return new QueryParser(new ByteArrayInputStream(queryExpressionString.getBytes())).parseInput(); - } - - public static void main( String[] args ) throws ParseException, TokenMgrError { - System.out.println(new QueryParser( System.in ).parseInput()); - } - - } -PARSER_END(QueryParser) - -SKIP : { "\r" | "\n" | "\r\n" } -TOKEN: { < SPACE : " " > } -TOKEN: { < AND : " AND " > } -TOKEN: { < OR : " OR " > } -TOKEN: { < QUOTE : "'" > } -TOKEN: { < EQUALS : "=" > } -TOKEN: { < SEMI_COLON : ";" > } -TOKEN: { < COMMA : "," > } -TOKEN: { < OPEN_BRACES : "{" > } -TOKEN: { < CLOSE_BRACES : "}" > } -TOKEN: { < OPEN_PARENS : "(" > } -TOKEN: { < CLOSE_PARENS : ")" > } -TOKEN: { < BUCKET_NAME_KEY : "bucketNames" > } -TOKEN: { < CUSTOM_NAME_KEY : "name" > } -TOKEN: { < P_KEY : "p:" <TERM> > } -TOKEN: { - < EQ : "==" > - | < GE : ">=" > - | < GT : ">" > - | < LE : "<=" > - | < LT : "<" > -} -TOKEN: { < TERM: (["a"-"z","A"-"Z"])+ (<STRING_LITERAL>)* > } -TOKEN: { < VALUE : "'" ( <TERM> | <NON_TERM> ) "'" > } -TOKEN: { < #NON_TERM: (<STRING_LITERAL> | <SPECIAL_CHARS>)+ (<STRING_LITERAL> | " "<STRING_LITERAL> | " "<SPECIAL_CHARS> | <SPECIAL_CHARS>)* > } -TOKEN: { < #STRING_LITERAL: (["0"-"9","a"-"z","A"-"Z","-","_",".",":","/"]) > } -TOKEN: { < #SPECIAL_CHARS: (["/","\\","?","<",">","~","`","*","#","&","!","@","$","%","^","(",")","{","}","[","]"]) > } - -QueryExpression parseInput() : -{/*@bgen(jjtree) parseInput */ - SimpleNode jjtn000 = new SimpleNode(JJTPARSEINPUT); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - QueryExpression qe = null; -} -{/*@bgen(jjtree) parseInput */ - try { -/*@egen*/ - qe = Query(null) <EOF>/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { return qe; }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression Query(Vector<String> bucketNames) : -{/*@bgen(jjtree) Query */ - SimpleNode jjtn000 = new SimpleNode(JJTQUERY); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - QueryExpression qe1 = null; - QueryExpression qe2 = null; - Token operator = null; -} -{/*@bgen(jjtree) Query */ - try { -/*@egen*/ - qe1 = QueryExpression(bucketNames) ( LOOKAHEAD( <AND> | <OR> ) ( operator = <AND> | operator = <OR> ) qe2 = Query(bucketNames) )*/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - if (qe2 == null) { - return qe1; - }else { - QueryLogicalGroup queryLogicalGroup = new QueryLogicalGroup(); - if (bucketNames != null) - queryLogicalGroup.setBucketNames(new HashSet<String>(bucketNames)); - queryLogicalGroup.setOperator(QueryLogicalGroup.Operator.valueOf(operator.image.trim().toUpperCase())); - queryLogicalGroup.addExpression(qe1); - queryLogicalGroup.addExpression(qe2); - return queryLogicalGroup; - } - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression QueryExpression(Vector<String> bucketNames) : -{/*@bgen(jjtree) QueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - QueryExpression qe = null; -} -{/*@bgen(jjtree) QueryExpression */ - try { -/*@egen*/ - ( - LOOKAHEAD ( <OPEN_PARENS> ) - qe = PriorityQueryExpression(bucketNames) - | - LOOKAHEAD ( <OPEN_BRACES> (<SPACE>)* <BUCKET_NAME_KEY> ) - qe = StdQueryExpression() - | - LOOKAHEAD ( <OPEN_BRACES> (<SPACE>)* <CUSTOM_NAME_KEY> ) - qe = CustomQueryExpression(bucketNames) - | - LOOKAHEAD ( <TERM> ) - qe = ComparisonQueryExpression(bucketNames) - )/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - - { return qe; }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression StdQueryExpression() : -{/*@bgen(jjtree) StdQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTSTDQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - QueryExpression qe = null; - Vector<String> bucketNames = new Vector<String>(); -} -{/*@bgen(jjtree) StdQueryExpression */ - try { -/*@egen*/ - <OPEN_BRACES> (<SPACE>)* <BUCKET_NAME_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* getValues(bucketNames) (<SPACE>)* [<SEMI_COLON> (<SPACE>)* qe = Query(bucketNames)] (<SPACE>)* <CLOSE_BRACES>/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - if (qe == null) { - return new StdQueryExpression(new HashSet<String>(bucketNames)); - }else { - return qe; - } - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression ComparisonQueryExpression(Vector<String> bucketNames) : -{/*@bgen(jjtree) ComparisonQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTCOMPARISONQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - Token termName = null; - Token operator = null; - Vector<String> values = new Vector<String>(); -} -{/*@bgen(jjtree) ComparisonQueryExpression */ - try { -/*@egen*/ - termName = <TERM> (<SPACE>)* ( operator = <EQ> | operator = <GT> | operator = <GE> | operator = <LT> | operator = <LE> ) (<SPACE>)* getValues(values)/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - Term term = new Term(termName.image); - term.setValues(values); //Arrays.asList(termValues.image.split(","))); - ComparisonQueryExpression comparisonQueryExpression = new ComparisonQueryExpression(); - if (bucketNames != null) - comparisonQueryExpression.setBucketNames(new HashSet<String>(bucketNames)); - comparisonQueryExpression.setTerm(term); - comparisonQueryExpression.setOperator(ComparisonQueryExpression.Operator.getOperatorBySign(operator.image)); - return comparisonQueryExpression; - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression PriorityQueryExpression(Vector<String> bucketNames) : -{/*@bgen(jjtree) PriorityQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTPRIORITYQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - QueryExpression qe = null; -} -{/*@bgen(jjtree) PriorityQueryExpression */ - try { -/*@egen*/ - <OPEN_PARENS> qe = Query(bucketNames) <CLOSE_PARENS>/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { return qe; }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -QueryExpression CustomQueryExpression(Vector<String> bucketNames) : -{/*@bgen(jjtree) CustomQueryExpression */ - SimpleNode jjtn000 = new SimpleNode(JJTCUSTOMQUERYEXPRESSION); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - Token customNameToken = null; - Properties p = new Properties(); -} -{/*@bgen(jjtree) CustomQueryExpression */ - try { -/*@egen*/ - <OPEN_BRACES> (<SPACE>)* <CUSTOM_NAME_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* <QUOTE> customNameToken = <TERM> <QUOTE> [ LOOKAHEAD ((<SPACE>)* <SEMI_COLON>) (<SPACE>)* <SEMI_COLON> getProperties(p) ] (<SPACE>)* <CLOSE_BRACES>/*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - CustomQueryExpression cqe = new CustomQueryExpression(customNameToken.image, p); - if (bucketNames != null) - cqe.setBucketNames(new HashSet<String>(bucketNames)); - return cqe; - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -void getValues(Vector<String> values) : -{/*@bgen(jjtree) getValues */ - SimpleNode jjtn000 = new SimpleNode(JJTGETVALUES); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - Token value = null; -} -{/*@bgen(jjtree) getValues */ - try { -/*@egen*/ - value = <VALUE> ( LOOKAHEAD (<COMMA>) <COMMA> getValues(values) ) */*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - values.add(0, value.image.replaceAll("'", "")); - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} - -void getProperties(Properties p) : -{/*@bgen(jjtree) getProperties */ - SimpleNode jjtn000 = new SimpleNode(JJTGETPROPERTIES); - boolean jjtc000 = true; - jjtree.openNodeScope(jjtn000); -/*@egen*/ - Token propertyKey = null; - Token propertyVal = null; -} -{/*@bgen(jjtree) getProperties */ - try { -/*@egen*/ - propertyKey = <P_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* propertyVal = <VALUE> ( LOOKAHEAD (<COMMA>) <COMMA> getProperties(p) ) */*@bgen(jjtree)*/ - { - jjtree.closeNodeScope(jjtn000, true); - jjtc000 = false; - } -/*@egen*/ - { - p.put(propertyKey.image.substring(2), propertyVal.image.replaceAll("'", "")); - }/*@bgen(jjtree)*/ - } catch (Throwable jjte000) { - if (jjtc000) { - jjtree.clearNodeScope(jjtn000); - jjtc000 = false; - } else { - jjtree.popNode(); - } - if (jjte000 instanceof RuntimeException) { - throw (RuntimeException)jjte000; - } - if (jjte000 instanceof ParseException) { - throw (ParseException)jjte000; - } - throw (Error)jjte000; - } finally { - if (jjtc000) { - jjtree.closeNodeScope(jjtn000, true); - } - } -/*@egen*/ -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jjt ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jjt b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jjt deleted file mode 100644 index 60697fb..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParser.jjt +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -options { - JDK_VERSION = "1.5"; - STATIC = false; -} - -PARSER_BEGIN(QueryParser) - package org.apache.oodt.cas.catalog.query.parser; - - import java.io.ByteArrayInputStream; - import java.util.Arrays; - import java.util.HashSet; - import java.util.Vector; - import java.util.Properties; - import org.apache.oodt.cas.catalog.query.QueryExpression; - import org.apache.oodt.cas.catalog.query.QueryLogicalGroup; - import org.apache.oodt.cas.catalog.query.StdQueryExpression; - import org.apache.oodt.cas.catalog.query.ComparisonQueryExpression; - import org.apache.oodt.cas.catalog.query.CustomQueryExpression; - import org.apache.oodt.cas.catalog.term.Term; - - public class QueryParser { - - public static QueryExpression parseQueryExpression(String queryExpressionString) throws ParseException, TokenMgrError { - return new QueryParser(new ByteArrayInputStream(queryExpressionString.getBytes())).parseInput(); - } - - public static void main( String[] args ) throws ParseException, TokenMgrError { - System.out.println(new QueryParser( System.in ).parseInput()); - } - - } -PARSER_END(QueryParser) - -SKIP : { "\r" | "\n" | "\r\n" } -TOKEN: { < SPACE : " " > } -TOKEN: { < AND : " AND " > } -TOKEN: { < OR : " OR " > } -TOKEN: { < QUOTE : "'" > } -TOKEN: { < EQUALS : "=" > } -TOKEN: { < SEMI_COLON : ";" > } -TOKEN: { < COMMA : "," > } -TOKEN: { < OPEN_BRACES : "{" > } -TOKEN: { < CLOSE_BRACES : "}" > } -TOKEN: { < OPEN_PARENS : "(" > } -TOKEN: { < CLOSE_PARENS : ")" > } -TOKEN: { < BUCKET_NAME_KEY : "bucketNames" > } -TOKEN: { < CUSTOM_NAME_KEY : "name" > } -TOKEN: { < P_KEY : "p:" <TERM> > } -TOKEN: { - < EQ : "==" > - | < GE : ">=" > - | < GT : ">" > - | < LE : "<=" > - | < LT : "<" > -} -TOKEN: { < TERM: (["a"-"z","A"-"Z"])+ (<STRING_LITERAL>)* > } -TOKEN: { < VALUE : "'" ( <TERM> | <NON_TERM> ) "'" > } -TOKEN: { < #NON_TERM: (<STRING_LITERAL> | <SPECIAL_CHARS>)+ (<STRING_LITERAL> | " "<STRING_LITERAL> | " "<SPECIAL_CHARS> | <SPECIAL_CHARS>)* > } -TOKEN: { < #STRING_LITERAL: (["0"-"9","a"-"z","A"-"Z","-","_",".",":","/"]) > } -TOKEN: { < #SPECIAL_CHARS: (["/","\\","?","<",">","~","`","*","#","&","!","@","$","%","^","(",")","{","}","[","]"]) > } - -QueryExpression parseInput() : -{ - QueryExpression qe = null; -} -{ - qe = Query(null) <EOF> - { return qe; } -} - -QueryExpression Query(Vector<String> bucketNames) : -{ - QueryExpression qe1 = null; - QueryExpression qe2 = null; - Token operator = null; -} -{ - qe1 = QueryExpression(bucketNames) ( LOOKAHEAD( <AND> | <OR> ) ( operator = <AND> | operator = <OR> ) qe2 = Query(bucketNames) )* - { - if (qe2 == null) { - return qe1; - }else { - QueryLogicalGroup queryLogicalGroup = new QueryLogicalGroup(); - if (bucketNames != null) - queryLogicalGroup.setBucketNames(new HashSet<String>(bucketNames)); - queryLogicalGroup.setOperator(QueryLogicalGroup.Operator.valueOf(operator.image.trim().toUpperCase())); - queryLogicalGroup.addExpression(qe1); - queryLogicalGroup.addExpression(qe2); - return queryLogicalGroup; - } - } -} - -QueryExpression QueryExpression(Vector<String> bucketNames) : -{ - QueryExpression qe = null; -} -{ - ( - LOOKAHEAD ( <OPEN_PARENS> ) - qe = PriorityQueryExpression(bucketNames) - | - LOOKAHEAD ( <OPEN_BRACES> (<SPACE>)* <BUCKET_NAME_KEY> ) - qe = StdQueryExpression() - | - LOOKAHEAD ( <OPEN_BRACES> (<SPACE>)* <CUSTOM_NAME_KEY> ) - qe = CustomQueryExpression(bucketNames) - | - LOOKAHEAD ( <TERM> ) - qe = ComparisonQueryExpression(bucketNames) - ) - - { return qe; } -} - -QueryExpression StdQueryExpression() : -{ - QueryExpression qe = null; - Vector<String> bucketNames = new Vector<String>(); -} -{ - <OPEN_BRACES> (<SPACE>)* <BUCKET_NAME_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* getValues(bucketNames) (<SPACE>)* [<SEMI_COLON> (<SPACE>)* qe = Query(bucketNames)] (<SPACE>)* <CLOSE_BRACES> - { - if (qe == null) { - return new StdQueryExpression(new HashSet<String>(bucketNames)); - }else { - return qe; - } - } -} - -QueryExpression ComparisonQueryExpression(Vector<String> bucketNames) : -{ - Token termName = null; - Token operator = null; - Vector<String> values = new Vector<String>(); -} -{ - termName = <TERM> (<SPACE>)* ( operator = <EQ> | operator = <GT> | operator = <GE> | operator = <LT> | operator = <LE> ) (<SPACE>)* getValues(values) - { - Term term = new Term(termName.image); - term.setValues(values); //Arrays.asList(termValues.image.split(","))); - ComparisonQueryExpression comparisonQueryExpression = new ComparisonQueryExpression(); - if (bucketNames != null) - comparisonQueryExpression.setBucketNames(new HashSet<String>(bucketNames)); - comparisonQueryExpression.setTerm(term); - comparisonQueryExpression.setOperator(ComparisonQueryExpression.Operator.getOperatorBySign(operator.image)); - return comparisonQueryExpression; - } -} - -QueryExpression PriorityQueryExpression(Vector<String> bucketNames) : -{ - QueryExpression qe = null; -} -{ - <OPEN_PARENS> qe = Query(bucketNames) <CLOSE_PARENS> - { return qe; } -} - -QueryExpression CustomQueryExpression(Vector<String> bucketNames) : -{ - Token customNameToken = null; - Properties p = new Properties(); -} -{ - <OPEN_BRACES> (<SPACE>)* <CUSTOM_NAME_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* <QUOTE> customNameToken = <TERM> <QUOTE> [ LOOKAHEAD ((<SPACE>)* <SEMI_COLON>) (<SPACE>)* <SEMI_COLON> getProperties(p) ] (<SPACE>)* <CLOSE_BRACES> - { - CustomQueryExpression cqe = new CustomQueryExpression(customNameToken.image, p); - if (bucketNames != null) - cqe.setBucketNames(new HashSet<String>(bucketNames)); - return cqe; - } -} - -void getValues(Vector<String> values) : -{ - Token value = null; -} -{ - value = <VALUE> ( LOOKAHEAD (<COMMA>) <COMMA> getValues(values) ) * - { - values.add(0, value.image.replaceAll("'", "")); - } -} - -void getProperties(Properties p) : -{ - Token propertyKey = null; - Token propertyVal = null; -} -{ - propertyKey = <P_KEY> (<SPACE>)* <EQUALS> (<SPACE>)* propertyVal = <VALUE> ( LOOKAHEAD (<COMMA>) <COMMA> getProperties(p) ) * - { - p.put(propertyKey.image.substring(2), propertyVal.image.replaceAll("'", "")); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParserConstants.java ---------------------------------------------------------------------- diff --git a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParserConstants.java b/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParserConstants.java deleted file mode 100644 index ac3ded6..0000000 --- a/catalog/src/main/java/org/apache/oodt/cas/catalog/query/parser/QueryParserConstants.java +++ /dev/null @@ -1,65 +0,0 @@ -/* Generated By:JJTree&JavaCC: Do not edit this line. QueryParserConstants.java */ -package org.apache.oodt.cas.catalog.query.parser; - -public interface QueryParserConstants { - - int EOF = 0; - int SPACE = 4; - int AND = 5; - int OR = 6; - int QUOTE = 7; - int EQUALS = 8; - int SEMI_COLON = 9; - int COMMA = 10; - int OPEN_BRACES = 11; - int CLOSE_BRACES = 12; - int OPEN_PARENS = 13; - int CLOSE_PARENS = 14; - int BUCKET_NAME_KEY = 15; - int CUSTOM_NAME_KEY = 16; - int P_KEY = 17; - int EQ = 18; - int GE = 19; - int GT = 20; - int LE = 21; - int LT = 22; - int TERM = 23; - int VALUE = 24; - int NON_TERM = 25; - int STRING_LITERAL = 26; - int SPECIAL_CHARS = 27; - - int DEFAULT = 0; - - String[] tokenImage = { - "<EOF>", - "\"\\r\"", - "\"\\n\"", - "\"\\r\\n\"", - "\" \"", - "\" AND \"", - "\" OR \"", - "\"\\\'\"", - "\"=\"", - "\";\"", - "\",\"", - "\"{\"", - "\"}\"", - "\"(\"", - "\")\"", - "\"bucketNames\"", - "\"name\"", - "<P_KEY>", - "\"==\"", - "\">=\"", - "\">\"", - "\"<=\"", - "\"<\"", - "<TERM>", - "<VALUE>", - "<NON_TERM>", - "<STRING_LITERAL>", - "<SPECIAL_CHARS>", - }; - -}
