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

Source Code of org.apache.ws.resource.properties.v2004_11.porttype.impl.QueryResourcePropertiesPortTypeImpl

/*=============================================================================*
*  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.v2004_11.porttype.impl;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.resource.NamespaceVersionHolder;
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.impl.AbstractResourcePropertiesPortType;
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.v2004_11.impl.NamespaceVersionHolderImpl;
import org.apache.ws.resource.properties.v2004_11.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.x11.wsrfWSResourceProperties12Draft05.QueryExpressionType;
import org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryResourcePropertiesDocument;
import org.oasisOpen.docs.wsrf.x2004.x11.wsrfWSResourceProperties12Draft05.QueryResourcePropertiesResponseDocument;
import java.lang.reflect.Array;

/**
* LOG-DONE An operation provider for wsrp:QueryResourceProperties.
*
* TODO (v1.1): factor out a common base class to be shared across spec versions
*
* @author Ian P. Springer
*/
public class QueryResourcePropertiesPortTypeImpl
   extends AbstractResourcePropertiesPortType
   implements QueryResourcePropertiesPortType
{
   private static final Log                    LOG =
      LogFactory.getLog( QueryResourcePropertiesPortTypeImpl.class );
   private static final Messages               MSG           = MessagesImpl.getInstance(  );
   private static final NamespaceVersionHolder NAMESPACE_SET = new NamespaceVersionHolderImpl(  );
   private static final QueryEngine            QUERY_ENGINE  = new QueryEngineImpl(  );

   /**
    * Creates a new {@link QueryResourcePropertiesPortTypeImpl} object.
    *
    * @param resourceContext DOCUMENT_ME
    */
   public QueryResourcePropertiesPortTypeImpl( 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.ResourceKeyHeaderNotFoundFaultException
    *
    * @throws UnknownQueryExpressionDialectFaultException
    *          if query dialect is unsupported.
    * @throws QueryEvaluationErrorFaultException
    *          if query evaluation fails.
    * @throws 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                     queryExprType =
         requestDoc.getQueryResourceProperties(  ).getQueryExpression(  );
      XmlBeansQueryExpression                 queryExpr = new XmlBeansQueryExpression( queryExprType );
      refreshAllProperties(  );
      Object result = null;
      try
      {
         result = QUERY_ENGINE.executeQuery( queryExpr,
                                             getProperties(  ) );
      }
      catch ( UnknownQueryExpressionDialectException uqede )
      {
         throw new UnknownQueryExpressionDialectFaultException( NAMESPACE_SET,
                                                                uqede.getDialect(  ) );
      }
      catch ( QueryEvaluationErrorException qeee )
      {
         throw new QueryEvaluationErrorFaultException( NAMESPACE_SET,
                                                       qeee.getMessage(  ) );
      }
      catch ( InvalidQueryExpressionException iqee )
      {
         throw new InvalidQueryExpressionFaultException( NAMESPACE_SET, 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 RuntimeException( "Unable to convert query result object to XmlObject.", e );
            }

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

      return responseDoc;
   }

   /**
    * DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    */
   protected NamespaceVersionHolder getNamespaceSet(  )
   {
      return NAMESPACE_SET;
   }

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

Related Classes of org.apache.ws.resource.properties.v2004_11.porttype.impl.QueryResourcePropertiesPortTypeImpl

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.