KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > webservice > JAXWSRuntimeEpiRegistry


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;
24
25 import com.sun.logging.LogDomains;
26 import com.sun.xml.ws.spi.runtime.RuntimeEndpointInfo;
27 import java.util.ArrayList JavaDoc;
28 import java.util.HashMap JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31 import java.util.Map JavaDoc;
32 import java.util.logging.Level JavaDoc;
33 import java.util.logging.Logger JavaDoc;
34 import com.sun.enterprise.util.i18n.StringManager;
35
36 /**
37  * Registry of JAXWS RuntimeEndpointInfo of endpoints.
38  * @author Manisha Umbarje
39  */

40 public class JAXWSRuntimeEpiRegistry {
41     
42     private static JAXWSRuntimeEpiRegistry registry = null;
43     
44     //Mapping of of ContextRoot to RuntimeEndpointInfo for all URLs within contextRoot
45
private Map JavaDoc store;
46     Logger JavaDoc logger = LogDomains.getLogger(LogDomains.WEB_LOGGER);
47     private static StringManager localStrings =
48         StringManager.getManager(JAXWSRuntimeEpiRegistry.class);
49     
50     /** Creates a new instance of JAXWSServletUtil */
51     private JAXWSRuntimeEpiRegistry() {
52         store = new HashMap JavaDoc();
53     }
54     
55     public static JAXWSRuntimeEpiRegistry getInstance() {
56         if(registry == null)
57             registry = new JAXWSRuntimeEpiRegistry();
58         return registry;
59     }
60     
61     public void addRuntimeEndpointInfo(String JavaDoc contextRoot, String JavaDoc urlPattern,
62             RuntimeEndpointInfo info) {
63         if (contextRoot == null)
64             contextRoot = "";
65         
66         ContextRuntimeEndpointInfo contextRtInfo =
67                 (ContextRuntimeEndpointInfo)store.get(contextRoot);
68         
69         if(contextRtInfo == null) {
70             contextRtInfo = new ContextRuntimeEndpointInfo(contextRoot);
71         }
72         
73         contextRtInfo.addRuntimeEndpointInfo(urlPattern, info);
74         store.put(contextRoot, contextRtInfo);
75     }
76     
77      public RuntimeEndpointInfo getRuntimeEndpointInfo(String JavaDoc contextRoot,
78              String JavaDoc path, String JavaDoc urlPattern ) {
79          ContextRuntimeEndpointInfo serviceInfo =
80                 (ContextRuntimeEndpointInfo)store.get(contextRoot);
81         
82         if(serviceInfo == null)
83              return null;
84         
85          return serviceInfo.getRuntimeEndpointInfo(path, urlPattern);
86      }
87   
88      public void removeRuntimeInfo(String JavaDoc contextRoot) {
89          if(contextRoot == null)
90              contextRoot = "";
91          
92          ContextRuntimeEndpointInfo serviceInfo =
93                 (ContextRuntimeEndpointInfo)store.get(contextRoot);
94         
95         if(serviceInfo == null)
96              return ;
97         
98         store.remove(contextRoot);
99      }
100     class ContextRuntimeEndpointInfo {
101         String JavaDoc contextRoot;
102         Map JavaDoc fixedUrlPatternEndpoints;
103         List JavaDoc<RuntimeEndpointInfo> pathUrlPatternEndpoints;
104
105         ContextRuntimeEndpointInfo(String JavaDoc contextRoot) {
106             this.contextRoot = contextRoot;
107             fixedUrlPatternEndpoints = new HashMap JavaDoc();
108             pathUrlPatternEndpoints = new ArrayList JavaDoc();
109         }
110
111         void addRuntimeEndpointInfo(String JavaDoc urlPattern, RuntimeEndpointInfo info) {
112             if (urlPattern.indexOf("*.") != -1) {
113                 // cannot deal with implicit mapping right now
114
logger.log(Level.SEVERE,
115                         localStrings.getString("enterprise.webservice.implicitMappingNotSupported"));
116             } else if (urlPattern.endsWith("/*")) {
117                 pathUrlPatternEndpoints.add(info);
118             } else {
119                 if (fixedUrlPatternEndpoints.containsKey(urlPattern)) {
120                     logger.log(Level.SEVERE,
121                             localStrings.getString("enterprise.webservice.duplicateService",
122                             new Object JavaDoc[]{urlPattern}));
123                 }
124                 fixedUrlPatternEndpoints.put(urlPattern, info);
125             }
126         }
127
128         RuntimeEndpointInfo getRuntimeEndpointInfo(String JavaDoc path, String JavaDoc urlPattern) {
129             RuntimeEndpointInfo result = (RuntimeEndpointInfo) fixedUrlPatternEndpoints.get(path);
130             if (result == null) {
131                 
132                 // This loop is unnecessary.Essentially what it is doing to always
133
// return the first element from pathUrlPatternEndpoints
134
// TO DO clean up after SCF required
135
for (Iterator JavaDoc iter = pathUrlPatternEndpoints.iterator(); iter.hasNext();) {
136                     RuntimeEndpointInfo candidate = (RuntimeEndpointInfo) iter.next();
137                     if (path.startsWith(getValidPathForEndpoint(urlPattern))) {
138                         result = candidate;
139                         break;
140                     }
141                 }
142             }
143             return result;
144         }
145
146          private String JavaDoc getValidPathForEndpoint(String JavaDoc s) {
147             if (s.endsWith("/*")) {
148                 return s.substring(0, s.length() - 2);
149             } else {
150                 return s;
151             }
152         }
153     }
154 }
Popular Tags