Author: jpell
Date: Wed Nov 28 22:05:43 2012
New Revision: 1414957
URL: http://svn.apache.org/viewvc?rev=1414957&view=rev
Log:
CXF-4662 - added support for specifying the jaxb.scanPackages using a Boolean
or a string.
Plus a small amount of refactoring to add a PropertyUtils class to cxf-api.
This new class is used by the JAXBDataBinding scan packages check. I also
changed MessageUtils.isTrue to delegate to PropertyUtils
Added:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java
(with props)
cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java
(with props)
cxf/trunk/rt/databinding/jaxb/.pmdruleset
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageUtils.java
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Added: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java?rev=1414957&view=auto
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java
(added)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java
Wed Nov 28 22:05:43 2012
@@ -0,0 +1,91 @@
+/**
+ * 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.cxf.common.util;
+
+import java.util.Map;
+
+/**
+ * Holder of generic property related methods
+ */
+public final class PropertyUtils {
+ private PropertyUtils() {
+ }
+
+ public static boolean isTrue(Map<String, Object> props, String key) {
+ if (props == null || key == null) {
+ return false;
+ } else {
+ return isTrue(props.get(key));
+ }
+ }
+
+ /**
+ * It might seem odd to return 'true' if a property == FALSE, but it
+ * is required sometimes.
+ *
+ * @param props
+ * @param key
+ * @return
+ */
+ public static boolean isFalse(Map<String, Object> props, String key) {
+ if (props == null || key == null) {
+ return false;
+ } else {
+ return isFalse(props.get(key));
+ }
+ }
+
+ /**
+ * Returns true if a value is either the String "true" (regardless of
case) or Boolean.TRUE.
+ * @param value
+ * @return true if value is either the String "true" or Boolean.TRUE.
Otherwise returns false.
+ */
+ public static boolean isTrue(Object property) {
+ if (property == null) {
+ return false;
+ }
+
+ if (Boolean.TRUE.equals(property) ||
"true".equalsIgnoreCase(property.toString())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * It might seem odd to return 'true' if a property == FALSE, but it is
required sometimes.
+ *
+ * Returns false if a value is either the String "false" (regardless of
case) or Boolean.FALSE.
+ * @param value
+ * @return false if value is either the String "false" or Boolean.FALSE.
Otherwise returns
+ * true.
+ */
+ public static boolean isFalse(Object property) {
+ if (property == null) {
+ return false;
+ }
+
+ if (Boolean.FALSE.equals(property) ||
"false".equalsIgnoreCase(property.toString())) {
+ return true;
+ }
+
+ return false;
+ }
+}
Propchange:
cxf/trunk/api/src/main/java/org/apache/cxf/common/util/PropertyUtils.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageUtils.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageUtils.java?rev=1414957&r1=1414956&r2=1414957&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageUtils.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/message/MessageUtils.java Wed
Nov 28 22:05:43 2012
@@ -21,6 +21,8 @@ package org.apache.cxf.message;
import org.w3c.dom.Node;
+import org.apache.cxf.common.util.PropertyUtils;
+
/**
* Holder for utility methods relating to messages.
@@ -117,22 +119,14 @@ public final class MessageUtils {
* @return true if value is either the String "true" or Boolean.TRUE
*/
public static boolean isTrue(Object value) {
- if (value == null) {
- return false;
- }
-
- if (Boolean.TRUE.equals(value) ||
"true".equalsIgnoreCase(value.toString())) {
- return true;
- }
-
- return false;
+ // TODO - consider deprecation as this really belongs in PropertyUtils
+ return PropertyUtils.isTrue(value);
}
-
public static boolean getContextualBoolean(Message m, String key, boolean
defaultValue) {
Object o = m.getContextualProperty(key);
if (o != null) {
- return isTrue(o);
+ return PropertyUtils.isTrue(o);
}
return defaultValue;
}
Added:
cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java?rev=1414957&view=auto
==============================================================================
---
cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java
(added)
+++
cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java
Wed Nov 28 22:05:43 2012
@@ -0,0 +1,98 @@
+/**
+ * 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.cxf.common.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class PropertyUtilsTest extends Assert {
+ private static final String TEST_KEY = "my.key";
+
+ @Test
+ public void testIsTrueWithMap() {
+ Map<String, Object> props = new HashMap<String, Object>();
+ assertFalse(PropertyUtils.isTrue(props, TEST_KEY));
+
+ props.put(TEST_KEY, "false");
+ assertFalse(PropertyUtils.isTrue(props, TEST_KEY));
+
+ props.put(TEST_KEY, Boolean.FALSE);
+ assertFalse(PropertyUtils.isTrue(props, TEST_KEY));
+
+ props.put(TEST_KEY, "true");
+ assertTrue(PropertyUtils.isTrue(props, TEST_KEY));
+
+ props.put(TEST_KEY, Boolean.TRUE);
+ assertTrue(PropertyUtils.isTrue(props, TEST_KEY));
+ }
+
+ @Test
+ public void testIsFalseWithMap() {
+ Map<String, Object> props = new HashMap<String, Object>();
+ assertFalse(PropertyUtils.isFalse(props, TEST_KEY));
+
+ props.put(TEST_KEY, "true");
+ assertFalse(PropertyUtils.isFalse(props, TEST_KEY));
+
+ props.put(TEST_KEY, Boolean.TRUE);
+ assertFalse(PropertyUtils.isFalse(props, TEST_KEY));
+
+ props.put(TEST_KEY, "false");
+ assertTrue(PropertyUtils.isFalse(props, TEST_KEY));
+
+ props.put(TEST_KEY, Boolean.FALSE);
+ assertTrue(PropertyUtils.isFalse(props, TEST_KEY));
+ }
+
+ @Test
+ public void testTrue() {
+ assertTrue(PropertyUtils.isTrue(Boolean.TRUE));
+ assertTrue(PropertyUtils.isTrue("true"));
+ assertTrue(PropertyUtils.isTrue("TRUE"));
+ assertTrue(PropertyUtils.isTrue("TrUe"));
+
+ assertFalse(PropertyUtils.isTrue(Boolean.FALSE));
+ assertFalse(PropertyUtils.isTrue("false"));
+ assertFalse(PropertyUtils.isTrue("FALSE"));
+ assertFalse(PropertyUtils.isTrue("FaLSE"));
+ assertFalse(PropertyUtils.isTrue(null));
+ assertFalse(PropertyUtils.isTrue(""));
+ assertFalse(PropertyUtils.isTrue("other"));
+ }
+
+ @Test
+ public void testFalse() {
+ assertTrue(PropertyUtils.isFalse(Boolean.FALSE));
+ assertTrue(PropertyUtils.isFalse("false"));
+ assertTrue(PropertyUtils.isFalse("FALSE"));
+ assertTrue(PropertyUtils.isFalse("FaLSE"));
+
+ assertFalse(PropertyUtils.isFalse(Boolean.TRUE));
+ assertFalse(PropertyUtils.isFalse("true"));
+ assertFalse(PropertyUtils.isFalse("TRUE"));
+ assertFalse(PropertyUtils.isFalse("TrUe"));
+ assertFalse(PropertyUtils.isFalse(null));
+ assertFalse(PropertyUtils.isFalse(""));
+ assertFalse(PropertyUtils.isFalse("other"));
+ }
+}
Propchange:
cxf/trunk/api/src/test/java/org/apache/cxf/common/util/PropertyUtilsTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: cxf/trunk/rt/databinding/jaxb/.pmdruleset
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/.pmdruleset?rev=1414957&view=auto
==============================================================================
--- cxf/trunk/rt/databinding/jaxb/.pmdruleset (added)
+++ cxf/trunk/rt/databinding/jaxb/.pmdruleset Wed Nov 28 22:05:43 2012
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<ruleset xmlns="http://pmd.sf.net/ruleset/1.0.0" name="M2Eclipse PMD RuleSet"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd">
+ <description/>
+
<exclude-pattern>.*/home/jason/Development/cxf-trunk/rt/databinding/jaxb/target.*</exclude-pattern>
+ <rule ref="rulesets/basic.xml/BooleanInstantiation"/>
+ <rule ref="rulesets/basic.xml/CollapsibleIfStatements"/>
+ <rule ref="rulesets/basic.xml/DoubleCheckedLocking"/>
+ <rule ref="rulesets/basic.xml/EmptyStatementNotInLoop"/>
+ <rule ref="rulesets/basic.xml/ForLoopShouldBeWhileLoop"/>
+ <rule ref="rulesets/basic.xml/JumbledIncrementer"/>
+ <rule ref="rulesets/basic.xml/ReturnFromFinallyBlock"/>
+ <rule ref="rulesets/basic.xml/UnconditionalIfStatement"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryConversionTemporary"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryFinalModifier"/>
+ <rule ref="rulesets/basic.xml/UnnecessaryReturn"/>
+ <rule ref="rulesets/design.xml/AvoidProtectedFieldInFinalClass"/>
+ <rule ref="rulesets/design.xml/ConstructorCallsOverridableMethod"/>
+ <rule ref="rulesets/design.xml/IdempotentOperations"/>
+ <rule ref="rulesets/design.xml/OptimizableToArrayCall"/>
+ <rule ref="rulesets/design.xml/PositionLiteralsFirstInComparisons"/>
+ <rule ref="rulesets/design.xml/SimplifyBooleanExpressions"/>
+ <rule ref="rulesets/design.xml/SimplifyBooleanReturns"/>
+ <rule ref="rulesets/design.xml/SimplifyConditional"/>
+ <rule ref="rulesets/design.xml/UnnecessaryLocalBeforeReturn"/>
+ <rule ref="rulesets/logging-java.xml/LoggerIsNotStaticFinal"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
+ <rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
+ <rule class="net.sourceforge.pmd.rules.XPathRule" dfa="false"
externalInfoUrl="" message="Don't use Logger.getLogger(...), use
LogUtils.getL7dLogger(....) instead" name="DontUseLoggerGetLogger"
typeResolution="true">
+ <description>Don't use Logger.getLogger(...), use
LogUtils.getL7dLogger(....) instead</description>
+ <priority>2</priority>
+ <properties>
+ <property name="xpath">
+ <value><![CDATA[
+
+//PrimaryPrefix/Name[ends-with(@Image, 'Logger.getLogger') and
//PackageDeclaration/Name[starts-with(@Image, 'org.apache.cxf')] and
not(//ExtendsList/ClassOrInterfaceType[contains(@Image, 'Service')])]
+
+ ]]></value>
+ </property>
+ </properties>
+ </rule>
+</ruleset>
Modified:
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=1414957&r1=1414956&r2=1414957&view=diff
==============================================================================
---
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++
cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Wed Nov 28 22:05:43 2012
@@ -66,6 +66,7 @@ import org.apache.cxf.common.jaxb.JAXBUt
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.PropertyUtils;
import org.apache.cxf.common.util.ReflectionUtil;
import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.cxf.databinding.AbstractDataBinding;
@@ -231,7 +232,9 @@ public class JAXBDataBinding extends Abs
extraClass = (Class[])o;
}
- if (props != null && "false".equalsIgnoreCase((String)
props.get(JAXB_SCAN_PACKAGES))) {
+ // the default for scan packages is true, so the jaxb scan packages
+ // property must be explicitly set to false to disable it
+ if (PropertyUtils.isFalse(props, JAXB_SCAN_PACKAGES)) {
scanPackages = false;
}
}
@@ -822,6 +825,4 @@ public class JAXBDataBinding extends Abs
public List<Interceptor<? extends Message>> getOutInterceptors() {
return out;
}
-
-
}