crafterm 2002/10/16 09:20:39
Added: xfc/src/java/org/apache/excalibur/xfc/modules/ecm ECM.java
ECMGenerator.java ECMSerializer.java
HandlerAnalyzer.java package.html
xfc/src/java/org/apache/excalibur/xfc/modules/fortress
Fortress.java FortressGenerator.java
FortressSerializer.java HandlerMapper.java
package.html
Log:
Started cleaning up and refactoring xfc code
* Split up Fortress and ECM modules into small components so
they are easier to work with.
* Adjusted test rigs and entry point classes to work with
the split.
Revision Changes Path
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ecm/ECM.java
Index: ECM.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.ecm;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.xfc.Module;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.modules.Constants;
/**
* <code>ECM</code> module implementation.
*
* <p>
* This implementation supports ECM style role files. ie:
*
* <pre>
* <role-list>
* <role name="..." shorthand="..." default-class="..."/>
* </role-list>
* </pre>
*
* and ECM style configuration files. ie:
*
* <pre>
* <shorthand>
* <config-data/>
* </shorthand>
* </pre>
* </p>
*
* <p>
* The input context should be the name of the roles file, followed
* by the name of the configuration file, separated by a colon.
* eg: <code>definitions.roles:config.xconf</code>
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: ECM.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class ECM extends AbstractLogEnabled
implements Module
{
private final ECMGenerator m_generator = new ECMGenerator();
private final ECMSerializer m_serializer = new ECMSerializer();
/**
* Generates a {@link Model} based on an a given ECM style
* Context.
*
* <p>
* The specified Context string names the ECM role and
* xconf files, separated by a ':' character. ie:
* <code>ecm.roles:ecm.xconf</code>
* </p>
*
* @param context a <code>String</code> context value
* @return a {@link Model} instance
* @exception Exception if an error occurs
*/
public Model generate( final String context )
throws Exception
{
return m_generator.generate( validateContext( context ) );
}
/**
* Serializes a {@link Model} definition, ECM style, to an
* output context.
*
* <p>
* The specified Context string names the ECM role and
* xconf files, separated by a ':' character. ie:
* <code>ecm.roles:ecm.xconf</code>
* </p>
*
* @param model a {@link Model} instance
* @param context ECM output Context
* @exception Exception if an error occurs
*/
public void serialize( final Model model, final String context )
throws Exception
{
m_serializer.serialize( model, validateContext( context ) );
}
/**
* Helper method to validate the input & output context's
* given to this module.
*
* @param context a <code>String</code> context value
* @return the validated context string
* @exception Exception if an error occurs
*/
private String validateContext( final String context )
throws Exception
{
if ( context.indexOf( Constants.CONTEXT_SEPARATOR ) == -1 )
throw new IllegalArgumentException(
"Module requires the role and xconf filename " +
"separated by a '" + Constants.CONTEXT_SEPARATOR + "' character"
);
return context;
}
/**
* Enables logging on this component, including internal
* components constructed using composition.
*
* @param logger a logger instance
*/
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
m_generator.enableLogging( logger );
m_serializer.enableLogging( logger );
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ecm/ECMGenerator.java
Index: ECMGenerator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.ecm;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.Constants;
/**
* ECM module generation class. This class contains the implementation
* of the <code>generate</code> method defined in {@link ECM}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: ECMGenerator.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class ECMGenerator extends AbstractLogEnabled
implements Constants
{
protected final DefaultConfigurationBuilder m_builder =
new DefaultConfigurationBuilder();
/**
* Generates a {@link Model} based on an a given ECM style
* Context.
*
* <p>
* The specified Context string names the ECM role and
* xconf files, separated by a ':' character. ie:
* <code>ecm.roles:ecm.xconf</code>
* </p>
*
* @param context a <code>String</code> context value
* @return a {@link Model} instance
* @exception Exception if an error occurs
*/
public Model generate( final String context )
throws Exception
{
Model model = new Model();
// locate all roles
Configuration[] roles = getRoles( getRoleFile( context ) );
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Identified total of " + roles.length + " roles" );
}
// for each role create a type object
for ( int i = 0; i < roles.length; ++i )
{
model.addRoleRef( buildRoleRef( roles[i] ) );
}
// locate all component instances
Configuration[] instances = getInstanceList( getConfigurationFile( context )
);
if ( getLogger().isDebugEnabled() )
{
getLogger().debug(
"Identified total of " + instances.length + " component instances"
);
}
for ( int i = 0; i < instances.length; ++i )
{
model.addInstance( buildInstance( instances[i], model ) );
}
// finished
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Model built" );
}
return model;
}
/**
* Helper method for obtaining the Role file.
*
* @param context a <code>String</code> value
* @return a <code>File</code> value
*/
private File getRoleFile( final String context )
{
int i = context.indexOf( CONTEXT_SEPARATOR );
return new File( context.substring( 0, i ) );
}
/**
* Helper method for obtaining the Configuration file.
*
* @param context a <code>String</code> value
* @return a <code>File</code> value
*/
private File getConfigurationFile( final String context )
{
int i = context.indexOf( CONTEXT_SEPARATOR );
return new File( context.substring( i + 1 ) );
}
/**
* Helper method for obtaining the roles defined in
* a particular input file.
*
* @param input a <code>File</code> value
* @return a <code>Configuration[]</code> value
* @exception Exception if an error occurs
*/
private Configuration[] getRoles( final File input )
throws Exception
{
Configuration config = m_builder.buildFromFile( input );
return config.getChildren( "role" );
}
/**
* Helper method for obtaining the instances defined in
* a particular input file
*
* @param input a <code>File</code> value
* @return a <code>Configuration[]</code> value
* @exception Exception if an error occurs
*/
private Configuration[] getInstanceList( final File input )
throws Exception
{
Configuration config = m_builder.buildFromFile( input );
return config.getChildren();
}
// ROLE GENERATION METHODS
/**
* Method to construct a {@link RoleRef} object from
* a Role definition.
*
* @param role role information
* @return a {@link RoleRef} instance
* @exception Exception if an error occurs
*/
protected RoleRef buildRoleRef( final Configuration role )
throws Exception
{
if ( isComponentSelectorRole( role ) ) // component selector definition
{
return buildMultipleComponentRoleRef( role );
}
// single component definition
return buildSingleComponentRoleRef( role );
}
/**
* Method to determine whether the given role definition entails
* a ComponentSelector style definition or not.
*
* @param role a <code>Configuration</code> value
* @return a <code>boolean</code> value
*/
protected boolean isComponentSelectorRole( final Configuration role )
{
// if there are any 'hint's then we have a component selector
return role.getChildren( HINT ).length > 0;
}
/**
* Method for constructing a {@link RoleRef} object from a single
* component role definition.
*
* @param role a <code>Configuration</code> value
* @return a {@link RoleRef} value
* @exception Exception if an error occurs
*/
protected RoleRef buildSingleComponentRoleRef( final Configuration role )
throws Exception
{
Definition def =
new Definition(
role.getAttribute( DEFAULT ),
role.getAttribute( SHORTHAND ),
HandlerAnalyzer.getHandler( role.getAttribute( DEFAULT ) )
);
return new RoleRef( role.getAttribute( NAME ), role.getAttribute( SHORTHAND
), def );
}
/**
* Method for constructing a {@link RoleRef} object from a multiple
* component role definition (ie. component selector).
*
* @param role a <code>Configuration</code> value
* @return a {@link RoleRef} value
* @exception Exception if an error occurs
*/
protected RoleRef buildMultipleComponentRoleRef( final Configuration role )
throws Exception
{
Configuration[] hints = role.getChildren( HINT );
Definition[] definitions = new Definition[ hints.length ];
for ( int i = 0; i < hints.length; ++i )
{
definitions[i] =
new Definition(
hints[i].getAttribute( CLASS ),
hints[i].getAttribute( SHORTHAND ),
HandlerAnalyzer.getHandler( hints[i].getAttribute( CLASS ) )
);
}
return new RoleRef(
role.getAttribute( NAME ), role.getAttribute( SHORTHAND ), definitions
);
}
// INSTANCE GENERATION METHODS
protected Instance buildInstance( final Configuration i, final Model model )
throws Exception
{
if ( i.getName().equals( COMPONENT ) )
{
Configuration[] kids = i.getChildren( COMPONENT_INSTANCE );
if ( kids.length > 0 )
{
// build non-role component selector
return buildNonRoleComponentSelectorInstance( i );
}
// build non-role component
return buildNonRoleComponentInstance( i );
}
if ( isComponentSelectorXConf( i.getName(), model ) )
{
// build multi role based component
return buildRoleComponentSelectorInstance( i );
}
// build single role based component
return buildRoleComponentInstance( i );
}
/**
* Helper method to determine whether the given shorthand corresponds
* to a component selector based role reference object.
*
* @param shorthand shorthand name
* @param model a {@link Model} instance
* @return true if this shorthand refers to a component selector role,
* false otherwise.
* @exception Exception if an error occurs
*/
private boolean isComponentSelectorXConf(
final String shorthand, final Model model
)
throws Exception
{
// check if shorthand corresponds to ECM
RoleRef ref = model.findByShorthand( shorthand );
if ( ref != null && ref.getProviders().length > 1 )
{
return true;
}
return false;
}
/**
* Builds an {@link Instance} object from a given xconf
* configuration framgment, for component selector xconf definitions
* that do not use RoleManager.
*
* @param i a <code>Configuration</code> instance
* @return an {@link Instance} instance
* @exception Exception if an error occurs
*/
private Instance buildNonRoleComponentSelectorInstance(
final Configuration i
)
throws Exception
{
final Configuration[] kids = i.getChildren( COMPONENT_INSTANCE );
final Instance[] subinstances = new Instance[ kids.length ];
for ( int j = 0; j < kids.length; ++j )
{
subinstances[j] = buildSubInstance( kids[j] );
}
return new Instance(
ECS, i.getAttribute( ROLE ), subinstances, SINGLETON
);
}
/**
* Builds an {@link Instance} object from a given xconf
* Configuration fragment, for single component definitions that
* do not use the role manager.
*
* @param i a <code>Configuration</code> instance
* @return an {@link Instance} instance
* @exception Exception if an error occurs
*/
private Instance buildNonRoleComponentInstance( final Configuration i )
throws Exception
{
return new Instance(
i.getChildren(),
i.getAttribute( CLASS, null ),
i.getAttribute( ROLE ),
HandlerAnalyzer.getHandler( i.getAttribute( CLASS, null ) )
);
}
/**
* Builds an {@link Instance} object from a given xconf
* Configuration fragment, for single components using rolemanager.
*
* @param i a <code>Configuration</code> instance
* @return an {@link Instance} instance
* @exception Exception if an error occurs
*/
private Instance buildRoleComponentInstance( final Configuration i )
throws Exception
{
String cl = i.getAttribute( CLASS, null );
return new Instance(
i.getName(),
i.getChildren(),
cl, cl == null ? null : HandlerAnalyzer.getHandler( cl )
);
}
/**
* Builds an {@link Instance} object from a given xconf Configuration
* fragment, for component selector definitions that use rolemanager.
*
* @param i a <code>Configuration</code> instance
* @return an {@link Instance} instance
*/
private Instance buildRoleComponentSelectorInstance( final Configuration i )
{
// get the subinstances
Configuration[] kids = i.getChildren();
Instance[] subinstances = new Instance[ kids.length ];
for ( int j = 0; j < kids.length; ++j )
{
subinstances[j] =
new Instance( kids[j].getName(), kids[j].getChildren(), null, null );
}
// create the root instance
return new Instance( i.getName(), subinstances );
}
/**
* Helper method for buiding an {@link Instance} object from a
* configuration snippet that refers to the component definitions
* inside a component selector definitino that isn't using rolemanager.
*
* @param i a <code>Configuration</code> instance
* @return an {@link Instance} instance
* @exception Exception if an error occurs
*/
private Instance buildSubInstance( final Configuration i )
throws Exception
{
String cl = i.getAttribute( CLASS );
return new Instance(
i.getAttribute( NAME ),
i.getChildren(),
cl, cl == null ? null : HandlerAnalyzer.getHandler( cl )
);
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ecm/ECMSerializer.java
Index: ECMSerializer.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.ecm;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.Constants;
/**
* ECM module serialization class. This class contains the implementation
* of the <code>serialize</code> method defined in {@link ECM}.
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: ECMSerializer.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class ECMSerializer extends AbstractLogEnabled
implements Constants
{
protected final DefaultConfigurationSerializer m_serializer;
/**
* Constructor, initializes serializer.
*/
public ECMSerializer()
{
m_serializer = new DefaultConfigurationSerializer();
m_serializer.setIndent( true );
}
/**
* Serializes a {@link Model} definition, ECM style, to an
* output context.
*
* @param model a {@link Model} instance
* @param context ECM output Context
* @exception Exception if an error occurs
*/
public void serialize( final Model model, final String context )
throws Exception
{
// create the role file
RoleRef[] rolerefs = model.getDefinitions();
DefaultConfiguration roles = new DefaultConfiguration( ROLELIST, "" );
// for each type object generate a roles file entry
for ( int i = 0; i < rolerefs.length; ++i )
{
roles.addChild( buildRole( rolerefs[i] ) );
}
m_serializer.serializeToFile( getRoleFile( context ), roles );
// create the xconf file
Instance[] instances = model.getInstances();
DefaultConfiguration xconf = new DefaultConfiguration( "xconf", "" );
// for each instance object generate an xconf file entry
for ( int j = 0; j < instances.length; ++j )
{
xconf.addChild( buildXConf( instances[j] ) );
}
m_serializer.serializeToFile( getConfigurationFile( context ), xconf );
}
/**
* Helper method for obtaining the Role file.
*
* @param context a <code>String</code> value
* @return a <code>File</code> value
*/
protected File getRoleFile( final String context )
{
int i = context.indexOf( CONTEXT_SEPARATOR );
return new File( context.substring( 0, i ) );
}
/**
* Helper method for obtaining the Configuration file.
*
* @param context a <code>String</code> value
* @return a <code>File</code> value
*/
protected File getConfigurationFile( final String context )
{
int i = context.indexOf( CONTEXT_SEPARATOR );
return new File( context.substring( i + 1 ) );
}
// ROLE GENERATION METHODS
/**
* Method to build a Role definition from a {@link RoleRef}
* object.
*
* @param roleref a {@link RoleRef} instance
* @return role definition as a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
protected Configuration buildRole( final RoleRef roleref )
throws Exception
{
Definition[] defs = roleref.getProviders();
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Building role for model: " + roleref.getRole() );
}
if ( roleref.getProviders().length > 1 )
{
return buildMultipleComponentRole( roleref );
}
return buildSingleComponentRole( roleref );
}
/**
* Builds a multiple component Role definition (ie ComponentSelector based)
* from a {@link RoleRef} definition.
*
* @param ref a {@link RoleRef} instance
* @return a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
protected Configuration buildMultipleComponentRole( final RoleRef ref )
throws Exception
{
DefaultConfiguration role = new DefaultConfiguration( ROLE, "" );
Definition[] defs = ref.getProviders();
for ( int i = 0; i < defs.length; ++i )
{
DefaultConfiguration hint = new DefaultConfiguration( HINT, "" );
hint.setAttribute( SHORTHAND, defs[i].getShorthand() );
hint.setAttribute( CLASS, defs[i].getDefaultClass() );
role.addChild( hint );
}
role.setAttribute( NAME, ref.getRole() );
role.setAttribute( SHORTHAND, ref.getShorthand() );
role.setAttribute( DEFAULT, ECS );
return role;
}
/**
* Builds a single component Role definition from a {@link RoleRef}
* definition.
*
* @param ref a {@link RoleRef} instance
* @return a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
protected Configuration buildSingleComponentRole( final RoleRef ref )
throws Exception
{
DefaultConfiguration role = new DefaultConfiguration( ROLE, "" );
Definition[] defs = ref.getProviders();
// there is only 1 provider, use index 0 directly
role.setAttribute( NAME, ref.getRole() );
role.setAttribute( SHORTHAND, ref.getShorthand() );
role.setAttribute( DEFAULT, defs[0].getDefaultClass() );
return role;
}
// XCONF GENERATION METHODS
/**
* Builds a Configuration object from an instance declaration
*
* @param i an {@link Instance} instance
* @return a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
private Configuration buildXConf( final Instance i )
throws Exception
{
// has shorthand
if ( i.getShorthand() != null )
{
return buildSingleRoleXConf( i );
}
if ( i.getSubInstances() == null )
{
// has no shorthand, no subinstances
return buildNonRoleSingleXConf( i );
}
// has no shorthand, has subinstances
return buildNonRoleMultiXConf( i );
// return buildMultiRoleXConf();
}
/**
* Builds a Configuration object from an Instance declaration,
* referring to a single role based component.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildSingleRoleXConf( final Instance i )
throws Exception
{
DefaultConfiguration conf = new DefaultConfiguration( i.getShorthand(), "" );
if ( i.getConfiguration() != null )
{
Configuration[] kids = i.getConfiguration();
for ( int j = 0; j < kids.length; ++j )
{
conf.addChild( kids[j] );
}
}
if ( i.getClassImpl() != null )
{
conf.setAttribute( CLASS, i.getClassImpl() );
}
return conf;
}
/**
* Builds a Configuration object from an Instance declaration,
* referring to a single non role based component.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildNonRoleSingleXConf( final Instance i )
throws Exception
{
DefaultConfiguration conf = new DefaultConfiguration( COMPONENT, "" );
conf.setAttribute( ROLE, i.getRole() );
conf.setAttribute( CLASS, i.getClassImpl() );
if ( i.getConfiguration() != null )
{
Configuration[] kids = i.getConfiguration();
for ( int j = 0; j < kids.length; ++j )
{
conf.addChild( kids[j] );
}
}
return conf;
}
/**
* Builds a Configuration object from an Instance declaration,
* referring to a non role based component selector component.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildNonRoleMultiXConf( final Instance i )
throws Exception
{
DefaultConfiguration conf = new DefaultConfiguration( COMPONENT, "" );
conf.setAttribute( ROLE, i.getRole() );
conf.setAttribute( CLASS, ECS );
Instance[] subs = i.getSubInstances();
for ( int j = 0; j < subs.length; ++j )
{
DefaultConfiguration child =
new DefaultConfiguration( COMPONENT_INSTANCE, "" );
child.setAttribute( CLASS, subs[j].getClassImpl() );
child.setAttribute( NAME, subs[j].getShorthand() );
if ( subs[j].getConfiguration() != null )
{
Configuration[] kids = subs[j].getConfiguration();
for ( int k = 0; k < kids.length; ++k )
{
child.addChild( kids[k] );
}
}
conf.addChild( child );
}
return conf;
}
/**
* Describe <code>buildRoleMultiXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildRoleMultiXConf( final Instance i )
throws Exception
{
// REVISIT
throw new UnsupportedOperationException( "Not yet implemented" );
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ecm/HandlerAnalyzer.java
Index: HandlerAnalyzer.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.ecm;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.Constants;
/**
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: HandlerAnalyzer.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public final class HandlerAnalyzer implements Constants
{
// Avalon Framework and Excalibur Pool markers
private static final String SINGLETHREADED =
"org.apache.avalon.framework.thread.SingleThreaded";
private static final String THREADSAFE =
"org.apache.avalon.framework.thread.ThreadSafe";
private static final String POOLABLE =
"org.apache.avalon.excalibur.pool.Poolable";
private static final String RECYCLABLE =
"org.apache.avalon.excalibur.pool.Recyclable";
private static final String COMPONENT_INSTANCE = "component-instance";
private static Map m_handlers = new HashMap();
// Normalized mappings for ECM lifestyles
static
{
// ECM -> Normalized
m_handlers.put( SINGLETHREADED, TRANSIENT );
m_handlers.put( POOLABLE, POOLED );
m_handlers.put( RECYCLABLE, POOLED );
m_handlers.put( THREADSAFE, SINGLETON );
}
/**
* Method for extracting a role's ComponentHandler name,
* ECM style. ECM roles don't define ComponentHandlers explicitly,
* so some simple class analysis is made in this method to
* try to ascertain which handler has been chosed by the
* implementor.
*
* @param classname class name as a <code>String</code> value
* @return normalized handler name
* @exception Exception if an error occurs
*/
public static String getHandler( final String classname )
throws Exception
{
try
{
Class clazz = Class.forName( classname );
String handler = getNormalizedHandlerName( clazz );
if ( handler != null )
{
return handler;
}
/*
if ( getLogger().isInfoEnabled() )
{
getLogger().info(
"No known component handler discovered on " + clazz.getName() +
", defaulting to 'transient'"
);
}
*/
return TRANSIENT;
}
catch ( ClassNotFoundException e )
{
/*
if ( getLogger().isWarnEnabled() )
{
getLogger().warn(
"Could not load Class " + classname +
" for Component Handler analysis, defaulting to 'transient'"
);
}
*/
/* leave out for the moment
if ( getLogger().isDebugEnabled() )
{
getLogger().debug( "Exception: ", e );
}
*/
return TRANSIENT;
}
}
/**
* Method to find out the normalized handler name for a given Class
* object. It checks all interfaces implemented by the given Class,
* and all subinterfaces of those interfaces, recursively, until
* either a known component marker is found, or all interfaces
* are exhausted.
*
* @param interfaze a <code>Class</code> instance
* @return normalized handler name
*/
private static String getNormalizedHandlerName( final Class interfaze )
{
// get all interfaces implemented by this Class
Class[] interfaces = interfaze.getInterfaces();
for ( int i = 0; i < interfaces.length; ++i )
{
// check if this interface is a known component marker
if ( m_handlers.containsKey( interfaces[i].getName() ) )
{
return (String) m_handlers.get( interfaces[i].getName() );
}
// if it's unknown, check for any subinterfaces and recurse
String handler = getNormalizedHandlerName( interfaces[i] );
// if a subinterface is known, return
if ( handler != null )
return handler;
}
// all interfaces unknown
return null;
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/ecm/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body>
<p>
<b>ECM Module</b>, ECM Module implementation.
</p>
<p>
This package contains the ECM Module implementation.
</p>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
<!-- Put @see and @since tags down here. -->
</body>
</html>
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/fortress/Fortress.java
Index: Fortress.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.fortress;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;
import org.apache.excalibur.xfc.Module;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.modules.Constants;
/**
* <code>Fortress</code> module implementation.
*
* <p>
* Fortress style role files are an extension to the ECM model.
* This implementation supports Fortress style role files. ie:
*
* <pre>
* <role-list>
* <role name="">
* <component shorthand="..." class="..." handler="..."/>
* </role>
* </role-list>
* </pre>
* </p>
*
* <p>
* The input context should be the name of the roles file, followed
* by the name of the configuration file, separated by a colon.
* eg: definitions.roles:config.xconf
* </p>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: Fortress.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class Fortress extends AbstractLogEnabled
implements Module
{
private final FortressGenerator m_generator = new FortressGenerator();
private final FortressSerializer m_serializer = new FortressSerializer();
/**
* Generates a {@link Model} based on an a given ECM style
* Context.
*
* <p>
* The specified Context string names the Fortress nrole and
* xconf files, separated by a ':' character. ie:
* <code>fortress.roles:fortress.xconf</code>
* </p>
*
* @param context a <code>String</code> context value
* @return a {@link Model} instance
* @exception Exception if an error occurs
*/
public Model generate( final String context )
throws Exception
{
return m_generator.generate( validateContext( context ) );
}
/**
* Serializes a {@link Model} definition, Fortress style, to an
* output context.
*
* @param model a {@link Model} instance
* @param context Fortress output Context
* @exception Exception if an error occurs
*/
public void serialize( final Model model, final String context )
throws Exception
{
m_serializer.serialize( model, validateContext( context ) );
}
/**
* Helper method to validate the input & output context's
* given to this module.
*
* @param context a <code>String</code> context value
* @return the validated context string
* @exception Exception if an error occurs
*/
private String validateContext( final String context )
throws Exception
{
if ( context.indexOf( Constants.CONTEXT_SEPARATOR ) == -1 )
throw new IllegalArgumentException(
"Fortress Module requires the role and xconf filename " +
"separated by a '" + Constants.CONTEXT_SEPARATOR + "' character"
);
return context;
}
/**
* Enables logging on this component, including internal
* components constructed using composition.
*
* @param logger a logger instance
*/
public void enableLogging( final Logger logger )
{
super.enableLogging( logger );
m_generator.enableLogging( logger );
m_serializer.enableLogging( logger );
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/fortress/FortressGenerator.java
Index: FortressGenerator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.fortress;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.ecm.ECMGenerator;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: FortressGenerator.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class FortressGenerator extends ECMGenerator
{
// ROLE GENERATION METHODS
/**
* Method to determine whether the given role definition entails
* a ComponentSelector style definition or not.
*
* @param role a <code>Configuration</code> value
* @return a <code>boolean</code> value
*/
protected boolean isComponentSelectorRole( final Configuration role )
{
// if we have more than 1 'component'we have a component selector
return role.getChildren( COMPONENT ).length > 1;
}
/**
* Method to create a {@link RoleRef} object for a Configuration
* definition that defines a single component based role.
*
* @param role a <code>Configuration</code> definition of a role
* @return a {@link RoleRef} instance
* @exception Exception if an error occurs
*/
protected RoleRef buildSingleComponentRoleRef( final Configuration role )
throws Exception
{
Configuration config = role.getChild( COMPONENT );
Definition definition =
new Definition(
config.getAttribute( CLASS ),
config.getAttribute( SHORTHAND ),
HandlerMapper.getHandler( config.getAttribute( HANDLER ) )
);
return new RoleRef(
role.getAttribute( NAME ), config.getAttribute( SHORTHAND ), definition
);
}
/**
* Method to construct a {@link RoleRef} object from a Configuration
* definition that defines a multiple component based role.
*
* @param role a <code>Configuration</code> definition of a role
* @return a {@link RoleRef} instance
* @exception Exception if an error occurs
*/
protected RoleRef buildMultipleComponentRoleRef( final Configuration role )
throws Exception
{
Configuration[] hints = role.getChildren( COMPONENT );
Definition[] definitions = new Definition[ hints.length ];
for ( int i = 0; i < hints.length; ++i )
{
definitions[i] =
new Definition(
hints[i].getAttribute( CLASS ),
hints[i].getAttribute( SHORTHAND ),
HandlerMapper.getHandler( hints[i].getAttribute( HANDLER ) )
);
}
return new RoleRef( role.getAttribute( NAME ), "UNKNOWN", definitions );
}
// INSTANCE GENERATION METHODS
/**
* Builds an Instance object from a Configuration snippet.
*
* @param i a <code>Configuration</code> value
* @return an <code>Instance</code> value
* @exception Exception if an error occurs
*/
protected Instance buildInstance( final Configuration i )
throws Exception
{
if ( i.getName().equals( COMPONENT ) )
{
// build non-role component
return buildNonRoleComponentInstance( i );
}
// build role based component
return buildRoleComponentInstance( i );
}
/**
* Builds an Instance object from a Configuration snippet,
* desribing a non-role manager component.
*
* @param i a <code>Configuration</code> value
* @return an <code>Instance</code> value
* @exception Exception if an error occurs
*/
private Instance buildNonRoleComponentInstance( final Configuration i )
throws Exception
{
return new Instance(
i.getChildren(),
i.getAttribute( CLASS ),
i.getAttribute( ROLE ),
null
);
}
/**
* Builds an Instance object from a Configuration snippet,
* describing a role manager based component.
*
* @param i a <code>Configuration</code> value
* @return an <code>Instance</code> value
* @exception Exception if an error occurs
*/
private Instance buildRoleComponentInstance( final Configuration i )
throws Exception
{
return new Instance(
i.getName(),
i.getChildren(),
null,
null
);
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/fortress/FortressSerializer.java
Index: FortressSerializer.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.fortress;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.ecm.ECMSerializer;
/**
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: FortressSerializer.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public class FortressSerializer extends ECMSerializer
{
/**
* Serializes a {@link Model} definition, ECM style, to an
* output context.
*
* @param model a {@link Model} instance
* @param context ECM output Context
* @exception Exception if an error occurs
*/
public void serialize( final Model model, final String context )
throws Exception
{
// create the role file
RoleRef[] rolerefs = model.getDefinitions();
DefaultConfiguration roles = new DefaultConfiguration( "role-list", "" );
// for each type object generate a roles file entry
for ( int i = 0; i < rolerefs.length; ++i )
{
roles.addChild( buildRole( rolerefs[i] ) );
}
m_serializer.serializeToFile( getRoleFile( context ), roles );
// create the xconf file
Instance[] instances = model.getInstances();
DefaultConfiguration xconf = new DefaultConfiguration( "xconf", "" );
// for each instance object generate an xconf file entry
for ( int j = 0; j < instances.length; ++j )
{
Configuration[] xconfs = buildXConf( instances[j] );
for ( int k = 0; k < xconfs.length; ++k )
{
xconf.addChild( xconfs[k] );
}
}
m_serializer.serializeToFile( getConfigurationFile( context ), xconf );
}
// ROLE GENERATION METHODS
/**
* Builds a single component Role definition from a {@link RoleRef}
* definition.
*
* @param ref a {@link RoleRef} instance
* @return a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
protected Configuration buildSingleComponentRole( final RoleRef ref )
throws Exception
{
// single role definitions are the same as multiple definitions
return buildMultipleComponentRole( ref );
}
/**
* Builds a multiple component Role definition (ie ComponentSelector based)
* from a {@link RoleRef} definition.
*
* @param ref a {@link RoleRef} instance
* @return a <code>Configuration</code> instance
* @exception Exception if an error occurs
*/
protected Configuration buildMultipleComponentRole( final RoleRef ref )
throws Exception
{
DefaultConfiguration role = new DefaultConfiguration( ROLE, "" );
Definition[] defs = ref.getProviders();
for ( int i = 0; i < defs.length; ++i )
{
DefaultConfiguration hint = new DefaultConfiguration( COMPONENT, "" );
hint.setAttribute( SHORTHAND, defs[i].getShorthand() );
hint.setAttribute( CLASS, defs[i].getDefaultClass() );
hint.setAttribute(
HANDLER, HandlerMapper.getHandler( defs[i].getHandler() )
);
role.addChild( hint );
}
role.setAttribute( NAME, ref.getRole() );
return role;
}
// XCONF GENERATION METHODS
/**
* Describe <code>buildXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration[]</code> value
* @exception Exception if an error occurs
*/
private Configuration[] buildXConf( final Instance i )
throws Exception
{
if ( i.getShorthand() != null )
{
if ( i.getSubInstances() == null )
{
// has shorthand, single component
return new Configuration[] { buildSingleRoleXConf( i ) };
}
// has shorthand, multi component
return buildMultiRoleXConf( i );
}
if ( i.getSubInstances() == null )
{
// has no shorthand, no subinstances
return new Configuration[] { buildNonRoleSingleXConf( i ) };
}
// has no shorthand, has subinstances
return buildNonRoleMultiXConf( i );
}
/**
* Describe <code>buildSingleRoleXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildSingleRoleXConf( final Instance i )
throws Exception
{
DefaultConfiguration conf = new DefaultConfiguration( i.getShorthand(), "" );
if ( i.getConfiguration() != null )
{
Configuration[] kids = i.getConfiguration();
for ( int j = 0; j < kids.length; ++j )
{
conf.addChild( kids[j] );
}
}
conf.setAttribute( ID, i.getShorthand() );
return conf;
}
/**
* Describe <code>buildMultiRoleXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration[]</code> value
* @exception Exception if an error occurs
*/
private Configuration[] buildMultiRoleXConf( final Instance i )
throws Exception
{
Instance[] subinstances = i.getSubInstances();
Configuration[] xconf = new Configuration[ subinstances.length ];
for ( int j = 0; j < subinstances.length; ++j )
{
xconf[j] = buildSingleRoleXConf( subinstances[j] );
}
return xconf;
}
/**
* Describe <code>buildNonRoleSingleXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration</code> value
* @exception Exception if an error occurs
*/
private Configuration buildNonRoleSingleXConf( final Instance i )
throws Exception
{
DefaultConfiguration conf = new DefaultConfiguration( COMPONENT, "" );
conf.setAttribute( ROLE, i.getRole() );
conf.setAttribute( CLASS, i.getClassImpl() );
conf.setAttribute( HANDLER, HandlerMapper.getHandler( i.getHandler() ) );
conf.setAttribute( ID, "UNKNOWN" );
if ( i.getConfiguration() != null )
{
Configuration[] kids = i.getConfiguration();
for ( int j = 0; j < kids.length; ++j )
{
conf.addChild( kids[j] );
}
}
return conf;
}
/**
* Describe <code>buildNonRoleMultiXConf</code> method here.
*
* @param i an <code>Instance</code> value
* @return a <code>Configuration[]</code> value
*/
private Configuration[] buildNonRoleMultiXConf( final Instance i )
{
Instance[] subs = i.getSubInstances();
Configuration[] xconfs = new Configuration[ subs.length ];
for ( int j = 0; j < subs.length; ++j )
{
DefaultConfiguration conf = new DefaultConfiguration( COMPONENT, "" );
conf.setAttribute( ROLE, i.getRole() );
conf.setAttribute( CLASS, subs[j].getClassImpl() );
conf.setAttribute( HANDLER, HandlerMapper.getHandler(
subs[j].getHandler() ) );
conf.setAttribute( ID, subs[j].getShorthand() );
if ( subs[j].getConfiguration() != null )
{
Configuration[] kids = subs[j].getConfiguration();
for ( int k = 0; k < kids.length; ++k )
{
conf.addChild( kids[k] );
}
}
xconfs[j] = conf;
}
return xconfs;
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/fortress/HandlerMapper.java
Index: HandlerMapper.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.modules.fortress;
import java.util.HashMap;
import java.util.Map;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Instance;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.Constants;
/**
* Simple class providing normalized mappings for Fortress Component
* handler names.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: HandlerMapper.java,v 1.1 2002/10/16 16:20:38 crafterm Exp $
*/
public final class HandlerMapper implements Constants
{
// ComponentHandler constants
private static final String FACTORY =
"org.apache.excalibur.fortress.handler.FactoryComponentHandler";
private static final String PERTHREAD =
"org.apache.excalibur.fortress.handler.PerThreadComponentHandler";
private static final String POOLABLE =
"org.apache.excalibur.fortress.handler.PoolableComponentHandler";
private static final String THREADSAFE =
"org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler";
// Map of fortress/type handlers
private static final Map m_handlers = new HashMap();
// Normalized mappings for Fortress component handlers
static
{
// Fortress -> Normalized
m_handlers.put( FACTORY, TRANSIENT );
m_handlers.put( PERTHREAD, THREAD );
m_handlers.put( POOLABLE, POOLED );
m_handlers.put( THREADSAFE, SINGLETON );
// Normalized -> Fortress
m_handlers.put( TRANSIENT, FACTORY );
m_handlers.put( THREAD, PERTHREAD );
m_handlers.put( POOLED, POOLABLE );
m_handlers.put( SINGLETON, THREADSAFE );
}
/**
* Method for extracting a role's ComponentHandler name.
*
* @return the role's normalized handler name
*/
public static String getHandler( final String handler )
{
return getLifestyleType( handler, FACTORY );
}
/**
* Helper method to convert known Fortress ComponentHandler types to meta
* REVISIT: meta should define transient/thread/pooled/etc as constants.
*
* @param handler a <code>String</code> value
* @param defaultValue a <code>String</code> default value if handler
* type cannot be found
* @return a <code>String</code> value
*/
private static String getLifestyleType( String handler, String defaultValue )
{
if ( handler != null )
{
String type = (String) m_handlers.get( handler );
if ( type != null )
return type;
}
/*
if ( getLogger().isWarnEnabled() )
{
getLogger().warn(
"Custom or unknown handler " + handler +
" defined, defaulting to " + defaultValue
);
}
*/
return defaultValue;
}
}
1.1
jakarta-avalon-excalibur/xfc/src/java/org/apache/excalibur/xfc/modules/fortress/package.html
Index: package.html
===================================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<body>
<p>
<b>Fortress Module</b>, Fortress Module implementation.
</p>
<p>
This package contains the Fortress Module implementation.
</p>
<!--
<h2>Package Specification</h2>
##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
<ul>
<li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
</ul>
<h2>Related Documentation</h2>
For overviews, tutorials, examples, guides, and tool documentation, please see:
<ul>
<li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
</ul>
-->
<!-- Put @see and @since tags down here. -->
</body>
</html>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>