package lava.net.common; import java.net.InetAddress; /** * UNL: * Description of the logical Name of an Object. * Format is similar to URL. * Scheme-Name is psyc:// * Objects might be Servers, Groups, Users, Services. * Servers: resource=null * Groups: resource begins with '@' * Users: resource begins with '~' * Services: resource begins with '$' * Every Object only can have one UNL. **/ public class UNL extends UNA { /** * **/ private String context = null; /** * **/ private UNL withoutContext = null; /** * **/ private int hashCode = -1; /** * **/ public UNL() { super(); } /** * **/ public UNL(String spec) { super(spec); } /** * **/ public UNL(UNL base, String spec) { super(base,spec); } /** * **/ public UNL(String scheme, String host, int port, String protocol, // String resource) { super(scheme,host,port,protocol,resource); } /** * **/ private UNL(String scheme, String host, int port, String protocol, // String resource, String context, UNL orig) { super(scheme,host,port,protocol,resource); this.context = context; if(orig != null) while(orig.withoutContext != null) orig = orig.withoutContext; withoutContext = orig; } /** * **/ public UNL(String scheme, InetAddress host, int port, String protocol, // String resource) { super(scheme,host,port,protocol,resource); } /** * **/ public UNL(UNA addr) { super(addr.getScheme(),addr.getHostName(),addr.getPort(),// addr.getProtocol(),addr.getResource()); } /** * **/ public UNL addContext(String context) { return new UNL(getScheme(),getHostName(),getPort(),// getProtocol(),getResource(),context,this); } /** * **/ public UNL withoutContext() { return withoutContext != null ? withoutContext : this; } /** * **/ public String getContext() { return context; } /** * **/ public boolean equalsInContext(UNL other) { if(other == null) return false; return (context == null || other.context == null ? // context == null && other.context == null : // context.equals(other.context)); } /** * **/ public boolean equals(Object obj) { return (obj instanceof UNL) && // super.equals(obj) && // equalsInContext((UNL)obj); } /** * **/ public int hashCode() { if(hashCode == -1) { hashCode = super.hashCode() ^ // (context == null ? 0 : context.hashCode()); } return hashCode; } }