mcconnell 2002/07/06 21:33:17
Added: assembly/src/java/org/apache/excalibur/meta/builder
ProfileBuilder.java ProfileCreator.java
XMLProfileCreator.java
assembly/src/java/org/apache/excalibur/meta/builder/doc-files
TypeBuilder.gif
Log:
Profile XML support
Revision Changes Path
1.1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/builder/ProfileBuilder.java
Index: ProfileBuilder.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.meta.builder;
import java.io.InputStream;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.data.Profile;
/**
* A ProfileBuilder is responsible for building {@link Profile}
* objects from Configuration objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/07/07 04:33:16 $
*/
public final class ProfileBuilder
{
private static final Resources REZ =
ResourceManager.getPackageResources( TypeBuilder.class );
private final ProfileCreator m_xmlProfileCreator = createXMLProfileCreator();
/**
* Build Profile from the XML descriptor format.
*
* @param classname The classname of Component
* @param classLoader the ClassLoader to load info from
* @return the created Type
* @throws Exception if an error occurs
*/
public Profile[] build( Type type, final ClassLoader classLoader )
throws Exception
{
final String xprofile =
type.getInfo().getImplementationKey().replace( '.', '/' ) + ".xprofile";
final InputStream inputStream =
classLoader.getResourceAsStream( xprofile );
final ProfileCreator creator = getXMLProfileCreator( xprofile );
if( null == inputStream )
{
return creator.createProfiles( type, new
DefaultConfiguration("profiles", null ) );
}
else
{
return creator.createProfiles( type, inputStream );
}
}
public Profile build( Type type, Configuration profile )
throws Exception
{
final ProfileCreator creator = getXMLProfileCreator( "implicit" );
return creator.createProfile( type, profile );
}
/**
* Utility to get xml info builder, else throw
* an exception if missing descriptor.
*
* @return the InfoCreator
*/
private ProfileCreator getXMLProfileCreator( final String classname )
throws Exception
{
if( null != m_xmlProfileCreator )
{
return m_xmlProfileCreator;
}
else
{
final String message =
REZ.getString( "builder.missing-xml-creator.error",
classname );
throw new Exception( message );
}
}
/**
* Utility to get XMLProfileCreator if XML files are on
* ClassPath.
*
* @return the XML {@link InfoCreator}
*/
private static ProfileCreator createXMLProfileCreator()
{
ProfileCreator xmlProfileCreator = null;
try
{
xmlProfileCreator = new XMLProfileCreator();
}
catch( final Exception e )
{
//Ignore it if ClassNot found due to no
//XML Classes on classpath
}
return xmlProfileCreator;
}
}
1.1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/builder/ProfileCreator.java
Index: ProfileCreator.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.meta.builder;
import org.apache.excalibur.meta.data.Profile;
import org.apache.excalibur.meta.info.Type;
import java.io.InputStream;
import org.apache.avalon.framework.configuration.Configuration;
/**
* Simple interface used to create {@link Profile}
* from stream. This abstraction was primarily created so
* that the Type could be built from non-XML
* sources and no XML classes need be in the classpath.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/07/07 04:33:16 $
*/
public interface ProfileCreator
{
/**
* Create a {@link Profile} from stream
*
* @param key the name of component type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link Type}
* @throws Exception
*/
Profile[] createProfiles( Type type, InputStream inputStream )
throws Exception;
/**
* Create a {@link Profile} from a configuration
*
* @param key the name of component type that we are looking up
* @param inputStream the stream that the resource is loaded from
* @return the newly created {@link Type}
* @throws Exception
*/
Profile[] createProfiles( Type type, Configuration config )
throws Exception;
Profile createProfile( Type type, Configuration config )
throws Exception;
}
1.1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/builder/XMLProfileCreator.java
Index: XMLProfileCreator.java
===================================================================
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE.txt file.
*/
package org.apache.excalibur.meta.builder;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Vector;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.framework.Version;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.excalibur.meta.info.Type;
import org.apache.excalibur.meta.data.Profile;
import org.apache.excalibur.meta.data.DefaultProfile;
import org.apache.excalibur.configuration.ContextFactory;
import org.xml.sax.InputSource;
/**
* Handles internalization of an XML based description of a {@link Type}
* from a Configuration object. The format for Configuration object
* is specified in the <a href="package-summary.html#external">package summary</a>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stephen McConnell</a>
* @version $Revision: 1.1 $ $Date: 2002/07/07 04:33:16 $
*/
public final class XMLProfileCreator
implements ProfileCreator
{
private static final Resources REZ =
ResourceManager.getPackageResources( XMLInfoCreator.class );
/**
* Create a {@link Type} object for specified
* classname, loaded from specified {@link InputStream}.
*
* @param implementationKey The classname of Component
* @param inputStream the InputStream to load Type from
* @return the created Type
* @throws ConfigurationException if an error occurs
*/
public Profile[] createProfiles( Type type, InputStream inputStream )
throws Exception
{
final InputSource input = new InputSource( inputStream );
final Configuration configuration = ConfigurationBuilder.build( input );
return createProfiles( type, configuration );
}
/**
* Create a {@link Profile} object for specified classname from
* specified configuration data.
*
* @param classname The classname of Component
* @param info the Type configuration
* @return the created Type
* @throws ConfigurationException if an error occurs
*/
public Profile[] createProfiles( Type type, final Configuration info )
throws Exception
{
Vector vector = new Vector();
Configuration[] profiles = info.getChildren("component");
if( profiles.length == 0 )
{
//
// build a default profile
//
return new Profile[]{
new DefaultProfile( null, null, null, null, type, Profile.IMPLICIT )
};
}
for( int i=0; i<profiles.length; i++ )
{
vector.add( buildProfile( type, profiles[i], Profile.PACKAGED ) );
}
return (Profile[]) vector.toArray( new Profile[0] );
}
public Profile createProfile( Type type, Configuration config )
throws Exception
{
return buildProfile( type, config, Profile.EXPLICIT );
}
private Profile buildProfile( Type type, Configuration profile, int mode )
throws Exception
{
String name = null;
if( mode == Profile.EXPLICIT )
{
name = profile.getAttribute("name");
}
Parameters params = Parameters.fromConfiguration(
profile.getChild("parameters") );
Configuration config = profile.getChild("configuration");
Context context = ContextFactory.createContextFromConfiguration(
null, profile.getChild("context") );
return new DefaultProfile( name, params, config, context, type, mode );
}
}
1.1
jakarta-avalon-excalibur/assembly/src/java/org/apache/excalibur/meta/builder/doc-files/TypeBuilder.gif
<<Binary file>>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>