leosutic    2003/12/28 12:40:37

  Added:       attributes/unittest/src/test/org/apache/commons/attributes/test
                        RuntimeSample.java
  Log:
  Added ability to programmatically define attributes
  for a class.
  
  Revision  Changes    Path
  1.1                  
jakarta-commons-sandbox/attributes/unittest/src/test/org/apache/commons/attributes/test/RuntimeSample.java
  
  Index: RuntimeSample.java
  ===================================================================
  package org.apache.commons.attributes.test;
  
  import org.apache.commons.attributes.Attributes;
  import org.apache.commons.attributes.RuntimeAttributeRepository;
  
  public class RuntimeSample extends SuperSample implements SampleIFJoin {
      
      static {
          try {
              RuntimeAttributeRepository rar = new RuntimeAttributeRepository 
(RuntimeSample.class);
              rar.addClassAttribute (new ThreadSafe ());
              rar.addClassAttribute (new Dependency ( SampleService.class, "sample" ));
              
              rar.addFieldAttribute ("field", new ThreadSafe ());
              
              rar.addMethodAttribute ("someMethod", new Class[]{}, new Dependency ( 
SampleService.class, "sample-some-method1" ));
              
              rar.addParameterAttribute ("methodWithAttributes", new Class[]{ 
Integer.TYPE, Integer.TYPE }, 1, new ThreadSafe ());
              rar.addReturnAttribute ("methodWithAttributes", new Class[]{ 
Integer.TYPE, Integer.TYPE }, new Dependency ( SampleService.class, "sample-return" ));
              
              rar.addMethodAttribute ("someMethod", new Class[]{ Integer.TYPE }, new 
Dependency ( SampleService.class, "sample-some-method2" ));
              
              Attributes.setAttributes (rar);
          } catch (Exception e) {
              throw new Error ("Unable to set attribute information: " + e.toString 
());
          }
      }
      
      public Object field;
      
      public Object noAttributesInSubClass;
      
      public void someMethod () {
          
      }
  
      public Integer methodWithAttributes (int param1, int param2) {
          return null;
      }
      
      public void someMethod (int parameter) {
          
      }
      
      public void methodWithNoAttributes () {
      }
      
      public static class InnerSample {
          static {
              try {
                  RuntimeAttributeRepository rar = new RuntimeAttributeRepository 
(RuntimeSample.InnerSample.class);
                  rar.addClassAttribute (new Dependency ( SampleService.class, 
"inner-sample" ));
                  Attributes.setAttributes (rar);
              } catch (Exception e) {
                  throw new Error ("Unable to set attribute information: " + 
e.toString ());
              }
          }
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to