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: * @(#)IncludeImpl.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.IncludeType;
038:
039: /**
040: * Implementation of WSDL 2.0 Include component.
041: *
042: * @author Sun Microsystems, Inc.
043: */
044: final class IncludeImpl extends Include {
045: /** The container for this import component */
046: private DescriptionImpl mContainer;
047:
048: /** The result of reading this component */
049: private DescriptionImpl mIncludeResult = 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 an Include component implementation from an Include XML Bean.
062: * @param bean The Include XML bean to use to construct this component.
063: * @param defs The container for this component.
064: */
065: private IncludeImpl(IncludeType 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(IncludeType.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 location hint for the included definitions.
101: *
102: * @return Location hint for the included definitions
103: */
104: public String getLocation() {
105: return getBean().getLocation();
106: }
107:
108: /**
109: * Set location hint for the included definitions.
110: *
111: * @param theLocation Location hint for the included definitions
112: */
113: public synchronized void setLocation(String theLocation) {
114: getBean().setLocation(theLocation);
115: this .mIncludeResult = null;
116: }
117:
118: /**
119: * Get the description included by this component
120: *
121: * @return Description from included by this component, if any
122: */
123: public synchronized com.sun.jbi.wsdl2.Description getDescription() {
124: if (this .mIncludeResult == null) {
125: this .mIncludeResult = includeTarget();
126: }
127:
128: return this .mIncludeResult;
129: }
130:
131: /**
132: * Get the definitions included by this component
133: *
134: * @deprecated - replaced by getDescription
135: * @return Definitions from included by this component, if any
136: */
137: public com.sun.jbi.wsdl2.Definitions getDefinitions() {
138: return (com.sun.jbi.wsdl2.Definitions) getDescription();
139: }
140:
141: /**
142: * Read the target of this include into its own Description component.
143: *
144: * @return The WSDL definitions component pointed to by this include.
145: */
146: private DescriptionImpl includeTarget() {
147: WsdlReader reader = new WsdlReader();
148: com.sun.jbi.wsdl2.Description defs = null;
149:
150: try {
151: defs = reader.readDescription(mContainer
152: .getDocumentBaseUri(), getLocation());
153: } catch (IOException ex) {
154: System.err.println("WSDL include IO error reading "
155: + getLocation() + " (relative to) "
156: + mContainer.getDocumentBaseUri() + ":");
157:
158: if (ex.getMessage() != null) {
159: System.err.println(ex.getMessage());
160: }
161:
162: ex.printStackTrace(System.err);
163: } catch (WsdlException ex) {
164: System.err.println("WSDL include error reading "
165: + getLocation() + " (relative to) "
166: + mContainer.getDocumentBaseUri() + ":");
167:
168: if (ex.getMessage() != null) {
169: System.err.println(ex.getMessage());
170: }
171:
172: ex.printStackTrace(System.err);
173: }
174:
175: return defs != null ? (DescriptionImpl) defs : null;
176: }
177:
178: /**
179: * A factory class for creating / finding components for given XML beans.
180: * <p>
181: * This factory guarantees that there will only be one component for each
182: * XML bean instance.
183: */
184: static class Factory {
185: /**
186: * Find the WSDL include component associated with the given XML
187: * bean, creating a new component if necessary.
188: * <p>
189: * This is thread-safe.<p>
190: *
191: * @param bean The XML bean to find the component for.
192: * @param defs The container for the component.
193: * @return The WSDL include component for the given <code>bean</code>
194: * (null if the <code>bean</code> is null).
195: */
196: static IncludeImpl getInstance(IncludeType bean,
197: DescriptionImpl defs) {
198: IncludeImpl result;
199:
200: if (bean != null) {
201: Map map = defs.getIncludeMap();
202:
203: synchronized (map) {
204: result = (IncludeImpl) map.get(bean);
205:
206: if (result == null) {
207: result = new IncludeImpl(bean, defs);
208: map.put(bean, result);
209: }
210: }
211: } else {
212: result = null;
213: }
214:
215: return result;
216: }
217: }
218: }
219:
220: // End-of-file: IncludeImpl.java
|