[DIGESTER-162] ObjectCreateRule doesn't allow create objects wich type is specified in attributeName only

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/digester/trunk@1293698 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt
index 50346e3..afbcf79 100644
--- a/RELEASE-NOTES.txt
+++ b/RELEASE-NOTES.txt
@@ -54,6 +54,7 @@
 ===========================
 
  * [DIGESTER-161] Document thread-safety in javadoc of Rule class.
+ * [DIGESTER-162] ObjectCreateRule doesn't allow create objects wich type is specified in attributeName only
 
 IMPROVEMENTS OVER PREVIOUS RELEASE
 ===================================
diff --git a/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java b/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
index 888a8e8..375c68f 100644
--- a/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
+++ b/annotations-processor/src/main/java/org/apache/commons/digester3/annotations/processor/DigesterAnnotationsProcessor.java
@@ -19,13 +19,19 @@
  * under the License.
  */
 
+import static java.lang.String.format;
+
+import static javax.tools.Diagnostic.Kind.*;
+
 import static java.util.Arrays.asList;
 
 import java.util.HashSet;
 import java.util.Set;
 
 import javax.annotation.processing.AbstractProcessor;
+import javax.annotation.processing.Messager;
 import javax.annotation.processing.RoundEnvironment;
+import javax.lang.model.element.Element;
 import javax.lang.model.element.TypeElement;
 
 import org.apache.commons.digester3.annotations.rules.BeanPropertySetter;
@@ -72,7 +78,21 @@
     @Override
     public boolean process( Set<? extends TypeElement> annotations, RoundEnvironment environment )
     {
-        return false;
+        // processingEnv is a predefined member in AbstractProcessor class
+        // Messager allows the processor to output messages to the environment
+        Messager messager = processingEnv.getMessager();
+
+        // Loop through the annotations that we are going to process
+        for (TypeElement annotation: annotations) {
+            // Get the members
+            for ( Element element : environment.getElementsAnnotatedWith( annotation ) )
+            {
+                System.out.println( format( "Processing @%s %s", annotation, element ) );
+                messager.printMessage( OTHER, format( "Processing @%s %s", annotation, element ) );
+            }
+        }
+
+        return true;
     }
 
 }
diff --git a/core/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java b/core/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
index 3d34cf9..ef98c45 100644
--- a/core/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
+++ b/core/src/main/java/org/apache/commons/digester3/ObjectCreateRule.java
@@ -229,7 +229,7 @@
      */
     public ObjectCreateRule( String attributeName, Class<?> clazz )
     {
-        this( clazz.getName(), attributeName );
+        this( clazz != null ? clazz.getName() : null, attributeName );
         this.clazz = clazz;
     }
 
diff --git a/core/src/test/java/org/apache/commons/digester3/Digester162TestCase.java b/core/src/test/java/org/apache/commons/digester3/Digester162TestCase.java
new file mode 100644
index 0000000..0c47687
--- /dev/null
+++ b/core/src/test/java/org/apache/commons/digester3/Digester162TestCase.java
@@ -0,0 +1,53 @@
+package org.apache.commons.digester3;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.Assert.assertTrue;
+
+import static org.apache.commons.digester3.binder.DigesterLoader.newLoader;
+
+import org.apache.commons.digester3.binder.AbstractRulesModule;
+import org.junit.Test;
+
+public final class Digester162TestCase
+{
+
+    @Test
+    public void allowCreateObjectsWichTypesAreSpecifiedInAttributeNameOnly()
+        throws Exception
+    {
+        Digester digester = newLoader( new AbstractRulesModule()
+        {
+
+            @Override
+            protected void configure()
+            {
+                forPattern( "toplevel" ).createObject().ofTypeSpecifiedByAttribute( "type" );
+            }
+
+        })
+        .newDigester();
+
+        Object object = digester.parse( getClass().getResource( "digester-162.xml" ) );
+
+        assertTrue( BetaBean.class.isInstance( object ) );
+    }
+
+}
diff --git a/core/src/test/resources/org/apache/commons/digester3/digester-162.xml b/core/src/test/resources/org/apache/commons/digester3/digester-162.xml
new file mode 100644
index 0000000..3fb0cb5
--- /dev/null
+++ b/core/src/test/resources/org/apache/commons/digester3/digester-162.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+  
+      http://www.apache.org/licenses/LICENSE-2.0
+  
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<toplevel type="org.apache.commons.digester3.BetaBean" />
diff --git a/dist/pom.xml b/dist/pom.xml
index 388abd9..17c085b 100644
--- a/dist/pom.xml
+++ b/dist/pom.xml
@@ -84,4 +84,13 @@
     </plugins>
   </build>
 
+  <profiles>
+    <profile>
+      <id>rc</id>
+      <build>
+        
+      </build>
+    </profile>
+  </profiles>
+
 </project>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cf1e575..2fa0e42 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="3.3" date="201?-??-??" description="Maintenance release.">
+    <action dev="simonetripodi" type="fix" issue="DIGESTER-162">
+      ObjectCreateRule doesn't allow create objects wich type is specified in attributeName only
+    </action>
     <action dev="simonetripodi" type="fix" issue="DIGESTER-161" due-to="Eduard Papa">
       Document thread-safety in javadoc of Rule class
     </action>