1 package org.astrogrid.applications.javaclass;
2
3 import java.io.IOException;
4 import org.apache.commons.logging.Log;
5 import org.apache.commons.logging.LogFactory;
6 import org.astrogrid.applications.manager.BaseConfiguration;
7 import org.astrogrid.component.descriptor.ComponentDescriptor;
8 import org.astrogrid.config.SimpleConfig;
9
10 /***
11 * A configuration object specialized for the JC-CEC.
12 * This kind of configuration has a method to get the
13 * class implementing the applications.
14 *
15 * This class uses SimpleConfig to get the information.
16 *
17 * @author Guy Rixon
18 */
19 public class BaseJavaClassConfiguration
20 extends BaseConfiguration
21 implements JavaClassConfiguration, ComponentDescriptor {
22
23 private static final Log logger
24 = LogFactory.getLog(BaseJavaClassConfiguration.class);
25
26 private Class applicationClass;
27
28 /***
29 * Constructs a BaseJavaClassConfiguration.
30 *
31 * @throws IOException If the superclass constructor fails.
32 */
33 public BaseJavaClassConfiguration() throws IOException {
34 super();
35 this.initializeApplicationClass();
36 }
37
38 /***
39 * Determines the name of the class implementing the application.
40 * The class name is read from the external environment. If not
41 * set in the environment, a default class is used.
42 */
43 protected void initializeApplicationClass() {
44 try {
45 String className
46 = SimpleConfig.getSingleton().getString("cea.javaclass.server.class");
47 this.applicationClass = Class.forName(className);
48 logger.info("The application is implemented by Java class " + className);
49 }
50 catch (Exception e) {
51 logger.warn("The class configured in cea.javaclass.server.class " +
52 "cannot be found. " +
53 SampleJavaClassApplications.class.getName() +
54 " will be used instead.");
55 this.applicationClass = SampleJavaClassApplications.class;
56 }
57 }
58
59 /***
60 * Obtains the class implementing the application.
61 *
62 * @return The class.
63 */
64 public Class getApplicationClass() {
65 return this.applicationClass;
66 }
67
68 /***
69 * Reveals the name of the component.
70 */
71 public String getName() {
72 return "Configuration for a Java-class CEC.";
73 }
74
75 /***
76 * Describes the component and its current state.
77 */
78 public String getDescription() {
79 StringBuffer sb = new StringBuffer();
80 sb.append("Class providing the applications: ");
81 sb.append(this.getApplicationClass().getName());
82 sb.append("\n");
83 return super.getDescription() + sb.toString();
84 }
85 }