Author: kylem
Date: Wed Aug 11 09:37:47 2004
New Revision: 36231

Added:
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlHandle.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlManifest.vm
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/packaging/
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/packaging/ControlJarTask.java
Removed:
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlHandle.java
Modified:
   incubator/beehive/trunk/controls/drt/build.xml
   
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.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/bean/ControlContainerContext.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.java
   
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlInterface.java
Log:
Added support for generating JavaBean jar manifest entries for all controls in 
a JAR file.  This is done by modifying annotation processing to generate 
manifest fragments for each control processed, and the creation of a new ant 
task (org.apache.beehive.controls.runtime.packaging.ControlJarTask) that 
derives from the standard Ant Jar task and will roll the manifest fragments up 
and write them to the created/updated manifest for the jar.

Moved the base interfaces for control/container event dispatch integration into 
the public API
set.


Modified: incubator/beehive/trunk/controls/drt/build.xml
==============================================================================
--- incubator/beehive/trunk/controls/drt/build.xml      (original)
+++ incubator/beehive/trunk/controls/drt/build.xml      Wed Aug 11 09:37:47 2004
@@ -5,10 +5,14 @@
     <property environment="os"/>
     <property file="${os.BEEHIVE_HOME}/beehive.properties"/>
 
-    <taskdef name="apt" 
classname="org.apache.beehive.controls.runtime.generator.AptTask" 
+    <taskdef name="apt" 
+             classname="org.apache.beehive.controls.runtime.generator.AptTask" 
              classpath="../build/jars/controls.jar" onerror="report" />
     <taskdef name="assemble" 
classname="org.apache.beehive.controls.runtime.assembly.AssembleTask" 
              classpath="../build/jars/controls.jar" onerror="report" />
+    <taskdef name="control-jar" 
+             
classname="org.apache.beehive.controls.runtime.packaging.ControlJarTask" 
+             classpath="../build/jars/controls.jar" onerror="report" />
 
     <!-- New V9 DRT Domain specific properties -->
     <property name="test.root" location="${basedir}"/>
@@ -99,7 +103,7 @@
                 <include name="**/*.controls.properties"/>
             </fileset>
         </assemble>
-        <jar destfile="${build.jars}/drtbeans.jar"  basedir="${build.beans}" />
+        <control-jar destfile="${build.jars}/drtbeans.jar"  
basedir="${build.beans}" />
     </target>
 
     <target name="build-tests">

Modified: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
    (original)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlBeanContext.java
    Wed Aug 11 09:37:47 2004
@@ -110,6 +110,18 @@
     public <T> T getService(Class<T> serviceClass, Object selector);
 
     /**
+     * Returns a ControlHandle instance that enables operations and events to 
be dispatched
+     * to the target control, if it is running inside of a container that 
supports external
+     * event dispatch.  If the runtime container for the control does not 
support this
+     * functionality, a value of null will be returned.
+     *
+     * @return a ControlHandle instance for the control, or null.
+     *
+     * @see org.apache.beehive.control.api.context.ControlHandle
+     */
+    public ControlHandle getControlHandle();
+
+    /**
      * The Lifecycle event interface defines a set of lifecycle events exposed 
by the
      * ControlBeanContext to any registered listener.
      */

Added: 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlHandle.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/api/org/apache/beehive/controls/api/context/ControlHandle.java
 Wed Aug 11 09:37:47 2004
@@ -0,0 +1,47 @@
+package org.apache.beehive.controls.api.context;
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2001-2004  BEA Systems, Inc.
+ *
+ * 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.reflect.InvocationTargetException;
+
+/**
+ * The ControlHandle interface defines a reference object to a control 
instance that enables
+ * control events to be fired on the control.  Control container 
implementations will provide
+ * implementation of this interface that use container-specific dispatch 
mechanisms to locate
+ * the appropriate control container instance when events are fired.
+ */
+public interface ControlHandle
+{
+    /**
+     * Returns the controlID of the target control referenced by this handle
+     */
+    public String getControlID();
+
+    /**
+     * Invokes the named operation on the target control referenced by this 
handle.
+     */
+    public Object invokeOperation(String operationName, Object [] args) 
+                  throws InvocationTargetException;
+
+    /**
+     * Delivers the specified event to the target control referenced by this 
handle.
+     */
+    public Object sendEvent(String eventSet, String eventName, Object [] args) 
+                  throws InvocationTargetException;
+}

