Permalink
Browse files

Merge pull request #10 from baranowb/AS7-4837

ProeprtyEditorFinder service instead of PropertyEditorManager
  • Loading branch information...
2 parents 0067333 + 1978613 commit 1ca910d7198b1d1e758ad9a2b74356754cedc6e0 @baranowb committed Jun 5, 2012
Showing with 668 additions and 543 deletions.
  1. +1 −1 src/main/java/org/jboss/common/beans/property/AtomicBooleanEditor.java
  2. +1 −1 src/main/java/org/jboss/common/beans/property/AtomicIntegerEditor.java
  3. +1 −1 src/main/java/org/jboss/common/beans/property/AtomicLongEditor.java
  4. +89 −0 src/main/java/org/jboss/common/beans/property/BeanUtils.java
  5. +1 −1 src/main/java/org/jboss/common/beans/property/BigDecimalEditor.java
  6. +1 −1 src/main/java/org/jboss/common/beans/property/BigIntegerEditor.java
  7. +1 −1 src/main/java/org/jboss/common/beans/property/BooleanEditor.java
  8. +1 −1 src/main/java/org/jboss/common/beans/property/ByteEditor.java
  9. +1 −1 src/main/java/org/jboss/common/beans/property/CharacterArrayEditor.java
  10. +1 −1 src/main/java/org/jboss/common/beans/property/CharacterEditor.java
  11. +1 −1 src/main/java/org/jboss/common/beans/property/ClassEditor.java
  12. +1 −1 src/main/java/org/jboss/common/beans/property/DateEditor.java
  13. +1 −1 src/main/java/org/jboss/common/beans/property/DocumentEditor.java
  14. +1 −1 src/main/java/org/jboss/common/beans/property/DoubleEditor.java
  15. +1 −1 src/main/java/org/jboss/common/beans/property/ElementEditor.java
  16. +1 −1 src/main/java/org/jboss/common/beans/property/FileEditor.java
  17. +1 −1 src/main/java/org/jboss/common/beans/property/FloatEditor.java
  18. +8 −4 src/main/java/org/jboss/common/beans/property/GenericArrayPropertyEditor.java
  19. +1 −1 src/main/java/org/jboss/common/beans/property/InetAddressEditor.java
  20. +2 −2 src/main/java/org/jboss/common/beans/property/{IntArrayEditor.java → IntegerArrayEditor.java}
  21. +1 −1 src/main/java/org/jboss/common/beans/property/IntegerEditor.java
  22. +1 −1 src/main/java/org/jboss/common/beans/property/LocaleEditor.java
  23. +1 −1 src/main/java/org/jboss/common/beans/property/LongEditor.java
  24. +1 −1 src/main/java/org/jboss/common/beans/property/PropertiesEditor.java
  25. +0 −445 src/main/java/org/jboss/common/beans/property/PropertyEditors.java
  26. +1 −1 src/main/java/org/jboss/common/beans/property/ShortEditor.java
  27. +1 −1 src/main/java/org/jboss/common/beans/property/StringEditor.java
  28. +1 −1 src/main/java/org/jboss/common/beans/property/URIEditor.java
  29. +1 −1 src/main/java/org/jboss/common/beans/property/URLEditor.java
  30. +193 −0 src/main/java/org/jboss/common/beans/property/finder/DefaultPropertyEditorFinder.java
  31. +155 −0 src/main/java/org/jboss/common/beans/property/finder/PropertyEditorFinder.java
  32. +1 −0 src/main/resources/META-INF/services/org.jboss.common.beans.property.finder.PropertyEditorFinder
  33. +6 −3 src/test/java/org/jboss/common/beans/property/PropertyEditorTester.java
  34. +0 −64 src/test/java/org/jboss/common/beans/property/PropertyEditorsTestCase.java
  35. +53 −0 src/test/java/org/jboss/common/beans/property/finder/PropertyEditorFinderTestCase.java
  36. +90 −0 src/test/java/org/jboss/common/beans/property/finder/Uranus.java
  37. +46 −0 src/test/java/org/jboss/common/beans/property/finder/UranusEditor.java
