KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > wsmgmt > transform > TransformHandler


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.admin.wsmgmt.transform;
24
25 import java.util.Collection JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants;
30 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigFactory;
31 import com.sun.enterprise.admin.wsmgmt.config.spi.ConfigProvider;
32 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
33 import com.sun.enterprise.admin.wsmgmt.pool.spi.Pool;
34 import com.sun.enterprise.admin.wsmgmt.pool.impl.BoundedPool;
35 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter;
36 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterRegistry;
37 import com.sun.appserv.management.ext.wsmgmt.MessageTrace;
38
39 import java.util.logging.Logger JavaDoc;
40 import java.util.logging.Level JavaDoc;
41 import com.sun.logging.LogDomains;
42 import com.sun.enterprise.util.i18n.StringManager;
43
44 /**
45  * Keeps track of SOAP messages per endpoint.
46  */

47 public class TransformHandler {
48
49     /**
50      * Constructor.
51      *
52      * @param endpoint name of the endpoint
53      */

54     public TransformHandler(WebServiceConfig wsc, String JavaDoc appId) throws
55     TransformException {
56
57         _applicationId = appId;
58         _endpointId = wsc.getName();
59
60     }
61
62     /**
63      * Constructor.
64      *
65      * @param endpoint name of the endpoint
66      */

67     public TransformHandler(String JavaDoc endpoint, String JavaDoc appId) {
68         _applicationId = appId;
69         _endpointId = endpoint;
70
71     }
72
73     /**
74      * Registers a filter with the filter manager for this endpoint.
75      */

76     public Filter registerFilter(WebServiceConfig wsc)
77         throws TransformException {
78
79         _filter = new TransformFilter(_applicationId, wsc);
80         FilterRegistry fr = FilterRegistry.getInstance();
81         String JavaDoc endpoint = getFQEndpointName();
82
83         // registers the filter
84
fr.registerFilter(Filter.PROCESS_REQUEST, endpoint, _filter);
85         fr.registerFilter(Filter.PROCESS_RESPONSE, endpoint, _filter);
86         return _filter;
87     }
88
89     /**
90      * Registers a filter with the filter manager for this endpoint.
91      */

92     private void registerFilter() {
93
94         // msg filter
95
_filter = new TransformFilter(_applicationId, _endpointId);
96         FilterRegistry fr = FilterRegistry.getInstance();
97         String JavaDoc endpoint = getFQEndpointName();
98
99         // registers the filter
100
fr.registerFilter(Filter.PROCESS_REQUEST, endpoint, _filter);
101         fr.registerFilter(Filter.PROCESS_RESPONSE, endpoint, _filter);
102     }
103
104     /**
105      * Disables transformation for the endpoint and deregisters the filters.
106      */

107     void destroy() {
108         if (_filter != null) {
109             FilterRegistry fr = FilterRegistry.getInstance();
110             String JavaDoc endpoint = getFQEndpointName();
111
112             // unregister filters
113
fr.unregisterFilter(Filter.PROCESS_REQUEST, endpoint, _filter);
114             fr.unregisterFilter(Filter.PROCESS_RESPONSE, endpoint, _filter);
115             _filter = null;
116         }
117         _logger.finer("Transform handler destroyed for "
118             + getEndpointName());
119     }
120
121     /**
122      * Disables transformation for the endpoint and deregisters the filters.
123      */

124     void unregisterFilter(String JavaDoc appId, WebServiceConfig wsc) {
125             String JavaDoc fn = TransformFilter.getName(appId, wsc);
126             FilterRegistry fr = FilterRegistry.getInstance();
127             String JavaDoc endpoint = getFQEndpointName(appId, wsc);
128
129             // unregister filters
130
fr.unregisterFilterByName(Filter.PROCESS_REQUEST, endpoint, fn);
131             fr.unregisterFilterByName(Filter.PROCESS_RESPONSE, endpoint, fn);
132         _logger.finer("Transform handler destroyed for "
133             + getEndpointName());
134     }
135
136     /**
137      * Gets the registered filter for transformation.
138      */

139     public Filter getFilter(String JavaDoc appId, WebServiceConfig wsc) {
140             FilterRegistry fr = FilterRegistry.getInstance();
141             String JavaDoc endpoint = getFQEndpointName(appId, wsc);
142
143         _logger.finer("getFilter called for "
144             + getEndpointName());
145            List JavaDoc filterList= fr.getFilters(Filter.PROCESS_REQUEST, endpoint);
146            if ( filterList == null) {
147                 return null;
148            }
149            Iterator JavaDoc filterItr = filterList.iterator();
150            if ( filterItr == null) {
151                 return null;
152            }
153           while ( filterItr.hasNext()) {
154                 Filter f = (Filter) filterItr.next();
155                 if ( f instanceof TransformFilter) {
156                 return f;
157           }
158         }
159         return null;
160     }
161
162     /**
163      * Returns the name of the endpoint.
164      *
165      * @return name of the endpoint
166      */

167     String JavaDoc getEndpointName() {
168         return _endpointId;
169     }
170
171     /**
172      * Returns the fully qualified name of this endpoint.
173      *
174      * @return fully qualified name of this endpoint
175      */

176     String JavaDoc getFQEndpointName() {
177         return _applicationId + DELIM + _endpointId;
178     }
179
180     /**
181      * Returns the fully qualified name of this endpoint.
182      *
183      * @return fully qualified name of this endpoint
184      */

185     String JavaDoc getFQEndpointName(String JavaDoc appId, WebServiceConfig wsc) {
186         return appId + DELIM + wsc.getName();
187     }
188
189     // ---- VARIABLES - PRIVATE ---------------------------------------
190
private TransformFilter _filter = null;
191     private String JavaDoc _endpointId = null;
192     private String JavaDoc _applicationId = null;
193     private static final String JavaDoc DELIM = "#";
194     private static final Logger JavaDoc _logger =
195         Logger.getLogger(LogDomains.ADMIN_LOGGER);
196     private static final StringManager _stringMgr =
197         StringManager.getManager(TransformHandler.class);
198 }
199
Popular Tags