You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Eung-ju Park <co...@isoft.co.kr> on 2001/03/18 11:19:13 UTC
Re: cvs commit: jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys DefaultComponentBuilder.java DefaultComponentManagerBuilder.java DefaultConfigurationRepository.java DefaultContextBuilder.java DefaultLogManager.java DefaultLoggerBuilder.
Hi.
I found another spelling mistake. :-)
in /org/apache/phoenix/engine
$ grep Entrys *.java
My English dictionary says plural of "entry" is "entries". ;-)
Good Luck.
----- Original Message -----
From: <do...@apache.org>
To: <ja...@apache.org>
Sent: Sunday, March 18, 2001 5:35 PM
Subject: cvs commit:
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilitys
DefaultComponentBuilder.java DefaultComponentManagerBuilder.java
DefaultConfigurationRepository.java DefaultContextBuilder.java
DefaultLogManager.java DefaultLoggerBuilder.java DefaultPolicy.java
DefaultThreadManager.java SarBlockFactory.java SarClassLoader.java
> donaldp 01/03/18 00:35:07
>
> Modified: src/java/org/apache/phoenix/engine
> DefaultServerApplication.java
> Added: src/java/org/apache/phoenix/engine/facilities
> DefaultComponentBuilder.java
> DefaultComponentManagerBuilder.java
> DefaultConfigurationRepository.java
> DefaultContextBuilder.java DefaultLogManager.java
> DefaultLoggerBuilder.java DefaultPolicy.java
> DefaultThreadManager.java SarBlockFactory.java
> SarClassLoader.java
> Removed: src/java/org/apache/phoenix/engine/facilitys
> DefaultComponentBuilder.java
> DefaultComponentManagerBuilder.java
> DefaultConfigurationRepository.java
> DefaultContextBuilder.java DefaultLogManager.java
> DefaultLoggerBuilder.java DefaultPolicy.java
> DefaultThreadManager.java SarBlockFactory.java
> SarClassLoader.java
> Log:
> Change package name facilitys to facilities to fix spelling mistake ;)
>
> Revision Changes Path
> 1.7 +9 -9
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultServerAppli
cation.java
>
> Index: DefaultServerApplication.java
> ===================================================================
> RCS file:
/home/cvs/jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/DefaultS
erverApplication.java,v
> retrieving revision 1.6
> retrieving revision 1.7
> diff -u -r1.6 -r1.7
> --- DefaultServerApplication.java 2001/02/28 08:28:32 1.6
> +++ DefaultServerApplication.java 2001/03/18 08:35:02 1.7
> @@ -39,15 +39,15 @@
> import org.apache.phoenix.engine.blocks.BlockDAG;
> import org.apache.phoenix.engine.blocks.BlockEntry;
> import org.apache.phoenix.engine.blocks.RoleEntry;
> -import org.apache.phoenix.engine.facilitys.DefaultComponentBuilder;
> -import
org.apache.phoenix.engine.facilitys.DefaultComponentManagerBuilder;
> -import
org.apache.phoenix.engine.facilitys.DefaultConfigurationRepository;
> -import org.apache.phoenix.engine.facilitys.DefaultContextBuilder;
> -import org.apache.phoenix.engine.facilitys.DefaultLogManager;
> -import org.apache.phoenix.engine.facilitys.DefaultLoggerBuilder;
> -import org.apache.phoenix.engine.facilitys.DefaultPolicy;
> -import org.apache.phoenix.engine.facilitys.DefaultThreadManager;
> -import org.apache.phoenix.engine.facilitys.SarClassLoader;
> +import org.apache.phoenix.engine.facilities.DefaultComponentBuilder;
> +import
org.apache.phoenix.engine.facilities.DefaultComponentManagerBuilder;
> +import
org.apache.phoenix.engine.facilities.DefaultConfigurationRepository;
> +import org.apache.phoenix.engine.facilities.DefaultContextBuilder;
> +import org.apache.phoenix.engine.facilities.DefaultLogManager;
> +import org.apache.phoenix.engine.facilities.DefaultLoggerBuilder;
> +import org.apache.phoenix.engine.facilities.DefaultPolicy;
> +import org.apache.phoenix.engine.facilities.DefaultThreadManager;
> +import org.apache.phoenix.engine.facilities.SarClassLoader;
> import org.apache.phoenix.engine.phases.DefaultPhase;
> import org.apache.phoenix.engine.phases.Phase;
> import org.apache.phoenix.engine.phases.Traversal;
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
ComponentBuilder.java
>
> Index: DefaultComponentBuilder.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.Component;
> import org.apache.avalon.ComponentManager;
> import org.apache.avalon.ComponentManagerException;
> import org.apache.avalon.Composer;
> import org.apache.avalon.Initializable;
> import org.apache.avalon.atlantis.ApplicationException;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.camelot.Entry;
> import org.apache.avalon.camelot.Factory;
> import org.apache.avalon.camelot.FactoryException;
> import org.apache.avalon.camelot.pipeline.ComponentBuilder;
> import org.apache.log.Logger;
> import org.apache.phoenix.Block;
> import org.apache.phoenix.engine.blocks.BlockEntry;
> import org.apache.phoenix.metainfo.BlockUtil;
> import org.apache.phoenix.metainfo.ServiceInfo;
>
> /**
> * Component responsible for building componentManager information for
entry.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultComponentBuilder
> extends AbstractLoggable
> implements Facility, ComponentBuilder, Composer, Initializable
> {
> protected SarBlockFactory m_factory = new SarBlockFactory();
>
> public void setLogger( final Logger logger )
> {
> super.setLogger( logger );
> setupLogger( m_factory, "<core>.factory" );
> }
>
> public void compose( final ComponentManager componentManager )
> throws ComponentManagerException
> {
> m_factory.compose( componentManager );
> }
>
> public void init()
> throws Exception
> {
> m_factory.init();
> }
>
> public Object createComponent( final String name, final Entry
entry )
> throws Exception
> {
> getLogger().info( "Creating block " + name );
>
> final BlockEntry blockEntry = (BlockEntry)entry;
>
> Block block = null;
>
> try { block = (Block)m_factory.create( blockEntry.getLocator(),
Block.class ); }
> catch( final FactoryException fe )
> {
> throw new ApplicationException( "Failed to create block " +
name, fe );
> }
>
> getLogger().debug( "Created block " + block );
> verifyBlockServices( name, blockEntry, block );
>
> return block;
> }
>
> /**
> * Verify that all the services that a block
> * declares it provides are actually provided.
> *
> * @param name the name of block
> * @param blockEntry the blockEntry
> * @param block the Block
> * @exception ApplicationException if verification fails
> */
> protected void verifyBlockServices( final String name,
> final BlockEntry blockEntry,
> final Block block )
> throws ApplicationException
> {
> final ServiceInfo[] services =
blockEntry.getBlockInfo().getServices();
> for( int i = 0; i < services.length; i++ )
> {
> if( false == BlockUtil.implementsService( block,
services[ i ] ) )
> {
> final String message = "Block " + name + " fails to
implement " +
> "advertised service " + services[ i ];
> getLogger().warn( message );
> throw new ApplicationException( message );
> }
> }
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
ComponentManagerBuilder.java
>
> Index: DefaultComponentManagerBuilder.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import org.apache.avalon.ComponentManager;
> import org.apache.avalon.ComponentManagerException;
> import org.apache.avalon.Composer;
> import org.apache.avalon.DefaultComponentManager;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.camelot.ContainerException;
> import org.apache.avalon.camelot.Entry;
> import org.apache.avalon.camelot.pipeline.ComponentManagerBuilder;
> import org.apache.phoenix.engine.ServerApplication;
> import org.apache.phoenix.engine.blocks.BlockEntry;
> import org.apache.phoenix.engine.blocks.RoleEntry;
>
> /**
> * Component responsible for building componentManager information for
entry.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultComponentManagerBuilder
> implements Facility, ComponentManagerBuilder, Composer
> {
> file://container to get dependencies from
> protected ServerApplication m_serverApplication;
>
> public void compose( final ComponentManager componentManager )
> throws ComponentManagerException
> {
> m_serverApplication = (ServerApplication)componentManager.
> lookup( "org.apache.phoenix.engine.ServerApplication" );
> }
>
> /**
> * Build a ComponentManager for a specific Block.
> *
> * @param name the name of the block
> * @param entry the BlockEntry
> * @return the created ComponentManager
> */
> public ComponentManager createComponentManager( String name, Entry
entry )
> throws ComponentManagerException
> {
> final DefaultComponentManager componentManager = new
DefaultComponentManager();
> final RoleEntry[] roleEntrys =
((BlockEntry)entry).getRoleEntrys();
>
> for( int i = 0; i < roleEntrys.length; i++ )
> {
> final String dependencyName = roleEntrys[ i ].getName();
>
> try
> {
> file://dependency should NEVER be null here as it
> file://is validated at entry time
> final BlockEntry dependency =
>
BlockEntry)m_serverApplication.getEntry( dependencyName );
> componentManager.put( roleEntrys[ i ].getRole(),
dependency.getBlock() );
> }
> catch( final ContainerException ce ) {}
> }
>
> return componentManager;
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
ConfigurationRepository.java
>
> Index: DefaultConfigurationRepository.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.camelot.Entry;
> import org.apache.avalon.camelot.pipeline.ConfigurationRepository;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> import org.apache.phoenix.engine.blocks.BlockEntry;
>
> /**
> * Repository from which all configuration data is retrieved.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultConfigurationRepository
> implements Facility, ConfigurationRepository
> {
> public Configuration getConfiguration( String name, Entry entry )
> throws ConfigurationException
> {
> final BlockEntry blockEntry = (BlockEntry)entry;
> return blockEntry.getConfiguration();
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
ContextBuilder.java
>
> Index: DefaultContextBuilder.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.io.File;
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.ComponentManager;
> import org.apache.avalon.ComponentManagerException;
> import org.apache.avalon.Composer;
> import org.apache.avalon.Context;
> import org.apache.avalon.Contextualizable;
> import org.apache.avalon.DefaultContext;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.camelot.Entry;
> import org.apache.avalon.camelot.pipeline.ContextBuilder;
> import org.apache.avalon.util.thread.ThreadManager;
> import org.apache.phoenix.BlockContext;
> import org.apache.phoenix.engine.SarContextResources;
> import org.apache.phoenix.engine.blocks.DefaultBlockContext;
>
> /**
> * Component responsible for building context information for block.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultContextBuilder
> extends AbstractLoggable
> implements Facility, ContextBuilder, Contextualizable, Composer
> {
> file://context used to setup hosted blocks
> protected DefaultContext m_baseBlockContext;
>
> file://thread manager used to build contexts with
> protected ThreadManager m_threadManager;
>
> public void contextualize( final Context context )
> {
> final File baseDirectory =
File)context.get( SarContextResources.APP_HOME_DIR );
> final String name =
String)context.get( SarContextResources.APP_NAME );
>
> file://base contxt that all block contexts inherit from
> final DefaultContext blockContext = new DefaultContext();
> blockContext.put( BlockContext.APP_NAME, name );
> blockContext.put( BlockContext.APP_HOME_DIR, baseDirectory );
> m_baseBlockContext = blockContext;
> }
>
> public void compose( final ComponentManager componentManager )
> throws ComponentManagerException
> {
> m_threadManager = (ThreadManager)componentManager.
> lookup( "org.apache.avalon.util.thread.ThreadManager" );
> }
>
> public Context createContext( String name, Entry entry )
> {
> final DefaultBlockContext context =
> new DefaultBlockContext( getLogger(), m_threadManager,
m_baseBlockContext );
> context.put( BlockContext.NAME, name );
> return context;
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
LogManager.java
>
> Index: DefaultLogManager.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this
distribution in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.io.File;
> import java.io.IOException;
> import java.lang.reflect.InvocationTargetException;
> import java.lang.reflect.Method;
> import java.util.Iterator;
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.Context;
> import org.apache.avalon.Contextualizable;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.configuration.Configurable;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> import org.apache.avalon.util.log.AvalonLogFormatter;
> import org.apache.log.Category;
> import org.apache.log.LogKit;
> import org.apache.log.LogTarget;
> import org.apache.log.output.FileOutputLogTarget;
>
> /**
> * Component responsible for managing logs.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultLogManager
> extends AbstractLoggable
> implements Facility, Contextualizable, Configurable
> {
> protected String m_baseName;
> protected File m_baseDirectory;
>
> public void contextualize( final Context context )
> {
> m_baseName = (String)context.get( "name" );
> if( null == m_baseName ) m_baseName = "<base>";
>
> m_baseDirectory = (File)context.get( "directory" );
> if( null == m_baseDirectory ) m_baseDirectory = new File( "." );
> }
>
> public void configure( final Configuration configuration )
> throws ConfigurationException
> {
> final Configuration[] targets =
onfiguration.getChildren( "log-target" );
> configureTargets( m_baseName, m_baseDirectory, targets );
>
> final Configuration[] categories =
onfiguration.getChildren( "category" );
> configureCategories( m_baseName, categories );
>
> /*
> final String logPriority =
onfiguration.getChild( "global-priority" ).getValue();
> final Priority.Enum priority =
ogKit.getPriorityForName( logPriority );
> LogKit.setGlobalPriority( priority );
> */
> }
>
> protected void configureTargets( final String baseName,
> final File baseDirectory,
> final Configuration[] targets )
> throws ConfigurationException
> {
> for( int i = 0; i < targets.length; i++ )
> {
> final Configuration target = targets[ i ];
> final String name = baseName + '.' +
arget.getAttribute( "name" );
> String location = target.getAttribute( "location" ).trim();
> final String format = target.getAttribute( "format", null );
>
> if( '/' == location.charAt( 0 ) )
> {
> location = location.substring( 1 );
> }
>
> final File file = new File( baseDirectory, location );
>
> final FileOutputLogTarget logTarget = new
FileOutputLogTarget();
> final AvalonLogFormatter formatter = new
AvalonLogFormatter();
> formatter.setFormat( "%{time} [%7.7{priority}]
<<%{category}>> " +
> "(%{context}):
%{message}\\n%{throwable}" );
> logTarget.setFormatter( formatter );
>
> try { logTarget.setFilename( file.getAbsolutePath() ); }
> catch( final IOException ioe )
> {
> throw new ConfigurationException( "Error initializing
log files", ioe );
> }
>
> if( null != format )
> {
> logTarget.setFormat( format );
> }
>
> LogKit.addLogTarget( name, logTarget );
> }
> }
>
> protected void configureCategories( final String baseName, final
Configuration[] categories )
> throws ConfigurationException
> {
> for( int i = 0; i < categories.length; i++ )
> {
> final Configuration category = categories[ i ];
> String name = category.getAttribute( "name" );
> final String target = baseName + '.' +
category.getAttribute( "target" );
> final String priority = category.getAttribute( "priority" );
>
> if( name.trim().equals( "" ) )
> {
> name = baseName;
> }
> else
> {
> name = baseName + '.' + name;
> }
>
> final Category logCategory =
> LogKit.createCategory( name,
ogKit.getPriorityForName( priority ) );
> final LogTarget logTarget = LogKit.getLogTarget( target );
> LogTarget logTargets[] = null;
>
> if( null != target ) logTargets = new LogTarget[]
logTarget };
>
> LogKit.createLogger( logCategory, logTargets );
> }
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
LoggerBuilder.java
>
> Index: DefaultLoggerBuilder.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.camelot.Entry;
> import org.apache.avalon.camelot.pipeline.LoggerBuilder;
> import org.apache.log.Logger;
>
> /**
> * Component responsible for building logger for entry.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultLoggerBuilder
> extends AbstractLoggable
> implements LoggerBuilder, Facility
> {
> public Logger createLogger( final String name, final Entry entry )
> {
> return getLogger().getChildLogger( name );
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
Policy.java
>
> Index: DefaultPolicy.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.io.File;
> import java.io.InputStream;
> import java.lang.reflect.Constructor;
> import java.net.MalformedURLException;
> import java.net.URL;
> import java.security.KeyStore;
> import java.security.KeyStoreException;
> import java.security.Permission;
> import java.security.PermissionCollection;
> import java.security.Permissions;
> import java.security.UnresolvedPermission;
> import java.security.cert.Certificate;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.Hashtable;
> import java.util.Iterator;
> import java.util.PropertyPermission;
> import java.util.StringTokenizer;
> import org.apache.avalon.Component;
> import org.apache.avalon.Context;
> import org.apache.avalon.Contextualizable;
> import org.apache.avalon.DefaultContext;
> import org.apache.avalon.Initializable;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.configuration.Configurable;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> import org.apache.avalon.util.PropertyException;
> import org.apache.avalon.util.PropertyUtil;
> import org.apache.avalon.util.security.AbstractPolicy;
>
> /**
> * Policy that extracts information from policy files.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultPolicy
> extends AbstractPolicy
> implements Facility, Contextualizable, Configurable, Initializable
> {
> protected DefaultContext m_context;
>
> public void contextualize( final Context context )
> {
> m_context = new DefaultContext( System.getProperties(),
context );
> m_context.put( "/", File.separator );
> }
>
> public void configure( final Configuration configuration )
> throws ConfigurationException
> {
> final Configuration[] keyStoreConfigurations =
configuration.getChildren( "keystore" );
> final HashMap keyStores =
onfigureKeyStores( keyStoreConfigurations );
>
> final Configuration[] grants =
onfiguration.getChildren( "grant" );
> configureGrants( grants, keyStores );
> }
>
> public void init()
> throws Exception
> {
> file://these properties straight out ot
${java.home}/lib/security/java.policy
> final Permissions permissions =
reatePermissionSetFor( "file:/-", null );
>
> permissions.add( new PropertyPermission( "os.name", "read" ) );
> permissions.add( new PropertyPermission( "os.arch", "read" ) );
> permissions.add( new PropertyPermission( "os.version",
"read" ) );
> permissions.add( new PropertyPermission( "file.separator",
"read" ) );
> permissions.add( new PropertyPermission( "path.separator",
"read" ) );
> permissions.add( new PropertyPermission( "line.separator",
"read" ) );
>
> permissions.add( new PropertyPermission( "java.version",
"read" ) );
> permissions.add( new PropertyPermission( "java.vendor",
"read" ) );
> permissions.add( new PropertyPermission( "java.vendor.url",
"read" ) );
>
> permissions.add( new PropertyPermission( "java.class.version",
"read" ) );
> permissions.add( new PropertyPermission( "java.vm.version",
"read" ) );
> permissions.add( new PropertyPermission( "java.vm.vendor",
"read" ) );
> permissions.add( new PropertyPermission( "java.vm.name",
"read" ) );
>
> permissions.add( new
ropertyPermission( "java.specification.version", "read" ) );
> permissions.add( new
ropertyPermission( "java.specification.vendor", "read" ) );
> permissions.add( new
ropertyPermission( "java.specification.name", "read" ) );
> permissions.add( new
ropertyPermission( "java.vm.specification.version", "read" ) );
> permissions.add( new
ropertyPermission( "java.vm.specification.vendor", "read" ) );
> permissions.add( new
ropertyPermission( "java.vm.specification.name", "read" ) );
> }
>
> protected HashMap configureKeyStores( final Configuration[]
configurations )
> throws ConfigurationException
> {
> final HashMap keyStores = new HashMap();
>
> for( int i = 0; i < configurations.length; i++ )
> {
> final Configuration configuration = configurations[ i ];
> final String type = configuration.getAttribute( "type" );
> final String location =
onfiguration.getAttribute( "location" );
> final String name = configuration.getAttribute( "name" );
>
> try
> {
> final KeyStore keyStore = KeyStore.getInstance( type );
> final URL url = new URL( location );
> final InputStream ins = url.openStream();
>
> keyStore.load( ins, null );
>
> keyStores.put( name, keyStore );
> }
> catch( final Exception e )
> {
> throw new ConfigurationException( "Error configuring
keystore " + name, e );
> }
> }
>
> return keyStores;
> }
>
> protected void configureGrants( final Configuration[]
configurations,
> final HashMap keyStores )
> throws ConfigurationException
> {
> for( int i = 0; i < configurations.length; i++ )
> {
> configureGrant( configurations[ i ], keyStores );
> }
> }
>
> protected void configureGrant( final Configuration configuration,
final HashMap keyStores )
> throws ConfigurationException
> {
> file://<grant signed-by="Fred"
code-base="file:${sar.home}/blocks/*" key-store="foo-keystore">
> file://<permission class="java.io.FilePermission"
target="/tmp/*" action="read,write" />
> file://</grant>
>
> final String signedBy = configuration.getAttribute( "signed-by",
null );
> final String keyStoreName =
onfiguration.getAttribute( "key-store", null );
>
> String codeBase = configuration.getAttribute( "code-base",
null );
> if( null != codeBase )
> {
> codeBase = expand( codeBase );
> }
>
> final Certificate[] signers = getSigners( signedBy,
keyStoreName, keyStores );
>
> Permissions permissions = null;
>
> try { permissions = createPermissionSetFor( codeBase,
signers ); }
> catch( final MalformedURLException mue )
> {
> throw new ConfigurationException( "Malformed code-base " +
codeBase, mue );
> }
>
>
> configurePermissions( configuration.getChildren( "permission" ),
> permissions,
> keyStores );
> }
>
> protected void configurePermissions( final Configuration[]
configurations,
> final Permissions permissions,
> final HashMap keyStores )
> throws ConfigurationException
> {
> for( int i = 0; i < configurations.length; i++ )
> {
> configurePermission( configurations[ i ], permissions,
keyStores );
> }
> }
>
> protected void configurePermission( final Configuration
configuration,
> final Permissions permissions,
> final HashMap keyStores )
> throws ConfigurationException
> {
> final String type = configuration.getAttribute( "class" );
> final String actions = configuration.getAttribute( "actions",
null );
> final String signedBy = configuration.getAttribute( "signed-by",
null );
> final String keyStoreName =
onfiguration.getAttribute( "key-store", null );
>
> String target = configuration.getAttribute( "target", null );
> if( null != target )
> {
> target = expand( target );
> }
>
> final Certificate[] signers = getSigners( signedBy,
keyStoreName, keyStores );
> final Permission permission = createPermission( type, target,
actions, signers );
>
> permissions.add( permission );
> }
>
> protected String expand( final String value )
> throws ConfigurationException
> {
> try
> {
> final Object resolvedValue =
ropertyUtil.resolveProperty( value, m_context, false );
> return resolvedValue.toString();
> }
> catch( final PropertyException pe )
> {
> throw new ConfigurationException( "Error resolving property
" + value, pe );
> }
> }
>
> protected Permission createPermission( final String type,
> final String target,
> final String actions,
> final Certificate[] signers )
> throws ConfigurationException
> {
> if( null != signers )
> {
> return createUnresolvedPermission( type, target, actions,
signers );
> }
>
> try
> {
> final Class c = Class.forName( type );
>
> Class paramClasses[] = null;
> Object params[] = null;
>
> if( null == actions && null == target )
> {
> paramClasses = new Class[ 0 ];
> params = new Object[ 0 ];
> }
> else if( null == actions )
> {
> paramClasses = new Class[1];
> paramClasses[0] = String.class;
> params = new Object[1];
> params[0] = target;
> }
> else
> {
> paramClasses = new Class[2];
> paramClasses[0] = String.class;
> paramClasses[1] = String.class;
> params = new Object[2];
> params[0] = target;
> params[1] = actions;
> }
>
> final Constructor constructor =
.getConstructor( paramClasses );
> final Object o = constructor.newInstance( params );
> return (Permission)o;
> }
> catch( final ClassNotFoundException cnfe )
> {
> return createUnresolvedPermission( type, target, actions,
signers );
> }
> catch( final Exception e )
> {
> throw new ConfigurationException( "Failed to create
permission " + type +
> " due to " + e, e );
> }
> }
>
> protected Permission createUnresolvedPermission( final String type,
> final String
target,
> final String
actions,
> final Certificate[]
signers )
> {
> return new UnresolvedPermission( type, target, actions,
signers );
> }
>
> protected Certificate[] getSigners( final String signedBy,
> String keyStoreName,
> final HashMap keyStores )
> throws ConfigurationException
> {
> if( null != signedBy && null == keyStoreName )
> {
> keyStoreName = "default";
> }
>
> Certificate[] signers = null;
>
> if( null != signedBy )
> {
> signers = getCertificates( signedBy, keyStoreName,
keyStores );
> }
>
> return signers;
> }
>
> protected Certificate[] getCertificates( final String signedBy,
> final String keyStoreName,
> final HashMap keyStores )
> throws ConfigurationException
> {
> final KeyStore keyStore =
(KeyStore)keyStores.get( keyStoreName );
>
> if( null == keyStore )
> {
> throw new ConfigurationException( "Unable to aquire keyStore
" + keyStoreName );
> }
>
> final ArrayList certificateSet = new ArrayList();
>
> final StringTokenizer tokenizer = new StringTokenizer( signedBy,
"," );
>
> while( tokenizer.hasMoreTokens() )
> {
> final String alias = ((String)tokenizer.nextToken()).trim();
> Certificate certificate = null;
>
> try { certificate = keyStore.getCertificate( alias ); }
> catch( final KeyStoreException kse )
> {
> throw new ConfigurationException( "Error aquiring
certificate " + alias,
> kse );
> }
>
> if( null == certificate )
> {
> throw new ConfigurationException( "Unable to locate
alias " + alias +
> " in keystore named "
+ keyStoreName );
> }
>
> if( !certificateSet.contains( certificate ) )
> {
> if( DEBUG ) getLogger().debug( "Certificate " +
certificate );
> certificateSet.add( certificate );
> }
> }
>
> return (Certificate[])certificateSet.toArray( new
Certificate[ 0 ] );
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/Default
ThreadManager.java
>
> Index: DefaultThreadManager.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.util.Hashtable;
> import java.util.Iterator;
> import org.apache.avalon.AbstractLoggable;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.configuration.Configurable;
> import org.apache.avalon.configuration.Configuration;
> import org.apache.avalon.configuration.ConfigurationException;
> import org.apache.avalon.util.thread.DefaultThreadPool;
> import org.apache.avalon.util.thread.ThreadManager;
> import org.apache.avalon.util.thread.ThreadPool;
>
> /**
> *
> *
> * @author <a href="mailto:fede@apache.org">Federico Barbieri</a>
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class DefaultThreadManager
> extends AbstractLoggable
> implements Facility, ThreadManager, Configurable
> {
> protected final Hashtable m_pools = new Hashtable();
>
> public void configure( final Configuration configuration )
> throws ConfigurationException
> {
> final Configuration[] groups =
onfiguration.getChildren( "thread-group" );
> for( int i = 0; i < groups.length; i++ )
> {
> final Configuration group = groups[ i ];
>
> final String name = group.getChild( "name" ).getValue();
> final int priority =
group.getChild( "priority" ).getValueAsInt( 5 );
> final boolean isDaemon =
group.getChild( "is-daemon" ).getValueAsBoolean( false );
>
> final int minThreads =
group.getChild( "min-threads" ).getValueAsInt( 5 );
> final int maxThreads =
group.getChild( "max-threads" ).getValueAsInt( 10 );
> final int minSpareThreads =
roup.getChild( "min-spare-threads" ).
> getValueAsInt( maxThreads - minThreads );
>
> try
> {
> final DefaultThreadPool threadPool = new
DefaultThreadPool( name, maxThreads );
> threadPool.setDaemon( isDaemon );
> setupLogger( threadPool );
> m_pools.put( name, threadPool );
> }
> catch( final Exception e )
> {
> throw new ConfigurationException( "Error creating thread
pool " + name,
> e );
> }
> }
> }
>
> public ThreadPool getDefaultThreadPool()
> {
> return getThreadPool( "default" );
> }
>
> public ThreadPool getThreadPool( final String name )
> {
> final ThreadPool threadPool = (ThreadPool)m_pools.get( name );
>
> if( null == threadPool )
> {
> file://Should this be a ComponentNotFoundException ????
> throw new IllegalArgumentException( "No such thread group "
+ name );
> }
>
> return threadPool;
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/SarBloc
kFactory.java
>
> Index: SarBlockFactory.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.net.URL;
> import org.apache.avalon.ComponentManager;
> import org.apache.avalon.ComponentManagerException;
> import org.apache.avalon.Composer;
> import org.apache.avalon.Initializable;
> import org.apache.avalon.camelot.DefaultFactory;
> import org.apache.avalon.camelot.DefaultLoader;
> import org.apache.avalon.camelot.Loader;
>
> /**
> * This component used to create blocks.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> class SarBlockFactory
> extends DefaultFactory
> implements Composer, Initializable
> {
> protected Loader m_loader;
> protected ClassLoader m_classLoader;
>
> public void compose( final ComponentManager componentManager )
> throws ComponentManagerException
> {
> m_classLoader =
ClassLoader)componentManager.lookup( "java.lang.ClassLoader" );
> }
>
> public void init()
> throws Exception
> {
> m_loader = new DefaultLoader( m_classLoader );
> }
>
> /**
> * Overidden so that there is only one Loader per Application rather
than one per archive.
> *
> * @param url the url to archive that contains code (ignored)
> * @return the Loader
> */
> protected Loader getLoaderFor( final URL url )
> {
> return m_loader;
> }
> }
>
>
>
> 1.1
jakarta-avalon-phoenix/src/java/org/apache/phoenix/engine/facilities/SarClas
sLoader.java
>
> Index: SarClassLoader.java
> ===================================================================
> /*
> * Copyright (C) The Apache Software Foundation. All rights reserved.
> *
> * This software is published under the terms of the Apache Software
License
> * version 1.1, a copy of which has been included with this distribution
in
> * the LICENSE file.
> */
> package org.apache.phoenix.engine.facilities;
>
> import java.io.File;
> import java.net.MalformedURLException;
> import java.net.URL;
> import java.security.Policy;
> import org.apache.avalon.ComponentManager;
> import org.apache.avalon.ComponentManagerException;
> import org.apache.avalon.Composer;
> import org.apache.avalon.Context;
> import org.apache.avalon.Contextualizable;
> import org.apache.avalon.Initializable;
> import org.apache.avalon.atlantis.Facility;
> import org.apache.avalon.util.io.ExtensionFileFilter;
> import org.apache.avalon.util.security.PolicyClassLoader;
> import org.apache.phoenix.engine.SarContextResources;
>
> /**
> * This component creates blocks and blockInfos.
> *
> * @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
> */
> public class SarClassLoader
> extends PolicyClassLoader
> implements Facility, Contextualizable, Composer, Initializable
> {
> protected File m_baseDirectory;
>
> public SarClassLoader()
> {
> super( new URL[ 0 ],
Thread.currentThread().getContextClassLoader(), null );
> }
>
> public void contextualize( final Context context )
> {
> m_baseDirectory =
File)context.get( SarContextResources.APP_HOME_DIR );
> }
>
> public void compose( final ComponentManager componentManager )
> throws ComponentManagerException
> {
> m_policy =
Policy)componentManager.lookup( "java.security.Policy" );
> }
>
> public void init()
> throws Exception
> {
> final File blockDir =
> (new File( m_baseDirectory, "blocks" )).getAbsoluteFile();
> final File libDir =
> (new File( m_baseDirectory, "lib" )).getAbsoluteFile();
>
> addURLs( blockDir, new String[] { ".bar" } );
> addURLs( libDir, new String[] { ".jar", ".zip" } );
> }
>
> protected void addURLs( final File directory, final String[]
extentions )
> throws MalformedURLException
> {
> final ExtensionFileFilter filter = new
xtensionFileFilter( extentions );
> final File[] files = directory.listFiles( filter );
> if( null == files ) return;
> addURLs( files );
> }
>
> protected void addURLs( final File[] files )
> throws MalformedURLException
>
> for( int i = 0; i < files.length; i++ )
> {
> addURL( files[ i ].toURL() );
> }
> }
>
> public String toString()
> {
> final StringBuffer sb = new StringBuffer();
> sb.append( "ClassLoader[" );
>
> final URL[] urls = getURLs();
>
> for( int i = 0; i < urls.length; i++ )
> {
> sb.append( ' ' );
> sb.append( urls[ i ] );
> }
>
> sb.append( " ]" );
> return sb.toString();
> }
> }
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: avalon-dev-help@jakarta.apache.org