From: <aft...@us...> - 2007-06-29 13:53:34
|
Revision: 4499 http://svn.sourceforge.net/smartfrog/?rev=4499&view=rev Author: aftereight Date: 2007-06-29 06:53:31 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Refactoring deployers again Modified Paths: -------------- branches/core-branch-osgi/components/anubisdeployer/src/org/smartfrog/services/anubisdeployer/ClusterDeployerImpl.java branches/core-branch-osgi/components/arithmetic-testharness/src/org/smartfrog/services/slp/PrimSLPDeployerImpl.java branches/core-branch-osgi/components/asyndeployer/src/org/smartfrog/services/asyndeployer/AsynPrimDeployerImpl.java branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSComponentDeployerImpl.java branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSDeployerImpl.java branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageOrDescriptionDeployerImpl.java branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageRecoveryDeployerImpl.java branches/core-branch-osgi/components/slp/src/org/smartfrog/services/comm/slp/SFSlpDeployerImpl.java branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironmentImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/ComponentDeployer.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/DefaultClassLoadingEnvironmentImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimHostDeployerImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimProcessDeployerImpl.java Added Paths: ----------- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/logging/ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/logging/LogToOSGiLogServiceImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractComponentFactory.java Removed Paths: ------------- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/LogToOSGiLogServiceImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java Modified: branches/core-branch-osgi/components/anubisdeployer/src/org/smartfrog/services/anubisdeployer/ClusterDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/anubisdeployer/src/org/smartfrog/services/anubisdeployer/ClusterDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/anubisdeployer/src/org/smartfrog/services/anubisdeployer/ClusterDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -65,7 +65,7 @@ * @param descr target to operate on */ public ClusterDeployerImpl(ComponentDescription descr, ComponentFactory factory) { - super(descr, factory); + super(descr); } public Prim deploy(Reference name, Prim parent, Context params) Modified: branches/core-branch-osgi/components/arithmetic-testharness/src/org/smartfrog/services/slp/PrimSLPDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/arithmetic-testharness/src/org/smartfrog/services/slp/PrimSLPDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/arithmetic-testharness/src/org/smartfrog/services/slp/PrimSLPDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -1,18 +1,20 @@ package org.smartfrog.services.slp; -import org.smartfrog.sfcore.prim.*; -import org.smartfrog.sfcore.parser.*; -import org.smartfrog.sfcore.reference.*; +import org.smartfrog.sfcore.common.Context; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.processcompound.PrimHostDeployerImpl; import org.smartfrog.sfcore.processcompound.ProcessCompound; -import org.smartfrog.sfcore.common.*; import org.smartfrog.sfcore.processcompound.SFProcess; -import org.smartfrog.sfcore.componentdescription.*; -import org.smartfrog.sfcore.deployer.ComponentFactory; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.reference.ReferencePart; -import java.util.*; -import java.net.*; +import java.net.InetAddress; +import java.util.Enumeration; +import java.util.Locale; +import java.util.StringTokenizer; +import java.util.Vector; /** Implements a specialized description deployer. This deployer uses * a service description in the target component to find through SLP @@ -39,9 +41,10 @@ /** Constructor * * @param descr target to operate on */ - public PrimSLPDeployerImpl(ComponentDescription descr, ComponentFactory factory) { - super(descr, factory); + public PrimSLPDeployerImpl(ComponentDescription descr) { + super(descr); } + public String buildServiceQuery(ComponentDescription attributesRequirements){ String result = ""; if (attributesRequirements != null) { Modified: branches/core-branch-osgi/components/asyndeployer/src/org/smartfrog/services/asyndeployer/AsynPrimDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/asyndeployer/src/org/smartfrog/services/asyndeployer/AsynPrimDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/asyndeployer/src/org/smartfrog/services/asyndeployer/AsynPrimDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -23,16 +23,15 @@ import java.io.IOException; import org.smartfrog.sfcore.common.MessageKeys; +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.SmartFrogCoreKeys; import org.smartfrog.sfcore.deployer.ComponentDeployer; import org.smartfrog.sfcore.deployer.ComponentFactory; import org.smartfrog.sfcore.componentdescription.ComponentDescription; - -import org.smartfrog.sfcore.logging.LogFactory; -import org.smartfrog.sfcore.logging.LogSF; import org.smartfrog.sfcore.prim.PrimDeployerImpl; import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.processcompound.ProcessCompound; import org.smartfrog.sfcore.processcompound.ProcessCompoundImpl; + import org.objectweb.proactive.core.descriptor.data.ProActiveDescriptor; import org.objectweb.proactive.core.descriptor.data.VirtualNode; import org.objectweb.proactive.core.node.Node; @@ -54,31 +53,41 @@ * * @param descr target description */ - public AsynPrimDeployerImpl (ComponentDescription descr, ComponentFactory factory) { - super (descr, factory); + public AsynPrimDeployerImpl (ComponentDescription descr) { + super(descr); } - /** - * - * @param primClass - * @return a new instance - * @throws ProActiveException - * @throws IOException - */ - protected Prim createPrimInstance(Class primClass) throws Exception { - Prim dComponent = null; - ProActiveDescriptor descriptorPad = ProActive.getProactiveDescriptor("RootNode.xml"); + private class ProActiveComponentFactory implements ComponentFactory { - descriptorPad.activateMappings(); + /** + * + * @param primClass + * @return a new instance + * @throws ProActiveException + * @throws IOException + */ + public Prim getComponent(ComponentDescription askedFor) throws SmartFrogDeploymentException { + try { + String primClassName = (String) askedFor.sfResolveHere(SmartFrogCoreKeys.SF_CLASS); - VirtualNode vnode = descriptorPad.getVirtualNode("RootNode"); - Node[] nodes = vnode.getNodes(); + Prim dComponent; + ProActiveDescriptor descriptorPad = ProActive.getProactiveDescriptor("RootNode.xml"); - dComponent = (Prim) ProActive.newActive(primClass.getName(), null, nodes[0]); - ProActive.register(dComponent, "RootProcessCompound"); - dComponent = (ProcessCompound) ProActive.lookupActive(ProcessCompoundImpl.class.getName(), "RootProcessCompound"); - // - return dComponent; - } + descriptorPad.activateMappings(); + VirtualNode vnode = descriptorPad.getVirtualNode("RootNode"); + Node[] nodes = vnode.getNodes(); + + dComponent = (Prim) ProActive.newActive(primClassName, null, nodes[0]); + ProActive.register(dComponent, "RootProcessCompound"); + // Huh. Is this really meant to return a ProcessCompound instead of the component instance ? + dComponent = (Prim) ProActive.lookupActive(ProcessCompoundImpl.class.getName(), "RootProcessCompound"); + + return dComponent; + + } catch (Exception e) { + throw new SmartFrogDeploymentException(e); + } + } + } } Modified: branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSComponentDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSComponentDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSComponentDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -26,7 +26,6 @@ import org.smartfrog.sfcore.common.MessageUtil; import org.smartfrog.sfcore.common.Context; import org.smartfrog.sfcore.common.SmartFrogException; -import org.smartfrog.sfcore.deployer.ComponentFactory; /** @@ -43,8 +42,8 @@ * * @param target a <code>ComponentDescription</code> value */ - public DNSComponentDeployerImpl(ComponentDescription target, ComponentFactory factory) { - super(target, factory); + public DNSComponentDeployerImpl(ComponentDescription target) { + super(target); } Modified: branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/dns/src/org/smartfrog/services/dns/DNSDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -34,7 +34,6 @@ import org.smartfrog.sfcore.processcompound.SFProcess; import org.smartfrog.sfcore.common.SmartFrogResolutionException; import org.smartfrog.sfcore.processcompound.ProcessCompound; -import org.smartfrog.sfcore.deployer.ComponentFactory; /** @@ -115,8 +114,8 @@ * * @param descr a <code>ComponentDescription</code> value */ - public DNSDeployerImpl(ComponentDescription descr, ComponentFactory factory) { - super(descr, factory); + public DNSDeployerImpl(ComponentDescription descr) { + super(descr); } Modified: branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageOrDescriptionDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageOrDescriptionDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageOrDescriptionDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -28,12 +28,11 @@ import org.smartfrog.sfcore.processcompound.PrimProcessDeployerImpl; import org.smartfrog.sfcore.processcompound.SFProcess; import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.deployer.ComponentFactory; public class StorageOrDescriptionDeployerImpl extends PrimProcessDeployerImpl { - public StorageOrDescriptionDeployerImpl(ComponentDescription descr, ComponentFactory factory) { - super(descr, factory); + public StorageOrDescriptionDeployerImpl(ComponentDescription descr) { + super(descr); } public Prim deploy(Reference name, Prim parent, Context params) Modified: branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageRecoveryDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageRecoveryDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/persistence/src/org/smartfrog/services/persistence/deployer/StorageRecoveryDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -32,12 +32,11 @@ import org.smartfrog.sfcore.prim.Prim; import org.smartfrog.sfcore.processcompound.PrimProcessDeployerImpl; import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.deployer.ComponentFactory; public class StorageRecoveryDeployerImpl extends PrimProcessDeployerImpl { - public StorageRecoveryDeployerImpl( ComponentDescription descr, ComponentFactory factory ) { - super( descr, factory ); + public StorageRecoveryDeployerImpl( ComponentDescription descr ) { + super( descr ); } public Prim deploy( Reference name, Prim parent, Context params ) throws Modified: branches/core-branch-osgi/components/slp/src/org/smartfrog/services/comm/slp/SFSlpDeployerImpl.java =================================================================== --- branches/core-branch-osgi/components/slp/src/org/smartfrog/services/comm/slp/SFSlpDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/components/slp/src/org/smartfrog/services/comm/slp/SFSlpDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -32,7 +32,6 @@ import org.smartfrog.sfcore.processcompound.PrimProcessDeployerImpl; import org.smartfrog.sfcore.processcompound.ProcessCompound; import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.deployer.ComponentFactory; import java.util.Locale; import java.util.Properties; @@ -53,8 +52,8 @@ protected String searchFilter = null; protected Vector scopes = null; - public SFSlpDeployerImpl(ComponentDescription descr, ComponentFactory factory) { - super(descr, factory); + public SFSlpDeployerImpl(ComponentDescription descr) { + super(descr); } /** Does a search for a ProcessCompound using SLP. */ Modified: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironmentImpl.java =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironmentImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironmentImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -7,7 +7,7 @@ import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; import org.smartfrog.sfcore.componentdescription.ComponentDescription; -import org.smartfrog.sfcore.deployer.AbstractClassLoadingEnvironment; +import org.smartfrog.sfcore.deployer.AbstractComponentFactory; import org.smartfrog.sfcore.prim.Prim; import org.smartfrog.sfcore.prim.TerminationRecord; @@ -17,7 +17,7 @@ import java.util.Enumeration; -public class BundleClassLoadingEnvironmentImpl extends AbstractClassLoadingEnvironment { +public class BundleClassLoadingEnvironmentImpl extends AbstractComponentFactory { public static final String LOCATION_ATTRIBUTE = "location"; private Bundle hostBundle = null; Deleted: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/LogToOSGiLogServiceImpl.java =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/LogToOSGiLogServiceImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/LogToOSGiLogServiceImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -1,4 +0,0 @@ -package org.smartfrog.osgi; - -public class LogToOSGiLogServiceImpl { -} Copied: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/logging/LogToOSGiLogServiceImpl.java (from rev 4497, branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/LogToOSGiLogServiceImpl.java) =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/logging/LogToOSGiLogServiceImpl.java (rev 0) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/logging/LogToOSGiLogServiceImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -0,0 +1,4 @@ +package org.smartfrog.osgi.logging; + +public class LogToOSGiLogServiceImpl { +} Deleted: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -1,62 +0,0 @@ -package org.smartfrog.sfcore.deployer; - -import org.smartfrog.sfcore.prim.PrimImpl; -import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.deployer.ClassLoadingEnvironment; -import org.smartfrog.sfcore.componentdescription.ComponentDescription; -import org.smartfrog.sfcore.common.SmartFrogResolutionException; -import org.smartfrog.sfcore.common.SmartFrogDeploymentException; -import org.smartfrog.sfcore.common.MessageUtil; -import org.smartfrog.sfcore.common.SmartFrogCoreKeys; - -import java.rmi.RemoteException; -import java.io.InputStream; -import java.io.IOException; - -public abstract class AbstractClassLoadingEnvironment extends PrimImpl implements ClassLoadingEnvironment { - - protected AbstractClassLoadingEnvironment() {} - - - public Prim getComponent(ComponentDescription askedFor) throws SmartFrogDeploymentException { - String className = null; - try { - // Not pretty - but needed to have a proper error message, and pass tests. - className = (String) askedFor.sfResolveHere(SmartFrogCoreKeys.SF_CLASS); - - return getComponentImpl(askedFor); - } catch (ClassNotFoundException e) { - throw deploymentException(MessageUtil.formatMessage( - MSG_CLASS_NOT_FOUND, className), e, askedFor); - } catch (InstantiationException instexcp) { - throw deploymentException(MessageUtil.formatMessage( - MSG_INSTANTIATION_ERROR, "Prim"), instexcp, askedFor); - } catch (IllegalAccessException illaexcp) { - throw deploymentException(MessageUtil.formatMessage( - MSG_ILLEGAL_ACCESS, "Prim", "newInstance()"), illaexcp, - askedFor); - } catch (SmartFrogResolutionException e) { - throw deploymentException(MessageUtil.formatMessage( - MSG_UNRESOLVED_REFERENCE, SmartFrogCoreKeys.SF_CLASS), e, - askedFor); - } - } - - private SmartFrogDeploymentException deploymentException(String message, Exception e, ComponentDescription askedFor) { - return new SmartFrogDeploymentException(message, e, this, askedFor.sfContext()); - } - - protected abstract Prim getComponentImpl(ComponentDescription askedFor) - throws ClassNotFoundException, InstantiationException, - IllegalAccessException, SmartFrogResolutionException, SmartFrogDeploymentException; - - public InputStream getResourceAsStream(String location) - throws RemoteException - { - try { - return getResource(location).openStream(); - } catch (IOException e) { - return null; // Same as in java.lang.ClassLoader to be consistent - } - } -} Copied: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractComponentFactory.java (from rev 4498, branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java) =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractComponentFactory.java (rev 0) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractComponentFactory.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -0,0 +1,62 @@ +package org.smartfrog.sfcore.deployer; + +import org.smartfrog.sfcore.prim.PrimImpl; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.deployer.ClassLoadingEnvironment; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.common.SmartFrogResolutionException; +import org.smartfrog.sfcore.common.SmartFrogDeploymentException; +import org.smartfrog.sfcore.common.MessageUtil; +import org.smartfrog.sfcore.common.SmartFrogCoreKeys; + +import java.rmi.RemoteException; +import java.io.InputStream; +import java.io.IOException; + +public abstract class AbstractComponentFactory extends PrimImpl implements ClassLoadingEnvironment { + + protected AbstractComponentFactory() {} + + + public Prim getComponent(ComponentDescription askedFor) throws SmartFrogDeploymentException { + String className = null; + try { + // Not pretty - but needed to have a proper error message, and pass tests. + className = (String) askedFor.sfResolveHere(SmartFrogCoreKeys.SF_CLASS); + + return getComponentImpl(askedFor); + } catch (ClassNotFoundException e) { + throw deploymentException(MessageUtil.formatMessage( + MSG_CLASS_NOT_FOUND, className), e, askedFor); + } catch (InstantiationException instexcp) { + throw deploymentException(MessageUtil.formatMessage( + MSG_INSTANTIATION_ERROR, "Prim"), instexcp, askedFor); + } catch (IllegalAccessException illaexcp) { + throw deploymentException(MessageUtil.formatMessage( + MSG_ILLEGAL_ACCESS, "Prim", "newInstance()"), illaexcp, + askedFor); + } catch (SmartFrogResolutionException e) { + throw deploymentException(MessageUtil.formatMessage( + MSG_UNRESOLVED_REFERENCE, SmartFrogCoreKeys.SF_CLASS), e, + askedFor); + } + } + + private SmartFrogDeploymentException deploymentException(String message, Exception e, ComponentDescription askedFor) { + return new SmartFrogDeploymentException(message, e, this, askedFor.sfContext()); + } + + protected abstract Prim getComponentImpl(ComponentDescription askedFor) + throws ClassNotFoundException, InstantiationException, + IllegalAccessException, SmartFrogResolutionException, SmartFrogDeploymentException; + + public InputStream getResourceAsStream(String location) + throws RemoteException + { + try { + return getResource(location).openStream(); + } catch (IOException e) { + return null; // Same as in java.lang.ClassLoader to be consistent + } + } +} Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/ComponentDeployer.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/ComponentDeployer.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/ComponentDeployer.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -26,10 +26,11 @@ import org.smartfrog.sfcore.reference.Reference; /** - * Defines the access point to deploy a component description. The class - * implementing this interface should have been parametrized with the - * description it is to work on + * Deploys a new {@link Prim} in the component hierarchy, delegating object creation to a {@link ComponentFactory}. + * Implementations are used to deploy a single Prim, and are discarded afterwards. + * Thus they must have a public, one-argument constructor that takes the Prim's {@link org.smartfrog.sfcore.componentdescription.ComponentDescription}. */ +// TODO: Look into reusing instances - it must be pretty bad to create loads of these during deployment ! public interface ComponentDeployer { /** * Deploys description for which this deployer was created. @@ -42,6 +43,12 @@ * * @exception SmartFrogDeploymentException failed to deploy */ - public Prim deploy(Reference name, Prim parent, Context params) + Prim deploy(Reference name, Prim parent, Context params) throws SmartFrogDeploymentException; + + /** + * Sets the factory to be used. Always called before {@link this.deploy()}. + * @param componentFactory The factory to be used to create component instances. + */ + void setComponentFactory(ComponentFactory componentFactory); } Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/DefaultClassLoadingEnvironmentImpl.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/DefaultClassLoadingEnvironmentImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/DefaultClassLoadingEnvironmentImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -4,15 +4,13 @@ import org.smartfrog.sfcore.common.SmartFrogResolutionException; import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.deployer.AbstractClassLoadingEnvironment; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.rmi.RemoteException; import java.util.Enumeration; -public class DefaultClassLoadingEnvironmentImpl extends AbstractClassLoadingEnvironment { +public class DefaultClassLoadingEnvironmentImpl extends AbstractComponentFactory { public DefaultClassLoadingEnvironmentImpl() {} @@ -33,10 +31,6 @@ return getClass().getResource(location); } - public InputStream getResourceAsStream(String location) throws RemoteException { - return getClass().getResourceAsStream(location); - } - public Enumeration getResources(String location) throws IOException { return getClass().getClassLoader().getResources(location); } Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -22,7 +22,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.rmi.RemoteException; import org.smartfrog.sfcore.common.Context; import org.smartfrog.sfcore.common.SmartFrogCoreKeys; @@ -100,18 +99,20 @@ private static ComponentDeployer getDeployer(ComponentDescription component) throws SmartFrogException { String className = (String) component.sfResolveHere(SmartFrogCoreKeys.SF_DEPLOYER_CLASS,false); - if (className == null) { - className = DEFAULT_DEPLOYER; - } + if (className == null) className = DEFAULT_DEPLOYER; try { + Class deplClass = SFClassLoader.forName(className); - Class[] deplConstArgsTypes = {ComponentDescription.class, ComponentFactory.class}; - Constructor deplConst = deplClass. - getConstructor(deplConstArgsTypes); - Object[] deplConstArgs = { component, getComponentFactory(component) }; + Class[] deplConstArgsTypes = { ComponentDescription.class }; + Constructor deplConst = deplClass.getConstructor(deplConstArgsTypes); + Object[] deplConstArgs = { component }; - return (ComponentDeployer) deplConst.newInstance(deplConstArgs); + ComponentDeployer deployer = (ComponentDeployer) + deplConst.newInstance(deplConstArgs); + deployer.setComponentFactory(getComponentFactory(component)); + return deployer; + } catch (NoSuchMethodException nsmetexcp) { throw new SmartFrogDeploymentException(MessageUtil.formatMessage( MSG_METHOD_NOT_FOUND, className, "getConstructor()"), @@ -133,7 +134,9 @@ } } - private static ComponentFactory getComponentFactory(ComponentDescription component) throws SmartFrogResolutionException { + private static ComponentFactory getComponentFactory(ComponentDescription component) + throws SmartFrogResolutionException + { ComponentDescription metadata = null; try { metadata = (ComponentDescription) component.sfResolveHere(SmartFrogCoreKeys.SF_METADATA); @@ -143,7 +146,7 @@ if (metadata != null) { // Component using the new sfMeta syntax. - // The sffactory attribute needs to be resolved in those two steps because sfMeta is declared as such: + // The sfFactory attribute needs to be resolved in those two steps because sfMeta is declared as such: // sfMeta extends DATA { ... sfFactory LAZY xxx; } Reference factoryRef = (Reference) metadata.sfResolveHere(SmartFrogCoreKeys.SF_FACTORY); return (ComponentFactory) metadata.sfResolve(factoryRef); Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -25,7 +25,6 @@ import org.smartfrog.sfcore.common.SmartFrogCoreKeys; import org.smartfrog.sfcore.common.Context; import org.smartfrog.sfcore.common.MessageKeys; -import org.smartfrog.sfcore.common.MessageUtil; import org.smartfrog.sfcore.common.SmartFrogDeploymentException; import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; @@ -61,7 +60,7 @@ protected static final Reference refCodeBase = new Reference( SmartFrogCoreKeys.SF_CODE_BASE); - /** The target description to work of. */ + /** The target description to work off. */ protected ComponentDescription target; /** The factory used to get the component instance. */ @@ -72,8 +71,11 @@ * * @param descr target description */ - public PrimDeployerImpl(ComponentDescription descr, ComponentFactory componentFactory) { + public PrimDeployerImpl(ComponentDescription descr) { target = descr; + } + + public void setComponentFactory(ComponentFactory componentFactory) { this.componentFactory = componentFactory; } @@ -146,7 +148,7 @@ * * @return class code base for that description. */ - protected String getSfCodeBase(ComponentDescription desc) { + private String getSfCodeBase(ComponentDescription desc) { try { return (String) desc.sfResolve(refCodeBase); } catch (Exception e) { @@ -177,8 +179,8 @@ obj = target.sfResolve(refClass); targetClassName = (String) obj; - // We look in the default code base if everything else fails. - return SFClassLoader.forName(targetClassName,targetCodeBase, true); + // 3rd parameter = true: We look in the default code base if everything else fails. + return SFClassLoader.forName(targetClassName, targetCodeBase, true); } catch (SmartFrogResolutionException resex) { resex.put(SmartFrogRuntimeException.SOURCE, target.sfCompleteName()); resex.fillInStackTrace(); Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimHostDeployerImpl.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimHostDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimHostDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -32,7 +32,6 @@ import org.smartfrog.sfcore.logging.LogFactory; import org.smartfrog.sfcore.logging.LogSF; -import org.smartfrog.sfcore.deployer.ComponentFactory; /** * Implements a specialized description deployer. This deployer uses the @@ -62,8 +61,8 @@ * * @param descr target to operate on */ - public PrimHostDeployerImpl(ComponentDescription descr, ComponentFactory componentFactory) { - super(descr, componentFactory); + public PrimHostDeployerImpl(ComponentDescription descr) { + super(descr); } /** Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimProcessDeployerImpl.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimProcessDeployerImpl.java 2007-06-29 12:49:24 UTC (rev 4498) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/processcompound/PrimProcessDeployerImpl.java 2007-06-29 13:53:31 UTC (rev 4499) @@ -24,7 +24,6 @@ import org.smartfrog.sfcore.common.SmartFrogResolutionException; import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.deployer.ComponentFactory; /** @@ -44,8 +43,8 @@ * * @param descr description of the component that is to be deployed */ - public PrimProcessDeployerImpl(ComponentDescription descr, ComponentFactory componentFactory) { - super(descr, componentFactory); + public PrimProcessDeployerImpl(ComponentDescription descr) { + super(descr); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |