KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.tools.ant.BuildException;
22 import org.apache.tools.ant.Task;
23 import org.apache.tools.ant.util.ClasspathUtils;
24
25 import java.util.Locale JavaDoc;
26
27
28 /**
29  * Creates the necessary rmic adapter, given basic criteria.
30  *
31  * @since 1.4
32  */

33 public final class RmicAdapterFactory {
34     /** The error message to be used when the compiler cannot be found. */
35     public static final String JavaDoc ERROR_UNKNOWN_COMPILER = "Class not found: ";
36
37     /** The error message to be used when the class is not an rmic adapter. */
38     public static final String JavaDoc ERROR_NOT_RMIC_ADAPTER = "Class of unexpected Type: ";
39
40     /** If the compiler has this name use a default compiler. */
41     public static final String JavaDoc DEFAULT_COMPILER = "default";
42
43     /** This is a singleton -- can't create instances!! */
44     private RmicAdapterFactory() {
45     }
46
47     /**
48      * Based on the parameter passed in, this method creates the necessary
49      * factory desired.
50      *
51      * <p>The current mapping for rmic names are as follows:</p>
52      * <ul><li>sun = SUN's rmic
53      * <li>kaffe = Kaffe's rmic
54      * <li><i>a fully quallified classname</i> = the name of a rmic
55      * adapter
56      * <li>weblogic = weblogic compiler
57      * <li>forking = Sun's RMIC by forking a new JVM
58      * </ul>
59      *
60      * @param rmicType either the name of the desired rmic, or the
61      * full classname of the rmic's adapter.
62      * @param task a task to log through.
63      * @return the compiler adapter
64      * @throws BuildException if the rmic type could not be resolved into
65      * a rmic adapter.
66      */

67     public static RmicAdapter getRmic(String JavaDoc rmicType, Task task)
68         throws BuildException {
69         //convert to lower case in the English locale,
70
String JavaDoc compiler = rmicType.toLowerCase(Locale.ENGLISH);
71
72         //handle default specially by choosing the sun or kaffe compiler
73
if (DEFAULT_COMPILER.equals(compiler) || compiler.length() == 0) {
74             compiler = KaffeRmic.isAvailable()
75                 ? KaffeRmic.COMPILER_NAME
76                 : SunRmic.COMPILER_NAME;
77         }
78         if (SunRmic.COMPILER_NAME.equals(compiler)) {
79             return new SunRmic();
80         } else if (KaffeRmic.COMPILER_NAME.equals(compiler)) {
81             return new KaffeRmic();
82         } else if (WLRmic.COMPILER_NAME.equals(compiler)) {
83             return new WLRmic();
84         } else if (ForkingSunRmic.COMPILER_NAME.equals(compiler)) {
85             return new ForkingSunRmic();
86         } else if (XNewRmic.COMPILER_NAME.equals(compiler)) {
87             return new XNewRmic();
88         }
89         //no match? ask for the non-lower-cased type
90
return resolveClassName(rmicType);
91     }
92
93     /**
94      * Tries to resolve the given classname into a rmic adapter.
95      * Throws a fit if it can't.
96      *
97      * @param className The fully qualified classname to be created.
98      * @throws BuildException This is the fit that is thrown if className
99      * isn't an instance of RmicAdapter.
100      */

101     private static RmicAdapter resolveClassName(String JavaDoc className)
102             throws BuildException {
103         return (RmicAdapter) ClasspathUtils.newInstance(className,
104                 RmicAdapterFactory.class.getClassLoader(), RmicAdapter.class);
105     }
106 }
107
Popular Tags