View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    * 
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   * 
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.river.tool.envcheck.plugins;
19  
20  import org.apache.river.tool.envcheck.AbstractPlugin;
21  import org.apache.river.tool.envcheck.Plugin;
22  import org.apache.river.tool.envcheck.EnvCheck;
23  import org.apache.river.tool.envcheck.Reporter;
24  import org.apache.river.tool.envcheck.Reporter.Message;
25  import org.apache.river.tool.envcheck.SubVMTask;
26  import org.apache.river.tool.envcheck.Util;
27  import java.io.File;
28  import org.apache.river.start.SharedActivationGroupDescriptor;
29  
30  /**
31   * Check that the Java platform is at least version 1.4. This check is applied
32   * to the VM invoked by the command line being analyzed and the VM invoked by
33   *  a <code>SharedActivationGroupDescriptor</code> if the
34   * descriptor's <code>getServerCommand()</code> method returns non-null. 
35   */
36  public class CheckJDK1_4 extends AbstractPlugin {
37  
38      /** reference to the plugin  container */
39      private EnvCheck envCheck;
40  
41      /** name of task to execute */
42      private String taskName = taskName("JDK1_4Task");
43  
44      /**
45       * Check the validity of the activation group VM (if there is one)
46       *
47       * @param envCheck the container
48       */
49      public void run(EnvCheck envCheck) {
50  	this.envCheck = envCheck;
51  	checkMainVM();
52  	checkGroupVM();
53      }
54  
55      /**
56       * Check the activation group VM. If there is a
57       * <code>SharedActivationGroupDescriptor</code> available from the
58       * container, invoke a subtask which verifies that the VM used to run that
59       * group is at least version 1.4.
60       */
61      private void checkGroupVM() {
62  	SharedActivationGroupDescriptor gd = envCheck.getGroupDescriptor();
63  	if (gd != null) {
64  	    String source;
65  	    String serverCommand = gd.getServerCommand();
66  	    if (serverCommand == null) {
67  		source = getString("cmdlinejava", envCheck.getJavaCmd());
68  	    } else {
69  		source = getString("groupjava", serverCommand);
70  	    }
71  	    processReturn(envCheck.launch(null, gd, taskName), source);
72  	}
73      }
74  
75      /**
76       * Check the vm invoked by the command-line java command.
77       */
78      private void checkMainVM() {
79  	String source = getString("mainsource", envCheck.getJavaCmd());
80  	processReturn(envCheck.launch(taskName), source);
81      }
82  
83      /**
84       * Process the object returned by the subtask. Prints a success or
85       * failure message based on the type and contents of <code>o</code>.
86       *
87       * @param o the object returned by the subtask
88       * @param source the source description
89       */
90      private void processReturn(Object o, String source) {
91  	if (o instanceof Boolean) {
92  	    Message message;
93  	    if (((Boolean) o).booleanValue()) {
94  		message = new Message(Reporter.INFO,
95  				      getString("goodjdk"),
96  				      getString("jdkExp"));
97  	    } else {
98  		message = new Message(Reporter.INFO,
99  				      getString("badjdk"),
100 				      getString("jdkExp"));
101 	    }
102 	    Reporter.print(message, source);
103 	} else {
104 	    handleUnexpectedSubtaskReturn(o, source);
105 	}
106     }
107 
108     /**
109      * Subtask to check the VM version. If it is possible to load
110      * <code>java.rmi.server.RMIClassLoaderSpi</code>, then this VM is presumed
111      * to be at least version 1.4. The run method return a
112      * <code>Boolean(true)</code> if the version is OK.
113      */
114     public static class JDK1_4Task implements SubVMTask {
115 	
116 	public Object run(String[] args) {
117 	    try {
118 		Class.forName("java.rmi.server.RMIClassLoaderSpi");
119 		return new Boolean(true);
120 	    } catch (ClassNotFoundException e) {
121 		return new Boolean(false);
122 	    }
123 	}
124     }
125 }