Source Code Cross Referenced for Web3DataSourceSelectorImpl.java in  » Content-Management-System » apache-lenya-2.0 » org » apache » cocoon » components » web3 » impl » 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 » Content Management System » apache lenya 2.0 » org.apache.cocoon.components.web3.impl 
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.components.web3.impl;
018:
019:        import java.util.Enumeration;
020:        import java.util.Hashtable;
021:
022:        import org.apache.avalon.framework.activity.Disposable;
023:        import org.apache.avalon.framework.configuration.Configurable;
024:        import org.apache.avalon.framework.configuration.Configuration;
025:        import org.apache.avalon.framework.configuration.ConfigurationException;
026:        import org.apache.avalon.framework.logger.AbstractLogEnabled;
027:        import org.apache.avalon.framework.service.ServiceException;
028:        import org.apache.avalon.framework.service.ServiceManager;
029:        import org.apache.avalon.framework.service.ServiceSelector;
030:        import org.apache.avalon.framework.service.Serviceable;
031:        import org.apache.avalon.framework.thread.ThreadSafe;
032:
033:        import org.apache.cocoon.components.LifecycleHelper;
034:        import org.apache.cocoon.components.web3.Web3DataSource;
035:        import org.apache.cocoon.util.ClassUtils;
036:
037:        import EDU.oswego.cs.dl.util.concurrent.Mutex;
038:
039:        /**
040:         * TBD
041:         *
042:         * @author <a href="mailto:michael.gerzabek@at.efp.cc">Michael Gerzabek</a>
043:         * @since 2.1
044:         * @version CVS $Id: Web3DataSourceSelectorImpl.java 524407 2007-03-31 10:59:28Z joerg $
045:         */
046:        public class Web3DataSourceSelectorImpl extends AbstractLogEnabled
047:                implements  ServiceSelector, Disposable, Serviceable,
048:                Configurable, ThreadSafe {
049:
050:            /** The service manager instance */
051:            protected ServiceManager manager;
052:            protected Configuration configuration;
053:            private static final Hashtable pools = new Hashtable();
054:            private static final Mutex lock = new Mutex();
055:
056:            /**
057:             * Set the current <code>ServiceManager</code> instance used by this
058:             * <code>Serviceable</code>.
059:             */
060:            public void service(ServiceManager manager) throws ServiceException {
061:                this .manager = manager;
062:            }
063:
064:            public void configure(Configuration configuration)
065:                    throws ConfigurationException {
066:                if (null != configuration) {
067:                    this .configuration = configuration;
068:                } else {
069:                    getLogger().error(
070:                            "Couldn't configure Web3DataSourceSelector."
071:                                    + " No configuration provided!");
072:                }
073:            }
074:
075:            public boolean isSelectable(Object obj) {
076:                return Web3DataSourceSelectorImpl.pools.containsKey(obj);
077:            }
078:
079:            public Object select(Object obj) throws ServiceException {
080:                Web3DataSource pool = null;
081:                try {
082:                    Web3DataSourceSelectorImpl.lock.acquire();
083:                    if (null != obj) {
084:                        if (Web3DataSourceSelectorImpl.pools.containsKey(obj)) {
085:                            pool = (Web3DataSource) Web3DataSourceSelectorImpl.pools
086:                                    .get(obj);
087:                        } else {
088:                            Configuration a[] = this .configuration
089:                                    .getChildren("backend");
090:                            Configuration c = null;
091:
092:                            if (null != a)
093:                                for (int i = 0; i < a.length; i++) {
094:                                    try {
095:                                        String s = a[i].getAttribute("name");
096:                                        if (null != s
097:                                                && s.equals(obj.toString())) {
098:                                            // a backend with a name can be defined only once
099:                                            c = a[i];
100:                                            break;
101:                                        }
102:                                    } catch (ConfigurationException x) {
103:                                        // this configuration element has no mandatory
104:                                        //attribute name
105:                                    }
106:                                }
107:                            // No configuration for this backend-id found!
108:                            if (null == c) {
109:                                return null;
110:                            }
111:                            Class theClass = Class
112:                                    .forName(
113:                                            c
114:                                                    .getChild("class")
115:                                                    .getValue(
116:                                                            "org.apache.cocoon.components.web3.impl.Web3DataSourceImpl"),
117:                                            true, ClassUtils.getClassLoader());
118:                            pool = (Web3DataSource) theClass.newInstance();
119:                            LifecycleHelper.setupComponent(pool, getLogger(),
120:                                    null, this .manager, c);
121:                            Web3DataSourceSelectorImpl.pools.put(obj, pool);
122:                        }
123:                    }
124:                } catch (Exception ex) {
125:                    getLogger().error(ex.getMessage(), ex);
126:                    throw new ServiceException(null, ex.getMessage());
127:                } finally {
128:                    Web3DataSourceSelectorImpl.lock.release();
129:                }
130:                getLogger().debug("Returning Web3DataSource[" + pool + "]");
131:                return pool;
132:            }
133:
134:            public void release(Object object) {
135:            }
136:
137:            /** Dispose properly of the pool */
138:            public void dispose() {
139:                this .manager = null;
140:                try {
141:                    Web3DataSourceSelectorImpl.lock.acquire();
142:                    String sid = null;
143:                    Web3DataSource pool;
144:                    for (Enumeration enumeration = Web3DataSourceSelectorImpl.pools
145:                            .keys(); enumeration.hasMoreElements();) {
146:                        sid = (String) enumeration.nextElement();
147:                        pool = (Web3DataSource) Web3DataSourceSelectorImpl.pools
148:                                .get(sid);
149:                        pool.dispose();
150:                    }
151:                    Web3DataSourceSelectorImpl.pools.clear();
152:                } catch (Exception ex) {
153:                } finally {
154:                    Web3DataSourceSelectorImpl.lock.release();
155:                }
156:            }
157:
158:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.