Author: kentam
Date: Tue Dec  7 02:24:29 2004
New Revision: 110100

URL: http://svn.apache.org/viewcvs?view=rev&rev=110100
Log:
Initial implementation of controls versioning (versioning for controls source 
artifacts).  See spec at 
http://wiki.apache.org/beehive/Controls/ControlsVersioning for details.

DRT: windows


Added:
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/Version.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionRequired.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionSupported.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/Hello.java
   (contents, props changed)
   
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/HelloImpl.jcs
   (contents, props changed)
Modified:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm

Added: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/Version.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/Version.java?view=auto&rev=110100
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/Version.java
    Tue Dec  7 02:24:29 2004
@@ -0,0 +1,45 @@
+package org.apache.beehive.controls.api.versioning;
+/*
+ * 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.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Used by the control author to specify the version (major.minor) of the 
control interface.
+ * Allowed on interfaces annotated with @ControlInterface.  This version number
+ * is the basis for control versioning, and versioning constraints against it 
are enforced both at
+ * compile time and runtime.
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]({ElementType.TYPE})
+public @interface Version
+{
+    /**
+     * Major version number, typically used to track significant functionality 
changes.
+     */
+    int major(); 
+    /**
+     * Minor version number, typically used to track small internal 
changes/fixes.  Version
+     * constraints default to ignoring the minor version number in their 
comparisons, but may
+     * be configured to specify a particular minor version.
+     */
+    int minor() default 0;
+}

Added: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionRequired.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionRequired.java?view=auto&rev=110100
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionRequired.java
    Tue Dec  7 02:24:29 2004
@@ -0,0 +1,55 @@
+package org.apache.beehive.controls.api.versioning;
+/*
+ * 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.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *  Specifies the minimum version of the control interface that this extension
+ *  requires.  Allowed on control extensions (interfaces annotated with
+ *  @ControlExtension), and on control field declarations (fields annotated
+ *  with @Control).  The version requirement is enforced at compile time of
+ *  extensions and control client, and at runtime when the appropriate control
+ *  bean is classloaded.
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]({ElementType.TYPE, ElementType.FIELD})
+public @interface VersionRequired
+{
+    /**
+     * The major version value required for this control extension or instance
+     * declaration to work.  Any version number greater than or equal to this
+     * value will suffice, implying that this requirement is valid only when
+     * back compatibility is part of the contract when increasing the version
+     * number.  Negative values mean that any major version is
+     * acceptable (in which case this annotation should probably just not be
+     * present).
+     */
+    int major(); 
+
+    /**
+     * The minor version value required for this control extension or instance
+     * declaration to work.  Any version number greater than or equal to this
+     * value will suffice.  Negative values mean that any minor version is
+     * acceptable (the default case).
+     */
+    int minor() default -1;
+}

Added: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionSupported.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionSupported.java?view=auto&rev=110100
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/versioning/VersionSupported.java
   Tue Dec  7 02:24:29 2004
