Home » openejb-3.1.2-src » org.apache » openejb » server » webservices » saaj » [javadoc | source]

    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     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    */
   17   package org.apache.openejb.server.webservices.saaj;
   18   
   19   import java.lang.reflect.InvocationTargetException;
   20   import java.lang.reflect.Method;
   21   
   22   import javax.xml.soap.MessageFactory;
   23   import javax.xml.soap.SAAJMetaFactory;
   24   import javax.xml.soap.SOAPException;
   25   import javax.xml.soap.SOAPFactory;
   26   
   27   public class SaajMetaFactoryImpl extends SAAJMetaFactory {
   28   
   29       protected MessageFactory newMessageFactory(String arg0) throws SOAPException {
   30           return (MessageFactory)callFactoryMethod("newMessageFactory", arg0);
   31       }
   32   
   33       protected SOAPFactory newSOAPFactory(String arg0) throws SOAPException {
   34           return (SOAPFactory)callFactoryMethod("newSOAPFactory", arg0);
   35       }
   36   
   37       private Object callFactoryMethod(String methodName, String arg) throws SOAPException {
   38           SAAJMetaFactory factory = 
   39               (SAAJMetaFactory) SaajFactoryFinder.find("javax.xml.soap.MetaFactory");
   40   
   41           try {
   42               Method method = 
   43                   factory.getClass().getDeclaredMethod(methodName, new Class[] { String.class });
   44               boolean accessibility = method.isAccessible();
   45               try {
   46                   method.setAccessible(true);
   47                   Object result = method.invoke(factory, new Object[] { arg });                
   48                   return result;
   49               } catch (InvocationTargetException e) {
   50                   if (e.getTargetException() instanceof SOAPException) {
   51                       throw (SOAPException) e.getTargetException();
   52                   } else {
   53                       throw new SOAPException("Error calling factory method: " + methodName, e);
   54                   }
   55               } catch (IllegalArgumentException e) {
   56                   throw new SOAPException("Error calling factory method: " + methodName, e);
   57               } catch (IllegalAccessException e) {
   58                   throw new SOAPException("Error calling factory method: " + methodName, e);
   59               } finally {
   60                   method.setAccessible(accessibility);
   61               }
   62           } catch (NoSuchMethodException e) {
   63               throw new SOAPException("Factory method not found: " + methodName, e);
   64           }
   65       }
   66   
   67   }

Home » openejb-3.1.2-src » org.apache » openejb » server » webservices » saaj » [javadoc | source]