View Javadoc

1   /*$Id: JavaClassApplicationDescriptionLibrary.java,v 1.5 2004/11/27 13:20:03 pah 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.description.BaseApplicationDescriptionLibrary;
14  import org.astrogrid.applications.description.base.ApplicationDescriptionEnvironment;
15  import org.astrogrid.applications.manager.idgen.IdGen;
16  import org.astrogrid.component.descriptor.ComponentDescriptor;
17  
18  import org.apache.commons.logging.Log;
19  import org.apache.commons.logging.LogFactory;
20  
21  import java.lang.reflect.Method;
22  import java.lang.reflect.Modifier;
23  
24  /*** A library of java class application descriptions.
25   * <p>
26   * This class constructs {@link org.astrogrid.applications.javaclass.JavaClassApplicationDescription} for each static method in its parameter class,
27   * and then collects them as an {@link org.astrogrid.applications.description.ApplicationDescriptionLibrary}
28   * @author Noel Winstanley nw@jb.man.ac.uk 08-Jun-2004
29   * @author Paul Harrison (pah@jb.man.ac.uk)
30   * @see org.astrogrid.applications.javaclass.JavaClassApplicationDescription
31   * @see org.astrogrid.applications.description.ApplicationDescriptionLibrary
32   *
33   */
34  public class JavaClassApplicationDescriptionLibrary extends BaseApplicationDescriptionLibrary implements  ComponentDescriptor{
35      /***
36       * Commons Logger for this class
37       */
38      private static final Log logger = LogFactory.getLog(JavaClassApplicationDescriptionLibrary.class);
39  
40  
41  
42      /*** Construct a new JavaClassApplicationDescriptionLibrary, based on static methods of parameter class
43       * @param implClass - class of static methods, each of which will provide an application for the library.
44       * @param authidResolver configuration object specifiying under which community (authority?) the applications are to be placed 
45       * @param env standard container object for helper code.
46       * 
47       */
48      public JavaClassApplicationDescriptionLibrary(Class implClass, ApplicationDescriptionEnvironment env) {
49          super(env);
50          this.implClass= implClass;
51          populate(implClass,env.getIdGen(), env.getAuthIDResolver());
52      }
53      protected final Class implClass;
54      /*** populates the library using reflection on the methods of the parameter class
55       * @param imp
56      * @param authidresolver
57       */
58      protected final void populate(Class imp,IdGen idgen, BaseApplicationDescriptionLibrary.AppAuthorityIDResolver authidresolver) {
59          String communityName = authidresolver.getAuthorityID();
60          Method[] methods = imp.getDeclaredMethods();
61          for (int i = 0; i < methods.length; i++) {
62              Method m = methods[i];
63              int code = m.getModifiers();
64              if (Modifier.isStatic(code) && Modifier.isPublic(code)) {
65                  super.addApplicationDescription(new JavaClassApplicationDescription(m,communityName,env));            
66                  } 
67          } 
68      }
69  
70      /***
71       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getDescription()
72       */
73      public String getDescription() {
74          return "Implementation class: " + implClass.getName() + "\n" + super.getDescription();
75      }
76  
77      /***
78       * @see org.astrogrid.component.descriptor.ComponentDescriptor#getName()
79       */
80      public String getName() {
81          return "Java Class Application Library";
82      }
83  
84  }
85  
86  /* 
87  $Log: JavaClassApplicationDescriptionLibrary.java,v $
88  Revision 1.5  2004/11/27 13:20:03  pah
89  result of merge of pah_cea_bz561 branch
90  
91  Revision 1.4.36.1  2004/11/09 09:21:16  pah
92  initial attempt to rationalise authorityID use & self registering
93  
94  Revision 1.4  2004/09/01 15:42:26  jdt
95  Merged in Case 3
96  
97  Revision 1.3.4.1  2004/08/09 16:36:25  jdt
98  pulled up an interface so I can use it in http apps
99  
100 Revision 1.3  2004/07/26 10:21:47  nw
101 javadoc
102 
103 Revision 1.2  2004/07/01 11:16:22  nw
104 merged in branch
105 nww-itn06-componentization
106 
107 Revision 1.1.2.3  2004/07/01 01:42:46  nw
108 final version, before merge
109 
110 Revision 1.1.2.2  2004/06/17 09:21:23  nw
111 finished all major functionality additions to core
112 
113 Revision 1.1.2.1  2004/06/14 08:56:58  nw
114 factored applications into sub-projects,
115 got packaging of wars to work again
116  
117 */