[jboss-cvs] microkernel/src/main/org/jboss/kernel/plugins/dependency ...
Adrian Brock
adrian.brock at jboss.com
Tue Jul 11 08:08:43 EDT 2006
User: adrian
Date: 06/07/11 08:08:43
Modified: src/main/org/jboss/kernel/plugins/dependency
KernelControllerContextActions.java
Added: src/main/org/jboss/kernel/plugins/dependency
LifecycleAction.java InstallAction.java
StartStopLifecycleAction.java
DispatchJoinPoint.java ConfigureAction.java
CreateDestroyLifecycleAction.java
KernelControllerContextAction.java
InstantiateAction.java DescribeAction.java
Log:
Split up the actions into separate classes.
Revision Changes Path
1.28 +1 -739 microkernel/src/main/org/jboss/kernel/plugins/dependency/KernelControllerContextActions.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: KernelControllerContextActions.java
===================================================================
RCS file: /cvsroot/jboss/microkernel/src/main/org/jboss/kernel/plugins/dependency/KernelControllerContextActions.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- KernelControllerContextActions.java 23 Jun 2006 10:07:13 -0000 1.27
+++ KernelControllerContextActions.java 11 Jul 2006 12:08:43 -0000 1.28
@@ -21,44 +21,11 @@
*/
package org.jboss.kernel.plugins.dependency;
-import java.security.AccessControlContext;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
import java.util.Map;
-import java.util.Set;
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.InstallMetaData;
-import org.jboss.beans.metadata.spi.LifecycleMetaData;
-import org.jboss.beans.metadata.spi.ParameterMetaData;
-import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.dependency.plugins.AbstractControllerContextActions;
-import org.jboss.dependency.plugins.AbstractDependencyItem;
-import org.jboss.dependency.plugins.spi.action.ControllerContextAction;
-import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
-import org.jboss.dependency.spi.DependencyInfo;
-import org.jboss.joinpoint.spi.Joinpoint;
-import org.jboss.joinpoint.spi.JoinpointException;
-import org.jboss.joinpoint.spi.MethodJoinpoint;
-import org.jboss.joinpoint.spi.TargettedJoinpoint;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.plugins.config.Configurator;
-import org.jboss.kernel.spi.config.KernelConfigurator;
-import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
-import org.jboss.kernel.spi.registry.KernelRegistry;
-import org.jboss.logging.Logger;
-import org.jboss.repository.spi.KernelRepository;
-import org.jboss.repository.spi.MetaDataContext;
-import org.jboss.repository.spi.MetaDataContextFactory;
/**
* The KernelControllerActions.<p>
@@ -69,7 +36,7 @@
* Otherwise, we just use the caller's privileges.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.27 $
+ * @version $Revision: 1.28 $
*/
public class KernelControllerContextActions extends AbstractControllerContextActions
{
@@ -80,41 +47,6 @@
private static KernelControllerContextActions noInstantiate;
/**
- * Dispatch a joinpoint
- *
- * @param context the context
- * @param joinpoint the joinpoint
- * @return the result
- * @throws Throwable for any error
- */
- protected static Object dispatchJoinPoint(final KernelControllerContext context, final Joinpoint joinpoint) throws Throwable
- {
- AccessControlContext access = null;
- if (context instanceof AbstractKernelControllerContext)
- {
- AbstractKernelControllerContext theContext = (AbstractKernelControllerContext) context;
- access = theContext.getAccessControlContext();
- }
-
- if (access == null)
- {
- return joinpoint.dispatch();
- }
- else
- {
- DispatchJoinPoint action = new DispatchJoinPoint(joinpoint);
- try
- {
- return AccessController.doPrivileged(action, access);
- }
- catch (PrivilegedActionException e)
- {
- throw e.getCause();
- }
- }
- }
-
- /**
* Get the instance
*
* @return the actions
@@ -162,674 +94,4 @@
{
super(actions);
}
-
- /**
- * Abstract action
- */
- public static class KernelControllerContextAction implements ControllerContextAction
- {
- protected Logger log = Logger.getLogger(getClass());
-
- public void install(final ControllerContext context) throws Throwable
- {
- if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false)
- installAction((KernelControllerContext) context);
- else
- {
- PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
- {
- public Object run() throws Exception
- {
- try
- {
- installAction((KernelControllerContext) context);
- return null;
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw e;
- }
- catch (Error e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- throw new RuntimeException(t);
- }
- }
- };
- try
- {
- AccessController.doPrivileged(action);
- }
- catch (PrivilegedActionException e)
- {
- throw e.getCause();
- }
- }
- }
-
- public void uninstall(final ControllerContext context)
- {
- if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false)
- uninstallAction((KernelControllerContext) context);
- else
- {
- PrivilegedAction<Object> action = new PrivilegedAction<Object>()
- {
- public Object run()
- {
- uninstallAction((KernelControllerContext) context);
- return null;
- }
- };
- AccessController.doPrivileged(action);
- }
- }
-
- public void installAction(KernelControllerContext context) throws Throwable
- {
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- }
- }
-
- /**
- * The describe action
- */
- public static class DescribeAction extends KernelControllerContextAction
- {
- public void installAction(KernelControllerContext context) throws Throwable
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- BeanMetaData metaData = context.getBeanMetaData();
- if (metaData.getBean() != null)
- {
- BeanInfo info = configurator.getBeanInfo(metaData);
- context.setBeanInfo(info);
-
- info = addAnnotations(context, metaData, info);
-
- // add custom dependencies (e.g. AOP layer).
- DependencyInfo depends = context.getDependencyInfo();
- List dependencies = info.getDependencies();
- if (dependencies != null)
- {
- Iterator it = dependencies.iterator();
- while (it.hasNext())
- {
- AbstractDependencyItem dependency = new AbstractDependencyItem(metaData.getName(), it.next(), ControllerState.INSTANTIATED, ControllerState.INSTALLED);
- depends.addIDependOn(dependency);
- }
- }
- }
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- context.setMetaDataContext(null);
- context.setBeanInfo(null);
- }
-
- /**
- * Adds annotations to the bean. If annotations are added, returns the bean info for the instance
- * @return The class bean info if no annotations exist or the instance bean info if annotations exist
- */
- private BeanInfo addAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
- {
- MetaDataContext metaCtx = addClassAnnotations(context, beanMetaData, beanInfo);
- metaCtx = addPropertyAnnotations(metaCtx, context, beanMetaData, beanInfo);
- return context.getBeanInfo();
- }
-
- private MetaDataContext addClassAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
- {
- Set annotations = beanMetaData.getAnnotations();
-
- MetaDataContext metaCtx = null;
-
- if (annotations != null && annotations.size() > 0)
- {
- if (metaCtx == null)
- {
- metaCtx = getMetaDataContext(context);
- }
- if (metaCtx != null)
- {
- metaCtx.addAnnotations(annotations);
- }
- }
-
- return metaCtx;
- }
-
- private MetaDataContext addPropertyAnnotations(MetaDataContext metaCtx, KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
- {
- Set properties = beanMetaData.getProperties();
-
- if (properties != null && properties.size() > 0)
- {
- for (Iterator it = properties.iterator() ; it.hasNext() ; )
- {
- PropertyMetaData property = (PropertyMetaData)it.next();
- Set propertyAnnotations = property.getAnnotations();
- if (propertyAnnotations != null && propertyAnnotations.size() > 0)
- {
- if (metaCtx == null)
- {
- metaCtx = getMetaDataContext(context);
- }
- if (metaCtx != null)
- {
- //metaCtx.addPropertyAnnotations(property.getName(), propertyAnnotations);
- Set propertyInfos = beanInfo.getProperties();
- if (propertyInfos != null && propertyInfos.size() > 0)
- {
- metaCtx.addPropertyAnnotations(property.getName(), beanInfo.getProperties(), propertyAnnotations);
- }
- }
- }
- }
- }
-
- return metaCtx;
- }
-
- private MetaDataContext getMetaDataContext(KernelControllerContext context)
- {
- //TODO: Hardcoding this doesn't feel right...
- ControllerContext repCtx = context.getController().getContext("Repository", ControllerState.INSTALLED);
-
- if (repCtx == null)
- {
- log.warn("You have defined annotations for bean '" + context.getName() + "', but no KernelRepository has been installed under the name 'Repository'");
- return null;
- }
-
- KernelRepository repository = (KernelRepository)repCtx.getTarget();
- MetaDataContextFactory metaFactory = context.getBeanInfo().getMetaDataContextFactory();
- MetaDataContext metaCtx = metaFactory.getMetaDataContext(repository, context.getName());
-
- context.setMetaDataContext(metaCtx);
-
- return metaCtx;
- }
- }
-
- /**
- * The instantiate action
- */
- public static class InstantiateAction extends KernelControllerContextAction
- {
- public void installAction(KernelControllerContext context) throws Throwable
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- BeanMetaData metaData = context.getBeanMetaData();
- BeanInfo info = context.getBeanInfo();
- final Joinpoint joinPoint = configurator.getConstructorJoinPoint(info, metaData.getConstructor(), metaData);
-
- Object object = dispatchJoinPoint(context, joinPoint);
- context.setTarget(object);
-
- MetaDataContext metaCtx = context.getMetaDataContext();
- if (metaCtx != null)
- {
- metaCtx.setTarget(object);
- }
-
- try
- {
- if (object != null && context.getBeanInfo() == null)
- {
- info = configurator.getBeanInfo(object.getClass());
- context.setBeanInfo(info);
- }
-
- if (object != null && object instanceof KernelControllerContextAware)
- ((KernelControllerContextAware) object).setKernelControllerContext(context);
- }
- catch (Throwable t)
- {
- uninstall(context);
- throw t;
- }
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- try
- {
- Object object = context.getTarget();
- if (object != null && object instanceof KernelControllerContextAware)
- ((KernelControllerContextAware) object).unsetKernelControllerContext(context);
- }
- catch (Throwable ignored)
- {
- log.debug("Ignored error unsetting context ", ignored);
- }
- finally
- {
- context.setTarget(null);
- }
- }
- }
-
- /**
- * The configure action
- */
- public static class ConfigureAction extends KernelControllerContextAction
- {
- public void installAction(KernelControllerContext context) throws Throwable
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- Object object = context.getTarget();
- BeanInfo info = context.getBeanInfo();
- BeanMetaData metaData = context.getBeanMetaData();
- Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
- setAttributes(context, object, joinPoints, false);
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- Object object = context.getTarget();
- BeanInfo info = context.getBeanInfo();
- BeanMetaData metaData = context.getBeanMetaData();
- try
- {
- Set joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
- setAttributes(context, object, joinPoints, true);
- }
- catch (Throwable t)
- {
- log.warn("Error unconfiguring bean " + context, t);
- }
- }
-
- /**
- * Set the attributes
- *
- * @param context the context
- * @param target the target
- * @param joinPoints the attribute setter joinpoints
- * @param ignoreErrors whether to ignore errors
- * @throws Throwable for any unignored error
- */
- protected void setAttributes(KernelControllerContext context, Object target, Set joinPoints, boolean ignoreErrors) throws Throwable
- {
- if (joinPoints.isEmpty() == false)
- {
- boolean trace = log.isTraceEnabled();
-
- for (Iterator i = joinPoints.iterator(); i.hasNext();)
- {
- TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next();
- joinPoint.setTarget(target);
- try
- {
- dispatchJoinPoint(context, joinPoint);
- }
- catch (Throwable t)
- {
- if (ignoreErrors)
- {
- if (trace)
- log.trace("Ignored for " + joinPoint, t);
- }
- else
- {
- throw t;
- }
- }
- }
- }
- }
- }
-
- /**
- * A lifecycle action
- */
- public static abstract class LifecycleAction extends KernelControllerContextAction
- {
- /**
- * Create a new AbstractLifecycleAction.
- */
- public LifecycleAction()
- {
- }
-
- /**
- * Get the install method
- *
- * @param context the context
- * @return the method
- */
- public abstract String getInstallMethod(KernelControllerContext context);
-
- /**
- * Get the install parameters
- *
- * @param context the context
- * @return the parameters
- */
- public abstract List<ParameterMetaData> getInstallParameters(KernelControllerContext context);
-
- /**
- * Get the uninstall method
- *
- * @param context the context
- * @return the method
- */
- public abstract String getUninstallMethod(KernelControllerContext context);
-
- /**
- * Get the uninstall parameters
- *
- * @param context the context
- * @return the parameters
- */
- public abstract List<ParameterMetaData> getUninstallParameters(KernelControllerContext context);
-
- public void installAction(KernelControllerContext context) throws Throwable
- {
- boolean trace = log.isTraceEnabled();
-
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- Object target = context.getTarget();
- BeanInfo info = context.getBeanInfo();
- BeanMetaData metaData = context.getBeanMetaData();
- String method = getInstallMethod(context);
- List<ParameterMetaData> parameters = getInstallParameters(context);
- MethodJoinpoint joinpoint = null;
- try
- {
- ClassLoader cl = Configurator.getClassLoader(metaData);
- joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
- }
- catch (JoinpointException ignored)
- {
- if (trace)
- {
- if (parameters == null)
- log.trace("No " + method + " method for " + context);
- else
- log.trace("No " + method + parameters + " method for " + context);
- }
- return;
- }
- joinpoint.setTarget(target);
- dispatchJoinPoint(context, joinpoint);
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- boolean trace = log.isTraceEnabled();
-
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelConfigurator configurator = kernel.getConfigurator();
-
- Object target = context.getTarget();
- BeanInfo info = context.getBeanInfo();
- BeanMetaData metaData = context.getBeanMetaData();
- String method = getUninstallMethod(context);
- List<ParameterMetaData> parameters = getUninstallParameters(context);
- MethodJoinpoint joinpoint = null;
- try
- {
- ClassLoader cl = Configurator.getClassLoader(metaData);
- joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
- joinpoint.setTarget(target);
- dispatchJoinPoint(context, joinpoint);
- }
- catch (JoinpointException ignored)
- {
- if (trace)
- {
- if (parameters == null)
- log.trace("No " + method + " method for " + context);
- else
- log.trace("No " + method + parameters + " method for " + context);
- }
- return;
- }
- catch (Throwable throwable)
- {
- log.warn("Error during " + method, throwable);
- }
- }
- }
-
- /**
- * A CreateDestroyLifecycleAction.
- */
- public static class CreateDestroyLifecycleAction extends LifecycleAction
- {
- public String getInstallMethod(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getCreate();
- if (lifecycle != null)
- return lifecycle.getMethodName();
- return "create";
- }
-
- public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getCreate();
- if (lifecycle != null)
- return lifecycle.getParameters();
- return null;
- }
-
- public String getUninstallMethod(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getDestroy();
- if (lifecycle != null)
- return lifecycle.getMethodName();
- return "destroy";
- }
-
- public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getDestroy();
- if (lifecycle != null)
- return lifecycle.getParameters();
- return null;
- }
- }
-
- /**
- * A StartStopLifecycleAction.
- */
- public static class StartStopLifecycleAction extends LifecycleAction
- {
- public String getInstallMethod(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStart();
- if (lifecycle != null)
- return lifecycle.getMethodName();
- return "start";
- }
-
- public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStart();
- if (lifecycle != null)
- return lifecycle.getParameters();
- return null;
- }
-
- public String getUninstallMethod(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStop();
- if (lifecycle != null)
- return lifecycle.getMethodName();
- return "stop";
- }
-
- public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
- {
- BeanMetaData metaData = context.getBeanMetaData();
- LifecycleMetaData lifecycle = metaData.getStop();
- if (lifecycle != null)
- return lifecycle.getParameters();
- return null;
- }
- }
-
- /**
- * The install action
- */
- public static class InstallAction extends KernelControllerContextAction
- {
- public void installAction(KernelControllerContext context) throws Throwable
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelRegistry registry = kernel.getRegistry();
-
- BeanMetaData metaData = context.getBeanMetaData();
- Object name = metaData.getName();
- registry.registerEntry(name, context);
- controller.addSupplies(context);
-
- List installs = metaData.getInstalls();
- if (installs != null)
- {
- for (int i = 0; i < installs.size(); ++i)
- {
- InstallMetaData install = (InstallMetaData) installs.get(i);
- KernelControllerContext target = context;
- if (install.getBean() != null)
- target = (KernelControllerContext) controller.getContext(install.getBean(), install.getDependentState());
- dispatch(target, install.getMethodName(), install.getParameters());
- }
- }
- }
-
- public void uninstallAction(KernelControllerContext context)
- {
- KernelController controller = (KernelController) context.getController();
- Kernel kernel = controller.getKernel();
- KernelRegistry registry = kernel.getRegistry();
- BeanMetaData metaData = context.getBeanMetaData();
- Object name = metaData.getName();
-
- List uninstalls = metaData.getUninstalls();
- if (uninstalls != null)
- {
- for (int i = uninstalls.size()-1; i >= 0; --i)
- {
- InstallMetaData uninstall = (InstallMetaData) uninstalls.get(i);
- KernelControllerContext target = context;
- if (uninstall.getBean() != null)
- {
- target = (KernelControllerContext) controller.getContext(uninstall.getBean(), uninstall.getDependentState());
- if (target == null)
- {
- log.warn("Ignoring uninstall action on target in incorrect state " + uninstall.getBean());
- continue;
- }
- }
- try
- {
- dispatch(target, uninstall.getMethodName(), uninstall.getParameters());
- }
- catch (Throwable t)
- {
- log.warn("Ignoring uninstall action on target " + uninstall, t);
- continue;
- }
- }
- }
-
- try
- {
- controller.removeSupplies(context);
- registry.unregisterEntry(name);
- }
- catch (Throwable t)
- {
- log.warn("Ignoring unregistered entry at uninstall " + name);
- }
- }
-
- protected void dispatch(KernelControllerContext context, String method, List<ParameterMetaData> parameters) throws Throwable
- {
- KernelController controller = (KernelController) context.getController();
- KernelConfigurator configurator = controller.getKernel().getConfigurator();
- BeanInfo info = context.getBeanInfo();
- BeanMetaData metaData = context.getBeanMetaData();
- ClassLoader cl = Configurator.getClassLoader(metaData);
- MethodJoinpoint joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
- joinpoint.setTarget(context.getTarget());
- dispatchJoinPoint(context, joinpoint);
- }
- }
-
- /**
- * Dispatches a joinpoint as a privileged action
- */
- private static class DispatchJoinPoint implements PrivilegedExceptionAction<Object>
- {
- private Joinpoint joinpoint;
-
- public DispatchJoinPoint(Joinpoint joinpoint)
- {
- this.joinpoint = joinpoint;
- }
-
- public Object run() throws Exception
- {
- try
- {
- return joinpoint.dispatch();
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Exception e)
- {
- throw e;
- }
- catch (Error e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- throw new RuntimeException(t);
- }
- }
- }
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/LifecycleAction.java
Index: LifecycleAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.List;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
import org.jboss.joinpoint.spi.JoinpointException;
import org.jboss.joinpoint.spi.MethodJoinpoint;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.config.Configurator;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* LifecycleAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public abstract class LifecycleAction extends KernelControllerContextAction
{
/**
* Create a new AbstractLifecycleAction.
*/
public LifecycleAction()
{
}
/**
* Get the install method
*
* @param context the context
* @return the method
*/
public abstract String getInstallMethod(KernelControllerContext context);
/**
* Get the install parameters
*
* @param context the context
* @return the parameters
*/
public abstract List<ParameterMetaData> getInstallParameters(KernelControllerContext context);
/**
* Get the uninstall method
*
* @param context the context
* @return the method
*/
public abstract String getUninstallMethod(KernelControllerContext context);
/**
* Get the uninstall parameters
*
* @param context the context
* @return the parameters
*/
public abstract List<ParameterMetaData> getUninstallParameters(KernelControllerContext context);
public void installAction(KernelControllerContext context) throws Throwable
{
boolean trace = log.isTraceEnabled();
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
Object target = context.getTarget();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
String method = getInstallMethod(context);
List<ParameterMetaData> parameters = getInstallParameters(context);
MethodJoinpoint joinpoint = null;
try
{
ClassLoader cl = Configurator.getClassLoader(metaData);
joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
}
catch (JoinpointException ignored)
{
if (trace)
{
if (parameters == null)
log.trace("No " + method + " method for " + context);
else
log.trace("No " + method + parameters + " method for " + context);
}
return;
}
joinpoint.setTarget(target);
dispatchJoinPoint(context, joinpoint);
}
public void uninstallAction(KernelControllerContext context)
{
boolean trace = log.isTraceEnabled();
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
Object target = context.getTarget();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
String method = getUninstallMethod(context);
List<ParameterMetaData> parameters = getUninstallParameters(context);
MethodJoinpoint joinpoint = null;
try
{
ClassLoader cl = Configurator.getClassLoader(metaData);
joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
joinpoint.setTarget(target);
dispatchJoinPoint(context, joinpoint);
}
catch (JoinpointException ignored)
{
if (trace)
{
if (parameters == null)
log.trace("No " + method + " method for " + context);
else
log.trace("No " + method + parameters + " method for " + context);
}
return;
}
catch (Throwable throwable)
{
log.warn("Error during " + method, throwable);
}
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/InstallAction.java
Index: InstallAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.List;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.InstallMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
import org.jboss.joinpoint.spi.MethodJoinpoint;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.config.Configurator;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.kernel.spi.registry.KernelRegistry;
/**
* InstallAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class InstallAction extends KernelControllerContextAction
{
public void installAction(KernelControllerContext context) throws Throwable
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelRegistry registry = kernel.getRegistry();
BeanMetaData metaData = context.getBeanMetaData();
Object name = metaData.getName();
registry.registerEntry(name, context);
controller.addSupplies(context);
List installs = metaData.getInstalls();
if (installs != null)
{
for (int i = 0; i < installs.size(); ++i)
{
InstallMetaData install = (InstallMetaData) installs.get(i);
KernelControllerContext target = context;
if (install.getBean() != null)
target = (KernelControllerContext) controller.getContext(install.getBean(), install.getDependentState());
dispatch(target, install.getMethodName(), install.getParameters());
}
}
}
public void uninstallAction(KernelControllerContext context)
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelRegistry registry = kernel.getRegistry();
BeanMetaData metaData = context.getBeanMetaData();
Object name = metaData.getName();
List uninstalls = metaData.getUninstalls();
if (uninstalls != null)
{
for (int i = uninstalls.size()-1; i >= 0; --i)
{
InstallMetaData uninstall = (InstallMetaData) uninstalls.get(i);
KernelControllerContext target = context;
if (uninstall.getBean() != null)
{
target = (KernelControllerContext) controller.getContext(uninstall.getBean(), uninstall.getDependentState());
if (target == null)
{
log.warn("Ignoring uninstall action on target in incorrect state " + uninstall.getBean());
continue;
}
}
try
{
dispatch(target, uninstall.getMethodName(), uninstall.getParameters());
}
catch (Throwable t)
{
log.warn("Ignoring uninstall action on target " + uninstall, t);
continue;
}
}
}
try
{
controller.removeSupplies(context);
registry.unregisterEntry(name);
}
catch (Throwable t)
{
log.warn("Ignoring unregistered entry at uninstall " + name);
}
}
protected void dispatch(KernelControllerContext context, String method, List<ParameterMetaData> parameters) throws Throwable
{
KernelController controller = (KernelController) context.getController();
KernelConfigurator configurator = controller.getKernel().getConfigurator();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
ClassLoader cl = Configurator.getClassLoader(metaData);
MethodJoinpoint joinpoint = configurator.getMethodJoinPoint(info, cl, method, parameters, false, true);
joinpoint.setTarget(context.getTarget());
dispatchJoinPoint(context, joinpoint);
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/StartStopLifecycleAction.java
Index: StartStopLifecycleAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.List;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.LifecycleMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* StartStopLifecycleAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class StartStopLifecycleAction extends LifecycleAction
{
public String getInstallMethod(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getStart();
if (lifecycle != null)
return lifecycle.getMethodName();
return "start";
}
public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getStart();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
public String getUninstallMethod(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getStop();
if (lifecycle != null)
return lifecycle.getMethodName();
return "stop";
}
public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getStop();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/DispatchJoinPoint.java
Index: DispatchJoinPoint.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.security.PrivilegedExceptionAction;
import org.jboss.joinpoint.spi.Joinpoint;
/**
* DispatchJoinPoint.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
class DispatchJoinPoint implements PrivilegedExceptionAction<Object>
{
private Joinpoint joinpoint;
public DispatchJoinPoint(Joinpoint joinpoint)
{
this.joinpoint = joinpoint;
}
public Object run() throws Exception
{
try
{
return joinpoint.dispatch();
}
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
throw e;
}
catch (Error e)
{
throw e;
}
catch (Throwable t)
{
throw new RuntimeException(t);
}
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/ConfigureAction.java
Index: ConfigureAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.Iterator;
import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.joinpoint.spi.TargettedJoinpoint;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* ConfigureAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class ConfigureAction extends KernelControllerContextAction
{
public void installAction(KernelControllerContext context) throws Throwable
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
Object object = context.getTarget();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
Set joinPoints = configurator.getPropertySetterJoinPoints(info, metaData);
setAttributes(context, object, joinPoints, false);
}
public void uninstallAction(KernelControllerContext context)
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
Object object = context.getTarget();
BeanInfo info = context.getBeanInfo();
BeanMetaData metaData = context.getBeanMetaData();
try
{
Set joinPoints = configurator.getPropertyNullerJoinPoints(info, metaData);
setAttributes(context, object, joinPoints, true);
}
catch (Throwable t)
{
log.warn("Error unconfiguring bean " + context, t);
}
}
/**
* Set the attributes
*
* @param context the context
* @param target the target
* @param joinPoints the attribute setter joinpoints
* @param ignoreErrors whether to ignore errors
* @throws Throwable for any unignored error
*/
protected void setAttributes(KernelControllerContext context, Object target, Set joinPoints, boolean ignoreErrors) throws Throwable
{
if (joinPoints.isEmpty() == false)
{
boolean trace = log.isTraceEnabled();
for (Iterator i = joinPoints.iterator(); i.hasNext();)
{
TargettedJoinpoint joinPoint = (TargettedJoinpoint) i.next();
joinPoint.setTarget(target);
try
{
dispatchJoinPoint(context, joinPoint);
}
catch (Throwable t)
{
if (ignoreErrors)
{
if (trace)
log.trace("Ignored for " + joinPoint, t);
}
else
{
throw t;
}
}
}
}
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/CreateDestroyLifecycleAction.java
Index: CreateDestroyLifecycleAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.List;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.LifecycleMetaData;
import org.jboss.beans.metadata.spi.ParameterMetaData;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
/**
* CreateDestroyLifecycleAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class CreateDestroyLifecycleAction extends LifecycleAction
{
public String getInstallMethod(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getCreate();
if (lifecycle != null)
return lifecycle.getMethodName();
return "create";
}
public List<ParameterMetaData> getInstallParameters(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getCreate();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
public String getUninstallMethod(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getDestroy();
if (lifecycle != null)
return lifecycle.getMethodName();
return "destroy";
}
public List<ParameterMetaData> getUninstallParameters(KernelControllerContext context)
{
BeanMetaData metaData = context.getBeanMetaData();
LifecycleMetaData lifecycle = metaData.getDestroy();
if (lifecycle != null)
return lifecycle.getParameters();
return null;
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/KernelControllerContextAction.java
Index: KernelControllerContextAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import org.jboss.dependency.plugins.spi.action.ControllerContextAction;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.joinpoint.spi.Joinpoint;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.logging.Logger;
/**
* KernelControllerContextAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class KernelControllerContextAction implements ControllerContextAction
{
protected Logger log = Logger.getLogger(getClass());
/**
* Dispatch a joinpoint
*
* @param context the context
* @param joinpoint the joinpoint
* @return the result
* @throws Throwable for any error
*/
protected static Object dispatchJoinPoint(final KernelControllerContext context, final Joinpoint joinpoint) throws Throwable
{
AccessControlContext access = null;
if (context instanceof AbstractKernelControllerContext)
{
AbstractKernelControllerContext theContext = (AbstractKernelControllerContext) context;
access = theContext.getAccessControlContext();
}
if (access == null)
{
return joinpoint.dispatch();
}
else
{
DispatchJoinPoint action = new DispatchJoinPoint(joinpoint);
try
{
return AccessController.doPrivileged(action, access);
}
catch (PrivilegedActionException e)
{
throw e.getCause();
}
}
}
public void install(final ControllerContext context) throws Throwable
{
if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false)
installAction((KernelControllerContext) context);
else
{
PrivilegedExceptionAction<Object> action = new PrivilegedExceptionAction<Object>()
{
public Object run() throws Exception
{
try
{
installAction((KernelControllerContext) context);
return null;
}
catch (RuntimeException e)
{
throw e;
}
catch (Exception e)
{
throw e;
}
catch (Error e)
{
throw e;
}
catch (Throwable t)
{
throw new RuntimeException(t);
}
}
};
try
{
AccessController.doPrivileged(action);
}
catch (PrivilegedActionException e)
{
throw e.getCause();
}
}
}
public void uninstall(final ControllerContext context)
{
if (System.getSecurityManager() == null || context instanceof AbstractKernelControllerContext == false)
uninstallAction((KernelControllerContext) context);
else
{
PrivilegedAction<Object> action = new PrivilegedAction<Object>()
{
public Object run()
{
uninstallAction((KernelControllerContext) context);
return null;
}
};
AccessController.doPrivileged(action);
}
}
public void installAction(KernelControllerContext context) throws Throwable
{
}
public void uninstallAction(KernelControllerContext context)
{
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/InstantiateAction.java
Index: InstantiateAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.joinpoint.spi.Joinpoint;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.kernel.spi.dependency.KernelControllerContextAware;
import org.jboss.repository.spi.MetaDataContext;
/**
* InstantiateAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class InstantiateAction extends KernelControllerContextAction
{
public void installAction(KernelControllerContext context) throws Throwable
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
BeanMetaData metaData = context.getBeanMetaData();
BeanInfo info = context.getBeanInfo();
final Joinpoint joinPoint = configurator.getConstructorJoinPoint(info, metaData.getConstructor(), metaData);
Object object = dispatchJoinPoint(context, joinPoint);
context.setTarget(object);
MetaDataContext metaCtx = context.getMetaDataContext();
if (metaCtx != null)
{
metaCtx.setTarget(object);
}
try
{
if (object != null && context.getBeanInfo() == null)
{
info = configurator.getBeanInfo(object.getClass());
context.setBeanInfo(info);
}
if (object != null && object instanceof KernelControllerContextAware)
((KernelControllerContextAware) object).setKernelControllerContext(context);
}
catch (Throwable t)
{
uninstall(context);
throw t;
}
}
public void uninstallAction(KernelControllerContext context)
{
try
{
Object object = context.getTarget();
if (object != null && object instanceof KernelControllerContextAware)
((KernelControllerContextAware) object).unsetKernelControllerContext(context);
}
catch (Throwable ignored)
{
log.debug("Ignored error unsetting context ", ignored);
}
finally
{
context.setTarget(null);
}
}
}
1.1 date: 2006/07/11 12:08:43; author: adrian; state: Exp;microkernel/src/main/org/jboss/kernel/plugins/dependency/DescribeAction.java
Index: DescribeAction.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, 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.plugins.dependency;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.dependency.plugins.AbstractDependencyItem;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.repository.spi.KernelRepository;
import org.jboss.repository.spi.MetaDataContext;
import org.jboss.repository.spi.MetaDataContextFactory;
/**
* DescribeAction.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
public class DescribeAction extends KernelControllerContextAction
{
public void installAction(KernelControllerContext context) throws Throwable
{
KernelController controller = (KernelController) context.getController();
Kernel kernel = controller.getKernel();
KernelConfigurator configurator = kernel.getConfigurator();
BeanMetaData metaData = context.getBeanMetaData();
if (metaData.getBean() != null)
{
BeanInfo info = configurator.getBeanInfo(metaData);
context.setBeanInfo(info);
info = addAnnotations(context, metaData, info);
// add custom dependencies (e.g. AOP layer).
DependencyInfo depends = context.getDependencyInfo();
List dependencies = info.getDependencies();
if (dependencies != null)
{
Iterator it = dependencies.iterator();
while (it.hasNext())
{
AbstractDependencyItem dependency = new AbstractDependencyItem(metaData.getName(), it.next(), ControllerState.INSTANTIATED, ControllerState.INSTALLED);
depends.addIDependOn(dependency);
}
}
}
}
public void uninstallAction(KernelControllerContext context)
{
context.setMetaDataContext(null);
context.setBeanInfo(null);
}
/**
* Adds annotations to the bean. If annotations are added, returns the bean info for the instance
* @return The class bean info if no annotations exist or the instance bean info if annotations exist
*/
private BeanInfo addAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
MetaDataContext metaCtx = addClassAnnotations(context, beanMetaData, beanInfo);
metaCtx = addPropertyAnnotations(metaCtx, context, beanMetaData, beanInfo);
return context.getBeanInfo();
}
private MetaDataContext addClassAnnotations(KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
Set annotations = beanMetaData.getAnnotations();
MetaDataContext metaCtx = null;
if (annotations != null && annotations.size() > 0)
{
if (metaCtx == null)
{
metaCtx = getMetaDataContext(context);
}
if (metaCtx != null)
{
metaCtx.addAnnotations(annotations);
}
}
return metaCtx;
}
private MetaDataContext addPropertyAnnotations(MetaDataContext metaCtx, KernelControllerContext context, BeanMetaData beanMetaData, BeanInfo beanInfo)
{
Set properties = beanMetaData.getProperties();
if (properties != null && properties.size() > 0)
{
for (Iterator it = properties.iterator() ; it.hasNext() ; )
{
PropertyMetaData property = (PropertyMetaData)it.next();
Set propertyAnnotations = property.getAnnotations();
if (propertyAnnotations != null && propertyAnnotations.size() > 0)
{
if (metaCtx == null)
{
metaCtx = getMetaDataContext(context);
}
if (metaCtx != null)
{
//metaCtx.addPropertyAnnotations(property.getName(), propertyAnnotations);
Set propertyInfos = beanInfo.getProperties();
if (propertyInfos != null && propertyInfos.size() > 0)
{
metaCtx.addPropertyAnnotations(property.getName(), beanInfo.getProperties(), propertyAnnotations);
}
}
}
}
}
return metaCtx;
}
private MetaDataContext getMetaDataContext(KernelControllerContext context)
{
//TODO: Hardcoding this doesn't feel right...
ControllerContext repCtx = context.getController().getContext("Repository", ControllerState.INSTALLED);
if (repCtx == null)
{
log.warn("You have defined annotations for bean '" + context.getName() + "', but no KernelRepository has been installed under the name 'Repository'");
return null;
}
KernelRepository repository = (KernelRepository)repCtx.getTarget();
MetaDataContextFactory metaFactory = context.getBeanInfo().getMetaDataContextFactory();
MetaDataContext metaCtx = metaFactory.getMetaDataContext(repository, context.getName());
context.setMetaDataContext(metaCtx);
return metaCtx;
}
}
More information about the jboss-cvs-commits
mailing list