[jboss-cvs] JBossAS SVN: r65585 - in projects/microcontainer/trunk: container/src/main/org/jboss/reflect/plugins/javassist and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Sep 24 10:51:56 EDT 2007
Author: alesj
Date: 2007-09-24 10:51:56 -0400 (Mon, 24 Sep 2007)
New Revision: 65585
Added:
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueNoTrim.xml
projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueTrim.xml
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/NoTrimTester.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTester.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimAnnotationTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimTestCase.java
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimXMLTestCase.java
Modified:
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ValueConvertor.java
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/DelegateClassInfo.java
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/PrimitiveInfo.java
projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/TypeInfo.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/StringValue.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/StringValueMetaData.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/StringValueAnnotationPlugin.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ParameterHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PlainValueHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertyHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/StringValueCharactersHandler.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueHandler.java
projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_1_0.xsd
projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
Log:
Add optional value trim.
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ClassInfoImpl.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -480,6 +480,11 @@
return ValueConvertor.convertValue(getType(), value, replaceProperties);
}
+ public Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable
+ {
+ return ValueConvertor.convertValue(getType(), value, replaceProperties, trim);
+ }
+
public boolean isArray()
{
return getType().isArray();
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ValueConvertor.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ValueConvertor.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/ValueConvertor.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -87,6 +87,22 @@
@SuppressWarnings("unchecked")
public static Object convertValue(Class<? extends Object> clazz, Object value, boolean replaceProperties) throws Throwable
{
+ return convertValue(clazz, value, replaceProperties, false);
+ }
+
+ /**
+ * Convert a value
+ *
+ * @param clazz the class
+ * @param value the value
+ * @param replaceProperties whether to replace system properties
+ * @param trim whether to trim string value
+ * @return the value or null if there is no editor
+ * @throws Throwable for any error
+ */
+ @SuppressWarnings("unchecked")
+ public static Object convertValue(Class<? extends Object> clazz, Object value, boolean replaceProperties, boolean trim) throws Throwable
+ {
if (clazz == null)
throw new IllegalArgumentException("Null class");
if (value == null)
@@ -94,11 +110,14 @@
Class<? extends Object> valueClass = value.getClass();
- // If we have a string replace any system properties when requested
- if (replaceProperties && valueClass == String.class)
+ // If we have a string, trim and replace any system properties when requested
+ if (valueClass == String.class)
{
String string = (String)value;
- value = StringPropertyReplacer.replaceProperties(string);
+ if (trim)
+ string = string.trim();
+ if (replaceProperties)
+ value = StringPropertyReplacer.replaceProperties(string);
}
if (clazz.isAssignableFrom(valueClass))
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -395,6 +395,11 @@
return ValueConvertor.convertValue(getType(), value, replaceProperties);
}
+ public Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable
+ {
+ return ValueConvertor.convertValue(getType(), value, replaceProperties, trim);
+ }
+
protected int getHashCode()
{
return getName().hashCode();
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/DelegateClassInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/DelegateClassInfo.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/DelegateClassInfo.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -226,6 +226,11 @@
return delegate.convertValue(value, replaceProperties);
}
+ public Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable
+ {
+ return delegate.convertValue(value, replaceProperties, trim);
+ }
+
public TypeInfo getArrayType()
{
return delegate.getArrayType();
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/PrimitiveInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/PrimitiveInfo.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/PrimitiveInfo.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -169,6 +169,16 @@
return ValueConvertor.convertValue(type, value, replaceProperties);
}
+ public Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable
+ {
+ Object progressResult = ValueConvertor.progressValue(type, value);
+ if (progressResult != null)
+ {
+ return progressResult;
+ }
+ return ValueConvertor.convertValue(type, value, replaceProperties, trim);
+ }
+
@Override
public boolean isPrimitive()
{
Modified: projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/TypeInfo.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/TypeInfo.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/reflect/spi/TypeInfo.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -73,6 +73,17 @@
Object convertValue(Object value, boolean replaceProperties) throws Throwable;
/**
+ * Convert a value
+ *
+ * @param value the original value
+ * @param replaceProperties whether to replace properties
+ * @param trim do we trim before conversion
+ * @return the converted value
+ * @throws Throwable for any error
+ */
+ Object convertValue(Object value, boolean replaceProperties, boolean trim) throws Throwable;
+
+ /**
* Whether this type is an array
*
* @return true when an array
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/StringValue.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/StringValue.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/api/annotations/StringValue.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -55,4 +55,11 @@
* @return true for replace with system properties, false otherwise
*/
boolean replace() default true;
+
+ /**
+ * Do we trim.
+ *
+ * @return
+ */
+ boolean trim() default true;
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/StringValueMetaData.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/StringValueMetaData.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/beans/metadata/plugins/StringValueMetaData.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -46,6 +46,12 @@
private boolean replace = true;
/**
+ * Do we trim string value before usage,
+ * by default is true.
+ */
+ private boolean trim = true;
+
+ /**
* Create a new string value
*/
public StringValueMetaData()
@@ -96,9 +102,9 @@
if (typeInfo != info && info != null)
{
Object typeValue = typeInfo.convertValue(getUnderlyingValue());
- return info.convertValue(typeValue, replace);
+ return info.convertValue(typeValue, replace, trim);
}
- return typeInfo.convertValue(getUnderlyingValue(), replace);
+ return typeInfo.convertValue(getUnderlyingValue(), replace, trim);
}
protected Object getDefaultInstance()
@@ -124,4 +130,14 @@
{
this.replace = replace;
}
+
+ public boolean isTrim()
+ {
+ return trim;
+ }
+
+ public void setTrim(boolean trim)
+ {
+ this.trim = trim;
+ }
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/StringValueAnnotationPlugin.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/StringValueAnnotationPlugin.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/annotations/StringValueAnnotationPlugin.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -45,6 +45,7 @@
if (isAttributePresent(annotation.type()))
value.setType(annotation.type());
value.setReplace(annotation.replace());
+ value.setTrim(annotation.trim());
return value;
}
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/BeanSchemaBinding.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -511,11 +511,21 @@
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
parameter.setType(attrs.getValue(i));
- else if ("replace".equals(localName))
+ else if ("replace".equals(localName) || "trim".equals(localName))
{
- StringValueMetaData svmd = new StringValueMetaData();
- svmd.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
- parameter.setValue(svmd);
+ ValueMetaData vmd = parameter.getValue();
+ StringValueMetaData stringValueMetaData;
+ if (vmd != null && vmd instanceof StringValueMetaData)
+ stringValueMetaData = (StringValueMetaData)vmd;
+ else
+ {
+ stringValueMetaData = new StringValueMetaData();
+ parameter.setValue(stringValueMetaData);
+ }
+ if ("replace".equals(localName))
+ stringValueMetaData.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ stringValueMetaData.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
@@ -538,6 +548,7 @@
{
StringValueMetaData previous = (StringValueMetaData) vmd;
svmd.setReplace(previous.isReplace());
+ svmd.setTrim(previous.isTrim());
String type = previous.getType();
if (type != null)
svmd.setType(type);
@@ -808,7 +819,7 @@
property.setName(attrs.getValue(i));
else if ("preinstantiate".equals(localName))
property.setPreInstantiate(Boolean.parseBoolean(attrs.getValue(i)));
- else if ("class".equals(localName) || "replace".equals(localName))
+ else if ("class".equals(localName) || "replace".equals(localName) || "trim".equals(localName))
{
StringValueMetaData svmd;
ValueMetaData vmd = property.getValue();
@@ -825,6 +836,8 @@
svmd.setType(attrs.getValue(i));
else if ("replace".equals(localName))
svmd.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ svmd.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
@@ -856,6 +869,7 @@
{
StringValueMetaData previous = (StringValueMetaData) vmd;
svmd.setReplace(previous.isReplace());
+ svmd.setTrim(previous.isTrim());
String type = previous.getType();
if (type != null)
svmd.setType(type);
@@ -1075,6 +1089,8 @@
value.setType(attrs.getValue(i));
else if ("replace".equals(localName))
value.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ value.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
});
@@ -1115,6 +1131,8 @@
string.setType(attrs.getValue(i));
else if ("replace".equals(localName))
string.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ string.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
});
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ParameterHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ParameterHandler.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ParameterHandler.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -26,6 +26,7 @@
import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementHandler;
import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.xml.sax.Attributes;
@@ -56,11 +57,21 @@
String localName = attrs.getLocalName(i);
if ("class".equals(localName))
parameter.setType(attrs.getValue(i));
- else if ("replace".equals(localName))
+ else if ("replace".equals(localName) || "trim".equals(localName))
{
- StringValueMetaData svmd = new StringValueMetaData();
- svmd.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
- parameter.setValue(svmd);
+ ValueMetaData vmd = parameter.getValue();
+ StringValueMetaData stringValueMetaData;
+ if (vmd != null && vmd instanceof StringValueMetaData)
+ stringValueMetaData = (StringValueMetaData)vmd;
+ else
+ {
+ stringValueMetaData = new StringValueMetaData();
+ parameter.setValue(stringValueMetaData);
+ }
+ if ("replace".equals(localName))
+ stringValueMetaData.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ stringValueMetaData.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PlainValueHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PlainValueHandler.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PlainValueHandler.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -55,6 +55,8 @@
value.setType(attrs.getValue(i));
else if ("replace".equals(localName))
value.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ value.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertyHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertyHandler.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/PropertyHandler.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -57,7 +57,7 @@
property.setName(attrs.getValue(i));
else if ("preinstantiate".equals(localName))
property.setPreInstantiate(Boolean.parseBoolean(attrs.getValue(i)));
- else if ("class".equals(localName) || "replace".equals(localName))
+ else if ("class".equals(localName) || "replace".equals(localName) || "trim".equals(localName))
{
StringValueMetaData svmd;
ValueMetaData vmd = property.getValue();
@@ -74,6 +74,8 @@
svmd.setType(attrs.getValue(i));
else if ("replace".equals(localName))
svmd.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ svmd.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/StringValueCharactersHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/StringValueCharactersHandler.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/StringValueCharactersHandler.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -52,6 +52,7 @@
{
StringValueMetaData previous = (StringValueMetaData) vmd;
svmd.setReplace(previous.isReplace());
+ svmd.setTrim(previous.isTrim());
String type = previous.getType();
if (type != null)
svmd.setType(type);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueHandler.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueHandler.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/deployment/xml/ValueHandler.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -57,6 +57,8 @@
string.setType(attrs.getValue(i));
else if ("replace".equals(localName))
string.setReplace(Boolean.parseBoolean(attrs.getValue(i)));
+ else if ("trim".equals(localName))
+ string.setTrim(Boolean.parseBoolean(attrs.getValue(i)));
}
}
}
Modified: projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_1_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_1_0.xsd 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_1_0.xsd 2007-09-24 14:51:56 UTC (rev 65585)
@@ -457,6 +457,7 @@
</xsd:annotation>
<xsd:attribute name="class" type="classNameType" use="optional"/>
<xsd:attribute name="replace" type="xsd:boolean" use="optional"/>
+ <xsd:attribute name="trim" type="xsd:boolean" use="optional"/>
</xsd:complexType>
<xsd:complexType name="valueType" mixed="true">
Modified: projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/resources/main/schema/bean-deployer_2_0.xsd 2007-09-24 14:51:56 UTC (rev 65585)
@@ -678,6 +678,7 @@
</xsd:annotation>
<xsd:attribute name="class" type="classNameType" use="optional"/>
<xsd:attribute name="replace" type="xsd:boolean" use="optional"/>
+ <xsd:attribute name="trim" type="xsd:boolean" use="optional"/>
</xsd:complexType>
<xsd:complexType name="valueType" mixed="true">
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueNoTrim.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueNoTrim.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueNoTrim.xml 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="SimpleBean" class="org.jboss.test.kernel.config.support.SimpleBean">
+ <property name="anInt" trim="false"> 10 </property>
+ </bean>
+
+</deployment>
+
Added: projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueTrim.xml
===================================================================
--- projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueTrim.xml (rev 0)
+++ projects/microcontainer/trunk/kernel/src/resources/tests/xml-test/org/jboss/test/kernel/config/test/testValueTrim.xml 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd"
+ xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="SimpleBean" class="org.jboss.test.kernel.config.support.SimpleBean">
+ <property name="anInt" trim="true"> 10 </property>
+ </bean>
+
+</deployment>
+
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/NoTrimTester.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/NoTrimTester.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/NoTrimTester.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.kernel.config.support;
+
+import org.jboss.beans.metadata.api.annotations.StringValue;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class NoTrimTester
+{
+ private Integer value;
+
+ public Integer getValue()
+ {
+ return value;
+ }
+
+ @StringValue(value = " 10 ", trim = false)
+ public void setValue(Integer value)
+ {
+ this.value = value;
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTester.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTester.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/support/TrimTester.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.kernel.config.support;
+
+import org.jboss.beans.metadata.api.annotations.StringValue;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TrimTester
+{
+ private Integer value;
+
+ public Integer getValue()
+ {
+ return value;
+ }
+
+ @StringValue(" 10 ")
+ public void setValue(Integer value)
+ {
+ this.value = value;
+ }
+}
Modified: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-09-24 11:26:59 UTC (rev 65584)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ConfigTestSuite.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -84,6 +84,9 @@
suite.addTest(ValueFactoryTestCase.suite());
suite.addTest(ValueFactoryXMLTestCase.suite());
suite.addTest(ValueFactoryAnnotationTestCase.suite());
+ suite.addTest(ValueTrimTestCase.suite());
+ suite.addTest(ValueTrimXMLTestCase.suite());
+ suite.addTest(ValueTrimAnnotationTestCase.suite());
return suite;
}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimAnnotationTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimAnnotationTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimAnnotationTestCase.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,72 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.test.kernel.config.support.NoTrimTester;
+import org.jboss.test.kernel.config.support.TrimTester;
+import org.jboss.dependency.spi.ControllerState;
+
+/**
+ * Value trim annotation test cases.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueTrimAnnotationTestCase extends ValueTrimTestCase
+{
+ public ValueTrimAnnotationTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueTrimAnnotationTestCase.class);
+ }
+
+ protected Object getTrimmedValue() throws Throwable
+ {
+ Kernel kernel = bootstrap();
+ KernelController controller = kernel.getController();
+ KernelControllerContext context = controller.install(new AbstractBeanMetaData("tester", TrimTester.class.getName()));
+ TrimTester tester = (TrimTester)context.getTarget();
+ return tester.getValue();
+ }
+
+ protected Object getPlainValue() throws Throwable
+ {
+ Kernel kernel = bootstrap();
+ KernelController controller = kernel.getController();
+ KernelControllerContext context = controller.install(new AbstractBeanMetaData("tester", NoTrimTester.class.getName()));
+ assertEquals(ControllerState.ERROR, context.getState());
+ throw new IllegalStateException();
+ }
+
+ protected Class<? extends Exception> getExceptionClass()
+ {
+ return IllegalStateException.class;
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimTestCase.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,96 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.beans.metadata.plugins.StringValueMetaData;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+
+/**
+ * Value trim test cases.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueTrimTestCase extends AbstractKernelConfigTest
+{
+ public ValueTrimTestCase(String name)
+ {
+ super(name);
+ }
+
+ public ValueTrimTestCase(String name, boolean xmltest)
+ {
+ super(name, xmltest);
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueTrimTestCase.class);
+ }
+
+ protected Object getValue(boolean trim, String value, Class<?> clazz) throws Throwable
+ {
+ Kernel kernel = bootstrap();
+ StringValueMetaData string = new StringValueMetaData(value);
+ string.setTrim(trim);
+ KernelConfigurator configurator = kernel.getConfigurator();
+ string.setConfigurator(configurator);
+ return string.getValue(configurator.getClassInfo(clazz), Thread.currentThread().getContextClassLoader());
+ }
+
+ protected Object getTrimmedValue() throws Throwable
+ {
+ return getValue(true, " 10 ", Integer.class);
+ }
+
+ public void testValueTrim() throws Throwable
+ {
+ Object value = getTrimmedValue();
+ assertNotNull(value);
+ assertInstanceOf(value, Integer.class);
+ assertEquals(10, value);
+ }
+
+ protected Object getPlainValue() throws Throwable
+ {
+ return getValue(false, " 10 ", Integer.class);
+ }
+
+ protected Class<? extends Exception> getExceptionClass()
+ {
+ return NumberFormatException.class;
+ }
+
+ public void testValueNoTrim() throws Throwable
+ {
+ try
+ {
+ Object value = getPlainValue();
+ assertNull("Should not be here.", value);
+ }
+ catch (Throwable t)
+ {
+ assertInstanceOf(t, getExceptionClass());
+ }
+ }
+}
Added: projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimXMLTestCase.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimXMLTestCase.java (rev 0)
+++ projects/microcontainer/trunk/kernel/src/tests/org/jboss/test/kernel/config/test/ValueTrimXMLTestCase.java 2007-09-24 14:51:56 UTC (rev 65585)
@@ -0,0 +1,64 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.test.kernel.config.test;
+
+import junit.framework.Test;
+import org.jboss.test.kernel.config.support.XMLUtil;
+import org.jboss.test.kernel.config.support.SimpleBean;
+
+/**
+ * Value trim xml test cases.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ValueTrimXMLTestCase extends ValueTrimTestCase
+{
+ public ValueTrimXMLTestCase(String name)
+ {
+ super(name, true);
+ }
+
+ public static Test suite()
+ {
+ return suite(ValueTrimXMLTestCase.class);
+ }
+
+ protected Object getTrimmedValue() throws Throwable
+ {
+ XMLUtil util = bootstrapXML(true);
+ SimpleBean bean = (SimpleBean)util.getBean("SimpleBean");
+ return bean.getAnInt();
+ }
+
+ protected Object getPlainValue() throws Throwable
+ {
+ XMLUtil util = bootstrapXML(true);
+ Object bean = util.getBean("SimpleBean");
+ util.validate();
+ return bean;
+ }
+
+ protected Class<? extends Exception> getExceptionClass()
+ {
+ return IllegalStateException.class;
+ }
+}
More information about the jboss-cvs-commits
mailing list