KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > attributes > test > RuntimeSample


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.attributes.test;
17
18 import org.apache.commons.attributes.Attributes;
19 import org.apache.commons.attributes.RuntimeAttributeRepository;
20
21 public class RuntimeSample extends SuperSample implements SampleIFJoin {
22     
23     static {
24         try {
25             RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.class);
26             rar.addClassAttribute (new ThreadSafe ());
27             rar.addClassAttribute (new Dependency ( SampleService.class, "sample" ));
28             
29             rar.addFieldAttribute ("field", new ThreadSafe ());
30             
31             rar.addMethodAttribute ("someMethod", new Class JavaDoc[]{}, new Dependency ( SampleService.class, "sample-some-method1" ));
32             
33             rar.addParameterAttribute ("methodWithAttributes", new Class JavaDoc[]{ Integer.TYPE, Integer.TYPE }, 1, new ThreadSafe ());
34             rar.addReturnAttribute ("methodWithAttributes", new Class JavaDoc[]{ Integer.TYPE, Integer.TYPE }, new Dependency ( SampleService.class, "sample-return" ));
35             
36             rar.addMethodAttribute ("someMethod", new Class JavaDoc[]{ Integer.TYPE }, new Dependency ( SampleService.class, "sample-some-method2" ));
37             
38             BeanAttribute ba = new BeanAttribute (1, "a");
39             ba.setAnotherNumber (56 - 14);
40             ba.setName ("Smith, John \"Agent\"");
41             rar.addMethodAttribute ("methodWithNamedParameters", new Class JavaDoc[]{}, ba);
42             
43             rar.addMethodAttribute ("privateMethod", new Class JavaDoc[]{}, new Dependency ( SampleService.class, "sample-privateMethod" ));
44             
45             Attributes.setAttributes (rar);
46         } catch (Exception JavaDoc e) {
47             throw new Error JavaDoc ("Unable to set attribute information: " + e.toString ());
48         }
49     }
50     
51     public Object JavaDoc field;
52     
53     public Object JavaDoc noAttributesInSubClass;
54     
55     public void someMethod () {
56         
57     }
58
59     public Integer JavaDoc methodWithAttributes (int param1, int param2) {
60         return null;
61     }
62     
63     public void someMethod (int parameter) {
64         
65     }
66     
67     public void methodWithNamedParameters () {
68         
69     }
70     
71     public void methodWithNoAttributes () {
72     }
73     
74     private void privateMethod () {
75     }
76     
77     public static class InnerSample {
78         static {
79             try {
80                 RuntimeAttributeRepository rar = new RuntimeAttributeRepository (RuntimeSample.InnerSample.class);
81                 rar.addClassAttribute (new Dependency ( SampleService.class, "inner-sample" ));
82                 Attributes.setAttributes (rar);
83             } catch (Exception JavaDoc e) {
84                 throw new Error JavaDoc ("Unable to set attribute information: " + e.toString ());
85             }
86         }
87     }
88 }
Popular Tags