You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ke...@apache.org on 2005/03/02 22:37:31 UTC

svn commit: r155961 - in incubator/beehive/trunk/controls: src/api/org/apache/beehive/controls/api/bean/ src/runtime/META-INF/services/ src/runtime/org/apache/beehive/controls/runtime/bean/ src/runtime/org/apache/beehive/controls/runtime/generator/apt/ test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/

Author: kentam
Date: Wed Mar  2 13:37:27 2005
New Revision: 155961

URL: http://svn.apache.org/viewcvs?view=rev&rev=155961
Log:
Fixes for BEEHIVE-206 and BEEHIVE-207

The ControlMemberTypeAnnotationProcessor is created to validate declarations of control member type
annotations.

A date format member has been added to AnnotationMemberTypes.Date, so users can customize the date format used
for this annotation.


Contributor: Hoi Lam


Added:
    incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessor.java
    incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessorFactory.java
Modified:
    incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java
    incubator/beehive/trunk/controls/src/runtime/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
    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/strings.properties
    incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java

Modified: incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java?view=diff&r1=155960&r2=155961
==============================================================================
--- incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java (original)
+++ incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/bean/AnnotationMemberTypes.java Wed Mar  2 13:37:27 2005
@@ -112,8 +112,9 @@
     }
 
     /**
-     * Member is a Date is the Form of:YYYY/MM/DD
+     * Member is a Date in the format specified (default is YYYY/MM/DD)
      * Only valid on a member that returns String
+     * @see java.text.SimpleDateFormat when selecting another date format.
      * Note: JSR175 does not allow java.util.Date as
      * a member type.
      */
@@ -121,6 +122,7 @@
     @Retention(RetentionPolicy.RUNTIME)
     public @interface Date
     {
+    	String format() default "yyyy/MM/dd";
         String minValue() default "";
         String maxValue() default "";
     }

Modified: incubator/beehive/trunk/controls/src/runtime/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory?view=diff&r1=155960&r2=155961
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory (original)
+++ incubator/beehive/trunk/controls/src/runtime/META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory Wed Mar  2 13:37:27 2005
@@ -3,3 +3,4 @@
 #
 org.apache.beehive.controls.runtime.generator.apt.ControlAnnotationProcessorFactory
 org.apache.beehive.controls.runtime.generator.apt.ControlClientAnnotationProcessorFactory
+org.apache.beehive.controls.runtime.generator.apt.ControlMemberTypeAnnotationProcessorFactory
\ No newline at end of file

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=155960&r2=155961
==============================================================================
--- 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 Wed Mar  2 13:37:27 2005
@@ -353,47 +353,47 @@
 
         try
         {
-            Date date = parseDate((String) value);
+        	String format = a.format();
+        	
+            Date date = parseDate(format , (String) value);
 
             String minValue = a.minValue();
             if (minValue != null && minValue.length() > 0)
             {
-                Date minDate = parseDate(a.minValue());
+                Date minDate = parseDate(format, a.minValue());
                 if (minDate.compareTo(date) > 0)
                 {
-                    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
                     error("The date, "
-                            + format.format(date)
+                            + value
                             + ", assigned to a date property is earlier than the earliest date allowed: "
-                            + format.format(minDate));
+                            + minValue);
                 }
             }
             String maxValue = a.maxValue();
             if (maxValue != null && maxValue.length() > 0)
             {
-                Date maxDate = parseDate(a.maxValue());
+                Date maxDate = parseDate(format, a.maxValue());
                 if (maxDate.compareTo(date) < 0)
                 {
-                    SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
                     error("The date, "
-                            + format.format(date)
+                            + value
                             + ", assigned to a date property is later than the latest date allowed: "
-                            + format.format(maxDate));
+                            + maxValue);
                 }
             }
         }
         catch (ParseException pe)
         {
-            error("Value assigned to a date property must be in the form 'YYYY/MM/DD'");
+            error("Value assigned to a date property is not in the specified format.");
         }
 
     }
 
