You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2003/07/05 05:27:56 UTC
cvs commit: avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder XMLProfilePackageCreator.java SerializedProfilePackageCreator.java ProfilePackageCreator.java ProfilePackageBuilder.java
mcconnell 2003/07/04 20:27:56
Added: merlin/meta/src/java/org/apache/avalon/meta/data/builder
XMLProfilePackageCreator.java
SerializedProfilePackageCreator.java
ProfilePackageCreator.java
ProfilePackageBuilder.java
Log:
Add support for the importing of serialized or XML based packed profiles. This implementation supports the declaration of:
1. multiple named component deployment profiles
2. containment profiles
3. composition profiles
Revision Changes Path
1.1 avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/XMLProfilePackageCreator.java
Index: XMLProfilePackageCreator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 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", "Apache Avalon", "Avalon Framework" 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 apache@apache.org.
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.avalon.meta.data.builder;
import java.util.ArrayList;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.meta.data.MetaDataException;
import org.apache.avalon.meta.data.Profile;
import org.apache.avalon.meta.data.ProfilePackage;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.excalibur.configuration.ConfigurationUtil;
/**
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/07/05 03:27:56 $
*/
public class XMLProfilePackageCreator
{
private static final Resources REZ =
ResourceManager.getPackageResources( XMLProfilePackageCreator.class );
private static final XMLCompositionProfileCreator COMPOSITION_CREATOR =
new XMLCompositionProfileCreator();
private static final XMLContainmentProfileCreator CONTAINMENT_CREATOR =
new XMLContainmentProfileCreator();
private static final XMLDeploymentProfileCreator DEPLOYMENT_CREATOR =
new XMLDeploymentProfileCreator();
/**
* Creation of a {@link ProfilePackage} from an XML configuration.
*
* @param config the configuration
* @return the profile package
*/
public ProfilePackage createProfilePackage( Configuration config )
throws MetaDataException
{
ArrayList list = new ArrayList();
Configuration[] children = config.getChildren();
for( int i=0; i<children.length; i++ )
{
Configuration child = children[i];
final String name = child.getName();
if( name.equals( "profile" ) || name.equals( "component" ) )
{
try
{
list.add(
DEPLOYMENT_CREATOR.createDeploymentProfile( child ) );
}
catch( Throwable e )
{
final String error =
"Unable to create a packaged deployment profile."
+ ConfigurationUtil.list( child );
throw new MetaDataException( error );
}
}
else if( name.equals( "container" ) )
{
try
{
list.add(
CONTAINMENT_CREATOR.createContainmentProfile( child ) );
}
catch( Throwable e )
{
final String error =
"Unable to create a packaged containment profile."
+ ConfigurationUtil.list( child );
throw new MetaDataException( error );
}
}
if( name.equals( "block" ) )
{
try
{
list.add(
COMPOSITION_CREATOR.createCompositionProfile( child ) );
}
catch( Throwable e )
{
final String error =
"Unable to create a packaged composition profile."
+ ConfigurationUtil.list( child );
throw new MetaDataException( error );
}
}
else
{
final String error =
"Package defintion contains an unrecognized profile"
+ ConfigurationUtil.list( child );
throw new MetaDataException( error );
}
}
Profile[] profiles = (Profile[]) list.toArray( new Profile[0] );
return new ProfilePackage( profiles );
}
}
1.1 avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/SerializedProfilePackageCreator.java
Index: SerializedProfilePackageCreator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 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", "Apache Avalon", "Avalon Framework" 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 apache@apache.org.
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.avalon.meta.data.builder;
import java.io.InputStream;
import java.io.ObjectInputStream;
import org.apache.avalon.meta.data.ProfilePackage;
/**
* Create {@link Type} from stream made up of
* serialized object.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/07/05 03:27:56 $
*/
public class SerializedProfilePackageCreator
implements ProfilePackageCreator
{
/**
* Create a {@link ProfilePackage} from a stream.
*
* @param inputStream the stream that the resource is loaded from
* @return the composition profile
* @exception Exception if a error occurs during package creation
*/
public ProfilePackage createProfilePackage( InputStream inputStream )
throws Exception
{
final ObjectInputStream ois = new ObjectInputStream( inputStream );
return (ProfilePackage)ois.readObject();
}
}
1.1 avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/ProfilePackageCreator.java
Index: ProfilePackageCreator.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 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", "Apache Avalon", "Avalon Framework" 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 apache@apache.org.
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.avalon.meta.data.builder;
import java.io.InputStream;
import org.apache.avalon.meta.data.ProfilePackage;
/**
* Interface used to create a {@link ProfilePackage}
* from an input stream.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/07/05 03:27:56 $
*/
public interface ProfilePackageCreator
{
/**
* Create a {@link ProfilePackage} from a stream.
*
* @param inputStream the stream that the resource is loaded from
* @return the profile package
* @exception Exception if a error occurs during package creation
*/
ProfilePackage createProfilePackage( InputStream inputStream )
throws Exception;
}
1.1 avalon-sandbox/merlin/meta/src/java/org/apache/avalon/meta/data/builder/ProfilePackageBuilder.java
Index: ProfilePackageBuilder.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 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", "Apache Avalon", "Avalon Framework" 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 apache@apache.org.
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.avalon.meta.data.builder;
import java.io.InputStream;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.excalibur.i18n.ResourceManager;
import org.apache.avalon.excalibur.i18n.Resources;
import org.apache.avalon.meta.ConfigurationBuilder;
import org.apache.avalon.meta.data.ProfilePackage;
import org.apache.avalon.meta.data.MetaDataException;
import org.xml.sax.InputSource;
/**
* A ProfileBuilder is responsible for building a {@link ProfilePackage}
* object from a source.
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $ $Date: 2003/07/05 03:27:56 $
*/
public final class ProfilePackageBuilder implements ProfilePackageCreator
{
private XMLProfilePackageCreator m_xml =
new XMLProfilePackageCreator( );
private final SerializedProfilePackageCreator m_serial =
new SerializedProfilePackageCreator();
/**
* Create a {@link ProfilePackage} from a stream.
*
* @param inputStream the stream that the resource is loaded from
* @return the profile package
* @exception Exception if a error occurs during profile creation
*/
public ProfilePackage createProfilePackage( InputStream inputStream )
throws Exception
{
final ProfilePackage profile = buildFromSerDescriptor( inputStream);
if( null != profile )
{
return profile;
}
else
{
return buildFromXMLDescriptor( inputStream );
}
}
/**
* Build ProfilePackage from the serialized format.
*
* @throws Exception if an error occurs
*/
private ProfilePackage buildFromSerDescriptor( InputStream inputStream )
throws Exception
{
return m_serial.createProfilePackage( inputStream );
}
/**
* Build CompositionProfile from an XML descriptor.
*
* @throws Exception if an error occurs
*/
private ProfilePackage buildFromXMLDescriptor( InputStream inputStream )
throws Exception
{
final InputSource inputSource = new InputSource( inputStream );
Configuration config = ConfigurationBuilder.build( inputSource );
return m_xml.createProfilePackage( config );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org