Source Code Cross Referenced for XDocletRunner.java in  » Database-ORM » db-ojb » xdoclet » junit » 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 » Database ORM » db ojb » xdoclet.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package xdoclet.junit;
002:
003:        /* Copyright 2003-2005 The Apache Software Foundation
004:         *
005:         * Licensed under the Apache License, Version 2.0 (the "License");
006:         * you may not use this file except in compliance with the License.
007:         * You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:
018:        import java.io.*;
019:        import java.lang.reflect.Method;
020:        import java.util.ArrayList;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:
024:        import org.apache.tools.ant.Project;
025:        import org.apache.tools.ant.types.FileSet;
026:
027:        import xdoclet.DocletTask;
028:        import xdoclet.XmlSubTask;
029:        import xdoclet.template.TemplateEngine;
030:
031:        /**
032:         * Runs xdoclet in a separate thread (with a special class loader).
033:         *
034:         * @author <a href="mailto:tomdz@users.sourceforge.net">Thomas Dudziak (tomdz@users.sourceforge.net)</a>
035:         */
036:        public class XDocletRunner extends Thread {
037:            private FileHandling _classWriter = new FileHandling();
038:            private ArrayList _srcFiles = new ArrayList();
039:            private ArrayList _srcDirectories = new ArrayList();
040:            private File _destFile = null;
041:            private String _taskName = null;
042:            private String _subTaskName = null;
043:            private HashMap _taskProperties = new HashMap();
044:            private HashMap _subTaskProperties = new HashMap();
045:            private String _result = null;
046:
047:            public XDocletRunner() {
048:                super ("XDocletRunner");
049:            }
050:
051:            public void addClass(String name, String content) {
052:                try {
053:                    _srcFiles.add(_classWriter.write(name, content));
054:                } catch (IOException ex) {
055:                    cleanFiles();
056:                    throw new RuntimeException(ex);
057:                }
058:            }
059:
060:            public void setDestFile(String path) {
061:                _destFile = _classWriter.ensurePath(path);
062:                _destFile.delete();
063:            }
064:
065:            public void setTaskName(String className) {
066:                _taskName = className;
067:            }
068:
069:            public void setSubTaskName(String className) {
070:                _subTaskName = className;
071:            }
072:
073:            public void setTaskProperty(String name, Object value) {
074:                _taskProperties.put(name, value);
075:            }
076:
077:            public void setSubTaskProperty(String name, Object value) {
078:                _subTaskProperties.put(name, value);
079:            }
080:
081:            /* (non-Javadoc)
082:             * @see java.lang.Runnable#run()
083:             */
084:            public void run() {
085:                _result = null;
086:
087:                DocletTask task = null;
088:
089:                try {
090:                    task = initTask();
091:                    if (_subTaskName != null) {
092:                        task.addSubTask(initSubTask());
093:                    }
094:                } catch (Exception ex) {
095:                    cleanFiles();
096:                    throw new RuntimeException(ex);
097:                }
098:
099:                try {
100:                    task.setVerbose(false);
101:                    task.init();
102:                    task.execute();
103:                } catch (Exception ex) {
104:                    // what to do with any exception ? rethrow it ?
105:                    cleanFiles();
106:                    return;
107:                }
108:
109:                if (_destFile != null) {
110:                    if (_destFile.exists()) {
111:                        try {
112:                            _result = getDestFileContents(_destFile
113:                                    .getAbsolutePath());
114:                        } catch (IOException ex) {
115:                        }
116:                    }
117:                }
118:                cleanFiles();
119:            }
120:
121:            public String getResult() {
122:                return _result;
123:            }
124:
125:            public void destroy() {
126:                cleanFiles();
127:            }
128:
129:            private void cleanFiles() {
130:                _destFile = null;
131:                _srcFiles.clear();
132:                _classWriter.removeTmpDir();
133:            }
134:
135:            private DocletTask initTask() throws Exception {
136:                DocletTask task = (DocletTask) this .getContextClassLoader()
137:                        .loadClass(_taskName).newInstance();
138:                FileSet files = new FileSet();
139:
140:                task.setDestDir(_classWriter.getTmpDir());
141:                files.setDir(_classWriter.getTmpDir());
142:
143:                StringBuffer includes = new StringBuffer();
144:
145:                for (Iterator it = _srcFiles.iterator(); it.hasNext();) {
146:                    if (includes.length() > 0) {
147:                        includes.append(" ");
148:                    }
149:                    includes.append(((File) it.next()).getName());
150:                }
151:
152:                task.addFileset(files);
153:                task.setProject(new Project());
154:
155:                String name;
156:
157:                for (Iterator it = _taskProperties.keySet().iterator(); it
158:                        .hasNext();) {
159:                    name = (String) it.next();
160:                    setProperty(task, name, _taskProperties.get(name));
161:                }
162:
163:                return task;
164:            }
165:
166:            private XmlSubTask initSubTask() throws Exception {
167:                XmlSubTask subTask = (XmlSubTask) this .getContextClassLoader()
168:                        .loadClass(_subTaskName).newInstance();
169:
170:                subTask.setEngine(TemplateEngine.getEngineInstance());
171:                if (_destFile != null) {
172:                    subTask.setDestinationFile(_destFile.getName());
173:                }
174:
175:                String name;
176:
177:                for (Iterator it = _subTaskProperties.keySet().iterator(); it
178:                        .hasNext();) {
179:                    name = (String) it.next();
180:                    setProperty(subTask, name, _subTaskProperties.get(name));
181:                }
182:
183:                return subTask;
184:            }
185:
186:            private void setProperty(Object obj, String propertyName,
187:                    Object propertyValue) throws Exception {
188:                String methodName = "set"
189:                        + Character.toUpperCase(propertyName.charAt(0));
190:
191:                if (propertyName.length() > 1) {
192:                    methodName += propertyName.substring(1);
193:                }
194:
195:                Method method = null;
196:
197:                try {
198:                    method = obj.getClass().getMethod(methodName,
199:                            new Class[] { propertyValue.getClass() });
200:                } catch (NoSuchMethodException ex) {
201:                    // we trying any method with that name then
202:                    Method[] methods = obj.getClass().getMethods();
203:
204:                    for (int idx = 0; idx < methods.length; idx++) {
205:                        if (methodName.equals(methods[idx].getName())) {
206:                            method = methods[idx];
207:                            break;
208:                        }
209:                    }
210:                    if (method == null) {
211:                        throw ex;
212:                    }
213:                }
214:                method.invoke(obj, new Object[] { propertyValue });
215:            }
216:
217:            private String getDestFileContents(String filename)
218:                    throws IOException {
219:                BufferedReader input = new BufferedReader(new FileReader(
220:                        filename));
221:                StringBuffer result = new StringBuffer();
222:                String line;
223:
224:                while ((line = input.readLine()) != null) {
225:                    result.append(line);
226:                    result.append("\n");
227:                }
228:                input.close();
229:                return result.toString().trim();
230:            }
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.