rsitze 2002/06/10 15:54:50 Modified: java/src/org/apache/axis/transport/http AxisServlet.java java/src/org/apache/axis/encoding DeserializationContextImpl.java DeserializerImpl.java java/src/org/apache/axis/message RPCHandler.java java/src/org/apache/axis MessageContext.java AxisEngine.java java/src/org/apache/axis/wsdl/toJava JavaBeanWriter.java java/src/org/apache/axis/utils Admin.java JavaUtils.java java/src/org/apache/axis/handlers SimpleAuthorizationHandler.java java/src/org/apache/axis/deployment/wsdd WSDDDeployableItem.java Log: Consolidate non-boolean tests for 'true' (String/Integer) in JavaUtils. JavaUtils is getting to be a mess... Revision Changes Path 1.111 +2 -6 xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java Index: AxisServlet.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/AxisServlet.java,v retrieving revision 1.110 retrieving revision 1.111 diff -u -r1.110 -r1.111 --- AxisServlet.java 9 Jun 2002 02:01:10 -0000 1.110 +++ AxisServlet.java 10 Jun 2002 22:54:49 -0000 1.111 @@ -161,12 +161,12 @@ INIT_PROPERTY_TRANSPORT_NAME, HTTPTransport.DEFAULT_TRANSPORT_NAME); - if (isTrue(getOption(context, INIT_PROPERTY_USE_SECURITY, null))) { + if (JavaUtils.isTrue(getOption(context, INIT_PROPERTY_USE_SECURITY, null))) { securityProvider = new ServletSecurityProvider(); } enableList = - isTrue(getOption(context, INIT_PROPERTY_ENABLE_LIST, null)); + JavaUtils.isTrue(getOption(context, INIT_PROPERTY_ENABLE_LIST, null)); jwsClassDir = getOption(context, INIT_PROPERTY_JWS_CLASS_DIR, null); if (jwsClassDir != null) { @@ -767,10 +767,6 @@ return (value != null) ? value : dephault; } - private static boolean isTrue(String value) { - return (value != null) && value.equalsIgnoreCase("true"); - } - /** * Provided to allow overload of default JWSClassDir * by derived class. 1.35 +3 -6 xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java Index: DeserializationContextImpl.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializationContextImpl.java,v retrieving revision 1.34 retrieving revision 1.35 diff -u -r1.34 -r1.35 --- DeserializationContextImpl.java 5 Jun 2002 21:49:20 -0000 1.34 +++ DeserializationContextImpl.java 10 Jun 2002 22:54:49 -0000 1.35 @@ -401,12 +401,9 @@ * @return true if xsi:nil is true */ public boolean isNil(Attributes attrs) { - if (attrs == null) { - return false; - } - String nil = Constants.getValue(attrs, Constants.URIS_SCHEMA_XSI, - "nil"); - return (nil != null && nil.equals("true")); + return JavaUtils.isTrueExplicitly( + Constants.getValue(attrs, Constants.URIS_SCHEMA_XSI, "nil"), + false); } /** 1.15 +2 -3 xml-axis/java/src/org/apache/axis/encoding/DeserializerImpl.java Index: DeserializerImpl.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/encoding/DeserializerImpl.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- DeserializerImpl.java 31 May 2002 19:08:07 -0000 1.14 +++ DeserializerImpl.java 10 Jun 2002 22:54:49 -0000 1.15 @@ -323,10 +323,9 @@ // If the xsi:nil attribute, set the value to null and return since // there is nothing to deserialize. - String nil = Constants.getValue(attributes, + if (JavaUtils.isTrue(Constants.getValue(attributes, Constants.URIS_SCHEMA_XSI, - "nil"); - if (nil != null && nil.equals("true")) { + "nil"))) { value = null; isNil = true; return; 1.44 +2 -4 xml-axis/java/src/org/apache/axis/message/RPCHandler.java Index: RPCHandler.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/RPCHandler.java,v retrieving revision 1.43 retrieving revision 1.44 diff -u -r1.43 -r1.44 --- RPCHandler.java 31 May 2002 19:08:09 -0000 1.43 +++ RPCHandler.java 10 Jun 2002 22:54:49 -0000 1.44 @@ -211,10 +211,8 @@ } - String isNil = attributes.getValue(Constants.URI_2001_SCHEMA_XSI, - "nil"); - - if ( isNil != null && isNil.equals("true") ) + if (JavaUtils.isTrue(attributes.getValue(Constants.URI_2001_SCHEMA_XSI, + "nil"))) return( new DeserializerImpl() ); Deserializer dser = null; 1.99 +2 -36 xml-axis/java/src/org/apache/axis/MessageContext.java Index: MessageContext.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/MessageContext.java,v retrieving revision 1.98 retrieving revision 1.99 diff -u -r1.98 -r1.99 --- MessageContext.java 9 Jun 2002 02:01:10 -0000 1.98 +++ MessageContext.java 10 Jun 2002 22:54:49 -0000 1.99 @@ -644,24 +644,7 @@ * All other types return 'true' */ public boolean isPropertyTrue(String propName) { - Object val = getProperty(propName); - if ( val == null ) return( false ); - if ( val instanceof Boolean ) { - Boolean b = (Boolean) val ; - return( b.booleanValue() ); - } - if ( val instanceof Integer ) { - Integer i = (Integer) val ; - if ( i.intValue() == 0 ) return( false ); - return( true ); - } - if ( val instanceof String ) { - String s = (String) val ; - if ( s.equalsIgnoreCase("false") || - s.equalsIgnoreCase("no") ) return( false ); - return( true ); - } - return( true ); + return isPropertyTrue(propName, false); } /** @@ -674,24 +657,7 @@ * All other types return 'true' */ public boolean isPropertyTrue(String propName, boolean defaultVal) { - Object val = getProperty(propName); - if ( val == null ) return( defaultVal ); - if ( val instanceof Boolean ) { - Boolean b = (Boolean) val ; - return( b.booleanValue() ); - } - if ( val instanceof Integer ) { - Integer i = (Integer) val ; - if ( i.intValue() == 0 ) return( false ); - return( true ); - } - if ( val instanceof String ) { - String s = (String) val ; - if ( s.equalsIgnoreCase("false") || - s.equalsIgnoreCase("no") ) return( false ); - return( true ); - } - return( true ); + return JavaUtils.isTrue(getProperty(propName), defaultVal); } /** 1.79 +1 -2 xml-axis/java/src/org/apache/axis/AxisEngine.java Index: AxisEngine.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisEngine.java,v retrieving revision 1.78 retrieving revision 1.79 diff -u -r1.78 -r1.79 --- AxisEngine.java 4 Jun 2002 22:58:32 -0000 1.78 +++ AxisEngine.java 10 Jun 2002 22:54:49 -0000 1.79 @@ -359,8 +359,7 @@ if (val != null) { if (val instanceof Boolean) continue; - if (val instanceof String && - "false".equalsIgnoreCase((String)val)) { + if (JavaUtils.isFalse(val)) { setOption(BOOLEAN_OPTIONS[i], Boolean.FALSE); continue; } 1.17 +1 -3 xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java Index: JavaBeanWriter.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/wsdl/toJava/JavaBeanWriter.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- JavaBeanWriter.java 7 Jun 2002 12:45:08 -0000 1.16 +++ JavaBeanWriter.java 10 Jun 2002 22:54:50 -0000 1.17 @@ -222,9 +222,7 @@ protected String getClassModifiers() { Node node = type.getNode(); if (node != null) { - String abstractValue = Utils.getAttribute(node, "abstract"); - if (abstractValue != null && - abstractValue.equalsIgnoreCase("true")) { + if (JavaUtils.isTrue(Utils.getAttribute(node, "abstract"))) { return super.getClassModifiers() + "abstract "; } } 1.112 +20 -24 xml-axis/java/src/org/apache/axis/utils/Admin.java Index: Admin.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Admin.java,v retrieving revision 1.111 retrieving revision 1.112 diff -u -r1.111 -r1.112 --- Admin.java 31 May 2002 19:08:09 -0000 1.111 +++ Admin.java 10 Jun 2002 22:54:50 -0000 1.112 @@ -193,30 +193,26 @@ * IP, unless the remoteAdmin option is set. */ Handler serviceHandler = msgContext.getService(); - if (serviceHandler != null) { - String remoteAdmin = (String)serviceHandler. - getOption("enableRemoteAdmin"); - if ((remoteAdmin == null) || - !remoteAdmin.equals("true")) { - String remoteIP = - msgContext.getStrProp(Constants.MC_REMOTE_ADDR); - if (remoteIP != null) { - if (!remoteIP.equals("127.0.0.1")) { - try { - InetAddress myAddr = InetAddress.getLocalHost(); - InetAddress remoteAddr = - InetAddress.getByName(remoteIP); - - if (!myAddr.equals(remoteAddr)) - throw new AxisFault("Server.Unauthorized", - JavaUtils.getMessage("noAdminAccess00"), - null, null); - } catch (UnknownHostException e) { - throw new AxisFault("Server.UnknownHost", - JavaUtils.getMessage("unknownHost00"), - null, null); - } - } + if (serviceHandler != null && + !JavaUtils.isTrue(serviceHandler.getOption("enableRemoteAdmin"))) { + + String remoteIP = msgContext.getStrProp(Constants.MC_REMOTE_ADDR); + if (remoteIP != null && + !remoteIP.equals("127.0.0.1")) { + + try { + InetAddress myAddr = InetAddress.getLocalHost(); + InetAddress remoteAddr = + InetAddress.getByName(remoteIP); + + if (!myAddr.equals(remoteAddr)) + throw new AxisFault("Server.Unauthorized", + JavaUtils.getMessage("noAdminAccess00"), + null, null); + } catch (UnknownHostException e) { + throw new AxisFault("Server.UnknownHost", + JavaUtils.getMessage("unknownHost00"), + null, null); } } } 1.46 +121 -0 xml-axis/java/src/org/apache/axis/utils/JavaUtils.java Index: JavaUtils.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/JavaUtils.java,v retrieving revision 1.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- JavaUtils.java 5 Jun 2002 21:49:20 -0000 1.45 +++ JavaUtils.java 10 Jun 2002 22:54:50 -0000 1.46 @@ -881,4 +881,125 @@ pw.close(); return sw.toString(); } + + /** + * Tests the String 'value': + * return 'false' if its 'false', '0', or 'no' - else 'true' + * + * Follow in 'C' tradition of boolean values: + * false is specific (0), everything else is true; + */ + public static final boolean isTrue(String value) { + return !isFalseExplicitly(value); + } + + /** + * Tests the String 'value': + * return 'true' if its 'true', '1', or 'yes' - else 'false' + */ + public static final boolean isTrueExplicitly(String value) { + return value != null && + (value.equalsIgnoreCase("true") || + value.equals("1") || + value.equalsIgnoreCase("yes")); + } + + /** + * Tests the Object 'value': + * if its null, return default. + * if its a Boolean, return booleanValue() + * if its an Integer, return 'false' if its '0' else 'true' + * if its a String, return isTrueExplicitly((String)value). + * All other types return 'true' + */ + public static final boolean isTrueExplicitly(Object value, boolean defaultVal) { + if ( value == null ) return defaultVal; + if ( value instanceof Boolean ) { + return ((Boolean)value).booleanValue(); + } + if ( value instanceof Integer ) { + return ((Integer)value).intValue() != 0; + } + if ( value instanceof String ) { + return isTrueExplicitly( (String)value ); + } + return true; + } + + /** + * Tests the Object 'value': + * if its null, return default. + * if its a Boolean, return booleanValue() + * if its an Integer, return 'false' if its '0' else 'true' + * if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' + * All other types return 'true' + */ + public static final boolean isTrue(Object value, boolean defaultVal) { + return !isFalseExplicitly(value, !defaultVal); + } + + public static final boolean isTrue(Object value) { + return isTrue(value, false); + } + + /** + * Tests the String 'value': + * return 'true' if its 'false', '0', or 'no' - else 'false' + * + * Follow in 'C' tradition of boolean values: + * false is specific (0), everything else is true; + */ + public static final boolean isFalse(String value) { + return isFalseExplicitly(value); + } + + /** + * Tests the String 'value': + * return 'true' if its null, 'false', '0', or 'no' - else 'false' + */ + public static final boolean isFalseExplicitly(String value) { + return value == null || + value.equalsIgnoreCase("false") || + value.equals("0") || + value.equalsIgnoreCase("no"); + } + + /** + * Tests the Object 'value': + * if its null, return default. + * if its a Boolean, return !booleanValue() + * if its an Integer, return 'true' if its '0' else 'false' + * if its a String, return isFalseExplicitly((String)value). + * All other types return 'false' + */ + public static final boolean isFalseExplicitly(Object value, boolean defaultVal) { + if ( value == null ) return defaultVal; + if ( value instanceof Boolean ) { + return !((Boolean)value).booleanValue(); + } + if ( value instanceof Integer ) { + return ((Integer)value).intValue() == 0; + } + if ( value instanceof String ) { + return isFalseExplicitly( (String)value ); + } + return false; + } + + /** + * Tests the Object 'value': + * if its null, return default. + * if its a Boolean, return booleanValue() + * if its an Integer, return 'false' if its '0' else 'true' + * if its a String, return 'false' if its 'false', 'no', or '0' - else 'true' + * All other types return 'true' + */ + public static final boolean isFalse(Object value, boolean defaultVal) { + return isFalseExplicitly(value, defaultVal); + } + + public static final boolean isFalse(Object value) { + return isFalse(value, true); + } + } 1.30 +2 -4 xml-axis/java/src/org/apache/axis/handlers/SimpleAuthorizationHandler.java Index: SimpleAuthorizationHandler.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/SimpleAuthorizationHandler.java,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- SimpleAuthorizationHandler.java 9 May 2002 18:25:17 -0000 1.29 +++ SimpleAuthorizationHandler.java 10 Jun 2002 22:54:50 -0000 1.30 @@ -92,10 +92,8 @@ log.debug("Enter: SimpleAuthorizationHandler::invoke"); } - boolean allowByDefault = false; - String optVal = (String)getOption("allowByDefault"); - if ((optVal != null) && (optVal.equalsIgnoreCase("true"))) - allowByDefault = true; + boolean allowByDefault = + JavaUtils.isTrue(getOption("allowByDefault")); AuthenticatedUser user = (AuthenticatedUser)msgContext. getProperty(MessageContext.AUTHUSER); 1.34 +1 -2 xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDeployableItem.java Index: WSDDDeployableItem.java =================================================================== RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/deployment/wsdd/WSDDDeployableItem.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- WSDDDeployableItem.java 5 Jun 2002 23:24:35 -0000 1.33 +++ WSDDDeployableItem.java 10 Jun 2002 22:54:50 -0000 1.34 @@ -166,8 +166,7 @@ String pname = param.getAttribute(ATTR_NAME); String value = param.getAttribute(ATTR_VALUE); String locked = param.getAttribute(ATTR_LOCKED); - parameters.put(pname, value, (locked != null && - locked.equalsIgnoreCase("true"))); + parameters.put(pname, value, JavaUtils.isTrueExplicitly(locked)); } }