[seam-commits] Seam SVN: r13842 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/parser/namespace and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Wed Oct 13 07:03:18 EDT 2010
Author: swd847
Date: 2010-10-13 07:03:17 -0400 (Wed, 13 Oct 2010)
New Revision: 13842
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/PropertyUtils.java
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
Log:
more work and tests for property accessibility
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-10-13 10:43:35 UTC (rev 13841)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-10-13 11:03:17 UTC (rev 13842)
@@ -38,6 +38,7 @@
import org.jboss.seam.xml.core.BeanResultType;
import org.jboss.seam.xml.core.VirtualProducerField;
import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.util.PropertyUtils;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
import org.jboss.weld.extensions.literal.InjectLiteral;
@@ -81,6 +82,7 @@
Property<Object> property = query.getFirstResult();
if (property != null)
{
+ PropertyUtils.setAccessible(property);
values.add(new PropertyXmlItem(this, property, e.getValue(), null, document, lineno));
}
else
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-10-13 10:43:35 UTC (rev 13841)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-10-13 11:03:17 UTC (rev 13842)
@@ -21,9 +21,6 @@
*/
package org.jboss.seam.xml.parser.namespace;
-import java.lang.reflect.Field;
-import java.lang.reflect.Member;
-import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -37,6 +34,7 @@
import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.model.XmlItemType;
import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.util.PropertyUtils;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
import org.jboss.weld.extensions.properties.Property;
@@ -141,18 +139,7 @@
else if (property != null)
{
// ensure the property is accessible
- Member member = property.getMember();
- if (member instanceof Field)
- {
- Field field = (Field) member;
- field.setAccessible(true);
- }
- else if (member instanceof Method)
- {
- Method method = (Method) member;
- method.setAccessible(true);
- }
-
+ PropertyUtils.setAccessible(property);
return new PropertyXmlItem(parent, property, innerText, null, document, lineno);
}
return null;
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/PropertyUtils.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/PropertyUtils.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/PropertyUtils.java 2010-10-13 11:03:17 UTC (rev 13842)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * 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.seam.xml.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.jboss.weld.extensions.properties.Property;
+
+public class PropertyUtils
+{
+ private PropertyUtils()
+ {
+
+ }
+
+ public static <V> void setAccessible(Property<V> property)
+ {
+ Member member = property.getMember();
+ if (member instanceof Field)
+ {
+ Field field = (Field) member;
+ field.setAccessible(true);
+ }
+ else if (member instanceof Method)
+ {
+ Method method = (Method) member;
+ method.setAccessible(true);
+ }
+ }
+
+}
Modified: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-10-13 10:43:35 UTC (rev 13841)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-10-13 11:03:17 UTC (rev 13842)
@@ -45,8 +45,13 @@
public double dvalue = 1;
- public BigDecimal bigDecimalValue;
+ private BigDecimal bigDecimalValue;
+ public BigDecimal readBigDecimalValue()
+ {
+ return bigDecimalValue;
+ }
+
public short svalue;
public long lvalue;
Modified: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-10-13 10:43:35 UTC (rev 13841)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-10-13 11:03:17 UTC (rev 13842)
@@ -44,7 +44,7 @@
public void simpleFieldSetterTest()
{
FieldValueBean x = getReference(FieldValueBean.class);
- Assert.assertTrue(x.bigDecimalValue.compareTo(BigDecimal.TEN) == 0);
+ Assert.assertTrue(x.readBigDecimalValue().compareTo(BigDecimal.TEN) == 0);
Assert.assertTrue(x.bvalue == true);
Assert.assertTrue(x.dvalue == 0);
Assert.assertTrue(x.enumValue == QualifierEnum.A);
@@ -63,7 +63,7 @@
FieldValueBean x = getReference(FieldValueBean.class, new AnnotationLiteral<FieldsetQualifier>()
{
});
- Assert.assertTrue(x.bigDecimalValue.compareTo(BigDecimal.TEN) == 0);
+ Assert.assertTrue(x.readBigDecimalValue().compareTo(BigDecimal.TEN) == 0);
Assert.assertTrue(x.bvalue == true);
Assert.assertTrue(x.dvalue == 0);
Assert.assertTrue(x.enumValue == QualifierEnum.A);
More information about the seam-commits
mailing list