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: * @(#)InterfaceOperationImpl.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 java.io.StringWriter;
032: import java.util.Map;
033:
034: import javax.xml.namespace.QName;
035:
036: import org.apache.xmlbeans.XmlOptions;
037:
038: import org.w3.ns.wsdl.InterfaceOperationType;
039: import org.w3.ns.wsdl.MessageRefFaultType;
040:
041: import org.w3c.dom.DocumentFragment;
042:
043: /**
044: * Implementation of WSDL 2.0 interface operation component.
045: *
046: * @author Sun Microsystems, Inc.
047: */
048: final class InterfaceOperationImpl extends InterfaceOperation {
049: /** Container for this component */
050: private DescriptionImpl mContainer;
051:
052: /**
053: * Get the container for this component.
054: *
055: * @return The component for this component
056: */
057: protected DescriptionImpl getContainer() {
058: return this .mContainer;
059: }
060:
061: /**
062: * Returns true if the operation is safe, as defined by the W3C Web Services
063: * Architecture document.
064: *
065: * @return True if the operation is safe, as defined by the W3C Web
066: * Services Architecture document
067: */
068: public boolean getSafe() {
069: return getBean().getSafe();
070: }
071:
072: /**
073: * Set true if the operation is safe, as defined by the W3C Web Services
074: * Architecture document.
075: *
076: * @param isSafe True if the operation is safe, as defined by the W3C
077: * Web Services Architecture document
078: */
079: public void setSafe(boolean isSafe) {
080: getBean().setSafe(isSafe);
081: }
082:
083: /**
084: * Construct an interface operation component implementation object from the
085: * given XML bean.
086: * @param bean The interface operation XML bean to use to construct this
087: * component.
088: * @param defs The definitions container for the interface operation.
089: */
090: private InterfaceOperationImpl(InterfaceOperationType bean,
091: DescriptionImpl defs) {
092: super (bean);
093: this .mContainer = defs;
094: }
095:
096: /** Map of WSDL-defined attribute QNames. Keyed by QName.toString value */
097: private static java.util.Map sWsdlAttributeQNames = null;
098:
099: /**
100: * Worker class method for {@link #getWsdlAttributeNameMap()}.
101: *
102: * @return Map of WSDL-defined attribute QNames for this component,
103: * indexed by QName.toString()
104: */
105: static synchronized java.util.Map getAttributeNameMap() {
106: if (sWsdlAttributeQNames == null) {
107: sWsdlAttributeQNames = XmlBeansUtil
108: .getAttributesMap(InterfaceOperationType.type);
109: }
110:
111: return sWsdlAttributeQNames;
112: }
113:
114: /**
115: * Get map of WSDL-defined attribute QNames for this component, indexed by
116: * canonical QName string (see {@link javax.xml.namespace.QName#toString()}.
117: *
118: * @return Map of WSDL-defined attribute QNames for this component,
119: * indexed by QName.toString()
120: */
121: public java.util.Map getWsdlAttributeNameMap() {
122: return getAttributeNameMap();
123: }
124:
125: /**
126: * Get name of this interface operation component.
127: *
128: * @return Name of this interface operation component
129: */
130: public String getName() {
131: return getBean().getName();
132: }
133:
134: /**
135: * Set name of this interface operation component.
136: *
137: * @param theName Name of this interface operation component
138: */
139: public void setName(String theName) {
140: getBean().setName(theName);
141: }
142:
143: /**
144: * Get message exchange pattern URI for this operation.
145: *
146: * @return Message exchange pattern URI for this operation
147: */
148: public String getPattern() {
149: return getBean().getPattern();
150: }
151:
152: /**
153: * Set message exchange pattern URI for this operation.
154: *
155: * @param thePattern Message exchange pattern URI for this operation
156: */
157: public void setPattern(String thePattern) {
158: getBean().setPattern(thePattern);
159: }
160:
161: /**
162: * Get a URI identifying the message construction rules for a message reference.
163: *
164: * @return A URI identifying the message construction rules for a message reference
165: */
166: public String getStyle() {
167: return getBean().getStyle();
168: }
169:
170: /**
171: * Set a URI identifying the message construction rules for a message reference.
172: *
173: * @param theStyle A URI identifying the message construction rules for a message
174: * reference
175: */
176: public void setStyle(String theStyle) {
177: getBean().setStyle(theStyle);
178: }
179:
180: /**
181: * Get the number of MessageReference items in inputs.
182: *
183: * @return The number of MessageReference items in inputs
184: */
185: public int getInputsLength() {
186: return getBean().sizeOfInputArray();
187: }
188:
189: /**
190: * Get input message references by indexed position.
191: *
192: * @param index Indexed position value 0..length-1
193: * @return Input message references at given <code>index</code> position.
194: */
195: public com.sun.jbi.wsdl2.MessageReference getInput(int index) {
196: return MessageReferenceImpl.Factory.getInstance(getBean()
197: .getInputArray(index), this .mContainer);
198: }
199:
200: /**
201: * Set input message references by indexed position.
202: *
203: * @param index Indexed position value (0..length-1) of the item to set
204: * @param theInput Item to add at position <code>index</code>.
205: */
206: public void setInput(int index,
207: com.sun.jbi.wsdl2.MessageReference theInput) {
208: getBean().setInputArray(
209: index,
210: theInput != null ? ((MessageReferenceImpl) theInput)
211: .getBean() : null);
212: }
213:
214: /**
215: * Append an item to input message references.
216: *
217: * @param theInput Item to append to inputs
218: */
219: public void appendInput(com.sun.jbi.wsdl2.MessageReference theInput) {
220: synchronized (getBean().monitor()) {
221: setInput(getInputsLength(), theInput);
222: }
223: }
224:
225: /**
226: * Remove input message references by index position.
227: *
228: * @param index The index position of the input to remove
229: * @return The MessageReference removed, if any.
230: */
231: public com.sun.jbi.wsdl2.MessageReference removeInput(int index) {
232: com.sun.jbi.wsdl2.MessageReference result;
233:
234: synchronized (getBean().monitor()) {
235: result = getInput(index);
236: getBean().removeInput(index);
237: }
238:
239: return result;
240: }
241:
242: /**
243: * Get the number of MessageReference items in outputs.
244: *
245: * @return The number of MessageReference items in outputs
246: */
247: public int getOutputsLength() {
248: return getBean().sizeOfOutputArray();
249: }
250:
251: /**
252: * Get output message references by indexed position.
253: *
254: * @param index Indexed position value 0..length-1
255: * @return Output message references at given <code>index</code> position.
256: */
257: public com.sun.jbi.wsdl2.MessageReference getOutput(int index) {
258: return MessageReferenceImpl.Factory.getInstance(getBean()
259: .getOutputArray(index), this .mContainer);
260: }
261:
262: /**
263: * Set output message references by indexed position.
264: *
265: * @param index Indexed position value (0..length-1) of the item to set
266: * @param theOutput Item to add at position <code>index</code>.
267: */
268: public void setOutput(int index,
269: com.sun.jbi.wsdl2.MessageReference theOutput) {
270: getBean().setOutputArray(
271: index,
272: theOutput != null ? ((MessageReferenceImpl) theOutput)
273: .getBean() : null);
274: }
275:
276: /**
277: * Append an item to output message references.
278: *
279: * @param theOutput Item to append to outputs
280: */
281: public void appendOutput(
282: com.sun.jbi.wsdl2.MessageReference theOutput) {
283: synchronized (getBean().monitor()) {
284: setOutput(getOutputsLength(), theOutput);
285: }
286: }
287:
288: /**
289: * Remove output message references by index position.
290: *
291: * @param index The index position of the output to remove
292: * @return The MessageReference removed, if any.
293: */
294: public com.sun.jbi.wsdl2.MessageReference removeOutput(int index) {
295: com.sun.jbi.wsdl2.MessageReference result;
296:
297: synchronized (getBean().monitor()) {
298: result = getOutput(index);
299: getBean().removeOutput(index);
300: }
301:
302: return result;
303: }
304:
305: /**
306: * Get the number of MessageFaultReference items in inFaults.
307: *
308: * @return The number of MessageFaultReference items in inFaults
309: */
310: public int getInFaultsLength() {
311: return getBean().sizeOfInfaultArray();
312: }
313:
314: /**
315: * Get in fault message references by indexed position.
316: *
317: * @param index Indexed position value 0..length-1
318: * @return In fault message references at given <code>index</code> position.
319: */
320: public com.sun.jbi.wsdl2.MessageFaultReference getInFault(int index) {
321: return MessageFaultReferenceImpl.Factory.getInstance(getBean()
322: .getInfaultArray(index), this .mContainer);
323: }
324:
325: /**
326: * Set in fault message references by indexed position.
327: *
328: * @param index Indexed position value (0..length-1) of the item to set
329: * @param theInFault Item to add at position <code>index</code>.
330: */
331: public void setInFault(int index,
332: com.sun.jbi.wsdl2.MessageFaultReference theInFault) {
333: getBean()
334: .setInfaultArray(
335: index,
336: theInFault != null ? ((MessageFaultReferenceImpl) theInFault)
337: .getBean()
338: : null);
339: }
340:
341: /**
342: * Append an item to in fault message references.
343: *
344: * @param theInFault Item to append to inFaults
345: */
346: public void appendInFault(
347: com.sun.jbi.wsdl2.MessageFaultReference theInFault) {
348: synchronized (getBean().monitor()) {
349: setInFault(getInFaultsLength(), theInFault);
350: }
351: }
352:
353: /**
354: * Remove in fault message references by index position.
355: *
356: * @param index The index position of the inFault to remove
357: * @return The MessageFaultReference removed, if any.
358: */
359: public com.sun.jbi.wsdl2.MessageFaultReference removeInFault(
360: int index) {
361: com.sun.jbi.wsdl2.MessageFaultReference result;
362:
363: synchronized (getBean().monitor()) {
364: result = getInFault(index);
365: getBean().removeInfault(index);
366: }
367:
368: return result;
369: }
370:
371: /**
372: * Get the number of MessageFaultReference items in outFaults.
373: *
374: * @return The number of MessageFaultReference items in outFaults
375: */
376: public int getOutFaultsLength() {
377: return getBean().sizeOfOutfaultArray();
378: }
379:
380: /**
381: * Get out fault message references by indexed position.
382: *
383: * @param index Indexed position value 0..length-1
384: * @return Out fault message references at given <code>index</code> position.
385: */
386: public com.sun.jbi.wsdl2.MessageFaultReference getOutFault(int index) {
387: return MessageFaultReferenceImpl.Factory.getInstance(getBean()
388: .getOutfaultArray(index), this .mContainer);
389: }
390:
391: /**
392: * Set out fault message references by indexed position.
393: *
394: * @param index Indexed position value (0..length-1) of the item to set
395: * @param theOutFault Item to add at position <code>index</code>.
396: */
397: public void setOutFault(int index,
398: com.sun.jbi.wsdl2.MessageFaultReference theOutFault) {
399: getBean()
400: .setOutfaultArray(
401: index,
402: theOutFault != null ? ((MessageFaultReferenceImpl) theOutFault)
403: .getBean()
404: : null);
405: }
406:
407: /**
408: * Append an item to out fault message references.
409: *
410: * @param theOutFault Item to append to outFaults
411: */
412: public void appendOutFault(
413: com.sun.jbi.wsdl2.MessageFaultReference theOutFault) {
414: synchronized (getBean().monitor()) {
415: setOutFault(getOutFaultsLength(), theOutFault);
416: }
417: }
418:
419: /**
420: * Remove out fault message references by index position.
421: *
422: * @param index The index position of the outFault to remove
423: * @return The MessageFaultReference removed, if any.
424: */
425: public com.sun.jbi.wsdl2.MessageFaultReference removeOutFault(
426: int index) {
427: com.sun.jbi.wsdl2.MessageFaultReference result;
428:
429: synchronized (getBean().monitor()) {
430: result = getOutFault(index);
431: getBean().removeOutfault(index);
432: }
433:
434: return result;
435: }
436:
437: /**
438: * Create a new input message reference for this operation, and append
439: * it to this operation's input list.
440: *
441: * @return The newly created input message reference.
442: */
443: public com.sun.jbi.wsdl2.MessageReference addNewInput() {
444: return MessageReferenceImpl.Factory.getInstance(getBean()
445: .addNewInput(), this .mContainer);
446: }
447:
448: /**
449: * Create a new output message reference for this operation, and append
450: * it to this operation's output list.
451: *
452: * @return The newly created input message reference.
453: */
454: public com.sun.jbi.wsdl2.MessageReference addNewOutput() {
455: return MessageReferenceImpl.Factory.getInstance(getBean()
456: .addNewOutput(), this .mContainer);
457: }
458:
459: /**
460: * Create a new messsage in-fault reference for this operation, and
461: * append it to the operation's in-fault list.
462: *
463: * @param fault Fault to add to this operation.
464: * @return The newly created in-fault reference.
465: */
466: public com.sun.jbi.wsdl2.MessageFaultReference addNewInFault(
467: com.sun.jbi.wsdl2.InterfaceFault fault) {
468: MessageRefFaultType faultBean = getBean().addNewInfault();
469:
470: if (fault != null) {
471: faultBean.setRef(fault.getQualifiedName());
472: }
473:
474: return MessageFaultReferenceImpl.Factory.getInstance(faultBean,
475: this .mContainer);
476: }
477:
478: /**
479: * Create a new messsage out-fault reference for this operation, and
480: * append it to the operation's out-fault list.
481: *
482: * @param fault Fault to add to this operation.
483: * @return The newly created out-fault reference.
484: */
485: public com.sun.jbi.wsdl2.MessageFaultReference addNewOutFault(
486: com.sun.jbi.wsdl2.InterfaceFault fault) {
487: MessageRefFaultType faultBean = getBean().addNewOutfault();
488:
489: if (fault != null) {
490: faultBean.setRef(fault.getQualifiedName());
491: }
492:
493: return MessageFaultReferenceImpl.Factory.getInstance(faultBean,
494: this .mContainer);
495: }
496:
497: /**
498: * Return this WSDL interface operation as an XML string.
499: *
500: * @return This operation, serialized as an XML string.
501: */
502: public String toXmlString() {
503: String result;
504: StringWriter sw = new StringWriter();
505: XmlOptions options = new XmlOptions();
506:
507: options.setSavePrettyPrint();
508: options
509: .setSavePrettyPrintIndent(Constants.XML_PRETTY_PRINT_INDENT);
510: options.setSaveOuter();
511:
512: try {
513: getBean().save(sw, options);
514: sw.close();
515: } catch (java.io.IOException ex) {
516: sw.write("\n<!-- IO error: ");
517: sw.write(ex.getMessage());
518: sw.write("\n Document fragment truncated. -->\n");
519: // $TODO: log error
520: }
521:
522: return sw.getBuffer().toString();
523: }
524:
525: /**
526: * Return this interface operation as a DOM document fragment. The DOM
527: * subtree is a copy; altering it will not affect this service.
528: *
529: * @return This operation, as a DOM document fragment.
530: */
531: public DocumentFragment toXmlDocumentFragment() {
532: XmlOptions options = new XmlOptions();
533:
534: options.setSaveOuter();
535: return (DocumentFragment) getBean().newDomNode(options);
536: }
537:
538: /**
539: * Get qualified name of this interface operation.
540: *
541: * @return Qualified name of this interface operation
542: */
543: public QName getQualifiedName() {
544: return new QName(this .mContainer.getTargetNamespace(),
545: getBean().getName());
546: }
547:
548: /**
549: * A factory class for creating / finding components for given XML beans.
550: * <p>
551: * This factory guarantees that there will only be one component for each
552: * XML bean instance.
553: */
554: static class Factory {
555: /**
556: * Find the WSDL interface operation component associated with the given XML
557: * bean, creating a new component if necessary.
558: * <p>
559: * This is thread-safe.<p>
560: *
561: * @param bean The XML bean to find the component for.
562: * @param defs The container for the component.
563: * @return The WSDL interface operation component for the given <code>bean</code>
564: * (null if the <code>bean</code> is null).
565: */
566: static InterfaceOperationImpl getInstance(
567: InterfaceOperationType bean, DescriptionImpl defs) {
568: InterfaceOperationImpl result;
569:
570: if (bean != null) {
571: Map map = defs.getInterfaceOperationMap();
572:
573: synchronized (map) {
574: result = (InterfaceOperationImpl) map.get(bean);
575:
576: if (result == null) {
577: result = new InterfaceOperationImpl(bean, defs);
578: map.put(bean, result);
579: }
580: }
581: } else {
582: result = null;
583: }
584:
585: return result;
586: }
587: }
588: }
589:
590: // End-of-file: InterfaceOperationImpl.java
|