Source Code Cross Referenced for BusFactory.java in  » Web-Services-apache-cxf-2.0.1 » api » org » apache » cxf » 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 Services apache cxf 2.0.1 » api » org.apache.cxf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */package org.apache.cxf;
019:
020:        import java.io.BufferedReader;
021:        import java.io.InputStream;
022:        import java.io.InputStreamReader;
023:        import java.util.logging.Level;
024:        import java.util.logging.Logger;
025:
026:        import org.apache.cxf.buslifecycle.BusLifeCycleManager;
027:        import org.apache.cxf.common.logging.LogUtils;
028:
029:        public abstract class BusFactory {
030:
031:            public static final String BUS_FACTORY_PROPERTY_NAME = "org.apache.cxf.bus.factory";
032:            public static final String DEFAULT_BUS_FACTORY = "org.apache.cxf.bus.CXFBusFactory";
033:
034:            protected static Bus defaultBus;
035:            protected static ThreadLocal<Bus> localBus = new ThreadLocal<Bus>();
036:
037:            private static final Logger LOG = LogUtils.getL7dLogger(
038:                    BusFactory.class, "APIMessages");
039:
040:            /** 
041:             * Creates a new bus. 
042:             * While concrete <code>BusFactory</code> may offer differently
043:             * parametrized methods for creating a bus, all factories support
044:             * this no-arg factory method.
045:             *
046:             * @return the newly created bus.
047:             */
048:            public abstract Bus createBus();
049:
050:            /**
051:             * Returns the default bus, creating it if necessary.
052:             * 
053:             * @return the default bus.
054:             */
055:            public static synchronized Bus getDefaultBus() {
056:                return getDefaultBus(true);
057:            }
058:
059:            /**
060:             * Returns the default bus
061:             * @param createIfNeeded Set to true to create a default bus if one doesn't exist
062:             * @return the default bus.
063:             */
064:            public static synchronized Bus getDefaultBus(boolean createIfNeeded) {
065:                if (defaultBus == null && createIfNeeded) {
066:                    defaultBus = newInstance().createBus();
067:                }
068:                return defaultBus;
069:            }
070:
071:            /**
072:             * Sets the default bus.
073:             * @param bus the default bus.
074:             */
075:            public static synchronized void setDefaultBus(Bus bus) {
076:                defaultBus = bus;
077:                setThreadDefaultBus(bus);
078:            }
079:
080:            /**
081:             * Sets the default bus for the thread.
082:             * @param bus the default bus.
083:             */
084:            public static synchronized void setThreadDefaultBus(Bus bus) {
085:                localBus.set(bus);
086:            }
087:
088:            /**
089:             * Gets the default bus for the thread.
090:             * @return the default bus.
091:             */
092:            public static synchronized Bus getThreadDefaultBus() {
093:                if (localBus.get() == null) {
094:                    Bus b = getDefaultBus();
095:                    localBus.set(b);
096:                }
097:                return localBus.get();
098:            }
099:
100:            /**
101:             * Sets the default bus if a default bus is not already set.
102:             * @param bus the default bus.
103:             * @return true if the bus was not set and is now set
104:             */
105:            public static synchronized boolean possiblySetDefaultBus(Bus bus) {
106:                if (localBus.get() == null) {
107:                    localBus.set(bus);
108:                }
109:
110:                if (defaultBus == null) {
111:                    defaultBus = bus;
112:                    return true;
113:                }
114:                return false;
115:            }
116:
117:            /**
118:             * Create a new BusFactory
119:             * 
120:             * The class of the BusFactory is determined by looking for the system propery: 
121:             * org.apache.cxf.bus.factory
122:             * or by searching the classpath for:
123:             * META-INF/services/org.apache.cxf.bus.factory
124:             * 
125:             * @return a new BusFactory to be used to create Bus objects
126:             */
127:            public static BusFactory newInstance() {
128:                return newInstance(null);
129:            }
130:
131:            /**
132:             * Create a new BusFactory
133:             * @param className The class of the BusFactory to create.  If null, uses the
134:             * default search algorithm.
135:             * @return a new BusFactory to be used to create Bus objects
136:             */
137:            public static BusFactory newInstance(String className) {
138:                BusFactory instance = null;
139:                ClassLoader classLoader = Thread.currentThread()
140:                        .getContextClassLoader();
141:                if (className == null) {
142:                    className = getBusFactoryClass(classLoader);
143:                }
144:                Class<? extends BusFactory> busFactoryClass;
145:                try {
146:                    busFactoryClass = Class.forName(className, true,
147:                            classLoader).asSubclass(BusFactory.class);
148:                    instance = busFactoryClass.newInstance();
149:                } catch (Exception ex) {
150:                    LogUtils.log(LOG, Level.SEVERE,
151:                            "BUS_FACTORY_INSTANTIATION_EXC", ex);
152:                    throw new RuntimeException(ex);
153:                }
154:                return instance;
155:            }
156:
157:            protected void initializeBus(Bus bus) {
158:                BusLifeCycleManager lifeCycleManager = bus
159:                        .getExtension(BusLifeCycleManager.class);
160:                if (null != lifeCycleManager) {
161:                    lifeCycleManager.initComplete();
162:                }
163:            }
164:
165:            private static String getBusFactoryClass(ClassLoader classLoader) {
166:
167:                String busFactoryClass = null;
168:                String busFactoryCondition = null;
169:
170:                // next check system properties
171:                busFactoryClass = System
172:                        .getProperty(BusFactory.BUS_FACTORY_PROPERTY_NAME);
173:                if (isValidBusFactoryClass(busFactoryClass)) {
174:                    return busFactoryClass;
175:                }
176:
177:                try {
178:                    // next, check for the services stuff in the jar file
179:                    String serviceId = "META-INF/services/"
180:                            + BusFactory.BUS_FACTORY_PROPERTY_NAME;
181:                    InputStream is = null;
182:
183:                    if (classLoader == null) {
184:                        classLoader = Thread.currentThread()
185:                                .getContextClassLoader();
186:                    }
187:
188:                    if (classLoader == null) {
189:                        is = ClassLoader.getSystemResourceAsStream(serviceId);
190:                    } else {
191:                        is = classLoader.getResourceAsStream(serviceId);
192:                    }
193:                    if (is != null) {
194:                        BufferedReader rd = new BufferedReader(
195:                                new InputStreamReader(is, "UTF-8"));
196:                        busFactoryClass = rd.readLine();
197:                        busFactoryCondition = rd.readLine();
198:                        rd.close();
199:                    }
200:                    if (isValidBusFactoryClass(busFactoryClass)) {
201:                        if (busFactoryCondition != null) {
202:                            try {
203:                                classLoader.loadClass(busFactoryCondition);
204:                                return busFactoryClass;
205:                            } catch (ClassNotFoundException e) {
206:                                return DEFAULT_BUS_FACTORY;
207:                            }
208:                        } else {
209:                            return busFactoryClass;
210:                        }
211:                    }
212:
213:                    // otherwise use default  
214:                    busFactoryClass = BusFactory.DEFAULT_BUS_FACTORY;
215:                    return busFactoryClass;
216:                } catch (Exception ex) {
217:                    LogUtils.log(LOG, Level.SEVERE,
218:                            "FAILED_TO_DETERMINE_BUS_FACTORY_EXC", ex);
219:                }
220:                return busFactoryClass;
221:            }
222:
223:            private static boolean isValidBusFactoryClass(
224:                    String busFactoryClassName) {
225:                return busFactoryClassName != null
226:                        && !"".equals(busFactoryClassName);
227:            }
228:
229:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.