Author: manaRH
Date: 2012-07-24 08:14:28 -0400 (Tue, 24 Jul 2012)
New Revision: 14997
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component1.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component2.java
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/PrecedenceComponentTest.java
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/init/Initialization.java
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/components.xml
Log:
JBSEAM-3138 take precedence in count if there is property definition in components.xml
Modified:
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/init/Initialization.java
===================================================================
---
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/init/Initialization.java 2012-07-23
13:23:43 UTC (rev 14996)
+++
branches/community/Seam_2_3/jboss-seam/src/main/java/org/jboss/seam/init/Initialization.java 2012-07-24
12:14:28 UTC (rev 14997)
@@ -511,7 +511,17 @@
propName = prop.getQName().getName();
}
String qualifiedPropName = name + '.' + toCamelCase(propName, false);
- properties.put( qualifiedPropName, getPropertyValue(prop, qualifiedPropName,
replacements) );
+ if (properties.containsKey(qualifiedPropName))
+ {
+ if (isSetProperties(name, precedence))
+ {
+ properties.put(qualifiedPropName, getPropertyValue(prop,
qualifiedPropName, replacements));
+ }
+ }
+ else
+ {
+ properties.put(qualifiedPropName, getPropertyValue(prop, qualifiedPropName,
replacements));
+ }
}
for ( Attribute prop: (List<Attribute>) component.attributes() )
@@ -520,11 +530,15 @@
if (isProperty(prop.getNamespaceURI(),attributeName))
{
String qualifiedPropName = name + '.' + toCamelCase(
prop.getQName().getName(), false );
+ log.info("qualifiedPropName " + qualifiedPropName);
Conversions.PropertyValue propValue = null;
try
{
propValue = getPropertyValue(prop, replacements);
- properties.put( qualifiedPropName, propValue );
+ if (isSetProperties(name, precedence))
+ {
+ properties.put(qualifiedPropName, propValue);
+ }
}
catch (Exception ex)
{
@@ -537,6 +551,24 @@
}
}
+ private boolean isSetProperties(String name, int precedence)
+ {
+ TreeSet<ComponentDescriptor> currentSet =
(TreeSet<ComponentDescriptor>) componentDescriptors.get(name);
+ if (currentSet != null)
+ {
+ ComponentDescriptor highestPriorityDescriptor = currentSet.first();
+ if (highestPriorityDescriptor == null)
+ {
+ return true;
+ }
+ return precedence > highestPriorityDescriptor.getPrecedence();
+ }
+ else
+ {
+ return true;
+ }
+ }
+
/**
* component properties are non-namespaced and not in the reserved attribute list
*/
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component1.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component1.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component1.java 2012-07-24
12:14:28 UTC (rev 14997)
@@ -0,0 +1,19 @@
+package org.jboss.seam.test.integration;
+
+
+public class Component1
+{
+
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component2.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component2.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/Component2.java 2012-07-24
12:14:28 UTC (rev 14997)
@@ -0,0 +1,18 @@
+package org.jboss.seam.test.integration;
+
+public class Component2
+{
+
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+}
Added:
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/PrecedenceComponentTest.java
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/PrecedenceComponentTest.java
(rev 0)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/java/org/jboss/seam/test/integration/PrecedenceComponentTest.java 2012-07-24
12:14:28 UTC (rev 14997)
@@ -0,0 +1,55 @@
+package org.jboss.seam.test.integration;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.OverProtocol;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.Component;
+import org.jboss.seam.mock.JUnitSeamTest;
+import org.jboss.shrinkwrap.api.Archive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+(a)RunWith(Arquillian.class)
+public class PrecedenceComponentTest
+ extends JUnitSeamTest
+{
+ @Deployment(name="JavaBeanEqualsTest")
+ @OverProtocol("Servlet 3.0")
+ public static Archive<?> createDeployment()
+ {
+ return Deployments.defaultSeamDeployment()
+ .addClasses(Component1.class, Component2.class);
+ }
+
+ /**
+ * Test if precedence of component is working correctly
+ * components.xml specifies component1 with 2 possible
+ * configuration - first has got higher precedence than
+ * second and the first should set component1.name property
+ * to Componen1High. Result should be that even last component1
+ * is set the higher precedence configuration has to be set and
+ * remain as the only one available.
+ * JBSEAM-3138
+ * @throws Exception
+ */
+ @Test
+ public void testPrecedenceComponents() throws Exception
+ {
+
+ new FacesRequest()
+ {
+ @Override
+ protected void invokeApplication() throws Exception {
+ Object component = Component.getInstance("component1");
+ if (!(component instanceof Component2))
+ {
+ Assert.fail("component is not expected Component2.class");
+ }
+ Component2 myPrecedenceComponent = (Component2) component;
+ Assert.assertEquals(myPrecedenceComponent.getName(),
"Component1High");
+ }
+ }.run();
+ }
+
+}
\ No newline at end of file
Modified:
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/components.xml
===================================================================
---
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/components.xml 2012-07-23
13:23:43 UTC (rev 14996)
+++
branches/community/Seam_2_3/seam-integration-tests/src/test/resources/WEB-INF/components.xml 2012-07-24
12:14:28 UTC (rev 14997)
@@ -42,6 +42,11 @@
<jms:managed-queue-sender name="testSender"
auto-create="true"
queue-jndi-name="queue/seamTest" />
-
+ <component name="component1"
class="org.jboss.seam.test.integration.Component2"
precedence="30">
+ <property name="name">Component1High</property>
+ </component>
+ <component name="component1"
class="org.jboss.seam.test.integration.Component1"
precedence="10">
+ <property name="name">Component1Low</property>
+ </component>
</components>
Show replies by date