001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.dataretrieval;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axis2.context.MessageContext;
024: import org.apache.axis2.description.AxisService;
025: import org.apache.axis2.description.AxisService2WSDL11;
026: import org.apache.axis2.AxisFault;
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: /**
031: * Axis 2 Data Locator responsibles for retrieving WSDL metadata.
032: */
033: public class WSDLDataLocator extends BaseAxisDataLocator implements
034: AxisDataLocator {
035: private static final Log log = LogFactory
036: .getLog(WSDLDataLocator.class);
037: String serviceURL = null;
038: AxisService theService = null;
039: String request_Identifier = null;
040:
041: protected WSDLDataLocator() {
042: }
043:
044: /**
045: * Constructor
046: *
047: * @param data an array of ServiceData instance defined in the
048: * ServiceData.xml for the WSDL dialect.
049: */
050: protected WSDLDataLocator(ServiceData[] data) {
051: dataList = data;
052: }
053:
054: /**
055: * getData API
056: * Implement data retrieval logic for WSDL dialect
057: */
058: public Data[] getData(DataRetrievalRequest request,
059: MessageContext msgContext) throws DataRetrievalException {
060: log.trace("Default WSDL DataLocator getData starts");
061:
062: request_Identifier = request.getIdentifier();
063: serviceURL = msgContext.getTo().getAddress();
064:
065: OutputForm outputform = request.getOutputForm();
066:
067: if (outputform == null) { // not defined, defualt to inline
068: outputform = OutputForm.INLINE_FORM;
069: }
070:
071: Data[] output;
072:
073: String outputFormString = outputform.getType();
074:
075: if (outputform == OutputForm.INLINE_FORM) {
076: output = outputInlineForm(msgContext, dataList);
077: } else if (outputform == OutputForm.LOCATION_FORM) {
078: output = outputLocationForm(dataList);
079:
080: } else if (outputform == OutputForm.REFERENCE_FORM) {
081: output = outputReferenceForm(msgContext, dataList);
082:
083: } else {
084: output = outputInlineForm(msgContext, dataList);
085:
086: }
087:
088: if (output == null) {
089: if (log.isTraceEnabled()) {
090: log
091: .trace("Null data return! Data Locator does not know how to handle request for dialect= "
092: + request.getDialect()
093: + " in the form of " + outputFormString);
094: }
095: }
096:
097: log.trace("Default WSDL DataLocator getData ends");
098:
099: return output;
100: }
101:
102: /*
103: * (non-Javadoc)
104: * @see org.apache.axis2.dataretrieval.BaseAxisDataLocator#outputInlineForm(org.apache.axis2.context.MessageContext, org.apache.axis2.dataretrieval.ServiceData[])
105: */
106: protected Data[] outputInlineForm(MessageContext msgContext,
107: ServiceData[] dataList) throws DataRetrievalException {
108: Data[] result = super .outputInlineForm(msgContext, dataList);
109:
110: // Do not generate WSDL if Identifier was specified in the request as
111: // (1) this is to support ?wsdl request;
112: // (2) Data for specified Identifier must be available to satisfy the GetMetadata request.
113:
114: if (result.length == 0) {
115:
116: log
117: .trace("Default WSDL DataLocator attempt to generates WSDL.");
118:
119: if (msgContext != null) {
120: theService = msgContext.getAxisService();
121: serviceURL = msgContext.getTo().getAddress();
122: } else {
123: throw new DataRetrievalException(
124: "MessageContext was not set!");
125: }
126:
127: if (request_Identifier == null
128: || request_Identifier.equals(theService
129: .getTargetNamespace())) {
130:
131: AxisService2WSDL11 axisService2WOM;
132: OMElement wsdlElement;
133:
134: try {
135: axisService2WOM = new AxisService2WSDL11(theService);
136: wsdlElement = axisService2WOM.generateOM();
137:
138: } catch (Exception e) {
139: log.debug(e);
140: throw new DataRetrievalException(e);
141: }
142:
143: if (wsdlElement != null) {
144: log
145: .trace("Default WSDL DataLocator successfully generated WSDL.");
146: result = new Data[1];
147: result[0] = new Data(wsdlElement, null);
148: }
149: }
150: }
151:
152: return result;
153: }
154:
155: /*
156: *
157: */
158: protected Data[] outputLocationForm(ServiceData[] serviceData)
159: throws DataRetrievalException {
160: Data[] result = super .outputLocationForm(serviceData);
161:
162: // Do not generate URL if Identifier was specified in the request as
163: // (1) Axis2 ?wsdl URL request is not supporting Identifier;
164: // (2) URL data for specified Identifier must be available to satisfy
165: // the GetMetadata request.
166:
167: if (result.length == 0 && request_Identifier == null) {
168: result = new Data[1];
169: result[0] = new Data(serviceURL + "?wsdl", null);
170: }
171: return result;
172: }
173:
174: }
|