View Javadoc

1   /*$Id: JavaClassApplicationDescriptionLibrary.java,v 1.12 2006/03/17 17:50:58 clq2 Exp $
2    * Created on 08-Jun-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
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  $Log: JavaClassApplicationDescriptionLibrary.java,v $
96  Revision 1.12  2006/03/17 17:50:58  clq2
97  gtr_1489_cea correted version
98  
99  Revision 1.10  2006/03/07 21:45:26  clq2
100 gtr_1489_cea
101 
102 Revision 1.7.20.2  2006/02/01 12:09:54  gtr
103 Refactored and fixed to allow the tests to work with the new configuration.
104 
105 Revision 1.7.20.1  2005/12/18 14:48:25  gtr
106 Refactored to allow the component managers to pass their unit tests and the fingerprint JSP to work. See BZ1492.
107 
108 Revision 1.7  2005/08/10 14:45:37  clq2
109 cea_pah_1317
110 
111 Revision 1.6.6.1  2005/07/19 11:58:05  pah
112 added comment that it would be good if the library could accommodate multiple classes as "application" implementations - would be nice to use annotations also to provide more of the documentation that is needed.
113 
114 Revision 1.6  2005/07/05 08:27:01  clq2
115 paul's 559b and 559c for wo/apps and jes
116 
117 Revision 1.5.68.1  2005/06/09 08:47:33  pah
118 result of merging branch cea_pah_559b into HEAD
119 
120 Revision 1.5.54.1  2005/06/02 14:57:29  pah
121 merge the ProvidesVODescription interface into the MetadataService interface
122 
123 Revision 1.5  2004/11/27 13:20:03  pah
124 result of merge of pah_cea_bz561 branch
125 
126 Revision 1.4.36.1  2004/11/09 09:21:16  pah
127 initial attempt to rationalise authorityID use & self registering
128 
129 Revision 1.4  2004/09/01 15:42:26  jdt
130 Merged in Case 3
131 
132 Revision 1.3.4.1  2004/08/09 16:36:25  jdt
133 pulled up an interface so I can use it in http apps
134 
135 Revision 1.3  2004/07/26 10:21:47  nw
136 javadoc
137 
138 Revision 1.2  2004/07/01 11:16:22  nw
139 merged in branch
140 nww-itn06-componentization
141 
142 Revision 1.1.2.3  2004/07/01 01:42:46  nw
143 final version, before merge
144 
145 Revision 1.1.2.2  2004/06/17 09:21:23  nw
146 finished all major functionality additions to core
147 
148 Revision 1.1.2.1  2004/06/14 08:56:58  nw
149 factored applications into sub-projects,
150 got packaging of wars to work again
151  
152 */