01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.webservices.saaj;
17:
18: import java.lang.reflect.InvocationTargetException;
19: import java.lang.reflect.Method;
20:
21: import javax.xml.soap.MessageFactory;
22: import javax.xml.soap.SAAJMetaFactory;
23: import javax.xml.soap.SOAPException;
24: import javax.xml.soap.SOAPFactory;
25:
26: public class GeronimoMetaFactory extends SAAJMetaFactory {
27:
28: protected MessageFactory newMessageFactory(String arg0)
29: throws SOAPException {
30: return (MessageFactory) callFactoryMethod("newMessageFactory",
31: arg0);
32: }
33:
34: protected SOAPFactory newSOAPFactory(String arg0)
35: throws SOAPException {
36: return (SOAPFactory) callFactoryMethod("newSOAPFactory", arg0);
37: }
38:
39: private Object callFactoryMethod(String methodName, String arg)
40: throws SOAPException {
41: SAAJMetaFactory factory = (SAAJMetaFactory) SAAJFactoryFinder
42: .find("javax.xml.soap.MetaFactory");
43:
44: try {
45: Method method = factory.getClass().getDeclaredMethod(
46: methodName, new Class[] { String.class });
47: boolean accessibility = method.isAccessible();
48: try {
49: method.setAccessible(true);
50: Object result = method.invoke(factory,
51: new Object[] { arg });
52: return result;
53: } catch (InvocationTargetException e) {
54: if (e.getTargetException() instanceof SOAPException) {
55: throw (SOAPException) e.getTargetException();
56: } else {
57: throw new SOAPException(
58: "Error calling factory method: "
59: + methodName, e);
60: }
61: } catch (IllegalArgumentException e) {
62: throw new SOAPException(
63: "Error calling factory method: " + methodName,
64: e);
65: } catch (IllegalAccessException e) {
66: throw new SOAPException(
67: "Error calling factory method: " + methodName,
68: e);
69: } finally {
70: method.setAccessible(accessibility);
71: }
72: } catch (NoSuchMethodException e) {
73: throw new SOAPException("Factory method not found: "
74: + methodName, e);
75: }
76: }
77:
78: }
|