Source Code Cross Referenced for FactoryManagerServiceImpl.java in  » Web-Framework » cocoon » org » apache » cocoon » portal » pluto » services » factory » 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 » cocoon » org.apache.cocoon.portal.pluto.services.factory 
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.cocoon.portal.pluto.services.factory;
018:
019:        import java.util.ArrayList;
020:        import java.util.HashMap;
021:        import java.util.Iterator;
022:        import java.util.List;
023:        import java.util.Map;
024:
025:        import javax.portlet.ActionRequest;
026:        import javax.portlet.ActionResponse;
027:        import javax.portlet.PortalContext;
028:        import javax.portlet.PortletConfig;
029:        import javax.portlet.PortletContext;
030:        import javax.portlet.PortletPreferences;
031:        import javax.portlet.PortletSession;
032:        import javax.portlet.PortletURL;
033:        import javax.portlet.RenderRequest;
034:        import javax.portlet.RenderResponse;
035:        import javax.servlet.ServletConfig;
036:
037:        import org.apache.avalon.framework.activity.Disposable;
038:        import org.apache.avalon.framework.activity.Initializable;
039:        import org.apache.avalon.framework.container.ContainerUtil;
040:        import org.apache.avalon.framework.context.Context;
041:        import org.apache.avalon.framework.context.ContextException;
042:        import org.apache.avalon.framework.context.Contextualizable;
043:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
044:        import org.apache.avalon.framework.service.ServiceException;
045:        import org.apache.avalon.framework.service.ServiceManager;
046:        import org.apache.avalon.framework.service.Serviceable;
047:        import org.apache.cocoon.portal.pluto.factory.ActionRequestFactoryImpl;
048:        import org.apache.cocoon.portal.pluto.factory.ControllerFactoryImpl;
049:        import org.apache.cocoon.portal.pluto.factory.ObjectIDFactoryImpl;
050:        import org.apache.cocoon.portal.pluto.factory.PortletInvokerFactoryImpl;
051:        import org.apache.cocoon.portal.pluto.factory.PortletPreferencesFactoryImpl;
052:        import org.apache.cocoon.portal.pluto.factory.RenderRequestFactoryImpl;
053:        import org.apache.cocoon.servlet.CocoonServlet;
054:        import org.apache.pluto.factory.Factory;
055:        import org.apache.pluto.factory.ObjectIDFactory;
056:        import org.apache.pluto.factory.impl.ActionResponseFactoryImpl;
057:        import org.apache.pluto.factory.impl.PortalContextFactoryImpl;
058:        import org.apache.pluto.factory.impl.PortletConfigFactoryImpl;
059:        import org.apache.pluto.factory.impl.PortletContextFactoryImpl;
060:        import org.apache.pluto.factory.impl.PortletSessionFactoryImpl;
061:        import org.apache.pluto.factory.impl.PortletURLFactoryImpl;
062:        import org.apache.pluto.factory.impl.RenderResponseFactoryImpl;
063:        import org.apache.pluto.invoker.PortletInvoker;
064:        import org.apache.pluto.om.ControllerFactory;
065:        import org.apache.pluto.services.factory.FactoryManagerService;
066:        import org.apache.pluto.util.NamespaceMapper;
067:        import org.apache.pluto.util.impl.NamespaceMapperFactoryImpl;
068:
069:        /**
070:         * Manages the life-time of factories registered during container startup.
071:         * A service has to derive from {@link Factory} and implement the
072:         * <CODE>init()</CODE> and <CODE>destroy()</CODE> methods as appropriate.
073:         * 
074:         * TODO This is a very lazy implementation, we need to improve it
075:         * 
076:         * @see Factory
077:         * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
078:         * 
079:         * @version CVS $Id: FactoryManagerServiceImpl.java 433543 2006-08-22 06:22:54Z crossley $
080:         */
081:        public class FactoryManagerServiceImpl extends AbstractLogEnabled
082:                implements  FactoryManagerService, Initializable,
083:                Contextualizable, Serviceable, Disposable {
084:
085:            /** The servlet configuration */
086:            protected ServletConfig servletConfig;
087:
088:            /** The avalon context */
089:            protected Context context;
090:
091:            /** The service manager */
092:            protected ServiceManager manager;
093:
094:            /* (non-Javadoc)
095:             * @see org.apache.avalon.framework.context.Contextualizable#contextualize(org.apache.avalon.framework.context.Context)
096:             */
097:            public void contextualize(Context context) throws ContextException {
098:                this .context = context;
099:                this .servletConfig = (ServletConfig) context
100:                        .get(CocoonServlet.CONTEXT_SERVLET_CONFIG);
101:            }
102:
103:            /* (non-Javadoc)
104:             * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
105:             */
106:            public void service(ServiceManager manager) throws ServiceException {
107:                this .manager = manager;
108:            }
109:
110:            /* (non-Javadoc)
111:             * @see org.apache.avalon.framework.activity.Initializable#initialize()
112:             */
113:            public void initialize() throws Exception {
114:                final Map factories = new HashMap();
115:
116:                factories.put(ActionRequest.class.getName(),
117:                        ActionRequestFactoryImpl.class.getName());
118:                factories.put(RenderRequest.class.getName(),
119:                        RenderRequestFactoryImpl.class.getName());
120:                factories.put(RenderResponse.class.getName(),
121:                        RenderResponseFactoryImpl.class.getName());
122:                factories.put(PortletSession.class.getName(),
123:                        PortletSessionFactoryImpl.class.getName());
124:                factories.put(PortletConfig.class.getName(),
125:                        PortletConfigFactoryImpl.class.getName());
126:                factories.put(PortletContext.class.getName(),
127:                        PortletContextFactoryImpl.class.getName());
128:                factories.put(PortletPreferences.class.getName(),
129:                        PortletPreferencesFactoryImpl.class.getName());
130:                factories.put(PortalContext.class.getName(),
131:                        PortalContextFactoryImpl.class.getName());
132:                factories.put(ActionResponse.class.getName(),
133:                        ActionResponseFactoryImpl.class.getName());
134:                factories.put(PortletURL.class.getName(),
135:                        PortletURLFactoryImpl.class.getName());
136:                factories.put(PortletPreferences.class.getName(),
137:                        PortletPreferencesFactoryImpl.class.getName());
138:
139:                factories.put(PortletInvoker.class.getName(),
140:                        PortletInvokerFactoryImpl.class.getName());
141:
142:                factories.put(NamespaceMapper.class.getName(),
143:                        NamespaceMapperFactoryImpl.class.getName());
144:
145:                factories.put(ObjectIDFactory.class.getName(),
146:                        ObjectIDFactoryImpl.class.getName());
147:
148:                factories.put(ControllerFactory.class.getName(),
149:                        ControllerFactoryImpl.class.getName());
150:
151:                for (Iterator iter = factories.entrySet().iterator(); iter
152:                        .hasNext();) {
153:                    Map.Entry me = (Map.Entry) iter.next();
154:                    String factoryInterfaceName = (String) me.getKey();
155:                    // try to get hold of the factory
156:                    Class factoryInterface;
157:
158:                    factoryInterface = Class.forName(factoryInterfaceName);
159:
160:                    String factoryImplName = (String) me.getValue();
161:                    Class factoryImpl = Class.forName(factoryImplName);
162:                    Factory factory = (Factory) factoryImpl.newInstance();
163:
164:                    ContainerUtil.enableLogging(factory, this .getLogger());
165:                    ContainerUtil.contextualize(factory, this .context);
166:                    ContainerUtil.service(factory, this .manager);
167:                    ContainerUtil.initialize(factory);
168:
169:                    factory.init(this .servletConfig, new HashMap());
170:
171:                    factoryMap.put(factoryInterface.getName(), factory);
172:
173:                    // build up list in reverse order for later destruction
174:                    factoryList.add(0, factory);
175:
176:                }
177:            }
178:
179:            /* (non-Javadoc)
180:             * @see org.apache.avalon.framework.activity.Disposable#dispose()
181:             */
182:            public void dispose() {
183:
184:                // destroy the services in reverse order
185:                for (Iterator iterator = factoryList.iterator(); iterator
186:                        .hasNext();) {
187:                    Factory factory = (Factory) iterator.next();
188:
189:                    try {
190:                        factory.destroy();
191:                    } catch (Exception exc) {
192:                        // ignore it
193:                    }
194:                }
195:
196:                factoryList.clear();
197:                factoryMap.clear();
198:
199:            }
200:
201:            /**
202:             ** Returns the service implementation for the given service class, or
203:             ** <CODE>null</CODE> if no such service is registered.
204:             **
205:             ** @param theClass  the service class
206:             **
207:             ** @return   the service implementation
208:             **/
209:            public Factory getFactory(Class theClass) {
210:                // at this state the services map is read-only,
211:                // therefore we can go without synchronization
212:                return ((Factory) factoryMap.get(theClass.getName()));
213:            }
214:
215:            private Map factoryMap = new HashMap();
216:            private List factoryList = new ArrayList();
217:
218:        }
w__ww__.__j__ava2___s.___c___om | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.