001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.xml.wsdl.model.extensions.soap.impl;
043:
044: import java.util.ArrayList;
045: import java.util.Collection;
046: import java.util.Collections;
047: import java.util.List;
048: import org.netbeans.modules.xml.wsdl.model.BindingInput;
049: import org.netbeans.modules.xml.wsdl.model.BindingOutput;
050: import org.netbeans.modules.xml.wsdl.model.Part;
051: import org.netbeans.modules.xml.wsdl.model.WSDLModel;
052: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPBody;
053: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPComponent;
054: import org.netbeans.modules.xml.wsdl.model.extensions.soap.SOAPQName;
055: import org.netbeans.modules.xml.wsdl.model.impl.Util;
056: import org.netbeans.modules.xml.xam.Component;
057: import org.netbeans.modules.xml.xam.Reference;
058: import org.w3c.dom.Element;
059:
060: /**
061: *
062: * @author Nam Nguyen
063: */
064: public class SOAPBodyImpl extends SOAPMessageBaseImpl implements
065: SOAPBody {
066:
067: /** Creates a new instance of SOAPBodyImpl */
068: public SOAPBodyImpl(WSDLModel model, Element e) {
069: super (model, e);
070: }
071:
072: public SOAPBodyImpl(WSDLModel model) {
073: this (model, createPrefixedElement(SOAPQName.BODY.getQName(),
074: model));
075: }
076:
077: public void accept(SOAPComponent.Visitor visitor) {
078: visitor.visit(this );
079: }
080:
081: public List<String> getParts() {
082: String s = getAttribute(SOAPAttribute.PARTS);
083: return s == null ? null : Util.parse(s);
084: }
085:
086: public List<Reference<Part>> getPartRefs() {
087: String s = getAttribute(SOAPAttribute.PARTS);
088: return s == null ? null : parseParts(s);
089: }
090:
091: public void addPart(String part) {
092: String parts = getAttribute(SOAPAttribute.PARTS);
093: parts = parts == null ? part : parts.trim() + " " + part; //NOI18N
094: setAttribute(PARTS_PROPERTY, SOAPAttribute.PARTS, parts);
095: }
096:
097: public void addPartRef(Reference<Part> partRef) {
098: addPart(partRef.getRefString());
099: }
100:
101: public void addPart(int index, String part) {
102: List<String> parts = getParts();
103: if (parts != null) {
104: parts.add(index, part);
105: } else {
106: parts = Collections.singletonList(part);
107: }
108: setAttribute(PARTS_PROPERTY, SOAPAttribute.PARTS, Util
109: .toString(parts));
110: ;
111: }
112:
113: public void addPartRef(int index, Reference<Part> partRef) {
114: addPart(index, partRef.getRefString());
115: }
116:
117: public void removePart(String part) {
118: Collection<String> parts = getParts();
119: if (parts != null && parts.remove(part)) {
120: setAttribute(PARTS_PROPERTY, SOAPAttribute.PARTS, Util
121: .toString(parts));
122: }
123: }
124:
125: public void removePartRef(Reference<Part> partRef) {
126: removePart(partRef.getRefString());
127: }
128:
129: public void setParts(List<String> parts) {
130: setAttribute(PARTS_PROPERTY, SOAPAttribute.PARTS, Util
131: .toString(parts));
132: }
133:
134: public void setPartRefs(List<Reference<Part>> parts) {
135: String value = null;
136: if (parts != null && !parts.isEmpty()) {
137: StringBuilder sb = new StringBuilder();
138: for (Reference<Part> ref : parts) {
139: sb.append(ref.getRefString());
140: }
141: value = sb.toString();
142: }
143: setAttribute(PARTS_PROPERTY, SOAPAttribute.PARTS, value);
144: }
145:
146: private List<Reference<Part>> parseParts(String s) {
147: List<Reference<Part>> ret = new ArrayList<Reference<Part>>();
148: for (String part : Util.parse(s)) {
149: ret.add(new PartReference(this , part));
150: }
151: return ret;
152: }
153:
154: @Override
155: public boolean canBeAddedTo(Component target) {
156: if (target instanceof BindingInput
157: || target instanceof BindingOutput) {
158: return true;
159: }
160: return false;
161: }
162: }
|