Source Code Cross Referenced for PropertyReader.java in  » J2EE » enhydra » org » enhydra » tool » archive » 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 » J2EE » enhydra » org.enhydra.tool.archive 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Enhydra Java Application Server Project
003:         *
004:         * The contents of this file are subject to the Enhydra Public License
005:         * Version 1.1 (the "License"); you may not use this file except in
006:         * compliance with the License. You may obtain a copy of the License on
007:         * the Enhydra web site ( http://www.enhydra.org/ ).
008:         *
009:         * Software distributed under the License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011:         * the License for the specific terms governing rights and limitations
012:         * under the License.
013:         *
014:         * The Initial Developer of the Enhydra Application Server is Lutris
015:         * Technologies, Inc. The Enhydra Application Server and portions created
016:         * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017:         * All Rights Reserved.
018:         *
019:         * Contributor(s):
020:         * Paul Mahar
021:         *
022:         */
023:        package org.enhydra.tool.archive;
024:
025:        // ToolBox
026:        import org.enhydra.tool.common.PathHandle;
027:
028:        // JDK
029:        import java.io.BufferedInputStream;
030:        import java.io.IOException;
031:        import java.io.File;
032:        import java.io.FileInputStream;
033:        import java.util.ArrayList;
034:        import java.util.Properties;
035:
036:        //
037:        public class PropertyReader implements  PropertyKeys {
038:            private Properties props = new Properties();
039:            private File file = null;
040:            private boolean validate = true;
041:
042:            public PropertyReader() {
043:            }
044:
045:            public boolean isValidate() {
046:                return validate;
047:            }
048:
049:            public void setValidate(boolean v) {
050:                validate = v;
051:            }
052:
053:            public JarPlan[] read(File in) throws IOException {
054:                FileInputStream fileStream = null;
055:                BufferedInputStream bufStream = null;
056:
057:                file = in;
058:                fileStream = new FileInputStream(file);
059:                bufStream = new BufferedInputStream(fileStream);
060:                props.load(bufStream);
061:                bufStream.close();
062:                fileStream.close();
063:                return read(props);
064:            }
065:
066:            public JarPlan[] read(Properties p) {
067:                ArrayList list = null;
068:                JarPlan[] plans = new JarPlan[0];
069:
070:                props = p;
071:                list = new ArrayList();
072:                for (int i = 0; i < 100; i++) {
073:                    JarPlan cursor = null;
074:                    String value = null;
075:
076:                    value = pathValue(props.getProperty(PATH + i));
077:                    if (isEmpty(value)) {
078:                        break;
079:                    } else {
080:                        try {
081:                            cursor = createPlan(i);
082:
083:                            // TODO: relative root expansion
084:                            cursor.setArchivePath(value);
085:                        } catch (ArchiveException e) {
086:                            e.printStackTrace(System.err);
087:                            cursor = null;
088:                        }
089:                    }
090:                    if (cursor != null) {
091:                        list.add(cursor);
092:                    }
093:                }
094:                list.trimToSize();
095:                plans = new JarPlan[list.size()];
096:                plans = (JarPlan[]) list.toArray(plans);
097:                list.clear();
098:                return plans;
099:            }
100:
101:            private JarPlan createPlan(int count) throws ArchiveException {
102:                String warValue = null;
103:                String earValue = null;
104:                String ejbValue = null;
105:                String jarValue = null;
106:                String serviceValue = null;
107:                JarPlan plan = null;
108:
109:                earValue = props.getProperty(APP_NAME_PROP + count);
110:                warValue = props.getProperty(CONTENT_ROOT_PROP + count);
111:                ejbValue = props.getProperty(CREATE_CLIENT_PROP + count);
112:                serviceValue = props.getProperty(Descriptor.ENHYDRA_SERVICE
113:                        + '.' + count);
114:                jarValue = props.getProperty(CLASS_ROOT_PROP + count);
115:                //Zeljko Kovacevic 28.10 2003 comment this
116:                /*        
117:                 if (!isEmpty(earValue)) {      	
118:                 plan = createEarPlan(count);
119:                 } else 
120:                 */
121:                if (!isEmpty(warValue)) {
122:                    plan = createWarPlan(count);
123:                    //Zeljko Kovacevic 28.10 2003 comment this
124:                    /*            
125:                     } else if (!isEmpty(ejbValue)) {
126:                     plan = createEjbPlan(count);
127:                     } else if (!isEmpty(serviceValue)) {
128:                     plan = createServicePlan(count);
129:                     */
130:                } else if (!isEmpty(jarValue)) {
131:                    plan = createJarPlan(count);
132:                }
133:                return plan;
134:            }
135:
136:            private JarPlan createJarPlan(int count) throws ArchiveException {
137:                JarPlan plan = null;
138:
139:                plan = new JarPlan();
140:                readJarProperties(plan, count);
141:                return plan;
142:            }
143:
144:            //Zeljko Kovacevic 28.10 2003 comment this
145:            /*
146:             private ServicePlan createServicePlan(int count) throws ArchiveException {
147:             ServicePlan plan = null;
148:
149:             plan = new ServicePlan();
150:             readJarProperties(plan, count);
151:             return plan;
152:             }
153:             */
154:            private void readJarProperties(JarPlan plan, int count)
155:                    throws ArchiveException {
156:                Descriptor[] dd = new Descriptor[0];
157:                String value = null;
158:                String[] files = new String[0];
159:
160:                plan.setValidate(isValidate());
161:
162:                // classes
163:                value = pathValue(props.getProperty(CLASS_ROOT_PROP + count));
164:                plan.setClassRoot(value);
165:                files = readFiles(CLASS, count);
166:                if (files.length > 0) {
167:                    plan.setClassFiles(files);
168:                }
169:
170:                // dd
171:                dd = plan.getDescriptors();
172:                for (int i = 0; i < dd.length; i++) {
173:                    value = pathValue(props.getProperty(dd[i].getType() + "."
174:                            + count));
175:                    dd[i].setPath(value);
176:                }
177:                plan.setDescriptors(dd);
178:            }
179:
180:            //Zeljko Kovacevic 28.10 2003 comment this
181:            /*
182:             private EjbPlan createEjbPlan(int count) throws ArchiveException {
183:             EjbPlan plan = null;
184:             Boolean b = null;
185:             String  value = null;
186:
187:             plan = new EjbPlan();
188:             readJarProperties(plan, count);
189:
190:             // create client
191:             value = props.getProperty(CREATE_CLIENT_PROP + count);
192:             b = Boolean.valueOf(value);
193:             plan.setCreateClient(b.booleanValue());
194:             return plan;
195:             }
196:
197:             private EarPlan createEarPlan(int count) throws ArchiveException {
198:             EarPlan          plan = null;
199:             String           value = null;
200:             Boolean          b = null;
201:             String[]         files = new String[0];
202:             WebApplication[] webApps = new WebApplication[0];
203:             Descriptor[]     dd = new Descriptor[0];
204:
205:             plan = new EarPlan();
206:             plan.setValidate(isValidate());
207:
208:             // app name
209:             value = props.getProperty(APP_NAME_PROP + count);
210:             plan.setAppName(value);
211:
212:             // description
213:             value = props.getProperty(APP_DESC_PROP + count);
214:             plan.setDescription(value);
215:
216:             // alt-dd
217:             value = props.getProperty(ALT_DD_PROP + count);
218:             b = Boolean.valueOf(value);
219:             plan.setAlt(b.booleanValue());
220:
221:             // copy-client
222:             value = props.getProperty(COPY_CLIENT_PROP + count);
223:             b = Boolean.valueOf(value);
224:             plan.setCopyClient(b.booleanValue());
225:
226:             // enterprise modules
227:             files = readFiles(ENTERPRISE_MODULE_PROP, count);
228:             if (files.length > 0) {
229:             plan.setEnterpriseModules(files);
230:             }
231:
232:             // webapps
233:             webApps = readWebApps(count);
234:             if (webApps.length > 0) {
235:             plan.setWebApplications(webApps);
236:             }
237:
238:             // libs
239:             files = readFiles(LIBRARY_PROP, count);
240:             if (files.length > 0) {
241:             plan.setLibFiles(files);
242:             }
243:
244:             // meta-dd
245:             files = readFiles(META_DD_PROP, count);
246:             if (files.length > 0) {
247:             dd = new Descriptor[files.length];
248:             for (int i = 0; i < dd.length; i++) {
249:             dd[i] = new Descriptor(files[i]);
250:             }
251:             plan.setDescriptors(dd);
252:             }
253:             return plan;
254:             }
255:             */
256:            private WarPlan createWarPlan(int count) throws ArchiveException {
257:                WarPlan plan = null;
258:                String value = null;
259:                String[] files = new String[0];
260:                Descriptor[] dd = new Descriptor[0];
261:
262:                plan = new WarPlan();
263:                readJarProperties(plan, count);
264:
265:                // content
266:                value = pathValue(props.getProperty(CONTENT_ROOT_PROP + count));
267:                plan.setContentRoot(value);
268:                files = readFiles(CONTENT, count);
269:                if (files.length > 0) {
270:                    plan.setContentFiles(files);
271:                }
272:
273:                // libs
274:                files = readFiles(LIBRARY_PROP, count);
275:                if (files.length > 0) {
276:                    plan.setLibFiles(files);
277:                }
278:
279:                //
280:                return plan;
281:            }
282:
283:            private String[] readFiles(String property, int count) {
284:                ArrayList list = new ArrayList();
285:                String[] files = new String[0];
286:                String value = null;
287:
288:                for (int i = 0; i < 2500; i++) {
289:                    value = pathValue(props.getProperty(property + count + "."
290:                            + i));
291:                    if (isEmpty(value)) {
292:                        break;
293:                    } else {
294:                        list.add(value);
295:                    }
296:                }
297:                list.trimToSize();
298:                files = new String[list.size()];
299:                files = (String[]) list.toArray(files);
300:                return files;
301:            }
302:
303:            private WebApplication[] readWebApps(int count) {
304:                ArrayList list = new ArrayList();
305:                WebApplication[] webApps = new WebApplication[0];
306:                String value = null;
307:
308:                for (int i = 0; i < 2500; i++) {
309:                    value = pathValue(props.getProperty(WEBAPP_MODULE_PROP
310:                            + count + "." + i));
311:                    if (isEmpty(value)) {
312:                        break;
313:                    } else {
314:                        WebApplication webApp = new WebApplication(value);
315:
316:                        value = props.getProperty(WEBAPP_CONTEXT_PROP + count
317:                                + "." + i);
318:                        if (!isEmpty(value)) {
319:                            webApp.setContextRoot(value);
320:                        }
321:                        list.add(webApp);
322:                    }
323:                }
324:                list.trimToSize();
325:                webApps = new WebApplication[list.size()];
326:                webApps = (WebApplication[]) list.toArray(webApps);
327:                return webApps;
328:            }
329:
330:            private boolean isEmpty(String value) {
331:                boolean empty = false;
332:
333:                if (value == null) {
334:                    empty = true;
335:                } else if (value.trim().length() == 0) {
336:                    empty = true;
337:                }
338:                return empty;
339:            }
340:
341:            private String pathValue(String in) {
342:                String out = null;
343:
344:                if (file == null) {
345:                    out = in;
346:                } else if (isEmpty(in)) {
347:                    out = in;
348:                } else {
349:                    PathHandle propPh = null;
350:                    PathHandle outPh = null;
351:
352:                    propPh = PathHandle.createPathHandle(file);
353:                    outPh = propPh.expandRelativePath(in);
354:                    out = outPh.getPath();
355:                }
356:                return out;
357:            }
358:
359:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.