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:49:45 UTC
svn commit: r397046 - in
/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime:
assembly/ bean/ generator/apt/
Author: ekoneil
Date: Tue Apr 25 18:49:41 2006
New Revision: 397046
URL: http://svn.apache.org/viewcvs?rev=397046&view=rev
Log:
Move three more static methods off of ControlBean and ControlBeanContext onto a ControlUtils class. I'm not a huge fan of a proliferation of utility classes, but this reduces the surface area of the public API of CB and CBC classes and decouples them from an implementation class.
BB: self
Test: Controls pass
Added:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlUtils.java
Modified:
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/assembly/BaseAssemblyContext.java
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ClientInitializer.java
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/InterceptorUtils.java
beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/assembly/BaseAssemblyContext.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/assembly/BaseAssemblyContext.java?rev=397046&r1=397045&r2=397046&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/assembly/BaseAssemblyContext.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/assembly/BaseAssemblyContext.java Tue Apr 25 18:49:41 2006
@@ -17,19 +17,22 @@
*/
package org.apache.beehive.controls.runtime.assembly;
-import org.apache.beehive.controls.api.bean.ControlInterface;
-import org.apache.beehive.controls.api.assembly.ControlAssemblyContext;
-import org.apache.beehive.controls.api.assembly.ControlAssemblyException;
-import org.apache.beehive.controls.runtime.bean.ControlBeanContext;
-
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
-import java.util.*;
+import java.util.Map;
+import java.util.Set;
+import java.util.LinkedList;
+import java.util.Queue;
import com.sun.mirror.apt.Messager;
import com.sun.mirror.util.SourcePosition;
+import org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.assembly.ControlAssemblyContext;
+import org.apache.beehive.controls.api.assembly.ControlAssemblyException;
+import org.apache.beehive.controls.runtime.bean.ControlUtils;
+
/**
* Abstract ControlAssemblyContext implementation. Provides a basic implementation of most non-module-specific
* APIs, meant to be extended by module-specific types.
@@ -82,8 +85,7 @@
return _controlMostDerivedIntf;
}
- // TODO - if we want to override class annotations on instance
- // then here is where we will do it
+ // TODO - if we want to override class annotations on instance then here is where we will do it
public <T extends Annotation> T
getControlAnnotation(Class<T> annotationClass)
{
@@ -108,7 +110,7 @@
ControlInterface a = (ControlInterface)
ci.getAnnotation(ControlInterface.class);
- return ControlBeanContext.resolveDefaultBinding( a.defaultBinding(), ci.getName() );
+ return ControlUtils.resolveDefaultBinding( a.defaultBinding(), ci.getName() );
}
public File getSrcOutputDir()
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ClientInitializer.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ClientInitializer.java?rev=397046&r1=397045&r2=397046&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ClientInitializer.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ClientInitializer.java Tue Apr 25 18:49:41 2006
@@ -40,7 +40,7 @@
*/
protected static void enforceVersionRequired( ControlBean control, VersionRequired versionRequired )
{
- Class controlIntf = control.getMostDerivedInterface( control.getControlInterface() );
+ Class controlIntf = ControlUtils.getMostDerivedInterface( control.getControlInterface() );
Version versionPresent = (Version) controlIntf.getAnnotation( Version.class );
if ( versionPresent != null )
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=397046&r1=397045&r2=397046&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:49:41 2006
@@ -47,8 +47,6 @@
import org.apache.beehive.controls.api.bean.Threading;
import org.apache.beehive.controls.api.bean.ThreadingPolicy;
import org.apache.beehive.controls.api.bean.ControlImplementation;
-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;
@@ -279,7 +277,7 @@
if ( bp != null )
implBinding = bp.controlImplementation();
else
- implBinding = ControlBeanContext.getDefaultControlBinding(_controlIntf);
+ implBinding = ControlUtils.getDefaultControlBinding(_controlIntf);
try
{
@@ -838,29 +836,12 @@
* Computes the most derived ControlInterface for the specified ControlExtension.
* @param controlIntf
* @return the most derived ControlInterface
+ * @deprecated Use {@link ControlUtils#getMostDerivedInterface(Class)} instead. This method will
+ * be removed in the next release.
*/
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;
+ return ControlUtils.getMostDerivedInterface(controlIntf);
}
/**
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=397046&r1=397045&r2=397046&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:49:41 2006
@@ -17,10 +17,6 @@
*/
package org.apache.beehive.controls.runtime.bean;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.beancontext.BeanContext;
@@ -28,17 +24,20 @@
import java.beans.beancontext.BeanContextServiceProvider;
import java.beans.beancontext.BeanContextServices;
import java.beans.beancontext.BeanContextServicesSupport;
-import java.util.Iterator;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.TooManyListenersException;
-import java.util.Vector;
import java.util.HashSet;
-import java.util.Set;
+import java.util.Iterator;
import java.util.Map;
-import java.util.Collections;
+import java.util.Set;
+import java.util.TooManyListenersException;
+import java.util.Vector;
import org.apache.beehive.controls.api.ControlException;
-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.BeanPropertyMap;
@@ -387,41 +386,6 @@
}
}
- /**
- * Returns the default binding based entirely upon annotations or naming conventions.
- */
- public static String getDefaultControlBinding(Class controlIntf)
- {
- controlIntf = ControlBean.getMostDerivedInterface(controlIntf);
-
- ControlInterface intfAnnot =
- (ControlInterface)controlIntf.getAnnotation(ControlInterface.class);
- String implBinding = intfAnnot.defaultBinding();
- implBinding = resolveDefaultBinding( implBinding, controlIntf.getName() );
-
- return implBinding;
- }
-
- /**
- * Implements the default control implementation binding algorithm ( <InterfaceName> + "Impl" ). See
- * documentation for the org.apache.beehive.controls.api.bean.ControlInterface annotation.
- *
- * @param implBinding the value of the defaultBinding attribute returned from a ControlInterface annotation
- * @param controlClass the actual name of the interface decorated by the ControlInterface annotation
- * @return the resolved defaultBinding value
- */
- public static String resolveDefaultBinding( String implBinding, String controlClass )
- {
- int intfIndex = implBinding.indexOf(ControlInterface.INTERFACE_NAME);
- if (intfIndex >= 0)
- {
- implBinding = implBinding.substring(0,intfIndex) + controlClass +
- implBinding.substring(intfIndex +
- ControlInterface.INTERFACE_NAME.length());
- }
- return implBinding;
- }
-
//
// ControlBeanContext.getControlInterface
//
@@ -788,6 +752,33 @@
*/
public static String[] prioritizeInterceptors( String [] interceptors ) {
return InterceptorUtils.prioritizeInterceptors(interceptors);
+ }
+
+ /**
+ * Returns the default binding based entirely upon annotations or naming conventions.
+ * @param controlIntf the control interface class
+ * @return the class name of the default control implementation binding
+ * @deprecated Use {@link ControlUtils#getDefaultControlBinding(Class)} insated. This method will be
+ * removed in the next point release.
+ */
+ public static String getDefaultControlBinding(Class controlIntf)
+ {
+ return ControlUtils.getDefaultControlBinding(controlIntf);
+ }
+
+ /**
+ * Implements the default control implementation binding algorithm ( <InterfaceName> + "Impl" ). See
+ * documentation for the org.apache.beehive.controls.api.bean.ControlInterface annotation.
+ *
+ * @param implBinding the value of the defaultBinding attribute returned from a ControlInterface annotation
+ * @param controlClass the actual name of the interface decorated by the ControlInterface annotation
+ * @return the resolved defaultBinding value
+ * @deprecated Use {@link ControlUtils#resolveDefaultBinding(String, String)} insated. This method
+ * will be removed in the next point release.
+ */
+ public static String resolveDefaultBinding( String implBinding, String controlClass )
+ {
+ return ControlUtils.resolveDefaultBinding(implBinding, controlClass);
}
/**
Added: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlUtils.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlUtils.java?rev=397046&view=auto
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlUtils.java (added)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/ControlUtils.java Tue Apr 25 18:49:41 2006
@@ -0,0 +1,96 @@
+/*
+ * 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 org.apache.beehive.controls.api.bean.ControlInterface;
+import org.apache.beehive.controls.api.bean.ControlExtension;
+import org.apache.beehive.controls.api.ControlException;
+
+/**
+ * Utilities used by the Controls runtime.
+ */
+public final class ControlUtils {
+
+ private ControlUtils() {}
+
+ /**
+ * Implements the default control implementation binding algorithm ( <InterfaceName> + "Impl" ). See
+ * documentation for the org.apache.beehive.controls.api.bean.ControlInterface annotation.
+ *
+ * @param implBinding the value of the defaultBinding attribute returned from a ControlInterface annotation
+ * @param controlClass the actual name of the interface decorated by the ControlInterface annotation
+ * @return the resolved defaultBinding value
+ */
+ public static String resolveDefaultBinding( String implBinding, String controlClass )
+ {
+ int intfIndex = implBinding.indexOf(ControlInterface.INTERFACE_NAME);
+ if (intfIndex >= 0)
+ {
+ implBinding = implBinding.substring(0,intfIndex) + controlClass +
+ implBinding.substring(intfIndex +
+ ControlInterface.INTERFACE_NAME.length());
+ }
+ return implBinding;
+ }
+
+ /**
+ * Returns the default binding based entirely upon annotations or naming conventions.
+ * @param controlIntf the control interface class
+ * @return the class name of the default control implementation binding
+ */
+ static String getDefaultControlBinding(Class controlIntf)
+ {
+ controlIntf = getMostDerivedInterface(controlIntf);
+
+ ControlInterface intfAnnot =
+ (ControlInterface)controlIntf.getAnnotation(ControlInterface.class);
+ String implBinding = intfAnnot.defaultBinding();
+ implBinding = resolveDefaultBinding( implBinding, controlIntf.getName() );
+
+ return implBinding;
+ }
+
+ /**
+ * Computes the most derived ControlInterface for the specified ControlExtension.
+ * @param controlIntf
+ * @return the most derived ControlInterface
+ */
+ 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;
+ }
+}
Modified: 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=397046&r1=397045&r2=397046&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/bean/InterceptorUtils.java Tue Apr 25 18:49:41 2006
@@ -30,6 +30,8 @@
*/
public final class InterceptorUtils {
+ private 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
Modified: beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java?rev=397046&r1=397045&r2=397046&view=diff
==============================================================================
--- beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java (original)
+++ beehive/trunk/controls/src/runtime/org/apache/beehive/controls/runtime/generator/apt/ControlClientAnnotationProcessor.java Tue Apr 25 18:49:41 2006
@@ -43,7 +43,7 @@
import com.sun.mirror.type.InterfaceType;
import com.sun.mirror.type.DeclaredType;
-import org.apache.beehive.controls.runtime.bean.ControlBeanContext;
+import org.apache.beehive.controls.runtime.bean.ControlUtils;
import org.apache.beehive.controls.runtime.generator.CodeGenerationException;
import org.apache.beehive.controls.runtime.generator.AptAnnotationHelper;
import org.apache.beehive.controls.runtime.generator.AptControlClient;
@@ -242,7 +242,7 @@
ControlInterface annot = controlIntf.getAnnotation(ControlInterface.class);
String defBinding = annot.defaultBinding();
- defBinding = ControlBeanContext.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );
+ defBinding = ControlUtils.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );
mf.addControlType( controlIntfOrExt.getQualifiedName(), defBinding );
}