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: */package org.apache.cxf.jaxws.support;
19:
20: import java.lang.reflect.Field;
21: import java.util.logging.Level;
22: import java.util.logging.Logger;
23:
24: import javax.xml.ws.Service;
25: import javax.xml.ws.WebServiceException;
26:
27: import org.apache.cxf.common.logging.LogUtils;
28: import org.apache.cxf.jaxws.ServiceImpl;
29:
30: /**
31: * A utility that allows access to the 'private' implementation specific delegate
32: * of a Service. Usefull when extensions to the JAXWS Service supported methods
33: * are required.
34: */
35: public final class ServiceDelegateAccessor {
36:
37: private static final Logger LOG = LogUtils
38: .getL7dLogger(ServiceDelegateAccessor.class);
39:
40: private static final String DELEGATE_FIELD_NAME = "delegate";
41:
42: private ServiceDelegateAccessor() {
43: }
44:
45: /**
46: * Get the delegate reference from the Service private field. This method
47: * uses Field.setAccessible() which, in the presence of a SecurityManager,
48: * requires the suppressAccessChecks permission
49: *
50: * @param service the taraget service
51: * @return the implementation delegate
52: * @throws WebServiceException if access to the field fails for any reason
53: */
54: public static ServiceImpl get(Service service) {
55: ServiceImpl delegate = null;
56: try {
57: Field delegateField = Service.class
58: .getDeclaredField(DELEGATE_FIELD_NAME);
59: delegateField.setAccessible(true);
60: delegate = (ServiceImpl) delegateField.get(service);
61: } catch (Exception e) {
62: WebServiceException wse = new WebServiceException(
63: "Failed to access Field named "
64: + DELEGATE_FIELD_NAME
65: + " of Service instance " + service, e);
66: LOG.log(Level.SEVERE, e.getMessage(), e);
67: throw wse;
68: }
69: return delegate;
70: }
71: }
|