You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2002/09/12 07:35:33 UTC

cvs commit: jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder ServiceCreator.java XMLServiceCreator.java Resources.properties XMLTypeCreator.java

mcconnell    2002/09/11 22:35:33

  Modified:    meta/src/java/org/apache/excalibur/meta
                        ConfigurationBuilder.java
               meta/src/java/org/apache/excalibur/meta/info/builder
                        Resources.properties XMLTypeCreator.java
  Added:       meta/src/java/org/apache/excalibur/meta example-service.xml
                        service.dtd
               meta/src/java/org/apache/excalibur/meta/info Service.java
               meta/src/java/org/apache/excalibur/meta/info/builder
                        ServiceCreator.java XMLServiceCreator.java
  Log:
  Addition of a seperate service descriptor, supporting builder and DTD.
  
  Revision  Changes    Path
  1.5       +4 -1      jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/ConfigurationBuilder.java
  
  Index: ConfigurationBuilder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/ConfigurationBuilder.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ConfigurationBuilder.java	11 Sep 2002 06:51:22 -0000	1.4
  +++ ConfigurationBuilder.java	12 Sep 2002 05:35:33 -0000	1.5
  @@ -34,6 +34,9 @@
           new DTDInfo( "-//AVALON/Component Type DTD Version 1.1//EN",
                        "http://jakarta.apache.org/avalon/dtds/type_1_1.dtd",
                        "org/apache/excalibur/meta/type.dtd" ),
  +        new DTDInfo( "-//AVALON/Service DTD Version 1.0//EN",
  +                     "http://jakarta.apache.org/avalon/dtds/service_1_0.dtd",
  +                     "org/apache/excalibur/meta/service.dtd" ),
           new DTDInfo( "-//PHOENIX/Block Info DTD Version 1.0//EN",
                        "http://jakarta.apache.org/avalon/dtds/phoenix/blockinfo_1.0.dtd",
                        "org/apache/excalibur/meta/blockinfo.dtd" ),
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/example-service.xml
  
  Index: example-service.xml
  ===================================================================
  <!DOCTYPE type
        PUBLIC "-//AVALON/Service DTD Version 1.0//EN"
               "http://jakarta.apache.org/avalon/dtds/service_1_0.dtd" >
  
  <!--
  This is an example of a service description.  Normally this file will be included in a jar file colocated with the interface class under the name [classname].xservice.  The DOCTYPE identifier shall normally include the URL http://jakarta.apache.org/avalon/dtds/service_1_0.dtd.
  -->
  
  <service>
    <attributes>
      <attribute key="avalon:service.name" value="example"/>
      <attribute key="avalon:service.href" value="http:\\www.somewhere.com\description.html"/>
      <attribute key="avalon:service.description">
        This is an example of a service description.
      </attribute>
    </attributes>
  </service>
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/service.dtd
  
  Index: service.dtd
  ===================================================================
  <!--
  
     This is the DTD defining the Service Meta Model 1.0
     descriptor (XML) file format/syntax.
  
     Author: Stephen McConnell <mc...@apache.org>
  
     An xservice file is an XML resource colocated with a class file
     sharing the same file name.  The &lt;classname&gt;.xservice resource
     contains the description of a service interface that may be referenced
     within component type defintions as either a supplied service or 
     consumed service.
  
     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.
  
    -->
  
  <!--
  A service element is the document root, it defines:
  
  attributes     an attributes set
  -->
  
  <!ELEMENT service (attributes?)>
  
  <!--
  The attributes element contains a list of attributes for feature.
  -->
  <!ELEMENT attributes    (attribute*)>
  
  <!--
  The attribute element defines an attribute (an opaque key-value pair for a feature).
  It defines:
  
  key          the key for attribute.
  value  	 the value of attribute.
  
  Attribute values may be declared within the content or under the value attribute. Attribute based value declaration shall take priority over content declaration.  If the value attribute is defined, any content shall be ignored.   
  -->
  <!ELEMENT attribute   (#PCDATA) >
    <!ATTLIST attribute
         key CDATA #REQUIRED
         value CDATA #IMPLIED
    >
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/Service.java
  
  Index: Service.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.excalibur.meta.info;
  
  import java.util.Properties;
  
  /**
   * This class contains the meta information about a particular
   * service. It contains a set of attributes qualifying the service;
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/12 05:35:33 $
   */
  public class Service extends Descriptor
  {
     /**
      * Creation of a new Service instance using a supplied properties argument.
      *
      * @param attributes the set of attributes to assign to the descriptor
      */
      public Service( final Properties attributes )
      {
          super( attributes );
      }
  }
  
  
  
  1.2       +3 -0      jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/Resources.properties
  
  Index: Resources.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/Resources.properties,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Resources.properties	20 Aug 2002 16:06:46 -0000	1.1
  +++ Resources.properties	12 Sep 2002 05:35:33 -0000	1.2
  @@ -9,3 +9,6 @@
   builder.creating-facility.notice=Creating a Facility from class "{0}".
   builder.created-facility.notice=Constructed Facility from class {0} with {1} services, {2} dependencies, {3} context entries, {4} loggers, {5} extended phases dependecies, and {6} phase extensions.
   
  +builder.creating-service.notice=Creating a Service from class "{0}".
  +builder.bad-toplevel-service-element.error=Error the service "{0}" has an invalid element at top level service descriptor. Expected: "service". Actual: "{1}"
  +builder.created-service.notice=Constructed Service from class {0} with {1} attribute(s).
  
  
  
  1.4       +2 -28     jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java
  
  Index: XMLTypeCreator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/XMLTypeCreator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- XMLTypeCreator.java	11 Sep 2002 06:51:22 -0000	1.3
  +++ XMLTypeCreator.java	12 Sep 2002 05:35:33 -0000	1.4
  @@ -40,7 +40,7 @@
    * @version $Revision$ $Date$
    */
   public class XMLTypeCreator
  -    extends AbstractLogEnabled
  +    extends XMLServiceCreator
       implements TypeCreator
   {
       private static final Resources REZ =
  @@ -399,32 +399,6 @@
           final Properties attributes =
               buildAttributes( service.getChild( "attributes" ) );
           return new ServiceDescriptor( designator, attributes );
  -    }
  -
  -    /**
  -     * Build up a list of attributes from specific config tree.
  -     *
  -     * @param config the attributes config
  -     * @return the Properties object representing attributes
  -     * @throws ConfigurationException if an error occurs
  -     */
  -    protected Properties buildAttributes( final Configuration config )
  -        throws ConfigurationException
  -    {
  -        final Properties attributes = new Properties();
  -        final Configuration[] children = config.getChildren( "attribute" );
  -        for( int i = 0; i < children.length; i++ )
  -        {
  -            Configuration child = children[ i ];
  -            final String key = child.getAttribute( "key" );
  -            String value = child.getAttribute( "value", null );
  -            if( value == null ) 
  -            {
  -                value = child.getValue();
  -            }
  -            attributes.setProperty( key, value );
  -        }
  -        return attributes;
       }
   
       /**
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/ServiceCreator.java
  
  Index: ServiceCreator.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.excalibur.meta.info.builder;
  
  import org.apache.excalibur.meta.info.Service;
  import java.io.InputStream;
  
  /**
   * Interface used to create a {@link Service}
   * from a stream.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/12 05:35:33 $
   */
  public interface ServiceCreator
  {
      /**
       * Create a {@link Service} from stream
       *
       * @param key the name of the service type
       * @param input the input stream that the resource is loaded from
       * @return the created {@link Service}
       * @exception Exception if an error occurs
       */
      Service createService( String key, InputStream input )
          throws Exception;
  }
  
  
  
  1.1                  jakarta-avalon-excalibur/meta/src/java/org/apache/excalibur/meta/info/builder/XMLServiceCreator.java
  
  Index: XMLServiceCreator.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.excalibur.meta.info.builder;
  
  import java.io.InputStream;
  import java.util.Properties;
  import org.apache.avalon.excalibur.i18n.ResourceManager;
  import org.apache.avalon.excalibur.i18n.Resources;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.logger.AbstractLogEnabled;
  import org.apache.excalibur.meta.info.Service;
  import org.apache.excalibur.meta.ConfigurationBuilder;
  import org.xml.sax.InputSource;
  
  /**
   * Utility class the handles the internalization of an XML description
   * of a service into a {@link Service} instance.
   *
   * @author <a href="mailto:mcconnell@apache.org">Stephen McConnell</a>
   * @version $Revision: 1.1 $ $Date: 2002/09/12 05:35:33 $
   */
  public class XMLServiceCreator
      extends AbstractLogEnabled
      implements ServiceCreator
  {
      private static final Resources REZ =
          ResourceManager.getPackageResources( XMLServiceCreator.class );
  
      /**
       * Create a {@link Service} from stream
       *
       * @param key the name of the service type
       * @param input the input stream that the resource is loaded from
       * @return the created {@link Service}
       * @exception Exception if an error occurs
       */
      public Service createService( String key, InputStream input )
          throws Exception
      {
          if( input == null ) 
          {
              throw new NullPointerException("input");
          }
  
          final InputSource source = new InputSource( input );
          final Configuration xservice = ConfigurationBuilder.build( source );
          return build( key, xservice );
      }
  
      /**
       * Create a {@link Service} object for a supplied classname from
       * configuration data.
       *
       * @param classname the classname of the service
       * @param info the service defintion
       * @return the created Service
       * @throws Exception if an error occurs
       */
      private Service build( final String classname, final Configuration info )
          throws Exception
      {
          if( getLogger().isDebugEnabled() )
          {
              final String message =
                  REZ.getString( "builder.creating-service.notice",
                                 classname );
              getLogger().debug( message );
          }
  
          final String topLevelName = info.getName();
          if( !topLevelName.equals( "service" ) )
          {
              final String message =
                REZ.getString( "builder.bad-toplevel-service-element.error",
                                 classname,
                                 topLevelName );
              throw new ConfigurationException( message );
          }
  
          Configuration configuration = null;
  
          final Properties attributes =
              buildAttributes( configuration.getChild( "attributes" ) );
  
          if( getLogger().isInfoEnabled() )
          {
              final String message =
                  REZ.getString( "builder.created-service.notice",
                                 classname,
                                 new Integer( attributes.size() ) );
              getLogger().info( message );
          }
  
          return new Service( attributes );
      }
  
      /**
       * Build up a list of attributes from specific config tree.
       *
       * @param config the attributes config
       * @return the Properties object representing attributes
       * @throws ConfigurationException if an error occurs
       */
      protected Properties buildAttributes( final Configuration config )
          throws ConfigurationException
      {
          final Properties attributes = new Properties();
          final Configuration[] children = config.getChildren( "attribute" );
          for( int i = 0; i < children.length; i++ )
          {
              Configuration child = children[ i ];
              final String key = child.getAttribute( "key" );
              String value = child.getAttribute( "value", null );
              if( value == null ) 
              {
                  value = child.getValue();
              }
              attributes.setProperty( key, value );
          }
          return attributes;
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>