Author: kentam
Date: Wed Apr 27 15:53:56 2005
New Revision: 165062
URL: http://svn.apache.org/viewcvs?rev=165062&view=rev
Log:
BEEHIVE-18: @ControlReferences in Controls clients not validated
Handle @ControlReferences on control clients -- validate that specified classes
are indeed control interfaces,
and add those classes to the list of controls used by that client (for manifest
generation etc).
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java
(with props)
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java
(with props)
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs
(with props)
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/assembly/AssemblyTests.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?rev=165062&r1=165061&r2=165062&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
Wed Apr 27 15:53:56 2005
@@ -112,14 +112,52 @@
}
}
}
+ else if (atd.getSimpleName().equals("ControlReferences"))
+ {
+ Collection<Declaration> decls =
getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd);
+ for (Declaration decl : decls)
+ {
+ if ( decl instanceof TypeDeclaration )
+ {
+ TypeDeclaration clientType = (TypeDeclaration)decl;
+ Set<TypeMirror> controlTypes = clientsMap.get(
clientType );
+ if ( controlTypes == null )
+ {
+ controlTypes = new HashSet<TypeMirror>();
+ clientsMap.put( clientType, controlTypes );
+ }
+
+ // Read ControlReferences annotation
+ AnnotationMirror controlMirror = null;
+ for (AnnotationMirror annot :
clientType.getAnnotationMirrors())
+ {
+ if
(annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
+
"org.apache.beehive.controls.api.bean.ControlReferences"))
+ {
+ controlMirror = annot;
+ break;
+ }
+ }
+
+ assert( controlMirror != null );
+
+ // Add each control type listed in the
ControlReferences annotation
+ AptAnnotationHelper controlAnnot = new
AptAnnotationHelper(controlMirror);
+ Collection<AnnotationValue> references =
(Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
+ for ( AnnotationValue av : references )
+ {
+ TypeMirror crType = (TypeMirror)av.getValue();
+ controlTypes.add( crType );
+ }
+ }
+ }
+ }
}
// For each client type:
// 1 - emit a controls client manifest in the same dir as the client
type's class.
// 2 - emit a controls client initializer class in the same pkg/dir
as the client type's class
- // TODO: support @ClientReferences
-
Filer f = getAnnotationProcessorEnvironment().getFiler();
Set<TypeDeclaration> clientTypes = clientsMap.keySet();
for ( TypeDeclaration clientType : clientTypes )
@@ -310,7 +348,46 @@
private void checkControlClientType( TypeDeclaration t )
{
- // TODO: validate @ControlReferences
+ // validate @ControlReferences
+ AnnotationMirror controlMirror = null;
+
+ for (AnnotationMirror annot : t.getAnnotationMirrors())
+ {
+ if
(annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
+ "org.apache.beehive.controls.api.bean.ControlReferences"))
+ {
+ controlMirror = annot;
+ break;
+ }
+ }
+
+ // Bail out if no @ControlReferences annotation found
+ if ( controlMirror == null )
+ return;
+
+ AptAnnotationHelper controlAnnot = new
AptAnnotationHelper(controlMirror);
+
+ //
+ // Validate that the types listed in the ControlReferences annotations
are actually
+ // control types.
+ //
+
+ Collection<AnnotationValue> references =
(Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
+
+ for ( AnnotationValue av : references )
+ {
+ DeclaredType crType = (DeclaredType)av.getValue();
+ if ( crType instanceof InterfaceType )
+ {
+ // Valid interface type decls must be annotated w/
@ControlInterface
+ // or @ControlExtension.
+ Declaration typeDecl = crType.getDeclaration();
+ if ( typeDecl.getAnnotation(ControlInterface.class) == null &&
+ typeDecl.getAnnotation(ControlExtension.class) == null )
+ printError( t, "control.reference.bad.interfacetype" );
+ }
+ }
+
}
/**
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties?rev=165062&r1=165061&r2=165062&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/strings.properties
Wed Apr 27 15:53:56 2005
@@ -47,4 +47,9 @@
The value assigned to a date property must be in the format specified.
control.member.type.invalid.date.format.error=\
-The date format specified is not valid, please see java.text.SimpleDateFormat
for valid formats.
\ No newline at end of file
+The date format specified is not valid, please see java.text.SimpleDateFormat
for valid formats.
+
+control.reference.bad.interfacetype=\
+Types listed in @ControlReferences must be control interfaces (ie, interfaces
annotated with @ControlInterface or @ControlExtension). \
+Verify the types listed in @ControlReferences are control interface types.
+
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java?rev=165062&view=auto
==============================================================================
---
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java
(added)
+++
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java
Wed Apr 27 15:53:56 2005
@@ -0,0 +1,36 @@
+package org.apache.beehive.controls.test.controls.assembly;
+
+import org.apache.beehive.controls.api.assembly.ControlAssembler;
+import org.apache.beehive.controls.api.assembly.ControlAssemblyException;
+import org.apache.beehive.controls.api.assembly.ControlAssemblyContext;
+
+import java.io.FileWriter;
+import java.io.File;
+
+public class AssemblyTestAssembler2 implements ControlAssembler
+{
+ public void assemble(ControlAssemblyContext cac)
+ throws ControlAssemblyException
+ {
+ String genPackageName =
"org.apache.beehive.controls.test.assembly.generated";
+ String genClassName = "AssemblyTest2Generated";
+
+ /* Write basic class structure out for later
+ compiliation and then finally instantiation in a test */
+ try {
+ File dir = new File( cac.getSrcOutputDir(),
genPackageName.replace(".",File.separator) );
+ dir.mkdirs();
+
+ FileWriter fw = new FileWriter( new File( dir, genClassName +
".java" ) );
+ fw.write("package " + genPackageName + ";" +
+ "public class " + genClassName + "{ }");
+ fw.close();
+ }
+ catch (java.io.IOException ioe)
+ {
+ throw new ControlAssemblyException("Error writing " +
+ genPackageName.replace(".",
File.separator) +
+ File.separator +
genClassName, ioe);
+ }
+ }
+}
Propchange:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestAssembler2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java?rev=165062&view=auto
==============================================================================
---
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java
(added)
+++
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java
Wed Apr 27 15:53:56 2005
@@ -0,0 +1,9 @@
+package org.apache.beehive.controls.test.controls.assembly;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+
[EMAIL PROTECTED] (
+ defaultBinding =
"org.apache.beehive.controls.test.controls.assembly.AssemblyTestControl2Impl"
+)
+public interface AssemblyTestControl2
+{ }
Propchange:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs?rev=165062&view=auto
==============================================================================
---
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs
(added)
+++
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs
Wed Apr 27 15:53:56 2005
@@ -0,0 +1,9 @@
+package org.apache.beehive.controls.test.controls.assembly;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+
[EMAIL PROTECTED](
+ assembler = AssemblyTestAssembler2.class
+)
+public class AssemblyTestControl2Impl implements AssemblyTestControl2,
java.io.Serializable
+{ }
Propchange:
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/assembly/AssemblyTestControl2Impl.jcs
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/assembly/AssemblyTests.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/assembly/AssemblyTests.java?rev=165062&r1=165061&r2=165062&view=diff
==============================================================================
---
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/assembly/AssemblyTests.java
(original)
+++
incubator/beehive/trunk/controls/test/src/units/org/apache/beehive/controls/test/java/assembly/AssemblyTests.java
Wed Apr 27 15:53:56 2005
@@ -3,8 +3,10 @@
import junit.framework.TestCase;
import org.apache.beehive.controls.api.bean.Control;
+import org.apache.beehive.controls.api.bean.ControlReferences;
import org.apache.beehive.controls.test.controls.assembly.AssemblyTestControl;
+import org.apache.beehive.controls.test.controls.assembly.AssemblyTestControl2;
import org.apache.beehive.controls.test.controls.util.TestBeanContext;
@@ -12,6 +14,7 @@
import org.apache.beehive.test.tools.mantis.annotations.tch.Desc;
@Freq("checkin")
[EMAIL PROTECTED]( { AssemblyTestControl2.class } )
public class AssemblyTests extends TestCase
{
@Control
@@ -41,6 +44,21 @@
Class c = null;
c = Class.forName("org.apache.beehive.controls.test.assembly" +
".generated.AssemblyTestGenerated");
+ assertNotNull(c.newInstance());
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ fail(cnfe.toString());
+ }
+ }
+
+ @Desc("Test that a control type specified via @ControlReference
participates in assembly")
+ public void testAssemblyViaReferences() throws Exception
+ {
+ try {
+ Class c = null;
+ c = Class.forName("org.apache.beehive.controls.test.assembly" +
+ ".generated.AssemblyTest2Generated");
assertNotNull(c.newInstance());
}
catch (ClassNotFoundException cnfe)