-    private static Date parseDate(String s) throws ParseException
+    public static Date parseDate(String format, String value) throws ParseException
     {
-        SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
-        format.setLenient(false);
-        return format.parse(s);
+        SimpleDateFormat sdFormat = new SimpleDateFormat(format);
+        sdFormat.setLenient(false);
+        return sdFormat.parse(value);
     }
 
     /**

Added: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessor.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessor.java?view=auto&rev=155961
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessor.java (added)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessor.java Wed Mar  2 13:37:27 2005
@@ -0,0 +1,95 @@
+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.lang.annotation.Annotation;
+import java.util.Set;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import org.apache.beehive.controls.api.bean.AnnotationMemberTypes;
+import org.apache.beehive.controls.runtime.generator.AptControlInterface;
+import org.apache.beehive.controls.runtime.generator.apt.TwoPhaseAnnotationProcessor;
+import org.apache.beehive.controls.runtime.bean.AnnotationConstraintValidator;
+
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+import com.sun.mirror.declaration.Declaration;
+import com.sun.mirror.declaration.MethodDeclaration;
+import com.sun.mirror.type.VoidType;
+
+public class ControlMemberTypeAnnotationProcessor extends TwoPhaseAnnotationProcessor
+{
+    /**
+     * @param atds
+     * @param env
+     */
+    public ControlMemberTypeAnnotationProcessor(
+            Set<AnnotationTypeDeclaration> atds,
+            AnnotationProcessorEnvironment env)
+    {
+        super(atds, env);
+    }
+
+    public void check()
+    {
+        super.check();
+        
+    }
+    public void check(Declaration decl)
+    {
+        if (decl.getAnnotation(AnnotationMemberTypes.Date.class) != null)
+        {
+        	checkDate(decl);
+        }
+    }
+
+    public void generate(Declaration decl)
+    {
+    }
+
+    public void checkDate(Declaration decl)
+    {
+    	AnnotationMemberTypes.Date date = decl.getAnnotation(AnnotationMemberTypes.Date.class);
+    	
+    	try
+    	{
+    		String dateValue = date.minValue();
+    		String format = date.format();
+    		
+        	//Validate the date format specified
+    		SimpleDateFormat sdFormat = new SimpleDateFormat(date.format());
+
+        	//Validate that the date specified is in the specified format.
+    		if (dateValue != null && dateValue.length() > 0)
+    			AnnotationConstraintValidator.parseDate(format, dateValue);
+    		dateValue = date.maxValue();
+    		if (dateValue != null && dateValue.length() > 0)
+    			AnnotationConstraintValidator.parseDate(format, dateValue);
+    	} 
+    	catch (ParseException pe)
+    	{
+    		printError( decl, "control.member.type.invalid.date.value.error");
+    	}
+    	catch (Exception e)
+    	{
+    		printError( decl, "control.member.type.invalid.date.format.error");    		
+    	}
+
+    }
+}

Added: incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessorFactory.java?view=auto&rev=155961
==============================================================================
--- incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessorFactory.java (added)
+++ incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlMemberTypeAnnotationProcessorFactory.java Wed Mar  2 13:37:27 2005
@@ -0,0 +1,61 @@
+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.util.Arrays;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+
+import org.apache.beehive.controls.api.bean.AnnotationMemberTypes.Date;
+
+import com.sun.mirror.apt.AnnotationProcessor;
+import com.sun.mirror.apt.AnnotationProcessorFactory;
+import com.sun.mirror.apt.AnnotationProcessorEnvironment;
+import com.sun.mirror.declaration.AnnotationTypeDeclaration;
+
+public class ControlMemberTypeAnnotationProcessorFactory implements AnnotationProcessorFactory
+{
+    private static final Collection<String> _supportedAnnotations =
+            Collections.unmodifiableCollection(
+                Arrays.asList(new String[] {
+                		"org.apache.beehive.controls.api.bean.AnnotationMemberTypes.Date"
+                }));
+
+    private static final Collection<String> _supportedOptions =
+            Collections.unmodifiableCollection(
+                Arrays.asList( new String[0] ) );
+
+    public Collection<String> supportedOptions()
+    {
+        return _supportedOptions;
+    }
+
+    public Collection<String> supportedAnnotationTypes()
+    {
+        return _supportedAnnotations;
+    }
+
+    public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds,
+                                               AnnotationProcessorEnvironment env)
+    {
+        return new ControlMemberTypeAnnotationProcessor(atds, env);   
+    }
+}

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?view=diff&r1=155960&r2=155961
==============================================================================
--- 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 Mar  2 13:37:27 2005
@@ -42,3 +42,9 @@
 propertyset.illegal.argument.error=\
 A value assigned to a control property does not satisfy \
 its constraints. Cause: {0} 
+
+control.member.type.invalid.date.value.error=\
+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

Modified: incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java
URL: http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java?view=diff&r1=155960&r2=155961
==============================================================================
--- incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java (original)
+++ incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/property/constraint/PersonControl.java Wed Mar  2 13:37:27 2005
@@ -20,7 +20,7 @@
 
 	public final static double SAVINGS_MIN_VALUE=100;
 	public final static String ISSUEDATE_MAXVALUE="2007/01/31";
-	public final static String EXPIRYDATE_MINVALUE="2007/01/32";
+	public final static String EXPIRYDATE_MINVALUE="2007/02/28";
 	//public final static String ISSUEDATE_MAXVALUE=null;
 
     @PropertySet