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


001:        /*
002:         * $Id: ComponentConfig.java,v 1.17 2003/12/07 18:50:34 ajzeneski Exp $
003:         *
004:         * Copyright (c) 2003 The Open For Business Project - www.ofbiz.org
005:         *
006:         * Permission is hereby granted, free of charge, to any person obtaining a
007:         * copy of this software and associated documentation files (the "Software"),
008:         * to deal in the Software without restriction, including without limitation
009:         * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010:         * and/or sell copies of the Software, and to permit persons to whom the
011:         * Software is furnished to do so, subject to the following conditions:
012:         *
013:         * The above copyright notice and this permission notice shall be included
014:         * in all copies or substantial portions of the Software.
015:         *
016:         * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017:         * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018:         * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019:         * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020:         * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021:         * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022:         * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023:         *
024:         */
025:        package org.ofbiz.base.component;
026:
027:        import java.io.File;
028:        import java.io.IOException;
029:        import java.io.InputStream;
030:        import java.net.URL;
031:        import java.util.Collection;
032:        import java.util.HashMap;
033:        import java.util.Iterator;
034:        import java.util.LinkedList;
035:        import java.util.List;
036:        import java.util.Map;
037:        import java.util.TreeMap;
038:
039:        import javax.xml.parsers.ParserConfigurationException;
040:
041:        import org.ofbiz.base.util.Debug;
042:        import org.ofbiz.base.util.OrderedMap;
043:        import org.ofbiz.base.util.UtilURL;
044:        import org.ofbiz.base.util.UtilValidate;
045:        import org.ofbiz.base.util.UtilXml;
046:        import org.w3c.dom.Document;
047:        import org.w3c.dom.Element;
048:        import org.xml.sax.SAXException;
049:
050:        /**
051:         * ComponentConfig - Component configuration class for ofbiz-container.xml
052:         *
053:         * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
054:         * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a>
055:         * @version    $Revision: 1.17 $
056:         * @since      3.0
057:         */
058:        public class ComponentConfig {
059:
060:            public static final String module = ComponentConfig.class.getName();
061:            public static final String OFBIZ_COMPONENT_XML_FILENAME = "ofbiz-component.xml";
062:
063:            // this is not a UtilCache because reloading may cause problems
064:            protected static Map componentConfigs = new OrderedMap();
065:            protected static Map serverWebApps = new HashMap();
066:
067:            public static ComponentConfig getComponentConfig(String globalName)
068:                    throws ComponentException {
069:                // TODO: we need to look up the rootLocation from the container config, or this will blow up
070:                return getComponentConfig(globalName, null);
071:            }
072:
073:            public static ComponentConfig getComponentConfig(String globalName,
074:                    String rootLocation) throws ComponentException {
075:                ComponentConfig componentConfig = null;
076:                if (UtilValidate.isNotEmpty(globalName)) {
077:                    componentConfig = (ComponentConfig) componentConfigs
078:                            .get(globalName);
079:                }
080:                if (componentConfig == null) {
081:                    if (rootLocation != null) {
082:                        synchronized (ComponentConfig.class) {
083:                            if (UtilValidate.isNotEmpty(globalName)) {
084:                                componentConfig = (ComponentConfig) componentConfigs
085:                                        .get(globalName);
086:                            }
087:                            if (componentConfig == null) {
088:                                componentConfig = new ComponentConfig(
089:                                        globalName, rootLocation);
090:                                if (componentConfigs
091:                                        .containsKey(componentConfig
092:                                                .getGlobalName())) {
093:                                    Debug
094:                                            .logWarning(
095:                                                    "WARNING: Loading ofbiz-component using a global name that already exists, will over-write: "
096:                                                            + componentConfig
097:                                                                    .getGlobalName(),
098:                                                    module);
099:                                }
100:                                componentConfigs.put(componentConfig
101:                                        .getGlobalName(), componentConfig);
102:                            }
103:                        }
104:                    } else {
105:                        throw new ComponentException(
106:                                "No component found named : " + globalName);
107:                    }
108:                }
109:                return componentConfig;
110:            }
111:
112:            public static Collection getAllComponents() {
113:                Collection values = componentConfigs.values();
114:                if (values != null) {
115:                    return values;
116:                } else {
117:                    Debug
118:                            .logWarning(
119:                                    "No components were found, something is probably missing or incorrect in the component-load setup.",
120:                                    module);
121:                    return new LinkedList();
122:                }
123:            }
124:
125:            public static List getAllClasspathInfos() {
126:                List classpaths = new LinkedList();
127:                Iterator i = getAllComponents().iterator();
128:                while (i.hasNext()) {
129:                    ComponentConfig cc = (ComponentConfig) i.next();
130:                    classpaths.addAll(cc.getClasspathInfos());
131:                }
132:                return classpaths;
133:            }
134:
135:            public static List getAllEntityResourceInfos(String type) {
136:                List entityInfos = new LinkedList();
137:                Iterator i = getAllComponents().iterator();
138:                while (i.hasNext()) {
139:                    ComponentConfig cc = (ComponentConfig) i.next();
140:                    List ccEntityInfoList = cc.getEntityResourceInfos();
141:                    if (UtilValidate.isEmpty(type)) {
142:                        entityInfos.addAll(ccEntityInfoList);
143:                    } else {
144:                        Iterator ccEntityInfoIter = ccEntityInfoList.iterator();
145:                        while (ccEntityInfoIter.hasNext()) {
146:                            EntityResourceInfo entityResourceInfo = (EntityResourceInfo) ccEntityInfoIter
147:                                    .next();
148:                            if (type.equals(entityResourceInfo.type)) {
149:                                entityInfos.add(entityResourceInfo);
150:                            }
151:                        }
152:                    }
153:                }
154:                return entityInfos;
155:            }
156:
157:            public static List getAllServiceResourceInfos(String type) {
158:                List serviceInfos = new LinkedList();
159:                Iterator i = getAllComponents().iterator();
160:                while (i.hasNext()) {
161:                    ComponentConfig cc = (ComponentConfig) i.next();
162:                    List ccServiceInfoList = cc.getServiceResourceInfos();
163:                    if (UtilValidate.isEmpty(type)) {
164:                        serviceInfos.addAll(ccServiceInfoList);
165:                    } else {
166:                        Iterator ccServiceInfoIter = ccServiceInfoList
167:                                .iterator();
168:                        while (ccServiceInfoIter.hasNext()) {
169:                            ServiceResourceInfo serviceResourceInfo = (ServiceResourceInfo) ccServiceInfoIter
170:                                    .next();
171:                            if (type.equals(serviceResourceInfo.type)) {
172:                                serviceInfos.add(serviceResourceInfo);
173:                            }
174:                        }
175:                    }
176:                }
177:                return serviceInfos;
178:            }
179:
180:            public static List getAllWebappResourceInfos() {
181:                List webappInfos = new LinkedList();
182:                Iterator i = getAllComponents().iterator();
183:                while (i.hasNext()) {
184:                    ComponentConfig cc = (ComponentConfig) i.next();
185:                    webappInfos.addAll(cc.getWebappInfos());
186:                }
187:                return webappInfos;
188:
189:            }
190:
191:            public static boolean isFileResourceLoader(String componentName,
192:                    String resourceLoaderName) throws ComponentException {
193:                ComponentConfig cc = ComponentConfig
194:                        .getComponentConfig(componentName);
195:                if (cc == null) {
196:                    throw new ComponentException(
197:                            "Could not find component with name: "
198:                                    + componentName);
199:                }
200:                return cc.isFileResourceLoader(resourceLoaderName);
201:            }
202:
203:            public static InputStream getStream(String componentName,
204:                    String resourceLoaderName, String location)
205:                    throws ComponentException {
206:                ComponentConfig cc = ComponentConfig
207:                        .getComponentConfig(componentName);
208:                if (cc == null) {
209:                    throw new ComponentException(
210:                            "Could not find component with name: "
211:                                    + componentName);
212:                }
213:                return cc.getStream(resourceLoaderName, location);
214:            }
215:
216:            public static URL getURL(String componentName,
217:                    String resourceLoaderName, String location)
218:                    throws ComponentException {
219:                ComponentConfig cc = ComponentConfig
220:                        .getComponentConfig(componentName);
221:                if (cc == null) {
222:                    throw new ComponentException(
223:                            "Could not find component with name: "
224:                                    + componentName);
225:                }
226:                return cc.getURL(resourceLoaderName, location);
227:            }
228:
229:            public static String getFullLocation(String componentName,
230:                    String resourceLoaderName, String location)
231:                    throws ComponentException {
232:                ComponentConfig cc = ComponentConfig
233:                        .getComponentConfig(componentName);
234:                if (cc == null) {
235:                    throw new ComponentException(
236:                            "Could not find component with name: "
237:                                    + componentName);
238:                }
239:                return cc.getFullLocation(resourceLoaderName, location);
240:            }
241:
242:            public static List getAppBarWebInfos(String serverName) {
243:                List webInfos = (List) serverWebApps.get(serverName);
244:                if (webInfos == null) {
245:                    synchronized (ComponentConfig.class) {
246:                        if (webInfos == null) {
247:                            Iterator i = getAllComponents().iterator();
248:                            TreeMap tm = new TreeMap();
249:                            while (i.hasNext()) {
250:                                ComponentConfig cc = (ComponentConfig) i.next();
251:                                Iterator wi = cc.getWebappInfos().iterator();
252:                                while (wi.hasNext()) {
253:                                    ComponentConfig.WebappInfo wInfo = (ComponentConfig.WebappInfo) wi
254:                                            .next();
255:                                    if (serverName.equals(wInfo.server)
256:                                            && wInfo.appBarDisplay) {
257:                                        tm.put(wInfo.title, wInfo);
258:                                    }
259:                                }
260:                            }
261:                            List webInfoList = new LinkedList(tm.values());
262:                            serverWebApps.put(serverName, webInfoList);
263:                            return webInfoList;
264:                        }
265:                    }
266:                }
267:                return webInfos;
268:            }
269:
270:            public static WebappInfo getWebAppInfo(String serverName,
271:                    String contextRoot) {
272:                ComponentConfig.WebappInfo info = null;
273:                if (serverName == null || contextRoot == null) {
274:                    return info;
275:                }
276:
277:                Iterator i = getAllComponents().iterator();
278:                while (i.hasNext() && info == null) {
279:                    ComponentConfig cc = (ComponentConfig) i.next();
280:                    Iterator wi = cc.getWebappInfos().iterator();
281:                    while (wi.hasNext()) {
282:                        ComponentConfig.WebappInfo wInfo = (ComponentConfig.WebappInfo) wi
283:                                .next();
284:                        if (serverName.equals(wInfo.server)
285:                                && contextRoot.equals(wInfo.getContextRoot())) {
286:                            info = wInfo;
287:                        }
288:                    }
289:                }
290:                return info;
291:            }
292:
293:            // ========== component info fields ==========
294:            protected String globalName = null;
295:            protected String rootLocation = null;
296:            protected String componentName = null;
297:
298:            protected Map resourceLoaderInfos = new HashMap();
299:            protected List classpathInfos = new LinkedList();
300:            protected List entityResourceInfos = new LinkedList();
301:            protected List serviceResourceInfos = new LinkedList();
302:            protected List webappInfos = new LinkedList();
303:
304:            protected ComponentConfig() {
305:            }
306:
307:            protected ComponentConfig(String globalName, String rootLocation)
308:                    throws ComponentException {
309:                this .globalName = globalName;
310:                if (!rootLocation.endsWith("/")) {
311:                    rootLocation = rootLocation + "/";
312:                }
313:                this .rootLocation = rootLocation.replace('\\', '/');
314:
315:                File rootLocationDir = new File(rootLocation);
316:                if (rootLocationDir == null) {
317:                    throw new ComponentException(
318:                            "The given component root location is does not exist: "
319:                                    + rootLocation);
320:                }
321:                if (!rootLocationDir.isDirectory()) {
322:                    throw new ComponentException(
323:                            "The given component root location is not a directory: "
324:                                    + rootLocation);
325:                }
326:
327:                String xmlFilename = rootLocation + "/"
328:                        + OFBIZ_COMPONENT_XML_FILENAME;
329:                URL xmlUrl = UtilURL.fromFilename(xmlFilename);
330:                if (xmlUrl == null) {
331:                    throw new ComponentException(
332:                            "Could not find the "
333:                                    + OFBIZ_COMPONENT_XML_FILENAME
334:                                    + " configuration file in the component root location: "
335:                                    + rootLocation);
336:                }
337:
338:                Document ofbizComponentDocument = null;
339:                try {
340:                    ofbizComponentDocument = UtilXml.readXmlDocument(xmlUrl,
341:                            true);
342:                } catch (SAXException e) {
343:                    throw new ComponentException(
344:                            "Error reading the component config file: "
345:                                    + xmlUrl, e);
346:                } catch (ParserConfigurationException e) {
347:                    throw new ComponentException(
348:                            "Error reading the component config file: "
349:                                    + xmlUrl, e);
350:                } catch (IOException e) {
351:                    throw new ComponentException(
352:                            "Error reading the component config file: "
353:                                    + xmlUrl, e);
354:                }
355:
356:                Element ofbizComponentElement = ofbizComponentDocument
357:                        .getDocumentElement();
358:                this .componentName = ofbizComponentElement.getAttribute("name");
359:                if (UtilValidate.isEmpty(this .globalName)) {
360:                    this .globalName = this .componentName;
361:                }
362:                Iterator elementIter = null;
363:
364:                // resource-loader - resourceLoaderInfos
365:                elementIter = UtilXml.childElementList(ofbizComponentElement,
366:                        "resource-loader").iterator();
367:                while (elementIter.hasNext()) {
368:                    Element curElement = (Element) elementIter.next();
369:                    ResourceLoaderInfo resourceLoaderInfo = new ResourceLoaderInfo(
370:                            curElement);
371:                    this .resourceLoaderInfos.put(resourceLoaderInfo.name,
372:                            resourceLoaderInfo);
373:                }
374:
375:                // classpath - classpathInfos
376:                elementIter = UtilXml.childElementList(ofbizComponentElement,
377:                        "classpath").iterator();
378:                while (elementIter.hasNext()) {
379:                    Element curElement = (Element) elementIter.next();
380:                    ClasspathInfo classpathInfo = new ClasspathInfo(this ,
381:                            curElement);
382:                    this .classpathInfos.add(classpathInfo);
383:                }
384:
385:                // entity-resource - entityResourceInfos
386:                elementIter = UtilXml.childElementList(ofbizComponentElement,
387:                        "entity-resource").iterator();
388:                while (elementIter.hasNext()) {
389:                    Element curElement = (Element) elementIter.next();
390:                    EntityResourceInfo entityResourceInfo = new EntityResourceInfo(
391:                            this , curElement);
392:                    this .entityResourceInfos.add(entityResourceInfo);
393:                }
394:
395:                // service-resource - serviceResourceInfos
396:                elementIter = UtilXml.childElementList(ofbizComponentElement,
397:                        "service-resource").iterator();
398:                while (elementIter.hasNext()) {
399:                    Element curElement = (Element) elementIter.next();
400:                    ServiceResourceInfo serviceResourceInfo = new ServiceResourceInfo(
401:                            this , curElement);
402:                    this .serviceResourceInfos.add(serviceResourceInfo);
403:                }
404:
405:                // webapp - webappInfos
406:                elementIter = UtilXml.childElementList(ofbizComponentElement,
407:                        "webapp").iterator();
408:                while (elementIter.hasNext()) {
409:                    Element curElement = (Element) elementIter.next();
410:                    WebappInfo webappInfo = new WebappInfo(this , curElement);
411:                    this .webappInfos.add(webappInfo);
412:                }
413:
414:                if (Debug.verboseOn())
415:                    Debug.logVerbose("Read component config : [" + rootLocation
416:                            + "]", module);
417:            }
418:
419:            public boolean isFileResource(ResourceInfo resourceInfo)
420:                    throws ComponentException {
421:                return isFileResourceLoader(resourceInfo.loader);
422:            }
423:
424:            public boolean isFileResourceLoader(String resourceLoaderName)
425:                    throws ComponentException {
426:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
427:                        .get(resourceLoaderName);
428:                if (resourceLoaderInfo == null) {
429:                    throw new ComponentException(
430:                            "Could not find resource-loader named: "
431:                                    + resourceLoaderName);
432:                }
433:                return "file".equals(resourceLoaderInfo.type)
434:                        || "component".equals(resourceLoaderInfo.type);
435:            }
436:
437:            public InputStream getStream(String resourceLoaderName,
438:                    String location) throws ComponentException {
439:                URL url = getURL(resourceLoaderName, location);
440:                try {
441:                    return url.openStream();
442:                } catch (java.io.IOException e) {
443:                    throw new ComponentException(
444:                            "Error opening resource at location ["
445:                                    + url.toExternalForm() + "]", e);
446:                }
447:            }
448:
449:            public URL getURL(String resourceLoaderName, String location)
450:                    throws ComponentException {
451:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
452:                        .get(resourceLoaderName);
453:                if (resourceLoaderInfo == null) {
454:                    throw new ComponentException(
455:                            "Could not find resource-loader named: "
456:                                    + resourceLoaderName);
457:                }
458:
459:                if ("component".equals(resourceLoaderInfo.type)
460:                        || "file".equals(resourceLoaderInfo.type)) {
461:                    String fullLocation = getFullLocation(resourceLoaderName,
462:                            location);
463:                    URL fileUrl = UtilURL.fromFilename(fullLocation);
464:                    if (fileUrl == null) {
465:                        throw new ComponentException(
466:                                "File Resource not found: " + fullLocation);
467:                    }
468:                    return fileUrl;
469:                } else if ("classpath".equals(resourceLoaderInfo.type)) {
470:                    String fullLocation = getFullLocation(resourceLoaderName,
471:                            location);
472:                    URL url = UtilURL.fromResource(fullLocation);
473:                    if (url == null) {
474:                        throw new ComponentException(
475:                                "Classpath Resource not found: " + fullLocation);
476:                    }
477:                    return url;
478:                } else if ("url".equals(resourceLoaderInfo.type)) {
479:                    String fullLocation = getFullLocation(resourceLoaderName,
480:                            location);
481:                    URL url = null;
482:                    try {
483:                        url = new URL(fullLocation);
484:                    } catch (java.net.MalformedURLException e) {
485:                        throw new ComponentException(
486:                                "Error with malformed URL while trying to load URL resource at location ["
487:                                        + fullLocation + "]", e);
488:                    }
489:                    if (url == null) {
490:                        throw new ComponentException("URL Resource not found: "
491:                                + fullLocation);
492:                    }
493:                    return url;
494:                } else {
495:                    throw new ComponentException(
496:                            "The resource-loader type is not recognized: "
497:                                    + resourceLoaderInfo.type);
498:                }
499:            }
500:
501:            public String getFullLocation(String resourceLoaderName,
502:                    String location) throws ComponentException {
503:                ResourceLoaderInfo resourceLoaderInfo = (ResourceLoaderInfo) resourceLoaderInfos
504:                        .get(resourceLoaderName);
505:                if (resourceLoaderInfo == null) {
506:                    throw new ComponentException(
507:                            "Could not find resource-loader named: "
508:                                    + resourceLoaderName);
509:                }
510:
511:                StringBuffer buf = new StringBuffer();
512:
513:                // pre-pend component root location if this is a type component resource-loader
514:                if ("component".equals(resourceLoaderInfo.type)) {
515:                    buf.append(rootLocation);
516:                }
517:
518:                if (resourceLoaderInfo.prependEnv != null
519:                        && resourceLoaderInfo.prependEnv.length() > 0) {
520:                    String propValue = System
521:                            .getProperty(resourceLoaderInfo.prependEnv);
522:                    if (propValue == null) {
523:                        String errMsg = "The Java environment (-Dxxx=yyy) variable with name "
524:                                + resourceLoaderInfo.prependEnv
525:                                + " is not set, cannot load resource.";
526:                        Debug.logError(errMsg, module);
527:                        throw new IllegalArgumentException(errMsg);
528:                    }
529:                    buf.append(propValue);
530:                }
531:                if (resourceLoaderInfo.prefix != null
532:                        && resourceLoaderInfo.prefix.length() > 0) {
533:                    buf.append(resourceLoaderInfo.prefix);
534:                }
535:                buf.append(location);
536:                return buf.toString();
537:            }
538:
539:            public List getClasspathInfos() {
540:                return classpathInfos;
541:            }
542:
543:            public String getComponentName() {
544:                return componentName;
545:            }
546:
547:            public List getEntityResourceInfos() {
548:                return entityResourceInfos;
549:            }
550:
551:            public String getGlobalName() {
552:                return globalName;
553:            }
554:
555:            public Map getResourceLoaderInfos() {
556:                return resourceLoaderInfos;
557:            }
558:
559:            public String getRootLocation() {
560:                return rootLocation;
561:            }
562:
563:            public List getServiceResourceInfos() {
564:                return serviceResourceInfos;
565:            }
566:
567:            public List getWebappInfos() {
568:                return webappInfos;
569:            }
570:
571:            public static class ResourceLoaderInfo {
572:                public String name;
573:                public String type;
574:                public String prependEnv;
575:                public String prefix;
576:
577:                public ResourceLoaderInfo(Element element) {
578:                    this .name = element.getAttribute("name");
579:                    this .type = element.getAttribute("type");
580:                    this .prependEnv = element.getAttribute("prepend-env");
581:                    this .prefix = element.getAttribute("prefix");
582:                }
583:            }
584:
585:            public static class ResourceInfo {
586:                public ComponentConfig componentConfig;
587:                public String loader;
588:                public String location;
589:
590:                public ResourceInfo(ComponentConfig componentConfig,
591:                        Element element) {
592:                    this .componentConfig = componentConfig;
593:                    this .loader = element.getAttribute("loader");
594:                    this .location = element.getAttribute("location");
595:                }
596:
597:                public ComponentResourceHandler createResourceHandler() {
598:                    return new ComponentResourceHandler(componentConfig
599:                            .getGlobalName(), loader, location);
600:                }
601:            }
602:
603:            public static class ClasspathInfo {
604:                public ComponentConfig componentConfig;
605:                public String type;
606:                public String location;
607:
608:                public ClasspathInfo(ComponentConfig componentConfig,
609:                        Element element) {
610:                    this .componentConfig = componentConfig;
611:                    this .type = element.getAttribute("type");
612:                    this .location = element.getAttribute("location");
613:                }
614:            }
615:
616:            public static class EntityResourceInfo extends ResourceInfo {
617:                public String type;
618:                public String readerName;
619:
620:                public EntityResourceInfo(ComponentConfig componentConfig,
621:                        Element element) {
622:                    super (componentConfig, element);
623:                    this .type = element.getAttribute("type");
624:                    this .readerName = element.getAttribute("reader-name");
625:                }
626:            }
627:
628:            public static class ServiceResourceInfo extends ResourceInfo {
629:                public String type;
630:
631:                public ServiceResourceInfo(ComponentConfig componentConfig,
632:                        Element element) {
633:                    super (componentConfig, element);
634:                    this .type = element.getAttribute("type");
635:                }
636:            }
637:
638:            public static class WebappInfo {
639:                public ComponentConfig componentConfig;
640:                public List virtualHosts;
641:                public Map initParameters;
642:                public String name;
643:                public String title;
644:                public String server;
645:                public String mountPoint;
646:                public String location;
647:                public String basePermission;
648:                public boolean appBarDisplay;
649:
650:                public WebappInfo(ComponentConfig componentConfig,
651:                        Element element) {
652:                    this .virtualHosts = new LinkedList();
653:                    this .initParameters = new HashMap();
654:                    this .componentConfig = componentConfig;
655:                    this .name = element.getAttribute("name");
656:                    this .title = element.getAttribute("title");
657:                    this .server = element.getAttribute("server");
658:                    this .mountPoint = element.getAttribute("mount-point");
659:                    this .location = element.getAttribute("location");
660:                    this .basePermission = element
661:                            .getAttribute("base-permission");
662:                    this .appBarDisplay = !"false".equals(element
663:                            .getAttribute("app-bar-display"));
664:
665:                    // default title is name w/ upper-cased first letter
666:                    if (UtilValidate.isEmpty(this .title)) {
667:                        this .title = Character.toUpperCase(name.charAt(0))
668:                                + name.substring(1).toLowerCase();
669:                    }
670:
671:                    // default mount point is name if none specified
672:                    if (UtilValidate.isEmpty(this .mountPoint)) {
673:                        this .mountPoint = this .name;
674:                    }
675:
676:                    // default base permission 'NONE'
677:                    if (UtilValidate.isEmpty(this .basePermission)) {
678:                        this .basePermission = "NONE";
679:                    }
680:
681:                    // check the mount point and make sure it is properly formatted
682:                    if (!"/".equals(this .mountPoint)) {
683:                        if (!this .mountPoint.startsWith("/")) {
684:                            this .mountPoint = "/" + this .mountPoint;
685:                        }
686:                        if (!this .mountPoint.endsWith("/*")) {
687:                            if (!this .mountPoint.endsWith("/")) {
688:                                this .mountPoint = this .mountPoint + "/";
689:                            }
690:                            this .mountPoint = this .mountPoint + "*";
691:                        }
692:                    }
693:
694:                    // load the virtual hosts
695:                    List virtHostList = UtilXml.childElementList(element,
696:                            "virtual-host");
697:                    if (virtHostList != null && virtHostList.size() > 0) {
698:                        Iterator elementIter = virtHostList.iterator();
699:                        while (elementIter.hasNext()) {
700:                            Element e = (Element) elementIter.next();
701:                            virtualHosts.add(e.getAttribute("host-name"));
702:                        }
703:                    }
704:
705:                    // load the init parameters
706:                    List initParamList = UtilXml.childElementList(element,
707:                            "init-param");
708:                    if (initParamList != null && initParamList.size() > 0) {
709:                        Iterator elementIter = initParamList.iterator();
710:                        while (elementIter.hasNext()) {
711:                            Element e = (Element) elementIter.next();
712:                            this .initParameters.put(e.getAttribute("name"), e
713:                                    .getAttribute("value"));
714:                        }
715:                    }
716:                }
717:
718:                public String getContextRoot() {
719:                    if (mountPoint.endsWith("/*")) {
720:                        return mountPoint.substring(0, mountPoint.length() - 2);
721:                    }
722:                    return mountPoint;
723:                }
724:
725:                public String getBasePermission() {
726:                    if (this .basePermission.indexOf('_') != -1) {
727:                        return this .basePermission.substring(0,
728:                                this .basePermission.indexOf('_'));
729:                    }
730:                    return this .basePermission;
731:                }
732:
733:                public String getTitle() {
734:                    return title;
735:                }
736:
737:                public List getVirtualHosts() {
738:                    return virtualHosts;
739:                }
740:
741:                public Map getInitParameters() {
742:                    return initParameters;
743:                }
744:            }
745:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.