@@ -0,0 +1,52 @@
+package org.apache.beehive.controls.api.versioning;
+/*
+ * 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.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ *  Specifies the maximum version of the control interface that this 
implementation
+ *  supports.  Allowed on control implementations (interfaces annotated with
+ *  @ControlImplementation).  This version requirement is enforced at compile 
time
+ *  of the implementation, and at runtime when the implementation is 
classloaded.
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]({ElementType.TYPE})
+public @interface VersionSupported
+{
+    /**
+     * The major version of the control interface that this implementation
+     * supports.  Any version number less than or equal to this value will 
suffice,
+     * implying that this constraint is only valid when backwards compatibility
+     * is part of the contract when increasing the version number.  Negative
+     * values mean that any major version is acceptable (in which case this
+     * annotation should probably just not be
+     * present).
+     */
+    int major(); 
+
+    /**
+     * The minor version of the control interface that this implementation
+     * supports.  Any version number less than or equal to this value will 
suffice.
+     * Negative values mean that any minor version is acceptable (the default 
case).
+     */
+    int minor() default -1;
+}

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?view=diff&rev=110100&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java&r1=110099&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java&r2=110100
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
      (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
      Tue Dec  7 02:24:29 2004
@@ -20,9 +20,7 @@
 import java.beans.beancontext.BeanContext;
 import java.beans.beancontext.BeanContextServices;
 import java.beans.PropertyChangeSupport;
-import java.beans.PropertyChangeListener;
 import java.beans.VetoableChangeSupport;
-import java.beans.VetoableChangeListener;
 import java.io.IOException;
 import java.io.ObjectOutputStream;
 import java.lang.reflect.AnnotatedElement;
@@ -32,8 +30,12 @@
 import java.util.concurrent.Semaphore;
 
 import org.apache.beehive.controls.api.ControlException;
+import org.apache.beehive.controls.api.versioning.VersionRequired;
+import org.apache.beehive.controls.api.versioning.Version;
 import org.apache.beehive.controls.api.bean.Threading;
 import org.apache.beehive.controls.api.bean.ThreadingPolicy;
+import org.apache.beehive.controls.api.bean.ControlExtension;
+import org.apache.beehive.controls.api.bean.ControlInterface;
 import org.apache.beehive.controls.api.context.ControlThreadContext;
 import org.apache.beehive.controls.api.events.EventRef;
 import org.apache.beehive.controls.api.events.EventSet;
@@ -696,6 +698,76 @@
     {
         throw new IllegalArgumentException("No parameter name data for " + m);
     }
+
+    /**
+     * Computes the most derived ControlInterface for the specified 
ControlExtension.
+     * @param controlIntf
+     * @return
+     */
+    public static Class getMostDerivedInterface(Class controlIntf)
+    {
+        while (controlIntf.isAnnotationPresent(ControlExtension.class))
+        {
+            Class [] intfs = controlIntf.getInterfaces();
+            boolean found = false;
+            for (int i = 0; i < intfs.length; i++)
+            {
+                if (intfs[i].isAnnotationPresent(ControlExtension.class) ||
+                    intfs[i].isAnnotationPresent(ControlInterface.class))
+                {
+                    controlIntf = intfs[i];
+                    found = true;
+                    break;
+                }
+            }
+            if (!found)
+            {
+                throw new ControlException("Can't find base control interface 
for " + controlIntf);
+            }
+        }
+        return controlIntf;
+    }
+
+    /**
+     * Enforces the VersionRequired annotation at runtime (called from each 
ControlBean).
+     * @param intfName
+     * @param version
+     * @param versionRequired
+     */
+    protected static void enforceVersionRequired(String intfName, Version 
version, VersionRequired versionRequired)
+    {
+        if ( versionRequired != null )
+        {
+            int majorRequired = versionRequired.major();
+            int minorRequired = versionRequired.minor();
+
+            if ( majorRequired < 0 )    // no real version requirement
+                return;
+
+            int majorPresent = -1;
+            int minorPresent = -1;
+            if ( version != null )
+            {
+                majorPresent = version.major();
+                minorPresent = version.minor();
+
+                if ( majorRequired <= majorPresent &&
+                     (minorRequired < 0 || minorRequired <= minorPresent) )
+                {
+                    // Version requirement is satisfied
+                    return;
+                }
+            }
+
+            //
+            // Version requirement failed
+            //
+            throw new ControlException( "Control extension " + intfName + " 
fails version requirement: requires interface version " +
+                    majorRequired + "." + minorRequired + ", found interface 
version " +
+                    majorPresent + "." + minorPresent + "." );
+        }
+    }
+
 
     /**
      * Implementation of the Java serialization writeObject method

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?view=diff&rev=110100&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r1=110099&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java&r2=110100
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
       (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
       Tue Dec  7 02:24:29 2004
@@ -471,27 +471,9 @@
      */
     static public Class getDefaultControlBinding(Class controlIntf)
     {
-        while (controlIntf.isAnnotationPresent(ControlExtension.class))
-        {
-            Class [] intfs = controlIntf.getInterfaces();
-            boolean found = false;
-            for (int i = 0; i < intfs.length; i++)
-            {
-                if (intfs[i].isAnnotationPresent(ControlExtension.class) ||
-                    intfs[i].isAnnotationPresent(ControlInterface.class))
-                {
-                    controlIntf = intfs[i];
-                    found = true;
-                    break;
-                }
-            }
-            if (!found)
-            {
-                throw new ControlException("Can't find base control interface 
for " + controlIntf);
-            }
-        }
+        controlIntf = ControlBean.getMostDerivedInterface(controlIntf);
 
-        ControlInterface intfAnnot = 
+        ControlInterface intfAnnot =
                     
(ControlInterface)controlIntf.getAnnotation(ControlInterface.class);
         String implBinding = intfAnnot.defaultBinding();
         implBinding = resolveDefaultBinding( implBinding, 
controlIntf.getName() );

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java?view=diff&rev=110100&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java&r1=110099&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java&r2=110100
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java
    (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlImplementation.java
    Tue Dec  7 02:24:29 2004
@@ -38,6 +38,8 @@
 
 import org.apache.beehive.controls.api.events.Client;
 import org.apache.beehive.controls.api.events.EventHandler;
+import org.apache.beehive.controls.api.versioning.VersionSupported;
+import org.apache.beehive.controls.api.versioning.Version;
 
 /**
  * The AptControlImplementation class provides validation and metadata 
management when
@@ -83,6 +85,10 @@
               "Control implementations must implement a control interface");
             return;
         }
+
+        _versionSupported = initVersionSupported();
+
+        enforceVersionSupported();
     }
 
     /**
@@ -187,6 +193,11 @@
     public ArrayList<AptClientField> getClients() { return _clients; }
 
     /**
+     * Returns the VersionSupported annotation, if any.
+     */
+    public VersionSupported getVersionSupported() { return _versionSupported; }
+
+    /**
      * Returns true if the implemenation class contains any nested event 
proxies
      */
     public boolean hasClients() { return _clients.size() != 0; }
@@ -391,11 +402,63 @@
         } 
     }
 
-    ClassDeclaration _implDecl;
-    AnnotationProcessorEnvironment _env;
-    AptControlImplementation    _superClass;
-    ArrayList<AptContextField>  _contexts;
-    ArrayList<AptClientField>   _clients;
-    ArrayList<AptControlField>  _controls;
-    ImplInitializer _init;
+    private VersionSupported initVersionSupported()
+    {
+        if ( _implDecl == null )
+            return null;
+        return _implDecl.getAnnotation(VersionSupported.class);
+    }
+
+    /**
+     * Enforces the VersionRequired annotation for control extensions.
+     */
+    private void enforceVersionSupported()
+    {
+        if ( _versionSupported != null )
+        {
+            int majorSupported = _versionSupported.major();
+            int minorSupported = _versionSupported.minor();
+
+            if ( majorSupported < 0 )    // no real version support requirement
+                return;
+
+            AptControlInterface ci = getControlInterface();
+            if ( ci == null )
+                return;
+
+            int majorPresent = -1;
+            int minorPresent = -1;
+            Version ciVersion = ci.getVersion();
+            if ( ciVersion != null )
+            {
+                majorPresent = ciVersion.major();
+                minorPresent = ciVersion.minor();
+
+                if ( majorSupported >= majorPresent &&
+                     (minorSupported < 0 || minorSupported >= minorPresent) )
+                {
+                    // Version requirement is satisfied
+                    return;
+                }
+            }
+
+            //
+            // Version requirement failed
+            //
+            _env.getMessager().printError( _implDecl.getPosition(),
+                    "Control implementation " + _implDecl + " fails version 
support requirement: " +
+                    "highest supported interface version is " +
+                    majorSupported + "." + minorSupported + ", found interface 
version " +
+                    majorPresent + "." + minorPresent + "." );
+        }
+    }
+
+    private ClassDeclaration                _implDecl;
+    private AnnotationProcessorEnvironment  _env;
+    private AptControlImplementation        _superClass;
+    private ArrayList<AptContextField>      _contexts;
+    private ArrayList<AptClientField>       _clients;
+    private ArrayList<AptControlField>      _controls;
+    private ImplInitializer                 _init;
+    private VersionSupported                _versionSupported;
 }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java?view=diff&rev=110100&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java&r1=110099&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java&r2=110100
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/AptControlInterface.java
 Tue Dec  7 02:24:29 2004
@@ -42,10 +42,8 @@
 import org.apache.beehive.controls.api.packaging.ManifestAttribute;
 import org.apache.beehive.controls.api.packaging.ManifestAttributes;
 import org.apache.beehive.controls.api.properties.PropertySet;
-
-/*
- * REVIEW: does it make sense to define AptControlExtension and/or 
ControlExtension?
- */
+import org.apache.beehive.controls.api.versioning.Version;
+import org.apache.beehive.controls.api.versioning.VersionRequired;
 
 /**
  * The AptControlInterface provides validation and metadata management for a 
ControlInterface
@@ -72,6 +70,8 @@
         _intfDecl = (InterfaceDeclaration)decl;
         setDeclaration(_intfDecl);
 
+        _isExtension = initIsExtension();
+
         _superClass = initSuperClass();
 
         _operations = initOperations();
@@ -82,18 +82,31 @@
 
         _featureInfo = initFeatureInfo();
 
+        _version = initVersion();
+        _versionRequired = initVersionRequired();
+
         //
         // Construct a bean instance for this interface
         //
         _bean = new ControlBean(this);
 
         //
-        // If this is an control extension, run the control-author-specified
-        // checker class to perform additional validation.
+        // Do work specific to control extensions
         //
 
         if (isExtension())
+        {
+            //
+            // Enforce VersionRequired semantics
+            //
+            enforceVersionRequired();
+
+            //
+            // If this is an control extension, run the 
control-author-specified
+            // checker class to perform additional validation.
+            //
             check();
+        }
     }
 
     /**
@@ -406,6 +419,22 @@
     }
 
     /**
+     * Returns the Version annotation, if any.
+     */
+    public Version getVersion()
+    {
+        return _version;
+    }
+
+    /**
+     * Returns the VersionRequired annotation, if any.
+     */
+    public VersionRequired getVersionRequired()
+    {
+        return _versionRequired;
+    }
+
+    /**
      * Returns the information necessary to generate a ControlBean from this 
AptControlInterface
      */
     public List<GeneratorOutput> getCheckOutput(Filer filer) throws IOException
@@ -473,10 +502,7 @@
      */
     public boolean isExtension()
     {
-        if ( _intfDecl == null )
-            return false;
-
-        return _intfDecl.getAnnotation(ControlExtension.class) != null;
+        return _isExtension;
     }
 
     /**
@@ -574,9 +600,20 @@
     }
 
     /**
+     * Computes whether this interface is a ControlInterface or a 
ControlExtension
+     */
+    private boolean initIsExtension()
+    {
+        if ( _intfDecl == null )
+            return false;
+
+        return _intfDecl.getAnnotation(ControlExtension.class) != null;
+    }
+
+    /**
      * Returns the FeatureInfo annotation for this control interface, or null 
if there is none.
      */
-    public FeatureInfo initFeatureInfo()
+    private FeatureInfo initFeatureInfo()
     {
         if ( _intfDecl == null )
             return null;
@@ -584,6 +621,69 @@
     }
 
     /**
+     * Returns the Version annotation for this control interface, or null if 
there is none.
+     */
+    private Version initVersion()
+    {
+        if ( _intfDecl == null )
+            return null;
+        return _intfDecl.getAnnotation(Version.class);
+    }
+
+    /**
+     * Returns the VersionRequired annotation for this control interface, or 
null if there is none.
+     */
+    private VersionRequired initVersionRequired()
+    {
+        if ( _intfDecl == null )
+            return null;
+        return _intfDecl.getAnnotation(VersionRequired.class);
+    }
+
+    /**
+     * Enforces the VersionRequired annotation for control extensions.
+     */
+    private void enforceVersionRequired()
+    {
+        if ( _versionRequired != null )
+        {
+            int majorRequired = _versionRequired.major();
+            int minorRequired = _versionRequired.minor();
+
+            if ( majorRequired < 0 )    // no real version requirement
+                return;
+
+            AptControlInterface ci = getMostDerivedInterface();
+            if ( ci == null )
+                return;
+
+            int majorPresent = -1;
+            int minorPresent = -1;
+            Version ciVersion = ci._version;
+            if ( ciVersion != null )
+            {
+                majorPresent = ciVersion.major();
+                minorPresent = ciVersion.minor();
+
+                if ( majorRequired <= majorPresent &&
+                     (minorRequired < 0 || minorRequired <= minorPresent) )
+                {
+                    // Version requirement is satisfied
+                    return;
+                }
+            }
+
+            //
+            // Version requirement failed
+            //
+            _env.getMessager().printError( _intfDecl.getPosition(),
+                    "Control extension " + _intfDecl + " fails version 
requirement: requires interface version " +
+                    majorRequired + "." + minorRequired + ", found interface 
version " +
+                    majorPresent + "." + minorPresent + "." );
+        }
+    }
+
+    /**
      * Runs control-specific checker class (if specified)
      */
     public void check()
@@ -656,15 +756,18 @@
         }
     }
 
