KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > core > ant > InputHandlerSetter


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ant.internal.core.ant;
12
13
14 import java.text.MessageFormat JavaDoc; // can't use ICU in ant
15

16 import org.apache.tools.ant.BuildException;
17 import org.apache.tools.ant.Project;
18 import org.apache.tools.ant.input.DefaultInputHandler;
19 import org.apache.tools.ant.input.InputHandler;
20
21 /**
22  * This class exists so that the Ant integration has backwards compatibility
23  * with Ant releases previous to 1.5. InputHandlers are a new feature of Ant 1.5.
24  */

25 class InputHandlerSetter {
26
27     protected void setInputHandler(Project project, String JavaDoc inputHandlerClassname) {
28         InputHandler handler = null;
29         if (inputHandlerClassname == null) {
30             handler = new DefaultInputHandler();
31         } else {
32             try {
33                 handler = (InputHandler)(Class.forName(inputHandlerClassname).newInstance());
34             } catch (ClassCastException JavaDoc e) {
35                 String JavaDoc msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_The_specified_input_handler_class__0__does_not_implement_the_org_apache_tools_ant_input_InputHandler_interface_5, new String JavaDoc[]{inputHandlerClassname});
36                 throw new BuildException(msg, e);
37             } catch (Exception JavaDoc e) {
38                 String JavaDoc msg = MessageFormat.format(InternalAntMessages.InternalAntRunner_Unable_to_instantiate_specified_input_handler_class__0_____1__6, new String JavaDoc[]{inputHandlerClassname, e.getClass().getName()});
39                 throw new BuildException(msg, e);
40             }
41         }
42         project.setInputHandler(handler);
43         project.setProjectReference(handler);
44     }
45 }
46
Popular Tags