KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > rmic > WLRmic


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18
19 package org.apache.tools.ant.taskdefs.rmic;
20
21 import java.lang.reflect.Method JavaDoc;
22 import org.apache.tools.ant.AntClassLoader;
23 import org.apache.tools.ant.BuildException;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.types.Commandline;
26
27 /**
28  * The implementation of the rmic for WebLogic
29  *
30  * @since Ant 1.4
31  */

32 public class WLRmic extends DefaultRmicAdapter {
33     /** The classname of the weblogic rmic */
34     public static final String JavaDoc WLRMIC_CLASSNAME = "weblogic.rmic";
35     /**
36      * the name of this adapter for users to select
37      */

38     public static final String JavaDoc COMPILER_NAME = "weblogic";
39
40     /** The error string to use if not able to find the weblogic rmic */
41     public static final String JavaDoc ERROR_NO_WLRMIC_ON_CLASSPATH =
42         "Cannot use WebLogic rmic, as it is not "
43         + "available. A common solution is to "
44         + "set the environment variable "
45         + "CLASSPATH.";
46
47     /** The error string to use if not able to start the weblogic rmic */
48     public static final String JavaDoc ERROR_WLRMIC_FAILED = "Error starting WebLogic rmic: ";
49     /** The stub suffix */
50     public static final String JavaDoc WL_RMI_STUB_SUFFIX = "_WLStub";
51     /** The skeleton suffix */
52     public static final String JavaDoc WL_RMI_SKEL_SUFFIX = "_WLSkel";
53
54     /**
55      * Carry out the rmic compilation.
56      * @return true if the compilation succeeded
57      * @throws BuildException on error
58      */

59     public boolean execute() throws BuildException {
60         getRmic().log("Using WebLogic rmic", Project.MSG_VERBOSE);
61         Commandline cmd = setupRmicCommand(new String JavaDoc[] {"-noexit"});
62
63         AntClassLoader loader = null;
64         try {
65             // Create an instance of the rmic
66
Class JavaDoc c = null;
67             if (getRmic().getClasspath() == null) {
68                 c = Class.forName(WLRMIC_CLASSNAME);
69             } else {
70                 loader
71                     = getRmic().getProject().createClassLoader(getRmic().getClasspath());
72                 c = Class.forName(WLRMIC_CLASSNAME, true, loader);
73             }
74             Method JavaDoc doRmic = c.getMethod("main",
75                                         new Class JavaDoc [] {String JavaDoc[].class});
76             doRmic.invoke(null, new Object JavaDoc[] {cmd.getArguments()});
77             return true;
78         } catch (ClassNotFoundException JavaDoc ex) {
79             throw new BuildException(ERROR_NO_WLRMIC_ON_CLASSPATH, getRmic().getLocation());
80         } catch (Exception JavaDoc ex) {
81             if (ex instanceof BuildException) {
82                 throw (BuildException) ex;
83             } else {
84                 throw new BuildException(ERROR_WLRMIC_FAILED, ex,
85                                          getRmic().getLocation());
86             }
87         } finally {
88             if (loader != null) {
89                 loader.cleanup();
90             }
91         }
92     }
93
94     /**
95      * Get the suffix for the rmic stub classes
96      * @return the stub suffix
97      */

98     public String JavaDoc getStubClassSuffix() {
99         return WL_RMI_STUB_SUFFIX;
100     }
101
102     /**
103      * Get the suffix for the rmic skeleton classes
104      * @return the skeleton suffix
105      */

106     public String JavaDoc getSkelClassSuffix() {
107         return WL_RMI_SKEL_SUFFIX;
108     }
109 }
110
Popular Tags