Package org.apache.muse.ws.resource.properties.query.impl

Source Code of org.apache.muse.ws.resource.properties.query.impl.SimpleQueryCapability

/*=============================================================================*
*  Copyright 2006 The Apache Software Foundation
*
*  Licensed 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.muse.ws.resource.properties.query.impl;

import java.lang.reflect.Method;
import java.util.Collection;

import javax.xml.namespace.QName;

import org.w3c.dom.Element;
import org.w3c.dom.Node;

import org.apache.muse.core.routing.MessageHandler;
import org.apache.muse.util.ReflectUtils;
import org.apache.muse.util.messages.Messages;
import org.apache.muse.util.messages.MessagesFactory;
import org.apache.muse.ws.addressing.soap.SoapFault;
import org.apache.muse.ws.resource.basefaults.BaseFault;
import org.apache.muse.ws.resource.impl.AbstractWsResourceCapability;
import org.apache.muse.ws.resource.properties.ResourcePropertyCollection;
import org.apache.muse.ws.resource.properties.query.QueryCapability;
import org.apache.muse.ws.resource.properties.query.QueryExpression;
import org.apache.muse.ws.resource.properties.query.QueryExpressionFactory;
import org.apache.muse.ws.resource.properties.query.faults.InvalidQueryExpressionFault;
import org.apache.muse.ws.resource.properties.query.faults.QueryEvaluationErrorFault;
import org.apache.muse.ws.resource.properties.query.faults.UnknownQueryExpressionDialectFault;

/**
*
* SimpleQueryCapability is Muse's default implementation of the WS-RP
* QueryResourceProperties port type. It uses an implementation of the
* QueryExpressionFactory component that supports XPath 1.0; users can
* augment the list of supported capabilities by providing an alternate
* implementation class for this factory (see the documentation of the
* createQueryExpressionFactory() method).
*
* @author Dan Jemiolo (danj)
*
*/

public class SimpleQueryCapability
    extends AbstractWsResourceCapability implements QueryCapability
{
    //
    // Used to lookup all exception messages
    //
    private static Messages _MESSAGES = MessagesFactory.get(SimpleQueryCapability.class);
   
    private QueryExpressionFactory _factory = null;
   
    /**
     *
     * Users can override this method to provide alternative implementations
     * of QueryExpressionFactory that support other dialects.
     *
     * @return An instance of XPathQueryExpressionFactory.
     *
     */
    protected QueryExpressionFactory createQueryExpressionFactory()
    {
        return new XPathQueryExpressionFactory();
    }
   
    protected MessageHandler createQueryHandler()
    {
        MessageHandler handler = new QueryHandler();
       
        Method method = ReflectUtils.getFirstMethod(getClass(), "queryResourceProperties");
        handler.setMethod(method);
       
        return handler;
    }
   
    public QName[] getPropertyNames()
    {
        return PROPERTIES;
    }
   
    public String[] getQueryExpressionDialect()
    {
        Collection dialects = _factory.getDialects();
        return (String[])dialects.toArray(new String[dialects.size()]);
    }
   
    protected QueryExpressionFactory getQueryExpressionFactory()
    {
        return _factory;
    }
   
    public void initialize()
        throws SoapFault
    {
        super.initialize();
       
        _factory = createQueryExpressionFactory();
       
        setMessageHandler(createQueryHandler());
    }
   
    public Node[] queryResourceProperties(String query, String dialect)
        throws UnknownQueryExpressionDialectFault,
               InvalidQueryExpressionFault,
               QueryEvaluationErrorFault,
               BaseFault
    {
        if (query == null)
            throw new NullPointerException(_MESSAGES.get("NullQuery"));
       
        //
        // get a copy of the whole ws-rp doc that we can evaluate against
        //
        ResourcePropertyCollection props = getWsResource().getPropertyCollection();
        Element wsrpDoc = props.getResourcePropertyDocument();
       
        QueryExpressionFactory factory = getQueryExpressionFactory();
        QueryExpression evaluator = factory.newInstance(dialect);
       
        return evaluator.evaluate(wsrpDoc, query);
    }
   
    protected void setQueryExpressionFactory(QueryExpressionFactory factory)
    {
        _factory = factory;
    }
}
TOP

Related Classes of org.apache.muse.ws.resource.properties.query.impl.SimpleQueryCapability

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.