📄 endpointaddress.java
字号:
if (null != cachedToString) { result = cachedToString.get(); if (null != result) { return result; } } StringBuilder newResult = new StringBuilder(protocol.length() + protocolAddress.length() + 64); newResult.append(protocol); if (hierarchical) { newResult.append("://"); } else { newResult.append(':'); } newResult.append(protocolAddress); if (null != service) { if (hierarchical) { newResult.append('/'); } else { newResult.append('#'); } newResult.append(service); if (null != serviceParam) { newResult.append('/'); newResult.append(serviceParam); } } result = newResult.toString(); cachedToString = new SoftReference<String>(result); return result; } /** * Return a URI which represents the endpoint address. * * @return a URI which represents the endpoint address. */ public URI toURI() { return URI.create(toString()); } /** * Return a String that contains the name of the protocol * contained in the EndpointAddress * * @return a String containing the protocol name */ public String getProtocolName() { return protocol; } /** * Return a String that contains the protocol address contained * in the EndpointAddress * * @return a String containing the protocol address */ public String getProtocolAddress() { return protocolAddress; } /** * Return a String that contains the service name contained in * the EndpointAddress * * @return a String containing the service name */ public String getServiceName() { return service; } /** * Return a String that contains the service parameter contained * in the EndpointAddress * * @return a String containing the protocol name */ public String getServiceParameter() { return serviceParam; } /** * Set the protocol name. * * @param name String containing the name of the protocol */ private void setProtocolName(String name) { if ((null == name) || (0 == name.length())) { throw new IllegalArgumentException("name must be non-null and contain at least one character"); } if (-1 != name.indexOf("/")) { throw new IllegalArgumentException("name may not contain '/' character"); } // XXX 20070207 bondolo We explicitly force all use of either "jxta" or "urn:jxta" to our prefered form. if (IDS_USE_JXTA_URL_FORM) { if (JXTA_ID_PROTOCOL.equals(name)) { name = "jxta"; } } else { if ("jxta".equals(name)) { name = JXTA_ID_PROTOCOL; } } int colonAt = name.indexOf(':'); if (-1 == colonAt) { hierarchical = true; } else { if (!"urn".equalsIgnoreCase(name.substring(0, colonAt))) { throw new IllegalArgumentException("Only urn may contain colon"); } if (colonAt == (name.length() - 1)) { throw new IllegalArgumentException("empty urn namespace!"); } hierarchical = false; } protocol = name; cachedToString = null; } /** * Set the protocol address. * * @param address String containing the peer address. */ private void setProtocolAddress(String address) { if ((null == address) || (0 == address.length())) { throw new IllegalArgumentException("address must be non-null and contain at least one character"); } if (-1 != address.indexOf("/")) { throw new IllegalArgumentException("address may not contain '/' character"); } protocolAddress = address; cachedToString = null; } /** * Set the service name. * * @param name String containing the name of the destination service */ private void setServiceName(String name) { if (null != name) { if (-1 != name.indexOf("/")) { throw new IllegalArgumentException("service name may not contain '/' character"); } } service = name; cachedToString = null; } /** * Set the service parameter * * @param param String containing the service parameter */ private void setServiceParameter(String param) { serviceParam = param; cachedToString = null; } /** * Parse any EndpointAddress from a URI * * @param addr endpoint address to parse */ private void parseURI(String addr) { int index = addr.indexOf("://"); if (index == -1) { parseURN(addr); } else { parseURL(addr); } } /** * Parse an EndpointAddress from a URN * * @param addr endpoint address to parse */ private void parseURN(String addr) { int protocolEnd = addr.indexOf(':'); if (-1 == protocolEnd) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address is not a valid URI: " + addr); } throw new IllegalArgumentException("Address is not a valid URI: " + addr); } if (!"urn".equalsIgnoreCase(addr.substring(0, protocolEnd))) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address is unrecognized URI form: " + addr); } throw new IllegalArgumentException("Address is unrecognized URI form: " + addr); } if ((addr.length() - 1) == protocolEnd) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address URN does not have a namespace: " + addr); } throw new IllegalArgumentException("Address URN does not have a namespace: " + addr); } // gather the namespace as well. int namespaceEnd = addr.indexOf(':', protocolEnd + 1); if (-1 == namespaceEnd) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address URN does not have a namespace: " + addr); } throw new IllegalArgumentException("Address URN does not have a namespace: " + addr); } setProtocolName(addr.substring(0, namespaceEnd)); if ((addr.length() - 1) == namespaceEnd) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address URN does not have a NSS portion: " + addr); } throw new IllegalArgumentException("Address URN does not have a NSS portion: " + addr); } // check for service and param int nssEnd = addr.indexOf('#', namespaceEnd + 1); if (-1 == nssEnd) { setProtocolAddress(addr.substring(namespaceEnd + 1)); } else { setProtocolAddress(addr.substring(namespaceEnd + 1, nssEnd)); int serviceEnd = addr.indexOf('/', nssEnd + 1); if (-1 == serviceEnd) { setServiceName(addr.substring(nssEnd + 1)); } else { setServiceName(addr.substring(nssEnd + 1, serviceEnd)); setServiceParameter(addr.substring(serviceEnd + 1)); } } } /** * Parse and EndpointAddress from a URL * * @param addr endpoint address to parse */ private void parseURL(String addr) { String remainder; int index = addr.indexOf("://"); if (index == -1) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Address is not in absolute form: " + addr); } throw new IllegalArgumentException("Address is not in absolute form: " + addr); } if (0 == index) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Protocol is missing: " + addr); } throw new IllegalArgumentException("Protocol is missing: " + addr); } try { setProtocolName(addr.substring(0, index)); remainder = addr.substring(index + 3); } catch (Exception e) { if (Logging.SHOW_FINE && LOG.isLoggable(Level.FINE)) { LOG.fine("Protocol address is missing: " + addr); } throw new IllegalArgumentException("Protocol address is missing: " + addr); } index = remainder.indexOf("/"); if (index == -1) { setProtocolAddress(remainder); return; } setProtocolAddress(remainder.substring(0, index)); remainder = remainder.substring(index + 1); index = remainder.indexOf("/"); if (index == -1) { setServiceName(remainder); return; } setServiceName(remainder.substring(0, index)); remainder = remainder.substring(index + 1); setServiceParameter(remainder); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -