1 /* 2 Copyright (c) 2006, University of Tromsø 3 All rights reserved. 4 5 Redistribution and use in source and binary forms, with or without 6 modification, are permitted provided that the following conditions are met: 7 8 * Redistributions of source code must retain the above copyright notice, this list 9 of conditions and the following disclaimer. 10 11 * Redistributions in binary form must reproduce the above copyright notice, this 12 list of conditions and the following disclaimer in the documentation and/or other 13 materials provided with the distribution. 14 15 * Neither the name of the University of Tromsø nor the names of its contributors may 16 be used to endorse or promote products derived from this software without specific 17 prior written permission. 18 19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 22 SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 24 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 DAMAGE. 29 */ 30 31 package axis.dynamic; 32 33 import javax.xml.rpc.holders.IntHolder; 34 35 import org.apache.axis.Handler; 36 import org.apache.axis.MessageContext; 37 import org.apache.axis.constants.Scope; 38 import org.apache.axis.description.JavaServiceDesc; 39 import org.apache.axis.handlers.soap.SOAPService; 40 import org.apache.axis.providers.java.JavaProvider; 41 import org.apache.axis.providers.java.RPCProvider; 42 43 /** 44 * Variant of the {@link JavaProvider}s, that does not create the service object but always uses the same instance. 45 * 46 * All the methods overridden here are defined in {@link JavaProvider} and are only used in that class. 47 * {@link JavaProvider} calls {@link #getServiceObject} and passes the object to {@link RPCProvider#processMessage}. 48 */ 49 @SuppressWarnings("serial") // we don't want to serialize this thing 50 public class ObjectRPCProvider extends RPCProvider 51 { 52 /** */ 53 private final Object _target; 54 55 /** */ 56 private final Class<?> _class; 57 58 /** 59 * uses target.getClass as class. 60 * @param target 61 */ 62 public ObjectRPCProvider( Object target ) 63 { 64 this(target, target.getClass()); 65 } 66 67 /** 68 * @param target 69 * @param cls class used to find methods etc. 70 */ 71 public ObjectRPCProvider( Object target, Class<?> cls ) 72 { 73 if (target == null) throw new NullPointerException("target"); 74 if (cls == null) throw new NullPointerException("class"); 75 _target = target; 76 _class = cls; 77 } 78 79 /** 80 * @return service class 81 */ 82 private Class<?> getServiceClass() 83 { 84 return _class; 85 } 86 87 /** 88 * called only from {@link JavaProvider#initServiceDesc}, but we override that, so it's never called. 89 * @param clsName 90 * @param service 91 * @param msgContext 92 * @return class set in {@link #ObjectRPCProvider(Object, Class) constructor}. 93 * @see JavaProvider#getServiceClass(String, SOAPService, MessageContext) 94 */ 95 @Override 96 protected Class<?> getServiceClass( String clsName, SOAPService service, MessageContext msgContext ) 97 { 98 return getServiceClass(); 99 } 100 101 /** 102 * called from {@link JavaProvider#invoke}, and from {@link JavaProvider#initServiceDesc} (but we override that here). 103 * @param service 104 * @return name of class set in {@link #ObjectRPCProvider(Object, Class) constructor}. 105 * @see JavaProvider#getServiceClassName(Handler) 106 */ 107 @Override 108 protected String getServiceClassName( Handler service ) 109 { 110 return getServiceClass().getName(); 111 } 112 113 /** 114 * called from {@link JavaProvider#getServiceClassName} (but we override that here), and from 115 * {@link JavaProvider#invoke} if {@link #getServiceClassName} returns null or "" (and that can't happen). 116 * @return null 117 * @see JavaProvider#getServiceClassNameOptionName() 118 */ 119 @Override 120 protected String getServiceClassNameOptionName() 121 { 122 return null; 123 } 124 125 /** 126 * called from {@link JavaProvider#invoke} 127 * @param msgContext ignored 128 * @param service ignored 129 * @param clsName ignored 130 * @param scopeHolder we set the scope to {@link Scope#APPLICATION} 131 * @return target object set in {@link #ObjectRPCProvider(Object, Class) constructor}. 132 * @see JavaProvider#invoke 133 */ 134 @Override 135 public Object getServiceObject( MessageContext msgContext, Handler service, String clsName, IntHolder scopeHolder ) 136 { 137 // tell java provider that there's never any need to destroy this object 138 scopeHolder.value = Scope.APPLICATION.getValue(); 139 return _target; 140 } 141 142 /** 143 * Called from {@link SOAPService#getInitializedServiceDesc}, which in turn is called from many places. 144 * We do not strictly have to override the implementation in JavaProvider, but it's safer this way, because 145 * we <b>must</b> make sure that this method can be invoked with a <tt>null</tt> {@link MessageContext}. 146 * It is (indirectly) called with a <tt>null</tt> parameter in {@link SoapReceiver#createService}. 147 * The current implementation of {@link JavaProvider#initServiceDesc} only passes on the parameter to 148 * {@link JavaProvider#getServiceClass}, which in our cases ignores it as well. The current implementation of 149 * {@link JavaProvider#getServiceClass} explicitly tolerates a null value. 150 * @param service 151 * @param msgContext ignored 152 * @see JavaProvider#initServiceDesc 153 * @see JavaProvider#getServiceClass 154 * @see SoapReceiver#createService 155 */ 156 @Override 157 public void initServiceDesc( SOAPService service, MessageContext msgContext ) 158 { 159 ((JavaServiceDesc)service.getServiceDescription()).loadServiceDescByIntrospection(_target.getClass()); 160 } 161 162 163 } 164