Author: veithen
Date: Tue Nov 17 19:45:12 2015
New Revision: 1714858

URL: http://svn.apache.org/viewvc?rev=1714858&view=rev
Log:
Use the datatypes library to process boolean attributes in SOAP headers.

Added:
    
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java
   (with props)
    
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java
   (with props)
    
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java
   (with props)
Modified:
    
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/AxiomSOAPHeaderBlockSupport.aj
    
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAPHelper.java

Modified: 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/AxiomSOAPHeaderBlockSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/AxiomSOAPHeaderBlockSupport.aj?rev=1714858&r1=1714857&r2=1714858&view=diff
==============================================================================
--- 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/AxiomSOAPHeaderBlockSupport.aj
 (original)
+++ 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/common/AxiomSOAPHeaderBlockSupport.aj
 Tue Nov 17 19:45:12 2015
@@ -18,6 +18,8 @@
  */
 package org.apache.axiom.soap.impl.common;
 
+import java.text.ParseException;
+
 import javax.xml.namespace.QName;
 
 import org.apache.axiom.core.ClonePolicy;
@@ -64,10 +66,9 @@ public aspect AxiomSOAPHeaderBlockSuppor
     private boolean AxiomSOAPHeaderBlock.getBooleanAttributeValue(String key, 
QName qname) {
         String literal = getAttributeValue(key, qname);
         if (literal != null) {
-            Boolean value = getSOAPHelper().parseBoolean(literal);
-            if (value != null) {
-                return value.booleanValue();
-            } else {
+            try {
+                return getSOAPHelper().getBooleanType().parse(literal);
+            } catch (ParseException ex) {
                 throw new SOAPProcessingException(
                         "Invalid value for attribute " + qname.getLocalPart() 
+ " in header block " + getQName());
             }
@@ -82,17 +83,17 @@ public aspect AxiomSOAPHeaderBlockSuppor
     
     public final void AxiomSOAPHeaderBlock.setMustUnderstand(String 
mustUnderstand) throws SOAPProcessingException {
         SOAPHelper helper = getSOAPHelper();
-        Boolean value = helper.parseBoolean(mustUnderstand);
-        if (value != null) {
-            _setAttributeValue(helper.getMustUnderstandAttributeQName(), 
mustUnderstand);
-        } else {
+        try {
+            helper.getBooleanType().parse(mustUnderstand);
+        } catch (ParseException ex) {
             throw new SOAPProcessingException("Invalid value for 
mustUnderstand attribute");
         }
+        _setAttributeValue(helper.getMustUnderstandAttributeQName(), 
mustUnderstand);
     }
 
     public final void AxiomSOAPHeaderBlock.setMustUnderstand(boolean 
mustUnderstand) {
         SOAPHelper helper = getSOAPHelper();
-        _setAttributeValue(helper.getMustUnderstandAttributeQName(), 
helper.formatBoolean(mustUnderstand));
+        _setAttributeValue(helper.getMustUnderstandAttributeQName(), 
helper.getBooleanType().format(mustUnderstand));
     }
 
     public final String AxiomSOAPHeaderBlock.getRole() {
@@ -119,7 +120,7 @@ public aspect AxiomSOAPHeaderBlockSuppor
         if (attributeQName == null) {
             throw new UnsupportedOperationException("Not supported for " + 
helper.getSpecName());
         } else {
-            _setAttributeValue(attributeQName, helper.formatBoolean(relay));
+            _setAttributeValue(attributeQName, 
helper.getBooleanType().format(relay));
         }
     }
 

Added: 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java?rev=1714858&view=auto
==============================================================================
--- 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java
 (added)
+++ 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java
 Tue Nov 17 19:45:12 2015
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.soap.impl.intf;
+
+import java.text.ParseException;
+
+import org.apache.axiom.datatype.AbstractInvariantType;
+import org.apache.axiom.datatype.TypeHelper;
+
+final class SOAP11BooleanType extends AbstractInvariantType<Boolean> {
+    static final SOAP11BooleanType INSTANCE = new SOAP11BooleanType();
+    
+    private SOAP11BooleanType() {}
+    
+    public Boolean parse(String literal) throws ParseException {
+        int start = TypeHelper.getStartIndex(literal);
+        int end = TypeHelper.getEndIndex(literal);
+        if (end-start == 1) {
+            switch (literal.charAt(start)) {
+                case '0': return Boolean.FALSE;
+                case '1': return Boolean.TRUE;
+            }
+        }
+        throw new ParseException("Unexpected boolean literal", start);
+    }
+
+    public String format(Boolean value) {
+        return value ? "1" : "0";
+    }
+}

Propchange: 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAP11BooleanType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAPHelper.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAPHelper.java?rev=1714858&r1=1714857&r2=1714858&view=diff
==============================================================================
--- 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAPHelper.java
 (original)
+++ 
webservices/axiom/branches/datatypes/aspects/om-aspects/src/main/java/org/apache/axiom/soap/impl/intf/SOAPHelper.java
 Tue Nov 17 19:45:12 2015
@@ -20,6 +20,8 @@ package org.apache.axiom.soap.impl.intf;
 
 import javax.xml.namespace.QName;
 
+import org.apache.axiom.datatype.InvariantType;
+import org.apache.axiom.datatype.xsd.XSBooleanType;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
@@ -47,27 +49,12 @@ public abstract class SOAPHelper {
             AxiomSOAP11FaultReason.class,
             AxiomSOAP11FaultRole.class,
             AxiomSOAP11FaultDetail.class,
-            SOAP11Constants.ATTR_ACTOR, null) {
+            SOAP11Constants.ATTR_ACTOR, null,
+            SOAP11BooleanType.INSTANCE) {
         @Override
         public SOAPFactory getSOAPFactory(OMMetaFactory metaFactory) {
             return metaFactory.getSOAP11Factory();
         }
-
-        @Override
-        public Boolean parseBoolean(String literal) {
-            if (literal.equals("1")) {
-                return Boolean.TRUE;
-            } else if (literal.equals("0")) {
-                return Boolean.FALSE;
-            } else {
-                return null;
-            }
-        }
-
-        @Override
-        public String formatBoolean(boolean value) {
-            return value ? "1" : "0";
-        }
     };
     
     public static final SOAPHelper SOAP12 = new 
SOAPHelper(SOAP12Version.getSingleton(), "SOAP 1.2",
@@ -80,27 +67,12 @@ public abstract class SOAPHelper {
             AxiomSOAP12FaultReason.class,
             AxiomSOAP12FaultRole.class,
             AxiomSOAP12FaultDetail.class,
-            SOAP12Constants.SOAP_ROLE, SOAP12Constants.SOAP_RELAY) {
+            SOAP12Constants.SOAP_ROLE, SOAP12Constants.SOAP_RELAY,
+            XSBooleanType.INSTANCE) {
         @Override
         public SOAPFactory getSOAPFactory(OMMetaFactory metaFactory) {
             return metaFactory.getSOAP12Factory();
         }
-
-        @Override
-        public Boolean parseBoolean(String literal) {
-            if (literal.equals("true") || literal.equals("1")) {
-                return Boolean.TRUE;
-            } else if (literal.equals("false") || literal.equals("0")) {
-                return Boolean.FALSE;
-            } else {
-                return null;
-            }
-        }
-
-        @Override
-        public String formatBoolean(boolean value) {
-            return String.valueOf(value);
-        }
     };
     
     private final SOAPVersion version;
@@ -121,6 +93,7 @@ public abstract class SOAPHelper {
     private final QName mustUnderstandAttributeQName;
     private final QName roleAttributeQName;
     private final QName relayAttributeQName;
+    private final InvariantType<Boolean> booleanType;
     
     private SOAPHelper(SOAPVersion version, String specName,
             Class<? extends AxiomSOAPEnvelope> envelopeClass,
@@ -132,7 +105,8 @@ public abstract class SOAPHelper {
             Class<? extends AxiomSOAPFaultReason> faultReasonClass,
             Class<? extends AxiomSOAPFaultRole> faultRoleClass,
             Class<? extends AxiomSOAPFaultDetail> faultDetailClass,
-            String roleAttributeLocalName, String relayAttributeLocalName) {
+            String roleAttributeLocalName, String relayAttributeLocalName,
+            InvariantType<Boolean> booleanType) {
         this.version = version;
         namespace = new OMNamespaceImpl(version.getEnvelopeURI(),
                 SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
@@ -158,6 +132,7 @@ public abstract class SOAPHelper {
                 version.getEnvelopeURI(), roleAttributeLocalName, 
SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
         relayAttributeQName = relayAttributeLocalName == null ? null :
             new QName(version.getEnvelopeURI(), relayAttributeLocalName, 
SOAPConstants.SOAP_DEFAULT_NAMESPACE_PREFIX);
+        this.booleanType = booleanType;
     }
     
     public final SOAPVersion getVersion() {
@@ -254,6 +229,7 @@ public abstract class SOAPHelper {
         return relayAttributeQName;
     }
 
-    public abstract Boolean parseBoolean(String literal);
-    public abstract String formatBoolean(boolean value);
+    public InvariantType<Boolean> getBooleanType() {
+        return booleanType;
+    }
 }

Added: 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java?rev=1714858&view=auto
==============================================================================
--- 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java
 (added)
+++ 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java
 Tue Nov 17 19:45:12 2015
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.datatype.xsd;
+
+import org.apache.axiom.datatype.InvariantType;
+
+public interface XSBooleanType extends InvariantType<Boolean> {
+    XSBooleanType INSTANCE = new XSBooleanTypeImpl();
+}

Propchange: 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java?rev=1714858&view=auto
==============================================================================
--- 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java
 (added)
+++ 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java
 Tue Nov 17 19:45:12 2015
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.datatype.xsd;
+
+import java.text.ParseException;
+
+import org.apache.axiom.datatype.AbstractInvariantType;
+import org.apache.axiom.datatype.TypeHelper;
+
+final class XSBooleanTypeImpl extends AbstractInvariantType<Boolean> 
implements XSBooleanType {
+    private static boolean equals(String s1, int start, String s2) {
+        for (int i=0, len=s2.length(); i<len; i++) {
+            if (s1.charAt(start+i) != s2.charAt(i)) {
+                return false;
+            }
+        }
+        return true;
+    }
+    
+    public Boolean parse(String literal) throws ParseException {
+        int start = TypeHelper.getStartIndex(literal);
+        int end = TypeHelper.getEndIndex(literal);
+        switch (end-start) {
+            case 1:
+                switch (literal.charAt(start)) {
+                    case '0': return Boolean.FALSE;
+                    case '1': return Boolean.TRUE;
+                }
+                break;
+            case 4:
+                if (equals(literal, start, "true")) {
+                    return Boolean.TRUE;
+                }
+                break;
+            case 5:
+                if (equals(literal, start, "false")) {
+                    return Boolean.FALSE;
+                }
+        }
+        throw new ParseException("Unexpected boolean literal", start);
+    }
+
+    public String format(Boolean value) {
+        return value.toString();
+    }
+}

Propchange: 
webservices/axiom/branches/datatypes/datatypes/src/main/java/org/apache/axiom/datatype/xsd/XSBooleanTypeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to