1 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 ; 28 import java.util.HashMap ; 29 import java.util.Iterator ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.logging.Level ; 33 import java.util.logging.Logger ; 34 import com.sun.enterprise.util.i18n.StringManager; 35 36 40 public class JAXWSRuntimeEpiRegistry { 41 42 private static JAXWSRuntimeEpiRegistry registry = null; 43 44 private Map store; 46 Logger logger = LogDomains.getLogger(LogDomains.WEB_LOGGER); 47 private static StringManager localStrings = 48 StringManager.getManager(JAXWSRuntimeEpiRegistry.class); 49 50 51 private JAXWSRuntimeEpiRegistry() { 52 store = new HashMap (); 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 contextRoot, String 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 contextRoot, 78 String path, String 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 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 contextRoot; 102 Map fixedUrlPatternEndpoints; 103 List <RuntimeEndpointInfo> pathUrlPatternEndpoints; 104 105 ContextRuntimeEndpointInfo(String contextRoot) { 106 this.contextRoot = contextRoot; 107 fixedUrlPatternEndpoints = new HashMap (); 108 pathUrlPatternEndpoints = new ArrayList (); 109 } 110 111 void addRuntimeEndpointInfo(String urlPattern, RuntimeEndpointInfo info) { 112 if (urlPattern.indexOf("*.") != -1) { 113 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 []{urlPattern})); 123 } 124 fixedUrlPatternEndpoints.put(urlPattern, info); 125 } 126 } 127 128 RuntimeEndpointInfo getRuntimeEndpointInfo(String path, String urlPattern) { 129 RuntimeEndpointInfo result = (RuntimeEndpointInfo) fixedUrlPatternEndpoints.get(path); 130 if (result == null) { 131 132 for (Iterator 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 getValidPathForEndpoint(String s) { 147 if (s.endsWith("/*")) { 148 return s.substring(0, s.length() - 2); 149 } else { 150 return s; 151 } 152 } 153 } 154 } | Popular Tags |