Source Code Cross Referenced for TurbineAvalonComponentService.java in  » Web-Framework » TURBINE » org » apache » turbine » services » avaloncomponent » 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 » TURBINE » org.apache.turbine.services.avaloncomponent 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.apache.turbine.services.avaloncomponent;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one
005:         * or more contributor license agreements.  See the NOTICE file
006:         * distributed with this work for additional information
007:         * regarding copyright ownership.  The ASF licenses this file
008:         * to you under the Apache License, Version 2.0 (the
009:         * "License"); you may not use this file except in compliance
010:         * with the License.  You may obtain a copy of the License at
011:         *
012:         *   http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing,
015:         * software distributed under the License is distributed on an
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017:         * KIND, either express or implied.  See the License for the
018:         * specific language governing permissions and limitations
019:         * under the License.
020:         */
021:
022:        import java.util.Iterator;
023:        import java.util.List;
024:        import java.util.Vector;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:
029:        import org.apache.avalon.excalibur.component.DefaultRoleManager;
030:        import org.apache.avalon.excalibur.component.ExcaliburComponentManager;
031:        import org.apache.avalon.excalibur.logger.Log4JLoggerManager;
032:        import org.apache.avalon.excalibur.logger.LoggerManager;
033:        import org.apache.avalon.framework.activity.Disposable;
034:        import org.apache.avalon.framework.activity.Initializable;
035:        import org.apache.avalon.framework.component.Component;
036:        import org.apache.avalon.framework.component.ComponentException;
037:        import org.apache.avalon.framework.configuration.Configuration;
038:        import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
039:        import org.apache.avalon.framework.context.DefaultContext;
040:        import org.apache.avalon.framework.logger.Logger;
041:
042:        import org.apache.turbine.Turbine;
043:        import org.apache.turbine.services.InitializationException;
044:        import org.apache.turbine.services.TurbineBaseService;
045:
046:        /**
047:         * An implementation of AvalonComponentService which loads all the
048:         * components given in the TurbineResources.properties File.
049:         * <p>
050:         * For component which require the location of the application or
051:         * context root, there are two ways to get it.
052:         * <ol>
053:         * <li>
054:         *   Implement the Contextualizable interface.  The full path to the
055:         *   correct OS directory can be found under the ComponentAppRoot key.
056:         * </li>
057:         * <li>
058:         *   The system property "applicationRoot" is also set to the full path
059:         *   of the correct OS directory.
060:         * </li>
061:         * </ol>
062:         * If you want to initialize Torque by using the AvalonComponentService, you
063:         * must activate Torque at initialization time by specifying
064:         *
065:         * services.AvalonComponentService.lookup = org.apache.torque.avalon.Torque
066:         *
067:         * in your TurbineResources.properties.
068:         *
069:         * @author <a href="mailto:quintonm@bellsouth.net">Quinton McCombs</a>
070:         * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
071:         * @version $Id: TurbineAvalonComponentService.java 534527 2007-05-02 16:10:59Z tv $
072:         */
073:        public class TurbineAvalonComponentService extends TurbineBaseService
074:                implements  AvalonComponentService, Initializable, Disposable {
075:            /** Logging */
076:            private static Log log = LogFactory
077:                    .getLog(TurbineAvalonComponentService.class);
078:
079:            /** Component manager */
080:            private ExcaliburComponentManager manager = null;
081:
082:            // -------------------------------------------------------------
083:            // Service initialization
084:            // -------------------------------------------------------------
085:
086:            /**
087:             * Load all configured components and initialize them. This is
088:             * a zero parameter variant which queries the Turbine Servlet
089:             * for its config.
090:             *
091:             * @throws InitializationException Something went wrong in the init
092:             *         stage
093:             */
094:            public void init() throws InitializationException {
095:                try {
096:                    initialize();
097:
098:                    setInit(true);
099:                } catch (Exception e) {
100:                    throw new InitializationException("init failed", e);
101:                }
102:            }
103:
104:            /**
105:             * Shuts the Component Service down, calls dispose on the components that
106:             * implement this interface
107:             *
108:             */
109:            public void shutdown() {
110:                dispose();
111:                setInit(false);
112:            }
113:
114:            // -------------------------------------------------------------
115:            // Avalon lifecycle interfaces
116:            // -------------------------------------------------------------
117:
118:            /**
119:             * Initializes the container
120:             *
121:             * @throws Exception generic exception
122:             */
123:            public void initialize() throws Exception {
124:                org.apache.commons.configuration.Configuration conf = getConfiguration();
125:
126:                // get the filenames and expand them relative to webapp root
127:                String sysConfigFilename = Turbine.getRealPath(conf.getString(
128:                        COMPONENT_CONFIG_KEY, COMPONENT_CONFIG_VALUE));
129:                String roleConfigFilename = Turbine.getRealPath(conf.getString(
130:                        COMPONENT_ROLE_KEY, COMPONENT_ROLE_VALUE));
131:
132:                log.debug("Config File: " + sysConfigFilename);
133:                log.debug("Role File:   " + roleConfigFilename);
134:
135:                // process configuration files
136:
137:                DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
138:                Configuration sysConfig = builder
139:                        .buildFromFile(sysConfigFilename);
140:                Configuration roleConfig = builder
141:                        .buildFromFile(roleConfigFilename);
142:
143:                // Create the LoggerManager for Log4J
144:                LoggerManager lm = new Log4JLoggerManager();
145:
146:                // Setup the RoleManager
147:                DefaultRoleManager roles = new DefaultRoleManager();
148:
149:                Logger logger = lm.getLoggerForCategory(AVALON_LOG_CATEGORY);
150:
151:                roles.enableLogging(logger);
152:                roles.configure(roleConfig);
153:
154:                // Setup ECM
155:                manager = new ExcaliburComponentManager();
156:
157:                manager.setLoggerManager(lm);
158:                manager.enableLogging(logger);
159:
160:                DefaultContext context = new DefaultContext();
161:                String realPath = Turbine.getRealPath("/");
162:
163:                context
164:                        .put(AvalonComponentService.COMPONENT_APP_ROOT,
165:                                realPath);
166:                System.setProperty("applicationRoot", realPath);
167:
168:                log.debug("Application Root is " + realPath);
169:
170:                manager.contextualize(context);
171:                manager.setRoleManager(roles);
172:                manager.configure(sysConfig);
173:
174:                // Init ECM!!!!
175:                manager.initialize();
176:
177:                List lookupComponents = conf.getList(COMPONENT_LOOKUP_KEY,
178:                        new Vector());
179:
180:                for (Iterator it = lookupComponents.iterator(); it.hasNext();) {
181:                    String component = (String) it.next();
182:                    try {
183:                        Component c = manager.lookup(component);
184:                        log.info("Lookup for Component " + component
185:                                + " successful");
186:                        manager.release(c);
187:                    } catch (Exception e) {
188:                        log.error("Lookup for Component " + component
189:                                + " failed!");
190:                    }
191:                }
192:            }
193:
194:            /**
195:             * Disposes of the container and releases resources
196:             */
197:            public void dispose() {
198:                manager.dispose();
199:            }
200:
201:            /**
202:             * Returns an instance of the named component
203:             *
204:             * @param roleName Name of the role the component fills.
205:             * @return an instance of the named component
206:             * @throws ComponentException generic exception
207:             */
208:            public Component lookup(String roleName) throws ComponentException {
209:                return manager.lookup(roleName);
210:            }
211:
212:            /**
213:             * Releases the component
214:             *
215:             * @param component the component to release
216:             */
217:            public void release(Component component) {
218:                manager.release(component);
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.