Source Code Cross Referenced for AutoDiscoverCarambaConfigFactory.java in  » Web-Framework » Caramba » org » caramba » config » 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 » Web Framework » Caramba » org.caramba.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.caramba.config;
002:
003:        import org.apache.commons.lang.StringUtils;
004:        import org.apache.commons.logging.Log;
005:        import org.apache.commons.logging.LogFactory;
006:        import org.caramba.CarambaException;
007:        import org.caramba.DestroyMode;
008:        import org.caramba.components.Container;
009:        import org.caramba.components.Page;
010:        import org.caramba.components.Panel;
011:
012:        import javax.servlet.ServletConfig;
013:        import javax.servlet.ServletException;
014:        import java.lang.reflect.Modifier;
015:        import java.net.MalformedURLException;
016:        import java.net.URL;
017:        import java.util.Iterator;
018:        import java.util.Set;
019:
020:        /**
021:         * @author Pieter Degraeuwe
022:         *         Date: Aug 28, 2006
023:         *         Time: 8:26:19 AM
024:         */
025:        public class AutoDiscoverCarambaConfigFactory extends
026:                DefaultCarambaConfigFactory {
027:            private static final transient Log log = LogFactory
028:                    .getLog(AutoDiscoverCarambaConfigFactory.class);
029:
030:            private static final String INIT_PARAM_CHECK_LIBRARIES = "checkLibaries";
031:
032:            public CarambaConfig createCarambaConfig(
033:                    ServletConfig pServletConfig) throws ServletException {
034:                CarambaConfig config;
035:                try {
036:                    config = super .createCarambaConfig(pServletConfig);
037:                } catch (ServletException e) {
038:                    //ignore error. It's due the fact that no caramba-config.xml was found.
039:                    config = new CarambaConfig();
040:                }
041:                config
042:                        .addPlugIn(new EnableImplicitComponentRegistrationPlugIn());
043:                String checkLibsParam = pServletConfig
044:                        .getInitParameter(INIT_PARAM_CHECK_LIBRARIES);
045:                boolean checkLibs = false;
046:                if (StringUtils.isNotEmpty(checkLibsParam)) {
047:                    try {
048:                        checkLibs = new Boolean(checkLibsParam);
049:                    } catch (Exception e) {
050:                        throw new ServletException(
051:                                INIT_PARAM_CHECK_LIBRARIES
052:                                        + " init param contains invalid value. Must be 'true' or 'false' (default: false) ");
053:                    }
054:                }
055:
056:                AutoDiscoverCarambaConfigUtil<Page> pageClassDiscoverer = new AutoDiscoverCarambaConfigUtil<Page>();
057:                pageClassDiscoverer.loadImplementationsFromServletContext(
058:                        Page.class, pServletConfig.getServletContext(),
059:                        checkLibs);
060:                discoverPageClasses(pServletConfig, config, pageClassDiscoverer
061:                        .getClasses());
062:
063:                AutoDiscoverCarambaConfigUtil<Panel> panelClassDiscoverer = new AutoDiscoverCarambaConfigUtil<Panel>();
064:                panelClassDiscoverer.loadImplementationsFromServletContext(
065:                        Panel.class, pServletConfig.getServletContext(),
066:                        checkLibs);
067:                discoverPanelClasses(pServletConfig, config,
068:                        panelClassDiscoverer.getClasses());
069:                return config;
070:            }
071:
072:            private void discoverPageClasses(ServletConfig pServletConfig,
073:                    CarambaConfig pConfig, Set<Class<? extends Page>> pClasses) {
074:                for (Iterator<Class<? extends Page>> iterator = pClasses
075:                        .iterator(); iterator.hasNext();) {
076:                    Class<? extends Page> aClass = iterator.next();
077:                    if (Modifier.isAbstract(aClass.getModifiers()))
078:                        continue;
079:                    org.caramba.annotations.PageConfig annotation = (org.caramba.annotations.PageConfig) aClass
080:                            .getAnnotation(org.caramba.annotations.PageConfig.class);
081:                    PageConfig pageConfig;
082:                    if (annotation != null) {
083:                        pageConfig = constructPageConfig(pConfig, annotation
084:                                .name(), annotation.resource(), aClass
085:                                .getName());
086:                        if (StringUtils.isNotEmpty(annotation.destroyMode())) {
087:                            DestroyMode dm = DestroyMode.getByName(annotation
088:                                    .destroyMode());
089:                            if (dm == null)
090:                                throw new CarambaException(
091:                                        "Unsupported DestroyMode on page  "
092:                                                + pageConfig.getName() + " : "
093:                                                + annotation.destroyMode());
094:                            pageConfig.setDestroyMode(dm);
095:                        }
096:                    } else {
097:                        pageConfig = constructPageConfig(pConfig, null, null,
098:                                aClass.getName());
099:                    }
100:
101:                    //only autodiscover pages which are not configured manually
102:                    PageConfig existingPageConfig = pConfig
103:                            .getPageConfig(pageConfig.getName());
104:                    if (existingPageConfig == null) {
105:                        URL resource = null;
106:                        try {
107:                            resource = pServletConfig.getServletContext()
108:                                    .getResource(pageConfig.getResource());
109:                        } catch (MalformedURLException e) {
110:                            throw new CarambaException(
111:                                    "Marformed resource for page "
112:                                            + pageConfig.getName());
113:                        }
114:                        if (resource != null) {
115:                            pConfig.addPageConfig(pageConfig);
116:                        } else {
117:                            log
118:                                    .warn("PageConfig skipped since resource was not found: "
119:                                            + pageConfig.getName());
120:                        }
121:                    } else {
122:                        log
123:                                .warn("AutoDiscovered PageConfig skipped since it was already defined in the caramba-config.xml: "
124:                                        + pageConfig.getName());
125:                    }
126:                }
127:            }
128:
129:            private void discoverPanelClasses(ServletConfig pServletConfig,
130:                    CarambaConfig pConfig, Set<Class<? extends Panel>> pClasses) {
131:                for (Iterator<Class<? extends Panel>> iterator = pClasses
132:                        .iterator(); iterator.hasNext();) {
133:                    Class<? extends Container> aClass = iterator.next();
134:                    if (Modifier.isAbstract(aClass.getModifiers()))
135:                        continue;
136:                    org.caramba.annotations.PanelConfig annotation = (org.caramba.annotations.PanelConfig) aClass
137:                            .getAnnotation(org.caramba.annotations.PanelConfig.class);
138:                    PanelConfig panelConfig;
139:                    if (annotation != null) {
140:                        panelConfig = constructPanelConfig(pConfig, annotation
141:                                .name(), annotation.resource(), aClass
142:                                .getName());
143:                    } else {
144:                        panelConfig = constructPanelConfig(pConfig, null, null,
145:                                aClass.getName());
146:                    }
147:
148:                    //only autodiscover panels which are not configured manually
149:                    PanelConfig existingPanelConfig = pConfig
150:                            .getPanelConfig(panelConfig.getName());
151:                    if (existingPanelConfig == null) {
152:                        URL resource = null;
153:                        try {
154:                            resource = pServletConfig.getServletContext()
155:                                    .getResource(panelConfig.getResource());
156:                        } catch (MalformedURLException e) {
157:                            throw new CarambaException(
158:                                    "Marformed resource for panel "
159:                                            + panelConfig.getName());
160:                        }
161:                        if (resource != null) {
162:                            pConfig.addPanelConfig(panelConfig);
163:                        } else {
164:                            log
165:                                    .warn("PanelConfig skipped since resource was not found: "
166:                                            + panelConfig.getName());
167:                        }
168:                    } else {
169:                        log
170:                                .warn("AutoDiscovered PanelConfig skipped since it was already defined in the caramba-config.xml: "
171:                                        + panelConfig.getName());
172:                    }
173:
174:                }
175:
176:            }
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.