[Mulgara-svn] r376 - branches/nw-interface/src/jar/itql/java/org/mulgara/itql
pag at mulgara.org
pag at mulgara.org
Fri Aug 24 16:07:51 UTC 2007
Author: pag
Date: 2007-08-24 11:07:49 -0500 (Fri, 24 Aug 2007)
New Revision: 376
Modified:
branches/nw-interface/src/jar/itql/java/org/mulgara/itql/VariableBuilder.java
Log:
Cleaned up formatting, and added some Javadoc
Modified: branches/nw-interface/src/jar/itql/java/org/mulgara/itql/VariableBuilder.java
===================================================================
--- branches/nw-interface/src/jar/itql/java/org/mulgara/itql/VariableBuilder.java 2007-08-24 06:49:41 UTC (rev 375)
+++ branches/nw-interface/src/jar/itql/java/org/mulgara/itql/VariableBuilder.java 2007-08-24 16:07:49 UTC (rev 376)
@@ -53,10 +53,6 @@
*
* @author Andrew Newman
*
- * @version $Revision: 1.8 $
- *
- * @modified $Date: 2005/01/05 04:58:15 $ by $Author: newmana $
- *
* @company <a href="mailto:info at PIsoftware.com">Plugged In Software</a>
*
* @copyright ©2004 <a href="http://www.pisoftware.com/">Plugged In
@@ -66,165 +62,135 @@
*/
public class VariableBuilder extends AnalysisAdapter {
- /**
- * The logger
- */
- private final static Logger logger =
- Logger.getLogger(VariableBuilder.class.getName());
+ /** The logger */
+ private final static Logger logger = Logger.getLogger(VariableBuilder.class.getName());
- /**
- * Variable name generator for anonymous columns
- */
+ /** Variable name generator for anonymous columns */
private VariableFactory variableFactory;
- /**
- * URI Syntax Exception - not null if exception occurred since last get.
- */
+ /** URI Syntax Exception - not null if exception occurred since last get. */
private URISyntaxException uriException = null;
- /**
- * Query Exception - not null if exception occurred since last get.
- */
+ /** Query Exception - not null if exception occurred since last get. */
private QueryException queryException = null;
/**
- * The list of variables - these are mixed object types
+ * The list of variables - these are mixed object types:
+ * ConstantValue, Variable, Count, SubQuery
*/
private List<Object> variableList;
- /**
- * The iTQL interpreter
- */
+ /** The TQL interpreter */
private Interpreter interpreter;
+
/**
* Create a new builder. Requires methods on the interpreter in order to
* function correctly.
- *
* @param newInterpreter the interpreter to use.
*/
- public VariableBuilder(Interpreter newInterpreter,
- VariableFactory newVariableFactory) {
-
+ public VariableBuilder(Interpreter newInterpreter, VariableFactory newVariableFactory) {
variableList = new ArrayList<Object>();
interpreter = newInterpreter;
variableFactory = newVariableFactory;
}
+
/**
* Converts a literal element to a constant and adds it to the variable list.
- *
+ * This method is called back from SableCC.
* @param element the literal element to add to the variable list.
*/
public void caseALiteralElement(ALiteralElement element) {
-
variableList.add(new ConstantValue(
variableFactory.newVariable(),
- interpreter.toLiteralImpl(((ALiteralElement) element).getLiteral())
+ interpreter.toLiteralImpl(((ALiteralElement)element).getLiteral())
));
}
+
/**
* Converts a resource element to a constant and adds it to the variable list.
- *
+ * This method is called back from SableCC.
* @param element the resource element to add to the variable list.
*/
public void caseAResourceElement(AResourceElement element) {
-
// add a new resource to the list
variableList.add(new ConstantValue(
variableFactory.newVariable(),
- new URIReferenceImpl(interpreter.toURI(
- ((AResourceElement) element).getResource()
- ))
+ new URIReferenceImpl(interpreter.toURI(((AResourceElement) element).getResource()))
));
}
+
/**
- * Gets the string values of a variable element and adds it to the variable
- * list.
- *
+ * Gets the string values of a variable element and adds it to the variable list.
+ * This method is called back from SableCC.
* @param element the variable element to add to the variable list.
*/
public void caseAVariableElement(AVariableElement element) {
-
// get the name of this variable
- String variableName =
- ((AVariable) ((AVariableElement) element).getVariable()).
- getIdentifier().getText();
+ String variableName = ((AVariable)((AVariableElement)element).getVariable()).getIdentifier().getText();
- // log that we've found a variable
- if (logger.isDebugEnabled()) {
- logger.debug("Found variable $" + variableName);
- }
+ if (logger.isDebugEnabled()) logger.debug("Found variable $" + variableName);
// add a new variable to the list
variableList.add(new Variable(variableName));
- if (logger.isDebugEnabled()) {
- logger.debug("Variable list: " + variableList);
- }
+ if (logger.isDebugEnabled()) logger.debug("Variable list: " + variableList);
}
+
/**
* Handle an aggregate element. At the moment it handles both count and
- * sub-queries. Will set URIException or QueryException if
- * an exception occurs.
- *
+ * sub-queries. Any further aggregates will be instantiated here.
+ * Will set URIException or QueryException if an exception occurs.
+ * This method is called back from SableCC.
* @param element the aggregate element to add to the variable list.
*/
public void caseAAggregateElement(AAggregateElement element) {
-
try {
- AAggregateElement aggregateElement = (AAggregateElement) element;
- PAggregate aggregate = aggregateElement.getAggregate();
+ AAggregateElement aggregateElement = (AAggregateElement)element;
+ // build the elements of the aggregate
+ Query aggregateQuery = interpreter.buildQuery(aggregateElement.getQuery());
+ Variable aggregateVariable = variableFactory.newVariable();
+
+ // create the correct aggregate type - count or subquery
+ PAggregate aggregate = aggregateElement.getAggregate();
if (aggregate instanceof ACountAggregate) {
- variableList.add(new Count(variableFactory.newVariable(),
- interpreter.buildQuery(aggregateElement.getQuery())));
+ variableList.add(new Count(aggregateVariable, aggregateQuery));
+ } else if (aggregate instanceof ASubqueryAggregate) {
+ variableList.add(new Subquery(aggregateVariable, aggregateQuery));
+ } else {
+ throw new Error("Unsupported aggregate type: " + aggregate.getClass());
}
- else if (aggregate instanceof ASubqueryAggregate) {
- variableList.add(new Subquery(variableFactory.newVariable(),
- interpreter.buildQuery(aggregateElement.getQuery())));
- }
- else {
- throw new Error("Unsupported aggregate type: " +
- aggregate.getClass());
- }
- }
- catch (QueryException qe) {
+ } catch (QueryException qe) {
queryException = qe;
- }
- catch (URISyntaxException use) {
+ } catch (URISyntaxException use) {
uriException = use;
}
}
+
/**
* Returns the latest variable list or throws an exception if there
* was an error creating it. Once called the variable list is cleared
* and exceptions are nulled.
- *
+ * @return A list of: Variable, ConstantValue, Count, Subquery.
* @throws QueryException if the variable does not is invalid
* @throws URISyntaxException if the variable contains a resource whose
* text violates <a href="http://www.isi.edu/in-notes/rfc2396.txt">RFC?2396</a>
*/
public List<Object> getVariableList() throws QueryException, URISyntaxException {
-
try {
List<Object> tmpVariableList = new ArrayList<Object>(variableList);
- if (uriException != null) {
- throw uriException;
- }
- else if (queryException != null) {
- throw queryException;
- }
- else {
- return tmpVariableList;
- }
- }
- finally {
+ if (uriException != null) throw uriException;
+ else if (queryException != null) throw queryException;
+ else return tmpVariableList;
+
+ } finally {
uriException = null;
queryException = null;
variableList.clear();
More information about the Mulgara-svn
mailing list