KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > spi > DefaultServiceDelegateFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.webservice.spi;
24
25 import java.util.ArrayList JavaDoc;
26 import java.util.logging.Level JavaDoc;
27
28 import javax.xml.ws.spi.ServiceDelegate;
29
30 import com.sun.enterprise.webservice.WsUtil;
31 import com.sun.enterprise.webservice.ServiceCreationListenerImpl;
32
33
34 /**
35  * DefaultServiceDelegateFactory is the factory used by our Provider implementation
36  * to create a ServiceDelegate instance. This also defines the ability to plug
37  * another ServiceDelegateFactory if necessary as well as providing hooks to
38  * register ServiceCreationListener listeners.
39  *
40  * @author Jerome Dochez
41  */

42 public class DefaultServiceDelegateFactory implements ServiceDelegateFactory {
43     
44     static ServiceDelegateFactory factory;
45     ArrayList JavaDoc<ServiceDelegateCreationListener> listeners = new ArrayList JavaDoc();
46     
47     /**
48      * Resets the current ServiceDelegateFactory instance responsible for
49      * creating ServiceDelegate instances
50      * @param ServiceDelegateFactory the instance
51      */

52     public static void setFactory(ServiceDelegateFactory f) {
53         factory = f;
54     }
55     
56     /**
57      * @return the current ServiceDelegateFactory instance
58      */

59     public static ServiceDelegateFactory getFactory() {
60         if (factory==null) {
61             synchronized(DefaultServiceDelegateFactory.class) {
62                 if (factory==null) {
63                     factory= new DefaultServiceDelegateFactory();
64                 }
65             }
66         }
67         return factory;
68     }
69     
70     /** Creates a new instance of DefaultServiceDelegateFactory */
71     protected DefaultServiceDelegateFactory() {
72         // add our unique listener instance
73
addListener(ServiceCreationListenerImpl.getDefaultListener());
74     }
75     
76     /**
77      * Creates a new ServiceDelegate instance using a delegation instance
78      * @param the delegate
79      * @return the new ServiceDelegate.
80      */

81     public ServiceDelegate create(ServiceDelegate delegate) {
82         ServiceDelegateImpl ourServiceDelegate = new ServiceDelegateImpl(delegate);
83         serviceCreated(ourServiceDelegate);
84         return ourServiceDelegate;
85     }
86     
87     /**
88      * Add a listener for ServiceDelegate creation
89      * @param listener implementation
90      */

91     public void addListener(ServiceDelegateCreationListener listener) {
92         listeners.add(listener);
93     }
94     
95     // ServiceDelegate creation notification
96
private void serviceCreated(ServiceDelegateImpl delegate) {
97         for (ServiceDelegateCreationListener listener : listeners) {
98              try {
99                 listener.serviceCreated(delegate);
100              } catch(Throwable JavaDoc t) {
101                  WsUtil.getDefaultLogger().severe("Exception "
102                          + t.getMessage() + " in serviceDelegateCreationListener : " + listener);
103                  WsUtil.getDefaultLogger().log(Level.FINE, t.getMessage(), t);
104              }
105         }
106     }
107 }
108
Popular Tags