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.wsdl.util;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import javax.wsdl.Definition;
026: import javax.wsdl.Import;
027: import javax.wsdl.Types;
028: import javax.wsdl.PortType;
029: import javax.wsdl.extensions.ExtensibilityElement;
030: import java.util.*;
031:
032: /**
033: * This class provides support for processing a WSDL4J defintion which includes imports.
034: * It allows the imports to be processed into a single WSDL4J Definition object
035: */
036: public class WSDL4JImportedWSDLHelper {
037:
038: protected static final Log log = LogFactory
039: .getLog(WSDL4JImportedWSDLHelper.class);
040: private static final boolean isTraceEnabled = log.isTraceEnabled();
041:
042: /**
043: * The intention of this procedure is to process the imports. When
044: * processing the imports the imported documents will be populating the
045: * items in the main document recursivley
046: *
047: * @param wsdl4JDefinition
048: */
049: public static void processImports(Definition wsdl4JDefinition,
050: List processedDocuments) {
051:
052: Map wsdlImports = wsdl4JDefinition.getImports();
053:
054: if (null != wsdlImports && !wsdlImports.isEmpty()) {
055: Collection importsCollection = wsdlImports.values();
056: for (Iterator iterator = importsCollection.iterator(); iterator
057: .hasNext();) {
058: Vector values = (Vector) iterator.next();
059: for (int i = 0; i < values.size(); i++) {
060: Import wsdlImport = (Import) values.elementAt(i);
061:
062: if (wsdlImport.getDefinition() != null) {
063: Definition importedDef = wsdlImport
064: .getDefinition();
065:
066: if (importedDef != null) {
067: String key = importedDef
068: .getDocumentBaseURI();
069: if (key == null) {
070: key = importedDef.getTargetNamespace();
071: }
072: // stop recursive imports!
073: if (processedDocuments.contains(key)) {
074: return;
075: }
076: processedDocuments.add(key);
077:
078: processImports(importedDef,
079: processedDocuments);
080:
081: // copy ns
082: Map namespaces = importedDef
083: .getNamespaces();
084: Iterator keys = namespaces.keySet()
085: .iterator();
086: while (keys.hasNext()) {
087: Object key2 = keys.next();
088: if (!wsdl4JDefinition.getNamespaces()
089: .containsValue(
090: namespaces.get(key2))) {
091: wsdl4JDefinition.getNamespaces()
092: .put(
093: key2,
094: namespaces
095: .get(key2));
096: }
097: }
098:
099: wsdl4JDefinition.getNamespaces().putAll(
100: namespaces);
101: // copy types
102: Types t = importedDef.getTypes();
103: if (t != null) {
104: List typesList = t
105: .getExtensibilityElements();
106: for (int j = 0; j < typesList.size(); j++) {
107: Types types = wsdl4JDefinition
108: .getTypes();
109: if (types == null) {
110: types = wsdl4JDefinition
111: .createTypes();
112: wsdl4JDefinition
113: .setTypes(types);
114: }
115: types
116: .addExtensibilityElement((ExtensibilityElement) typesList
117: .get(j));
118:
119: }
120: }
121:
122: // add messages
123: Map messagesMap = importedDef.getMessages();
124: wsdl4JDefinition.getMessages().putAll(
125: messagesMap);
126:
127: // add portypes
128: Map porttypeMap = importedDef
129: .getPortTypes();
130: wsdl4JDefinition.getPortTypes().putAll(
131: porttypeMap);
132:
133: // add bindings
134: Map bindingMap = importedDef.getBindings();
135: wsdl4JDefinition.getBindings().putAll(
136: bindingMap);
137:
138: // add services
139: Map serviceMap = importedDef.getServices();
140: wsdl4JDefinition.getServices().putAll(
141: serviceMap);
142:
143: List extElementList = importedDef
144: .getExtensibilityElements();
145: wsdl4JDefinition.getExtensibilityElements()
146: .addAll(extElementList);
147:
148: }
149:
150: }
151: }
152: }
153: }
154: }
155:
156: }
|