mcconnell 2002/12/19 02:34:01 Modified: assembly/src/java/org/apache/avalon/assembly/appliance DefaultAppliance.java Log: Enhancement management of the deployment context. Revision Changes Path 1.12 +119 -13 avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java Index: DefaultAppliance.java =================================================================== RCS file: /home/cvs/avalon-sandbox/assembly/src/java/org/apache/avalon/assembly/appliance/DefaultAppliance.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- DefaultAppliance.java 17 Dec 2002 09:55:23 -0000 1.11 +++ DefaultAppliance.java 19 Dec 2002 10:34:00 -0000 1.12 @@ -50,6 +50,7 @@ package org.apache.avalon.assembly.appliance; +import java.io.File; import java.util.Map; import java.util.Hashtable; import java.net.URL; @@ -93,9 +94,9 @@ //===================================================================== /** - * The appliance context. + * The profile. */ - private ApplianceContext m_context; + private Profile m_profile; /** * The lifestyle service from which the appliance lifestyle handler is established. @@ -119,6 +120,11 @@ private boolean m_enabled = true; /** + * The context provider. + */ + private Appliance m_context; + + /** * The dependencies providers keyed by role name. */ private final Hashtable m_providers = new Hashtable(); @@ -134,6 +140,11 @@ private String m_path; /** + * The partition name. + */ + private String m_partition; + + /** * The logging channel. */ private Logger m_logger; @@ -148,6 +159,16 @@ */ private String m_domain; + /** + * The deployment context. + */ + private Map m_deployment; + + /** + * The activation policy. + */ + private boolean m_activation; + //============================================================== // constructor //============================================================== @@ -175,9 +196,16 @@ m_logger = logger; m_engine = engine; - m_context = context; m_enabled = context.getEnabled(); m_system = system; + m_activation = context.getActivationPolicy(); + m_partition = context.getPartitionName(); + m_profile = (Profile) context.getProfile(); + + if( m_partition == null ) + { + m_partition = ""; + } try { @@ -188,16 +216,69 @@ m_domain = "localhost"; } - if( getPartitionName() != null ) + if( m_partition.endsWith("/") ) { - m_path = getPartitionName() - + "/" + context.getProfile().getName(); + m_path = m_partition + context.getProfile().getName(); } else { - m_path = "/" + context.getProfile().getName(); + m_path = m_partition + "/" + context.getProfile().getName(); + } + + // + // make sure that the deployment context is fully populated + // + + try + { + Map map = context.getDeploymentContext(); + + // + // setup the name and the partition + // + + map.put( "urn:avalon:name", m_profile.getName() ); + map.put( "urn:avalon:partition.name", m_partition ); + + // + // setup the home and working directory for the component + // + + File base = (File) system.get( "urn:assembly:home" ); + File dir = new File( base, "work" ); + dir.mkdirs(); + File home = new File( dir, m_path ); + File work = new File( home, "temp" ); + home.mkdir(); + work.mkdir(); + work.deleteOnExit(); + map.put( "urn:avalon:home", home ); + map.put( "urn:avalon:work", work ); + + // + // assign the updated map as the deployment context + // + + m_deployment = map; + + } + catch( ContextException e ) + { + final String error = "System context does not contain the entry 'urn:assembly:home'" + + " in appliance: " + this; + throw new IllegalStateException( error ); + } + catch( Throwable e ) + { + final String error = + "Unexpected exception while preparing deployment context in appliance: " + this; + throw new ApplianceException( error, e ); } + // + // finally, create the lifestyle handler + // + try { m_handler = @@ -207,7 +288,7 @@ catch( Throwable e ) { final String error = - "Could not initialize appliance due to a lifestyle handler establishment failure."; + "Unexpected lifestyle handler establishment failure in appliance: " + this; throw new ApplianceException( error, e ); } } @@ -252,7 +333,7 @@ */ public String getPartitionName() { - return m_context.getPartitionName(); + return m_partition; } /** @@ -269,7 +350,7 @@ */ public Map getDeploymentContext() { - return m_context.getDeploymentContext(); + return m_deployment; } /** @@ -279,7 +360,7 @@ */ public Profile getProfile() { - return m_context.getProfile(); + return m_profile; } /** @@ -291,7 +372,7 @@ */ public boolean getActivationPolicy() { - return m_context.getActivationPolicy(); + return m_activation; } /** @@ -314,6 +395,31 @@ public void setEnabled( boolean value ) { m_enabled = value; + } + + /** + * Return the context provider. + * + * @return the appliance mapped as provider of the context + */ + public Appliance getContextProvider() + { + return m_context; + } + + /** + * Set the context provider. + * + * @param applaince the appliance to be mapped as provider of the context + * @exception IllegalStateException if the provider is already set + */ + public void setContextProvider( Appliance appliance ) + { + if( m_context != null ) + { + throw new IllegalStateException( "appliance" ); + } + m_context = appliance; } /**
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>