001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api.server;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.message.Packet;
041:
042: import javax.xml.ws.Provider;
043: import javax.xml.ws.WebServiceContext;
044: import java.lang.reflect.InvocationTargetException;
045: import java.lang.reflect.Method;
046:
047: /**
048: * Hides the detail of calling into application endpoint implementation.
049: *
050: * <p>
051: * Typical host of the JAX-WS RI would want to use
052: * {@link InstanceResolver#createDefault(Class)} and then
053: * use <tt>{@link InstanceResolver#createInvoker()} to obtain
054: * the default invoker implementation.
055: *
056: *
057: * @author Jitendra Kotamraju
058: * @author Kohsuke Kawaguchi
059: */
060: public abstract class Invoker {
061: /**
062: * Called by {@link WSEndpoint} when it's set up.
063: *
064: * <p>
065: * This is an opportunity for {@link Invoker}
066: * to do a endpoint-specific initialization process.
067: *
068: * @param wsc
069: * The {@link WebServiceContext} instance that can be injected
070: * to the user instances.
071: * @param endpoint
072: */
073: public void start(@NotNull
074: WSWebServiceContext wsc, @NotNull
075: WSEndpoint endpoint) {
076: // backward compatibility
077: start(wsc);
078: }
079:
080: /**
081: * @deprecated
082: * Use {@link #start(WSWebServiceContext,WSEndpoint)}
083: */
084: public void start(@NotNull
085: WebServiceContext wsc) {
086: throw new IllegalStateException("deprecated version called");
087: }
088:
089: /**
090: * Called by {@link WSEndpoint}
091: * when {@link WSEndpoint#dispose()} is called.
092: *
093: * This allows {@link InstanceResolver} to do final clean up.
094: *
095: * <p>
096: * This method is guaranteed to be only called once by {@link WSEndpoint}.
097: */
098: public void dispose() {
099: }
100:
101: /**
102: *
103: */
104: public abstract Object invoke(@NotNull
105: Packet p, @NotNull
106: Method m, @NotNull
107: Object... args) throws InvocationTargetException,
108: IllegalAccessException;
109:
110: /**
111: * Invokes {@link Provider#invoke(Object)}
112: */
113: public <T> T invokeProvider(@NotNull
114: Packet p, T arg) throws IllegalAccessException,
115: InvocationTargetException {
116: // default slow implementation that delegates to the other invoke method.
117: return (T) invoke(p, invokeMethod, arg);
118: }
119:
120: /**
121: * Invokes {@link AsyncProvider#invoke(Object, AsyncProviderCallback, WebServiceContext)}
122: */
123: public <T> void invokeAsyncProvider(@NotNull
124: Packet p, T arg, AsyncProviderCallback cbak, WebServiceContext ctxt)
125: throws IllegalAccessException, InvocationTargetException {
126: // default slow implementation that delegates to the other invoke method.
127: invoke(p, asyncInvokeMethod, arg, cbak, ctxt);
128: }
129:
130: private static final Method invokeMethod;
131:
132: static {
133: try {
134: invokeMethod = Provider.class.getMethod("invoke",
135: Object.class);
136: } catch (NoSuchMethodException e) {
137: throw new AssertionError(e);
138: }
139: }
140:
141: private static final Method asyncInvokeMethod;
142:
143: static {
144: try {
145: asyncInvokeMethod = AsyncProvider.class.getMethod("invoke",
146: Object.class, AsyncProviderCallback.class,
147: WebServiceContext.class);
148: } catch (NoSuchMethodException e) {
149: throw new AssertionError(e);
150: }
151: }
152: }
|