-    private AptControlInterface    _superClass;
-    AptMethodSet<AptOperation>     _operations;
-    ArrayList<AptPropertySet>      _propertySets;
-    boolean                        _hasBoundProperties;
-    boolean                        _hasConstrainedProperties;;
-    ArrayList<AptEventSet>         _eventSets;
-    ControlBean                    _bean;
-    FeatureInfo                    _featureInfo;
-    InterfaceDeclaration           _intfDecl;
-    InterfaceDeclaration           _superDecl;
-    AnnotationProcessorEnvironment _env;
+    private AptControlInterface         _superClass;
+    private AptMethodSet<AptOperation>  _operations;
+    private ArrayList<AptPropertySet>   _propertySets;
+    private boolean                     _isExtension;        // true if 
ControlExtension, else ControlInterface
+    private boolean                     _hasBoundProperties;
+    private boolean                     _hasConstrainedProperties;;
+    private ArrayList<AptEventSet>      _eventSets;
+    private ControlBean                 _bean;
+    private FeatureInfo                 _featureInfo;
+    private Version                     _version;
+    private VersionRequired             _versionRequired;
+    private InterfaceDeclaration        _intfDecl;
+    private InterfaceDeclaration        _superDecl;
+    private AnnotationProcessorEnvironment _env;
 }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm?view=diff&rev=110100&p1=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm&r1=110099&p2=incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm&r2=110100
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
   (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
   Tue Dec  7 02:24:29 2004
@@ -365,6 +365,20 @@
     protected Map getPropertyMapCache() { return _annotCache; }
 #end
 ##
+## This macro enforces the VersionRequired annotation semantics
+##
+#macro (enforceVersionRequired)
+    /*
+     * Enforce VersionRequired
+     */
+    Class controlIntf = 
org.apache.beehive.controls.runtime.bean.ControlBean.getMostDerivedInterface(${intf.className}.class);
+
+    Version versionPresent = (Version)controlIntf.getAnnotation(Version.class);
+    VersionRequired versionRequired = 
(${bean.shortName}.class).getAnnotation(VersionRequired.class);
+
+    
org.apache.beehive.controls.runtime.bean.ControlBean.enforceVersionRequired("${intf.className}",
 versionPresent, versionRequired);
+#end
+##
 ## THE CONTROLBEAN CLASS TEMPLATE
 ##
 package $bean.package;
@@ -376,10 +390,11 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.beehive.controls.api.bean.Extensible;
+import org.apache.beehive.controls.api.bean.*;
 import org.apache.beehive.controls.api.context.ControlBeanContext;
 import org.apache.beehive.controls.api.properties.PropertyKey;
 import org.apache.beehive.controls.api.properties.PropertyMap;
+import org.apache.beehive.controls.api.versioning.*;
 
 public class ${bean.shortName} extends $bean.superClass.className implements 
$intf.className
 {
@@ -389,6 +404,7 @@
     static
     {
         #initMethodStatics()
+        #enforceVersionRequired()
     }
     #end
 

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/Hello.java
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/Hello.java?view=auto&rev=110100
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/Hello.java
  Tue Dec  7 02:24:29 2004
@@ -0,0 +1,47 @@
+package org.apache.beehive.controls.test.controls.versioning;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.properties.PropertySet;
+import org.apache.beehive.controls.api.versioning.Version;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]( major=2, minor=1 )
+public interface Hello
+{
+    //
+    // A simple enumerated type used to customize the greeting by gender
+    //
+    public enum GenderType
+    {
+        NEUTRAL, MALE, FEMALE
+    }
+
+    public @interface Gender
+    {
+        GenderType value();
+    }
+
+    /**
+     * Declare a simple PropertySet, that allows the salutation used by the 
custom
+     * control to be customized.
+     */
+    @PropertySet
+    @Target( {ElementType.TYPE, ElementType.FIELD, ElementType.METHOD} )
+    @Retention(RetentionPolicy.RUNTIME)
+    public @interface Greeting
+    {
+        String salutation() default "Hello";
+        Gender gender() default @Gender(GenderType.NEUTRAL);
+    }
+
+    java.lang.String hello(java.lang.String name);
+
+    java.lang.String lastVisitor();
+
+    int visitorCount();
+}

Added: 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/HelloImpl.jcs
Url: 
http://svn.apache.org/viewcvs/incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/HelloImpl.jcs?view=auto&rev=110100
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/test/src/controls/org/apache/beehive/controls/test/controls/versioning/HelloImpl.jcs
       Tue Dec  7 02:24:29 2004
@@ -0,0 +1,43 @@
+package org.apache.beehive.controls.test.controls.versioning;
+
+import java.lang.reflect.Method;
+
+import org.apache.beehive.controls.api.bean.ControlImplementation;
+import org.apache.beehive.controls.api.bean.Extensible;
+import org.apache.beehive.controls.api.versioning.VersionSupported;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]( major=2 )
+public class HelloImpl implements Hello, Extensible
+{ 
+    public String _lastVisitor = "<none>";
+    int _visitorCount = 0;
+
+    public String hello(String name)
+    {
+        _lastVisitor = name;
+        _visitorCount++;
+        return "Hello, " + name;
+    }
+
+    public String lastVisitor()
+    {
+        return _lastVisitor;
+    }
+
+    public int visitorCount()
+    {
+        return _visitorCount;
+    }
+
+    /**
+     * Implements the Extensible.invoke interface when a JCX-declared method 
is called
+     */
+    public Object invoke(Method method, Object [] args)
+    {
+        //
+        // To Be Implemented
+        //
+        return null; 
+    }
+} 

Reply via email to