KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.admin.wsmgmt.config.spi.Constants;
26 import com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule;
27 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter;
28 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterContext;
29
30 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig;
31
32 import java.util.concurrent.locks.ReentrantReadWriteLock JavaDoc;
33 import java.util.concurrent.locks.Lock JavaDoc;
34
35 import java.util.logging.Logger JavaDoc;
36 import java.util.logging.Level JavaDoc;
37 import com.sun.logging.LogDomains;
38 import com.sun.enterprise.util.i18n.StringManager;
39
40
41
42 /**
43  * Filter that can implement XSLT transformations.
44  */

45 public class TransformFilter implements Filter {
46
47     /**
48      * Public Constructor.
49      *
50      * @param appId name of the application
51      * @param endpoint end point name for which stats are collected
52      */

53     public TransformFilter(String JavaDoc appId, String JavaDoc endpoint) {
54         _applicationId = appId;
55         _endpointId = endpoint;
56         _rwl = new ReentrantReadWriteLock JavaDoc();
57         _readLock = _rwl.readLock();
58         _writeLock = _rwl.writeLock();
59     }
60
61     /**
62      * Public Constructor.
63      *
64      * @param appId name of the application
65      * @param endpoint end point name for which stats are collected
66      */

67     public TransformFilter(String JavaDoc appId, WebServiceConfig wsc)
68         throws TransformException {
69         _applicationId = appId;
70         _endpointId = wsc.getName();
71         TransformationRule[] reqRules = wsc.getRequestTransformationRule();
72         if ( reqRules != null) {
73             reqChain = new FilterChain();
74             reqChain.addFilter(reqRules, false);
75         } else {
76             reqChain = null;
77         }
78         TransformationRule[] resRules = wsc.getResponseTransformationRule();
79         if (resRules != null) {
80             resChain = new FilterChain();
81             resChain.addFilter(resRules, true);
82         } else {
83             resChain = null;
84         }
85         _rwl = new ReentrantReadWriteLock JavaDoc();
86         _readLock = _rwl.readLock();
87         _writeLock = _rwl.writeLock();
88     }
89
90     // XXX optimize these resetXXXChain, rather than creating the new chain
91
// modify the existing RequestChain.
92

93     public void resetRequestChain(TransformationRule[] tRules) throws
94     TransformException {
95         _writeLock.lock();
96         try {
97             reqChain = new FilterChain();
98             reqChain.addFilter(tRules, false);
99         } finally {
100            _writeLock.unlock();
101         }
102     }
103
104     public void resetResponseChain(TransformationRule[] tRules) throws
105     TransformException {
106         _writeLock.lock();
107         try {
108             resChain = new FilterChain();
109             resChain.addFilter(tRules, true);
110         } finally {
111            _writeLock.unlock();
112         }
113     }
114
115     /**
116      * Returns the unique name for this filter
117      */

118     public String JavaDoc getName() {
119         return (NAME_PREFIX + _applicationId + DELIM + _endpointId);
120     }
121
122     /**
123      * Returns the unique name for this filter
124      */

125     static public String JavaDoc getName(String JavaDoc appId, WebServiceConfig wsc) {
126         return (NAME_PREFIX + appId + DELIM + wsc.getName());
127     }
128
129     /**
130      * Invoke the filter.
131      *
132      * @param stage stage of the execution
133      * @param endpoint name of the endpoint
134      * @param context filter context
135      */

136     public void process(String JavaDoc stage, String JavaDoc endpoint, FilterContext context) {
137
138         _readLock.lock();
139         try {
140             // SOAP request
141
if ( stage.equals(Filter.PROCESS_REQUEST) ) {
142                 // optmize this XXX
143
if ( reqChain != null) {
144                         reqChain.process(context);
145                 }
146             // SOAP response
147
} else if ( stage.equals(Filter.PROCESS_RESPONSE) ) {
148                 if ( resChain != null) {
149                         resChain.process(context);
150                 }
151             }
152         } catch(Exception JavaDoc e) {
153             // log a warning
154
String JavaDoc msg = _stringMgr.getString("transform_failed", endpoint);
155             _logger.log(Level.INFO, msg, e);
156         } finally {
157             _readLock.unlock();
158         }
159
160     }
161
162     // -- PRIVATE - VARIABLES -------------------------
163
private String JavaDoc _applicationId = null;
164     private String JavaDoc _endpointId = null;
165     private static final String JavaDoc DELIM = "#";
166     private static final String JavaDoc NAME_PREFIX = "TRANSFORMFILTER_";
167     private FilterChain reqChain = null;
168     private FilterChain resChain = null;
169     private ReentrantReadWriteLock JavaDoc _rwl = null;
170     private Lock JavaDoc _readLock = null;
171     private Lock JavaDoc _writeLock = null;
172     private static final Logger JavaDoc _logger =
173         Logger.getLogger(LogDomains.ADMIN_LOGGER);
174     private static final StringManager _stringMgr =
175         StringManager.getManager(TransformFilter.class);
176
177
178 }
179
Popular Tags