ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime ConverterDef.java Facility.java Import.java Resources.properties TypeDef.java
Date Mon, 17 Dec 2001 08:48:57 GMT
donaldp     01/12/17 00:48:57

  Added:       proposal/myrmidon/src/java/org/apache/antlib/runtime
                        ConverterDef.java Facility.java Import.java
                        Resources.properties TypeDef.java
  Log:
  Move runtime tasks from myrmidon.libs package
  to abtlib package
  
  Revision  Changes    Path
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/ConverterDef.java
  
  Index: ConverterDef.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.antlib.runtime;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.interfaces.converter.ConverterRegistry;
  import org.apache.myrmidon.interfaces.type.DefaultTypeFactory;
  import org.apache.myrmidon.interfaces.type.TypeManager;
  import org.apache.myrmidon.converter.Converter;
  
  /**
   * Task to define a converter.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class ConverterDef
      extends AbstractTask
      implements Composable
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( ConverterDef.class );
  
      private String              m_sourceType;
      private String              m_destinationType;
      private File                m_lib;
      private String              m_classname;
      private ConverterRegistry   m_converterRegistry;
      private TypeManager         m_typeManager;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          m_converterRegistry = (ConverterRegistry)componentManager.lookup( ConverterRegistry.ROLE
);
          m_typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE );
      }
  
      public void setLib( final File lib )
      {
          m_lib = lib;
      }
  
      public void setClassname( final String classname )
      {
          m_classname = classname;
      }
  
      public void setSourceType( final String sourceType )
      {
          m_sourceType = sourceType;
      }
  
      public void setDestinationType( final String destinationType )
      {
          m_destinationType = destinationType;
      }
  
      public void execute()
          throws TaskException
      {
          if( null == m_classname )
          {
              final String message = REZ.getString( "converterdef.no-classname.error" );
              throw new TaskException( message );
          }
          else if( null == m_sourceType )
          {
              final String message = REZ.getString( "converterdef.no-source.error" );
              throw new TaskException( message );
          }
          else if( null == m_destinationType )
          {
              final String message = REZ.getString( "converterdef.no-destination.error" );
              throw new TaskException( message );
          }
          else if( null == m_lib )
          {
              final String message = REZ.getString( "converterdef.no-lib.error" );
              throw new TaskException( message );
          }
  
          try
          {
              m_converterRegistry.registerConverter( m_classname, m_sourceType, m_destinationType
);
  
              final URL url = m_lib.toURL();
              final DefaultTypeFactory factory = new DefaultTypeFactory( new URL[] { url }
);
              factory.addNameClassMapping( m_classname, m_classname );
  
              m_typeManager.registerType( Converter.ROLE, m_classname, factory );
          }
          catch( final Exception e )
          {
              final String message = REZ.getString( "converterdef.no-register.error", m_classname
);
              throw new TaskException( message, e );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Facility.java
  
  Index: Facility.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.antlib.runtime;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.aspects.AspectHandler;
  import org.apache.myrmidon.interfaces.aspect.AspectManager;
  import org.apache.myrmidon.interfaces.type.TypeException;
  import org.apache.myrmidon.interfaces.type.TypeFactory;
  import org.apache.myrmidon.interfaces.type.TypeManager;
  import org.apache.myrmidon.framework.AbstractContainerTask;
  
  /**
   * Task that definesMethod to register a single converter.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class Facility
      extends AbstractContainerTask
      implements Composable, Configurable
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( Facility.class );
  
      private String              m_namespace;
      private AspectHandler       m_aspectHandler;
  
      private AspectManager       m_aspectManager;
      private TypeFactory         m_factory;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          super.compose( componentManager );
  
          m_aspectManager = (AspectManager)componentManager.lookup( AspectManager.ROLE );
  
          final TypeManager typeManager = (TypeManager)componentManager.lookup( TypeManager.ROLE
);
          try { m_factory = typeManager.getFactory( AspectHandler.ROLE ); }
          catch( final TypeException te )
          {
              final String message = REZ.getString( "facility.no-factory.error" );
              throw new ComponentException( message, te );
          }
      }
  
      public void configure( final Configuration configuration )
          throws ConfigurationException
      {
          final String[] attributes = configuration.getAttributeNames();
          for( int i = 0; i < attributes.length; i++ )
          {
              final String name = attributes[ i ];
              final String value = configuration.getAttribute( name );
              configure( this, name, value );
          }
  
          final Configuration[] children = configuration.getChildren();
  
          if( 1 == children.length )
          {
              try
              {
                  m_aspectHandler = (AspectHandler)m_factory.create( children[ 0 ].getName()
);
              }
              catch( final Exception e )
              {
                  final String message =
                      REZ.getString( "facility.no-create.error", children[ 0 ].getName() );
                  throw new ConfigurationException( message, e );
              }
  
              configure( m_aspectHandler, children[ 0 ] );
          }
          else
          {
              final String message = REZ.getString( "facility.multi-element.error" );
              throw new ConfigurationException( message );
          }
      }
  
      public void setNamespace( final String namespace )
      {
          m_namespace = namespace;
      }
  
      public void execute()
          throws TaskException
      {
          if( null == m_namespace )
          {
              final String message = REZ.getString( "facility.no-namespace.error" );
              throw new TaskException( message );
          }
  
          m_aspectManager.addAspectHandler( m_namespace, m_aspectHandler );
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Import.java
  
  Index: Import.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.antlib.runtime;
  
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URL;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.myrmidon.api.AbstractTask;
  import org.apache.myrmidon.api.TaskException;
  import org.apache.myrmidon.interfaces.deployer.Deployer;
  import org.apache.myrmidon.interfaces.deployer.DeploymentException;
  
  /**
   * Task to import a tasklib.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class Import
      extends AbstractTask
      implements Composable
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( Import.class );
  
      private File        m_lib;
      private Deployer    m_deployer;
  
      public void compose( final ComponentManager componentManager )
          throws ComponentException
      {
          m_deployer = (Deployer)componentManager.lookup( Deployer.ROLE );
      }
  
      public void setLib( final File lib )
      {
          m_lib = lib;
      }
  
      public void execute()
          throws TaskException
      {
          if( null == m_lib )
          {
              final String message = REZ.getString( "import.no-lib.error" );
              throw new TaskException( message );
          }
  
          try
          {
              m_deployer.deploy( m_lib );
          }
          catch( final DeploymentException de )
          {
              final String message = REZ.getString( "import.no-deploy.error" );
              throw new TaskException( message, de );
          }
      }
  }
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  converterdef.no-classname.error=Must specify classname parameter.
  converterdef.no-source.error=Must specify the source-type parameter.
  converterdef.no-destination.error=Must specify the destination-type parameter.
  converterdef.no-lib.error=Must specify the lib parameter.
  converterdef.no-register.error=Failed to register converter {0}.
  
  facility.no-factory.error=Unable to retrieve AspectHandler factory from TypeManager.
  facility.no-create.error=Failed to create aspect handler of type {0}.
  facility.multi-element.error=Expected one sub-element to configure facility.
  facility.no-namespace.error=Must specify namespace parameter.
  
  import.no-lib.error=Must specify lib parameter.
  import.no-deploy.error=Error importing tasklib.
  
  
  
  1.1                  jakarta-ant/proposal/myrmidon/src/java/org/apache/antlib/runtime/TypeDef.java
  
  Index: TypeDef.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.antlib.runtime;
  
  import org.apache.myrmidon.api.Task;
  import org.apache.myrmidon.framework.AbstractTypeDef;
  
  /**
   * Task to define a type.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public class TypeDef
      extends AbstractTypeDef
  {
      private String     m_type;
  
      public void setType( final String type )
      {
          m_type = type;
      }
  
      protected String getTypeName()
      {
          return m_type;
      }
  }
  
  
  

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


Mime
View raw message