Source Code Cross Referenced for ComponentConfig.java in  » ERP-CRM-Financial » ofbiz » org » ofbiz » base » component » 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 » ERP CRM Financial » ofbiz » org.ofbiz.base.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         * 
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         *******************************************************************************/package org.ofbiz.base.component;
019:
020:        import java.io.File;
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:        import java.net.URL;
024:        import java.util.Collection;
025:        import java.util.Comparator;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.TreeMap;
030:        import java.security.KeyStore;
031:        import javax.xml.parsers.ParserConfigurationException;
032:
033:        import javolution.util.FastList;
034:        import javolution.util.FastMap;
035:        import org.ofbiz.base.util.*;
036:        import org.w3c.dom.Document;
037:        import org.w3c.dom.Element;
038:        import org.xml.sax.SAXException;
039:
040:        /**
041:         * ComponentConfig - Component configuration class for ofbiz-container.xml
042:         *
043:         */
044:        public class ComponentConfig {
045:
046:            public static final String module = ComponentConfig.class.getName();
047:            public static final String OFBIZ_COMPONENT_XML_FILENAME = "ofbiz-component.xml";
048:
049:            // this is not a UtilCache because reloading may cause problems
050:            protected static Map componentConfigs = FastMap.newInstance();
051:            protected static Map serverWebApps = FastMap.newInstance();
052:
053:            public static ComponentConfig getComponentConfig(String globalName)
054:                    throws ComponentException {
055:                // TODO: we need to look up the rootLocation from the container config, or this will blow up
056:                return getComponentConfig(globalName, null);
057:            }
058:
059:            public static ComponentConfig getComponentConfig(String globalName,
060:                    String rootLocation) throws ComponentException {
061:                ComponentConfig componentConfig = null;
062:                if (UtilValidate.isNotEmpty(globalName)) {
063:                    componentConfig = (ComponentConfig) componentConfigs
064:                            .get(globalName);
065:                }
066:                if (componentConfig == null) {
067:                    if (rootLocation != null) {
068:                        synchronized (ComponentConfig.class) {
069:                            if (UtilValidate.isNotEmpty(globalName)) {
070:                                componentConfig = (ComponentConfig) componentConfigs
071:                                        .get(globalName);
072:                            }
073:                            if (componentConfig == null) {
074:                                componentConfig = new ComponentConfig(
075:                                        globalName, rootLocation);
076:                                if (componentConfigs
077:                                        .containsKey(componentConfig
078:                                                .getGlobalName())) {
079:                                    Debug
080:                                            .logWarning(
081:                                                    "WARNING: Loading ofbiz-component using a global name that already exists, will over-write: "
082:                                                            + componentConfig
083:                                                                    .getGlobalName(),
084:                                                    module);
085:                                }
086:                                if (componentConfig.enabled()) {
087:                                    componentConfigs.put(componentConfig
088:                                            .getGlobalName(), componentConfig);
089:                                }
090:                            }
091:                        }
092:                    } else {
093:                        throw new ComponentException(
094:                                "No component found named : " + globalName);
095:                    }
096:                }
097:                return componentConfig;
098:            }
099:
100:            public static Collection getAllComponents() {
101:                Collection values = componentConfigs.values();
102:                if (values != null) {
103:                    return values;
104:                } else {
105:                    Debug
106:                            .logWarning(
107:                                    "No components were found, something is probably missing or incorrect in the component-load setup.",
108:                                    module);
109:                    return FastList.newInstance();
110:                }
111:            }
112:
113:            public static List getAllClasspathInfos() {
114:                return getAllClasspathInfos(null);
115:            }
116:
117:            public static List getAllClasspathInfos(String componentName) {
118:                List classpaths = FastList.newInstance();
119:                Iterator i = getAllComponents().iterator();
120:                while (i.hasNext()) {
121:                    ComponentConfig cc = (ComponentConfig) i.next();
122:                    if (componentName == null
123:                            || componentName.equals(cc.getComponentName())) {
124:                        classpaths.addAll(cc.getClasspathInfos());
125:                    }
126:                }
127:                return classpaths;
128:            }
129:
130:            public static List getAllEntityResourceInfos(String type) {
131:                return getAllEntityResourceInfos(type, null);
132:            }
133:
134:            public static List getAllEntityResourceInfos(String type,
135:                    String componentName) {
136:                List entityInfos = FastList.newInstance();
137:                Iterator i = getAllComponents().iterator();
138:                while (i.hasNext()) {
139:                    ComponentConfig cc = (ComponentConfig) i.next();
140:                    if (componentName == null
141:                            || componentName.equals(cc.getComponentName())) {
142:                        List ccEntityInfoList = cc.getEntityResourceInfos();
143:                        if (UtilValidate.isEmpty(type)) {
144:                            entityInfos.addAll(ccEntityInfoList);
145:                        } else {
146:                            Iterator ccEntityInfoIter = ccEntityInfoList
147:                                    .iterator();
148:                            while (ccEntityInfoIter.hasNext()) {
149:                                EntityResourceInfo entityResourceInfo = (EntityResourceInfo) ccEntityInfoIter
150:                                        .next();
151:                                if (type.equals(entityResourceInfo.type)) {
152:                                    entityInfos.add(entityResourceInfo);
153:                                }
154:                            }
155:                        }
156:                    }
157:                }
158:                return entityInfos;
159:            }
160:
161:            public static List getAllServiceResourceInfos(String type) {
162:                return getAllServiceResourceInfos(type, null);
163:            }
164:
165:            public static List getAllServiceResourceInfos(String type,
166:                    String componentName) {
167:                List serviceInfos = FastList.newInstance();
168:                Iterator i = getAllComponents().iterator();
169:                while (i.hasNext()) {
170:                    ComponentConfig cc = (ComponentConfig) i.next();
171:                    if (componentName == null
172:                            || componentName.equals(cc.getComponentName())) {
173:                        List ccServiceInfoList = cc.getServiceResourceInfos();
174:                        if (UtilValidate.isEmpty(type)) {
175:                            serviceInfos.addAll(ccServiceInfoList);
176:                        } else {
177:                            Iterator ccServiceInfoIter = ccServiceInfoList
178:                                    .iterator();
179:                            while (ccServiceInfoIter.hasNext()) {
180:                                ServiceResourceInfo serviceResourceInfo = (ServiceResourceInfo) ccServiceInfoIter
181:                                        .next();
182:                                if (type.equals(serviceResourceInfo.type)) {
183:                                    serviceInfos.add(serviceResourceInfo);
184:                                }
185:                            }
186:                        }
187:                    }
188:                }
189:                return serviceInfos;
190:            }
191:
192:            public static List getAllTestSuiteInfos() {
193:                return getAllTestSuiteInfos(null);
194:            }
195:
196:            public static List getAllTestSuiteInfos(String componentName) {
197:                List testSuiteInfos = FastList.newInstance();
198:                Iterator i = getAllComponents().iterator();
199:                while (i.hasNext()) {
200:                    ComponentConfig cc = (ComponentConfig) i.next();
201:                    if (componentName == null
202:                            || componentName.equals(cc.getComponentName())) {
203:                        testSuiteInfos.addAll(cc.getTestSuiteInfos());
204:                    }
205:                }
206:                return testSuiteInfos;
207:            }
208:
209:            public static List getAllKeystoreInfos() {
210:                return getAllKeystoreInfos(null);
211:            }
212:
213:            public static List getAllKeystoreInfos(String componentName) {
214:                List keystoreInfos = FastList.newInstance();
215:                Iterator i = getAllComponents().iterator();
216:                while (i.hasNext()) {
217:                    ComponentConfig cc = (ComponentConfig) i.next();
218:                    if (componentName == null
219:                            || componentName.equals(cc.getComponentName())) {
220:                        keystoreInfos.addAll(cc.getKeystoreInfos());
221:                    }
222:                }
223:                return keystoreInfos;
224:            }
225:
226:            public static KeystoreInfo getKeystoreInfo(String componentName,
227:                    String keystoreName) {
228:                Iterator i = getAllComponents().iterator();
229:                while (i.hasNext()) {
230:                    ComponentConfig cc = (ComponentConfig) i.next();
231:                    if (componentName != null
232:                            && componentName.equals(cc.getComponentName())) {
233:                        Iterator ki = cc.getKeystoreInfos().iterator();
234:                        while (ki.hasNext()) {
235:                            KeystoreInfo ks = (KeystoreInfo) ki.next();
236:                            if (keystoreName != null
237:                                    && keystoreName.equals(ks.getName())) {
238:                                return ks;
239:                            }
240:                        }
241:                    }
242:                }
243:
244:                return null;
245:            }
246:
247:            public static List getAllWebappResourceInfos() {
248:                return getAllWebappResourceInfos(null);
249:            }
250:
251:            public static List getAllWebappResourceInfos(String componentName) {
252:                List webappInfos = FastList.newInstance();
253:                Iterator i = getAllComponents().iterator();
254:                while (i.hasNext()) {
255:                    ComponentConfig cc = (ComponentConfig) i.next();
256:                    if (componentName == null
257:                            || componentName.equals(cc.getComponentName())) {
258:                        webappInfos.addAll(cc.getWebappInfos());
259:                    }
260:                }
261:                return webappInfos;
262:            }
263:
264:            public static boolean isFileResourceLoader(String componentName,
265:                    String resourceLoaderName) throws ComponentException {
266:                ComponentConfig cc = ComponentConfig
267:                        .getComponentConfig(componentName);
268:                if (cc == null) {
269:                    throw new ComponentException(
270:                            "Could not find component with name: "
271:                                    + componentName);
272:                }
273:                return cc.isFileResourceLoader(resourceLoaderName);
274:            }
275:
276:            public static InputStream getStream(String componentName,
277:                    String resourceLoaderName, String location)
278:                    throws ComponentException {
279:                ComponentConfig cc = ComponentConfig
280:                        .getComponentConfig(componentName);
281:                if (cc == null) {
282:                    throw new ComponentException(
283:                            "Could not find component with name: "
284:                                    + componentName);
285:                }
286:                return cc.getStream(resourceLoaderName, location);
287:            }
288:
289:            public static URL getURL(String componentName,
290:                    String resourceLoaderName, String location)
291:                    throws ComponentException {
292:                ComponentConfig cc = ComponentConfig
293:                        .getComponentConfig(componentName);
294:                if (cc == null) {
295:                    throw new ComponentException(
296:                            "Could not find component with name: "
297:                                    + componentName);
298:                }
299:                return cc.getURL(resourceLoaderName, location);
300:            }
301:
302:            public static String getFullLocation(String componentName,
303:                    String resourceLoaderName, String location)
304:                    throws ComponentException {
305:                ComponentConfig cc = ComponentConfig
306:                        .getComponentConfig(componentName);
307:                if (cc == null) {
308:                    throw new ComponentException(
309:                            "Could not find component with name: "
310:                                    + componentName);
311:                }
312:                return cc.getFullLocation(resourceLoaderName, location);
313:            }
314:
315:            public static String getRootLocation(String componentName)
316:                    throws ComponentException {
317:                ComponentConfig cc = ComponentConfig
318:                        .getComponentConfig(componentName);
319:                if (cc == null) {
320:                    throw new ComponentException(
321:                            "Could not find component with name: "
322:                                    + componentName);
323:                }
324:                return cc.getRootLocation();
325:            }
326:
327:            public static List getAppBarWebInfos(String serverName) {
328:                return ComponentConfig.getAppBarWebInfos(serverName, null);
329:            }
330:
331:            public static List getAppBarWebInfos(String serverName,
332:                    Comparator comp) {
333:                List webInfos = (List) serverWebApps.get(serverName);
334:                if (webInfos == null) {
335:                    synchronized (ComponentConfig.class) {
336:                        if (webInfos == null) {
337:                            Map tm = null;
338:                            Iterator i = getAllComponents().iterator();
339:
340:                            // use a TreeMap to sort the components alpha by title
341:                            if (comp != null) {
342:                                tm = new TreeMap(comp);
343:                            } else {
344:                                tm = new TreeMap();
345:                            }
346:
347:                            while (i.hasNext()) {
348:                                ComponentConfig cc = (ComponentConfig) i.next();
349:                                Iterator wi = cc.getWebappInfos().iterator();
350:                                while (wi.hasNext()) {
351:                                    ComponentConfig.WebappInfo wInfo = (ComponentConfig.WebappInfo) wi
352:                                            .next();
353:                                    if (serverName.equals(wInfo.server)
354:                                            && wInfo.appBarDisplay) {
355:                                        tm.put(wInfo.title, wInfo);
356:                                    }
357:                                }
358:                            }
359:                            List webInfoList = FastList.newInstance();
360:                            webInfoList.addAll(tm.values());
361:                            serverWebApps.put(serverName, webInfoList);
362:                            return webInfoList;
363:                        }
364:                    }
365:                }
366:                return webInfos;
367:            }
368:
369:            public static WebappInfo getWebAppInfo(String serverName,
370:                    String contextRoot) {
371:                ComponentConfig.WebappInfo info = null;
372:                if (serverName == null || contextRoot == null) {
373:                    return info;
374:                }
375:
376:                Iterator i = getAllComponents().iterator();
377:                while (i.hasNext() && info == null) {
378:                    ComponentConfig cc = (ComponentConfig) i.next();
379:                    Iterator wi = cc.getWebappInfos().iterator();
380:                    while (wi.hasNext()) {
381:                        ComponentConfig.WebappInfo wInfo = (ComponentConfig.WebappInfo) wi
382:                                .next();
383:                        if (serverName.equals(wInfo.server)
384:                                && contextRoot.equals(wInfo.getContextRoot())) {
385:                            info = wInfo;
386:                        }
387:                    }
388:                }
389:                return info;
390:            }
391:
392:            // ========== component info fields ==========
393:            protected String globalName = null;
394:            protected String rootLocation = null;
395:            protected String componentName = null;
396:            protected boolean enabled = true;
397:
398:            protected Map resourceLoaderInfos = FastMap.newInstance();
399:            protected List classpathInfos = FastList.newInstance();
400:            protected List entityResourceInfos = FastList.newInstance();
401:            protected List serviceResourceInfos = FastList.newInstance();
402:            protected List testSuiteInfos = FastList.newInstance();
403:            protected List keystoreInfos = FastList.newInstance();
404:            protected List webappInfos = FastList.newInstance();
405:
406:            protected ComponentConfig() {
407:            }
408:
409:            protected ComponentConfig(String globalName, String rootLocation)
410:                    throws ComponentException {
411:                this .globalName = globalName;
412:                if (!rootLocation.endsWith("/")) {
413:                    rootLocation = rootLocation + "/";
414:                }
415:                this .rootLocation = rootLocation.replace('\\', '/');
416:
417:                File rootLocationDir = new File(rootLocation);
418:                if (rootLocationDir == null) {
419:                    throw new ComponentException(
420:                            "The given component root location is does not exist: "
421:                                    + rootLocation);
422:                }
423:                if (!rootLocationDir.isDirectory()) {
424:                    throw new ComponentException(
425:                            "The given component root location is not a directory: "
426:                                    + rootLocation);
427:                }
428:
429:                String xmlFilename = rootLocation + "/"
430:                        + OFBIZ_COMPONENT_XML_FILENAME;
431:                URL xmlUrl = UtilURL.fromFilename(xmlFilename);
432:                if (xmlUrl == null) {
433:                    throw new ComponentException(
434:                            "Could not find the "
435:                                    + OFBIZ_COMPONENT_XML_FILENAME
436:                                    + " configuration file in the component root location: "
437:                                    + rootLocation);
438:                }
439:
440:                Document ofbizComponentDocument = null;
441:                try {
442:                    ofbizComponentDocument = UtilXml.readXmlDocument(xmlUrl,
443:                            true);
444:                } catch (SAXException e) {
445:                    throw new ComponentException(
446:                            "Error reading the component config file: "
447:                                    + xmlUrl, e);
448:                } catch (ParserConfigurationException e) {
449:                    throw new ComponentException(
450:                            "Error reading the component config file: "
451:                                    + xmlUrl, e);
452:                } catch (IOException e) {
453:                    throw new ComponentException(
454:                            "Error reading the component config file: "
455:                                    + xmlUrl, e);
456:                }
457:
458:                Element ofbizComponentElement = ofbizComponentDocument
459:                        .getDocumentElement();
460:                this .componentName = ofbizComponentElement.getAttribute("name");
461:                this .enabled = "true".equalsIgnoreCase(ofbizComponentElement
462:                        .getAttribute("enabled"));
463:                if (UtilValidate.isEmpty(this .globalName)) {
464:                    this .globalName = this .componentName;
465:                }
466:                Iterator elementIter = null;
467:
468:                // resource-loader - resourceLoaderInfos
469:                elementIter = UtilXml.childElementList(ofbizComponentElement,
470:                        "resource-loader").iterator();
471:                while (elementIter.hasNext()) {
472:                    Element curElement = (Element) elementIter.next();
473:                    ResourceLoaderInfo resourceLoaderInfo = new ResourceLoaderInfo(
474:                            curElement);
475:                    this .resourceLoaderInfos.put(resourceLoaderInfo.name,
476:                            resourceLoaderInfo);
477:                }
478:
479:                // classpath - classpathInfos
480:                elementIter = UtilXml.childElementList(ofbizComponentElement,
481:                        "classpath").iterator();
482:                while (elementIter.hasNext()) {
483:                    Element curElement = (Element) elementIter.next();
484:                    ClasspathInfo classpathInfo = new ClasspathInfo(this ,
485:                            curElement);
486:                    this .classpathInfos.add(classpathInfo);
487:                }
488:
489:                // entity-resource - entityResourceInfos
490:                elementIter = UtilXml.childElementList(ofbizComponentElement,
491:                        "entity-resource").iterator();
492:                while (elementIter.hasNext()) {
493:                    Element curElement = (Element) elementIter.next();
494:                    EntityResourceInfo entityResourceInfo = new EntityResourceInfo(
495:                            this , curElement);
496:                    this .entityResourceInfos.add(entityResourceInfo);
497:                }
498:
499:                // service-resource - serviceResourceInfos
500:                elementIter = UtilXml.childElementList(ofbizComponentElement,
501:                        "service-resource").iterator();
502:                while (elementIter.hasNext()) {
503:                    Element curElement = (Element) elementIter.next();
504:                    ServiceResourceInfo serviceResourceInfo = new ServiceResourceInfo(
505:                            this , curElement);
506:                    this .serviceResourceInfos.add(serviceResourceInfo);
507:                }
508:
509:                // test-suite - serviceResourceInfos
510:                elementIter = UtilXml.childElementList(ofbizComponentElement,
511:                        "test-suite").iterator();
512:                while (elementIter.hasNext()) {
513:                    Element curElement = (Element) elementIter.next();
514:                    TestSuiteInfo testSuiteInfo = new TestSuiteInfo(this ,
515:                            curElement);
516:                    this .testSuiteInfos.add(testSuiteInfo);
517:                }
518:
519:                // keystore - (cert/trust store infos)
520:                elementIter = UtilXml.childElementList(ofbizComponentElement,
521:                        "keystore").iterator();
522:                while (elementIter.hasNext()) {
523:                    Element curElement = (Element) elementIter.next();
524:                    KeystoreInfo keystoreInfo = new KeystoreInfo(this ,
525:                            curElement);
526:                    this .keystoreInfos.add(keystoreInfo);
527:                }
528:
529:                // webapp - webappInfos
530:                elementIter = UtilXml.childElementList(ofbizComponentElement,
531:                        "webapp").iterator();
532:                while (elementIter.hasNext()) {
533:                    Element curElement = (Element) elementIter.next();
534:                    WebappInfo webappInfo = new WebappInfo(this , curElement);
535:                    this .webappInfos.add(webappInfo);
536:                }
537:
538:                if (Debug.verboseOn())
539:                    Debug.logVerbose("Read component config : [" + rootLocation
540:                            + "]", module);
541:            }
542:
543:            public boolean isFileResource(ResourceInfo resourceInfo)
544:                    throws ComponentException {
545:                return isFileResourceLoader(resourceInfo.loader);
546:            }
547:
548:            public boolean isFileResourceLoader(String resourceLoaderName)
549:                    throws ComponentException {
550:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
551:                        .get(resourceLoaderName);
552:                if (resourceLoaderInfo == null) {
553:                    throw new ComponentException(
554:                            "Could not find resource-loader named: "
555:                                    + resourceLoaderName);
556:                }
557:                return "file".equals(resourceLoaderInfo.type)
558:                        || "component".equals(resourceLoaderInfo.type);
559:            }
560:
561:            public InputStream getStream(String resourceLoaderName,
562:                    String location) throws ComponentException {
563:                URL url = getURL(resourceLoaderName, location);
564:                try {
565:                    return url.openStream();
566:                } catch (java.io.IOException e) {
567:                    throw new ComponentException(
568:                            "Error opening resource at location ["
569:                                    + url.toExternalForm() + "]", e);
570:                }
571:            }
572:
573:            public URL getURL(String resourceLoaderName, String location)
574:                    throws ComponentException {
575:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
576:                        .get(resourceLoaderName);
577:                if (resourceLoaderInfo == null) {
578:                    throw new ComponentException(
579:                            "Could not find resource-loader named: "
580:                                    + resourceLoaderName);
581:                }
582:
583:                if ("component".equals(resourceLoaderInfo.type)
584:                        || "file".equals(resourceLoaderInfo.type)) {
585:                    String fullLocation = getFullLocation(resourceLoaderName,
586:                            location);
587:                    URL fileUrl = UtilURL.fromFilename(fullLocation);
588:                    if (fileUrl == null) {
589:                        throw new ComponentException(
590:                                "File Resource not found: " + fullLocation);
591:                    }
592:                    return fileUrl;
593:                } else if ("classpath".equals(resourceLoaderInfo.type)) {
594:                    String fullLocation = getFullLocation(resourceLoaderName,
595:                            location);
596:                    URL url = UtilURL.fromResource(fullLocation);
597:                    if (url == null) {
598:                        throw new ComponentException(
599:                                "Classpath Resource not found: " + fullLocation);
600:                    }
601:                    return url;
602:                } else if ("url".equals(resourceLoaderInfo.type)) {
603:                    String fullLocation = getFullLocation(resourceLoaderName,
604:                            location);
605:                    URL url = null;
606:                    try {
607:                        url = new URL(fullLocation);
608:                    } catch (java.net.MalformedURLException e) {
609:                        throw new ComponentException(
610:                                "Error with malformed URL while trying to load URL resource at location ["
611:                                        + fullLocation + "]", e);
612:                    }
613:                    if (url == null) {
614:                        throw new ComponentException("URL Resource not found: "
615:                                + fullLocation);
616:                    }
617:                    return url;
618:                } else {
619:                    throw new ComponentException(
620:                            "The resource-loader type is not recognized: "
621:                                    + resourceLoaderInfo.type);
622:                }
623:            }
624:
625:            public String getFullLocation(String resourceLoaderName,
626:                    String location) throws ComponentException {
627:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
628:                        .get(resourceLoaderName);
629:                if (resourceLoaderInfo == null) {
630:                    throw new ComponentException(
631:                            "Could not find resource-loader named: "
632:                                    + resourceLoaderName);
633:                }
634:
635:                StringBuffer buf = new StringBuffer();
636:
637:                // pre-pend component root location if this is a type component resource-loader
638:                if ("component".equals(resourceLoaderInfo.type)) {
639:                    buf.append(rootLocation);
640:                }
641:
642:                if (resourceLoaderInfo.prependEnv != null
643:                        && resourceLoaderInfo.prependEnv.length() > 0) {
644:                    String propValue = System
645:                            .getProperty(resourceLoaderInfo.prependEnv);
646:                    if (propValue == null) {
647:                        String errMsg = "The Java environment (-Dxxx=yyy) variable with name "
648:                                + resourceLoaderInfo.prependEnv
649:                                + " is not set, cannot load resource.";
650:                        Debug.logError(errMsg, module);
651:                        throw new IllegalArgumentException(errMsg);
652:                    }
653:                    buf.append(propValue);
654:                }
655:                if (resourceLoaderInfo.prefix != null
656:                        && resourceLoaderInfo.prefix.length() > 0) {
657:                    buf.append(resourceLoaderInfo.prefix);
658:                }
659:                buf.append(location);
660:                return buf.toString();
661:            }
662:
663:            public List getClasspathInfos() {
664:                return this .classpathInfos;
665:            }
666:
667:            public String getComponentName() {
668:                return this .componentName;
669:            }
670:
671:            public List getEntityResourceInfos() {
672:                return this .entityResourceInfos;
673:            }
674:
675:            public String getGlobalName() {
676:                return this .globalName;
677:            }
678:
679:            public Map getResourceLoaderInfos() {
680:                return this .resourceLoaderInfos;
681:            }
682:
683:            public String getRootLocation() {
684:                return this .rootLocation;
685:            }
686:
687:            public List getServiceResourceInfos() {
688:                return this .serviceResourceInfos;
689:            }
690:
691:            public List getTestSuiteInfos() {
692:                return this .testSuiteInfos;
693:            }
694:
695:            public List getKeystoreInfos() {
696:                return this .keystoreInfos;
697:            }
698:
699:            public List getWebappInfos() {
700:                return this .webappInfos;
701:            }
702:
703:            public boolean enabled() {
704:                return this .enabled;
705:            }
706:
707:            public static class ResourceLoaderInfo {
708:                public String name;
709:                public String type;
710:                public String prependEnv;
711:                public String prefix;
712:
713:                public ResourceLoaderInfo(Element element) {
714:                    this .name = element.getAttribute("name");
715:                    this .type = element.getAttribute("type");
716:                    this .prependEnv = element.getAttribute("prepend-env");
717:                    this .prefix = element.getAttribute("prefix");
718:                }
719:            }
720:
721:            public static class ResourceInfo {
722:                public ComponentConfig componentConfig;
723:                public String loader;
724:                public String location;
725:
726:                public ResourceInfo(ComponentConfig componentConfig,
727:                        Element element) {
728:                    this .componentConfig = componentConfig;
729:                    this .loader = element.getAttribute("loader");
730:                    this .location = element.getAttribute("location");
731:                }
732:
733:                public ComponentResourceHandler createResourceHandler() {
734:                    return new ComponentResourceHandler(componentConfig
735:                            .getGlobalName(), loader, location);
736:                }
737:            }
738:
739:            public static class ClasspathInfo {
740:                public ComponentConfig componentConfig;
741:                public String type;
742:                public String location;
743:
744:                public ClasspathInfo(ComponentConfig componentConfig,
745:                        Element element) {
746:                    this .componentConfig = componentConfig;
747:                    this .type = element.getAttribute("type");
748:                    this .location = element.getAttribute("location");
749:                }
750:            }
751:
752:            public static class EntityResourceInfo extends ResourceInfo {
753:                public String type;
754:                public String readerName;
755:
756:                public EntityResourceInfo(ComponentConfig componentConfig,
757:                        Element element) {
758:                    super (componentConfig, element);
759:                    this .type = element.getAttribute("type");
760:                    this .readerName = element.getAttribute("reader-name");
761:                }
762:            }
763:
764:            public static class ServiceResourceInfo extends ResourceInfo {
765:                public String type;
766:
767:                public ServiceResourceInfo(ComponentConfig componentConfig,
768:                        Element element) {
769:                    super (componentConfig, element);
770:                    this .type = element.getAttribute("type");
771:                }
772:            }
773:
774:            public static class TestSuiteInfo extends ResourceInfo {
775:                public TestSuiteInfo(ComponentConfig componentConfig,
776:                        Element element) {
777:                    super (componentConfig, element);
778:                }
779:            }
780:
781:            public static class KeystoreInfo extends ResourceInfo {
782:                public String name;
783:                public String type;
784:                public String password;
785:                public boolean isCertStore;
786:                public boolean isTrustStore;
787:
788:                public KeystoreInfo(ComponentConfig componentConfig,
789:                        Element element) {
790:                    super (componentConfig, element);
791:                    this .name = element.getAttribute("name");
792:                    this .type = element.getAttribute("type");
793:                    this .password = element.getAttribute("password");
794:                    this .isCertStore = "true".equalsIgnoreCase(element
795:                            .getAttribute("is-certstore"));
796:                    this .isTrustStore = "true".equalsIgnoreCase(element
797:                            .getAttribute("is-truststore"));
798:                }
799:
800:                public KeyStore getKeyStore() {
801:                    ComponentResourceHandler rh = this .createResourceHandler();
802:                    if (rh != null) {
803:                        try {
804:                            return KeyStoreUtil.getStore(rh.getURL(), this 
805:                                    .getPassword(), this .getType());
806:                        } catch (Exception e) {
807:                            Debug.logWarning(e, module);
808:                        }
809:                    }
810:                    return null;
811:                }
812:
813:                public String getName() {
814:                    return name;
815:                }
816:
817:                public String getType() {
818:                    return type;
819:                }
820:
821:                public String getPassword() {
822:                    return password;
823:                }
824:
825:                public boolean isCertStore() {
826:                    return isCertStore;
827:                }
828:
829:                public boolean isTrustStore() {
830:                    return isTrustStore;
831:                }
832:            }
833:
834:            public static class WebappInfo {
835:                public ComponentConfig componentConfig;
836:                public List virtualHosts;
837:                public Map initParameters;
838:                public String name;
839:                public String title;
840:                public String server;
841:                public String mountPoint;
842:                public String location;
843:                public String[] basePermission;
844:                public boolean appBarDisplay;
845:
846:                public WebappInfo(ComponentConfig componentConfig,
847:                        Element element) {
848:                    this .virtualHosts = FastList.newInstance();
849:                    this .initParameters = FastMap.newInstance();
850:                    this .componentConfig = componentConfig;
851:                    this .name = element.getAttribute("name");
852:                    this .title = element.getAttribute("title");
853:                    this .server = element.getAttribute("server");
854:                    this .mountPoint = element.getAttribute("mount-point");
855:                    this .location = element.getAttribute("location");
856:                    this .appBarDisplay = !"false".equals(element
857:                            .getAttribute("app-bar-display"));
858:                    String basePermStr = element
859:                            .getAttribute("base-permission");
860:                    if (UtilValidate.isNotEmpty(basePermStr)) {
861:                        this .basePermission = basePermStr.split(",");
862:                    } else {
863:                        // default base permission is NONE
864:                        this .basePermission = new String[] { "NONE" };
865:                    }
866:
867:                    // trim the permussions (remove spaces)
868:                    for (int i = 0; i < this .basePermission.length; i++) {
869:                        this .basePermission[i] = this .basePermission[i].trim();
870:                        if (this .basePermission[i].indexOf('_') != -1) {
871:                            this .basePermission[i] = this .basePermission[i]
872:                                    .substring(0, this .basePermission[i]
873:                                            .indexOf('_'));
874:                        }
875:                    }
876:
877:                    // default title is name w/ upper-cased first letter
878:                    if (UtilValidate.isEmpty(this .title)) {
879:                        this .title = Character.toUpperCase(name.charAt(0))
880:                                + name.substring(1).toLowerCase();
881:                    }
882:
883:                    // default mount point is name if none specified
884:                    if (UtilValidate.isEmpty(this .mountPoint)) {
885:                        this .mountPoint = this .name;
886:                    }
887:
888:                    // check the mount point and make sure it is properly formatted
889:                    if (!"/".equals(this .mountPoint)) {
890:                        if (!this .mountPoint.startsWith("/")) {
891:                            this .mountPoint = "/" + this .mountPoint;
892:                        }
893:                        if (!this .mountPoint.endsWith("/*")) {
894:                            if (!this .mountPoint.endsWith("/")) {
895:                                this .mountPoint = this .mountPoint + "/";
896:                            }
897:                            this .mountPoint = this .mountPoint + "*";
898:                        }
899:                    }
900:
901:                    // load the virtual hosts
902:                    List virtHostList = UtilXml.childElementList(element,
903:                            "virtual-host");
904:                    if (virtHostList != null && virtHostList.size() > 0) {
905:                        Iterator elementIter = virtHostList.iterator();
906:                        while (elementIter.hasNext()) {
907:                            Element e = (Element) elementIter.next();
908:                            virtualHosts.add(e.getAttribute("host-name"));
909:                        }
910:                    }
911:
912:                    // load the init parameters
913:                    List initParamList = UtilXml.childElementList(element,
914:                            "init-param");
915:                    if (initParamList != null && initParamList.size() > 0) {
916:                        Iterator elementIter = initParamList.iterator();
917:                        while (elementIter.hasNext()) {
918:                            Element e = (Element) elementIter.next();
919:                            this .initParameters.put(e.getAttribute("name"), e
920:                                    .getAttribute("value"));
921:                        }
922:                    }
923:                }
924:
925:                public String getContextRoot() {
926:                    if (mountPoint.endsWith("/*")) {
927:                        return mountPoint.substring(0, mountPoint.length() - 2);
928:                    }
929:                    return mountPoint;
930:                }
931:
932:                public String[] getBasePermission() {
933:                    return this .basePermission;
934:                }
935:
936:                public String getName() {
937:                    return name;
938:                }
939:
940:                public String getLocation() {
941:                    return componentConfig.getRootLocation() + location;
942:                }
943:
944:                public String getTitle() {
945:                    return title;
946:                }
947:
948:                public List getVirtualHosts() {
949:                    return virtualHosts;
950:                }
951:
952:                public Map getInitParameters() {
953:                    return initParameters;
954:                }
955:            }
956:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.