Package org.apache.ws.resource.properties.v1_2.porttype.impl

Source Code of org.apache.ws.resource.properties.v1_2.porttype.impl.QueryResourcePropertiesProvider

/*=============================================================================*
*  Copyright 2004 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.ws.resource.properties.v1_2.porttype.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.i18n.Keys;
import org.apache.ws.resource.i18n.MessagesImpl;
import org.apache.ws.resource.properties.faults.InvalidQueryExpressionFaultException;
import org.apache.ws.resource.properties.faults.QueryEvaluationErrorFaultException;
import org.apache.ws.resource.properties.faults.UnknownQueryExpressionDialectFaultException;
import org.apache.ws.resource.properties.query.InvalidQueryExpressionException;
import org.apache.ws.resource.properties.query.QueryEngine;
import org.apache.ws.resource.properties.query.QueryEvaluationErrorException;
import org.apache.ws.resource.properties.query.UnknownQueryExpressionDialectException;
import org.apache.ws.resource.properties.query.impl.QueryEngineImpl;
import org.apache.ws.resource.properties.query.impl.XmlBeansQueryExpression;
import org.apache.ws.resource.properties.v1_2.porttype.QueryResourcePropertiesPortType;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.ws.util.i18n.Messages;
import org.apache.xmlbeans.XmlObject;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryExpressionType;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x06.wsrfWSResourceProperties12Draft01.QueryResourcePropertiesResponseDocument;

import javax.xml.rpc.JAXRPCException;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;
import java.lang.reflect.Array;

/**
* LOG-DONE An operation provider for wsrp:QueryResourceProperties.
*
* @author Ian P. Springer
*/
public class QueryResourcePropertiesProvider
        extends AbstractResourcePropertiesPortType
        implements QueryResourcePropertiesPortType
{

    private static final Log LOG = LogFactory.getLog( QueryResourcePropertiesProvider.class );
    private static final Messages MSG = MessagesImpl.getInstance();

    /**
     * DOCUMENT_ME
     */
    private static final QueryEngine QUERY_ENGINE = new QueryEngineImpl();

    /**
     * Creates a new {@link QueryResourcePropertiesProvider} object.
     *
     * @param resourceContext DOCUMENT_ME
     */
    public QueryResourcePropertiesProvider( ResourceContext resourceContext )
    {
        super( resourceContext );
    }

    /**
     * Implementation of the wsrp:QueryResourceProperties operation.
     *
     * @param requestDoc the requestDoc XMLBean
     *
     * @return the response XMLBean
     *
     * @throws org.apache.ws.resource.faults.ResoureKeyHeaderNotFoundFaultException
     *
     * @throws org.apache.ws.resource.properties.faults.UnknownQueryExpressionDialectFaultException
     *          if query dialect is unsupported.
     * @throws org.apache.ws.resource.properties.faults.QueryEvaluationErrorFaultException
     *          if query evaluation fails.
     * @throws org.apache.ws.resource.properties.faults.InvalidQueryExpressionFaultException
     *          if query expression is invalid.
     */
    public QueryResourcePropertiesResponseDocument queryResourceProperties( QueryResourcePropertiesDocument requestDoc )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( MSG.getMessage( Keys.QUERY_RP_REQ,
                    requestDoc.toString() ) );
        }

        QueryResourcePropertiesResponseDocument responseDoc = createResponseDocument();
        QueryExpressionType queryExprElem =
                requestDoc.getQueryResourceProperties().getQueryExpression();
        SOAPEnvelope envelope;
        try
        {
            envelope = getResourceContext().getSOAPMessage().getSOAPPart().getEnvelope();
        }
        catch ( SOAPException soape )
        {
            throw new JAXRPCException( MSG.getMessage( Keys.FAILED_TO_EXTRACT_SOAP_ENV, soape ) );
        }

        XmlBeansQueryExpression queryExpr = new XmlBeansQueryExpression( queryExprElem );

        refreshAllProperties();
        Object result = null;
        try
        {
            result = QUERY_ENGINE.executeQuery( queryExpr,
                    getProperties(),
                    envelope );
        }
        catch ( UnknownQueryExpressionDialectException uqede )
        {
            throw new UnknownQueryExpressionDialectFaultException( uqede.getDialect() );
        }
        catch ( QueryEvaluationErrorException qeee )
        {
            throw new QueryEvaluationErrorFaultException( qeee.getMessage() );
        }
        catch ( InvalidQueryExpressionException iqee )
        {
            throw new InvalidQueryExpressionFaultException( queryExpr );
        }

        QueryResourcePropertiesResponseDocument.QueryResourcePropertiesResponse responseElem =
                responseDoc.getQueryResourcePropertiesResponse();
        if ( result.getClass().isArray() )
        {
            for ( int i = 0; i < Array.getLength( result ); i++ )
            {
                Object resultItem = Array.get( result, i );
                XmlObject resultXBean = null;
                try
                {
                    resultXBean = XmlBeanUtils.toXmlObject( resultItem );
                }
                catch ( Exception e )
                {
                    throw new JAXRPCException( e );
                }

                XmlBeanUtils.addChildElement( responseElem, resultXBean );
            }
        }
        else
        {
            XmlBeanUtils.setValue( responseElem,
                    result.toString() );
        }

        return responseDoc;
    }

    private QueryResourcePropertiesResponseDocument createResponseDocument()
    {
        QueryResourcePropertiesResponseDocument responseDoc =
                QueryResourcePropertiesResponseDocument.Factory.newInstance();
        responseDoc.addNewQueryResourcePropertiesResponse();
        return responseDoc;
    }
}
TOP

Related Classes of org.apache.ws.resource.properties.v1_2.porttype.impl.QueryResourcePropertiesProvider

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.