source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/rmic/RmicAdapterFactory.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 3.1 KB
Line 
1/*
2 * Copyright 2001-2002,2004 The Apache Software Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.apache.tools.ant.taskdefs.rmic;
19
20import org.apache.tools.ant.BuildException;
21import org.apache.tools.ant.Task;
22
23
24/**
25 * Creates the necessary rmic adapter, given basic criteria.
26 *
27 * @since 1.4
28 */
29public class RmicAdapterFactory {
30
31 /** This is a singleton -- can't create instances!! */
32 private RmicAdapterFactory() {
33 }
34
35 /**
36 * Based on the parameter passed in, this method creates the necessary
37 * factory desired.
38 *
39 * <p>The current mapping for rmic names are as follows:</p>
40 * <ul><li>sun = SUN's rmic
41 * <li>kaffe = Kaffe's rmic
42 * <li><i>a fully quallified classname</i> = the name of a rmic
43 * adapter
44 * </ul>
45 *
46 * @param rmicType either the name of the desired rmic, or the
47 * full classname of the rmic's adapter.
48 * @param task a task to log through.
49 * @throws BuildException if the rmic type could not be resolved into
50 * a rmic adapter.
51 */
52 public static RmicAdapter getRmic(String rmicType, Task task)
53 throws BuildException {
54 if (rmicType.equalsIgnoreCase("sun")) {
55 return new SunRmic();
56 } else if (rmicType.equalsIgnoreCase("kaffe")) {
57 return new KaffeRmic();
58 } else if (rmicType.equalsIgnoreCase("weblogic")) {
59 return new WLRmic();
60 }
61 return resolveClassName(rmicType);
62 }
63
64 /**
65 * Tries to resolve the given classname into a rmic adapter.
66 * Throws a fit if it can't.
67 *
68 * @param className The fully qualified classname to be created.
69 * @throws BuildException This is the fit that is thrown if className
70 * isn't an instance of RmicAdapter.
71 */
72 private static RmicAdapter resolveClassName(String className)
73 throws BuildException {
74 try {
75 Class c = Class.forName(className);
76 Object o = c.newInstance();
77 return (RmicAdapter) o;
78 } catch (ClassNotFoundException cnfe) {
79 throw new BuildException(className + " can\'t be found.", cnfe);
80 } catch (ClassCastException cce) {
81 throw new BuildException(className + " isn\'t the classname of "
82 + "a rmic adapter.", cce);
83 } catch (Throwable t) {
84 // for all other possibilities
85 throw new BuildException(className + " caused an interesting "
86 + "exception.", t);
87 }
88 }
89}
Note: See TracBrowser for help on using the repository browser.