@@ -39,7 +39,7 @@ public AtomicBooleanEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
setValue(new AtomicBoolean(Boolean.parseBoolean(text)));
@@ -37,7 +37,7 @@ public AtomicIntegerEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -36,7 +36,7 @@ public AtomicLongEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -0,0 +1,89 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2011, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.common.beans.property;
+
+/**
+ * @author baranowb
+ *
+ */
+public final class BeanUtils {
+ /** The null string */
+ private static final String NULL = "null";
+
+ public static Class<?> findClass(String name) throws ClassNotFoundException {
+ try {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ if (loader == null) {
+ loader = ClassLoader.getSystemClassLoader();
+ }
+ if (loader != null) {
+ return Class.forName(name, false, loader);
+ }
+
+ } catch (Exception e) {
+ }
+ return Class.forName(name);
+ }
+
+ public static Class<?> findClass(String name, ClassLoader loader) throws ClassNotFoundException {
+ if (loader != null) {
+ try {
+ return Class.forName(name, false, loader);
+ } catch (Exception e) {
+ }
+ }
+ return findClass(name);
+ }
+
+ /**
+ * Whether a string is interpreted as the null value, including the empty string.
+ *
+ * @param value the value
+ * @return true when the string has the value null
+ */
+ public static boolean isNull(final String value) {
+ return isNull(value, true, true);
+ }
+
+ /**
+ * Whether a string is interpreted as the null value
+ *
+ * @param value the value
+ * @param trim whether to trim the string
+ * @param empty whether to include the empty string as null
+ * @return true when the string has the value null
+ */
+ public static boolean isNull(final String value, final boolean trim, final boolean empty) {
+
+ // No value?
+ if (value == null)
+ return true;
+ // Trim the text when requested
+ String trimmed = trim ? value.trim() : value;
+ // Is the empty string null?
+ if (empty && trimmed.length() == 0)
+ return true;
+ // Just check it.
+ return NULL.equalsIgnoreCase(trimmed);
+ }
+}
@@ -36,7 +36,7 @@ public BigDecimalEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -36,7 +36,7 @@ public BigIntegerEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -39,7 +39,7 @@ public BooleanEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -37,7 +37,7 @@ public ByteEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -40,7 +40,7 @@ public CharacterArrayEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)){
+ if (BeanUtils.isNull(text)){
setValue(null);
return;
}
@@ -35,7 +35,7 @@ public CharacterEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -35,7 +35,7 @@ public ClassEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -108,7 +108,7 @@ public void setValue(Object value) {
*/
@Override
public void setAsText(String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -41,7 +41,7 @@ public DocumentEditor() {
*/
@Override
public void setAsText(String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -38,7 +38,7 @@ public DoubleEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -52,7 +52,7 @@ public ElementEditor() {
*/
@Override
public void setAsText(String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -37,7 +37,7 @@ public FileEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
} else {
try {
@@ -37,7 +37,7 @@ public FloatEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -26,6 +26,9 @@
import java.lang.reflect.Array;
import java.util.StringTokenizer;
+import org.jboss.common.beans.property.finder.DefaultPropertyEditorFinder;
+import org.jboss.common.beans.property.finder.PropertyEditorFinder;
+
/**
* Generic array support editor. Depending on type of array it performs all required operations to transform from/to text. It
* requires array cell property editor to be present - <b>ProperyEditorManager.findEditor(arrayClass.getComponentType()) !=
@@ -56,7 +59,8 @@ public GenericArrayPropertyEditor(Class<T> initType) {
this.cellType = initType.getComponentType();
// generic interface.
- java.beans.PropertyEditor cellPropertyEditor = PropertyEditors.findEditor(this.cellType);
+
+ java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType);
// jic
if (cellPropertyEditor == null) {
throw new IllegalArgumentException("No editor found for '" + this.cellType + "'");
@@ -70,12 +74,12 @@ public GenericArrayPropertyEditor(Class<T> initType) {
*/
@Override
public void setAsText(String text) throws IllegalArgumentException {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
this.setValue(null);
return;
}
// generic interface.
- java.beans.PropertyEditor cellPropertyEditor = PropertyEditors.findEditor(this.cellType);
+ java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType);
String[] cellStringValues = tokenize(text);
Object reflectiveArray = Array.newInstance(this.cellType, cellStringValues.length);
@@ -100,7 +104,7 @@ public String getAsText() {
return null;
}
// generic interface.
- java.beans.PropertyEditor cellPropertyEditor = PropertyEditors.findEditor(this.cellType);
+ java.beans.PropertyEditor cellPropertyEditor = PropertyEditorFinder.getInstance().find(this.cellType);
int length = Array.getLength(reflectiveArray);
String[] cellStringValues = new String[length];
@@ -39,7 +39,7 @@ public InetAddressEditor() {
@Override
public void setAsText(final String text) throws IllegalArgumentException {
try {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -25,9 +25,9 @@
* A property editor for int[].
*
*/
-public class IntArrayEditor extends GenericArrayPropertyEditor<int[]> {
+public class IntegerArrayEditor extends GenericArrayPropertyEditor<int[]> {
- public IntArrayEditor() {
+ public IntegerArrayEditor() {
super(int[].class);
}
@@ -37,7 +37,7 @@ public IntegerEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -37,7 +37,7 @@ public LocaleEditor() {
@Override
public void setAsText(String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -37,7 +37,7 @@ public LongEditor() {
*/
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
@@ -39,7 +39,7 @@ public PropertiesEditor() {
@Override
public void setAsText(final String text) {
- if (PropertyEditors.isNull(text)) {
+ if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Oops, something went wrong.

0 comments on commit 1ca910d

Please sign in to comment.