Save This Page
Home » axis2-1.5-src » org.apache » axis2 » dataretrieval » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements. See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership. The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License. You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied. See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.
   18    */
   19   
   20   package org.apache.axis2.dataretrieval;
   21   
   22   import org.apache.axiom.om.OMElement;
   23   import org.apache.axis2.context.MessageContext;
   24   import org.apache.axis2.description.AxisService;
   25   import org.apache.axis2.description.AxisService2WSDL11;
   26   import org.apache.commons.logging.Log;
   27   import org.apache.commons.logging.LogFactory;
   28   
   29   /**
   30    * Axis 2 Data Locator responsibles for retrieving WSDL metadata.
   31    */
   32   public class WSDLDataLocator extends BaseAxisDataLocator implements AxisDataLocator {
   33       private static final Log log = LogFactory.getLog(WSDLDataLocator.class);
   34       String serviceURL = null;
   35       AxisService theService = null;
   36       String request_Identifier = null;
   37   
   38       protected WSDLDataLocator() {
   39       }
   40   
   41       /**
   42        * Constructor
   43        *
   44        * @param data an array of ServiceData instance defined in the
   45        *             ServiceData.xml for the WSDL dialect.
   46        */
   47       protected WSDLDataLocator(ServiceData[] data) {
   48           dataList = data;
   49       }
   50   
   51       /**
   52        * getData API
   53        * Implement data retrieval logic for WSDL dialect
   54        */
   55       public Data[] getData(DataRetrievalRequest request,
   56                             MessageContext msgContext) throws DataRetrievalException {
   57           log.trace("Default WSDL DataLocator getData starts");
   58   
   59           request_Identifier = request.getIdentifier();
   60           serviceURL = msgContext.getTo().getAddress();
   61   
   62           OutputForm outputform = request.getOutputForm();
   63   
   64           if (outputform == null) { // not defined, defualt to inline
   65               outputform = OutputForm.INLINE_FORM;
   66           }
   67   
   68           Data[] output;
   69   
   70           String outputFormString = outputform.getType();
   71   
   72           if (outputform == OutputForm.INLINE_FORM) {
   73               output = outputInlineForm(msgContext, dataList);
   74           } else if (outputform == OutputForm.LOCATION_FORM) {
   75               output = outputLocationForm(dataList);
   76   
   77           } else if (outputform == OutputForm.REFERENCE_FORM) {
   78               output = outputReferenceForm(msgContext, dataList);
   79   
   80           } else {
   81               output = outputInlineForm(msgContext, dataList);
   82   
   83           }
   84   
   85           if (output == null) {
   86               if (log.isTraceEnabled()) {
   87                   log.trace(
   88                           "Null data return! Data Locator does not know how to handle request for dialect= " +
   89                                   request.getDialect() + " in the form of " + outputFormString);
   90               }
   91           }
   92   
   93   
   94           log.trace("Default WSDL DataLocator getData ends");
   95   
   96   
   97           return output;
   98       }
   99   
  100       /*
  101        * (non-Javadoc)
  102        * @see org.apache.axis2.dataretrieval.BaseAxisDataLocator#outputInlineForm(org.apache.axis2.context.MessageContext, org.apache.axis2.dataretrieval.ServiceData[])
  103        */
  104       protected Data[] outputInlineForm(MessageContext msgContext, ServiceData[] dataList)
  105               throws DataRetrievalException {
  106           Data[]  result = super.outputInlineForm(msgContext, dataList);
  107   
  108           // Do not generate WSDL if Identifier was specified in the request as
  109           // (1) this is to support ?wsdl request; 
  110           // (2) Data for specified Identifier must be available to satisfy the GetMetadata request.
  111   
  112           if (result.length == 0) {
  113               
  114               log.trace("Default WSDL DataLocator attempt to generates WSDL.");
  115   
  116               if (msgContext != null) {
  117                   theService = msgContext.getAxisService();
  118                   serviceURL = msgContext.getTo().getAddress();
  119                   theService.setEndpointURL(serviceURL);
  120               } else {
  121                   throw new DataRetrievalException("MessageContext was not set!");
  122               }
  123   
  124               if (request_Identifier == null || request_Identifier.equals(theService.getTargetNamespace())) {
  125   
  126                   AxisService2WSDL11 axisService2WOM;
  127                   OMElement wsdlElement;
  128   
  129                   try {
  130                       axisService2WOM = new AxisService2WSDL11(theService);
  131                       wsdlElement = axisService2WOM.generateOM();
  132                       
  133                   } catch (Exception e) {
  134                       log.debug(e);
  135                       throw new DataRetrievalException(e);
  136                   }
  137   
  138                   if (wsdlElement != null) {
  139                       log.trace("Default WSDL DataLocator successfully generated WSDL.");
  140                       result = new Data[1];
  141                       result[0] = new Data(wsdlElement, null);
  142                   }
  143               }
  144           }
  145           
  146           return result;
  147       }
  148   
  149       /*
  150        * 
  151        */
  152       protected Data[] outputLocationForm(ServiceData[] serviceData) throws DataRetrievalException {
  153           Data[] result = super.outputLocationForm(serviceData);
  154   
  155           // Do not generate URL if Identifier was specified in the request as
  156           // (1) Axis2 ?wsdl URL request is not supporting Identifier; 
  157           // (2) URL data for specified Identifier must be available to satisfy
  158           //     the GetMetadata request.
  159   
  160           if (result.length == 0 && request_Identifier == null) {
  161               result = new Data[1];
  162               result[0] = new Data(serviceURL + "?wsdl", null);
  163           }
  164           return result;
  165       }
  166   
  167   
  168   }

Save This Page
Home » axis2-1.5-src » org.apache » axis2 » dataretrieval » [javadoc | source]