You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/04/26 03:17:12 UTC

svn commit: r397041 - in /beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime: bean/ControlBean.java bean/ControlBeanContext.java bean/DefaultControlBeanContextFactory.java bean/InterceptorUtils.java generator/ControlBean.vm

Author: ekoneil
Date: Tue Apr 25 18:17:08 2006
New Revision: 397041

URL: http://svn.apache.org/viewcvs?rev=397041&view=rev
Log:
Code changes in core controls.  This moves the interceptor support methods off of ControlBeanContext and into their own InterceptorUtils class.  The old constant / static method will be deleted in a subsequent release.

BB: self
Test: Controls pass


Added:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java
Modified:
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java
    beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java?rev=397041&r1=397040&r2=397041&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBean.java Tue Apr 25 18:17:08 2006
@@ -61,8 +61,8 @@
  * The ControlBean class is an abstract base class for the JavaBean classes generated to support
  * Beehive Controls.
  * <p>
- * The ControlBean class indirectly implements BeanContextProxy; the ControlBeanContext that it contains/scopes
- * acts as that proxy.
+ * The ControlBean class indirectly implements BeanContextProxy; the
+ * {@link org.apache.beehive.controls.api.context.ControlBeanContext} that it contains/scopes acts as that proxy.
  * <p>
  * All support APIs (which may be called from derived subclasses or contextual services)
  * are generally marked as protected and have names that start with an underscore.  This avoids the
@@ -469,8 +469,6 @@
             //
             if ( interceptorNames != null )
             {
-                ControlBeanContext cbc = getControlBeanContext();
-
                 for (int cnt = interceptorNames.length-1; cnt >= 0; cnt-- )
                 {
                     String n  = interceptorNames[cnt];

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java?rev=397041&r1=397040&r2=397041&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlBeanContext.java Tue Apr 25 18:17:08 2006
@@ -28,14 +28,9 @@
 import java.beans.beancontext.BeanContextServiceProvider;
 import java.beans.beancontext.BeanContextServices;
 import java.beans.beancontext.BeanContextServicesSupport;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.BufferedReader;
-import java.io.IOException;
 import java.util.Iterator;
 import java.util.HashMap;
 import java.util.TooManyListenersException;
-import java.util.ArrayList;
 import java.util.Vector;
 import java.util.HashSet;
 import java.util.Set;
@@ -622,83 +617,6 @@
         return getControlInterface().getClassLoader();
     }
 
-    /**
-     * Filename that contains ordering priority for controls interceptor services.
-     * Each line in the file is a fully qualified interface name.  The first line in the file
-     * is highest priority.
-     */
-    public static final String INTERCEPTOR_CONFIG_FILE = "controls-interceptors.config";
-
-    /**
-     * Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for
-     * controls interceptor services.
-     *
-     * @param interceptors
-     * @return String[]
-     */
-    public static String[] prioritizeInterceptors( String [] interceptors )
-    {
-        if ( interceptors == null )
-            return null;
-
-        // Read external configuration to obtain desired prioritization.
-        if ( _interceptorPriorities == null )
-        {
-            // Only ever attempt to read the external configuration once; bounce the VM if you
-            // want to try again.
-            _interceptorPriorities = new ArrayList<String>();
-            BufferedReader in = null;
-            try
-            {
-                InputStream configFileStream =
-                    ControlBeanContext.class.getClassLoader().getResourceAsStream( INTERCEPTOR_CONFIG_FILE );
-
-                if ( configFileStream != null )
-                {
-                    in = new BufferedReader(new InputStreamReader(configFileStream));
-                    String str;
-                    while ((str = in.readLine()) != null)
-                        _interceptorPriorities.add(str);
-                }
-            }
-            catch (IOException e)
-            {
-                // ignore
-            }
-            finally
-            {
-                try {
-                    if (in != null)
-                        in.close();
-                }
-                catch ( IOException ie ) { /* ignore */ }
-            }
-        }
-
-        // Put input list of interceptors into a Set for easy lookup
-        Set<String> input = new HashSet<String>();
-        for ( String ii : interceptors )
-            input.add( ii );
-
-        // Scan through priorities list, building a prioritized list
-        ArrayList<String> prioritized = new ArrayList<String>(interceptors.length);
-        for ( String p : _interceptorPriorities )
-        {
-            if ( input.contains(p) )
-            {
-                input.remove(p);
-                prioritized.add(p);
-            }
-        }
-
-        // Anything still left in the input set did not have a priority associated with it,
-        // so they just go at the end in arbitrary order.
-        for ( String p : input )
-            prioritized.add(p);
-
-        return prioritized.toArray(new String[prioritized.size()]);
-    }
-
     //
     // ControlBeanContext.addLifeCycleListener
     //
@@ -851,6 +769,28 @@
     }
 
     /**
+     * Filename that contains ordering priority for controls interceptor services.
+     * Each line in the file is a fully qualified interface name.  The first line in the file
+     * is highest priority.
+     * @deprecated Use {@link InterceptorUtils#INTERCEPTOR_CONFIG_FILE} instead.  This constant
+     *             will be removed in the next point release.
+     */
+    public static final String INTERCEPTOR_CONFIG_FILE = "controls-interceptors.config";
+
+    /**
+     * Applies externally defined (via INTERCEPTOR_CONFIG_FILE) ordering priority for
+     * controls interceptor services.
+     *
+     * @param interceptors
+     * @return String[]
+     * @deprecated Use {@link InterceptorUtils#prioritizeInterceptors(String[])} instead.  This method will
+     *             be removed in the next point release.
+     */
+    public static String[] prioritizeInterceptors( String [] interceptors ) {
+        return InterceptorUtils.prioritizeInterceptors(interceptors);
+    }
+
+    /**
      * The ControlBeanContextProvider inner class acts as a single BeanContext service
      * provider for the ControlBeanContext service class.  The implementation is simple,
      * because the runtime ControlBeanContext implementation class directly implements
@@ -897,11 +837,6 @@
      * completely stateless and thread-safe.
      */
     private static ControlBeanContextProvider theProvider = new ControlBeanContextProvider();
