wam         2002/05/31 05:23:24

  Modified:    src/share/org/apache/slide/search/basic BasicQuery.java
                        BasicSearchLanguage.java
  Added:       src/share/org/apache/slide/search/basic
                        BasicQueryFactory.java BasicQueryImpl.java
  Log:
  make the implementation of BasicQuery pluggable
  
  Revision  Changes    Path
  1.9       +131 -203  
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java
  
  Index: BasicQuery.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- BasicQuery.java   25 Apr 2002 21:12:30 -0000      1.8
  +++ BasicQuery.java   31 May 2002 12:23:23 -0000      1.9
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.8 
2002/04/25 21:12:30 jericho Exp $
  - * $Revision: 1.8 $
  - * $Date: 2002/04/25 21:12:30 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQuery.java,v 1.9 
2002/05/31 12:23:23 wam Exp $
  + * $Revision: 1.9 $
  + * $Date: 2002/05/31 12:23:23 $
    *
    * ====================================================================
    *
  @@ -62,10 +62,10 @@
    */
   
   package org.apache.slide.search.basic;
  -import org.apache.slide.search.*;
   
  +import org.apache.slide.search.SearchToken;
  +import org.apache.slide.search.QueryScope;
   import org.apache.slide.search.SearchQuery;
  -import org.apache.slide.search.SearchException;
   import org.apache.slide.search.BadQueryException;
   import org.apache.slide.search.SearchQueryResult;
   import org.apache.slide.common.ServiceAccessException;
  @@ -79,112 +79,68 @@
   import org.jdom.Namespace;
   import org.jdom.Element;
   import org.jdom.Document;
  -import org.xml.sax.InputSource;
  -
  -//import org.apache.slide.common.SlideToken;
   
   import java.io.StringReader;
   import java.util.List;
   import java.util.Set;
   
   /**
  - * A BasicSearchQuery represents the query and is able to deliver a
  - * SearchQueryResult using the execute method. It may serve as a base class for
  + * A BasicQuery represents the query and is able to deliver a
  + * SearchQueryResult using the execute method. It serves as a base class for
    * store specific implementations. It hosts the information about the SELECT,
    * FROM, WHERE, ORDERBY and LIMIT. It also holds a tree of
    * BasicSearchExpressions.
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
  - * @version $Revision: 1.8 $
  + * @version $Revision: 1.9 $
    */
  -public class BasicQuery extends SearchQuery {
  +public abstract class BasicQuery extends SearchQuery {
       
       /** all resources within the scope */
  -    private RequestedResourcesPool requestedResources;
  +    protected RequestedResourcesPool requestedResources;
       
       /** the element describing this query */
  -    private Element queryElement;
  +    protected Element queryElement;
       
       /** the namespace for this query */
  -    private Namespace namespace;
  +    protected Namespace namespace;
       
       /** the scope of this query, <FROM> */
  -    private QueryScope scope;
  +    protected QueryScope scope;
  +    
  +    /** the element describing the WHERE clauise */
  +    protected Element whereElement;
       
       /** List of requested properties, <SELECT> */
  -    private RequestedProperties requestedProperties;
  +    protected RequestedProperties requestedProperties;
       
       /** <LIMIT> */
  -    private int limit;
  +    protected int limit;
       
       /** ORDER BY */
  -    private OrderBy orderBy;
  +    protected OrderBy orderBy;
       
       /** indicates, if a limit is defined */
  -    private boolean limitDefined = false;
  +    protected boolean limitDefined = false;
       
       /** the top level expression in the <WHERE> clause */
  -    private BasicExpression rootExpression;
  +    protected BasicExpression rootExpression;
       
  -    private BasicExpressionFactory expressionFactory;
  -   
  -    /**
  -     * Constructs a query from the queryString. queryString is an XML
  -     * document according to the DASL basicsearch specfication.
  -     *
  -     * @parameter queryString the search query
  -     *
  -     * @throws BadQueryException
  -     */
  -    BasicQuery (String queryString, SearchToken token) throws BadQueryException {
  +    void setSearchToken (SearchToken token) {
           this.searchToken = token;
  -        try {
  -            Document doc =
  -                new SAXBuilder ().build (new StringReader (queryString));
  -            
  -            Element root = doc.getRootElement();
  -            parseQueryElement (root);
  -        }
  -        catch (Exception e) {
  -            e.printStackTrace();
  -            throw new BadQueryException (e.getMessage());
  -        }
       }
       
       /**
  -     * Constructs a query from queryElement. queryElement is a DOM
  -     * element <searchrequest> according to the DASL basicsearch
  -     * specfication.
  -     *
  -     * @parameter queryString the search query
  +     * builds the internal structure from the JDOM tree. Concrete implementations
  +     * may use parseQueryElementWithoutExpression to create most of the
  +     * objects describing the query.
        *
  -     * @throws BadQueryException
  -     */
  -    BasicQuery (org.w3c.dom.Element basicSearchElementDOM, SearchToken token)
  -        throws BadQueryException
  -    {
  -        this.searchToken = token;
  -        
  -        org.jdom.Element basicSearchElementJDom =
  -            new DOMBuilder ().build (basicSearchElementDOM);
  -        
  -        parseQueryElement (basicSearchElementJDom);
  -    }
  -    
  -    
  -    /**
  -     * Constructs a query from queryElement. queryElement is a DOM
  -     * element <searchrequest> according to the DASL basicsearch
  -     * specfication.
  -     *
  -     * @parameter queryString the search query
  +     * @param    basicSearchElement                an Element
        *
  -     * @throws BadQueryException
  +     * @throws   BadQueryException
        */
  -    BasicQuery (Element basicSearchElementJDOM, SearchToken token) throws 
BadQueryException {
  -        this.searchToken = token;
  -        parseQueryElement (basicSearchElementJDOM);
  -    }
  +    public abstract void parseQueryElement (Element basicSearchElement)
  +        throws BadQueryException;
       
       
       /**
  @@ -196,99 +152,18 @@
        * @throws   ServiceAccessException
        *
        */
  -    public SearchQueryResult execute () throws ServiceAccessException {
  -        SearchQueryResult result = null;
  -        
  -        try {
  -            requestedResources =
  -                new RequestedResourcesPoolImpl (searchToken, scope);
  -            
  -            Set pool = requestedResources.getPool ();
  -            rootExpression.resolve (pool);
  -            
  -            if (rootExpression.isResolved ()) {
  -                if (orderBy != null) {
  -                    result = new SearchQueryResult (rootExpression.getResultSet(),
  -                                                   orderBy.getComparator());
  -                }
  -                else {
  -                    result = new SearchQueryResult (rootExpression.getResultSet());
  -                }
  -                if (requestedResources.partialResult()) {
  -                    result.setStatus(SearchQueryResult.STATUS_PARTIAL_RESULT);
  -                    result.setDescription ("The server truncated the result set");
  -                }
  -            }
  -        }
  -        
  -        catch (InvalidScopeException e) {
  -            result = new SearchQueryResult ();
  -            result.setStatus (SearchQueryResult.STATUS_INVALID_SCOPE);
  -            result.setHref (scope.getHref());
  -        }
  -        
  -        catch (BadQueryException e) { // is this only INVALID_SCOPE?
  -            result = new SearchQueryResult ();
  -            result.setStatus (SearchQueryResult.STATUS_BAD_QUERY);
  -            result.setDescription (e.getMessage());
  -            result.setHref (scope.getHref());
  -        }
  -        finally  {
  -            return result;
  -        }
  -    }
  -    
  +    public abstract SearchQueryResult execute () throws ServiceAccessException;
       
       /**
  -     * QueryScope accessor
  -     *
  -     * @return   the Scope
  -     *
  -     */
  -    QueryScope getScope () {
  -        return scope;
  -    }
  -    
  -    /**
  -     * Method getSelectedProperties
  -     *
  -     * @return   a SelectedPropertyList
  -     */
  -    public RequestedProperties requestedProperties () {
  -        return requestedProperties;
  -    }
  -    
  -    BasicExpression getExpression () {
  -        return rootExpression;
  -    }
  -    
  -    
  -    /**
  -     * Method isLimitDefined
  -     *
  -     * @return true if <limit> was specified
  -     */
  -    boolean isLimitDefined () {
  -        return limitDefined;
  -    }
  -    
  -    /**
  -     * Method getLimit
  -     *
  -     * @return   the value of <limit>
  -     */
  -    int getLimit () {
  -        return limit;
  -    }
  -        
  -    /**
  -     * builds the internal structure from the JDOM tree
  +     * builds the internal structure from the JDOM tree. It may be used by the
  +     * concrete implementation of BasicQuery. It does NOT create the tree of
  +     * Expressions. This must be done in the specific implementation.
        *
        * @param    basicSearchElement                an Element
        *
        * @throws   BadQueryException
        */
  -    private void parseQueryElement (Element basicSearchElement)
  +    protected void parseQueryElementWithoutExpression (Element basicSearchElement)
           throws BadQueryException
       {
           if (basicSearchElement == null)
  @@ -307,10 +182,11 @@
               (Literals.FROM, namespace);
           
           // FROM is mandatory
  -        if (fromElement == null)
  +        if (fromElement == null) {
               throw new BadQueryException ("required element <from> not supplied");
  +        }
           
  -        Element whereElement = basicSearchElement.getChild
  +        whereElement = basicSearchElement.getChild
               (Literals.WHERE, namespace);
           
           Element orderByElement = basicSearchElement.getChild
  @@ -320,31 +196,22 @@
               (Literals.LIMIT, namespace);
           
           Element propElement = selectElement.getChild (Literals.PROP, namespace);
  -        if (propElement == null)
  +        if (propElement == null) {
               propElement = selectElement.getChild (Literals.ALLPROP, namespace);
  +        }
           
  -        if (propElement == null)
  -            throw new BadQueryException ("required element <prop> or <allprop> not 
supplied");
  +        if (propElement == null) {
  +            throw new BadQueryException
  +                ("required element <prop> or <allprop> not supplied");
  +        }
           
           requestedProperties = new RequestedPropertiesImpl (propElement);
           
           scope = new BasicQueryScope (fromElement);
           
  -        if (orderByElement != null)
  +        if (orderByElement != null) {
               orderBy = new OrderBy (orderByElement);
  -        
  -        BasicExpressionFactory expressionFactory
  -            = getExpressionFactory (scope);
  -        
  -        // <where> is not mandatory
  -        if (whereElement != null) {
  -            List expressionList = whereElement.getChildren();
  -            
  -            rootExpression = expressionFactory.createExpression
  -                ((Element) expressionList.get (0));
           }
  -        else
  -            rootExpression = expressionFactory.createExpression (null);
           
           if (limitElement != null) {
               limit = new Integer (limitElement.getTextTrim()).intValue();
  @@ -354,6 +221,54 @@
       
       
       /**
  +     * QueryScope accessor
  +     *
  +     * @return   the Scope
  +     *
  +     */
  +    QueryScope getScope () {
  +        return scope;
  +    }
  +    
  +    /**
  +     * Method getSelectedProperties
  +     *
  +     * @return   a SelectedPropertyList
  +     */
  +    public RequestedProperties requestedProperties () {
  +        return requestedProperties;
  +    }
  +    
  +    /**
  +     * Method getExpression
  +     *
  +     * @return   a BasicExpression
  +     *
  +     */
  +    BasicExpression getExpression () {
  +        return rootExpression;
  +    }
  +    
  +    
  +    /**
  +     * Method isLimitDefined
  +     *
  +     * @return true if <limit> was specified
  +     */
  +    boolean isLimitDefined () {
  +        return limitDefined;
  +    }
  +    
  +    /**
  +     * Method getLimit
  +     *
  +     * @return   the value of <limit>
  +     */
  +    int getLimit () {
  +        return limit;
  +    }
  +    
  +    /**
        * For debugging purpose.
        *
        * @return   this query in string representation
  @@ -368,39 +283,52 @@
           return result;
       }
       
  -    private BasicExpressionFactory getExpressionFactory (QueryScope scope) {
  -        BasicExpressionFactory result = null;
  -        
  -        String queryClass = "org.apache.slide.search.basic.BasicExpressionFactory";
  -
  -        // might be null in testsuite
  -        if (searchToken.getNamespace() != null) {
  -            Uri uri = new Uri (searchToken.getNamespace(), scope.getHref());
  -            AbstractStore store = (AbstractStore)uri.getStore();
  -            String s = (String) 
store.getParameter(BasicExpressionFactory.EXPRESSION_FACTORY);
  -            if (s != null)
  -                queryClass = s;
  -        }
  -        
  -        try {
  -            Class factoryClass = Class.forName (queryClass);
  -            result = (BasicExpressionFactory)factoryClass.newInstance();
  -        }
  -        catch (Exception e) {
  -            throw new SlideRuntimeException (e.getMessage());
  -        }
  -        
  -        return result;
  -    }
  -    
  -    
       // for testing
  +    /**
  +     * Method setPropertyResolver
  +     *
  +     * @param    propertyResolver    a  RequestedResourcesPool
  +     *
  +     */
       public void setPropertyResolver (RequestedResourcesPool propertyResolver) {
           this.requestedResources = propertyResolver;
       }
       
  +    /**
  +     * Method getPropertyResolver
  +     *
  +     * @return   a RequestedResourcesPool
  +     *
  +     */
       public RequestedResourcesPool getPropertyResolver() {
           return requestedResources;
  +    }
  +    
  +    /**
  +     * Needed to decide, which implementation of BasicQuery to load
  +     *
  +     * @param    basicSearchElementJDOMan Element
  +     *
  +     * @return   a QueryScope
  +     *
  +     * @throws   BadQueryException
  +     *
  +     */
  +    private static QueryScope getScope(Element basicSearchElementJDOM)
  +        throws BadQueryException
  +    {
  +        if (basicSearchElementJDOM == null)
  +            throw new BadQueryException ("No query element");
  +        
  +        Namespace namespace = basicSearchElementJDOM.getNamespace();
  +        Element fromElement = basicSearchElementJDOM.getChild
  +            (Literals.FROM, namespace);
  +        
  +        // FROM is mandatory
  +        if (fromElement == null)
  +            throw new BadQueryException ("required element <from> not supplied");
  +        
  +        return new BasicQueryScope (fromElement);
       }
   }
   
  
  
  
  1.7       +7 -7      
jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java
  
  Index: BasicSearchLanguage.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- BasicSearchLanguage.java  27 May 2002 08:17:13 -0000      1.6
  +++ BasicSearchLanguage.java  31 May 2002 12:23:24 -0000      1.7
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java,v
 1.6 2002/05/27 08:17:13 wam Exp $
  - * $Revision: 1.6 $
  - * $Date: 2002/05/27 08:17:13 $
  + * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicSearchLanguage.java,v
 1.7 2002/05/31 12:23:24 wam Exp $
  + * $Revision: 1.7 $
  + * $Date: 2002/05/31 12:23:24 $
    *
    * ====================================================================
    *
  @@ -74,7 +74,7 @@
    * Represent the BasicSearchLanguage for Slide
    *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
  - * @version $Revision: 1.6 $
  + * @version $Revision: 1.7 $
    */
   public class BasicSearchLanguage extends SearchLanguage {
       
  @@ -116,7 +116,7 @@
       public SearchQuery parseQuery (String queryString, SearchToken token)
           throws BadQueryException
       {
  -             BasicQuery query = new BasicQuery (queryString, token);
  +        BasicQuery query = BasicQueryFactory.newInstance (queryString, token);
           return query;
       }
       
  @@ -134,7 +134,7 @@
       public SearchQuery parseQuery (Element basicSearchElement, SearchToken token)
           throws BadQueryException
       {
  -        BasicQuery query = new BasicQuery (basicSearchElement, token);
  +        BasicQuery query = BasicQueryFactory.newInstance (basicSearchElement, 
token);
           return query;
       }
   
  @@ -152,7 +152,7 @@
       public SearchQuery parseQuery (org.jdom.Element basicSearchElement, SearchToken 
token)
           throws BadQueryException
       {
  -             BasicQuery query = new BasicQuery (basicSearchElement, token);
  +        BasicQuery query = BasicQueryFactory.newInstance (basicSearchElement, 
token);
           return query;
       }
   }
  
  
  
  1.1                  
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryFactory.java
  
  Index: BasicQueryFactory.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryFactory.java,v
 1.1 2002/05/31 12:23:23 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/05/31 12:23:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. 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.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Slide", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS 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.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.slide.search.basic;
  
  import org.apache.slide.search.SearchToken;
  import org.apache.slide.search.QueryScope;
  import org.apache.slide.search.SearchQuery;
  import org.apache.slide.search.BadQueryException;
  import org.apache.slide.search.SearchQueryResult;
  import org.apache.slide.common.ServiceAccessException;
  import org.apache.slide.common.SlideRuntimeException;
  import org.apache.slide.common.RequestedProperties;
  import org.apache.slide.common.RequestedPropertiesImpl;
  import org.apache.slide.common.Uri;
  import org.apache.slide.store.AbstractStore;
  import org.jdom.input.DOMBuilder;
  import org.jdom.input.SAXBuilder;
  import org.jdom.Namespace;
  import org.jdom.Element;
  import org.jdom.Document;
  
  import java.io.StringReader;
  import java.util.List;
  import java.util.Set;
  
  /**
   * Serves as a factory for store specific implementations of BasicQuery. If the
   * parameter "basicQueryClass" is set in the store used for the scope of this
   * query, the specified class is loaded. If not specified, the default
   * implementaion is used. The loaded class MUST override the abstract class
   * BasicQuery.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
   * @version $Revision: 1.1 $
   */
  public abstract class BasicQueryFactory {
      
      /** BasicSearch class */
      private static final String BASIC_QUERY_CLASS = "basicQueryClass";
      
      private static final String DEFAULT_QUERY_CLASS =
          "org.apache.slide.search.basic.BasicQueryImpl";
      
      /**
       * Factory method to create a BasicQuery instance
       *
       * @param    basicSearchElementJDOM describes the query
       * @param    token                  the  SearchToken
       *
       * @return   a BasicQuery
       *
       * @throws   BadQueryException
       *
       */
      public static BasicQuery newInstance
          (Element basicSearchElementJDOM, SearchToken token)
          throws BadQueryException
      {
          return createQuery (basicSearchElementJDOM, token);
      }
      
      
      // sollte wegschmeissable sein
      /**
       * Method newInstance
       *
       * @param    basicSearchElementDOMan Element
       * @param    token               a  SearchToken
       *
       * @return   a BasicQuery
       *
       * @throws   BadQueryException
       *
       */
      public static BasicQuery newInstance
          (org.w3c.dom.Element basicSearchElementDOM, SearchToken token)
          throws BadQueryException
      {
          org.jdom.Element basicSearchElementJDom =
              new DOMBuilder ().build (basicSearchElementDOM);
          return createQuery (basicSearchElementJDom, token);
      }
      
      
      /**
       * Method newInstance
       *
       * @param    queryString         describes the query
       * @param    token               the SearchToken
       *
       * @return   a BasicQuery
       *
       * @throws   BadQueryException
       *
       */
      public static BasicQuery newInstance
          (String queryString, SearchToken token) throws BadQueryException
      {
          try {
              Document doc =
                  new SAXBuilder ().build (new StringReader (queryString));
              
              Element root = doc.getRootElement();
              return createQuery (root, token);
          }
          catch (Exception e) {
              e.printStackTrace();
              throw new BadQueryException (e.getMessage());
          }
      }
      
      private static BasicQuery createQuery (Element basicSearchElementJDOM, 
SearchToken token)
          throws BadQueryException
      {
          BasicQuery result = getBasicQueryInstance (getScope 
(basicSearchElementJDOM), token);
          result.setSearchToken (token);
          result.parseQueryElement(basicSearchElementJDOM);
          return result;
      }
      
      /**
       * Needed to decide, which implementation of BasicQuery to load
       *
       * @param    basicSearchElementJDOMan Element
       *
       * @return   a QueryScope
       *
       * @throws   BadQueryException
       *
       */
      private static QueryScope getScope(Element basicSearchElementJDOM) throws 
BadQueryException
      {
          if (basicSearchElementJDOM == null)
              throw new BadQueryException ("No query element");
          
          Namespace namespace = basicSearchElementJDOM.getNamespace();
          Element fromElement = basicSearchElementJDOM.getChild
              (Literals.FROM, namespace);
          
          // FROM is mandatory
          if (fromElement == null)
              throw new BadQueryException ("required element <from> not supplied");
          
          return new BasicQueryScope (fromElement);
      }
      
      /**
       * Instantiates a store specific BasicQuery. If the store-parameter
       * "basicQueryClass" is set (via Domain.xml or hard coded), the specified
       * class is loaded.
       *
       * @param    scope               a  QueryScope
       * @param    searchToken         a  SearchToken
       *
       * @return   a BasicQuery
       *
       */
      private static BasicQuery getBasicQueryInstance (QueryScope scope, SearchToken 
searchToken) {
          BasicQuery result = null;
          
          String className = DEFAULT_QUERY_CLASS;
          
          // might be null in testsuite
          if (searchToken.getNamespace() != null) {
              Uri uri = new Uri (searchToken.getNamespace(), scope.getHref());
              AbstractStore store = (AbstractStore)uri.getStore();
              String s = (String) store.getParameter(BASIC_QUERY_CLASS);
              if (s != null)
                  className = s;
          }
          
          try {
              Class factoryClass = Class.forName (className);
              result = (BasicQuery) factoryClass.newInstance();
          }
          catch (Exception e) {
              e.printStackTrace();
              throw new SlideRuntimeException (e.getMessage());
          }
          
          return result;
      }
  }
  
  
  
  
  1.1                  
jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryImpl.java
  
  Index: BasicQueryImpl.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-slide/src/share/org/apache/slide/search/basic/BasicQueryImpl.java,v 
1.1 2002/05/31 12:23:23 wam Exp $
   * $Revision: 1.1 $
   * $Date: 2002/05/31 12:23:23 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. 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.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Slide", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS 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.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package org.apache.slide.search.basic;
  import org.apache.slide.search.*;
  
  import org.apache.slide.search.SearchQuery;
  import org.apache.slide.search.SearchException;
  import org.apache.slide.search.BadQueryException;
  import org.apache.slide.search.SearchQueryResult;
  import org.apache.slide.common.ServiceAccessException;
  import org.apache.slide.common.SlideRuntimeException;
  import org.apache.slide.common.RequestedProperties;
  import org.apache.slide.common.RequestedPropertiesImpl;
  import org.apache.slide.common.Uri;
  import org.apache.slide.store.AbstractStore;
  import org.jdom.input.DOMBuilder;
  import org.jdom.input.SAXBuilder;
  import org.jdom.Namespace;
  import org.jdom.Element;
  import org.jdom.Document;
  import org.xml.sax.InputSource;
  
  //import org.apache.slide.common.SlideToken;
  
  import java.io.StringReader;
  import java.util.List;
  import java.util.Set;
  
  /**
   * BasicQueryImpl represents the generic (store independent) implementation of
   * BasicSearch.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Martin Wallmer</a>
   * @version $Revision: 1.1 $
   */
  public class BasicQueryImpl extends BasicQuery {
      
      /**
       * Executes a request.
       *
       * @return   a SearchQueryResult
       *
       * @throws   ServiceAccessException
       *
       */
      public SearchQueryResult execute () throws ServiceAccessException {
          SearchQueryResult result = null;
          
          try {
              requestedResources =
                  new RequestedResourcesPoolImpl (searchToken, scope);
              
              Set pool = requestedResources.getPool ();
              rootExpression.resolve (pool);
              
              if (rootExpression.isResolved ()) {
                  if (orderBy != null) {
                      result = new SearchQueryResult (rootExpression.getResultSet(),
                                                      orderBy.getComparator());
                  }
                  else {
                      result = new SearchQueryResult (rootExpression.getResultSet());
                  }
                  if (requestedResources.partialResult()) {
                      result.setStatus(SearchQueryResult.STATUS_PARTIAL_RESULT);
                      result.setDescription ("The server truncated the result set");
                  }
              }
          }
          
          catch (InvalidScopeException e) {
              result = new SearchQueryResult ();
              result.setStatus (SearchQueryResult.STATUS_INVALID_SCOPE);
              result.setHref (scope.getHref());
          }
          
          catch (BadQueryException e) { // is this only INVALID_SCOPE?
              result = new SearchQueryResult ();
              result.setStatus (SearchQueryResult.STATUS_BAD_QUERY);
              result.setDescription (e.getMessage());
              result.setHref (scope.getHref());
          }
          finally  {
              return result;
          }
      }
      /**
       * builds the internal structure from the JDOM tree
       *
       * @param    basicSearchElement                an Element
       *
       * @throws   BadQueryException
       */
      public void parseQueryElement (Element basicSearchElement)
          throws BadQueryException
      {
          parseQueryElementWithoutExpression (basicSearchElement);
          BasicExpressionFactory expressionFactory = new BasicExpressionFactory ();
          
          // <where> is not mandatory
          if (whereElement != null) {
              List expressionList = whereElement.getChildren();
              
              rootExpression = expressionFactory.createExpression
                  ((Element) expressionList.get (0));
          }
          else
              rootExpression = expressionFactory.createExpression (null);
      }
  }
  
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to