Skip to content

Commit

Permalink
Merge pull request jboss#10 from baranowb/AS7-4837
Browse files Browse the repository at this point in the history
ProeprtyEditorFinder service instead of PropertyEditorManager
  • Loading branch information
baranowb committed Jun 5, 2012
2 parents 0067333 + 1978613 commit 1ca910d
Show file tree
Hide file tree
Showing 37 changed files with 668 additions and 543 deletions.
Expand Up @@ -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)));
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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 {
Expand Down
89 changes: 89 additions & 0 deletions src/main/java/org/jboss/common/beans/property/BeanUtils.java
@@ -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);
}
}
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -39,7 +39,7 @@ public BooleanEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public ByteEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -40,7 +40,7 @@ public CharacterArrayEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)){
if (BeanUtils.isNull(text)){
setValue(null);
return;
}
Expand Down
Expand Up @@ -35,7 +35,7 @@ public CharacterEditor() {

@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -41,7 +41,7 @@ public DocumentEditor() {
*/
@Override
public void setAsText(String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -38,7 +38,7 @@ public DoubleEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public ElementEditor() {
*/
@Override
public void setAsText(String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -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 {
Expand Down
Expand Up @@ -37,7 +37,7 @@ public FloatEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -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()) !=
Expand Down Expand Up @@ -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 + "'");
Expand All @@ -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);
Expand All @@ -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];
Expand Down
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -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);

}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public IntegerEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public LocaleEditor() {

@Override
public void setAsText(String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -37,7 +37,7 @@ public LongEditor() {
*/
@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down
Expand Up @@ -39,7 +39,7 @@ public PropertiesEditor() {

@Override
public void setAsText(final String text) {
if (PropertyEditors.isNull(text)) {
if (BeanUtils.isNull(text)) {
setValue(null);
return;
}
Expand Down

0 comments on commit 1ca910d

Please sign in to comment.