001: /*
002: * BEGIN_HEADER - DO NOT EDIT
003: *
004: * The contents of this file are subject to the terms
005: * of the Common Development and Distribution License
006: * (the "License"). You may not use this file except
007: * in compliance with the License.
008: *
009: * You can obtain a copy of the license at
010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011: * See the License for the specific language governing
012: * permissions and limitations under the License.
013: *
014: * When distributing Covered Code, include this CDDL
015: * HEADER in each file and include the License file at
016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017: * If applicable add the following below this CDDL HEADER,
018: * with the fields enclosed by brackets "[]" replaced with
019: * your own identifying information: Portions Copyright
020: * [year] [name of copyright owner]
021: */
022:
023: /*
024: * @(#)ImportImpl.java
025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026: *
027: * END_HEADER - DO NOT EDIT
028: */
029: package com.sun.jbi.wsdl2.impl;
030:
031: import com.sun.jbi.wsdl2.WsdlException;
032:
033: import java.io.IOException;
034:
035: import java.util.Map;
036:
037: import org.w3.ns.wsdl.ImportType;
038:
039: /**
040: * Implementation of WSDL 2.0 Import component.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: final class ImportImpl extends Import {
045: /** The container for this import component */
046: private DescriptionImpl mContainer;
047:
048: /** The result of importing this component */
049: private DescriptionImpl mImportResult = null;
050:
051: /**
052: * Get the container for this component.
053: *
054: * @return The component for this component
055: */
056: protected DescriptionImpl getContainer() {
057: return this .mContainer;
058: }
059:
060: /**
061: * Construct this Import component implementation from the given XML bean.
062: * @param bean The import XML bean to use to construct this component.
063: * @param defs The container for this component.
064: */
065: private ImportImpl(ImportType bean, DescriptionImpl defs) {
066: super (bean);
067: this .mContainer = defs;
068: }
069:
070: /** Map of WSDL-defined attribute QNames. Keyed by QName.toString value */
071: private static java.util.Map sWsdlAttributeQNames = null;
072:
073: /**
074: * Worker class method for {@link #getWsdlAttributeNameMap()}.
075: *
076: * @return Map of WSDL-defined attribute QNames for this component,
077: * indexed by QName.toString()
078: */
079: static synchronized java.util.Map getAttributeNameMap() {
080: if (sWsdlAttributeQNames == null) {
081: sWsdlAttributeQNames = XmlBeansUtil
082: .getAttributesMap(ImportType.type);
083: }
084:
085: return sWsdlAttributeQNames;
086: }
087:
088: /**
089: * Get map of WSDL-defined attribute QNames for this component, indexed by
090: * canonical QName string (see {@link javax.xml.namespace.QName#toString()}.
091: *
092: * @return Map of WSDL-defined attribute QNames for this component,
093: * indexed by QName.toString()
094: */
095: public java.util.Map getWsdlAttributeNameMap() {
096: return getAttributeNameMap();
097: }
098:
099: /**
100: * Get target namespace of import (must be different that this Description TNS).
101: *
102: * @return Target namespace of import (must be different that this Description TNS)
103: */
104: public String getNamespace() {
105: return getBean().getNamespace();
106: }
107:
108: /**
109: * Set target namespace of import (must be different that this Description TNS).
110: *
111: * @param theNamespace Target namespace of import (must be different that this
112: * Description TNS)
113: */
114: public void setNamespace(String theNamespace) {
115: getBean().setNamespace(theNamespace);
116: }
117:
118: /**
119: * Get location hint, if any.
120: *
121: * @return Location hint, if any
122: */
123: public String getLocation() {
124: return getBean().getLocation();
125: }
126:
127: /**
128: * Set location hint, if any.
129: *
130: * @param theLocation Location hint, if any
131: */
132: public void setLocation(String theLocation) {
133: getBean().setLocation(theLocation);
134: }
135:
136: /**
137: * Get the description from this import component
138: *
139: * @return Description from this import component, if any
140: */
141: public synchronized com.sun.jbi.wsdl2.Description getDescription() {
142: if (this .mImportResult == null) {
143: mImportResult = importTarget();
144: }
145:
146: return this .mImportResult;
147: }
148:
149: /**
150: * Get the definitions from this import component.
151: *
152: * @deprecated - replaced by getDescription
153: * @return Definitions n from this import component, if any
154: */
155: public com.sun.jbi.wsdl2.Definitions getDefinitions() {
156: return (com.sun.jbi.wsdl2.Definitions) getDescription();
157: }
158:
159: /**
160: * Import the target of this import component, if possible.
161: *
162: * @return The definitions component imported by this component, if any.
163: */
164: private DescriptionImpl importTarget() {
165: WsdlReader reader = new WsdlReader();
166: com.sun.jbi.wsdl2.Description defs = null;
167:
168: try {
169: defs = reader.readDescription(mContainer
170: .getDocumentBaseUri(), getLocation());
171: } catch (IOException ex) {
172: System.err.println("WSDL import IO error reading "
173: + getLocation() + " (relative to) "
174: + mContainer.getDocumentBaseUri() + ":");
175:
176: if (ex.getMessage() != null) {
177: System.err.println(ex.getMessage());
178: }
179:
180: ex.printStackTrace(System.err);
181: } catch (WsdlException ex) {
182: System.err.println("WSDL import error reading "
183: + getLocation() + " (relative to) "
184: + mContainer.getDocumentBaseUri() + ":");
185:
186: if (ex.getMessage() != null) {
187: System.err.println(ex.getMessage());
188: }
189:
190: ex.printStackTrace(System.err);
191: }
192:
193: return defs != null ? (DescriptionImpl) defs : null;
194: }
195:
196: /**
197: * A factory class for creating / finding components for given XML beans.
198: * <p>
199: * This factory guarantees that there will only be one component for each
200: * XML bean instance.
201: */
202: static class Factory {
203: /**
204: * Find the WSDL import component associated with the given XML
205: * bean, creating a new component if necessary.
206: * <p>
207: * This is thread-safe.<p>
208: *
209: * @param bean The XML bean to find the component for.
210: * @param defs The container for the component.
211: * @return The WSDL import component for the given <code>bean</code>
212: * (null if the <code>bean</code> is null).
213: */
214: static ImportImpl getInstance(ImportType bean,
215: DescriptionImpl defs) {
216: ImportImpl result;
217:
218: if (bean != null) {
219: Map map = defs.getImportMap();
220:
221: synchronized (map) {
222: result = (ImportImpl) map.get(bean);
223:
224: if (result == null) {
225: result = new ImportImpl(bean, defs);
226: map.put(bean, result);
227: }
228: }
229: } else {
230: result = null;
231: }
232:
233: return result;
234: }
235: }
236: }
237:
238: // End-of-file: ImportImpl.java
|