PlexusContainer
. That is, the
* PlexusContainer
that this component is in.
*/
private PlexusContainer parentPlexus;
/** Our own PlexusContainer
. */
private DefaultPlexusContainer myPlexus;
private String plexusConfig;
private Properties contextValues;
public void contextualize( Context context )
throws ContextException
{
parentPlexus = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
public void initialize()
throws InitializationException
{
myPlexus = new DefaultPlexusContainer();
myPlexus.setParentPlexusContainer( parentPlexus );
ClassLoader loader = Thread.currentThread().getContextClassLoader();
InputStream stream = loader.getResourceAsStream( plexusConfig );
Reader r = new InputStreamReader( stream );
try
{
myPlexus.setConfigurationResource( r );
}
catch ( PlexusConfigurationResourceException e )
{
throw new InitializationException( "Unable to initialize container configuration", e );
}
if ( contextValues != null )
{
for ( Iterator i = contextValues.keySet().iterator(); i.hasNext(); )
{
String name = (String) i.next();
myPlexus.addContextValue( name, contextValues.getProperty( name ) );
}
}
try
{
myPlexus.initialize();
}
catch ( PlexusContainerException e )
{
throw new InitializationException( "Error initializing container", e );
}
}
public void start()
throws StartingException
{
try
{
myPlexus.start();
}
catch ( PlexusContainerException e )
{
throw new StartingException( "Error starting container", e );
}
}
public void stop()
{
myPlexus.dispose();
}
public PlexusContainer[] getManagedContainers()
{
return new PlexusContainer[] { myPlexus };
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/ 0000755 0001750 0001750 00000000000 10631507706 024766 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/AbstractLifecycleHandler.java 0000644 0001750 0001750 00000007661 10231133376 032516 0 ustar paul paul package org.codehaus.plexus.lifecycle;
import org.codehaus.plexus.component.manager.ComponentManager;
import org.codehaus.plexus.lifecycle.phase.Phase;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public abstract class AbstractLifecycleHandler
implements LifecycleHandler
{
private String id = null;
private String name = null;
private List beginSegment;
private List suspendSegment;
private List resumeSegment;
private List endSegment;
public AbstractLifecycleHandler()
{
beginSegment = new ArrayList();
suspendSegment = new ArrayList();
resumeSegment = new ArrayList();
endSegment = new ArrayList();
}
public String getId()
{
return id;
}
public String getName()
{
return name;
}
// ----------------------------------------------------------------------
// Begin Segment
// ----------------------------------------------------------------------
public List getBeginSegment()
{
return beginSegment;
}
// ----------------------------------------------------------------------
// Suspend Segment
// ----------------------------------------------------------------------
public List getSuspendSegment()
{
return suspendSegment;
}
// ----------------------------------------------------------------------
// Resume Segment
// ----------------------------------------------------------------------
public List getResumeSegment()
{
return resumeSegment;
}
// ----------------------------------------------------------------------
// End Segment
// ----------------------------------------------------------------------
public List getEndSegment()
{
return endSegment;
}
// ----------------------------------------------------------------------
// Lifecylce Management
// ----------------------------------------------------------------------
/**
* Start a component's lifecycle.
*/
public void start( Object component, ComponentManager manager )
throws PhaseExecutionException
{
if ( segmentIsEmpty( getBeginSegment() ) )
{
return;
}
for ( Iterator i = getBeginSegment().iterator(); i.hasNext(); )
{
Phase phase = (Phase) i.next();
phase.execute( component, manager );
}
}
public void suspend( Object component, ComponentManager manager )
throws PhaseExecutionException
{
if ( segmentIsEmpty( getSuspendSegment() ) )
{
return;
}
for ( Iterator i = getSuspendSegment().iterator(); i.hasNext(); )
{
Phase phase = (Phase) i.next();
phase.execute( component, manager );
}
}
public void resume( Object component, ComponentManager manager )
throws PhaseExecutionException
{
if ( segmentIsEmpty( getResumeSegment() ) )
{
return;
}
for ( Iterator i = getResumeSegment().iterator(); i.hasNext(); )
{
Phase phase = (Phase) i.next();
phase.execute( component, manager );
}
}
/**
* End a component's lifecycle.
*/
public void end( Object component, ComponentManager manager )
throws PhaseExecutionException
{
if ( segmentIsEmpty( getEndSegment() ) )
{
return;
}
for ( Iterator i = getEndSegment().iterator(); i.hasNext(); )
{
Phase phase = (Phase) i.next();
phase.execute( component, manager );
}
}
private boolean segmentIsEmpty( List segment )
{
if ( segment == null || segment.size() == 0 )
{
return true;
}
return false;
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/LifecycleHandler.java 0000644 0001750 0001750 00000001253 10231133376 031021 0 ustar paul paul package org.codehaus.plexus.lifecycle;
import org.codehaus.plexus.component.manager.ComponentManager;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
public interface LifecycleHandler
{
String getId();
void start( Object component, ComponentManager manager )
throws PhaseExecutionException;
void suspend( Object component, ComponentManager manager )
throws PhaseExecutionException;
void resume( Object component, ComponentManager manager )
throws PhaseExecutionException;
void end( Object component, ComponentManager manager )
throws PhaseExecutionException;
void initialize();
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/LifecycleHandlerManager.java 0000644 0001750 0001750 00000000736 10231133376 032321 0 ustar paul paul package org.codehaus.plexus.lifecycle;
/**
*
*
* @author Jason van Zyl
*
* @version $Id: LifecycleHandlerManager.java 1750 2005-04-19 07:45:02Z brett $
*/
public interface LifecycleHandlerManager
{
void initialize();
LifecycleHandler getDefaultLifecycleHandler()
throws UndefinedLifecycleHandlerException;
LifecycleHandler getLifecycleHandler( String id )
throws UndefinedLifecycleHandlerException;
}
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/DefaultLifecycleHandlerManager.java plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/DefaultLifecycleHandlerManager.0000644 0001750 0001750 00000005103 10231133376 032755 0 ustar paul paul package org.codehaus.plexus.lifecycle;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.util.Iterator;
import java.util.List;
/**
* @author Jason van Zyl
*
* @version $Id: DefaultLifecycleHandlerManager.java 1750 2005-04-19 07:45:02Z brett $
*/
public class DefaultLifecycleHandlerManager
implements LifecycleHandlerManager
{
private List lifecycleHandlers = null;
private String defaultLifecycleHandlerId = "plexus";
public void initialize()
{
for ( Iterator iterator = lifecycleHandlers.iterator(); iterator.hasNext(); )
{
LifecycleHandler lifecycleHandler = (LifecycleHandler) iterator.next();
lifecycleHandler.initialize();
}
}
public LifecycleHandler getLifecycleHandler( String id )
throws UndefinedLifecycleHandlerException
{
LifecycleHandler lifecycleHandler = null;
for ( Iterator iterator = lifecycleHandlers.iterator(); iterator.hasNext(); )
{
lifecycleHandler = (LifecycleHandler) iterator.next();
if ( id.equals( lifecycleHandler.getId() ) )
{
return lifecycleHandler;
}
}
throw new UndefinedLifecycleHandlerException( "Specified lifecycle handler cannot be found: " + id );
}
public LifecycleHandler getDefaultLifecycleHandler()
throws UndefinedLifecycleHandlerException
{
return getLifecycleHandler( defaultLifecycleHandlerId );
}
}
././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/UndefinedLifecycleHandlerException.java plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/UndefinedLifecycleHandlerExcept0000644 0001750 0001750 00000000330 10161654653 033077 0 ustar paul paul package org.codehaus.plexus.lifecycle;
public class UndefinedLifecycleHandlerException
extends Exception
{
public UndefinedLifecycleHandlerException( String message )
{
super( message );
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/BasicLifecycleHandler.java 0000644 0001750 0001750 00000002562 10231133376 031767 0 ustar paul paul package org.codehaus.plexus.lifecycle;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class BasicLifecycleHandler
extends AbstractLifecycleHandler
{
/** @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable#initialize */
public void initialize()
{
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/PassiveLifecycleHandler.java 0000644 0001750 0001750 00000002564 10231133376 032362 0 ustar paul paul package org.codehaus.plexus.lifecycle;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
public class PassiveLifecycleHandler
extends AbstractLifecycleHandler
{
/** @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable#initialize */
public void initialize()
{
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phase/ 0000755 0001750 0001750 00000000000 10631507706 026066 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phase/Phase.java 0000644 0001750 0001750 00000000554 10231133376 027767 0 ustar paul paul package org.codehaus.plexus.lifecycle.phase;
import org.codehaus.plexus.component.manager.ComponentManager;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
public interface Phase
{
/** Execute the phase. */
public void execute( Object component, ComponentManager manager )
throws PhaseExecutionException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/lifecycle/phase/AbstractPhase.java 0000644 0001750 0001750 00000000627 10231133376 031454 0 ustar paul paul package org.codehaus.plexus.lifecycle.phase;
import org.codehaus.plexus.component.manager.ComponentManager;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.PhaseExecutionException;
public abstract class AbstractPhase
implements Phase
{
/** Execute the phase. */
public abstract void execute( Object component, ComponentManager manager )
throws PhaseExecutionException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/DuplicateChildContainerException.java 0000644 0001750 0001750 00000002316 10263567340 032275 0 ustar paul paul package org.codehaus.plexus;
/*
* Copyright 2001-2005 The 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.
*/
public class DuplicateChildContainerException
extends PlexusContainerException
{
private final String parent;
private final String child;
public DuplicateChildContainerException( String parent, String child )
{
super( "Cannot create child container, because child named \'" + child + "\' already exists in parent \'" + parent + "\'." );
this.parent = parent;
this.child = child;
}
public String getParent()
{
return parent;
}
public String getChild()
{
return child;
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/PlexusContainer.java 0000644 0001750 0001750 00000014560 10322665042 027016 0 ustar paul paul package org.codehaus.plexus;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.component.composition.CompositionException;
import org.codehaus.plexus.component.composition.UndefinedComponentComposerException;
import org.codehaus.plexus.component.discovery.ComponentDiscoveryListener;
import org.codehaus.plexus.component.factory.ComponentInstantiationException;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.component.repository.exception.ComponentRepositoryException;
import org.codehaus.plexus.configuration.PlexusConfigurationResourceException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.LoggerManager;
import java.io.File;
import java.io.Reader;
import java.util.Date;
import java.util.List;
import java.util.Map;
public interface PlexusContainer
{
String ROLE = PlexusContainer.class.getName();
// ----------------------------------------------------------------------
// Timestamp access
// ----------------------------------------------------------------------
public Date getCreationDate();
// ----------------------------------------------------------------------
// Child container access
// ----------------------------------------------------------------------
boolean hasChildContainer( String name );
void removeChildContainer( String name );
PlexusContainer getChildContainer( String name );
PlexusContainer createChildContainer( String name, List classpathJars, Map context )
throws PlexusContainerException;
PlexusContainer createChildContainer( String name, List classpathJars, Map context, List discoveryListeners )
throws PlexusContainerException;
// ----------------------------------------------------------------------
// Component lookup
// ----------------------------------------------------------------------
Object lookup( String componentKey )
throws ComponentLookupException;
Object lookup( String role, String roleHint )
throws ComponentLookupException;
Map lookupMap( String role )
throws ComponentLookupException;
List lookupList( String role )
throws ComponentLookupException;
// ----------------------------------------------------------------------
// Component Descriptor Lookup
// ----------------------------------------------------------------------
ComponentDescriptor getComponentDescriptor( String componentKey );
Map getComponentDescriptorMap( String role );
List getComponentDescriptorList( String role );
void addComponentDescriptor( ComponentDescriptor componentDescriptor )
throws ComponentRepositoryException;
// ----------------------------------------------------------------------
// Component release
// ----------------------------------------------------------------------
void release( Object component )
throws ComponentLifecycleException;
void releaseAll( Map components )
throws ComponentLifecycleException;
void releaseAll( List components )
throws ComponentLifecycleException;
// ----------------------------------------------------------------------
// Component discovery
// ----------------------------------------------------------------------
boolean hasComponent( String componentKey );
boolean hasComponent( String role, String roleHint );
// ----------------------------------------------------------------------
// Component replacement
// ----------------------------------------------------------------------
void suspend( Object component )
throws ComponentLifecycleException;
void resume( Object component )
throws ComponentLifecycleException;
// ----------------------------------------------------------------------
// Lifecycle
// ----------------------------------------------------------------------
void initialize()
throws PlexusContainerException;
boolean isInitialized();
void start()
throws PlexusContainerException;
boolean isStarted();
void dispose();
// ----------------------------------------------------------------------
// Context
// ----------------------------------------------------------------------
Context getContext();
// ----------------------------------------------------------------------
// Container setup
// ----------------------------------------------------------------------
void setParentPlexusContainer( PlexusContainer parentContainer );
void addContextValue( Object key, Object value );
void setConfigurationResource( Reader configuration )
throws PlexusConfigurationResourceException;
Logger getLogger();
Object createComponentInstance( ComponentDescriptor componentDescriptor )
throws ComponentInstantiationException, ComponentLifecycleException;
void composeComponent( Object component, ComponentDescriptor componentDescriptor )
throws CompositionException, UndefinedComponentComposerException;
// ----------------------------------------------------------------------
// Discovery
// ----------------------------------------------------------------------
void registerComponentDiscoveryListener( ComponentDiscoveryListener listener );
void removeComponentDiscoveryListener( ComponentDiscoveryListener listener );
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
void addJarRepository( File repository );
void addJarResource( File resource ) throws PlexusContainerException;
ClassRealm getContainerRealm();
/** @deprecated Use getContainerRealm() instead. */
ClassRealm getComponentRealm( String componentKey );
// ----------------------------------------------------------------------
// Start of new programmatic API to fully control the container
// ----------------------------------------------------------------------
void setLoggerManager( LoggerManager loggerManager );
LoggerManager getLoggerManager();
}
plexus-container-default/src/main/java/org/codehaus/plexus/PlexusContainerException.java 0000644 0001750 0001750 00000000767 10251162615 030700 0 ustar paul paul package org.codehaus.plexus;
/**
* Container execution exception.
*
* @author Brett Porter
* @version $Id: PlexusContainerException.java 2097 2005-06-07 00:08:45Z jdcasey $
*/
public class PlexusContainerException extends Exception
{
public PlexusContainerException( String message, Throwable throwable )
{
super( message, throwable );
}
public PlexusContainerException( String message )
{
super( message );
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/component/ 0000755 0001750 0001750 00000000000 10631507712 025026 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ 0000755 0001750 0001750 00000000000 10631507712 026475 5 ustar paul paul ././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/AbstractComponentFactory.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/AbstractComponentFactor0000644 0001750 0001750 00000000570 10161654653 033214 0 ustar paul paul package org.codehaus.plexus.component.factory;
/**
*
*
* @author Jason van Zyl
*
* @version $Id: AbstractComponentFactory.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public abstract class AbstractComponentFactory
implements ComponentFactory
{
protected String id;
public String getId()
{
return id;
}
}
././@LongLink 0000000 0000000 0000000 00000000165 00000000000 011567 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/UndefinedComponentFactoryException.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/UndefinedComponentFacto0000644 0001750 0001750 00000001162 10161654653 033166 0 ustar paul paul package org.codehaus.plexus.component.factory;
/**
*
*
* @author Jason van Zyl
*
* @version $Id: UndefinedComponentFactoryException.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public class UndefinedComponentFactoryException
extends Exception
{
public UndefinedComponentFactoryException( String message )
{
super( message );
}
public UndefinedComponentFactoryException( String message, Throwable cause )
{
super( message, cause );
}
public UndefinedComponentFactoryException( Throwable cause )
{
super( cause );
}
}
././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/DefaultComponentFactoryManager.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/DefaultComponentFactory0000644 0001750 0001750 00000007121 10231133376 033215 0 ustar paul paul package org.codehaus.plexus.component.factory;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.factory.java.JavaComponentFactory;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
import org.codehaus.plexus.util.StringUtils;
import java.util.List;
/**
*
*
* @author Jason van Zyl
*
* @version $Id: DefaultComponentFactoryManager.java 1750 2005-04-19 07:45:02Z brett $
*/
public class DefaultComponentFactoryManager
implements ComponentFactoryManager, Contextualizable
{
private String defaultComponentFactoryId = "java";
private ComponentFactory defaultComponentFactory = new JavaComponentFactory();
private PlexusContainer container;
/** @deprecated Register factories as components with language as role-hint instead.*/
private List componentFactories;
public ComponentFactory findComponentFactory( String id )
throws UndefinedComponentFactoryException
{
if(StringUtils.isEmpty(id) || defaultComponentFactoryId.equals(id))
{
return defaultComponentFactory;
}
else
{
try
{
return (ComponentFactory) container.lookup(ComponentFactory.ROLE, id);
}
catch ( ComponentLookupException e )
{
throw new UndefinedComponentFactoryException( "Specified component factory cannot be found: " + id, e );
}
}
// Commented out until we get active collections working; we'll do direct
// lookups until then.
// for ( Iterator iterator = componentFactories.iterator(); iterator.hasNext(); )
// {
// componentFactory = (ComponentFactory) iterator.next();
//
// if ( id.equals( componentFactory.getId() ) )
// {
// return componentFactory;
// }
// }
}
public ComponentFactory getDefaultComponentFactory()
throws UndefinedComponentFactoryException
{
return defaultComponentFactory;
}
public void contextualize( Context context )
throws ContextException
{
this.container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ComponentFactory.java 0000644 0001750 0001750 00000001454 10161654653 032643 0 ustar paul paul package org.codehaus.plexus.component.factory;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.classworlds.ClassRealm;
/** A ServiceFactory
is responsible for instantiating a component.
*
* @author Jason van Zyl
* @author Michal Maczka
*
* @version $Id: ComponentFactory.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public interface ComponentFactory
{
/** Component role. */
static String ROLE = ComponentFactory.class.getName();
String getId();
Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container )
throws ComponentInstantiationException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/java/ 0000755 0001750 0001750 00000000000 10631507712 027416 5 ustar paul paul ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/java/JavaComponentFactory.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/java/JavaComponentFacto0000644 0001750 0001750 00000006147 10251162615 033067 0 ustar paul paul package org.codehaus.plexus.component.factory.java;
import java.lang.reflect.Modifier;
import org.codehaus.classworlds.ClassRealm;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.factory.AbstractComponentFactory;
import org.codehaus.plexus.component.factory.ComponentInstantiationException;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
/**
* Component Factory for components written in Java Language which have default no parameter constructor
*
* @author Jason van Zyl
* @author Michal Maczka
* @version $Id: JavaComponentFactory.java 2097 2005-06-07 00:08:45Z jdcasey $
*/
public class JavaComponentFactory
extends AbstractComponentFactory
{
public Object newInstance( ComponentDescriptor componentDescriptor, ClassRealm classRealm, PlexusContainer container )
throws ComponentInstantiationException
{
Class implementationClass = null;
try
{
String implementation = componentDescriptor.getImplementation();
implementationClass = classRealm.loadClass( implementation );
int modifiers = implementationClass.getModifiers();
if ( Modifier.isInterface( modifiers ) )
{
throw new ComponentInstantiationException( "Cannot instanciate implementation '" + implementation + "' because the class is a interface." );
}
if ( Modifier.isAbstract( modifiers ) )
{
throw new ComponentInstantiationException( "Cannot instanciate implementation '" + implementation + "' because the class is abstract." );
}
Object instance = implementationClass.newInstance();
return instance;
}
catch ( InstantiationException e )
{
throw makeException( classRealm, componentDescriptor, implementationClass, e );
}
catch ( ClassNotFoundException e )
{
throw makeException( classRealm, componentDescriptor, implementationClass, e );
}
catch( IllegalAccessException e )
{
throw makeException( classRealm, componentDescriptor, implementationClass, e );
}
catch( LinkageError e )
{
throw makeException( classRealm, componentDescriptor, implementationClass, e );
}
}
private ComponentInstantiationException makeException( ClassRealm componentClassRealm, ComponentDescriptor componentDescriptor, Class implementationClass, Throwable e )
{
// ----------------------------------------------------------------------
// Display the realm when there is an error, We should probably return a string here so we
// can incorporate this into the error message for easy debugging.
// ----------------------------------------------------------------------
componentClassRealm.display();
String msg = "Could not instanciate component: " + componentDescriptor.getHumanReadableKey();
return new ComponentInstantiationException( msg, e );
}
}
././@LongLink 0000000 0000000 0000000 00000000162 00000000000 011564 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ComponentInstantiationException.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ComponentInstantiationE0000644 0001750 0001750 00000001147 10161654653 033244 0 ustar paul paul package org.codehaus.plexus.component.factory;
/**
*
*
* @author Michal Maczka
*
* @version $Id: ComponentInstantiationException.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public class ComponentInstantiationException
extends Exception
{
public ComponentInstantiationException( String message )
{
super( message );
}
public ComponentInstantiationException( String message, Throwable cause )
{
super( message, cause );
}
public ComponentInstantiationException( Throwable cause )
{
super( cause );
}
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ComponentFactoryManager.java plexus-container-default/src/main/java/org/codehaus/plexus/component/factory/ComponentFactoryManager0000644 0001750 0001750 00000000716 10161654653 033216 0 ustar paul paul package org.codehaus.plexus.component.factory;
/**
*
*
* @author Jason van Zyl
*
* @version $Id: ComponentFactoryManager.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public interface ComponentFactoryManager
{
ComponentFactory findComponentFactory( String id )
throws UndefinedComponentFactoryException;
ComponentFactory getDefaultComponentFactory()
throws UndefinedComponentFactoryException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/component/MapOrientedComponent.java 0000644 0001750 0001750 00000002175 10251162615 031765 0 ustar paul paul package org.codehaus.plexus.component;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import java.util.Map;
/*
* Copyright 2001-2005 The 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.
*/
public interface MapOrientedComponent
{
void addComponentRequirement( ComponentRequirement requirementDescriptor, Object requirementValue )
throws ComponentConfigurationException;
void setComponentConfiguration( Map componentConfiguration )
throws ComponentConfigurationException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/ 0000755 0001750 0001750 00000000000 10631507707 027251 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/io/ 0000755 0001750 0001750 00000000000 10631507707 027660 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/component/repository/io/PlexusTools.java 0000644 0001750 0001750 00000016724 10236467234 033037 0 ustar paul paul package org.codehaus.plexus.component.repository.io;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.component.repository.ComponentSetDescriptor;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfigurationException;
import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration;
import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
/**
* @author Jason van Zyl
* @version $Id: PlexusTools.java 1781 2005-05-05 19:06:04Z jdcasey $
* @todo these are all really tools for dealing with xml configurations so they
* should be packaged as such.
*/
public class PlexusTools
{
public static PlexusConfiguration buildConfiguration( String resourceName, Reader configuration )
throws PlexusConfigurationException
{
try
{
return new XmlPlexusConfiguration( Xpp3DomBuilder.build( configuration ) );
}
catch ( XmlPullParserException e )
{
throw new PlexusConfigurationException( "Failed to parse configuration resource: \'" + resourceName + "\'\nError was: \'" + e.getLocalizedMessage() + "\'", e );
}
catch ( IOException e )
{
throw new PlexusConfigurationException( "IO error building configuration from: " + resourceName, e );
}
}
public static PlexusConfiguration buildConfiguration( String configuration )
throws PlexusConfigurationException
{
return buildConfiguration( "java.util.Properties
.
*
* @author Michal Maczka
* @version $Id: PropertiesConverter.java 6054 2007-03-11 01:43:15Z jvanzyl $
*/
public class PropertiesConverter
extends AbstractConfigurationConverter
{
public boolean canConvert( Class type )
{
return Properties.class.isAssignableFrom( type );
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
Object retValueInterpolated = fromExpression( configuration, expressionEvaluator, type );
if ( retValueInterpolated != null )
{
return retValueInterpolated;
}
String element = configuration.getName();
Properties retValue = new Properties();
PlexusConfiguration[] children = configuration.getChildren( "property" );
if ( children != null && children.length > 0 )
{
for ( int i = 0; i < children.length; i++ )
{
PlexusConfiguration child = children[i];
addEntry( retValue, element, child );
}
}
return retValue;
}
private void addEntry( Properties properties, String element, PlexusConfiguration property )
throws ComponentConfigurationException
{
String name;
name = property.getChild( "name" ).getValue( null );
if ( name == null )
{
String msg = "Converter: java.util.Properties. Trying to convert the configuration element: '" + element
+ "', missing child element 'name'.";
throw new ComponentConfigurationException( msg );
}
String value = property.getChild( "value" ).getValue( "" );
properties.put( name, value );
}
}
././@LongLink 0000000 0000000 0000000 00000000206 00000000000 011563 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composite/ObjectWithFieldsConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composi0000644 0001750 0001750 00000013117 10321664044 033317 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.composite;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.ComponentValueSetter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.ReflectionUtils;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Dictionary;
import java.util.Map;
/**
* @author Michal Maczka
* @version $Id: ObjectWithFieldsConverter.java 2634 2005-10-08 06:33:08Z brett $
*/
public class ObjectWithFieldsConverter
extends AbstractConfigurationConverter
{
/**
* @param type
* @return
* @todo I am not sure what should go into this method
*/
public boolean canConvert( Class type )
{
boolean retValue = true;
if ( Dictionary.class.isAssignableFrom( type ) )
{
retValue = false;
}
else if ( Map.class.isAssignableFrom( type ) )
{
retValue = false;
}
else if ( Collection.class.isAssignableFrom( type ) )
{
retValue = false;
}
return retValue;
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
Object retValue = fromExpression( configuration, expressionEvaluator, type );
if ( retValue == null )
{
try
{
// it is a "composite" - we compose it from its children. It does not have a value of its own
Class implementation = getClassForImplementationHint( type, configuration, classLoader );
retValue = instantiateObject( implementation );
processConfiguration( converterLookup, retValue, classLoader, configuration, expressionEvaluator,
listener );
}
catch ( ComponentConfigurationException e )
{
if ( e.getFailedConfiguration() == null )
{
e.setFailedConfiguration( configuration );
}
throw e;
}
}
return retValue;
}
public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader,
PlexusConfiguration configuration )
throws ComponentConfigurationException
{
processConfiguration( converterLookup, object, classLoader, configuration, null );
}
public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader,
PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator )
throws ComponentConfigurationException
{
processConfiguration( converterLookup, object, classLoader, configuration, expressionEvaluator, null );
}
public void processConfiguration( ConverterLookup converterLookup, Object object, ClassLoader classLoader,
PlexusConfiguration configuration, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
int items = configuration.getChildCount();
for ( int i = 0; i < items; i++ )
{
PlexusConfiguration childConfiguration = configuration.getChild( i );
String elementName = childConfiguration.getName();
ComponentValueSetter valueSetter = new ComponentValueSetter( fromXML( elementName ), object,
converterLookup, listener );
valueSetter.configure( childConfiguration, classLoader, expressionEvaluator );
}
}
}
././@LongLink 0000000 0000000 0000000 00000000211 00000000000 011557 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composite/PlexusConfigurationConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composi0000644 0001750 0001750 00000005041 10321664044 033314 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.composite;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
/**
* Converter for org.codehaus.plexus.configuration.PlexusConfiguration
*
* @author Michal Maczka
* @version $Id: PlexusConfigurationConverter.java 2634 2005-10-08 06:33:08Z brett $
*/
public class PlexusConfigurationConverter
extends AbstractConfigurationConverter
{
public boolean canConvert( Class type )
{
return PlexusConfiguration.class.isAssignableFrom( type );
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
return configuration;
}
}
././@LongLink 0000000 0000000 0000000 00000000171 00000000000 011564 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composite/MapConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composi0000644 0001750 0001750 00000006334 10321664044 033322 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.composite;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
/**
* Converter for java.util.Properties
.
*
* @author Michal Maczka
* @version $Id: MapConverter.java 2634 2005-10-08 06:33:08Z brett $
*/
public class MapConverter
extends AbstractConfigurationConverter
{
public boolean canConvert( Class type )
{
return Map.class.isAssignableFrom( type ) && !Properties.class.isAssignableFrom( type );
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
Object retValue;
String expression = configuration.getValue( null );
if ( expression == null )
{
Map map = new TreeMap();
PlexusConfiguration[] children = configuration.getChildren();
for ( int i = 0; i < children.length; i++ )
{
PlexusConfiguration child = children[i];
String name = child.getName();
map.put( name, fromExpression( child, expressionEvaluator ) );
}
retValue = map;
}
else
{
retValue = fromExpression( configuration, expressionEvaluator );
}
return retValue;
}
}
././@LongLink 0000000 0000000 0000000 00000000173 00000000000 011566 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composite/ArrayConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composi0000644 0001750 0001750 00000013022 10321664044 033312 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.composite;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* @author Kenney Westerhof
* @version $Id: ArrayConverter.java 2634 2005-10-08 06:33:08Z brett $
*/
public class ArrayConverter
extends AbstractConfigurationConverter
{
public boolean canConvert( Class type )
{
return type.isArray();
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
Object retValue = fromExpression( configuration, expressionEvaluator, type );
if ( retValue != null )
{
return retValue;
}
List values = new ArrayList();
for ( int i = 0; i < configuration.getChildCount(); i++ )
{
PlexusConfiguration c = configuration.getChild( i );
String configEntry = c.getName();
String name = fromXML( configEntry );
Class childType = getClassForImplementationHint( null, c, classLoader );
// check if the name is a fully qualified classname
if ( childType == null && name.indexOf( '.' ) > 0 )
{
try
{
childType = classLoader.loadClass( name );
}
catch ( ClassNotFoundException e )
{
// doesn't exist - continue processing
}
}
if ( childType == null )
{
// try to find the class in the package of the baseType
// (which is the component being configured)
String baseTypeName = baseType.getName();
int lastDot = baseTypeName.lastIndexOf( '.' );
String className;
if ( lastDot == -1 )
{
className = name;
}
else
{
String basePackage = baseTypeName.substring( 0, lastDot );
className = basePackage + "." + StringUtils.capitalizeFirstLetter( name );
}
try
{
childType = classLoader.loadClass( className );
}
catch ( ClassNotFoundException e )
{
// doesn't exist, continue processing
}
}
// finally just try the component type of the array
if ( childType == null )
{
childType = type.getComponentType();
}
ConfigurationConverter converter = converterLookup.lookupConverterForType( childType );
Object object = converter.fromConfiguration( converterLookup, c, childType, baseType, classLoader,
expressionEvaluator, listener );
values.add( object );
}
return values.toArray( (Object []) Array.newInstance( type.getComponentType(), 0 ) );
}
protected Collection getDefaultCollection( Class collectionType )
{
Collection retValue = null;
if ( List.class.isAssignableFrom( collectionType ) )
{
retValue = new ArrayList();
}
else if ( Set.class.isAssignableFrom( collectionType ) )
{
retValue = new HashSet();
}
return retValue;
}
}
././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composite/CollectionConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/composi0000644 0001750 0001750 00000016636 10321664044 033330 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.composite;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.AbstractConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author Michal Maczka
* @version $Id: CollectionConverter.java 2634 2005-10-08 06:33:08Z brett $
*/
public class CollectionConverter
extends AbstractConfigurationConverter
{
public boolean canConvert( Class type )
{
return Collection.class.isAssignableFrom( type ) && !Map.class.isAssignableFrom( type );
}
public Object fromConfiguration( ConverterLookup converterLookup, PlexusConfiguration configuration, Class type,
Class baseType, ClassLoader classLoader, ExpressionEvaluator expressionEvaluator,
ConfigurationListener listener )
throws ComponentConfigurationException
{
Object retValue = fromExpression( configuration, expressionEvaluator, type );
if ( retValue != null )
{
return retValue;
}
Class implementation = getClassForImplementationHint( null, configuration, classLoader );
if ( implementation != null )
{
retValue = instantiateObject( implementation );
}
else
{
// we can have 2 cases here:
// - provided collection class which is not abstract
// like Vector, ArrayList, HashSet - so we will just instantantiate it
// - we have an abtract class so we have to use default collection type
int modifiers = type.getModifiers();
if ( Modifier.isAbstract( modifiers ) )
{
retValue = getDefaultCollection( type );
}
else
{
try
{
retValue = type.newInstance();
}
catch ( IllegalAccessException e )
{
String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " +
type + " object failed: " + e.getMessage();
throw new ComponentConfigurationException( msg, e );
}
catch ( InstantiationException e )
{
String msg = "An attempt to convert configuration entry " + configuration.getName() + "' into " +
type + " object failed: " + e.getMessage();
throw new ComponentConfigurationException( msg, e );
}
}
}
// now we have collection and we have to add some objects to it
for ( int i = 0; i < configuration.getChildCount(); i++ )
{
PlexusConfiguration c = configuration.getChild( i );
//Object o = null;
String configEntry = c.getName();
String name = fromXML( configEntry );
Class childType = getClassForImplementationHint( null, c, classLoader );
if ( childType == null && name.indexOf( '.' ) > 0 )
{
try
{
childType = classLoader.loadClass( name );
}
catch ( ClassNotFoundException e )
{
// not found, continue processing
}
}
if ( childType == null )
{
// Some classloaders don't create Package objects for classes
// so we have to resort to slicing up the class name
String baseTypeName = baseType.getName();
int lastDot = baseTypeName.lastIndexOf( '.' );
String className;
if ( lastDot == -1 )
{
className = name;
}
else
{
String basePackage = baseTypeName.substring( 0, lastDot );
className = basePackage + "." + StringUtils.capitalizeFirstLetter( name );
}
try
{
childType = classLoader.loadClass( className );
}
catch ( ClassNotFoundException e )
{
if ( c.getChildCount() == 0 )
{
// If no children, try a String.
// TODO: If we had generics we could try that instead - or could the component descriptor list an impl?
childType = String.class;
}
else
{
throw new ComponentConfigurationException( "Error loading class '" + className + "'", e );
}
}
}
ConfigurationConverter converter = converterLookup.lookupConverterForType( childType );
Object object = converter.fromConfiguration( converterLookup, c, childType, baseType, classLoader,
expressionEvaluator, listener );
Collection collection = (Collection) retValue;
collection.add( object );
}
return retValue;
}
protected Collection getDefaultCollection( Class collectionType )
{
Collection retValue = null;
if ( List.class.isAssignableFrom( collectionType ) )
{
retValue = new ArrayList();
}
else if ( Set.class.isAssignableFrom( collectionType ) )
{
retValue = new HashSet();
}
return retValue;
}
}
././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/ plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/0000755 0001750 0001750 00000000000 10631507711 033232 5 ustar paul paul ././@LongLink 0000000 0000000 0000000 00000000200 00000000000 011555 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/DefaultConverterLookup.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/0000644 0001750 0001750 00000014463 10317644473 033254 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.lookup;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.basic.BooleanConverter;
import org.codehaus.plexus.component.configurator.converters.basic.ByteConverter;
import org.codehaus.plexus.component.configurator.converters.basic.CharConverter;
import org.codehaus.plexus.component.configurator.converters.basic.DateConverter;
import org.codehaus.plexus.component.configurator.converters.basic.DoubleConverter;
import org.codehaus.plexus.component.configurator.converters.basic.FileConverter;
import org.codehaus.plexus.component.configurator.converters.basic.FloatConverter;
import org.codehaus.plexus.component.configurator.converters.basic.IntConverter;
import org.codehaus.plexus.component.configurator.converters.basic.LongConverter;
import org.codehaus.plexus.component.configurator.converters.basic.ShortConverter;
import org.codehaus.plexus.component.configurator.converters.basic.StringBufferConverter;
import org.codehaus.plexus.component.configurator.converters.basic.StringConverter;
import org.codehaus.plexus.component.configurator.converters.basic.UrlConverter;
import org.codehaus.plexus.component.configurator.converters.composite.ArrayConverter;
import org.codehaus.plexus.component.configurator.converters.composite.CollectionConverter;
import org.codehaus.plexus.component.configurator.converters.composite.MapConverter;
import org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter;
import org.codehaus.plexus.component.configurator.converters.composite.PlexusConfigurationConverter;
import org.codehaus.plexus.component.configurator.converters.composite.PropertiesConverter;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class DefaultConverterLookup
implements ConverterLookup
{
private List converters = new LinkedList();
private List customConverters = new LinkedList();
private Map converterMap = new HashMap();
public DefaultConverterLookup()
{
registerDefaultBasicConverters();
registerDefaultCompositeConverters();
}
public void registerConverter( ConfigurationConverter converter )
{
customConverters.add( converter );
}
protected void registerDefaultConverter( ConfigurationConverter converter )
{
converters.add( converter );
}
public ConfigurationConverter lookupConverterForType( Class type )
throws ComponentConfigurationException
{
ConfigurationConverter retValue = null;
if ( converterMap.containsKey( type ) )
{
retValue = (ConfigurationConverter) converterMap.get( type );
}
else
{
retValue = findConverterForType( customConverters, type );
if ( retValue == null )
{
retValue = findConverterForType( converters, type );
}
}
if ( retValue == null )
{
// this is highly irregular
throw new ComponentConfigurationException( "Configuration converter lookup failed for type: " + type );
}
return retValue;
}
private ConfigurationConverter findConverterForType( List converters, Class type )
{
for ( Iterator iterator = converters.iterator(); iterator.hasNext(); )
{
ConfigurationConverter converter = (ConfigurationConverter) iterator.next();
if ( converter.canConvert( type ) )
{
converterMap.put( type, converter );
return converter;
}
}
return null;
}
private void registerDefaultBasicConverters()
{
registerDefaultConverter( new BooleanConverter() );
registerDefaultConverter( new ByteConverter() );
registerDefaultConverter( new CharConverter() );
registerDefaultConverter( new DoubleConverter() );
registerDefaultConverter( new FloatConverter() );
registerDefaultConverter( new IntConverter() );
registerDefaultConverter( new LongConverter() );
registerDefaultConverter( new ShortConverter() );
registerDefaultConverter( new StringBufferConverter() );
registerDefaultConverter( new StringConverter() );
registerDefaultConverter( new DateConverter() );
registerDefaultConverter( new FileConverter() );
registerDefaultConverter( new UrlConverter() );
//registerDefaultConverter( new BigIntegerConverter() );
}
private void registerDefaultCompositeConverters()
{
registerDefaultConverter( new MapConverter() );
registerDefaultConverter( new ArrayConverter() );
registerDefaultConverter( new CollectionConverter() );
registerDefaultConverter( new PropertiesConverter() );
registerDefaultConverter( new PlexusConfigurationConverter() );
// this converter should be always registred as the last one
registerDefaultConverter( new ObjectWithFieldsConverter() );
}
}
././@LongLink 0000000 0000000 0000000 00000000171 00000000000 011564 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/ConverterLookup.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/lookup/0000644 0001750 0001750 00000003214 10223105111 033215 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters.lookup;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.converters.ConfigurationConverter;
/**
* @version $Id: ConverterLookup.java 1632 2005-03-31 23:39:53Z trygvis $
*/
public interface ConverterLookup{
void registerConverter( ConfigurationConverter converter );
ConfigurationConverter lookupConverterForType( Class type )
throws ComponentConfigurationException;
}
././@LongLink 0000000 0000000 0000000 00000000201 00000000000 011556 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/AbstractConfigurationConverter.java plexus-container-default/src/main/java/org/codehaus/plexus/component/configurator/converters/Abstrac0000644 0001750 0001750 00000017166 10321670505 033234 0 ustar paul paul package org.codehaus.plexus.component.configurator.converters;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.configurator.ConfigurationListener;
import org.codehaus.plexus.component.configurator.converters.lookup.ConverterLookup;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.codehaus.plexus.util.StringUtils;
/**
* @author Michal Maczka
* @version $Id: AbstractConfigurationConverter.java 2636 2005-10-08 07:12:05Z brett $
*/
public abstract class AbstractConfigurationConverter
implements ConfigurationConverter
{
private static final String IMPLEMENTATION = "implementation";
/**
* We will check if user has provided a hint which class should be used for given field.
* So we will check if something like CompositionException
instance.
*
* @param message The detail message for this exception.
*/
public CompositionException( String s )
{
super( s );
}
/**
* Construct a new CompositionException
instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public CompositionException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
././@LongLink 0000000 0000000 0000000 00000000156 00000000000 011567 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/SetterComponentComposer.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/SetterComponentComp0000644 0001750 0001750 00000026104 10161654653 033274 0 ustar paul paul package org.codehaus.plexus.component.composition;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.beans.Statement;
import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
/**
* @author Michal Maczka
* @version $Id: SetterComponentComposer.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public class SetterComponentComposer extends AbstractComponentComposer
{
public List assembleComponent( final Object component,
final ComponentDescriptor descriptor,
final PlexusContainer container )
throws CompositionException, UndefinedComponentComposerException
{
final List requirements = descriptor.getRequirements();
BeanInfo beanInfo = null;
try
{
beanInfo = Introspector.getBeanInfo( component.getClass() );
}
catch ( IntrospectionException e )
{
reportErrorFailedToIntrospect( descriptor );
}
final List retValue = new LinkedList();
final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for ( final Iterator i = requirements.iterator(); i.hasNext(); )
{
final ComponentRequirement requirement = ( ComponentRequirement ) i.next();
final PropertyDescriptor propertyDescriptor = findMatchingPropertyDescriptor( requirement, propertyDescriptors );
if ( propertyDescriptor != null )
{
final List descriptors = setProperty( component, descriptor, requirement, propertyDescriptor, container );
retValue.addAll( descriptors );
}
else
{
reportErrorNoSuchProperty( descriptor, requirement );
}
}
return retValue;
}
private List setProperty( final Object component,
final ComponentDescriptor descriptor,
final ComponentRequirement requirement,
final PropertyDescriptor propertyDescriptor,
final PlexusContainer container ) throws CompositionException
{
List retValue = null;
final Method writeMethod = propertyDescriptor.getWriteMethod();
final String role = requirement.getRole();
final Object[] params = new Object[ 1 ];
final Class propertyType = propertyDescriptor.getPropertyType();
try
{
if ( propertyType.isArray() )
{
final Map dependencies = container.lookupMap( role );
final Object[] array = ( Object[] ) Array.newInstance( propertyType, dependencies.size() );
retValue = container.getComponentDescriptorList( role );
params[ 0 ] = dependencies.entrySet().toArray( array );
}
else if ( Map.class.isAssignableFrom( propertyType ) )
{
final Map dependencies = container.lookupMap( role );
retValue = container.getComponentDescriptorList( role );
params[ 0 ] = dependencies;
}
else if ( List.class.isAssignableFrom( propertyType ) )
{
// final Map dependencies = container.lookupMap( role );
retValue = container.getComponentDescriptorList( role );
params[ 0 ] = container.lookupList( role );
}
else if ( Set.class.isAssignableFrom( propertyType ) )
{
final Map dependencies = container.lookupMap( role );
retValue = container.getComponentDescriptorList( role );
params[ 0 ] = dependencies.entrySet();
}
else //"ordinary" field
{
final String key = requirement.getRequirementKey();
final Object dependency = container.lookup( key );
final ComponentDescriptor componentDescriptor = container.getComponentDescriptor( key );
retValue = new ArrayList( 1 );
retValue.add( componentDescriptor );
params[ 0 ] = dependency;
}
}
catch ( ComponentLookupException e )
{
reportErrorCannotLookupRequiredComponent( descriptor, requirement, e );
}
final Statement statement = new Statement( component, writeMethod.getName(), params );
try
{
statement.execute();
}
catch ( Exception e )
{
reportErrorCannotAssignRequiredComponent( descriptor, requirement, e );
}
return retValue;
}
/**
* @param requirement
* @return
*/
protected PropertyDescriptor findMatchingPropertyDescriptor( final ComponentRequirement requirement,
final PropertyDescriptor[] propertyDescriptors )
{
PropertyDescriptor retValue = null;
final String property = requirement.getFieldName();
if ( property != null )
{
retValue = getPropertyDescriptorByName( property, propertyDescriptors );
}
else
{
final String role = requirement.getRole();
retValue = getPropertyDescriptorByType( role, propertyDescriptors );
}
return retValue;
}
/**
* @param name
* @return
*/
protected PropertyDescriptor getPropertyDescriptorByName( final String name,
final PropertyDescriptor[] propertyDescriptors )
{
PropertyDescriptor retValue = null;
for ( int i = 0; i < propertyDescriptors.length; i++ )
{
final PropertyDescriptor propertyDescriptor = propertyDescriptors[ i ];
if ( name.equals( propertyDescriptor.getName() ) )
{
retValue = propertyDescriptor;
break;
}
}
return retValue;
}
protected PropertyDescriptor getPropertyDescriptorByType( final String type,
final PropertyDescriptor[] propertyDescriptors )
{
PropertyDescriptor retValue = null;
for ( int i = 0; i < propertyDescriptors.length; i++ )
{
final PropertyDescriptor propertyDescriptor = propertyDescriptors[ i ];
if ( propertyDescriptor.getPropertyType().toString().indexOf( type ) > 0 )
{
retValue = propertyDescriptor;
break;
}
}
return retValue;
}
private void reportErrorNoSuchProperty( final ComponentDescriptor descriptor,
final ComponentRequirement requirement ) throws CompositionException
{
final String causeDescriprion = "Failed to assign requirment using Java Bean introspection mechanism." +
" No matching property was found in bean class";
final String msg = getErrorMessage( descriptor, requirement, causeDescriprion );
throw new CompositionException( msg );
}
private void reportErrorCannotAssignRequiredComponent( final ComponentDescriptor descriptor,
final ComponentRequirement requirement,
final Exception e ) throws CompositionException
{
final String causeDescriprion = "Failed to assign requirment using Java Bean introspection mechanism. ";
final String msg = getErrorMessage( descriptor, requirement, causeDescriprion );
throw new CompositionException( msg );
}
private void reportErrorCannotLookupRequiredComponent( final ComponentDescriptor descriptor,
final ComponentRequirement requirement,
final Throwable cause ) throws CompositionException
{
final String causeDescriprion = "Failed to lookup required component.";
final String msg = getErrorMessage( descriptor, requirement, causeDescriprion );
throw new CompositionException( msg, cause );
}
/**
* @param descriptor
*/
private void reportErrorFailedToIntrospect( final ComponentDescriptor descriptor ) throws CompositionException
{
final String msg = getErrorMessage( descriptor, null, null );
throw new CompositionException( msg );
}
private String getErrorMessage( final ComponentDescriptor descriptor,
final ComponentRequirement requirement,
final String causeDescription )
{
final StringBuffer msg = new StringBuffer( "Component composition failed." );
msg.append( " Failed to resolve requirement for component of role: '" );
msg.append( descriptor.getRole() );
msg.append( "'" );
if ( descriptor.getRoleHint() != null )
{
msg.append( " and role-hint: '" );
msg.append( descriptor.getRoleHint() );
msg.append( "'. " );
}
if ( requirement != null )
{
msg.append( "Failing requirement: " + requirement.getHumanReadableKey() );
}
if ( causeDescription != null )
{
msg.append( causeDescription );
}
return msg.toString();
}
}
././@LongLink 0000000 0000000 0000000 00000000172 00000000000 011565 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/UndefinedComponentComposerException.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/UndefinedComponentC0000644 0001750 0001750 00000001176 10161654653 033215 0 ustar paul paul package org.codehaus.plexus.component.composition;
/**
*
*
* @author Michal Maczka
*
* @version $Id: UndefinedComponentComposerException.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public class UndefinedComponentComposerException
extends Exception
{
public UndefinedComponentComposerException( String message )
{
super( message );
}
public UndefinedComponentComposerException( String message, Throwable cause )
{
super( message, cause );
}
public UndefinedComponentComposerException( Throwable cause )
{
super( cause );
}
}
././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/DefaultCompositionResolver.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/DefaultCompositionR0000644 0001750 0001750 00000005720 10227405046 033250 0 ustar paul paul package org.codehaus.plexus.component.composition;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.util.dag.CycleDetectedException;
import org.codehaus.plexus.util.dag.DAG;
import java.util.Iterator;
import java.util.List;
/**
* @author Michal Maczka
* @version $Id: DefaultCompositionResolver.java 1700 2005-04-14 06:13:58Z brett $
*/
public class DefaultCompositionResolver
implements CompositionResolver
{
private DAG dag = new DAG();
public void addComponentDescriptor( final ComponentDescriptor componentDescriptor )
throws CompositionException
{
final String componentKey = componentDescriptor.getComponentKey();
final List requirements = componentDescriptor.getRequirements();
for ( final Iterator iterator = requirements.iterator(); iterator.hasNext(); )
{
final ComponentRequirement requirement = (ComponentRequirement) iterator.next();
try
{
dag.addEdge( componentKey, requirement.getRole() );
}
catch ( CycleDetectedException e )
{
throw new CompositionException( "Cyclic requirement detected", e );
}
}
}
/**
* @see org.codehaus.plexus.component.composition.CompositionResolver#getRequirements(java.lang.String)
*/
public List getRequirements( final String componentKey )
{
return dag.getChildLabels( componentKey );
}
/**
* @see org.codehaus.plexus.component.composition.CompositionResolver#findRequirements(java.lang.String)
*/
public List findRequirements( final String componentKey )
{
return dag.getParentLabels( componentKey );
}
}
././@LongLink 0000000 0000000 0000000 00000000163 00000000000 011565 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/MapOrientedComponentComposer.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/MapOrientedComponen0000644 0001750 0001750 00000012316 10251162615 033222 0 ustar paul paul package org.codehaus.plexus.component.composition;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.MapOrientedComponent;
import org.codehaus.plexus.component.configurator.ComponentConfigurationException;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import org.codehaus.plexus.component.repository.ComponentRequirement;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.util.StringUtils;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
/*
* Copyright 2001-2005 The 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.
*/
public class MapOrientedComponentComposer
extends AbstractComponentComposer
{
private static final String SINGLE_MAPPING_TYPE = "single";
private static final String MAP_MAPPING_TYPE = "map";
private static final String SET_MAPPING_TYPE = "set";
private static final String DEFAULT_MAPPING_TYPE = SINGLE_MAPPING_TYPE;
public List assembleComponent( Object component, ComponentDescriptor componentDescriptor, PlexusContainer container )
throws CompositionException
{
if ( !( component instanceof MapOrientedComponent ) )
{
throw new CompositionException( "Cannot compose component: " + component.getClass().getName()
+ "; it does not implement " + MapOrientedComponent.class.getName() );
}
List retValue = new LinkedList();
List requirements = componentDescriptor.getRequirements();
for ( Iterator i = requirements.iterator(); i.hasNext(); )
{
ComponentRequirement requirement = (ComponentRequirement) i.next();
List descriptors = addRequirement( (MapOrientedComponent) component, container, requirement );
retValue.addAll( descriptors );
}
return retValue;
}
private List addRequirement( MapOrientedComponent component, PlexusContainer container,
ComponentRequirement requirement )
throws CompositionException
{
try
{
List retValue;
String role = requirement.getRole();
String hint = requirement.getRoleHint();
String mappingType = requirement.getFieldMappingType();
Object value = null;
// if the hint is not empty, we don't care about mapping type...it's a single-value, not a collection.
if ( StringUtils.isNotEmpty( hint ) )
{
String key = requirement.getRequirementKey();
value = container.lookup( key );
ComponentDescriptor componentDescriptor = container.getComponentDescriptor( key );
retValue = Collections.singletonList( componentDescriptor );
}
else if ( SINGLE_MAPPING_TYPE.equals( mappingType ) )
{
String key = requirement.getRequirementKey();
value = container.lookup( key );
ComponentDescriptor componentDescriptor = container.getComponentDescriptor( key );
retValue = Collections.singletonList( componentDescriptor );
}
else if ( MAP_MAPPING_TYPE.equals( mappingType ) )
{
value = container.lookupMap( role );
retValue = container.getComponentDescriptorList( role );
}
else if ( SET_MAPPING_TYPE.equals( mappingType ) )
{
value = new HashSet( container.lookupList( role ) );
retValue = container.getComponentDescriptorList( role );
}
else
{
String key = requirement.getRequirementKey();
value = container.lookup( key );
ComponentDescriptor componentDescriptor = container.getComponentDescriptor( key );
retValue = Collections.singletonList( componentDescriptor );
}
component.addComponentRequirement( requirement, value );
return retValue;
}
catch ( ComponentLookupException e )
{
throw new CompositionException( "Composition failed in object of type " + component.getClass().getName()
+ " because the requirement " + requirement + " was missing", e );
}
catch ( ComponentConfigurationException e )
{
throw new CompositionException( "Composition failed in object of type " + component.getClass().getName()
+ " because the requirement " + requirement + " cannot be set on the component.", e );
}
}
}
././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/CompositionResolver.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/CompositionResolver0000644 0001750 0001750 00000002402 10161654653 033344 0 ustar paul paul package org.codehaus.plexus.component.composition;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
import java.util.List;
/**
*
*
* @author Jason van Zyl
* @author Michal Maczka
*
* @version $Id: CompositionResolver.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public interface CompositionResolver
{
/**
*
* @param componentDescriptor
* @throws CompositionException when cycle is detected
*/
void addComponentDescriptor( ComponentDescriptor componentDescriptor ) throws CompositionException;
/**
* Returns the list of names of components which are required
* by the component of given componentKey.
*
* @param componentKey The name of the component
* @return The list of components which are required by given component
*/
List getRequirements( String componentKey );
/**
* Returns the list of names of components which are using the component.
* of given componentKey
*
* @param componentKey The name of the component
* @return The list of components which are requiring given component
*/
List findRequirements( String componentKey );
}
././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/ComponentComposerManager.java plexus-container-default/src/main/java/org/codehaus/plexus/component/composition/ComponentComposerMa0000644 0001750 0001750 00000001171 10231133376 033241 0 ustar paul paul package org.codehaus.plexus.component.composition;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.ComponentDescriptor;
/**
* @author Michal Maczka
* @version $Id: ComponentComposerManager.java 1750 2005-04-19 07:45:02Z brett $
*/
public interface ComponentComposerManager
{
String ROLE = ComponentComposerManager.class.getName();
void assembleComponent( Object component, final ComponentDescriptor componentDescriptor, final PlexusContainer container )
throws CompositionException, UndefinedComponentComposerException;
}
plexus-container-default/src/main/java/org/codehaus/plexus/PlexusConstants.java 0000644 0001750 0001750 00000000522 10161654653 027050 0 ustar paul paul package org.codehaus.plexus;
public abstract class PlexusConstants
{
/** Key used to retrieve the plexus container from the context. */
public static final String PLEXUS_KEY = "plexus";
/** Key used to retrieve the core classworlds realm from the context.*/
public static final String PLEXUS_CORE_REALM = "coreRealm";
}
plexus-container-default/src/main/java/org/codehaus/plexus/embed/ 0000755 0001750 0001750 00000000000 10631507717 024105 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/embed/Embedder.java 0000644 0001750 0001750 00000015432 10317361503 026454 0 ustar paul paul package org.codehaus.plexus.embed;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.DefaultPlexusContainer;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfigurationResourceException;
import org.codehaus.plexus.util.PropertyUtils;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
public class Embedder implements PlexusEmbedder
{
private Reader configurationReader;
/** Context properties */
private Properties properties;
private final DefaultPlexusContainer container;
private boolean embedderStarted = false;
private boolean embedderStopped = false;
public Embedder()
{
container = new DefaultPlexusContainer();
}
public synchronized PlexusContainer getContainer()
{
if ( !embedderStarted )
{
throw new IllegalStateException( "Embedder must be started" );
}
return container;
}
public Object lookup( String role )
throws ComponentLookupException
{
return getContainer().lookup( role );
}
public Object lookup( String role, String id )
throws ComponentLookupException
{
return getContainer().lookup( role, id );
}
public boolean hasComponent( String role )
{
return getContainer().hasComponent( role );
}
public boolean hasComponent( String role, String id )
{
return getContainer().hasComponent( role, id );
}
public void release( Object service )
throws ComponentLifecycleException
{
getContainer().release( service );
}
//public synchronized void setClassLoader( ClassLoader classLoader )
//{
// container.setClassLoader( classLoader );
//}
public synchronized void setClassWorld( ClassWorld classWorld )
{
container.setClassWorld( classWorld );
}
public synchronized void setConfiguration( URL configuration ) throws IOException {
if ( embedderStarted || embedderStopped )
{
throw new IllegalStateException( "Embedder has already been started" );
}
this.configurationReader = new InputStreamReader(configuration.openStream());
}
public synchronized void setConfiguration( Reader configuration ) throws IOException {
if ( embedderStarted || embedderStopped )
{
throw new IllegalStateException( "Embedder has already been started" );
}
this.configurationReader = configuration;
}
public synchronized void addContextValue( Object key, Object value )
{
if ( embedderStarted || embedderStopped )
{
throw new IllegalStateException( "Embedder has already been started" );
}
container.addContextValue( key, value );
}
public synchronized void setProperties( Properties properties )
{
this.properties = properties;
}
public synchronized void setProperties( File file )
{
properties = PropertyUtils.loadProperties( file );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
public void setLoggerManager( LoggerManager loggerManager )
{
container.setLoggerManager( loggerManager );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
protected synchronized void initializeContext()
{
Set keys = properties.keySet();
for ( Iterator iter = keys.iterator(); iter.hasNext(); )
{
String key = ( String ) iter.next();
String value = properties.getProperty( key );
container.addContextValue( key, value );
}
}
public synchronized void start( ClassWorld classWorld )
throws PlexusContainerException
{
container.setClassWorld( classWorld );
start();
}
public synchronized void start()
throws PlexusContainerException
{
if ( embedderStarted )
{
throw new IllegalStateException( "Embedder already started" );
}
if ( embedderStopped )
{
throw new IllegalStateException( "Embedder cannot be restarted" );
}
if ( configurationReader != null )
{
try
{
container.setConfigurationResource( configurationReader );
}
catch ( PlexusConfigurationResourceException e )
{
throw new PlexusContainerException( "Error loading from configuration reader", e );
}
}
if ( properties != null)
{
initializeContext();
}
container.initialize();
embedderStarted = true;
container.start();
}
public synchronized void stop()
{
if ( embedderStopped )
{
throw new IllegalStateException( "Embedder already stopped" );
}
if ( !embedderStarted )
{
throw new IllegalStateException( "Embedder not started" );
}
container.dispose();
embedderStarted = false;
embedderStopped = true;
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/embed/PlexusEmbedder.java 0000644 0001750 0001750 00000003464 10317361503 027657 0 ustar paul paul /* Created on Oct 7, 2004 */
package org.codehaus.plexus.embed;
import org.codehaus.classworlds.ClassWorld;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.PlexusContainerException;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.configuration.PlexusConfigurationResourceException;
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.net.URL;
import java.util.Properties;
/**
* @author jdcasey
*/
public interface PlexusEmbedder
{
PlexusContainer getContainer();
Object lookup( String role ) throws ComponentLookupException;
Object lookup( String role, String id ) throws ComponentLookupException;
boolean hasComponent( String role );
boolean hasComponent( String role, String id );
void release( Object service )
throws ComponentLifecycleException;
void setClassWorld( ClassWorld classWorld );
void setConfiguration( URL configuration ) throws IOException;
void setConfiguration( Reader configuration ) throws IOException;
void addContextValue( Object key, Object value );
void setProperties( Properties properties );
void setProperties( File file );
void start( ClassWorld classWorld )
throws PlexusContainerException, PlexusConfigurationResourceException;
void start()
throws PlexusContainerException, PlexusConfigurationResourceException;
void stop();
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
void setLoggerManager( LoggerManager loggerManager );
}
plexus-container-default/src/main/java/org/codehaus/plexus/PlexusContainerManager.java 0000644 0001750 0001750 00000001365 10161654653 030317 0 ustar paul paul /*
* $Id: PlexusContainerManager.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
package org.codehaus.plexus;
/**
* PlexusContainerManager
defines the interface for Plexus
* components that can create and manage Plexus containers. An
* implementation of this interface will configure and create Plexus
* containers according to some policy that the component defines;
* for example, a container factory might create a Plexus container for
* each JAR file that exists in a given directory.
*
* @author Mark Wilkinson
* @version $Revision: 1323 $
*/
public interface PlexusContainerManager
{
String ROLE = PlexusContainerManager.class.getName();
PlexusContainer[] getManagedContainers();
}
plexus-container-default/src/main/java/org/codehaus/plexus/context/ 0000755 0001750 0001750 00000000000 10631507706 024513 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/context/ContextException.java 0000644 0001750 0001750 00000007205 10161654653 030667 0 ustar paul paul /* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", 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 (INCLUDING, 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
* ContextException
instance.
*
* @param message The detail message for this exception.
*/
public ContextException( final String message )
{
this( message, null );
}
/**
* Construct a new ContextException
instance.
*
* @param message The detail message for this exception.
* @param throwable the root cause of the exception
*/
public ContextException( final String message, final Throwable throwable )
{
super( message, throwable );
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/context/ContextMapAdapter.java 0000644 0001750 0001750 00000001201 10161654653 030735 0 ustar paul paul package org.codehaus.plexus.context;
import java.util.HashMap;
public class ContextMapAdapter
extends HashMap
{
private Context context;
public ContextMapAdapter( Context context )
{
this.context = context;
}
public Object get( Object key )
{
try
{
Object value = context.get( key );
if ( value instanceof String )
{
return value;
}
else
{
return null;
}
}
catch ( ContextException e )
{
return null;
}
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/context/DefaultContext.java 0000644 0001750 0001750 00000014617 10161654653 030322 0 ustar paul paul package org.codehaus.plexus.context;
/*
* The MIT License
*
* Copyright (c) 2004, The Codehaus
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import java.io.Serializable;
import java.util.Hashtable;
import java.util.Map;
/**
* Default implementation of Context.
*
* This implementation is a static hierarchial store. It has the normal get()
* and put
methods. The hide
method will hide a property. When
* a property has been hidden the context will not search in the parent context for the value.
*
* @author Avalon Development Team
* @version $Id: DefaultContext.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public class DefaultContext
implements Context
{
/** */
private static Hidden HIDDEN_MAKER = new Hidden();
/** Context data. */
private Map contextData;
/** Parent Context. */
private Context parent;
/** Is the context read only. */
private boolean readOnly;
/**
* Create a Context with specified data and parent.
*
* @param contextData the context data
* @param parent the parent Context (may be null)
*/
public DefaultContext( Map contextData, Context parent )
{
this.parent = parent;
this.contextData = contextData;
}
/**
* Create a empty Context with specified data.
*
* @param contextData the context data
*/
public DefaultContext( Map contextData )
{
this( contextData, null );
}
/**
* Create a Context with specified parent.
*
* @param parent the parent Context (may be null)
*/
public DefaultContext( Context parent )
{
this( new Hashtable(), parent );
}
/**
* Create a empty Context with no parent.
*/
public DefaultContext()
{
this( (Context) null );
}
/**
* Returns true if the map or the parent map contains the key.
*
* @param key The key to search for.
* @return Returns true if the key was found.
*/
public boolean contains( Object key )
{
Object data = contextData.get( key );
if ( null != data )
{
if ( data instanceof Hidden )
{
return false;
}
return true;
}
// If data was null, check the parent
if ( null == parent )
{
return false;
}
return parent.contains( key );
}
/**
* Returns the value of the key. If the key can't be found it will throw a exception.
*
* @param key The key of the value to look up.
* @return Returns
* @throws ContextException If the key doesn't exist.
*/
public Object get( Object key )
throws ContextException
{
Object data = contextData.get( key );
if ( data != null )
{
if ( data instanceof Hidden )
{
// Always fail
throw new ContextException( "Unable to locate " + key );
}
return data;
}
// If data was null, check the parent
if ( parent == null )
{
// There was no parent, and no data
throw new ContextException( "Unable to resolve context key: " + key );
}
return parent.get( key );
}
/**
* Helper method for adding items to Context.
*
* @param key the items key
* @param value the item
* @throws java.lang.IllegalStateException if context is read only
*/
public void put( Object key, Object value )
throws IllegalStateException
{
checkWriteable();
if ( null == value )
{
contextData.remove( key );
}
else
{
contextData.put( key, value );
}
}
/**
* Hides the item in the context.
*
* After remove(key) has been called, a get(key)
* will always fail, even if the parent context
* has such a mapping.
*
* @param key the items key
* @throws java.lang.IllegalStateException if context is read only
*/
public void hide( Object key )
throws IllegalStateException
{
checkWriteable();
contextData.put( key, HIDDEN_MAKER );
}
/**
* Utility method to retrieve context data.
*
* @return the context data
*/
protected Map getContextData()
{
return contextData;
}
/**
* Get parent context if any.
*
* @return the parent Context (may be null)
*/
protected Context getParent()
{
return parent;
}
/**
* Make the context read-only.
* Any attempt to write to the context via put()
* will result in an IllegalStateException.
*/
public void makeReadOnly()
{
readOnly = true;
}
/**
* Utility method to check if context is writeable and if not throw exception.
*
* @throws java.lang.IllegalStateException if context is read only
*/
protected void checkWriteable()
throws IllegalStateException
{
if ( readOnly )
{
throw new IllegalStateException( "Context is read only and can not be modified" );
}
}
/**
* This class is only used as a marker in the map to indicate a hidden value.
*/
private static class Hidden
implements Serializable
{
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/context/Context.java 0000644 0001750 0001750 00000007103 10161654653 027005 0 ustar paul paul /* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 1997-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, 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", 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 (INCLUDING, 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
* ContainerHost
.
*
* @author Jason van Zyl
* @author bob mcwhirter
*
* @version $Id: PlexusContainerHost.java 1750 2005-04-19 07:45:02Z brett $
*/
public class PlexusContainerHost
implements Runnable
{
private DefaultPlexusContainer container;
private boolean shouldStop;
private boolean isStopped;
private Object shutdownSignal;
// ----------------------------------------------------------------------
// Constructors
// ----------------------------------------------------------------------
/**
* Constuctor.
*/
public PlexusContainerHost()
{
shutdownSignal = new Object();
}
// ----------------------------------------------------------------------
// Implementation
// ----------------------------------------------------------------------
public PlexusContainer start( ClassWorld classWorld, String configurationResource )
throws FileNotFoundException, PlexusConfigurationResourceException, PlexusContainerException
{
container = getPlexusContainer();
container.setClassWorld( classWorld );
container.setConfigurationResource( new FileReader( configurationResource ) );
customizeContainer( container );
// Move this to the logging subsystem. And there might be a logging directory
// so we need better analsys as the container might be embedded.
File plexusLogs = new File( System.getProperty( "plexus.home" ) + "/logs" );
if ( plexusLogs.exists() == false )
{
plexusLogs.mkdirs();
}
container.initialize();
container.start();
Thread thread = new Thread( this );
thread.setDaemon( false );
Runtime.getRuntime().addShutdownHook( new Thread( new Runnable()
{
public void run()
{
try
{
shutdown();
}
catch ( Exception e )
{
// do nothing.
}
}
} ) );
thread.start();
return container;
}
// ----------------------------------------------------------------------
// Methods for customizing the container
// ----------------------------------------------------------------------
protected DefaultPlexusContainer getPlexusContainer()
{
return new DefaultPlexusContainer();
}
protected void customizeContainer( PlexusContainer container )
{
container.addContextValue( "plexus.home", System.getProperty( "plexus.home" ) );
container.addContextValue( "plexus.work", System.getProperty( "plexus.home" ) + "/work" );
container.addContextValue( "plexus.logs", System.getProperty( "plexus.home" ) + "/logs" );
}
/**
* Asynchronous hosting component loop.
*/
public void run()
{
synchronized ( this )
{
while ( !shouldStop )
{
try
{
wait();
}
catch ( InterruptedException e )
{
//ignore
}
}
}
synchronized ( this )
{
isStopped = true;
notifyAll();
}
}
// ----------------------------------------------------------------------
// Container control
// ----------------------------------------------------------------------
/**
* Shutdown this container.
*/
public void shutdown()
{
synchronized ( this )
{
shouldStop = true;
container.dispose();
notifyAll();
}
synchronized ( this )
{
while ( !isStopped() )
{
try
{
wait();
}
catch ( InterruptedException e )
{
//ignore
}
}
synchronized( shutdownSignal )
{
shutdownSignal.notifyAll();
}
}
}
public void waitForContainerShutdown()
{
while ( !isStopped() )
{
try
{
synchronized( shutdownSignal )
{
shutdownSignal.wait();
}
}
catch ( InterruptedException e )
{
// ignored
}
}
}
public boolean isStopped()
{
return isStopped;
}
/**
* Main entry-point.
*
* @param args Command-line arguments.
*/
public static void main( String[] args, ClassWorld classWorld )
{
if ( args.length != 1 )
{
System.err.println( "usage: plexus * **/ static final String SOURCE = "source"; String getId(); PlexusConfiguration[] handleRequest( Map parameters ) throws ConfigurationResourceNotFoundException, ConfigurationProcessingException; } ././@LongLink 0000000 0000000 0000000 00000000171 00000000000 011564 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/configuration/processor/ConfigurationProcessingException.java plexus-container-default/src/main/java/org/codehaus/plexus/configuration/processor/ConfigurationProc0000644 0001750 0001750 00000003331 10161654653 033275 0 ustar paul paul package org.codehaus.plexus.configuration.processor; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Jason van Zyl * @version $Id: ConfigurationProcessingException.java 1323 2004-12-20 23:00:59Z jvanzyl $ */ public class ConfigurationProcessingException extends Exception { public ConfigurationProcessingException( String message ) { super( message ); } public ConfigurationProcessingException( Throwable cause ) { super( cause ); } public ConfigurationProcessingException( String message, Throwable cause ) { super( message, cause ); } } ././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/configuration/processor/AbstractConfigurationResourceHandler.java plexus-container-default/src/main/java/org/codehaus/plexus/configuration/processor/AbstractConfigura0000644 0001750 0001750 00000003573 10161654653 033253 0 ustar paul paul package org.codehaus.plexus.configuration.processor; import java.util.Map; /* * The MIT License * * Copyright (c) 2004, The Codehaus * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ /** * @author Jason van Zyl * @version $Id: AbstractConfigurationResourceHandler.java 1323 2004-12-20 23:00:59Z jvanzyl $ */ public abstract class AbstractConfigurationResourceHandler implements ConfigurationResourceHandler { protected String getSource( Map parameters ) throws ConfigurationProcessingException { String source = (String) parameters.get( ConfigurationResourceHandler.SOURCE ); if ( source == null ) { throw new ConfigurationProcessingException( "The 'source' attribute for a configuration resource handler cannot be null." ); } return source; } } plexus-container-default/src/main/java/org/codehaus/plexus/logging/ 0000755 0001750 0001750 00000000000 10631507706 024455 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/logging/LogEnabled.java 0000644 0001750 0001750 00000005423 10161654653 027322 0 ustar paul paul /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 1997-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, 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", 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 (INCLUDING, 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 ** * **
Map
's.
*
* @param role The component role.
* @param roleHint The component role hint.
* @return Returns a string thats useful as a key for components.
*/
protected String toMapKey( String role, String roleHint )
{
if ( roleHint == null )
{
return role;
}
else
{
return role + ":" + roleHint;
}
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/logging/AbstractLogger.java 0000644 0001750 0001750 00000004433 10231120071 030205 0 ustar paul paul package org.codehaus.plexus.logging;
/*
* LICENSE
*/
/**
* @author Trygve Laugstøl
* @version $Id: AbstractLogger.java 1748 2005-04-19 06:07:53Z brett $
*/
public abstract class AbstractLogger
implements Logger
{
private int threshold;
private String name;
public AbstractLogger( int threshold, String name )
{
if ( !isValidThreshold( threshold ) )
{
throw new IllegalArgumentException( "Threshold " + threshold + " is not valid" );
}
this.threshold = threshold;
this.name = name;
}
public int getThreshold()
{
return threshold;
}
public void setThreshold( int threshold )
{
this.threshold = threshold;
}
public String getName()
{
return name;
}
public void debug( String message )
{
debug( message, null );
}
public boolean isDebugEnabled()
{
return threshold <= LEVEL_DEBUG;
}
public void info( String message )
{
info( message, null );
}
public boolean isInfoEnabled()
{
return threshold <= LEVEL_INFO;
}
public void warn( String message )
{
warn( message, null );
}
public boolean isWarnEnabled()
{
return threshold <= LEVEL_WARN;
}
public void error( String message )
{
error( message, null );
}
public boolean isErrorEnabled()
{
return threshold <= LEVEL_ERROR;
}
public void fatalError( String message )
{
fatalError( message, null );
}
public boolean isFatalErrorEnabled()
{
return threshold <= LEVEL_FATAL;
}
protected boolean isValidThreshold( int threshold )
{
if ( threshold == LEVEL_DEBUG )
{
return true;
}
if ( threshold == LEVEL_INFO )
{
return true;
}
if ( threshold == LEVEL_WARN )
{
return true;
}
if ( threshold == LEVEL_ERROR )
{
return true;
}
if ( threshold == LEVEL_FATAL )
{
return true;
}
if ( threshold == LEVEL_DISABLED )
{
return true;
}
return false;
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/logging/LoggerManager.java 0000644 0001750 0001750 00000002406 10161654653 030036 0 ustar paul paul package org.codehaus.plexus.logging;
/**
* @author Jason van Zyl
* @author Trygve Laugstøl
* @version $Id: LoggerManager.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public interface LoggerManager
{
String ROLE = LoggerManager.class.getName();
/**
* Sets the threshold for all new loggers. It will NOT affect the existing loggers.
*
* This is usually only set once while the logger manager is configured.
*
* @param threshold The new threshold.
*/
void setThreshold( int threshold );
/**
* Returns the current threshold for all new loggers.
*
* @return Returns the current threshold for all new loggers.
*/
int getThreshold();
// The new stuff
void setThreshold( String role, int threshold );
void setThreshold( String role, String roleHint, int threshold );
int getThreshold( String role );
int getThreshold( String role, String roleHint );
Logger getLoggerForComponent( String role );
Logger getLoggerForComponent( String role, String roleHint );
void returnComponentLogger( String role );
void returnComponentLogger( String role, String hint );
int getActiveLoggerCount();
}
plexus-container-default/src/main/java/org/codehaus/plexus/logging/BaseLoggerManager.java 0000644 0001750 0001750 00000007324 10231133376 030625 0 ustar paul paul package org.codehaus.plexus.logging;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
import java.util.HashMap;
import java.util.Map;
/**
* Base class for all LoggerManagers which use cache of Loggers.
*
* @author Michal Maczka
* @version $Id: BaseLoggerManager.java 1750 2005-04-19 07:45:02Z brett $
*/
public abstract class BaseLoggerManager
extends AbstractLoggerManager implements Initializable
{
/** */
private Map loggerCache = new HashMap();
private String threshold = "info";
private int currentThreshold;
public void initialize()
{
currentThreshold = parseThreshold( threshold );
if ( currentThreshold == -1 )
{
currentThreshold = Logger.LEVEL_DEBUG;
}
}
protected int parseThreshold( String text )
{
text = text.trim().toLowerCase();
if ( text.equals( "debug" ) )
{
return Logger.LEVEL_DEBUG;
}
else if ( text.equals( "info" ) )
{
return Logger.LEVEL_INFO;
}
else if ( text.equals( "warn" ) )
{
return Logger.LEVEL_WARN;
}
else if ( text.equals( "error" ) )
{
return Logger.LEVEL_ERROR;
}
else if ( text.equals( "fatal" ) )
{
return Logger.LEVEL_FATAL;
}
return -1;
}
/**
* Sets the threshold for all new loggers. It will NOT affect the existing loggers.
*
* This is usually only set once while the logger manager is configured.
*
* @param currentThreshold The new threshold.
*/
public void setThreshold( int currentThreshold )
{
this.currentThreshold = currentThreshold;
}
/**
* Returns the current threshold for all new loggers.
*
* @return Returns the current threshold for all new loggers.
*/
public int getThreshold()
{
return currentThreshold;
}
public void setThreshold( String role, String roleHint, int threshold )
{
AbstractLogger logger;
String key = toMapKey( role, roleHint );
logger = ( AbstractLogger ) loggerCache.get( key );
if ( logger == null )
{
return; // nothing to do
}
logger.setThreshold( threshold );
}
public int getThreshold( String role, String roleHint )
{
AbstractLogger logger;
String key = toMapKey( role, roleHint );
logger = ( AbstractLogger ) loggerCache.get( key );
if ( logger == null )
{
return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE
}
return logger.getThreshold();
}
public Logger getLoggerForComponent( String role, String roleHint )
{
Logger logger;
String key = toMapKey( role, roleHint );
logger = ( Logger ) loggerCache.get( key );
if ( logger != null )
{
return logger;
}
logger = createLogger( key );
loggerCache.put( key, logger );
return logger;
}
protected abstract Logger createLogger( String key );
public void returnComponentLogger( String role, String roleHint )
{
Object obj;
String key = toMapKey( role, roleHint );
obj = loggerCache.remove( key );
if ( obj == null )
{
// TODO: use a logger!
System.err.println( "There was no such logger '" + key + "' " + hashCode() + "." );
}
}
public int getActiveLoggerCount()
{
return loggerCache.size();
}
public String getThresholdAsString()
{
return threshold;
}
}
plexus-container-default/src/main/java/org/codehaus/plexus/logging/console/ 0000755 0001750 0001750 00000000000 10631507706 026117 5 ustar paul paul plexus-container-default/src/main/java/org/codehaus/plexus/logging/console/ConsoleLogger.java 0000644 0001750 0001750 00000004543 10161654653 031534 0 ustar paul paul package org.codehaus.plexus.logging.console;
import org.codehaus.plexus.logging.AbstractLogger;
import org.codehaus.plexus.logging.Logger;
/**
* Logger sending everything to the standard output streams.
* This is mainly for the cases when you have a utility that
* does not have a logger to supply.
*
* @author Avalon Development Team
* @version $Id: ConsoleLogger.java 1323 2004-12-20 23:00:59Z jvanzyl $
*/
public final class ConsoleLogger
extends AbstractLogger
{
public ConsoleLogger( int threshold, String name )
{
super( threshold, name );
}
public void debug( String message, Throwable throwable )
{
if ( isDebugEnabled() )
{
System.out.print( "[DEBUG] " );
System.out.println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void info( String message, Throwable throwable )
{
if ( isInfoEnabled() )
{
System.out.print( "[INFO] " );
System.out.println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void warn( String message, Throwable throwable )
{
if ( isWarnEnabled() )
{
System.out.print( "[WARNING] " );
System.out.println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void error( String message, Throwable throwable )
{
if ( isErrorEnabled() )
{
System.out.print( "[ERROR] " );
System.out.println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public void fatalError( String message, Throwable throwable )
{
if ( isFatalErrorEnabled() )
{
System.out.print( "[FATAL ERROR] " );
System.out.println( message );
if ( null != throwable )
{
throwable.printStackTrace( System.out );
}
}
}
public Logger getChildLogger( String name )
{
return this;
}
}
././@LongLink 0000000 0000000 0000000 00000000145 00000000000 011565 L ustar root root plexus-container-default/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java plexus-container-default/src/main/java/org/codehaus/plexus/logging/console/ConsoleLoggerManager.java0000644 0001750 0001750 00000013360 10161654653 033024 0 ustar paul paul package org.codehaus.plexus.logging.console;
import java.util.HashMap;
import java.util.Map;
import org.codehaus.plexus.logging.AbstractLoggerManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.LoggerManager;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
/**
* This is a simple logger manager that will only write the logging statements to the console.
*
* Sample configuration:
* ** * @author Jason van Zyl * @author Trygve Laugstøl * @version $Id: ConsoleLoggerManager.java 1323 2004-12-20 23:00:59Z jvanzyl $ */ public class ConsoleLoggerManager extends AbstractLoggerManager implements LoggerManager, Initializable { /** * Message of this level or higher will be logged. * * This field is set by the plexus container thus the name is 'threshold'. The field * currentThreshold contains the current setting of the threshold. */ private String threshold = "info"; private int currentThreshold; private Map loggers; /** The number of active loggers in use. */ private int loggerCount; private boolean bootTimeLogger = false; /** */ public ConsoleLoggerManager() { } /** * This special constructor is called directly when the container is bootstrapping itself. */ public ConsoleLoggerManager( String threshold ) { this.threshold = threshold; bootTimeLogger = true; initialize(); } public void initialize() { debug( "Initializing ConsoleLoggerManager: " + this.hashCode() + "." ); // if ( !bootTimeLogger ) // new Throwable().printStackTrace(System.err); currentThreshold = parseThreshold( threshold ); if ( currentThreshold == -1 ) { debug( "Could not parse the threshold level: '" + threshold + "', setting to debug." ); currentThreshold = Logger.LEVEL_DEBUG; } loggers = new HashMap(); } public void setThreshold( int currentThreshold ) { this.currentThreshold = currentThreshold; } /** * @return Returns the threshold. */ public int getThreshold() { return currentThreshold; } // new stuff public void setThreshold( String role, String roleHint, int threshold ) { ConsoleLogger logger; String name; name = toMapKey( role, roleHint ); logger = (ConsoleLogger)loggers.get( name ); if(logger == null) { debug( "Trying to set the threshold of a unknown logger '" + name + "'." ); return; // nothing to do } logger.setThreshold( threshold ); } public int getThreshold( String role, String roleHint ) { ConsoleLogger logger; String name; name = toMapKey( role, roleHint ); logger = (ConsoleLogger)loggers.get( name ); if(logger == null) { debug( "Trying to get the threshold of a unknown logger '" + name + "'." ); return Logger.LEVEL_DEBUG; // does not return null because that could create a NPE } return logger.getThreshold(); } public Logger getLoggerForComponent( String role, String roleHint ) { Logger logger; String name; name = toMapKey( role, roleHint ); logger = (Logger)loggers.get( name ); if ( logger != null ) return logger; debug( "Creating logger '" + name + "' " + this.hashCode() + "." ); logger = new ConsoleLogger( getThreshold(), name ); loggers.put( name, logger ); return logger; } public void returnComponentLogger( String role, String roleHint ) { Object obj; String name; name = toMapKey( role, roleHint ); obj = loggers.remove( name ); if ( obj == null ) { debug( "There was no such logger '" + name + "' " + this.hashCode() + "."); } else { debug( "Removed logger '" + name + "' " + this.hashCode() + "."); } } public int getActiveLoggerCount() { return loggers.size(); } private int parseThreshold( String text ) { text = text.trim().toLowerCase(); if ( text.equals( "debug" ) ) { return ConsoleLogger.LEVEL_DEBUG; } else if ( text.equals( "info" ) ) { return ConsoleLogger.LEVEL_INFO; } else if ( text.equals( "warn" ) ) { return ConsoleLogger.LEVEL_WARN; } else if ( text.equals( "error" ) ) { return ConsoleLogger.LEVEL_ERROR; } else if ( text.equals( "fatal" ) ) { return ConsoleLogger.LEVEL_FATAL; } return -1; } private String decodeLogLevel( int logLevel ) { switch(logLevel) { case ConsoleLogger.LEVEL_DEBUG: return "debug"; case ConsoleLogger.LEVEL_INFO: return "info"; case ConsoleLogger.LEVEL_WARN: return "warn"; case ConsoleLogger.LEVEL_ERROR: return "error"; case ConsoleLogger.LEVEL_FATAL: return "fatal"; case ConsoleLogger.LEVEL_DISABLED: return "disabled"; default: return "unknown"; } } /** * Remove this method and all references when this code is verified. * * @param msg */ private void debug( String msg ) { // if ( !bootTimeLogger ) // System.out.println( "[Console] " + msg ); } } plexus-container-default/src/main/java/org/codehaus/plexus/logging/Logger.java 0000644 0001750 0001750 00000010254 10161654653 026543 0 ustar paul paul /* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 1997-2003 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, 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", 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 (INCLUDING, 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 ** *org.codehaus.plexus.logging.ConsoleLoggerManager ** *DEBUG *