Author: kentam
Date: Tue Feb 8 11:23:14 2005
New Revision: 152923
URL: http://svn.apache.org/viewcvs?view=rev&rev=152923
Log:
Separated the ControlConstraintValidator into two different classes:
- ConstrolConstraintValidator, which is used for run time validation
- ConstrolConstraintAptValidator, which is used for build time validation
This was done because performing validation at build time requires the Mirror
API. If both runtime and build time
validation is performed by the same class, then control clients will require to
have the Mirror API in their classpath.
Separating the validator into 2 classes eliminates this requirement.
Contributor: Hoi Lam
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java
(with props)
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java?view=diff&r1=152922&r2=152923
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/AnnotationConstraintValidator.java
Tue Feb 8 11:23:14 2005
@@ -39,15 +39,6 @@
import org.apache.beehive.controls.api.properties.PropertyKey;
import org.apache.beehive.controls.api.properties.PropertySet;
-import com.sun.mirror.declaration.AnnotationMirror;
-import com.sun.mirror.declaration.AnnotationTypeDeclaration;
-import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
-import com.sun.mirror.declaration.AnnotationValue;
-import com.sun.mirror.declaration.Declaration;
-import com.sun.mirror.declaration.MethodDeclaration;
-import com.sun.mirror.declaration.TypeDeclaration;
-import com.sun.mirror.type.AnnotationType;
-
/**
* This class offers methods for validating values assigned to a control
property.
* The validation process will ensure
@@ -87,90 +78,6 @@
}
/**
- * This method ensures that any control property value assignment satisfies
- * all property constraints. This method should be called from an
annotation
- * processor to ensure declarative control property assignment using
- * annotations are validated at build time. This method is currently called
- * from ControlAnnotationProcessor and ControlClientAnnotationProcessor.
- *
- * @param d
- * a declaration which may contain a control property value
- * assignment
- * @throws IllegalArgumentException
- * when the declaration contains a control property value
- * assignment that does not satisfy a property constraint.
- */
- public static void validate(Declaration d) throws IllegalArgumentException
- {
- Collection<AnnotationMirror> mirrors = d.getAnnotationMirrors();
-
- // for each annotations defined on the declaration, if the annotation
- // is a PropertySet, ensure the values assigned to the properties
- // satisfy all PropertySet and PropertyType constraints.
- for (AnnotationMirror m : mirrors)
- {
- AnnotationType type = m.getAnnotationType();
- AnnotationTypeDeclaration decl =
m.getAnnotationType().getDeclaration();
- if (decl.getAnnotation(PropertySet.class) != null)
- {
- Iterator<Map.Entry<AnnotationTypeElementDeclaration,
AnnotationValue>> i = m
- .getElementValues().entrySet().iterator();
- while (i.hasNext())
- {
- Map.Entry<AnnotationTypeElementDeclaration,
AnnotationValue> entry = i
- .next();
- Collection<Annotation> annotations =
getMemberTypeAnnotations(entry.getKey());
- if (annotations.size() > 0)
- {
- Annotation[] anArray = new
Annotation[annotations.size()];
- annotations.toArray(anArray);
- validate(anArray, entry.getValue().getValue());
- }
- }
-
- //If a membership rule is defined on the property set, ensure
the rule is satisfied.
- if (decl.getAnnotation(MembershipRule.class) != null)
- {
- try
- {
- String declClassName = decl.getQualifiedName();
-
- TypeDeclaration owningClass = decl.getDeclaringType();
- if (owningClass != null)
- declClassName = owningClass.getQualifiedName() +
"$" + decl.getSimpleName();
-
- Class clazz = Class.forName(declClassName);
- Annotation a = d.getAnnotation(clazz);
- validateMembership(a);
- }
- catch (ClassNotFoundException cnfe)
- {
- //should not happen
- }
- }
- }
- }
-
- // If the declaration is a class or interface, validate its methods
- // and fields.
- if (d instanceof TypeDeclaration)
- {
- TypeDeclaration td = ((TypeDeclaration) d);
- for (Declaration md : td.getMethods())
- validate(md);
- for (Declaration fd : td.getFields())
- validate(fd);
- }
- // If the delcaration is a method, validate its parameters.
- else if (d instanceof MethodDeclaration)
- {
- for (Declaration pd : ((MethodDeclaration) d).getParameters())
- validate(pd);
- }
-
- }
-
- /**
* This method ensures the membership constraints defined on a property set
* is satisfied.
*
@@ -276,40 +183,7 @@
return num;
}
- private static Collection<Annotation> getMemberTypeAnnotations(
- Declaration decl)
- {
- Collection<Annotation> annotations = new ArrayList<Annotation>();
- for (AnnotationMirror am : decl.getAnnotationMirrors())
- {
- AnnotationType at = am.getAnnotationType();
- try
- {
- if (at.getContainingType() == null)
- continue;
- String containingClassName = at.getContainingType()
- .getDeclaration().getQualifiedName();
- if (containingClassName.equals(AnnotationMemberTypes.class
- .getName()))
- {
- String memberTypeName =
at.getDeclaration().getSimpleName();
- Class clazz = Class.forName(containingClassName + "$"
- + memberTypeName);
- Annotation a = decl.getAnnotation(clazz);
- if (null != a)
- {
- annotations.add(a);
- }
- }
- }
- catch (ClassNotFoundException e)
- {
- }
- }
- return annotations;
- }
-
- private static synchronized void validate(Annotation[] annotations,
+ protected static synchronized void validate(Annotation[] annotations,
Object value) throws IllegalArgumentException
{
Added:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java?view=auto&rev=152923
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java
(added)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java
Tue Feb 8 11:23:14 2005
@@ -0,0 +1,181 @@
+package org.apache.beehive.controls.runtime.generator.apt;
+
+/*
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ * $Header:$
+ */
+
+import java.io.File;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.apache.beehive.controls.api.bean.AnnotationMemberTypes;
+import
org.apache.beehive.controls.api.bean.AnnotationConstraints.MembershipRule;
+import
org.apache.beehive.controls.api.bean.AnnotationConstraints.MembershipRuleValues;
+import org.apache.beehive.controls.api.properties.PropertyKey;
+import org.apache.beehive.controls.api.properties.PropertySet;
+import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator;
+
+import com.sun.mirror.declaration.AnnotationMirror;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.AnnotationTypeElementDeclaration;
+import com.sun.mirror.declaration.AnnotationValue;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.declaration.TypeDeclaration;
+import com.sun.mirror.type.AnnotationType;
+
+/**
+ * This class is for validating control property values at build time
+ * It calls [EMAIL PROTECTED]
org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator
+ * AnnotationConstraintValidator} to do the validation.
+ */
+public class AnnotationConstraintAptValidator extends
AnnotationConstraintValidator
+{
+
+ public AnnotationConstraintAptValidator()
+ {
+ super();
+ }
+
+ /**
+ * This method ensures that any control property value assignment satisfies
+ * all property constraints. This method should be called from an
annotation
+ * processor to ensure declarative control property assignment using
+ * annotations are validated at build time. This method is currently called
+ * from ControlAnnotationProcessor and ControlClientAnnotationProcessor.
+ *
+ * @param d
+ * a declaration which may contain a control property value
+ * assignment
+ * @throws IllegalArgumentException
+ * when the declaration contains a control property value
+ * assignment that does not satisfy a property constraint.
+ */
+ public static void validate(Declaration d) throws IllegalArgumentException
+ {
+ Collection<AnnotationMirror> mirrors = d.getAnnotationMirrors();
+
+ // for each annotations defined on the declaration, if the annotation
+ // is a PropertySet, ensure the values assigned to the properties
+ // satisfy all PropertySet and PropertyType constraints.
+ for (AnnotationMirror m : mirrors)
+ {
+ AnnotationType type = m.getAnnotationType();
+ AnnotationTypeDeclaration decl =
m.getAnnotationType().getDeclaration();
+ if (decl.getAnnotation(PropertySet.class) != null)
+ {
+ Iterator<Map.Entry<AnnotationTypeElementDeclaration,
AnnotationValue>> i = m
+ .getElementValues().entrySet().iterator();
+ while (i.hasNext())
+ {
+ Map.Entry<AnnotationTypeElementDeclaration,
AnnotationValue> entry = i
+ .next();
+ Collection<Annotation> annotations =
getMemberTypeAnnotations(entry.getKey());
+ if (annotations.size() > 0)
+ {
+ Annotation[] anArray = new
Annotation[annotations.size()];
+ annotations.toArray(anArray);
+ validate(anArray, entry.getValue().getValue());
+ }
+ }
+
+ //If a membership rule is defined on the property set, ensure
the rule is satisfied.
+ if (decl.getAnnotation(MembershipRule.class) != null)
+ {
+ try
+ {
+ String declClassName = decl.getQualifiedName();
+
+ TypeDeclaration owningClass = decl.getDeclaringType();
+ if (owningClass != null)
+ declClassName = owningClass.getQualifiedName() +
"$" + decl.getSimpleName();
+
+ Class clazz = Class.forName(declClassName);
+ Annotation a = d.getAnnotation(clazz);
+ validateMembership(a);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ //should not happen
+ }
+ }
+ }
+ }
+
+ // If the declaration is a class or interface, validate its methods
+ // and fields.
+ if (d instanceof TypeDeclaration)
+ {
+ TypeDeclaration td = ((TypeDeclaration) d);
+ for (Declaration md : td.getMethods())
+ validate(md);
+ for (Declaration fd : td.getFields())
+ validate(fd);
+ }
+ // If the delcaration is a method, validate its parameters.
+ else if (d instanceof MethodDeclaration)
+ {
+ for (Declaration pd : ((MethodDeclaration) d).getParameters())
+ validate(pd);
+ }
+
+ }
+
+ private static Collection<Annotation> getMemberTypeAnnotations(
+ Declaration decl)
+ {
+ Collection<Annotation> annotations = new ArrayList<Annotation>();
+ for (AnnotationMirror am : decl.getAnnotationMirrors())
+ {
+ AnnotationType at = am.getAnnotationType();
+ try
+ {
+ if (at.getContainingType() == null)
+ continue;
+ String containingClassName = at.getContainingType()
+ .getDeclaration().getQualifiedName();
+ if (containingClassName.equals(AnnotationMemberTypes.class
+ .getName()))
+ {
+ String memberTypeName =
at.getDeclaration().getSimpleName();
+ Class clazz = Class.forName(containingClassName + "$"
+ + memberTypeName);
+ Annotation a = decl.getAnnotation(clazz);
+ if (null != a)
+ {
+ annotations.add(a);
+ }
+ }
+ }
+ catch (ClassNotFoundException e)
+ {
+ }
+ }
+ return annotations;
+ }
+}
Propchange:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/AnnotationConstraintAptValidator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
URL:
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java?view=diff&r1=152922&r2=152923
==============================================================================
---
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
(original)
+++
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlAnnotationProcessor.java
Tue Feb 8 11:23:14 2005
@@ -38,7 +38,6 @@
import org.apache.beehive.controls.api.bean.ControlInterface;
import org.apache.beehive.controls.api.properties.PropertySet;
-import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator;
import org.apache.beehive.controls.runtime.generator.*;
public class ControlAnnotationProcessor extends TwoPhaseAnnotationProcessor
@@ -68,7 +67,7 @@
// constraints declared in the properties.
try
{
- AnnotationConstraintValidator.validate(decl);
+ AnnotationConstraintAptValidator.validate(decl);
}
catch (IllegalArgumentException iae)
{
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?view=diff&r1=152922&r2=152923
==============================================================================
---
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
Tue Feb 8 11:23:14 2005
@@ -34,7 +34,6 @@
import org.apache.beehive.controls.runtime.generator.Generator;
import org.apache.beehive.controls.runtime.generator.GeneratorOutput;
import org.apache.beehive.controls.runtime.generator.CodeGenerator;
-import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator;
import org.apache.beehive.controls.runtime.bean.ControlBeanContext;
import org.apache.beehive.controls.api.bean.*;
@@ -69,7 +68,7 @@
// constraints declared in the properties.
try
{
- AnnotationConstraintValidator.validate(d);
+ AnnotationConstraintAptValidator.validate(d);
}
catch (IllegalArgumentException iae)
{