/** * Given a [queriable] instance, tells wether this instance satisfies the * query. * This implementation delegates the work to the underlying [real] query. */ public boolean validate (final Object o) throws QueryException { //log.debug("validate() this is \n"+this.toString()); final QueryItem qi = fetch(); //log.debug("validate() fetch returned \n"+qi.toString()); return qi.validate(o); }
/** * Returns the value stored in an AssignmentItem ('set', 'property', ...) */ protected String lookupValue (final String name) { final java.util.Iterator it = this.items.iterator(); while (it.hasNext()) { final Object o = it.next(); if ( ! (o instanceof AssignmentItem)) continue; final AssignmentItem ai = (AssignmentItem)o; if (name.equals(ai.getName())) return ai.getValue(); } if (getParentQuery() != null) return getParentQuery().lookupValue(name); return ""; }
private QueryItem fetch () throws QueryException { if (getReference() != null) return getReference(); if (getSreference() != null) { //log.debug("fetch() looking up "+getSreference()); final QueryItem qi = lookup(getSreference()); setReference(qi); return qi; } // // no reference ? then uses the first available item if (this.items.size() < 1) { throw new QueryException ("Cannot use this Query, "+ "it contains no atomic query item"); } //log.debug("'"+getName()+"' fetch() using first available query"); return (QueryItem)this.items.get(0); }
/** * Looks up for a query item in this scope or in the parent scope. */ public Query lookup (final String itemName) { //log.debug("lookup() in '"+getName()+"' for '"+itemName+"'"); Query result = this.get(itemName); if (result != null) return result; //if (getParentQuery() == null) return null; return getParentQuery().lookup(itemName); }
public boolean validate (final Object o) throws QueryException { if (getChildren() == null || getChildren().size() < 1) return false; final java.util.Iterator it = getChildren().iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); if ( ! qi.validate(o)) return false; } return true; }
public boolean validate (final Object o) throws QueryException { //log.debug("validate()"); if (getChildren() == null || getChildren().size() < 1) { //log.debug("validate() no children : returning false"); return false; } final java.util.Iterator it = getChildren().iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); if (qi.validate(o)) return true; } //log.debug("validate() finally returning false"); return false; }
public Set query (final Object o) throws QueryException { if (getChildren() == null || getChildren().size() < 1) return null; Set result = null; final java.util.Iterator it = getChildren().iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); if (result == null) result = qi.query(o); else result = SetUtils.doUnion(result, qi.query(o)); } return result; }
public Set query (final Object o) throws QueryException { if (getChildren() == null || getChildren().size() < 1) return null; Set result = null; final java.util.Iterator it = getChildren().iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); if (result == null) result = qi.query(o); else result = SetUtils.doIntersection(result, qi.query(o)); if (result.isEmpty()) break; } return result; }
private static QueryItem lookupQuery (final Query query, final String[] url, final int index) throws QueryException { if (log.isDebugEnabled()) { log.debug("lookupQuery() index is "+index); log.debug("lookupQuery() into '"+query.getName()+"'"); //log.debug("lookupQuery() into\n"+query); log.debug("lookupQuery() for '"+url[index]+"'"); } final QueryItem qi = query.get(url[index]); if (qi == null) { log.debug("lookupQuery() found null, returning null"); return null; } if (index >= url.length-1) return qi; if ( ! (qi instanceof Query)) { throw new QueryException ("Cannot dive into non-scope '"+url[index]+"'"); } //log.debug("lookupQuery() diving into >"+((Query)qi).getName()+"<"); return lookupQuery((Query)qi, url, index+1); }
public static void main (String[] args) throws Exception { // // init query map //ApplicationContext con = new ApplicationContext(); java.util.Map params = new java.util.HashMap(); params.put ("queryConfigurationFile", "tst/query-config.xml"); XmlQueryMap queryMap = new XmlQueryMap(); queryMap.init("queryMap", null, params); QueryItem qi = queryMap.lookupQuery("tst/query-map.xml#Store.querystore#charly"); //log.debug("qi.class is "+qi.getClass().getName()); org.jdom.Element elt = new org.jdom.Element("toto"); elt.setAttribute("participantName", "role-bravo"); log.debug("validate returns "+qi.validate(elt)); }
if (rootQuery.getLastModified() >= FileUtils.getLastModified(docUrl)) rootQuery.setLastModified(FileUtils.getLastModified(docUrl));
public Query get (final String name) { //return (Query)this.subQueries.get(name); final java.util.Iterator it = this.items.iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); if ( ! (qi instanceof Query)) continue; final Query q = (Query)qi; //if (name.equals(q.getName())) return q; if (name.matches(q.getName())) return q; } return null; }
public Object get (final Object key) { return Query.this.lookupValue(key.toString()); }
public static String lookupAttributeValue (final Query parentQuery, final org.jdom.Element elt, final String attributeName) { final String result = elt.getAttributeValue(attributeName); if (result == null) return null; if (parentQuery == null) return null; return openwfe.org.misc.Text .substitute(result, parentQuery.asTextSubstitutionMap()); }
public String toString () { final StringBuffer sb = new StringBuffer(); sb.append("<"); sb.append(this.getClass().getName()); sb.append("::or>\n"); final java.util.Iterator it = getChildren().iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); sb.append(qi.toString()); } sb.append("</"); sb.append(this.getClass().getName()); sb.append("::or>\n"); return sb.toString(); }
/** * Given a query item in its XML element form, returns the corresponding * query item. */ public QueryItem determineQueryItem (final Query parentQuery, final Object o) throws QueryException { final org.jdom.Element elt = (org.jdom.Element)o; final String classname = (String)this.config.get(elt.getName()); //log.debug("determineQueryItem() classname : "+classname); if (classname == null) { throw new QueryException ("no query item class for elt named '"+elt.getName()+"'"); } final QueryItem qi = (QueryItem)ReflectionUtils.buildNewInstance(classname); qi.init(this, parentQuery, elt); //if (parentQuery != null) parentQuery.put(qi); return qi; }
public String toString () { final StringBuffer sb = new StringBuffer(); sb.append("<"); sb.append(this.getClass().getName()); sb.append("::"); sb.append(getName()); sb.append(">\n"); final java.util.Iterator it = this.items.iterator(); while (it.hasNext()) { final QueryItem qi = (QueryItem)it.next(); sb.append(qi.toString()); } sb.append("</"); sb.append(this.getClass().getName()); sb.append("::"); sb.append(getName()); sb.append(">\n"); return sb.toString(); }