Modified: 
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/bean/ControlBeanContext.java
       (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
       Wed Aug 11 09:37:47 2004
@@ -41,6 +41,7 @@
 import org.apache.beehive.controls.api.ControlException;
 import org.apache.beehive.controls.api.bean.ControlExtension;
 import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.context.ControlHandle;
 import org.apache.beehive.controls.api.properties.AnnotatedElementMap;
 import org.apache.beehive.controls.api.properties.PropertyMap;
 import org.apache.beehive.controls.api.properties.PropertySet;
@@ -590,6 +591,28 @@
             // revocation notifications failed for some reason.
             throw new ControlException("Unable to register for service 
events", tmle);
         }
+    }
+
+    //
+    // ControlBeanContext.getControlHandle
+    //
+    public ControlHandle getControlHandle()
+    {
+        //
+        // Find the associated ControlContainerContext, which provides a 
container-specific
+        // implementation of ControlHandle
+        //
+        ControlBeanContext beanContext = this;
+        while (beanContext != null && !(beanContext instanceof 
ControlContainerContext))
+            beanContext = (ControlBeanContext)beanContext.getBeanContext();
+
+        if (beanContext == null)
+            return null;
+
+        //
+        // Ask the container for a ControlHandle instance referencing the 
target bean
+        //
+        return ((ControlContainerContext)beanContext).getControlHandle(_bean);
     }
 
     //

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java
  (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlContainerContext.java
  Wed Aug 11 09:37:47 2004
@@ -22,6 +22,7 @@
 import java.lang.reflect.Method;
 import java.util.Stack;
 
+import org.apache.beehive.controls.api.context.ControlHandle;
 import org.apache.beehive.controls.api.context.ResourceContext;
 
 /**
@@ -204,9 +205,10 @@
      * Returns a ControlHandle to the component containing the control.  This 
handle can be
      * used to dispatch events and operations to a control instance.  This 
method will return
      * null if the containing component does not support direct dispatch.
+     *
      * @param targetID the composite ID of the target control bean
      */
-    public ControlHandle getHandle(String targetID)
+    protected ControlHandle getControlHandle(ControlBean bean)
     {
         //
         // The base implementation doesn't support dispatch.  Containers 
should override

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.java
 (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.java
 Wed Aug 11 09:37:47 2004
@@ -65,6 +65,11 @@
     public String getClassName() { return _className; }
 
     /**
+     * Returns the class as a Jar Manifest Name attribute
+     */
+    public String getManifestName() { return _className.replace('.','/') + 
".class"; }
+
+    /**
      * Returns the public or extension interface associated with the 
ControlBean
      */
     public ControlInterface getControlInterface() { return _controlIntf; }

Modified: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlInterface.java
==============================================================================
--- 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlInterface.java
    (original)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlInterface.java
    Wed Aug 11 09:37:47 2004
@@ -176,11 +176,23 @@
         map.put("intf", this);                  // the control interface
         map.put("bean", _bean);
 
-        Writer writer = new 
IndentingWriter(filer.createSourceFile(_bean.getClassName()));
-        GeneratorOutput genOut = 
-            new GeneratorOutput(writer, 
"org/apache/beehive/controls/runtime/generator/ControlBean.vm", map);
-        ArrayList<GeneratorOutput> genList = new ArrayList(1);
-        genList.add(genOut);
+        ArrayList<GeneratorOutput> genList = new ArrayList();
+
+        Writer beanWriter = new 
IndentingWriter(filer.createSourceFile(_bean.getClassName()));
+        GeneratorOutput beanSource = 
+            new GeneratorOutput(beanWriter, 
+                               
"org/apache/beehive/controls/runtime/generator/ControlBean.vm", map);
+        genList.add(beanSource);
+
+        Writer manifestWriter = 
filer.createTextFile(Filer.Location.CLASS_TREE, _bean.getPackage(),
+                                                     new 
File(_bean.getShortName() + ".class.manifest"), 
+                                                     null);
+        GeneratorOutput beanManifest =
+            new GeneratorOutput(manifestWriter,
+                                
"org/apache/beehive/controls/runtime/generator/ControlManifest.vm", 
+                                map);
+        genList.add(beanManifest);
+
         return genList;
     }
 

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlManifest.vm
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlManifest.vm
       Wed Aug 11 09:37:47 2004
@@ -0,0 +1,37 @@
+##
+## The Velocity code generation template for the JAR manifest file 
(META-INF/MANIFEST.MF)
+## entries associated with a control bean and its public interface or 
extension class.
+##
+## B E A   S Y S T E M S
+## Copyright 2001-2004  BEA Systems, Inc.
+##
+## 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:$
+##
+## The following context variables are used by this template:
+##      $bean - a ControlBean instance that defines the attributes of the bean
+##      $intf - a ControlInterface instance that defines the attributes of the 
public interface
+##
+##
+## THE CONTROL BEAN MANIFEST.MF TEMPLATE
+##
+## This template defines the JAR manifest contents that will be injected into 
any JAR file
+## containing Beehive controls.  The template is used to generate per-control 
manifest files,
+## which are then merged by the 
org.apache.beehive.controls.runtime.packaging.ControlJarTask
+## ant task into a single JAR manifest file.
+##
+Manifest-Version: 1.0
+
+Name: $bean.manifestName
+JavaBean: true

Added: 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/packaging/ControlJarTask.java
==============================================================================
--- (empty file)
+++ 
incubator/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/packaging/ControlJarTask.java
      Wed Aug 11 09:37:47 2004
@@ -0,0 +1,158 @@
+package org.apache.beehive.controls.runtime.packaging;
+
+/*
+ * B E A   S Y S T E M S
+ * Copyright 2001-2004  BEA Systems, Inc.
+ *
+ * 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.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Jar;
+import org.apache.tools.ant.taskdefs.Manifest;
+import org.apache.tools.ant.taskdefs.ManifestException;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.zip.ZipOutputStream;
+
+/**
+ * The ControlTask class extends the standard ant Jar task to perform
+ * additional processing for JAR files that contain Beehive Controls.
+ */
+public class ControlJarTask extends Jar
+{
+    private static FileUtils fileUtils = FileUtils.newFileUtils();
+
+    /**
+     * Step #1: Wrap the implementation of Zip.grabResources.  This method 
identifies the
+     * set of resources to be stored in the JAR file.   For each added/updated 
resource,
+     * the overrided method will look for an associated .manifest file that any
+     * JAR manifest data to add/update in the JAR manifest.
+     */
+    protected Resource[][] grabResources(FileSet[] filesets) 
+    {
+        //
+        // Get the list of resources being added/updated by calling 
Zip.grabResources
+        //
+        Resource [][] resources = super.grabResources(filesets);
+
+        //
+        // Iterate through the resources for each input FileSet, looking for 
an associated
+        // manifest file.
+        //
+        for (int i = 0; i < filesets.length; i++)
+        {
+            if (resources[i].length == 0)
+                continue;
+
+            File base = filesets[i].getDir(getProject());
+            Resource [] setResources = resources[i];
+
+            for (int j = 0; j < setResources.length; j++)
+            {
+                File manifestFile = 
+                    fileUtils.resolveFile(base, setResources[j].getName() + 
".manifest");
+                if (manifestFile.exists())
+                    manifestFiles.add(manifestFile);
+            }
+        }
+
+        return resources;
+    }
+
+    /**
+     * Step #2: Override Jar.initZipOutputStream to inject manifest sections.  
This is done
+     * by treating them as if they were 'inline' entries, from a <jar> task 
perspective.
+     */
+    protected void initZipOutputStream(ZipOutputStream zOut) throws 
IOException, BuildException 
+    {
+        if (manifestFiles.size() != 0)
+        {
+            //
+            // Create a default (empty) manifest
+            //
+            Manifest mergeManifest = Manifest.getDefaultManifest();
+
+            //
+            // Iterate through each found manifest file, merging its contents 
into the
+            // merge manifest
+            //
+            for (File manifestFile : manifestFiles)
+            {
+                FileInputStream fis = null;
+                try
+                {
+                    fis = new FileInputStream(manifestFile);
+                    Manifest resourceManifest = new Manifest(new 
InputStreamReader(fis));
+                    mergeManifest.merge(resourceManifest);
+                }
+                catch (IOException ioe)
+                {
+                    throw new BuildException("Unable to read manifest file:" + 
manifestFile, ioe);
+                }
+                catch (ManifestException me)
+                {
+                    throw new BuildException("Unable to process manifest file: 
"+ manifestFile, me);
+                }
+                finally 
+                {
+                    if (fis != null) fis.close();
+                }
+            }
+
+            //
+            // Set the merge manifest as the 'configured' manifest.   This 
will treat its
+            // contents as if they had been included inline with the <jar> 
task, with
+            // similar precedence rules.
+            //
+            try
+            {
+                addConfiguredManifest(mergeManifest);
+            }
+            catch (ManifestException me)
+            {
+                throw new BuildException("Unable to add new manifest entries:" 
+ me);
+            }
+        }
+
+        super.initZipOutputStream(zOut);
+    }
+
+    protected void addToManifest(Manifest jarManifest, List<File> mergeList)
+    {
+    }
+
+    /**
+     * Reset the manifest file list to be empty
+     */
+    protected void cleanUp()
+    {
+        manifestFiles = new Vector<File>();
+    }
+
+    /**
+     * Contains the set of manifest entries to merge into the JAR manifest
+     */
+    private List<File> manifestFiles = new Vector<File>();
+}

Reply via email to