Source Code Cross Referenced for AbstractCeltixToolContainer.java in  » ESB » celtix-1.0 » org » objectweb » celtix » tools » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » celtix 1.0 » org.objectweb.celtix.tools 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.objectweb.celtix.tools;
002:
003:        import java.io.IOException;
004:        import java.io.InputStream;
005:        import java.util.ArrayList;
006:        import java.util.HashMap;
007:        import java.util.List;
008:        import java.util.Map;
009:        import java.util.Properties;
010:        import java.util.Set;
011:        import java.util.StringTokenizer;
012:        import java.util.logging.Logger;
013:
014:        import org.objectweb.celtix.common.logging.LogUtils;
015:        import org.objectweb.celtix.tools.common.ToolConstants;
016:        import org.objectweb.celtix.tools.common.ToolException;
017:        import org.objectweb.celtix.tools.common.toolspec.AbstractToolContainer;
018:        import org.objectweb.celtix.tools.common.toolspec.ToolSpec;
019:        import org.objectweb.celtix.tools.common.toolspec.parser.BadUsageException;
020:        import org.objectweb.celtix.tools.common.toolspec.parser.CommandDocument;
021:        import org.objectweb.celtix.tools.common.toolspec.parser.CommandLineParser;
022:        import org.objectweb.celtix.tools.common.toolspec.parser.ErrorVisitor;
023:        import org.objectweb.celtix.version.Version;
024:
025:        public abstract class AbstractCeltixToolContainer extends
026:                AbstractToolContainer {
027:            protected static final Logger LOG = LogUtils
028:                    .getL7dLogger(AbstractCeltixToolContainer.class);
029:            private static AbstractCeltixToolContainer instance;
030:
031:            private final String name;
032:            private CommandDocument commandDocument;
033:            private boolean verbose;
034:            private String usage;
035:            private final ErrorVisitor errors = new ErrorVisitor();
036:
037:            public AbstractCeltixToolContainer(String nm, ToolSpec toolspec)
038:                    throws Exception {
039:                super (toolspec);
040:                name = nm;
041:                instance = this ;
042:            }
043:
044:            public static AbstractCeltixToolContainer getInstance() {
045:                return instance;
046:            }
047:
048:            public boolean hasInfoOption() throws ToolException {
049:                boolean result = false;
050:                commandDocument = getCommandDocument();
051:                if ((commandDocument.hasParameter("help"))
052:                        || (commandDocument.hasParameter("version"))) {
053:                    result = true;
054:                }
055:                return result;
056:            }
057:
058:            public void execute(boolean exitOnFinish) throws ToolException {
059:                if (hasInfoOption()) {
060:                    outputInfo();
061:                } else {
062:                    if (commandDocument.hasParameter("verbose")) {
063:                        verbose = true;
064:                        outputFullCommandLine();
065:                        outputVersion();
066:
067:                    }
068:                    checkParams(errors);
069:                }
070:            }
071:
072:            private void outputInfo() {
073:                CommandLineParser parser = getCommandLineParser();
074:
075:                if (commandDocument.hasParameter("help")) {
076:                    try {
077:                        System.out.println(name + " " + getUsage());
078:                        System.out.println();
079:                        System.out.println("Options : ");
080:                        System.out.println();
081:                        System.out.println(parser.getDetailedUsage());
082:                        String toolUsage = parser.getToolUsage();
083:
084:                        if (toolUsage != null) {
085:                            System.out.println(toolUsage);
086:                            System.out.println();
087:                        }
088:                    } catch (Exception ex) {
089:                        System.err
090:                                .println("Error : Could not output detailed usage");
091:                        System.err.println();
092:                    }
093:                }
094:                if (commandDocument.hasParameter("version")) {
095:                    outputVersion();
096:                }
097:            }
098:
099:            public abstract void checkParams(ErrorVisitor err)
100:                    throws ToolException;
101:
102:            public boolean isVerboseOn() {
103:                return verbose;
104:            }
105:
106:            public String getToolName() {
107:                return name;
108:            }
109:
110:            public String getUsage() {
111:                if (usage == null) {
112:                    try {
113:                        CommandLineParser parser = getCommandLineParser();
114:
115:                        if (parser != null) {
116:                            usage = parser.getUsage();
117:                        }
118:                    } catch (Exception ex) {
119:                        usage = "Could not get usage for the tool";
120:                    }
121:                }
122:                return usage;
123:            }
124:
125:            public void outputVersion() {
126:                System.out.println(name + " - "
127:                        + Version.getCompleteVersionString());
128:                System.out.println();
129:            }
130:
131:            public void outputFullCommandLine() {
132:                System.out.print(name);
133:                for (int i = 0; i < getArgument().length; i++) {
134:                    System.out.print(" " + getArgument()[i]);
135:                }
136:                System.out.println();
137:            }
138:
139:            public String getFileBase(String wsdlUrl) {
140:                String fileBase = wsdlUrl;
141:                StringTokenizer tok = new StringTokenizer(wsdlUrl, "\\/");
142:
143:                while (tok.hasMoreTokens()) {
144:                    fileBase = tok.nextToken();
145:                }
146:                if (fileBase.endsWith(".wsdl")) {
147:                    fileBase = new String(fileBase.substring(0, fileBase
148:                            .length() - 5));
149:                }
150:                return fileBase;
151:            }
152:
153:            public void printUsageException(String toolName,
154:                    BadUsageException ex) {
155:                if (getInstance().verbose) {
156:                    getInstance().outputFullCommandLine();
157:                }
158:                System.err.println(ex.getMessage());
159:                System.err.println("Usage : " + toolName + " " + ex.getUsage());
160:                if (getInstance().verbose) {
161:                    getInstance().outputVersion();
162:                }
163:                System.err.println();
164:            }
165:
166:            public String getFileName(String loc) {
167:                int idx = loc.lastIndexOf("/");
168:
169:                if (idx != -1) {
170:                    loc = loc.substring(idx + 1);
171:                }
172:                idx = loc.lastIndexOf("\\");
173:                if (idx != -1) {
174:                    loc = loc.substring(idx + 1);
175:                }
176:
177:                idx = loc.lastIndexOf(".");
178:                if (idx != -1) {
179:                    loc = loc.substring(0, idx);
180:                }
181:
182:                StringTokenizer strToken = new StringTokenizer(loc,
183:                        "-.!~*'();?:@&=+$,");
184:                StringBuffer strBuf = new StringBuffer();
185:
186:                if (!strToken.hasMoreTokens()) {
187:                    strBuf.append(loc);
188:                }
189:
190:                while (strToken.hasMoreTokens()) {
191:                    strBuf.append(strToken.nextToken());
192:                    if (strToken.countTokens() != 0) {
193:                        strBuf.append("_");
194:                    }
195:                }
196:
197:                return strBuf.toString();
198:            }
199:
200:            private InputStream getResourceAsStream(String resource) {
201:                ClassLoader cl = AbstractCeltixToolContainer.class
202:                        .getClassLoader();
203:                InputStream ins = cl.getResourceAsStream(resource);
204:                if (ins == null && resource.startsWith("/")) {
205:                    ins = cl.getResourceAsStream(resource.substring(1));
206:                }
207:                return ins;
208:            }
209:
210:            public Properties loadProperties(String propertyFile) {
211:                Properties p = new Properties();
212:
213:                try {
214:                    InputStream ins = getResourceAsStream(ToolConstants.TOOLSPECS_BASE
215:                            + propertyFile);
216:
217:                    p.load(ins);
218:                    ins.close();
219:                } catch (IOException ex) {
220:                    // ignore, use defaults
221:                }
222:                return p;
223:            }
224:
225:            protected String[] getDefaultExcludedNamespaces(String excludeProps) {
226:                List<String> result = new ArrayList<String>();
227:                Properties props = loadProperties(excludeProps);
228:                java.util.Enumeration nexcludes = props.propertyNames();
229:
230:                while (nexcludes.hasMoreElements()) {
231:                    result.add(props.getProperty((String) nexcludes
232:                            .nextElement()));
233:                }
234:                return result.toArray(new String[result.size()]);
235:            }
236:
237:            /**
238:             * get all parameters in a map
239:             * @param stringArrayKeys, contains keys, whose value should be string array
240:             */
241:            protected Map<String, Object> getParametersMap(Set stringArrayKeys) {
242:                Map<String, Object> map = new HashMap<String, Object>();
243:                CommandDocument doc = getCommandDocument();
244:                String[] keys = doc.getParameterNames();
245:                if (keys == null) {
246:                    return map;
247:                }
248:                for (int i = 0; i < keys.length; i++) {
249:                    if (stringArrayKeys.contains(keys[i])) {
250:                        map.put(keys[i], doc.getParameters(keys[i]));
251:                    } else {
252:                        map.put(keys[i], doc.getParameter(keys[i]));
253:                    }
254:                }
255:                return map;
256:            }
257:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.