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: * @(#)MessageReferenceImpl.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.Direction;
032: import com.sun.jbi.wsdl2.MessageContentModel;
033:
034: import java.util.Map;
035:
036: import javax.xml.namespace.QName;
037:
038: import org.apache.xmlbeans.XmlCursor;
039:
040: import org.w3.ns.wsdl.MessageRefType;
041:
042: /**
043: * Implementation of WSDL 2.0 Message Reference Component.
044: *
045: * @author Sun Microsystems, Inc.
046: */
047: final class MessageReferenceImpl extends MessageReference {
048: /** The container for this component */
049: private DescriptionImpl mContainer;
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 a message reference implementation object from the given XML
062: * bean.
063: * @param bean The Message Reference XML bean to use to construct this
064: * component.
065: * @param defs The container for this component
066: */
067: private MessageReferenceImpl(MessageRefType bean,
068: DescriptionImpl defs) {
069: super (bean);
070: this .mContainer = defs;
071: }
072:
073: /** Map of WSDL-defined attribute QNames. Keyed by QName.toString value */
074: private static java.util.Map sWsdlAttributeQNames = null;
075:
076: /**
077: * Worker class method for {@link #getWsdlAttributeNameMap()}.
078: *
079: * @return Map of WSDL-defined attribute QNames for this component,
080: * indexed by QName.toString()
081: */
082: static synchronized java.util.Map getAttributeNameMap() {
083: if (sWsdlAttributeQNames == null) {
084: sWsdlAttributeQNames = XmlBeansUtil
085: .getAttributesMap(MessageRefType.type);
086: }
087:
088: return sWsdlAttributeQNames;
089: }
090:
091: /**
092: * Get map of WSDL-defined attribute QNames for this component, indexed by
093: * canonical QName string (see {@link javax.xml.namespace.QName#toString()}.
094: *
095: * @return Map of WSDL-defined attribute QNames for this component,
096: * indexed by QName.toString()
097: */
098: public java.util.Map getWsdlAttributeNameMap() {
099: return getAttributeNameMap();
100: }
101:
102: /**
103: * Get message exchange pattern role identifier.
104: *
105: * @return Message exchange pattern role identifier
106: */
107: public String getMessageLabel() {
108: return getBean().getMessageLabel();
109: }
110:
111: /**
112: * Set message exchange pattern role identifier.
113: *
114: * @param theMessageLabel Message exchange pattern role identifier
115: */
116: public void setMessageLabel(String theMessageLabel) {
117: if (theMessageLabel != null) {
118: getBean().setMessageLabel(theMessageLabel);
119: } else {
120: getBean().unsetMessageLabel();
121: }
122:
123: return;
124: }
125:
126: /**
127: * Get content or payload element type declaration.
128: *
129: * @return Content or payload element type declaration
130: */
131: public Object getElement() {
132: return getBean().getElement();
133: }
134:
135: /**
136: * Set content or payload element type declaration.
137: *
138: * @param theElement Content or payload element type declaration
139: */
140: public void setElement(Object theElement) {
141: if (theElement != null
142: && (theElement instanceof QName || theElement instanceof String)) {
143: getBean().setElement(theElement);
144: }
145: }
146:
147: /**
148: * Get direction of this message in the exchange.
149: *
150: * @return Direction of this message in the exchange
151: */
152: public Direction getDirection() {
153: XmlCursor cursor = getBean().newCursor();
154: QName name = cursor.getName();
155:
156: cursor.dispose();
157:
158: return INPUT.equals(name.getLocalPart()) ? Direction.IN
159: : Direction.OUT;
160: }
161:
162: /**
163: * Get content model type: #ANY, #NONE, or #ELEMENT.
164: *
165: * @return Content model type: #ANY, #NONE, or #ELEMENT
166: */
167: public MessageContentModel getMessageContentModel() {
168: MessageContentModel result = MessageContentModel.NONE;
169: Object element = getBean().getElement();
170:
171: if (element != null) {
172: if (element instanceof QName) {
173: result = MessageContentModel.ELEMENT;
174: }
175:
176: //assert (element instanceof String);
177: result = MessageContentModel.ANY;
178: }
179:
180: return result;
181: }
182:
183: /** WSDL element local name for an input message */
184: private static final String INPUT = "input";
185:
186: /** WSDL element local name for an output message */
187: private static final String OUTPUT = "output";
188:
189: /**
190: * Set direction of this message in the exchange.
191: * <p>
192: * Direction is encoded in name of the XML element representing this component.
193: *
194: * @param theDirection Direction of this message in the exchange
195: */
196: public void setDirection(Direction theDirection) {
197: XmlCursor cursor = getBean().newCursor();
198: QName name = cursor.getName();
199: QName newName = new QName(name.getNamespaceURI(),
200: theDirection == Direction.IN ? INPUT : OUTPUT);
201:
202: cursor.setName(newName);
203: cursor.dispose();
204: }
205:
206: /**
207: * A factory class for creating / finding components for given XML beans.
208: * <p>
209: * This factory guarantees that there will only be one component for each
210: * XML bean instance.
211: */
212: static final class Factory {
213: /**
214: * Find the WSDL message reference component associated with the given
215: * XML bean, creating a new component if necessary.
216: * <p>
217: * This is thread-safe.<p>
218: *
219: * @param bean The XML bean to find the component for.
220: * @param defs The container for the component.
221: * @return The WSDL message reference component for the given
222: * <code>bean</code> (null if the <code>bean</code> is null).
223: */
224: static MessageReferenceImpl getInstance(MessageRefType bean,
225: DescriptionImpl defs) {
226: MessageReferenceImpl result;
227:
228: if (bean != null) {
229: Map map = defs.getMessageReferenceMap();
230:
231: synchronized (map) {
232: result = (MessageReferenceImpl) map.get(bean);
233:
234: if (result == null) {
235: result = new MessageReferenceImpl(bean, defs);
236: map.put(bean, result);
237: }
238: }
239: } else {
240: result = null;
241: }
242:
243: return result;
244: }
245: } // end inner class Factory
246: }
247:
248: // End-of-file: MessageReferenceImpl.java
|