001: /*
002: * Portions Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.ws.wsdl.document.soap;
027:
028: import java.util.ArrayList;
029: import java.util.Iterator;
030: import java.util.List;
031:
032: import javax.xml.namespace.QName;
033:
034: import com.sun.tools.internal.ws.wsdl.framework.Entity;
035: import com.sun.tools.internal.ws.wsdl.framework.EntityAction;
036: import com.sun.tools.internal.ws.wsdl.framework.Extension;
037: import com.sun.tools.internal.ws.wsdl.framework.ExtensionVisitor;
038: import com.sun.tools.internal.ws.wsdl.framework.QNameAction;
039:
040: /**
041: * A SOAP header extension.
042: *
043: * @author WS Development Team
044: */
045: public class SOAPHeader extends Extension {
046:
047: public SOAPHeader() {
048: _faults = new ArrayList();
049: }
050:
051: public void add(SOAPHeaderFault fault) {
052: _faults.add(fault);
053: }
054:
055: public Iterator faults() {
056: return _faults.iterator();
057: }
058:
059: public QName getElementName() {
060: return SOAPConstants.QNAME_HEADER;
061: }
062:
063: public String getNamespace() {
064: return _namespace;
065: }
066:
067: public void setNamespace(String s) {
068: _namespace = s;
069: }
070:
071: public SOAPUse getUse() {
072: return _use;
073: }
074:
075: public void setUse(SOAPUse u) {
076: _use = u;
077: }
078:
079: public boolean isEncoded() {
080: return _use == SOAPUse.ENCODED;
081: }
082:
083: public boolean isLiteral() {
084: return _use == SOAPUse.LITERAL;
085: }
086:
087: public String getEncodingStyle() {
088: return _encodingStyle;
089: }
090:
091: public void setEncodingStyle(String s) {
092: _encodingStyle = s;
093: }
094:
095: public String getPart() {
096: return _part;
097: }
098:
099: public void setMessage(QName message) {
100: _message = message;
101: }
102:
103: public QName getMessage() {
104: return _message;
105: }
106:
107: public void setPart(String s) {
108: _part = s;
109: }
110:
111: public void withAllSubEntitiesDo(EntityAction action) {
112: super .withAllSubEntitiesDo(action);
113:
114: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
115: action.perform((Entity) iter.next());
116: }
117: }
118:
119: public void withAllQNamesDo(QNameAction action) {
120: super .withAllQNamesDo(action);
121:
122: if (_message != null) {
123: action.perform(_message);
124: }
125: }
126:
127: public void accept(ExtensionVisitor visitor) throws Exception {
128: visitor.preVisit(this );
129: for (Iterator iter = _faults.iterator(); iter.hasNext();) {
130: ((SOAPHeaderFault) iter.next()).accept(visitor);
131: }
132: visitor.postVisit(this );
133: }
134:
135: public void validateThis() {
136: if (_message == null) {
137: failValidation("validation.missingRequiredAttribute",
138: "message");
139: }
140: if (_part == null) {
141: failValidation("validation.missingRequiredAttribute",
142: "part");
143: }
144: // Fix for bug 4851427
145: // if (_use == null) {
146: // failValidation("validation.missingRequiredAttribute", "use");
147: // }
148: }
149:
150: private String _encodingStyle;
151: private String _namespace;
152: private String _part;
153: private QName _message;
154: private SOAPUse _use = SOAPUse.LITERAL;
155: private List _faults;
156: }
|