< prev index next >

jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/soap/ver1_2/Body1_2Impl.java

Print this page




  40 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
  41 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
  42 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
  43 import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
  44 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  45 
  46 public class Body1_2Impl extends BodyImpl {
  47 
  48     protected static final Logger log =
  49         Logger.getLogger(Body1_2Impl.class.getName(),
  50                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
  51 
  52     public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
  53             super(ownerDocument, NameImpl.createBody1_2Name(prefix));
  54     }
  55 
  56     public Body1_2Impl(SOAPDocumentImpl ownerDoc, Element domElement) {
  57         super(ownerDoc, domElement);
  58     }
  59 

  60     protected NameImpl getFaultName(String name) {
  61         return NameImpl.createFault1_2Name(name, null);
  62     }
  63 

  64     protected SOAPBodyElement createBodyElement(Name name) {
  65         return new BodyElement1_2Impl(
  66             ((SOAPDocument) getOwnerDocument()).getDocument(),
  67             name);
  68     }

  69     protected SOAPBodyElement createBodyElement(QName name) {
  70         return new BodyElement1_2Impl(
  71             ((SOAPDocument) getOwnerDocument()).getDocument(),
  72             name);
  73     }
  74 

  75     protected QName getDefaultFaultCode() {
  76         return SOAPConstants.SOAP_RECEIVER_FAULT;
  77     }
  78 

  79     public SOAPFault addFault() throws SOAPException {
  80         if (hasAnyChildElement()) {
  81             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
  82             throw new SOAPExceptionImpl(
  83                 "No other element except Fault allowed in SOAPBody");
  84         }
  85         return super.addFault();
  86     }
  87 
  88     /*
  89      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
  90      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
  91      */

  92     public void setEncodingStyle(String encodingStyle) throws SOAPException {
  93         log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
  94         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
  95     }
  96 
  97     /*
  98      * Override addAttribute of ElementImpl to restrict adding encodingStyle
  99      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
 100      */

 101     public SOAPElement addAttribute(Name name, String value)
 102         throws SOAPException {
 103         if (name.getLocalName().equals("encodingStyle")
 104             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
 105 
 106             setEncodingStyle(value);
 107         }
 108         return super.addAttribute(name, value);
 109     }
 110 

 111     public SOAPElement addAttribute(QName name, String value)
 112         throws SOAPException {
 113         if (name.getLocalPart().equals("encodingStyle")
 114             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
 115 
 116             setEncodingStyle(value);
 117         }
 118         return super.addAttribute(name, value);
 119     }
 120 

 121     protected boolean isFault(SOAPElement child) {
 122         return (child.getElementName().getURI().equals(
 123                     SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
 124                 child.getElementName().getLocalName().equals(
 125                     "Fault"));
 126     }
 127 

 128     protected SOAPFault createFaultElement() {
 129         return new Fault1_2Impl(
 130             ((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
 131     }
 132 
 133     /*
 134      * section 5.4 of SOAP1.2 candidate recommendation says that a
 135      * SOAP message MUST contain a single Fault element as the only
 136      * child element of the SOAP Body.
 137      */

 138     public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
 139         if (hasFault()) {
 140             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 141             throw new SOAPExceptionImpl(
 142                 "No other element except Fault allowed in SOAPBody");
 143         }
 144         return super.addBodyElement(name);
 145     }
 146 

 147     public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
 148         if (hasFault()) {
 149             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 150             throw new SOAPExceptionImpl(
 151                 "No other element except Fault allowed in SOAPBody");
 152         }
 153         return super.addBodyElement(name);
 154     }
 155 

 156     protected SOAPElement addElement(Name name) throws SOAPException {
 157         if (hasFault()) {
 158             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 159             throw new SOAPExceptionImpl(
 160                 "No other element except Fault allowed in SOAPBody");
 161         }
 162         return super.addElement(name);
 163     }
 164 

 165     protected SOAPElement addElement(QName name) throws SOAPException {
 166         if (hasFault()) {
 167             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 168             throw new SOAPExceptionImpl(
 169                 "No other element except Fault allowed in SOAPBody");
 170         }
 171         return super.addElement(name);
 172     }
 173 

 174     public SOAPElement addChildElement(Name name) throws SOAPException {
 175         if (hasFault()) {
 176             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 177             throw new SOAPExceptionImpl(
 178                 "No other element except Fault allowed in SOAPBody");
 179         }
 180         return super.addChildElement(name);
 181     }
 182 

 183     public SOAPElement addChildElement(QName name) throws SOAPException {
 184         if (hasFault()) {
 185             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 186             throw new SOAPExceptionImpl(
 187                 "No other element except Fault allowed in SOAPBody");
 188         }
 189         return super.addChildElement(name);
 190     }
 191 
 192     private boolean hasAnyChildElement() {
 193         Node currentNode = getFirstChild();
 194         while (currentNode != null) {
 195             if (currentNode.getNodeType() == Node.ELEMENT_NODE)
 196                 return true;
 197             currentNode = currentNode.getNextSibling();
 198         }
 199         return false;
 200     }
 201 }


  40 import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
  41 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocument;
  42 import com.sun.xml.internal.messaging.saaj.soap.SOAPDocumentImpl;
  43 import com.sun.xml.internal.messaging.saaj.soap.impl.BodyImpl;
  44 import com.sun.xml.internal.messaging.saaj.soap.name.NameImpl;
  45 
  46 public class Body1_2Impl extends BodyImpl {
  47 
  48     protected static final Logger log =
  49         Logger.getLogger(Body1_2Impl.class.getName(),
  50                          "com.sun.xml.internal.messaging.saaj.soap.ver1_2.LocalStrings");
  51 
  52     public Body1_2Impl(SOAPDocumentImpl ownerDocument, String prefix) {
  53             super(ownerDocument, NameImpl.createBody1_2Name(prefix));
  54     }
  55 
  56     public Body1_2Impl(SOAPDocumentImpl ownerDoc, Element domElement) {
  57         super(ownerDoc, domElement);
  58     }
  59 
  60     @Override
  61     protected NameImpl getFaultName(String name) {
  62         return NameImpl.createFault1_2Name(name, null);
  63     }
  64 
  65     @Override
  66     protected SOAPBodyElement createBodyElement(Name name) {
  67         return new BodyElement1_2Impl(
  68             ((SOAPDocument) getOwnerDocument()).getDocument(),
  69             name);
  70     }
  71     @Override
  72     protected SOAPBodyElement createBodyElement(QName name) {
  73         return new BodyElement1_2Impl(
  74             ((SOAPDocument) getOwnerDocument()).getDocument(),
  75             name);
  76     }
  77 
  78     @Override
  79     protected QName getDefaultFaultCode() {
  80         return SOAPConstants.SOAP_RECEIVER_FAULT;
  81     }
  82 
  83     @Override
  84     public SOAPFault addFault() throws SOAPException {
  85         if (hasAnyChildElement()) {
  86             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
  87             throw new SOAPExceptionImpl(
  88                 "No other element except Fault allowed in SOAPBody");
  89         }
  90         return super.addFault();
  91     }
  92 
  93     /*
  94      * Override setEncodingStyle of ElementImpl to restrict adding encodingStyle
  95      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
  96      */
  97     @Override
  98     public void setEncodingStyle(String encodingStyle) throws SOAPException {
  99         log.severe("SAAJ0401.ver1_2.no.encodingstyle.in.body");
 100         throw new SOAPExceptionImpl("encodingStyle attribute cannot appear on Body");
 101     }
 102 
 103     /*
 104      * Override addAttribute of ElementImpl to restrict adding encodingStyle
 105      * attribute to SOAP Body (SOAP 1.2 spec, part 1, section 5.1.1)
 106      */
 107     @Override
 108     public SOAPElement addAttribute(Name name, String value)
 109         throws SOAPException {
 110         if (name.getLocalName().equals("encodingStyle")
 111             && name.getURI().equals(NameImpl.SOAP12_NAMESPACE)) {
 112 
 113             setEncodingStyle(value);
 114         }
 115         return super.addAttribute(name, value);
 116     }
 117 
 118     @Override
 119     public SOAPElement addAttribute(QName name, String value)
 120         throws SOAPException {
 121         if (name.getLocalPart().equals("encodingStyle")
 122             && name.getNamespaceURI().equals(NameImpl.SOAP12_NAMESPACE)) {
 123 
 124             setEncodingStyle(value);
 125         }
 126         return super.addAttribute(name, value);
 127     }
 128 
 129     @Override
 130     protected boolean isFault(SOAPElement child) {
 131         return (child.getElementName().getURI().equals(
 132                     SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE) &&
 133                 child.getElementName().getLocalName().equals(
 134                     "Fault"));
 135     }
 136 
 137     @Override
 138     protected SOAPFault createFaultElement() {
 139         return new Fault1_2Impl(
 140             ((SOAPDocument) getOwnerDocument()).getDocument(), getPrefix());
 141     }
 142 
 143     /*
 144      * section 5.4 of SOAP1.2 candidate recommendation says that a
 145      * SOAP message MUST contain a single Fault element as the only
 146      * child element of the SOAP Body.
 147      */
 148     @Override
 149     public SOAPBodyElement addBodyElement(Name name) throws SOAPException {
 150         if (hasFault()) {
 151             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 152             throw new SOAPExceptionImpl(
 153                 "No other element except Fault allowed in SOAPBody");
 154         }
 155         return super.addBodyElement(name);
 156     }
 157 
 158     @Override
 159     public SOAPBodyElement addBodyElement(QName name) throws SOAPException {
 160         if (hasFault()) {
 161             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 162             throw new SOAPExceptionImpl(
 163                 "No other element except Fault allowed in SOAPBody");
 164         }
 165         return super.addBodyElement(name);
 166     }
 167 
 168     @Override
 169     protected SOAPElement addElement(Name name) throws SOAPException {
 170         if (hasFault()) {
 171             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 172             throw new SOAPExceptionImpl(
 173                 "No other element except Fault allowed in SOAPBody");
 174         }
 175         return super.addElement(name);
 176     }
 177 
 178     @Override
 179     protected SOAPElement addElement(QName name) throws SOAPException {
 180         if (hasFault()) {
 181             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 182             throw new SOAPExceptionImpl(
 183                 "No other element except Fault allowed in SOAPBody");
 184         }
 185         return super.addElement(name);
 186     }
 187 
 188     @Override
 189     public SOAPElement addChildElement(Name name) throws SOAPException {
 190         if (hasFault()) {
 191             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 192             throw new SOAPExceptionImpl(
 193                 "No other element except Fault allowed in SOAPBody");
 194         }
 195         return super.addChildElement(name);
 196     }
 197 
 198     @Override
 199     public SOAPElement addChildElement(QName name) throws SOAPException {
 200         if (hasFault()) {
 201             log.severe("SAAJ0402.ver1_2.only.fault.allowed.in.body");
 202             throw new SOAPExceptionImpl(
 203                 "No other element except Fault allowed in SOAPBody");
 204         }
 205         return super.addChildElement(name);
 206     }
 207 
 208     private boolean hasAnyChildElement() {
 209         Node currentNode = getFirstChild();
 210         while (currentNode != null) {
 211             if (currentNode.getNodeType() == Node.ELEMENT_NODE)
 212                 return true;
 213             currentNode = currentNode.getNextSibling();
 214         }
 215         return false;
 216     }
 217 }
< prev index next >