From: <aft...@us...> - 2007-07-06 17:07:41
|
Revision: 4590 http://svn.sourceforge.net/smartfrog/?rev=4590&view=rev Author: aftereight Date: 2007-07-06 10:07:40 -0700 (Fri, 06 Jul 2007) Log Message: ----------- Refactoring of function application Modified Paths: -------------- branches/core-branch-osgi/components/cddlm/src/org/smartfrog/services/cddlm/cdl/ResourceLoader.java branches/core-branch-osgi/components/database/test/org/smartfrog/services/database/test/system/core/mysql/ConnectionOpenTest.sf branches/core-branch-osgi/components/xml/src/org/smartfrog/services/xml/utils/ResourceLoader.java branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/OSGiBundleCompound.java branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/components.sf branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/parser/ParseTimeResourceFactory.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/ApplyReference.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/AssertReference.java Added Paths: ----------- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironment.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmClassLoadingEnvironment.java Removed Paths: ------------- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundlePrimFactoryImpl.java branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmPrimFactory.java Modified: branches/core-branch-osgi/components/cddlm/src/org/smartfrog/services/cddlm/cdl/ResourceLoader.java =================================================================== --- branches/core-branch-osgi/components/cddlm/src/org/smartfrog/services/cddlm/cdl/ResourceLoader.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/components/cddlm/src/org/smartfrog/services/cddlm/cdl/ResourceLoader.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -56,16 +56,6 @@ /** - * load with a given codebase; goes through the smartfrog loader. - * - * @param sfCodebase - */ - public ResourceLoader(String sfCodebase) { - this.codebase = sfCodebase; - } - - - /** * get the sfcodebase from a component. This is used to trigger sfcodebase * operation. * @@ -90,15 +80,13 @@ throws RuntimeException { String targetCodeBase = codebase; - InputStream in = SFClassLoader.getResourceAsStream(resourcename, + return SFClassLoader.getResourceAsStream(resourcename, targetCodeBase, true); - return in; } private InputStream loadResourceThroughClassloader(String resourceName) { - InputStream in = loader.getResourceAsStream(resourceName); - return in; + return loader.getResourceAsStream(resourceName); } private void assertResourceLoaded(InputStream in, String resourcename) Modified: branches/core-branch-osgi/components/database/test/org/smartfrog/services/database/test/system/core/mysql/ConnectionOpenTest.sf =================================================================== --- branches/core-branch-osgi/components/database/test/org/smartfrog/services/database/test/system/core/mysql/ConnectionOpenTest.sf 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/components/database/test/org/smartfrog/services/database/test/system/core/mysql/ConnectionOpenTest.sf 2007-07-06 17:07:40 UTC (rev 4590) @@ -33,8 +33,4 @@ } } -sfConfig extends ConnectionOpenTest { - - - -} \ No newline at end of file +sfConfig extends ConnectionOpenTest; \ No newline at end of file Modified: branches/core-branch-osgi/components/xml/src/org/smartfrog/services/xml/utils/ResourceLoader.java =================================================================== --- branches/core-branch-osgi/components/xml/src/org/smartfrog/services/xml/utils/ResourceLoader.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/components/xml/src/org/smartfrog/services/xml/utils/ResourceLoader.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -57,16 +57,6 @@ /** - * load with a given codebase; goes through the smartfrog loader. - * - * @param sfCodebase the codebase - */ - public ResourceLoader(String sfCodebase) { - this.codebase = sfCodebase; - } - - - /** * get the sfcodebase from a component. This is used to trigger sfcodebase * operation. * Copied: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironment.java (from rev 4550, branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundlePrimFactoryImpl.java) =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironment.java (rev 0) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundleClassLoadingEnvironment.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -0,0 +1,83 @@ +package org.smartfrog.osgi; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.smartfrog.sfcore.common.SmartFrogCoreKeys; +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.prim.Prim; +import org.smartfrog.sfcore.prim.TerminationRecord; + +import java.rmi.RemoteException; +import java.io.InputStream; +import java.io.IOException; +import java.net.URL; + + +public class BundleClassLoadingEnvironment extends AbstractClassLoadingEnvironment { + public static final String LOCATION_ATTRIBUTE = "location"; + private Bundle hostBundle = null; + + public BundleClassLoadingEnvironment() throws RemoteException {} + + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + super.sfDeploy(); + + BundleContext daemonBundleContext = OSGiUtilities.getDaemonBundleContext(this); + String location = (String) sfResolve(LOCATION_ATTRIBUTE); + + try { + hostBundle = daemonBundleContext.installBundle(location); + } catch (BundleException e) { + throw SmartFrogException.forward( + "Error when installing bundle from location: " + location, e); + } + } + + public synchronized void sfStart() throws SmartFrogException, RemoteException { + super.sfStart(); + + if (OSGiUtilities.isNotFragment(hostBundle)) { + try { + hostBundle.start(); + } catch (BundleException e) { + SmartFrogException.forward("Error when starting bundle", e); + } + } + } + + protected void sfTerminateWith(TerminationRecord status) { + try { + hostBundle.uninstall(); + } catch (BundleException e) { + sfLog().error("Error when uninstalling bundle", e); + } + + super.sfTerminate(status); + } + + protected Prim getComponentImpl(ComponentDescription askedFor) + throws ClassNotFoundException, InstantiationException, IllegalAccessException, + SmartFrogResolutionException + { + String sfClass = (String) askedFor.sfResolveHere(SmartFrogCoreKeys.SF_CLASS); + Class primClass = hostBundle.loadClass(sfClass); + return (Prim) primClass.newInstance(); + } + + protected Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { + return hostBundle.loadClass(className).newInstance(); + } + + public InputStream getComponentDescription(String pathname) { + URL url = hostBundle.getResource(pathname); + try { + return url != null ? url.openStream() : null; + } catch (IOException e) { + return null; + } + } +} Deleted: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundlePrimFactoryImpl.java =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundlePrimFactoryImpl.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/BundlePrimFactoryImpl.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -1,83 +0,0 @@ -package org.smartfrog.osgi; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.smartfrog.sfcore.common.SmartFrogCoreKeys; -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.prim.Prim; -import org.smartfrog.sfcore.prim.TerminationRecord; - -import java.rmi.RemoteException; -import java.io.InputStream; -import java.io.IOException; -import java.net.URL; - - -public class BundlePrimFactoryImpl extends AbstractClassLoadingEnvironment { - public static final String LOCATION_ATTRIBUTE = "location"; - private Bundle hostBundle = null; - - public BundlePrimFactoryImpl() throws RemoteException {} - - public synchronized void sfDeploy() throws SmartFrogException, RemoteException { - super.sfDeploy(); - - BundleContext daemonBundleContext = OSGiUtilities.getDaemonBundleContext(this); - String location = (String) sfResolve(LOCATION_ATTRIBUTE); - - try { - hostBundle = daemonBundleContext.installBundle(location); - } catch (BundleException e) { - throw SmartFrogException.forward( - "Error when installing bundle from location: " + location, e); - } - } - - public synchronized void sfStart() throws SmartFrogException, RemoteException { - super.sfStart(); - - if (OSGiUtilities.isNotFragment(hostBundle)) { - try { - hostBundle.start(); - } catch (BundleException e) { - SmartFrogException.forward("Error when starting bundle", e); - } - } - } - - protected void sfTerminateWith(TerminationRecord status) { - try { - hostBundle.uninstall(); - } catch (BundleException e) { - sfLog().error("Error when uninstalling bundle", e); - } - - super.sfTerminate(status); - } - - protected Prim getComponentImpl(ComponentDescription askedFor) - throws ClassNotFoundException, InstantiationException, IllegalAccessException, - SmartFrogResolutionException - { - String sfClass = (String) askedFor.sfResolveHere(SmartFrogCoreKeys.SF_CLASS); - Class primClass = hostBundle.loadClass(sfClass); - return (Prim) primClass.newInstance(); - } - - protected Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { - return hostBundle.loadClass(className).newInstance(); - } - - public InputStream getComponentDescription(String pathname) { - URL url = hostBundle.getResource(pathname); - try { - return url != null ? url.openStream() : null; - } catch (IOException e) { - return null; - } - } -} Modified: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/OSGiBundleCompound.java =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/OSGiBundleCompound.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/OSGiBundleCompound.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -19,7 +19,7 @@ import java.util.Enumeration; /** - * @deprecated Use BundlePrimFactoryImpl instead. + * @deprecated Use BundleClassLoadingEnvironment instead. */ public class OSGiBundleCompound extends CompoundImpl implements Compound { private static final String BUNDLE_URL = "bundleURL"; Modified: branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/components.sf =================================================================== --- branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/components.sf 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/extras/osgi/daemon-bundle/src/org/smartfrog/osgi/components.sf 2007-07-06 17:07:40 UTC (rev 4590) @@ -6,7 +6,7 @@ } OSGiBundle extends Prim { - sfClass "org.smartfrog.osgi.BundlePrimFactoryImpl"; + sfClass "org.smartfrog.osgi.BundleClassLoadingEnvironment"; sfExport false; location extends String; } \ No newline at end of file Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/common/SmartFrogCoreKeys.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -347,4 +347,5 @@ */ public static final String SF_METADATA = "sfMeta"; + public static final String SF_FUNCTION_CLASS = "sfFunctionClass"; } Modified: 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-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/AbstractClassLoadingEnvironment.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -50,7 +50,8 @@ protected abstract Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException; - public final Function getFunction(String className) throws Exception { + public final Function getFunction(ComponentDescription metadata) throws Exception { + String className = (String) metadata.sfResolveHere(SmartFrogCoreKeys.SF_FUNCTION_CLASS); return (Function) newInstance(className); } Copied: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmClassLoadingEnvironment.java (from rev 4550, branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmPrimFactory.java) =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmClassLoadingEnvironment.java (rev 0) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmClassLoadingEnvironment.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -0,0 +1,115 @@ +package org.smartfrog.sfcore.deployer; + +import org.smartfrog.sfcore.common.*; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.componentdescription.ComponentDescriptionImpl; +import org.smartfrog.sfcore.prim.Prim; +import org.smartfrog.sfcore.reference.Reference; +import org.smartfrog.sfcore.security.SFClassLoader; + +import java.io.InputStream; + +/** + * Implements the sfCodebase-aware component creation, as currently documented. + * The code was originally in PrimImpl. + */ +public class OldAlgorithmClassLoadingEnvironment extends AbstractClassLoadingEnvironment { + + /** + * Efficiency holder of sfClass reference. + */ + private static final Reference refClass = new Reference( + SmartFrogCoreKeys.SF_CLASS); + + /** + * Efficiency holder of sfCodeBase reference. + */ + private static final Reference refCodeBase = new Reference( + SmartFrogCoreKeys.SF_CODE_BASE); + + + protected Prim getComponentImpl(ComponentDescription askedFor) + throws ClassNotFoundException, InstantiationException, + IllegalAccessException, SmartFrogResolutionException, + SmartFrogDeploymentException + { + return (Prim) getPrimClass(askedFor).newInstance(); + } + + protected Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { + return SFClassLoader.forName(className).newInstance(); + } + + + /** + * Get the class for the primitive to be deployed. This is where the + * sfClass attribute is looked up, using the classloader returned by + * getPrimClassLoader + * + * @return class for target + * @throws Exception failed to load class + */ + private Class getPrimClass(ComponentDescription target) throws SmartFrogResolutionException, SmartFrogDeploymentException { + String targetCodeBase = null; + String targetClassName; + Object obj = null; + try { + + targetCodeBase = getSfCodeBase(target); + targetClassName = (String) target.sfResolve(refClass); + + // 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(); + + throw resex; + } catch (ClassCastException ccex) { + Object name = null; + if (target.sfContext().containsKey(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME)) { + name = target.sfResolveHere(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME, false); + } + throw new SmartFrogDeploymentException(refClass, null, name, target, + null, "Wrong class when resolving '" + refClass + "': '" + + obj + "' (" + obj.getClass().getName() + ")", ccex, targetCodeBase); + } catch (ClassNotFoundException cnfex) { + Object name = null; + if (target.sfContext().containsKey(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME)) { + name = target.sfResolveHere(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME, false); + } + ComponentDescription cdInfo = new ComponentDescriptionImpl(null, new ContextImpl(), false); + try { + if (targetCodeBase != null) cdInfo.sfAddAttribute(SmartFrogCoreKeys.SF_CODE_BASE, + targetCodeBase); + cdInfo.sfAddAttribute("java.class.path", System.getProperty("java.class.path")); + cdInfo.sfAddAttribute(SmartFrogCoreProperty.sfProcessName, + System.getProperty(SmartFrogCoreProperty.sfProcessName)); + } catch (SmartFrogException sfex) { + if (sfLog().isDebugEnabled()) sfLog().debug("", sfex); + } + throw new SmartFrogDeploymentException(refClass, null, name, target, null, "Class not found", cnfex, cdInfo); + } + } + + /** + * Gets the class code base by resolving the sfCodeBase attribute in the + * given description. + * + * @param desc Description in which we resolve the code base. + * @return class code base for that description. + */ + private String getSfCodeBase(ComponentDescription desc) { + try { + return (String) desc.sfResolve(refCodeBase); + } catch (Exception e) { + return null; + } + } + + + public InputStream getComponentDescription(String pathname) { + return SFClassLoader.getResourceAsStream(pathname); + } +} Deleted: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmPrimFactory.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmPrimFactory.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/OldAlgorithmPrimFactory.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -1,115 +0,0 @@ -package org.smartfrog.sfcore.deployer; - -import org.smartfrog.sfcore.common.*; -import org.smartfrog.sfcore.componentdescription.ComponentDescription; -import org.smartfrog.sfcore.componentdescription.ComponentDescriptionImpl; -import org.smartfrog.sfcore.prim.Prim; -import org.smartfrog.sfcore.reference.Reference; -import org.smartfrog.sfcore.security.SFClassLoader; - -import java.io.InputStream; - -/** - * Implements the sfCodebase-aware component creation, as currently documented. - * The code was originally in PrimImpl. - */ -public class OldAlgorithmPrimFactory extends AbstractClassLoadingEnvironment { - - /** - * Efficiency holder of sfClass reference. - */ - private static final Reference refClass = new Reference( - SmartFrogCoreKeys.SF_CLASS); - - /** - * Efficiency holder of sfCodeBase reference. - */ - private static final Reference refCodeBase = new Reference( - SmartFrogCoreKeys.SF_CODE_BASE); - - - protected Prim getComponentImpl(ComponentDescription askedFor) - throws ClassNotFoundException, InstantiationException, - IllegalAccessException, SmartFrogResolutionException, - SmartFrogDeploymentException - { - return (Prim) getPrimClass(askedFor).newInstance(); - } - - protected Object newInstance(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException { - return SFClassLoader.forName(className).newInstance(); - } - - - /** - * Get the class for the primitive to be deployed. This is where the - * sfClass attribute is looked up, using the classloader returned by - * getPrimClassLoader - * - * @return class for target - * @throws Exception failed to load class - */ - private Class getPrimClass(ComponentDescription target) throws SmartFrogResolutionException, SmartFrogDeploymentException { - String targetCodeBase = null; - String targetClassName; - Object obj = null; - try { - - targetCodeBase = getSfCodeBase(target); - targetClassName = (String) target.sfResolve(refClass); - - // 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(); - - throw resex; - } catch (ClassCastException ccex) { - Object name = null; - if (target.sfContext().containsKey(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME)) { - name = target.sfResolveHere(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME, false); - } - throw new SmartFrogDeploymentException(refClass, null, name, target, - null, "Wrong class when resolving '" + refClass + "': '" - + obj + "' (" + obj.getClass().getName() + ")", ccex, targetCodeBase); - } catch (ClassNotFoundException cnfex) { - Object name = null; - if (target.sfContext().containsKey(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME)) { - name = target.sfResolveHere(SmartFrogCoreKeys.SF_PROCESS_COMPONENT_NAME, false); - } - ComponentDescription cdInfo = new ComponentDescriptionImpl(null, new ContextImpl(), false); - try { - if (targetCodeBase != null) cdInfo.sfAddAttribute(SmartFrogCoreKeys.SF_CODE_BASE, - targetCodeBase); - cdInfo.sfAddAttribute("java.class.path", System.getProperty("java.class.path")); - cdInfo.sfAddAttribute(SmartFrogCoreProperty.sfProcessName, - System.getProperty(SmartFrogCoreProperty.sfProcessName)); - } catch (SmartFrogException sfex) { - if (sfLog().isDebugEnabled()) sfLog().debug("", sfex); - } - throw new SmartFrogDeploymentException(refClass, null, name, target, null, "Class not found", cnfex, cdInfo); - } - } - - /** - * Gets the class code base by resolving the sfCodeBase attribute in the - * given description. - * - * @param desc Description in which we resolve the code base. - * @return class code base for that description. - */ - private String getSfCodeBase(ComponentDescription desc) { - try { - return (String) desc.sfResolve(refCodeBase); - } catch (Exception e) { - return null; - } - } - - - public InputStream getComponentDescription(String pathname) { - return SFClassLoader.getResourceAsStream(pathname); - } -} 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-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/deployer/SFDeployer.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -36,7 +36,7 @@ public class SFDeployer implements MessageKeys { private static ComponentDeployer defaultComponentDeployer = new PrimProcessDeployerImpl(); - private static PrimFactory defaultPrimFactory = new OldAlgorithmPrimFactory(); + private static PrimFactory defaultPrimFactory = new OldAlgorithmClassLoadingEnvironment(); /** * Deploy description. Constructs the real deployer using getDeployer Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/parser/ParseTimeResourceFactory.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/parser/ParseTimeResourceFactory.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/parser/ParseTimeResourceFactory.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -2,6 +2,7 @@ import org.smartfrog.sfcore.languages.sf.PhaseAction; import org.smartfrog.sfcore.reference.Function; +import org.smartfrog.sfcore.componentdescription.ComponentDescription; import java.io.InputStream; @@ -9,7 +10,7 @@ * A factory used to access user-provided resources needed at parse time. */ public interface ParseTimeResourceFactory { - Function getFunction(String className) throws Exception; + Function getFunction(ComponentDescription metadata) throws Exception; PhaseAction getPhaseAction(String className) throws Exception; InputStream getComponentDescription(String pathname); // getConstraintSolver also someday 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-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimDeployerImpl.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -136,7 +136,7 @@ } // BEGIN LEGACY CODE ////////////// - // This is now in OldAlgorithmPrimFactory, but DNSComponentDeployerImpl needs it here. + // This is now in OldAlgorithmClassLoadingEnvironment, but DNSComponentDeployerImpl needs it here. // Should be removed very soon. @@ -163,7 +163,7 @@ * * @return class for target * @throws Exception failed to load class - * @deprecated This is now in OldAlgorithmPrimFactory + * @deprecated This is now in OldAlgorithmClassLoadingEnvironment */ protected Class getPrimClass() throws SmartFrogResolutionException, SmartFrogDeploymentException { String targetCodeBase = null; Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/prim/PrimImpl.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -788,11 +788,7 @@ SFProcess.getProcessCompound().sfDeRegister(this); } } catch (Exception ex) { - // @TODO: Log. Ignore. - //Logger.logQuietly(ex); - if (sfLog().isIgnoreEnabled()){ - sfLog().ignore(ex); - } + sfLog().ignore(ex); } } @@ -1045,11 +1041,7 @@ try { sfTerminateWithHooks.applyHooks(this, status); } catch (Exception ex) { - // @TODO: Log. Ignore. - //Logger.logQuietly(ex); - if (sfLog().isIgnoreEnabled()){ - sfLog().ignore(ex); - } + sfLog().ignore(ex); } deregisterWithProcessCompound(); @@ -1117,9 +1109,7 @@ try { org.smartfrog.sfcore.security.SecureRemoteObject.unexportObject(this, true); } catch (NoSuchObjectException ex) { - // @TODO: Log. Ignore. - //Logger.logQuietly(ex); - if (sfLog().isIgnoreEnabled()){ sfLog().ignore(ex); } + sfLog().ignore(ex); } //synchronized (this) { @@ -1159,9 +1149,7 @@ sfStartLivenessSender(); sfParentageChanged(); } catch (SmartFrogResolutionException ex){ - //@Todo: log - sfLog().ignore("unknown at detach time",ex); - //ignore + sfLog().ignore("unknown at detach time", ex); } } @@ -1180,7 +1168,7 @@ sfParent = null; terminateNotifying(status, null); } catch (Exception ex) { - if (sfLog().isIgnoreEnabled()){ sfLog().ignore(ex); } + sfLog().ignore(ex); } } Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/ApplyReference.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/ApplyReference.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/ApplyReference.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -1,16 +1,12 @@ package org.smartfrog.sfcore.reference; import org.smartfrog.sfcore.common.*; - -import org.smartfrog.sfcore.languages.sf.sfcomponentdescription.SFComponentDescription; -import org.smartfrog.sfcore.security.SFClassLoader; import org.smartfrog.sfcore.componentdescription.ComponentDescription; +import org.smartfrog.sfcore.parser.ParseTimeResourceFactory; import org.smartfrog.sfcore.prim.Prim; import java.io.Serializable; -import java.util.Enumeration; import java.util.Iterator; -import java.rmi.RemoteException; /** * The subclass of Reference that is a function application. The structure of the classes is @@ -25,6 +21,8 @@ * If */ public class ApplyReference extends Reference implements Copying, Cloneable, Serializable { + // This will cause NotSerializableExceptions if someone tries to serialize us, + // but the class should not be Serializable anyway protected ComponentDescription comp; public ApplyReference(ComponentDescription comp) { @@ -94,57 +92,13 @@ * @param rr ReferenceResolver to be used for resolving this reference * @param index index of first referencepart to start resolving at * @return value found on resolving this function - * @throws SmartFrogResolutionException if reference failed to resolve + * @throws org.smartfrog.sfcore.common.SmartFrogResolutionException + * if reference failed to resolve */ public Object resolve(ReferenceResolver rr, int index) - throws SmartFrogResolutionException { - //take a new context... - // iterate over the attributes of comp- ignoring any beginning with sf; - // cache sfFunctionClass attribute; - // resolve all non-sf attributes, if they are links - // if any return s LAZY object, set self to lazy and return self, otherwise update copy - // and invoke function with copy of CD, return result - - Context forFunction = new ContextImpl(); - String functionClass = null; - Object result; - - if (getData()) return this; - - if (rr instanceof ComponentDescription) - comp.setParent((ComponentDescription) rr); - else if (rr instanceof Prim) - comp.setPrimParent((Prim) rr); - - try { - functionClass = (String) comp.sfResolveHere("sfFunctionClass"); - } catch (ClassCastException e) { - throw new SmartFrogResolutionException("function class is not a string", e); - } - - for (Iterator v = comp.sfAttributes(); v.hasNext();) { - Object name = v.next(); - String nameS = name.toString(); - if (!nameS.equals("sfFunctionClass")){ - Object value = comp.sfResolve(new Reference(ReferencePart.here(name))); - try { - forFunction.sfAddAttribute(name, value); - } catch (SmartFrogContextException e) { - //shouldn't happen - } - } - } - if (functionClass == null) { - throw new SmartFrogResolutionException("unknown function class "); - } - try { - Function function = (Function) (SFClassLoader.forName((String) functionClass) - .newInstance()); - result = function.doit(forFunction, null, rr); - } catch (Exception e) { - throw new SmartFrogResolutionException("failed to create function class " + functionClass, e); - } - return result; + throws SmartFrogResolutionException + { + return doResolve(rr, false); } /** @@ -153,62 +107,119 @@ * @param rr ReferenceResolver to be used for resolving this reference * @param index index of first referencepart to start resolving at * @return value found on resolving this function - * @throws SmartFrogResolutionException if reference failed to resolve + * @throws org.smartfrog.sfcore.common.SmartFrogResolutionException + * if reference failed to resolve */ public Object resolve(RemoteReferenceResolver rr, int index) - throws SmartFrogResolutionException { - //take a new context... + throws SmartFrogResolutionException + { + return doResolve(rr, true); + } + + private Object doResolve(Object rr, final boolean remote) throws SmartFrogResolutionException {//take a new context... // iterate over the attributes of comp- ignoring any beginning with sf; // cache sfFunctionClass attribute; // resolve all non-sf attributes, if they are links // if any return s LAZY object, set self to lazy and return self, otherwise update copy // and invoke function with copy of CD, return result - Context forFunction = new ContextImpl(); - String functionClass = null; + + if (getData()) return this; + + initComp(rr); + + Object result = createAndApplyFunction(rr, remote); + + return result; + } + + + private Object createAndApplyFunction(Object rr, boolean remote) throws SmartFrogResolutionException { Object result; + try { + // First try to use the new syntax + ComponentDescription metadata = (ComponentDescription) comp.sfResolveHere(SmartFrogCoreKeys.SF_METADATA); + Context forFunction = createContext(SmartFrogCoreKeys.SF_METADATA); + Function function = createFunction(metadata); - if (getData()) { - return this; + try { + if (remote) result = function.doit(forFunction, null, (RemoteReferenceResolver) rr); + else result = function.doit(forFunction, null, (ReferenceResolver) rr); + } catch (SmartFrogException e) { + throw new SmartFrogResolutionException("Function invocation failed", e); + } + } catch (ClassCastException cce) { + throw new SmartFrogResolutionException("The sfMeta attribute is not a DATA block", cce); + + + } catch (SmartFrogResolutionException e) { + + // Using the old syntax + String functionClass; + try { + functionClass = (String) comp.sfResolveHere(SmartFrogCoreKeys.SF_FUNCTION_CLASS); + } catch (ClassCastException cce) { + throw new SmartFrogResolutionException("function class is not a string", cce); + } + Context forFunction = createContext(SmartFrogCoreKeys.SF_FUNCTION_CLASS); + result = createFunctionOldSyntax(functionClass); + } + return result; + } - if (rr instanceof ComponentDescription) { - comp.setParent((ComponentDescription) rr); - } else if (rr instanceof Prim) { - comp.setPrimParent((Prim) rr); + private Function createFunctionOldSyntax(String functionClass) throws SmartFrogResolutionException { + if (functionClass == null) + throw new SmartFrogResolutionException("unknown function class"); + + try { + return (Function) Class.forName(functionClass).newInstance(); + } catch (Exception e) { + throw new SmartFrogResolutionException("failed to create function class " + functionClass, e); } + } + private Function createFunction(ComponentDescription metadata) throws SmartFrogResolutionException { + if (metadata == null) + throw new SmartFrogResolutionException("sfMeta attribute is null"); + try { - functionClass = (String) comp.sfResolveHere("sfFunctionClass"); - } catch (ClassCastException e) { - throw new SmartFrogResolutionException("function class is not a string", e); + Reference factoryRef = (Reference) metadata.sfResolveHere(SmartFrogCoreKeys.SF_FACTORY); + ParseTimeResourceFactory factory = (ParseTimeResourceFactory) metadata.sfResolve(factoryRef); + return factory.getFunction(metadata); + } catch (Exception e) { + throw new SmartFrogResolutionException("Failed to create function. sfMeta block: " + metadata, e); } + } + private Context createContext(final String omittedAttribute) + throws SmartFrogResolutionException + { + Context forFunction = new ContextImpl(); for (Iterator v = comp.sfAttributes(); v.hasNext();) { Object name = v.next(); String nameS = name.toString(); - if (!nameS.equals("sfFunctionClass")) { + if (!nameS.equals(omittedAttribute)) { Object value = comp.sfResolve(new Reference(ReferencePart.here(name))); try { forFunction.sfAddAttribute(name, value); } catch (SmartFrogContextException e) { - //shouldn't happen. but when it does... + //shouldn't happen e.printStackTrace(); } } } - if (functionClass == null) { - throw new SmartFrogResolutionException("unknown function class "); - } - try { - Function function = (Function) (SFClassLoader.forName((String) functionClass) - .newInstance()); - result = function.doit(forFunction, null, rr); - } catch (Exception e) { - throw new SmartFrogResolutionException("failed to create or evaluate function class " + functionClass + " with data " + forFunction, e); - } - return result; + return forFunction; } + + private void initComp(Object rr) { + if (rr instanceof ComponentDescription) + comp.setParent((ComponentDescription) rr); + else if (rr instanceof Prim) + comp.setPrimParent((Prim) rr); + } + + /** * Returns string representation of the reference. * Overrides Object.toString. Modified: branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/AssertReference.java =================================================================== --- branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/AssertReference.java 2007-07-06 16:19:32 UTC (rev 4589) +++ branches/core-branch-osgi/smartfrog/src/org/smartfrog/sfcore/reference/AssertReference.java 2007-07-06 17:07:40 UTC (rev 4590) @@ -23,42 +23,13 @@ * The function application reference resolves by evaluating hte refeences it contains, then evaluating the funciton. * If */ -public class AssertReference extends Reference implements Copying, Cloneable, Serializable { - protected ComponentDescription comp; - +public class AssertReference extends ApplyReference implements Copying, Cloneable, Serializable { + public AssertReference(ComponentDescription comp) { - super(); - this.comp = comp; + super(comp); } - /** - * Returns a copy of the reference, by cloning itself and the function part - * - * @return copy of reference - * @see org.smartfrog.sfcore.common.Copying - */ - public Object copy() { - AssertReference ret = (AssertReference) clone(); - - ret.comp = (ComponentDescription) comp.copy(); - - return ret; - } - - /** - * Makes a clone of the reference. The inside ref holder is cloned, but the - * contained component is NOT. - * - * @return clone of reference - */ - public Object clone() { - AssertReference res = (AssertReference) super.clone(); - res.comp = comp; - return res; - } - - /** * Checks if this and given reference are equal. Two references are * considered to be equal if the component they wrap are == * @@ -66,28 +37,13 @@ * @return true if equal, false if not */ public boolean equals(Object ref) { - if (!(ref instanceof AssertReference)) { + if (!(ref instanceof AssertReference)) return false; - } - - if (((AssertReference) ref).comp != comp) { - return false; - } - - return true; + + return super.equals(ref); } /** - * Returns the hashcode for this reference. Hash code for reference is made - * out of the sum of the parts hashcodes - * - * @return integer hashcode - */ - public int hashCode() { - return comp.hashCode(); - } - - /** * Resolves this apply reference by applying the function - unless this is data.. * * @param rr ReferenceResolver to be used for resolving this reference @@ -96,68 +52,10 @@ * @throws org.smartfrog.sfcore.common.SmartFrogResolutionException if reference failed to resolve */ public Object resolve(ReferenceResolver rr, int index) - throws SmartFrogResolutionException { - //take a new context... - // iterate over the attributes of comp- ignoring any beginning with sf; - // cache sfFunctionClass attribute; - // resolve all non-sf attributes, if they are links - // if any return s LAZY object, set self to lazy and return self, otherwise update copy - // and invoke function with copy of CD, return result - - Context forFunction = new ContextImpl(); - String functionClass = null; - Object result; - - if (getData()) return this; - - if (rr instanceof ComponentDescription) - comp.setParent((ComponentDescription) rr); - else if (rr instanceof Prim) - comp.setPrimParent((Prim) rr); - - try { - functionClass = (String) comp.sfResolveHere("sfFunctionClass"); - } catch (ClassCastException e) { - throw new SmartFrogResolutionException("function class is not a string", e); - } - - for (Iterator v = comp.sfAttributes(); v.hasNext();) { - Object name = v.next(); - String nameS = name.toString(); - if (!nameS.equals("sfFunctionClass")) { - Object value = comp.sfResolve(new Reference(ReferencePart.here(name))); - try { - forFunction.sfAddAttribute(name, value); - } catch (SmartFrogContextException e) { - //shouldn't happen - } - } - } - if (functionClass == null) { - throw new SmartFrogResolutionException("unknown function class "); - } - try { - Function function = (Function) (SFClassLoader.forName((String) functionClass) - .newInstance()); - result = function.doit(forFunction, null, rr); - } catch (Exception e) { - throw new SmartFrogResolutionException("failed to create function class " + functionClass, e); - } - if (result instanceof Boolean) { - if (!((Boolean) result).booleanValue()) throw new SmartFrogAssertionResolutionException("Assertion failure (false) for " + - this + - ((rr instanceof ComponentDescriptionImpl) ? - " in component " - + ((ComponentDescriptionImpl)rr).sfCompleteNameSafe() - : "")); - } else { - throw new SmartFrogAssertionResolutionException("Assertion failure (non boolean result) for " - + this + - ((rr instanceof ComponentDescriptionImpl) ? - " in component " - + ((ComponentDescriptionImpl)rr).sfCompleteNameSafe() - : "")); - } + throws SmartFrogResolutionException + { + Object result = super.resolve(rr, index); + checkAssert(result, rr, true); return result; } @@ -170,70 +68,34 @@ * @throws org.smartfrog.sfcore.common.SmartFrogResolutionException if reference failed to resolve */ public Object resolve(RemoteReferenceResolver rr, int index) - throws SmartFrogResolutionException { - //take a new context... - // iterate over the attributes of comp- ignoring any beginning with sf; - // cache sfFunctionClass attribute; - // resolve all non-sf attributes, if they are links - // if any return s LAZY object, set self to lazy and return self, otherwise update copy - // and invoke function with copy of CD, return result - Context forFunction = new ContextImpl(); - String functionClass = null; - Object result; + throws SmartFrogResolutionException + { + Object result = super.resolve(rr, index); + checkAssert(result, rr, true); + return result; + } - if (getData()) return this; - - if (rr instanceof ComponentDescription) - comp.setParent((ComponentDescription) rr); - else if (rr instanceof Prim) - comp.setPrimParent((Prim) rr); - - try { - functionClass = (String) comp.sfResolveHere("sfFunctionClass"); - } catch (ClassCastException e) { - throw new SmartFrogAssertionResolutionException("function class is not a string", e); - } - - for (Iterator v = comp.sfAttributes(); v.hasNext();) { - Object name = v.next(); - String nameS = name.toString(); - if (!nameS.equals("sfFunctionClass")) { - Object value = comp.sfResolve(new Reference(ReferencePart.here(name))); - try { - forFunction.sfAddAttribute(name, value); - } catch (SmartFrogContextException e) { - //shouldn't happen - } - } - } - if (functionClass == null) { - throw new SmartFrogAssertionResolutionException("unknown function class "); - } - try { - Function function = (Function) (SFClassLoader.forName((String) functionClass) - .newInstance()); - result = function.doit(forFunction, null, rr); - } catch (Exception e) { - throw new SmartFrogAssertionResolutionException("failed to create or evaluate function class \"" + functionClass + "\" with data " + forFunction, e); - } + private void checkAssert(Object result, Object rr, boolean remote) throws SmartFrogAssertionResolutionException { if (result instanceof Boolean) { - if (!((Boolean) result).booleanValue()) throw new SmartFrogAssertionResolutionException("Assertion failure (false) for " - + this + - ((rr instanceof PrimImpl) ? - " in component " - + ((PrimImpl)rr).sfCompleteNameSafe() - : "")); + if (!((Boolean) result).booleanValue()) + throw new SmartFrogAssertionResolutionException("Assertion failure (false) for " + + this + sfCompleteNameSafe(rr, remote)); } else { - throw new SmartFrogAssertionResolutionException("Assertion failure (non boolean result) for " + - this + - ((rr instanceof PrimImpl) ? - " in component " - + ((PrimImpl)rr).sfCompleteNameSafe() - : "")); + throw new SmartFrogAssertionResolutionException("Assertion failure (non boolean result) for " + + this + sfCompleteNameSafe(rr, remote)); } - return result; } + private String sfCompleteNameSafe(Object rr, boolean remote) { + if (remote) { + if (rr instanceof PrimImpl) return " in component " + ((PrimImpl) rr).sfCompleteNameSafe(); + else return "<complete name unknown>"; + } else { + if (rr instanceof ComponentDescriptionImpl) + return " in component " + ((ComponentDescriptionImpl) rr).sfCompleteNameSafe(); + else return "<complete name unknown>"; + } + } /** * Returns string representation of the reference. * Overrides Object.toString. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |