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:
20: package org.apache.axis2.jaxws.server.dispatcher;
21:
22: import org.apache.axis2.jaxws.ExceptionFactory;
23: import org.apache.axis2.jaxws.core.MessageContext;
24: import org.apache.axis2.jaxws.i18n.Messages;
25: import org.apache.commons.logging.Log;
26: import org.apache.commons.logging.LogFactory;
27:
28: /**
29: * JavaDispatcher is an abstract class that can be extended to implement an EndpointDispatcher to a
30: * Java object.
31: */
32: public abstract class JavaDispatcher implements EndpointDispatcher {
33:
34: private static final Log log = LogFactory
35: .getLog(JavaDispatcher.class);
36:
37: protected Class serviceImplClass;
38: protected Object serviceInstance;
39:
40: protected JavaDispatcher(Class impl, Object serviceInstance) {
41: this .serviceImplClass = impl;
42: this .serviceInstance = serviceInstance;
43: }
44:
45: public abstract MessageContext invoke(MessageContext mc)
46: throws Exception;
47:
48: public Class getServiceImplementationClass() {
49: return serviceImplClass;
50: }
51:
52: protected Object createServiceInstance() {
53: if (log.isDebugEnabled()) {
54: log.debug("Creating new instance of service endpoint");
55: }
56:
57: if (serviceImplClass == null) {
58: throw ExceptionFactory.makeWebServiceException(Messages
59: .getMessage("JavaDispErr1"));
60: }
61:
62: Object instance = null;
63: try {
64: instance = serviceImplClass.newInstance();
65: } catch (IllegalAccessException e) {
66: throw ExceptionFactory.makeWebServiceException(Messages
67: .getMessage("JavaDispErr2", serviceImplClass
68: .getName()));
69: } catch (InstantiationException e) {
70: throw ExceptionFactory.makeWebServiceException(Messages
71: .getMessage("JavaDispErr2", serviceImplClass
72: .getName()));
73: }
74:
75: return instance;
76: }
77:
78: }
|