Return-Path: Delivered-To: apmail-avalon-cvs-archive@www.apache.org Received: (qmail 7800 invoked from network); 7 Feb 2004 19:31:10 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 7 Feb 2004 19:31:10 -0000 Received: (qmail 42815 invoked by uid 500); 7 Feb 2004 19:31:00 -0000 Delivered-To: apmail-avalon-cvs-archive@avalon.apache.org Received: (qmail 42740 invoked by uid 500); 7 Feb 2004 19:30:59 -0000 Mailing-List: contact cvs-help@avalon.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Avalon CVS List" Reply-To: "Avalon Developers List" Delivered-To: mailing list cvs@avalon.apache.org Received: (qmail 42714 invoked from network); 7 Feb 2004 19:30:59 -0000 Received: from unknown (HELO minotaur.apache.org) (209.237.227.194) by daedalus.apache.org with SMTP; 7 Feb 2004 19:30:59 -0000 Received: (qmail 7723 invoked by uid 1438); 7 Feb 2004 19:31:08 -0000 Date: 7 Feb 2004 19:31:08 -0000 Message-ID: <20040207193108.7722.qmail@minotaur.apache.org> From: mcconnell@apache.org To: avalon-cvs@apache.org Subject: cvs commit: avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl DefaultContainmentModelAssemblyHelper.java DefaultContainmentModelComponentHelper.java DefaultContainmentModelNavigationHelper.java DefaultContainmentModel.java Resources.properties ComponentModelContextHelper.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N mcconnell 2004/02/07 11:31:08 Modified: merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl DefaultContainmentModel.java Resources.properties Added: merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl DefaultContainmentModelAssemblyHelper.java DefaultContainmentModelComponentHelper.java DefaultContainmentModelNavigationHelper.java Removed: merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl ComponentModelContextHelper.java Log: Seperation of the navigation and assembly functions into helper classes. Revision Changes Path 1.28 +61 -573 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java Index: DefaultContainmentModel.java =================================================================== RCS file: /home/cvs/avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModel.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -r1.27 -r1.28 --- DefaultContainmentModel.java 7 Feb 2004 17:46:24 -0000 1.27 +++ DefaultContainmentModel.java 7 Feb 2004 19:31:08 -0000 1.28 @@ -29,9 +29,10 @@ import java.util.ArrayList; import java.util.Map; +import org.apache.avalon.logging.data.CategoriesDirective; + import org.apache.avalon.composition.data.BlockCompositionDirective; import org.apache.avalon.composition.data.BlockIncludeDirective; -import org.apache.avalon.logging.data.CategoriesDirective; import org.apache.avalon.composition.data.ContainmentProfile; import org.apache.avalon.composition.data.ComponentProfile; import org.apache.avalon.composition.data.NamedComponentProfile; @@ -314,344 +315,21 @@ } getLogger().debug( "assembly phase" ); + DefaultContainmentModelAssemblyHelper helper = + new DefaultContainmentModelAssemblyHelper( m_context, this ); + DeploymentModel[] models = m_context.getModelRepository().getModels(); for( int i=0; iAvalon Development Team * @version $Revision: 1.1 $ $Date: 2004/02/07 19:31:08 $ */ class DefaultContainmentModelAssemblyHelper { //------------------------------------------------------------------- // static //------------------------------------------------------------------- private static final Resources REZ = ResourceManager.getPackageResources( DefaultContainmentModelAssemblyHelper.class ); //------------------------------------------------------------------- // immutable state //------------------------------------------------------------------- private final ContainmentContext m_context; private final ContainmentModel m_model; //------------------------------------------------------------------- // constructor //------------------------------------------------------------------- public DefaultContainmentModelAssemblyHelper( ContainmentContext context, ContainmentModel model ) { m_context = context; m_model = model; } //------------------------------------------------------------------- // implementation //------------------------------------------------------------------- public void assembleModel( DeploymentModel model ) throws AssemblyException { if( null == model ) { throw new NullPointerException( "model" ); } if( model.isAssembled() ) { return; } else { if( model instanceof ComponentModel ) { assembleComponent( (ComponentModel) model ); } else { model.assemble(); } } } private void assembleComponent( ComponentModel model ) throws AssemblyException { ModelRepository repository = m_context.getModelRepository(); // // locate and assemble the component context handler // if( model.getContextModel() != null ) { ContextModel context = model.getContextModel(); Class clazz = context.getStrategyClass(); if( !clazz.getName().equals( ContextModel.DEFAULT_STRATEGY_CLASSNAME ) ) { if( null == context.getProvider() ) { try { StageDescriptor stage = new StageDescriptor( clazz.getName() ); DeploymentModel provider = findExtensionProvider( repository, stage ); context.setProvider( provider ); } catch( Throwable e ) { final String error = "Unable to assemble component: " + model + " due to a component context phase handler establishment failure."; throw new AssemblyException( error, e ); } } } } // // locate and resolve the stage providers // StageModel[] stages = model.getStageModels(); for( int i=0; iAvalon Development Team * @version $Revision: 1.1 $ $Date: 2004/02/07 19:31:08 $ */ class DefaultContainmentModelComponentHelper { //------------------------------------------------------------------- // static //------------------------------------------------------------------- private static final Resources REZ = ResourceManager.getPackageResources( DefaultContainmentModelComponentHelper.class ); //------------------------------------------------------------------- // immutable state //------------------------------------------------------------------- private final ContainmentContext m_context; private final ContainmentModel m_model; //------------------------------------------------------------------- // constructor //------------------------------------------------------------------- /** * Creation of a component context creation helper. * @param context the containment model context * @param model the containment model */ public DefaultContainmentModelComponentHelper( ContainmentContext context, ContainmentModel model ) { if( context == null ) { throw new NullPointerException( "context" ); } if( model == null ) { throw new NullPointerException( "model" ); } m_context = context; m_model = model; } //------------------------------------------------------------------- // implementation //------------------------------------------------------------------- /** * Creation of a new component model relative to a supplied profile. * * @param profile the component profile * @return the component model context */ public ComponentContext createComponentContext( final ComponentProfile profile ) throws ModelException { if( null == profile ) { throw new NullPointerException( "profile" ); } SystemContext system = m_context.getSystemContext(); final String name = profile.getName(); final String partition = m_model.getPartition(); LoggingManager logging = system.getLoggingManager(); CategoriesDirective categories = profile.getCategories(); if( null != categories ) { logging.addCategories( partition, categories ); } Logger logger = logging.getLoggerForCategory( partition + name ); DependencyGraph graph = m_context.getDependencyGraph(); ClassLoader classloader = m_context.getClassLoader(); final File home = new File( m_context.getHomeDirectory(), name ); final File temp = new File( m_context.getTempDirectory(), name ); try { Class base = classloader.loadClass( profile.getClassname() ); Type type = m_model.getClassLoaderModel().getTypeRepository().getType( base ); return new DefaultComponentContext( logger, name, system, classloader, graph, m_model, profile, type, base, home, temp, partition ); } catch( Throwable e ) { final String error = REZ.getString( "containment.deployment.create.error", m_model.getPath(), name ); throw new ModelException( error, e ); } } } 1.1 avalon/merlin/composition/impl/src/java/org/apache/avalon/composition/model/impl/DefaultContainmentModelNavigationHelper.java Index: DefaultContainmentModelNavigationHelper.java =================================================================== /* * Copyright 2004 Apache Software Foundation * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or * implied. * * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.avalon.composition.model.impl; import org.apache.avalon.composition.model.ContainmentModel; import org.apache.avalon.composition.model.ContainmentContext; import org.apache.avalon.composition.model.DeploymentModel; import org.apache.avalon.excalibur.i18n.ResourceManager; import org.apache.avalon.excalibur.i18n.Resources; /** * A utility class that assists in the location of a model relative * a supplied path. * * @author Avalon Development Team * @version $Revision: 1.1 $ $Date: 2004/02/07 19:31:08 $ */ class DefaultContainmentModelNavigationHelper { //------------------------------------------------------------------- // static //------------------------------------------------------------------- private static final Resources REZ = ResourceManager.getPackageResources( DefaultContainmentModelNavigationHelper.class ); //------------------------------------------------------------------- // immutable state //------------------------------------------------------------------- private final ContainmentContext m_context; private final ContainmentModel m_model; //------------------------------------------------------------------- // constructor //------------------------------------------------------------------- public DefaultContainmentModelNavigationHelper( ContainmentContext context, ContainmentModel model ) { m_context = context; m_model = model; } //------------------------------------------------------------------- // implementation //------------------------------------------------------------------- public DeploymentModel getModel( String path ) { ContainmentModel parent = m_context.getParentContainmentModel(); if( path.equals( "" ) ) { return m_model; } else if( path.startsWith( "/" ) ) { // // its a absolute reference that need to be handled by the // root container // if( null != parent ) { return parent.getModel( path ); } else { // // this is the root container thereforw the // path can be transfored to a relative reference // return m_model.getModel( path.substring( 1 ) ); } } else { // // its a relative reference in the form xxx/yyy/zzz // so if the path contains "/", then locate the token // proceeding the "/" (i.e. xxx) and apply the remainder // (i.e. yyy/zzz) as the path argument , otherwise, its // a local reference that we can pull from the model // repository // final String root = getRootName( path ); if( root.equals( ".." ) ) { // // its a relative reference in the form "../xxx/yyy" // in which case we simply redirect "xxx/yyy" to the // parent container // if( null != parent ) { final String remainder = getRemainder( root, path ); return parent.getModel( remainder ); } else { final String error = "Supplied path [" + path + "] references a container above the root container."; throw new IllegalArgumentException( error ); } } else if( root.equals( "." ) ) { // // its a path with a redundant "./xxx/yyy" which is // equivalent to "xxx/yyy" // final String remainder = getRemainder( root, path ); return m_model.getModel( remainder ); } else if( path.indexOf( "/" ) < 0 ) { // // its a path in the form "xxx" so we can use this // to lookup and return a local child // return m_context.getModelRepository().getModel( path ); } else { // // locate the relative root container, and apply // getModel to the container // DeploymentModel model = m_context.getModelRepository().getModel( root ); if( model != null ) { // // we have the sub-container so we can apply // the relative path after subtracting the name of // this container and the path seperator character // if( model instanceof ContainmentModel ) { ContainmentModel container = (ContainmentModel) model; final String remainder = getRemainder( root, path ); return container.getModel( remainder ); } else { final String error = "The path element [" + root + "] does not reference a containment model within [" + m_model + "]."; throw new IllegalArgumentException( error ); } } else { // // path contains a token that does not map to // known container // final String error = "Unable to locate a container with name [" + root + "] within the container [" + m_model + "]."; throw new IllegalArgumentException( error ); } } } } private String getRootName( String path ) { int n = path.indexOf( "/" ); if( n < 0 ) { return path; } else { return path.substring( 0, n ); } } private String getRemainder( String name, String path ) { return path.substring( name.length() + 1 ); } } --------------------------------------------------------------------- To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org For additional commands, e-mail: cvs-help@avalon.apache.org