325N/A/*
325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.xml.internal.ws.server;
325N/A
325N/Aimport com.sun.xml.internal.ws.api.server.InstanceResolver;
325N/Aimport com.sun.xml.internal.ws.api.server.ResourceInjector;
325N/Aimport com.sun.xml.internal.ws.api.server.WSEndpoint;
325N/Aimport com.sun.xml.internal.ws.api.server.WSWebServiceContext;
325N/A
325N/Aimport javax.annotation.PostConstruct;
325N/Aimport javax.annotation.PreDestroy;
325N/Aimport java.lang.reflect.Method;
325N/A
325N/A/**
325N/A * Partial implementation of {@link InstanceResolver} with code
325N/A * to handle multiple instances per server.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic abstract class AbstractMultiInstanceResolver<T> extends AbstractInstanceResolver<T> {
325N/A protected final Class<T> clazz;
325N/A
325N/A // fields for resource injection.
325N/A private /*almost final*/ WSWebServiceContext webServiceContext;
325N/A protected /*almost final*/ WSEndpoint owner;
325N/A private final Method postConstructMethod;
325N/A private final Method preDestroyMethod;
325N/A private /*almost final*/ ResourceInjector resourceInjector;
325N/A
325N/A public AbstractMultiInstanceResolver(Class<T> clazz) {
325N/A this.clazz = clazz;
325N/A
325N/A postConstructMethod = findAnnotatedMethod(clazz, PostConstruct.class);
325N/A preDestroyMethod = findAnnotatedMethod(clazz, PreDestroy.class);
325N/A }
325N/A
325N/A /**
325N/A * Perform resource injection on the given instance.
325N/A */
325N/A protected final void prepare(T t) {
325N/A // we can only start creating new instances after the start method is invoked.
325N/A assert webServiceContext!=null;
325N/A
325N/A resourceInjector.inject(webServiceContext,t);
325N/A invokeMethod(postConstructMethod,t);
325N/A }
325N/A
325N/A /**
325N/A * Creates a new instance via the default constructor.
325N/A */
325N/A protected final T create() {
325N/A T t = createNewInstance(clazz);
325N/A prepare(t);
325N/A return t;
325N/A }
325N/A
325N/A @Override
325N/A public void start(WSWebServiceContext wsc, WSEndpoint endpoint) {
325N/A resourceInjector = getResourceInjector(endpoint);
325N/A this.webServiceContext = wsc;
325N/A this.owner = endpoint;
325N/A }
325N/A
325N/A protected final void dispose(T instance) {
325N/A invokeMethod(preDestroyMethod,instance);
325N/A }
325N/A}