Source Code Cross Referenced for DependencyManager.java in  » Web-Services-AXIS2 » kernal » org » apache » axis2 » engine » 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 AXIS2 » kernal » org.apache.axis2.engine 
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:         */
019:
020:        package org.apache.axis2.engine;
021:
022:        import org.apache.axis2.AxisFault;
023:        import org.apache.axis2.Constants;
024:        import org.apache.axis2.service.Lifecycle;
025:        import org.apache.axis2.context.ServiceContext;
026:        import org.apache.axis2.context.ServiceGroupContext;
027:        import org.apache.axis2.description.AxisService;
028:        import org.apache.axis2.description.AxisServiceGroup;
029:        import org.apache.axis2.description.Parameter;
030:        import org.apache.axis2.util.Loader;
031:        import org.apache.commons.logging.Log;
032:        import org.apache.commons.logging.LogFactory;
033:
034:        import java.lang.reflect.InvocationTargetException;
035:        import java.lang.reflect.Method;
036:        import java.util.Iterator;
037:
038:        /**
039:         * If the service implementation has an init method with 1 or 2 message context as its parameters, then
040:         * the DependencyManager calls the init method with appropriate parameters.
041:         */
042:        public class DependencyManager {
043:            private static final Log log = LogFactory
044:                    .getLog(DependencyManager.class);
045:            public final static String SERVICE_INIT_METHOD = "init";
046:            public final static String SERVICE_DESTROY_METHOD = "destroy";
047:
048:            /**
049:             * Initialize a new service object.  Essentially, check to see if the object wants to receive
050:             * an init() call - if so, call it.
051:             *
052:             * @param obj the service object
053:             * @param serviceContext the active ServiceContext
054:             * @throws AxisFault if there's a problem initializing
055:             * 
056:             * @deprecated please use initServiceObject()
057:             */
058:            public static void initServiceClass(Object obj,
059:                    ServiceContext serviceContext) throws AxisFault {
060:                initServiceObject(obj, serviceContext);
061:            }
062:
063:            /**
064:             * Initialize a new service object.  Essentially, check to see if the object wants to receive
065:             * an init() call - if so, call it.
066:             *
067:             * @param obj the service object
068:             * @param serviceContext the active ServiceContext
069:             * @throws AxisFault if there's a problem initializing
070:             */
071:            public static void initServiceObject(Object obj,
072:                    ServiceContext serviceContext) throws AxisFault {
073:                // This is the way to do things into the future.
074:                if (obj instanceof  Lifecycle) {
075:                    ((Lifecycle) obj).init(serviceContext);
076:                    return;
077:                }
078:
079:                // ...however, we also still support the old way for now.  Note that introspecting for
080:                // a method like this is something like 10 times slower than the above instanceof check.
081:
082:                Class classToLoad = obj.getClass();
083:                // We can not call classToLoad.getDeclaredMethed() , since there
084:                //  can be insatnce where mutiple services extends using one class
085:                // just for init and other reflection methods
086:                Method method = null;
087:                try {
088:                    method = classToLoad.getMethod(SERVICE_INIT_METHOD,
089:                            new Class[] { ServiceContext.class });
090:                } catch (Exception e) {
091:                    //We do not need to inform this to user , since this something
092:                    // Axis2 is checking to support Session. So if the method is
093:                    // not there we should ignore that
094:                }
095:                if (method != null) {
096:                    try {
097:                        method.invoke(obj, new Object[] { serviceContext });
098:                    } catch (IllegalAccessException e) {
099:                        log.info("Exception trying to call "
100:                                + SERVICE_INIT_METHOD, e);
101:                    } catch (IllegalArgumentException e) {
102:                        log.info("Exception trying to call "
103:                                + SERVICE_INIT_METHOD, e);
104:                    } catch (InvocationTargetException e) {
105:                        log.info("Exception trying to call "
106:                                + SERVICE_INIT_METHOD, e);
107:                    }
108:                }
109:            }
110:
111:            /**
112:             * To init all the services in application scope
113:             *
114:             * @param serviceGroupContext the ServiceGroupContext from which to extract all the services
115:             * @throws AxisFault if there's a problem initializing
116:             */
117:            public static void initService(
118:                    ServiceGroupContext serviceGroupContext) throws AxisFault {
119:                AxisServiceGroup serviceGroup = serviceGroupContext
120:                        .getDescription();
121:                Iterator serviceItr = serviceGroup.getServices();
122:                while (serviceItr.hasNext()) {
123:                    AxisService axisService = (AxisService) serviceItr.next();
124:                    ServiceContext serviceContext = serviceGroupContext
125:                            .getServiceContext(axisService);
126:                    AxisService service = serviceContext.getAxisService();
127:                    ClassLoader classLoader = service.getClassLoader();
128:                    Parameter implInfoParam = service
129:                            .getParameter(Constants.SERVICE_CLASS);
130:                    if (implInfoParam != null) {
131:                        try {
132:                            Class implClass = Loader.loadClass(classLoader,
133:                                    ((String) implInfoParam.getValue()).trim());
134:                            Object serviceImpl = implClass.newInstance();
135:                            serviceContext.setProperty(
136:                                    ServiceContext.SERVICE_OBJECT, serviceImpl);
137:                            initServiceObject(serviceImpl, serviceContext);
138:                        } catch (Exception e) {
139:                            AxisFault.makeFault(e);
140:                        }
141:                    }
142:                }
143:            }
144:
145:            /**
146:             * Notify a service object that it's on death row.
147:             * @param serviceContext the active ServiceContext
148:             */
149:            public static void destroyServiceObject(
150:                    ServiceContext serviceContext) {
151:                Object obj = serviceContext
152:                        .getProperty(ServiceContext.SERVICE_OBJECT);
153:                if (obj != null) {
154:                    // If this is a Lifecycle object, just call it.
155:                    if (obj instanceof  Lifecycle) {
156:                        ((Lifecycle) obj).destroy(serviceContext);
157:                        return;
158:                    }
159:
160:                    // For now, we also use "raw" introspection to try and find the destroy method.
161:
162:                    Class classToLoad = obj.getClass();
163:                    Method method = null;
164:                    try {
165:                        method = classToLoad.getMethod(SERVICE_DESTROY_METHOD,
166:                                new Class[] { ServiceContext.class });
167:                    } catch (NoSuchMethodException e) {
168:                        //We do not need to inform this to user , since this something
169:                        // Axis2 is checking to support Session. So if the method is
170:                        // not there we should ignore that
171:                    }
172:
173:                    if (method != null) {
174:                        try {
175:                            method.invoke(obj, new Object[] { serviceContext });
176:                        } catch (IllegalAccessException e) {
177:                            log.info("Exception trying to call "
178:                                    + SERVICE_DESTROY_METHOD, e);
179:                        } catch (InvocationTargetException e) {
180:                            log.info("Exception trying to call "
181:                                    + SERVICE_DESTROY_METHOD, e);
182:                        }
183:                    }
184:
185:                }
186:            }
187:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.