587
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.ant.util;
|
|
19 |
|
628
|
20 |
import org.apache.log4j.Logger;
|
587
|
21 |
|
|
22 |
import com.nokia.tools.Tool;
|
|
23 |
import com.nokia.tools.ToolsProcessException;
|
|
24 |
/**
|
|
25 |
* Utility class to read property value, if property is not defined it will raise an exception.
|
|
26 |
*
|
|
27 |
*/
|
|
28 |
public final class ToolsProcess {
|
|
29 |
private static Logger log;
|
|
30 |
|
|
31 |
private ToolsProcess() { }
|
|
32 |
|
|
33 |
public static Tool getTool(String reqTool) throws ToolsProcessException {
|
|
34 |
if (log == null) {
|
|
35 |
log = Logger.getLogger(ToolsProcess.class);
|
|
36 |
}
|
|
37 |
log.info("processing for tool" + reqTool);
|
|
38 |
Class toolClass = null;
|
|
39 |
String className = "com.nokia.tools."
|
|
40 |
+ reqTool.toLowerCase() + "." + reqTool.toUpperCase()
|
|
41 |
+ "Tool";
|
|
42 |
try {
|
|
43 |
toolClass = Class.forName(className);
|
|
44 |
Tool tool = (Tool) toolClass.newInstance();
|
|
45 |
log.debug("Found tool" + reqTool);
|
|
46 |
return tool;
|
|
47 |
} catch (ClassNotFoundException e1) {
|
|
48 |
throw new ToolsProcessException("tool not supported: " + className);
|
|
49 |
} catch (InstantiationException e2) {
|
|
50 |
throw new ToolsProcessException("tool " + toolClass
|
|
51 |
+ "cannot be instantiated");
|
|
52 |
} catch (IllegalAccessException e3) {
|
|
53 |
throw new ToolsProcessException("tool " + toolClass
|
|
54 |
+ " cannot be accessed");
|
|
55 |
}
|
|
56 |
}
|
|
57 |
} |