01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.jaxws.handler.lifecycle.impl;
20:
21: import javax.xml.ws.handler.Handler;
22:
23: import org.apache.axis2.jaxws.ExceptionFactory;
24: import org.apache.axis2.jaxws.core.MessageContext;
25: import org.apache.axis2.jaxws.description.ServiceDescription;
26: import org.apache.axis2.jaxws.handler.lifecycle.factory.HandlerLifecycleManager;
27: import org.apache.axis2.jaxws.injection.ResourceInjectionException;
28: import org.apache.axis2.jaxws.lifecycle.BaseLifecycleManager;
29: import org.apache.axis2.jaxws.lifecycle.LifecycleException;
30: import org.apache.axis2.jaxws.runtime.description.injection.ResourceInjectionServiceRuntimeDescription;
31: import org.apache.axis2.jaxws.runtime.description.injection.ResourceInjectionServiceRuntimeDescriptionFactory;
32:
33: public class HandlerLifecycleManagerImpl extends BaseLifecycleManager
34: implements HandlerLifecycleManager {
35:
36: public Handler createHandlerInstance(MessageContext mc,
37: Class handlerClass) throws LifecycleException,
38: ResourceInjectionException {
39: if (handlerClass == null) {
40: throw ExceptionFactory
41: .makeWebServiceException("Handler class must be passed");
42: }
43:
44: ServiceDescription serviceDesc = mc.getEndpointDescription()
45: .getServiceDescription();
46: ResourceInjectionServiceRuntimeDescription injectionDesc = null;
47: if (serviceDesc != null) {
48: injectionDesc = ResourceInjectionServiceRuntimeDescriptionFactory
49: .get(serviceDesc, handlerClass);
50: }
51:
52: try {
53: this .instance = handlerClass.newInstance();
54: } catch (InstantiationException e) {
55: throw ExceptionFactory.makeWebServiceException(e);
56: } catch (IllegalAccessException e) {
57: throw ExceptionFactory.makeWebServiceException(e);
58: }
59:
60: //Invoke PostConstruct
61: if (injectionDesc != null
62: && injectionDesc.getPostConstructMethod() != null) {
63: invokePostConstruct(injectionDesc.getPostConstructMethod());
64: }
65:
66: return (Handler) this.instance;
67: }
68:
69: }
|