Source Code Cross Referenced for SpringComponentManager.java in  » Portal » jetspeed-2.1.3 » org » apache » jetspeed » components » 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 » Portal » jetspeed 2.1.3 » org.apache.jetspeed.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         * 
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         * 
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.jetspeed.components;
018:
019:        import java.io.File;
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.Map;
025:        import java.util.Properties;
026:
027:        import javax.servlet.ServletContext;
028:
029:        import org.apache.jetspeed.engine.JetspeedEngineConstants;
030:        import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
031:        import org.springframework.context.ApplicationContext;
032:        import org.springframework.context.ConfigurableApplicationContext;
033:        import org.springframework.context.support.FileSystemXmlApplicationContext;
034:        import org.springframework.context.support.GenericApplicationContext;
035:        import org.springframework.web.context.WebApplicationContext;
036:        import org.springframework.web.context.support.XmlWebApplicationContext;
037:
038:        /**
039:         * <p>
040:         * SpringComponentManager
041:         * </p>
042:         * <p>
043:         * 
044:         * </p>
045:         * 
046:         * @author <a href="mailto:weaver@apache.org">Scott T. Weaver</a>
047:         * @version $Id: SpringComponentManager.java 517719 2007-03-13 15:05:48Z ate $
048:         * 
049:         */
050:        public class SpringComponentManager implements  ComponentManager {
051:            protected ConfigurableApplicationContext appContext;
052:
053:            private ConfigurableApplicationContext bootCtx;
054:
055:            protected ArrayList factories;
056:
057:            private Map preconfiguredBeans;
058:
059:            private boolean started = false;
060:
061:            public SpringComponentManager(String[] bootConfigs,
062:                    String[] appConfigs, ServletContext servletContext,
063:                    String appRoot) {
064:                File appRootDir = new File(appRoot);
065:                System.setProperty(
066:                        JetspeedEngineConstants.APPLICATION_ROOT_KEY,
067:                        appRootDir.getAbsolutePath());
068:
069:                if (bootConfigs != null && bootConfigs.length > 0) {
070:                    bootCtx = new XmlWebApplicationContext();
071:                    ((XmlWebApplicationContext) bootCtx)
072:                            .setServletContext(servletContext);
073:                    ((XmlWebApplicationContext) bootCtx)
074:                            .setConfigLocations(bootConfigs);
075:                } else {
076:                    bootCtx = new GenericApplicationContext();
077:                }
078:
079:                appContext = new XmlWebApplicationContext();
080:                ((XmlWebApplicationContext) appContext).setParent(bootCtx);
081:                ((XmlWebApplicationContext) appContext)
082:                        .setServletContext(servletContext);
083:                ((XmlWebApplicationContext) appContext)
084:                        .setConfigLocations(appConfigs);
085:
086:                factories = new ArrayList();
087:                factories.add(appContext);
088:
089:                servletContext
090:                        .setAttribute(
091:                                WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
092:                                appContext);
093:            }
094:
095:            public SpringComponentManager(String[] bootConfigs,
096:                    String[] appConfigs, ServletContext servletContext,
097:                    String appRoot, Map preconfiguredBeans) {
098:                this (bootConfigs, appConfigs, servletContext, appRoot);
099:                this .preconfiguredBeans = preconfiguredBeans;
100:            }
101:
102:            public SpringComponentManager(String[] bootConfigs,
103:                    String[] appConfigs, String appRoot) {
104:                PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
105:                Properties p = new Properties();
106:                //p.setProperty(APPLICATION_ROOT_KEY,appRootDir.getAbsolutePath());
107:                ppc.setProperties(p);
108:
109:                if (bootConfigs != null && bootConfigs.length > 0) {
110:                    bootCtx = new FileSystemXmlApplicationContext(bootConfigs,
111:                            false);
112:                    bootCtx.addBeanFactoryPostProcessor(ppc);
113:                    bootCtx.refresh();
114:                } else {
115:                    bootCtx = new GenericApplicationContext();
116:                }
117:
118:                appContext = new FileSystemXmlApplicationContext(appConfigs,
119:                        false, bootCtx);
120:                appContext.addBeanFactoryPostProcessor(ppc);
121:                appContext.refresh();
122:                factories = new ArrayList();
123:                factories.add(appContext);
124:
125:            }
126:
127:            /**
128:             * <p>
129:             * getComponent
130:             * </p>
131:             * 
132:             * @see org.apache.jetspeed.components.ComponentManagement#getComponent(java.lang.Object)
133:             * @param componentName
134:             * @return
135:             */
136:            public Object getComponent(Object componentName) {
137:                if (componentName instanceof  Class) {
138:                    return appContext
139:                            .getBean(((Class) componentName).getName());
140:                } else {
141:                    return appContext.getBean(componentName.toString());
142:                }
143:            }
144:
145:            /**
146:             * <p>
147:             * getComponent
148:             * </p>
149:             * 
150:             * @see org.apache.jetspeed.components.ComponentManagement#getComponent(java.lang.Object,
151:             *      java.lang.Object)
152:             * @param containerName
153:             * @param componentName
154:             * @return
155:             */
156:            public Object getComponent(Object containerName,
157:                    Object componentName) {
158:                return getComponent(componentName);
159:            }
160:
161:            /**
162:             * <p>
163:             * getContainer
164:             * </p>
165:             * 
166:             * @see org.apache.jetspeed.components.ContainerManagement#getContainer(java.lang.String)
167:             * @param containerName
168:             * @return
169:             */
170:            public Object getContainer(String containerName) {
171:                return appContext;
172:            }
173:
174:            /**
175:             * <p>
176:             * getRootContainer
177:             * </p>
178:             * 
179:             * @see org.apache.jetspeed.components.ContainerManagement#getRootContainer()
180:             * @return
181:             */
182:            public Object getRootContainer() {
183:                return appContext;
184:            }
185:
186:            /**
187:             * <p>
188:             * getContainers
189:             * </p>
190:             * 
191:             * @see org.apache.jetspeed.components.ContainerManagement#getContainers()
192:             * @return
193:             */
194:            public Collection getContainers() {
195:                return factories;
196:            }
197:
198:            /**
199:             * <p>
200:             * stop
201:             * </p>
202:             * 
203:             * @see org.apache.jetspeed.components.ContainerManagement#stop()
204:             * 
205:             */
206:            public void stop() {
207:                appContext.close();
208:                bootCtx.close();
209:                started = false;
210:            }
211:
212:            public ApplicationContext getApplicationContext() {
213:                return appContext;
214:            }
215:
216:            public void addComponent(String name, Object bean) {
217:                if (preconfiguredBeans == null) {
218:                    preconfiguredBeans = new HashMap();
219:                }
220:                preconfiguredBeans.put(name, bean);
221:
222:                if (started) {
223:                    bootCtx.getBeanFactory().registerSingleton(name, bean);
224:                }
225:            }
226:
227:            public void start() {
228:                bootCtx.refresh();
229:                if (preconfiguredBeans != null) {
230:                    Iterator itr = preconfiguredBeans.entrySet().iterator();
231:                    while (itr.hasNext()) {
232:                        Map.Entry entry = (Map.Entry) itr.next();
233:                        bootCtx.getBeanFactory().registerSingleton(
234:                                entry.getKey().toString(), entry.getValue());
235:                    }
236:                }
237:
238:                appContext.refresh();
239:                started = true;
240:            }
241:
242:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.