avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader SarPolicy.java SarPolicyResolver.java DefaultClassLoaderManager.java DefaultPolicy.java
Date Sun, 22 Sep 2002 08:52:13 GMT
donaldp     2002/09/22 01:52:13

  Modified:    lib/container excalibur-loader-1.0a.jar
               src/java/org/apache/avalon/phoenix/components/classloader
                        DefaultClassLoaderManager.java
  Added:       src/java/org/apache/avalon/phoenix/components/classloader
                        SarPolicy.java SarPolicyResolver.java
  Removed:     src/java/org/apache/avalon/phoenix/components/classloader
                        DefaultPolicy.java
  Log:
  Integrate the Policy stuff into Phoenix tree.
  
  Revision  Changes    Path
  1.2       +274 -184  jakarta-avalon-phoenix/lib/container/excalibur-loader-1.0a.jar
  
  	<<Binary file>>
  
  
  1.41      +22 -5     jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/DefaultClassLoaderManager.java
  
  Index: DefaultClassLoaderManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/DefaultClassLoaderManager.java,v
  retrieving revision 1.40
  retrieving revision 1.41
  diff -u -r1.40 -r1.41
  --- DefaultClassLoaderManager.java	6 Sep 2002 12:01:07 -0000	1.40
  +++ DefaultClassLoaderManager.java	22 Sep 2002 08:52:13 -0000	1.41
  @@ -31,6 +31,11 @@
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
   import org.apache.avalon.phoenix.interfaces.ClassLoaderManager;
  +import org.apache.avalon.phoenix.components.util.ConfigurationUtil;
  +import org.apache.excalibur.policy.reader.PolicyReader;
  +import org.apache.excalibur.policy.metadata.PolicyMetaData;
  +import org.apache.excalibur.policy.builder.PolicyBuilder;
  +import org.w3c.dom.Element;
   
   /**
    * Component that creates and manages the {@link ClassLoader}
  @@ -256,10 +261,22 @@
                                       final File workDirectory )
           throws ConfigurationException
       {
  -        final DefaultPolicy policy =
  -            new DefaultPolicy( baseDirectory, workDirectory );
  -        policy.enableLogging( getLogger() );
  -        policy.configure( configuration );
  -        return policy;
  +        final SarPolicyResolver resolver =
  +            new SarPolicyResolver(baseDirectory, workDirectory );
  +        setupLogger( resolver );
  +        final PolicyBuilder builder = new PolicyBuilder();
  +        final PolicyReader reader = new PolicyReader();
  +
  +        final Element element = ConfigurationUtil.toElement( configuration );
  +        element.setAttribute( "version", "1.0" );
  +        try
  +        {
  +            final PolicyMetaData policyMetaData = reader.readPolicy( element );
  +            return builder.buildPolicy( policyMetaData, resolver );
  +        }
  +        catch( final Exception e )
  +        {
  +            throw new ConfigurationException( e.getMessage(), e );
  +        }
       }
   }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/SarPolicy.java
  
  Index: SarPolicy.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.classloader;
  
  import java.security.CodeSource;
  import java.security.PermissionCollection;
  import java.security.Permissions;
  import java.util.Map;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.excalibur.policy.runtime.DefaultPolicy;
  
  /**
   * Policy that extracts information from policy files.
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   */
  class SarPolicy
      extends DefaultPolicy
      implements LogEnabled, Initializable
  {
      private Logger m_logger;
      private Map m_grants;
  
      public SarPolicy( final Map grants )
          throws Exception
      {
          m_grants = grants;
      }
  
      public void enableLogging( final Logger logger )
      {
          m_logger = logger;
      }
  
      public void initialize()
          throws Exception
      {
          processGrants( m_grants );
      }
  
      public PermissionCollection getPermissions( final CodeSource codeSource )
      {
          if( m_logger.isDebugEnabled() )
          {
              m_logger.debug( "getPermissions(" + codeSource.getLocation() + ");" );
          }
  
          return super.getPermissions( codeSource );
      }
  
      protected Permissions createPermissionSetFor( final CodeSource codeSource )
      {
          if( m_logger.isDebugEnabled() )
          {
              m_logger.debug( "createPermissionSetFor(" + codeSource + ");" );
          }
  
          return super.createPermissionSetFor( codeSource );
      }
  
      protected void error( final String message,
                            final Throwable throwable )
      {
          m_logger.error( message, throwable );
      }
  }
  
  
  
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/classloader/SarPolicyResolver.java
  
  Index: SarPolicyResolver.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.phoenix.components.classloader;
  
  import java.io.File;
  import java.net.URL;
  import java.util.HashMap;
  import java.util.Map;
  import java.security.Policy;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.context.DefaultContext;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.phoenix.components.util.ResourceUtil;
  import org.apache.excalibur.policy.builder.PolicyResolver;
  
  /**
   * A basic resolver that resolves Phoenix specific features.
   * (like remapping URLs).
   *
   * @author <a href="mailto:peter at apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/22 08:52:13 $
   */
  class SarPolicyResolver
      extends AbstractLogEnabled
      implements PolicyResolver
  {
      private final static Resources REZ =
          ResourceManager.getPackageResources( SarPolicyResolver.class );
  
      private final File m_baseDirectory;
      private final File m_workDirectory;
      private final DefaultContext m_context;
  
      SarPolicyResolver( final File baseDirectory,
                         final File workDirectory )
      {
          final HashMap map = new HashMap();
          map.putAll( System.getProperties() );
          m_context = new DefaultContext( map );
          m_context.put( "/", File.separator );
          m_context.put( "app.home", baseDirectory );
          m_workDirectory = workDirectory;
          m_baseDirectory = baseDirectory;
      }
  
      public Policy createPolicy( Map grants )
          throws Exception
      {
          final SarPolicy sarPolicy = new SarPolicy( grants );
          ContainerUtil.enableLogging( sarPolicy, getLogger() );
          ContainerUtil.initialize( sarPolicy );
          return sarPolicy;
      }
  
      public URL resolveLocation( String location )
          throws Exception
      {
          if( null == location )
          {
              return null;
          }
          else
          {
              location = expand( location );
              location = ResourceUtil.expandSarURL( location,
                                                    m_baseDirectory,
                                                    m_workDirectory );
              return new URL( location );
          }
      }
  
      public String resolveTarget( String target )
      {
          try
          {
              return expand( target );
          }
          catch( Exception e )
          {
              final String message = "Error resolving: " + target;
              getLogger().warn( message, e );
              return target;
          }
      }
  
      private String expand( final String value )
          throws Exception
      {
          try
          {
              final Object resolvedValue =
                  PropertyUtil.resolveProperty( value, m_context, false );
              return resolvedValue.toString();
          }
          catch( final Exception e )
          {
              final String message = REZ.getString( "policy.error.property.resolve", value
);
              throw new Exception( message, e );
          }
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message