You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/11/19 17:04:30 UTC

cvs commit: jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/impl DefaultAttribute.java DefaultAttributeFinder.java

jstrachan    2002/11/19 08:04:30

  Modified:    attributes/src/java/org/apache/commons/attributes
                        AttributeFinder.java Attributes.java
               attributes/src/test/org/apache/commons/attributes
                        AttributesTest.java AttributesTestClass.java
               attributes project.xml
               attributes/xdocs usage.xml navigation.xml
               attributes/src/java/org/apache/commons/attributes/task
                        AttributesCompiler.java
               attributes/src/java/org/apache/commons/attributes/impl
                        DefaultAttributeFinder.java
  Added:       attributes/src/java/org/apache/commons/attributes
                        Attribute.java
               attributes build.xml
               attributes/xdocs usecases.xml
               attributes/src/java/org/apache/commons/attributes/impl
                        DefaultAttribute.java
  Removed:     attributes maven.xml
  Log:
  Added Jon Tirs�n's patches to support an Attribute interface as well as adding Ara to the documentation.
  
  Revision  Changes    Path
  1.2       +3 -3      jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/AttributeFinder.java
  
  Index: AttributeFinder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/AttributeFinder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributeFinder.java	14 Nov 2002 08:09:56 -0000	1.1
  +++ AttributeFinder.java	19 Nov 2002 16:04:29 -0000	1.2
  @@ -74,9 +74,9 @@
    */
   public interface AttributeFinder {
   	
  -	String getAttribute(Class aClass, String attribute);
  +	Attribute getAttribute(Class aClass, String attribute);
   
  -	String getAttribute(Method method, String attribute);
  +	Attribute getAttribute(Method method, String attribute);
   
  -	String getAttribute(Field field, String attribute);
  +	Attribute getAttribute(Field field, String attribute);
   }
  
  
  
  1.2       +18 -3     jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/Attributes.java
  
  Index: Attributes.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/Attributes.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Attributes.java	14 Nov 2002 08:09:56 -0000	1.1
  +++ Attributes.java	19 Nov 2002 16:04:29 -0000	1.2
  @@ -114,16 +114,31 @@
           Attributes.finder = finder;
       }
   
  -	public static String getAttribute(Class aClass, String attribute) {
  +	public static Attribute getAttribute(Class aClass, String attribute) {
   		return getAttributeFinder().getAttribute(aClass, attribute);
   	}
   
  -	public static String getAttribute(Method method, String attribute) {
  +	public static Attribute getAttribute(Method method, String attribute) {
           return getAttributeFinder().getAttribute(method, attribute);
   	}
   
  -	public static String getAttribute(Field field, String attribute) {
  +	public static Attribute getAttribute(Field field, String attribute) {
           return getAttributeFinder().getAttribute(field, attribute);
  +	}
  +
  +	public static String getString(Class aClass, String attributeName) {
  +        Attribute attribute = getAttribute(aClass, attributeName);
  +        return attribute == null ? null : attribute.getValue();
  +	}
  +
  +	public static String getString(Method method, String attributeName) {
  +        Attribute attribute = getAttribute(method, attributeName);
  +        return attribute == null ? null : attribute.getValue();
  +	}
  +
  +	public static String getString(Field field, String attributeName) {
  +        Attribute attribute = getAttribute(field, attributeName);
  +        return attribute == null ? null : attribute.getValue();
   	}
   
   	public static boolean hasAttribute(Class aClass, String attribute) {
  
  
  
  1.1                  jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/Attribute.java
  
  Index: Attribute.java
  ===================================================================
  /*
   * $Header: $
   * $Revision:  $
   * $Date:  $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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
   * <http://www.apache.org/>.
   * 
   * $Id: $
   */
  package org.apache.commons.attributes;
  
  /**
   * Represents a runtime attribute value that can be attached to 
   * Package, Class, Method or Field.
   *  
   * @author <a href="mailto:jon_tirsen@yahoo.com">Jon Tirs�n</a>
   * @author Ara Abrahamian
   * @version $Revision: $
   */
  public interface Attribute {
  	
  	/**
  	 * @return the name of the attribute
	 */
      public String getName();
      
      /**
       * @return the textual value of the attribute
     */
      public String getValue();
  }
  
  
  
  1.2       +21 -12    jakarta-commons-sandbox/attributes/src/test/org/apache/commons/attributes/AttributesTest.java
  
  Index: AttributesTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/test/org/apache/commons/attributes/AttributesTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributesTest.java	14 Nov 2002 08:09:56 -0000	1.1
  +++ AttributesTest.java	19 Nov 2002 16:04:29 -0000	1.2
  @@ -130,17 +130,17 @@
               assertSame(expectField, actualField);
           }
   
  -        public String getAttribute(Class aClass, String attribute) {
  +        public Attribute getAttribute(Class aClass, String attribute) {
               actualClass = aClass;
               return null;
           }
   
  -        public String getAttribute(Method method, String attribute) {
  +        public Attribute getAttribute(Method method, String attribute) {
               actualMethod = method;
               return null;
           }
   
  -        public String getAttribute(Field field, String attribute) {
  +        public Attribute getAttribute(Field field, String attribute) {
               actualField = field;
               return null;
           }
  @@ -163,9 +163,9 @@
               testAttributesLoader.expectClass(testClass);
               testAttributesLoader.expectMethod(testMethod);
               testAttributesLoader.expectField(testField);
  -            Attributes.getAttribute(testClass, "testAttribute");
  -            Attributes.getAttribute(testMethod, "testAttribute");
  -            Attributes.getAttribute(testField, "testAttribute");
  +            Attributes.getString(testClass, "testAttribute");
  +            Attributes.getString(testMethod, "testAttribute");
  +            Attributes.getString(testField, "testAttribute");
               testAttributesLoader.verify();
           } finally {
               // clear the pluggability for coming tests
  @@ -179,7 +179,7 @@
           // maybe this shouldn't actually fail like this in the future
           // but that's what happens now so I write a test for it
           try {
  -            Attributes.getAttribute(Object.class, "someAttribute");
  +            Attributes.getString(Object.class, "someAttribute");
               //fail("didn't fail when asking for the attributes of unsupported class");
           } catch (AttributesException shouldHappen) {
           }
  @@ -194,7 +194,7 @@
   
   		assertEquals(
   			"classValue",
  -			Attributes.getAttribute(
  +			Attributes.getString(
   				AttributesTestClass.class,
   				"classAttribute"));
   		assertTrue(
  @@ -207,12 +207,18 @@
   				"stupidAttribute"));
           assertEquals(
   			"fieldValue",
  -			Attributes.getAttribute(testField, "fieldAttribute"));
  +			Attributes.getString(testField, "fieldAttribute"));
  +        assertEquals(
  +			"fieldAttribute",
  +			Attributes.getAttribute(testField, "fieldAttribute").getName());
   		assertTrue(Attributes.hasAttribute(testField, "fieldAttribute"));
   		assertFalse(Attributes.hasAttribute(testField, "stupidAttribute"));
           assertEquals(
   			"methodValue",
  -			Attributes.getAttribute(testMethod, "methodAttribute"));
  +			Attributes.getString(testMethod, "methodAttribute"));
  +        assertEquals(
  +			"methodAttribute",
  +			Attributes.getAttribute(testMethod, "methodAttribute").getName());
   		assertTrue(Attributes.hasAttribute(testMethod, "methodAttribute"));
   		assertFalse(Attributes.hasAttribute(testMethod, "stupidAttribute"));
   		Method argMethod =
  @@ -221,8 +227,11 @@
   				new Class[] { String.class, String.class });
   		assertEquals(
   			"argMethodValue",
  -			Attributes.getAttribute(argMethod, "methodAttribute"));
  -		assertTrue(Attributes.hasAttribute(argMethod, "methodAttribute"));
  +			Attributes.getString(argMethod, "argMethodAttribute"));
  +        assertEquals(
  +			"argMethodAttribute",
  +			Attributes.getAttribute(argMethod, "argMethodAttribute").getName());
  +		assertTrue(Attributes.hasAttribute(argMethod, "argMethodAttribute"));
   		assertFalse(Attributes.hasAttribute(argMethod, "stupidAttribute"));
   	}
   }
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/attributes/src/test/org/apache/commons/attributes/AttributesTestClass.java
  
  Index: AttributesTestClass.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/test/org/apache/commons/attributes/AttributesTestClass.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributesTestClass.java	14 Nov 2002 08:09:56 -0000	1.1
  +++ AttributesTestClass.java	19 Nov 2002 16:04:29 -0000	1.2
  @@ -86,7 +86,7 @@
   	}
   
   	/**
  -	 * @methodAttribute argMethodValue
  +	 * @argMethodAttribute argMethodValue
   	 */
   	public void method(String arg, String arg2) {
   	}
  
  
  
  1.3       +8 -1      jakarta-commons-sandbox/attributes/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	14 Nov 2002 12:50:09 -0000	1.2
  +++ project.xml	19 Nov 2002 16:04:29 -0000	1.3
  @@ -63,7 +63,7 @@
         <name>Jon Tirsen</name>
         <id>tirsen</id>
         <email>tirsen@users.sourceforge.net</email>
  -      <organization></organization>
  +      <organization>Lecando AB</organization>
       </developer>
   
       <developer>
  @@ -71,6 +71,13 @@
         <id>jstrachan</id>
         <email>jstrachan@apache.org</email>
         <organization>SpiritSoft, Inc.</organization>
  +    </developer>
  +
  +    <developer>
  +      <name>Ara Abrahamian</name>
  +      <id>ara</id>
  +      <email>ara_e_w@yahoo.com</email>
  +      <organization></organization>
       </developer>
     </developers>
   
  
  
  
  1.1                  jakarta-commons-sandbox/attributes/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  
  <project default="jar" name="commons-attributes" basedir=".">
    
    <property name="defaulttargetdir" value="target"></property> 
    <property name="classesdir" value="target/classes"></property>
    <property name="testclassesdir" value="target/test-classes"></property>
    <property name="testreportdir" value="target/test-reports"></property>
    
    
    
    
    	
  		
    
    
    <property name="resourcedir" value="src/java"></property>
    
    <property name="distdir" value="dist"></property>
    <property name="javadocdir" value="target/docs/apidocs"></property>
    <property name="final.name" value="commons-attributes-0.1"></property>
    
    <target name="init" description="o Initializes some properties">
      <mkdir dir="lib"></mkdir>
      <condition property="noget">
        <equals arg2="only" arg1="${build.sysclasspath}"></equals>
      </condition>
    </target>
  
    <target name="compile" description="o Compile the code" depends="get-deps">
      
      <mkdir dir="${classesdir}"></mkdir>
  
      <javac destdir="${classesdir}" deprecation="true" debug="true" optimize="false" excludes="**/package.html">
        <src>
          <pathelement location="src/java"></pathelement>
        </src>
        <classpath>
          <fileset dir="lib">
            <include name="*.jar"></include>
          </fileset>
        </classpath>
      </javac>
      
      
   
      
   
      <copy todir="${classesdir}">
        
        <fileset dir="${resourcedir}">
        
        
          <include name="**/*.xml"></include>
        
        
        </fileset>
      </copy>
   
      
  
      
  		
   
      <copy todir="${testclassesdir}">
        
        
        
        
        <fileset dir="src/test">
        
        
          <include name="**/*.xml"></include>
        
          <include name="**/*.properties"></include>
        
        
        </fileset>
      </copy>
   
  		
  
    </target>
      
    <target name="jar" description="o Create the jar" depends="compile,test">
  
      <jar jarfile="target/${final.name}.jar" excludes="**/package.html" basedir="${classesdir}"></jar>
  
    </target>
    
    <target name="clean" description="o Clean up the generated directories">
      <delete dir="${defaulttargetdir}"></delete>
      <delete dir="${distdir}"></delete>
    </target>
  
    <target name="dist" description="o Create a distribution" depends="jar, javadoc">
      <mkdir dir="dist"></mkdir>
      <copy todir="dist">
        <fileset dir="${defaulttargetdir}"></fileset>
      </copy>
    </target>
   
    <target name="test" description="o Run the test cases" if="test.failure" depends="internal-test">
      <fail message="There were test failures."></fail>
    </target>
    <target name="internal-test" depends="compile-tests">
      
        <mkdir dir="${testreportdir}"></mkdir>
        <junit dir="./" failureproperty="test.failure" printSummary="yes" fork="true" haltonerror="true">
          
          <sysproperty key="basedir" value="C:\workspace\jakarta-commons-sandbox\attributes"></sysproperty>
          <formatter type="xml"></formatter>
          <formatter usefile="true" type="plain"></formatter>
          <classpath>
            <fileset dir="lib">
              <include name="*.jar"></include>
            </fileset>
            <pathelement path="${testclassesdir}"></pathelement>
            <pathelement path="${classesdir}"></pathelement>
          </classpath>
          <batchtest todir="${testreportdir}">
            <fileset dir="src/test">
              
                <include name="**/*Test.java"></include>
              
              
                <exclude name="**/Abstract*.java"></exclude>
              
              
              
              
            </fileset>
          </batchtest>
        </junit>
      
    </target>
  
    <target name="compile-tests" depends="compile">
      
        <mkdir dir="${testclassesdir}"></mkdir>
        <javac destdir="${testclassesdir}" deprecation="true" debug="true" optimize="false" excludes="**/package.html">
          <src>
            <pathelement location="src/test"></pathelement>
          </src>
          <classpath>
            <fileset dir="lib">
              <include name="*.jar"></include>
            </fileset>
            <pathelement path="${classesdir}"></pathelement>
          </classpath>
        </javac>
  
        
     
        
      
    </target>
  
    <target name="javadoc" description="o Generate javadoc" depends="jar">
   
   
      <mkdir dir="${javadocdir}"></mkdir>
   
      
      <tstamp>
        <format pattern="2002-yyyy" property="year"></format>
      </tstamp>
   
      <property name="copyright" value="Copyright &amp;copy;  Apache Software Foundation. All Rights Reserved."></property>
   
      <property name="title" value="Commons Attributes 0.1 API"></property>
   
      <javadoc use="true" private="true" destdir="${javadocdir}" author="true" version="true" sourcepath="src/java" packagenames="org.apache.commons.attributes.*">
        <classpath>
          <fileset dir="lib">
            <include name="*.jar"></include>
          </fileset>
          <pathelement location="target/${final.name}.jar"></pathelement>
        </classpath>
      </javadoc>
   
    </target>
  
    <target name="get-deps" unless="noget" depends="init">
    
      
      <get dest="lib/qdox-1.0.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/qdox/jars/qdox-1.0.jar"></get>
      <get dest="lib/commons-logging-1.0.2.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/commons-logging/jars/commons-logging-1.0.2.jar"></get>
      <get dest="lib/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar"></get>
      <get dest="lib/ant-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar"></get>
      
      <get dest="lib/junit-3.8.1.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/junit/jars/junit-3.8.1.jar"></get>
      <get dest="lib/ant-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-1.5.jar"></get>
      <get dest="lib/ant-optional-1.5.jar" usetimestamp="true" ignoreerrors="true" src="http://www.ibiblio.org/maven/ant/jars/ant-optional-1.5.jar"></get>
    </target>
  
    
    
    
    
    
    
    
    
  
    <target name="install-maven">
  
      
  
      <get dest="${user.home}/maven-install-latest.jar" usetimestamp="true" src="${maven.repo.remote}/maven/maven-install-latest.jar"></get>
      
      <unjar dest="${maven.home}" src="${user.home}/maven-install-latest.jar"></unjar>
      
    </target>
  
  </project>
      
  
  
  1.2       +20 -18    jakarta-commons-sandbox/attributes/xdocs/usage.xml
  
  Index: usage.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/xdocs/usage.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- usage.xml	14 Nov 2002 08:10:00 -0000	1.1
  +++ usage.xml	19 Nov 2002 16:04:29 -0000	1.2
  @@ -10,10 +10,26 @@
   
           <section name="Using runtime attributes">
               <p>
  -                This is an example from the unit-tests:
  +                Accessing runtime attributes is very simple.
  +            </p>
  +            <source><![CDATA[
  +Field field = AttributesTestClass.class.getDeclaredField("field");
  +String fieldAttribute = Attributes.getString(field, "fieldAttribute");
  +
  +Method method = AttributesTestClass.class.getMethod("method", null);
  +String methodAttribute = Attributes.getString(method, "methodAttribute");
  +
  +Method argMethod = AttributesTestClass.class.getMethod("method", new Class[]{String.class});
  +String argMethodAttribute = Attributes.getString(argMethod, "methodAttribute");
  +            ]]></source>
  +    </section>
  +        <section name="Using the default implementation">
  +            <p>
  +                Commons-attributes ships with a default implementation but you can also plug in your own. This is
  +                how to specify attributes and compile them for the default implementation.
               </p>
               <p>
  -                The class (with the attributes):
  +                You specify your attributes like JavaDoc-tags in the source-code. Like this:
               </p>
               <source><![CDATA[
   /**
  @@ -42,29 +58,15 @@
   }
               ]]></source>
               <p>
  -                The code that compiles and accesses these attributes:
  +                You can use the compiler in Java or as an Ant-task. (TODO: sample of ant-task.) An upcoming Maven-plugin
  +                will also support this. This shows how to use the compiler in Java.
               </p>
               <source><![CDATA[
   AttributesCompiler attributesCompiler = new AttributesCompiler();
   attributesCompiler.setSrc(new File("src" + File.separator + "test"));
   attributesCompiler.setDest(targetDir);
   attributesCompiler.execute();
  -
  -assertEquals("classValue", Attributes.getAttribute(AttributesTestClass.class, "classAttribute"));
  -Field field = AttributesTestClass.class.getDeclaredField("field");
  -assertEquals("fieldValue", Attributes.getAttribute(field, "fieldAttribute"));
  -Method method = AttributesTestClass.class.getMethod("method", null);
  -assertEquals("methodValue", Attributes.getAttribute(method, "methodAttribute"));
  -Method argMethod = AttributesTestClass.class.getMethod("method", new Class[]{String.class});
  -assertEquals("argMethodValue", Attributes.getAttribute(argMethod, "methodAttribute"));
               ]]></source>
  -            <p>
  -                The attributes-compiler can also be used as an ant-task (or better yet! inside
  -                <a
  -                    href="http://jakarta.apache.org/maven">maven</a>). This is left as an exercise
  -                for the interested reader (yeah, yeah, I'm lazy...).
  -            </p>
  -
           </section>
   
       </body>
  
  
  
  1.2       +2 -0      jakarta-commons-sandbox/attributes/xdocs/navigation.xml
  
  Index: navigation.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/xdocs/navigation.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- navigation.xml	14 Nov 2002 08:10:01 -0000	1.1
  +++ navigation.xml	19 Nov 2002 16:04:29 -0000	1.2
  @@ -5,12 +5,14 @@
   
       <body>
           <links>
  +            <item name="XDoclet" href="http://xdoclet.sourceforge.net/"/>
               <item name="Nanning" href="http://nanning.sourceforge.net/"/>
               <item name="Maven" href="http://jakarta.apache.org/turbine/maven/"/>
               <item name="QDox" href="http://qdox.sourceforge.net/"/>
           </links>
           <menu name="Commons Attributes">
               <item name="Usage" href="/usage.html"/>
  +            <item name="Sample Usecases" href="/usecases.html"/>
           </menu>
       </body>
   </project>
  
  
  
  1.1                  jakarta-commons-sandbox/attributes/xdocs/usecases.xml
  
  Index: usecases.xml
  ===================================================================
  <?xml version="1.0"?>
  <document>
  
      <properties>
          <author email="tirsen@users.sourceforge.net">Jon Tirsen</author>
          <title>Nanning Aspects</title>
      </properties>
  
      <body>
  
          <section name="Usage Scenarios">
              <p>
                  Some examples on how to use runtime-attributes.
              </p>
              <subsection name="Object-relational mapper">
                  <p>
                      For example in OJB.
                  </p>
              </subsection>
              <subsection name="Serializing objects into XML">
                  <p>
                      For example in Betwixt.
                  </p>
              </subsection>
              <subsection name="SOAP encoding">
                  <p>
                      For example in Axis.
                  </p>
              </subsection>
              <subsection name="Interceptors in AOP">
                  <p>
                      On what methods should an interceptor run and what an interceptor should do.
                  </p>
              </subsection>
              <subsection name="In a remote-invocation framework">
                  <p>
                      For example specifying what classes (or parameters) are sent by reference and
                      what are sent by value.
                  </p>
              </subsection>
          </section>
  
      </body>
  </document>
  
  
  
  1.2       +2 -1      jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/task/AttributesCompiler.java
  
  Index: AttributesCompiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/task/AttributesCompiler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AttributesCompiler.java	14 Nov 2002 08:09:56 -0000	1.1
  +++ AttributesCompiler.java	19 Nov 2002 16:04:30 -0000	1.2
  @@ -72,6 +72,7 @@
   
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.BuildException;
  +import org.apache.commons.attributes.impl.DefaultAttributeFinder;
   
   /**
    * <p><code>AttributesCompiler</code> is an Ant Task which 
  @@ -178,7 +179,7 @@
   		Properties properties) {
   		for (int i = 0; i < tags.length; i++) {
   			DocletTag tag = tags[i];
  -			properties.put(prefix + '.' + tag.getName(), tag.getValue());
  +			properties.put(prefix + DefaultAttributeFinder.SEPARATOR + tag.getName(), tag.getValue());
   		}
   	}
   
  
  
  
  1.2       +31 -20    jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/impl/DefaultAttributeFinder.java
  
  Index: DefaultAttributeFinder.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/impl/DefaultAttributeFinder.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DefaultAttributeFinder.java	14 Nov 2002 08:09:55 -0000	1.1
  +++ DefaultAttributeFinder.java	19 Nov 2002 16:04:30 -0000	1.2
  @@ -63,6 +63,7 @@
   
   import org.apache.commons.attributes.AttributesException;
   import org.apache.commons.attributes.AttributeFinder;
  +import org.apache.commons.attributes.Attribute;
   
   import java.io.IOException;
   import java.io.InputStream;
  @@ -82,24 +83,25 @@
   	
   	private static List searchPaths = new ArrayList();
   
  -	private Map propertiesCache = new HashMap();
  +	private Map attributesCache = new HashMap();
  +    public static final char SEPARATOR = '_';
   
  -	public String getAttribute(Class aClass, String attribute) {
  -		return getProperty(aClass, attributeName(aClass, attribute));
  +    public Attribute getAttribute(Class aClass, String attribute) {
  +		return getAttributeByKey(aClass, attributeName(aClass, attribute));
   	}
   
   	private String attributeName(Class aClass, String attribute) {
  -		return "class." + attribute;
  +		return "class" + SEPARATOR + attribute;
   	}
   
  -	private String getProperty(Class aClass, String key) {
  -		Properties properties = getProperties(aClass);
  -		return properties.getProperty(key);
  +	private Attribute getAttributeByKey(Class aClass, String key) {
  +		Map attributes = getAttributes(aClass);
  +		return (Attribute) attributes.get(key);
   	}
   
  -	private Properties getProperties(Class aClass) {
  -		Properties properties = (Properties) propertiesCache.get(aClass);
  -		if (properties == null) {
  +	private Map getAttributes(Class aClass) {
  +		Map attributes = (Map) attributesCache.get(aClass);
  +		if (attributes == null) {
   			InputStream inputStream = null;
   			try {
   				String className = aClass.getName();
  @@ -127,10 +129,19 @@
                       }
   				}
   
  +                Properties properties;
   				if (inputStream != null) {
  -					properties = new Properties();
  -					properties.load(inputStream);
  -					propertiesCache.put(aClass, properties);
  +                    properties = new Properties();
  +                    properties.load(inputStream);
  +                    attributes = new HashMap();
  +                    for (Iterator iterator = properties.entrySet().iterator(); iterator.hasNext();) {
  +                        Map.Entry entry = (Map.Entry) iterator.next();
  +                        String property = (String) entry.getKey();
  +                        String value = (String) entry.getValue();
  +                        String name = property.substring(property.indexOf(SEPARATOR) + 1);
  +                        attributes.put(property, new DefaultAttribute(name, value));
  +                    }
  +                    attributesCache.put(aClass, attributes);
   				} else {
   					throw new AttributesException(
   						"Could not find attributes for " + aClass);
  @@ -147,12 +158,12 @@
   				}
   			}
   		}
  -		return properties;
  +		return attributes;
   	}
   
  -	public String getAttribute(Method method, String attribute) {
  +	public Attribute getAttribute(Method method, String attribute) {
   		String name = attributeName(method, attribute);
  -		return getProperty(method.getDeclaringClass(), name);
  +		return getAttributeByKey(method.getDeclaringClass(), name);
   	}
   
   	private String attributeName(Method method, String attribute) {
  @@ -168,20 +179,20 @@
   			}
   		}
   		stringBuffer.append(')');
  -		stringBuffer.append('.');
  +        stringBuffer.append(SEPARATOR);
   		stringBuffer.append(attribute);
   		String name = stringBuffer.toString();
   		return name;
   	}
   
  -	public String getAttribute(Field field, String attribute) {
  -		return getProperty(
  +	public Attribute getAttribute(Field field, String attribute) {
  +		return getAttributeByKey(
   			field.getDeclaringClass(),
   			attributeName(field, attribute));
   	}
   
   	private String attributeName(Field field, String attribute) {
  -		return field.getName() + '.' + attribute;
  +		return field.getName() + SEPARATOR + attribute;
   	}
   
   	public static void addSearchPath(URL searchPath) {
  
  
  
  1.1                  jakarta-commons-sandbox/attributes/src/java/org/apache/commons/attributes/impl/DefaultAttribute.java
  
  Index: DefaultAttribute.java
  ===================================================================
  /*
   * $Header: $
   * $Revision:  $
   * $Date:  $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2002 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", 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 names without prior written
   *    permission of the Apache Group.
   *
   * 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
   * <http://www.apache.org/>.
   * 
   * $Id: $
   */
  package org.apache.commons.attributes.impl;
  
  import org.apache.commons.attributes.Attribute;
  
  public class DefaultAttribute implements Attribute {
      private String name;
      private String value;
  
      public DefaultAttribute(String name, String value) {
          this.name = name;
          this.value = value;
      }
  
      public String getName() {
          return name;
      }
  
      public String getValue() {
          return value;
      }
  }
  
  
  

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