-
-    /**
-     * List that keeps track of the interceptors in their priority order.
-     */
-    private static ArrayList<String> _interceptorPriorities;
 
     /**
      * The ControlBean instance that this context is providing services for.  This value can

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java?rev=397041&r1=397040&r2=397041&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/DefaultControlBeanContextFactory.java Tue Apr 25 18:17:08 2006
@@ -35,7 +35,8 @@
      */
     public ControlBeanContext instantiate(ControlBean controlBean) {
         if(!(controlBean instanceof org.apache.beehive.controls.runtime.bean.ControlBean))
-            throw new IllegalArgumentException("The ControlBean of type \"" + controlBean.getClass().getName() +
+            throw new IllegalArgumentException("The ControlBean of type \"" +
+                controlBean.getClass().getName() +
                 "\" is unsupported.  The ControlBean must extend " +
                 org.apache.beehive.controls.runtime.bean.ControlBean.class.getName());
 

Added: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java?rev=397041&view=auto
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java (added)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java Tue Apr 25 18:17:08 2006
@@ -0,0 +1,115 @@
+/*
+ * Copyright 2006 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:$
+ */
+package org.apache.beehive.controls.runtime.bean;
+
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.IOException;
+
+/**
+ * Class used to support prioritizing interceptors on methods of a {@link ControlBean}.
+ */
+public final class InterceptorUtils {
+
+    /**
+     * Filename that contains ordering priority for controls interceptor services.
+     * Each line in the file is a fully qualified interface name.  The first line in the file
+     * is highest priority.
+     */
+    public static final String INTERCEPTOR_CONFIG_FILE = "controls-interceptors.config";
+
+    // todo: this interceptor priority list should be stored by ClassLoader instead of shared between them
+    /**
+     * List that keeps track of the interceptors in their priority order.
+     */
+    private static ArrayList<String> _interceptorPriorities;
+
+    /**
+     * Applies externally defined (via {@link #INTERCEPTOR_CONFIG_FILE}) ordering priority for
+     * controls interceptor services.
+     *
+     * @param interceptors
+     * @return String[]
+     */
+    public static String[] prioritizeInterceptors( String [] interceptors )
+    {
+        if ( interceptors == null )
+            return null;
+
+        // Read external configuration to obtain desired prioritization.
+        if ( _interceptorPriorities == null )
+        {
+            // Only attempt to read the external configuration once; bounce the VM if you
+            // want to try again.
+            _interceptorPriorities = new ArrayList<String>();
+            BufferedReader in = null;
+            try
+            {
+                InputStream configFileStream =
+                    ControlBeanContext.class.getClassLoader().getResourceAsStream( INTERCEPTOR_CONFIG_FILE );
+
+                if ( configFileStream != null )
+                {
+                    in = new BufferedReader(new InputStreamReader(configFileStream));
+                    String str;
+                    while ((str = in.readLine()) != null)
+                        _interceptorPriorities.add(str);
+                }
+            }
+            catch (IOException e)
+            {
+                // ignore
+            }
+            finally
+            {
+                try {
+                    if (in != null)
+                        in.close();
+                }
+                catch ( IOException ie ) { /* ignore */ }
+            }
+        }
+
+        // Put input list of interceptors into a Set for easy lookup
+        Set<String> input = new HashSet<String>();
+        for ( String ii : interceptors )
+            input.add( ii );
+
+        // Scan through priorities list, building a prioritized list
+        ArrayList<String> prioritized = new ArrayList<String>(interceptors.length);
+        for ( String p : _interceptorPriorities )
+        {
+            if ( input.contains(p) )
+            {
+                input.remove(p);
+                prioritized.add(p);
+            }
+        }
+
+        // Anything still left in the input set did not have a priority associated with it,
+        // so they just go at the end in arbitrary order.
+        for ( String p : input )
+            prioritized.add(p);
+
+        return prioritized.toArray(new String[prioritized.size()]);
+    }
+}

Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm?rev=397041&r1=397040&r2=397041&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/ControlBean.vm Tue Apr 25 18:17:08 2006
@@ -599,13 +599,13 @@
 #macro (prioritizeInterceptors)
     #foreach ($operation in $intf.operations)
         #if ($operation.interceptorServiceNames.size() != 0)
-        ${operation.methodField}Interceptors = org.apache.beehive.controls.runtime.bean.ControlBeanContext.prioritizeInterceptors( ${operation.methodField}Interceptors );
+        ${operation.methodField}Interceptors = org.apache.beehive.controls.runtime.bean.InterceptorUtils.prioritizeInterceptors( ${operation.methodField}Interceptors );
         #end
     #end
     #foreach ($eventSet in $intf.eventSets)
         #foreach ($event in $eventSet.events)
             #if ($event.interceptorServiceNames.size() != 0)
-		        ${event.methodField}Interceptors = org.apache.beehive.controls.runtime.bean.ControlBeanContext.prioritizeInterceptors(${event.methodField}Interceptors);
+		        ${event.methodField}Interceptors = org.apache.beehive.controls.runtime.bean.InterceptorUtils.prioritizeInterceptors(${event.methodField}Interceptors);
 		    #end
         #end
     #end