[jboss-cvs] JBossAS SVN: r59614 - in projects/microcontainer/trunk: kernel/src/main/org/jboss/kernel/plugins/dependency and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Jan 13 19:24:04 EST 2007
Author: alesj
Date: 2007-01-13 19:23:56 -0500 (Sat, 13 Jan 2007)
New Revision: 59614
Added:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DispatchContext.java
Removed:
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DispatchContext.java
Modified:
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelControllerContext.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstallAction.java
projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/KernelControllerContext.java
Log:
rewrite DispatchContext code (very similar to DynamicMBean)
Added: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DispatchContext.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DispatchContext.java 2007-01-13 18:32:55 UTC (rev 59613)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/spi/DispatchContext.java 2007-01-14 00:23:56 UTC (rev 59614)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.dependency.spi;
+
+/**
+ * The API similar to the DynamicMBean API
+ * where there are methods to get/set Properties/Attributes and invoke on
+ * methods/operations with each context knowing how to do this, e.g.
+ * KernelControllerContext -> Configurator
+ * ServiceControllerContext -> MBeanServer
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface DispatchContext
+{
+ /**
+ * Getter property / attribute
+ *
+ * @param name
+ * @return target's property / attribute instance
+ * @throws Throwable
+ */
+ Object get(String name) throws Throwable;
+
+ /**
+ * Setter property / attribute
+ *
+ * @param name
+ * @param value set target's property / attribute instance
+ * @throws Throwable
+ */
+ void set(String name, Object value) throws Throwable;
+
+ /**
+ * Invoke method / operation
+ *
+ * @param name
+ * @param parameters
+ * @param signature
+ * @return inovocation's return object
+ * @throws Throwable
+ */
+ Object invoke(String name, Object parameters[], String[] signature) throws Throwable;
+
+ /**
+ * Get context's classloader.
+ * Used when determining type info for parameter and
+ * getting the parameter actual value.
+ *
+ * @return context's classloader
+ * @throws Throwable
+ */
+ ClassLoader getClassLoader() throws Throwable;
+
+ /**
+ * Get context's target, if available.
+ * @return target
+ */
+ Object getTarget();
+
+}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelControllerContext.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelControllerContext.java 2007-01-13 18:32:55 UTC (rev 59613)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/AbstractKernelControllerContext.java 2007-01-14 00:23:56 UTC (rev 59614)
@@ -24,13 +24,12 @@
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Stack;
+import java.util.*;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.*;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractParameterMetaData;
import org.jboss.dependency.plugins.AbstractControllerContext;
import org.jboss.dependency.plugins.AbstractDependencyInfo;
import org.jboss.dependency.spi.*;
@@ -230,33 +229,50 @@
});
}
- public void set(final PropertyMetaData property) throws Throwable
+ public void set(final String name, final Object value) throws Throwable
{
execute(new JoinPointCreator()
{
public TargettedJoinpoint createJoinpoint(ClassLoader cl, KernelConfigurator configurator) throws Throwable
{
- return configurator.getPropertySetterJoinPoint(getBeanInfo(), cl, property);
+ return configurator.getPropertySetterJoinPoint(getBeanInfo(), name, cl, new AbstractValueMetaData(value));
}
});
}
- public Object invoke(final String name, final List<ParameterMetaData> parameters) throws Throwable
+ public Object invoke(final String name, final Object[] parameters, final String[] signature) throws Throwable
{
return execute(new JoinPointCreator()
{
public TargettedJoinpoint createJoinpoint(ClassLoader cl, KernelConfigurator configurator) throws Throwable
{
- return configurator.getMethodJoinPoint(getBeanInfo(), cl, name, parameters, false, true);
+ List<ParameterMetaData> params = new ArrayList<ParameterMetaData>();
+ if (parameters != null)
+ {
+ for(int i = 0; i < parameters.length; i++)
+ {
+ AbstractParameterMetaData pmd = new AbstractParameterMetaData(parameters[i]);
+ // setting it as it was; we don't want the actual value class
+ pmd.setType(signature[i] != null ? signature[i] : null);
+ pmd.setIndex(i);
+ params.add(pmd);
+ }
+ }
+ return configurator.getMethodJoinPoint(getBeanInfo(), cl, name, params, false, true);
}
});
}
+ public ClassLoader getClassLoader() throws Throwable
+ {
+ return Configurator.getClassLoader(getBeanMetaData());
+ }
+
protected Object execute(JoinPointCreator creator) throws Throwable
{
KernelController controller = (KernelController) getController();
final KernelConfigurator configurator = controller.getKernel().getConfigurator();
- final ClassLoader cl = Configurator.getClassLoader(getBeanMetaData());
+ final ClassLoader cl = getClassLoader();
TargettedJoinpoint joinpoint = creator.createJoinpoint(cl, configurator);
joinpoint.setTarget(getTarget());
return KernelControllerContextAction.dispatchJoinPoint(this, joinpoint);
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstallAction.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstallAction.java 2007-01-13 18:32:55 UTC (rev 59613)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/plugins/dependency/InstallAction.java 2007-01-14 00:23:56 UTC (rev 59614)
@@ -22,12 +22,20 @@
package org.jboss.kernel.plugins.dependency;
import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.InstallMetaData;
+import org.jboss.beans.metadata.spi.ParameterMetaData;
+import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.*;
import org.jboss.kernel.spi.registry.KernelRegistry;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.dependency.spi.DispatchContext;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.MethodInfo;
/**
* InstallAction.
@@ -42,6 +50,7 @@
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelRegistry registry = kernel.getRegistry();
+ KernelConfigurator configurator = kernel.getConfigurator();
BeanMetaData metaData = context.getBeanMetaData();
Object name = metaData.getName();
@@ -57,7 +66,7 @@
DispatchContext target = context;
if (install.getBean() != null)
target = (DispatchContext) controller.getContext(install.getBean(), install.getDependentState());
- target.invoke(install.getMethodName(), install.getParameters());
+ invoke(configurator, target, install.getMethodName(), install.getParameters());
}
}
}
@@ -72,6 +81,7 @@
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelRegistry registry = kernel.getRegistry();
+ KernelConfigurator configurator = kernel.getConfigurator();
BeanMetaData metaData = context.getBeanMetaData();
Object name = metaData.getName();
@@ -93,7 +103,7 @@
}
try
{
- target.invoke(uninstall.getMethodName(), uninstall.getParameters());
+ invoke(configurator, target, uninstall.getMethodName(), uninstall.getParameters());
}
catch (Throwable t)
{
@@ -113,4 +123,55 @@
}
}
+ protected Object invoke(KernelConfigurator configurator, DispatchContext context, String name, List<ParameterMetaData> params) throws Throwable
+ {
+ ClassLoader classLoader = context.getClassLoader();
+ int size = (params != null) ? params.size() : 0;
+ Object[] parameters = new Object[size];
+ String[] signature = new String[size];
+ for(int i = 0; i < size; i++)
+ {
+ ParameterMetaData pmd = params.get(i);
+ signature[i] = pmd.getType();
+ TypeInfo typeInfo;
+ if (signature[i] != null)
+ {
+ typeInfo = configurator.getClassInfo(signature[i], classLoader);
+ }
+ else
+ {
+ typeInfo = findTypeInfo(configurator, context.getTarget(), name, i);
+ }
+ parameters[i] = pmd.getValue().getValue(typeInfo, classLoader);
+ }
+ return context.invoke(name, parameters, signature);
+ }
+
+ private TypeInfo findTypeInfo(KernelConfigurator configurator, Object target, String name, int index) throws Throwable
+ {
+ if (target == null)
+ {
+ return null;
+ }
+ BeanInfo beanInfo = configurator.getBeanInfo(target.getClass());
+ Set<MethodInfo> methods = beanInfo.getMethods();
+ Set<MethodInfo> possibleMethods = new HashSet<MethodInfo>();
+ for(MethodInfo mi : methods)
+ {
+ if (name.equals(mi.getName()))
+ {
+ possibleMethods.add(mi);
+ }
+ }
+ if (possibleMethods.isEmpty() || possibleMethods.size() > 1)
+ {
+ log.warn("Unable to determine parameter TypeInfo, method name: " + name + ", index: " + index + ", target: " + target);
+ return null;
+ }
+ else
+ {
+ return possibleMethods.iterator().next().getParameterTypes()[index];
+ }
+ }
+
}
\ No newline at end of file
Deleted: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DispatchContext.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DispatchContext.java 2007-01-13 18:32:55 UTC (rev 59613)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/DispatchContext.java 2007-01-14 00:23:56 UTC (rev 59614)
@@ -1,66 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.kernel.spi.dependency;
-
-import java.util.List;
-
-import org.jboss.beans.metadata.spi.ParameterMetaData;
-import org.jboss.beans.metadata.spi.PropertyMetaData;
-
-/**
- * The API similar to the DynamicMBean API
- * where there are methods to get/set Properties/Attributes and invoke on
- * methods/operations with each context knowing how to do this, e.g.
- * KernelControllerContext -> Configurator
- * ServiceControllerContext -> MBeanServer
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public interface DispatchContext
-{
- /**
- * Getter property / attribute
- *
- * @param name
- * @return
- * @throws Throwable
- */
- Object get(String name) throws Throwable;
-
- /**
- * Setter property / attribute
- *
- * @param property
- * @throws Throwable
- */
- void set(PropertyMetaData property) throws Throwable;
-
- /**
- * Invoke method / opration
- *
- * @param name
- * @param parameters
- * @return
- * @throws Throwable
- */
- Object invoke(String name, List<ParameterMetaData> parameters) throws Throwable;
-}
Modified: projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/KernelControllerContext.java
===================================================================
--- projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/KernelControllerContext.java 2007-01-13 18:32:55 UTC (rev 59613)
+++ projects/microcontainer/trunk/kernel/src/main/org/jboss/kernel/spi/dependency/KernelControllerContext.java 2007-01-14 00:23:56 UTC (rev 59614)
@@ -27,6 +27,8 @@
import org.jboss.kernel.spi.registry.KernelRegistryEntry;
import org.jboss.metadata.spi.MetaData;
import org.jboss.metadata.spi.scope.ScopeKey;
+import org.jboss.dependency.spi.DispatchContext;
+
/**
* Information about dependencies and state.
*
@@ -41,49 +43,49 @@
* @return the kernel
*/
Kernel getKernel();
-
+
/**
* Get the BeanInfo
*
* @return the bean info
*/
BeanInfo getBeanInfo();
-
+
/**
* Set the bean info
*
* @param info the bean info
*/
void setBeanInfo(BeanInfo info);
-
+
/**
* Get the metadata
*
* @return the bean metadata
*/
BeanMetaData getBeanMetaData();
-
+
/**
* Set the target
*
* @param target the target
*/
void setTarget(Object target);
-
+
/**
* Get the metadata
*
* @return the metadata
*/
MetaData getMetaData();
-
+
/**
* Get the scope
*
* @return the scope
*/
ScopeKey getScope();
-
+
/**
* Set the scope
*
More information about the jboss-cvs-commits
mailing list