geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r767342 - in /geronimo/sandbox/blueprint/blueprint-core/src: main/java/org/apache/geronimo/blueprint/context/ main/java/org/apache/geronimo/blueprint/reflect/ test/java/org/apache/geronimo/blueprint/ test/resources/
Date Wed, 22 Apr 2009 01:46:44 GMT
Author: gawor
Date: Wed Apr 22 01:46:44 2009
New Revision: 767342

URL: http://svn.apache.org/viewvc?rev=767342&view=rev
Log:
enforce index attribute on all or none constructor arguments during parsing

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ConstructorInjectionMetadataImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ParameterSpecificationImpl.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
    geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java?rev=767342&r1=767341&r2=767342&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/Parser.java
Wed Apr 22 01:46:44 2009
@@ -399,7 +399,6 @@
         }
 
         // Parse elements
-        int indexConstructor = 0;
         NodeList nl = element.getChildNodes();
         for (int i = 0; i < nl.getLength(); i++) {
             Node node = nl.item(i);
@@ -407,12 +406,10 @@
                 Element e = (Element) node;
                 if (isBlueprintNamespace(node.getNamespaceURI())) {                
                     if (nodeNameEquals(node, CONSTRUCTOR_ARG_ELEMENT)) {
-                        // TODO: all indexes attributes must be set or none according to
the spec
-                        int index = e.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(e.getAttribute(INDEX_ATTRIBUTE))
: indexConstructor;
+                        int index = e.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(e.getAttribute(INDEX_ATTRIBUTE))
: -1;
                         String type = e.hasAttribute(TYPE_ATTRIBUTE) ? e.getAttribute(TYPE_ATTRIBUTE)
: null;
                         Value value = parseValue(e, metadata);
                         metadata.addConsuctorArg(new ParameterSpecificationImpl(value, type,
index));
-                        indexConstructor++;
                     } else if (nodeNameEquals(node, PROPERTY_ELEMENT)) {
                         String name = e.hasAttribute(NAME_ATTRIBUTE) ? e.getAttribute(NAME_ATTRIBUTE)
: null;
                         Value value = parseValue(e, metadata);

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ConstructorInjectionMetadataImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ConstructorInjectionMetadataImpl.java?rev=767342&r1=767341&r2=767342&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ConstructorInjectionMetadataImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ConstructorInjectionMetadataImpl.java
Wed Apr 22 01:46:44 2009
@@ -63,6 +63,14 @@
     }
 
     public void addParameterSpecification(ParameterSpecification parameterSpecification)
{
+        if (!parameterSpecifications.isEmpty()) {
+            ParameterSpecification p1 = parameterSpecifications.get(0);
+            ParameterSpecification p2 = parameterSpecification;
+            if ( (p1.getIndex() > -1 && p2.getIndex() < 0) ||
+                 (p1.getIndex() < 0 && p2.getIndex() > -1) ) {
+                throw new IllegalArgumentException("Index attribute must be specified either
on all or none constructor arguments");
+            }
+        }
         parameterSpecifications.add(parameterSpecification);
     }
 }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ParameterSpecificationImpl.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ParameterSpecificationImpl.java?rev=767342&r1=767341&r2=767342&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ParameterSpecificationImpl.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/reflect/ParameterSpecificationImpl.java
Wed Apr 22 01:46:44 2009
@@ -31,7 +31,7 @@
 
     private Value value;
     private String typeName;
-    private int index;
+    private int index = -1;
 
     public ParameterSpecificationImpl() {
     }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java?rev=767342&r1=767341&r2=767342&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/ParserTest.java
Wed Apr 22 01:46:44 2009
@@ -74,7 +74,7 @@
         assertEquals(6, params.size());
         ParameterSpecification param = params.get(0);
         assertNotNull(param);
-        assertEquals(0, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertNull(param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof TypedStringValue);
@@ -82,20 +82,20 @@
         assertNull(((TypedStringValue) param.getValue()).getTypeName());
         param = params.get(1);
         assertNotNull(param);
-        assertEquals(2, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertNull(param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof ReferenceValue);
         assertEquals("val1", ((ReferenceValue) param.getValue()).getComponentName());
         param = params.get(2);
         assertNotNull(param);
-        assertEquals(1, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertNull(param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof NullValue);
         param = params.get(3);
         assertNotNull(param);
-        assertEquals(3, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertEquals("java.lang.String", param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof TypedStringValue);
@@ -103,7 +103,7 @@
         assertNull(((TypedStringValue) param.getValue()).getTypeName());
         param = params.get(4);
         assertNotNull(param);
-        assertEquals(4, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertNull(param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof ArrayValue);
@@ -116,7 +116,7 @@
         assertTrue(array.getArray()[2] instanceof NullValue);
         param = params.get(5);
         assertNotNull(param);
-        assertEquals(5, param.getIndex());
+        assertEquals(-1, param.getIndex());
         assertNull(param.getTypeName());
         assertNotNull(param.getValue());
         assertTrue(param.getValue() instanceof ReferenceValue);
@@ -133,6 +133,18 @@
         LocalComponentMetadata pojoBLocal = (LocalComponentMetadata) pojoB;
         assertEquals("initPojo", pojoBLocal.getInitMethodName());
         assertEquals("", pojoBLocal.getDestroyMethodName());
+        
+        cns = pojoBLocal.getConstructorInjectionMetadata();
+        assertNotNull(cns);
+        params = cns.getParameterSpecifications();
+        assertNotNull(params);
+        assertEquals(2, params.size());
+        param = params.get(0);
+        assertNotNull(param);
+        assertEquals(1, param.getIndex());
+        param = params.get(1);
+        assertNotNull(param);
+        assertEquals(0, param.getIndex());
     }
 
     public void testParse() throws Exception {

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml?rev=767342&r1=767341&r2=767342&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/resources/test-simple-component.xml
Wed Apr 22 01:46:44 2009
@@ -6,8 +6,8 @@
 
     <component id="pojoA" class="org.apache.geronimo.blueprint.pojos.PojoA" depends-on="
pojoB , pojoC ,">
         <constructor-arg value="val0"/>
-        <constructor-arg ref="val1" index="2"/>
-        <constructor-arg index="1">
+        <constructor-arg ref="val1" />
+        <constructor-arg>
             <description>null value</description>
             <null/>
         </constructor-arg>
@@ -32,6 +32,9 @@
         </property>
     </component>
     
-    <component id="pojoB" class="org.apache.geronimo.blueprint.pojos.PojoA" init-method="initPojo"
destroy-method="" />
-
+    <component id="pojoB" class="org.apache.geronimo.blueprint.pojos.PojoA" init-method="initPojo"
destroy-method="" >
+        <constructor-arg index = "1" value="val0"/>
+        <constructor-arg index = "0" ref="val1" />
+    </component>
+    
 </components>
\ No newline at end of file



Mime
View raw message