1
2
3
4
5
6
7
8
9
10
11 package org.astrogrid.applications.javaclass;
12
13 import org.astrogrid.applications.manager.AppAuthorityIDResolver;
14 import org.astrogrid.applications.description.BaseApplicationDescriptionLibrary;
15 import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
16 import org.astrogrid.applications.manager.idgen.IdGen;
17 import org.astrogrid.component.descriptor.ComponentDescriptor;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21
22 import java.lang.reflect.Method;
23 import java.lang.reflect.Modifier;
24
25 /*** A library of java class application descriptions.
26 * <p>
27 * This class constructs {@link org.astrogrid.applications.javaclass.JavaClassApplicationDescription} for each static method in its parameter class,
28 * and then collects them as an {@link org.astrogrid.applications.description.ApplicationDescriptionLibrary}
29 * @TODO would be nice if this library read a file/property list to allow multiple classes to be registered.
30 * @TODO would be good to be able to use annotation to provide nore of the documenation that is needed for a full registry entry.
31 * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
32 * @author Paul Harrison (pah@jb.man.ac.uk)
33 * @see org.astrogrid.applications.javaclass.JavaClassApplicationDescription
34 * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary
35 *
36 */
37 public class JavaClassApplicationDescriptionLibrary
38 extends BaseApplicationDescriptionLibrary
39 implements ComponentDescriptor{
40 /***
41 * Commons Logger for this class
42 */
43 private static final Log logger = LogFactory.getLog(JavaClassApplicationDescriptionLibrary.class);
44
45
46
47 /*** Construct a new JavaClassApplicationDescriptionLibrary, based on static methods of parameter class
48 * @param implClass - class of static methods, each of which will provide an application for the library.
49 * @param authidResolver configuration object specifiying under which community (authority?) the applications are to be placed
50 * @param env standard container object for helper code.
51 *
52 */
53 public JavaClassApplicationDescriptionLibrary(JavaClassConfiguration config,
54 ApplicationDescriptionEnvironment env) {
55 super(env);
56 this.implClass = config.getApplicationClass();
57 populate(implClass, env.getIdGen(), env.getAuthIDResolver());
58 }
59
60 protected final Class implClass;
61 /*** populates the library using reflection on the methods of the parameter class
62 * @param imp
63 * @param authidresolver
64 */
65 protected final void populate(Class imp,IdGen idgen,
66 AppAuthorityIDResolver authidresolver) {
67 String communityName = authidresolver.getAuthorityID();
68 Method[] methods = imp.getDeclaredMethods();
69 for (int i = 0; i < methods.length; i++) {
70 Method m = methods[i];
71 int code = m.getModifiers();
72 if (Modifier.isStatic(code) && Modifier.isPublic(code)) {
73 super.addApplicationDescription(new JavaClassApplicationDescription(m,communityName,env));
74 }
75 }
76 }
77
78 /***
79 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
80 */
81 public String getDescription() {
82 return "Implementation class: " + implClass.getName() + "\n" + super.getDescription();
83 }
84
85 /***
86 * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
87 */
88 public String getName() {
89 return "Java Class Application Library";
90 }
91
92 }
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152