1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.ws.wsdl.document.soap;
  27 
  28 import com.sun.tools.internal.ws.wsdl.framework.*;
  29 import org.xml.sax.Locator;
  30 
  31 import javax.xml.namespace.QName;
  32 import java.util.ArrayList;
  33 import java.util.Iterator;
  34 import java.util.List;
  35 
  36 /**
  37  * A SOAP header extension.
  38  *
  39  * @author WS Development Team
  40  */
  41 public class SOAPHeader extends ExtensionImpl {
  42 
  43     public SOAPHeader(Locator locator) {
  44         super(locator);
  45         _faults = new ArrayList();
  46     }
  47 
  48     public void add(SOAPHeaderFault fault) {
  49         _faults.add(fault);
  50     }
  51 
  52     public Iterator faults() {
  53         return _faults.iterator();
  54     }
  55 
  56     public QName getElementName() {
  57         return SOAPConstants.QNAME_HEADER;
  58     }
  59 
  60     public String getNamespace() {
  61         return _namespace;
  62     }
  63 
  64     public void setNamespace(String s) {
  65         _namespace = s;
  66     }
  67 
  68     public SOAPUse getUse() {
  69         return _use;
  70     }
  71 
  72     public void setUse(SOAPUse u) {
  73         _use = u;
  74     }
  75 
  76     public boolean isEncoded() {
  77         return _use == SOAPUse.ENCODED;
  78     }
  79 
  80     public boolean isLiteral() {
  81         return _use == SOAPUse.LITERAL;
  82     }
  83 
  84     public String getEncodingStyle() {
  85         return _encodingStyle;
  86     }
  87 
  88     public void setEncodingStyle(String s) {
  89         _encodingStyle = s;
  90     }
  91 
  92     public String getPart() {
  93         return _part;
  94     }
  95 
  96     public void setMessage(QName message) {
  97         _message = message;
  98     }
  99 
 100     public QName getMessage() {
 101         return _message;
 102     }
 103 
 104     public void setPart(String s) {
 105         _part = s;
 106     }
 107 
 108     public void withAllSubEntitiesDo(EntityAction action) {
 109         super.withAllSubEntitiesDo(action);
 110 
 111         for (Iterator iter = _faults.iterator(); iter.hasNext();) {
 112             action.perform((Entity) iter.next());
 113         }
 114     }
 115 
 116     public void withAllQNamesDo(QNameAction action) {
 117         super.withAllQNamesDo(action);
 118 
 119         if (_message != null) {
 120             action.perform(_message);
 121         }
 122     }
 123 
 124     public void accept(ExtensionVisitor visitor) throws Exception {
 125         visitor.preVisit(this);
 126         for (Iterator iter = _faults.iterator(); iter.hasNext();) {
 127             ((SOAPHeaderFault) iter.next()).accept(visitor);
 128         }
 129         visitor.postVisit(this);
 130     }
 131 
 132     public void validateThis() {
 133         if (_message == null) {
 134             failValidation("validation.missingRequiredAttribute", "message");
 135         }
 136         if (_part == null) {
 137             failValidation("validation.missingRequiredAttribute", "part");
 138         }
 139         // Fix for bug 4851427
 140         //        if (_use == null) {
 141         //            failValidation("validation.missingRequiredAttribute", "use");
 142         //        }
 143 
 144         if(_use == SOAPUse.ENCODED) {
 145             throw new ValidationException("validation.unsupportedUse.encoded", getLocator().getLineNumber(),getLocator().getSystemId());
 146         }
 147     }
 148 
 149     private String _encodingStyle;
 150     private String _namespace;
 151     private String _part;
 152     private QName _message;
 153     private SOAPUse _use=SOAPUse.LITERAL;
 154     private List _faults;
 155 }