
com.addc.jndi.urls.UrlName Maven / Gradle / Ivy
package com.addc.jndi.urls;
import java.util.Enumeration;
import java.util.Vector;
import javax.naming.InvalidNameException;
import javax.naming.Name;
/**
* The UrlName supplies a {@link Name} that contains a URL string.
*/
public class UrlName implements Name {
private static final long serialVersionUID= 3629269921266332407L;
private final String url;
/**
* Create new UrlName
*
* @param url
* The URL to wrap
*/
public UrlName(String url) {
this.url= url;
}
@Override
public int compareTo(Object obj) {
return url.compareTo(((UrlName) obj).url);
}
@Override
public int size() {
return 1;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
@SuppressWarnings("PMD.UseArrayListInsteadOfVector")
public Enumeration getAll() {
Vector v= new Vector<>();
v.add(url);
return v.elements();
}
@Override
public String get(int posn) {
if (posn != 0) {
throw new ArrayIndexOutOfBoundsException(posn + " out of bounds can only be 0");
}
return url;
}
@Override
public Name getPrefix(int posn) {
if (posn != 0) {
throw new ArrayIndexOutOfBoundsException(posn + " out of bounds can only be 0");
}
return this;
}
@Override
public Name getSuffix(int posn) {
if (posn != 0) {
throw new ArrayIndexOutOfBoundsException(posn + " out of bounds can only be 0");
}
return this;
}
@Override
public boolean startsWith(Name n) {
if (n.size() == 1) {
return url.equals(n.toString());
}
return false;
}
@Override
public boolean endsWith(Name n) {
if (n.size() == 1) {
return url.equals(n.toString());
}
return false;
}
@Override
public Name addAll(Name suffix) throws InvalidNameException {
throw new InvalidNameException("UrlName does not support adding components");
}
@Override
public Name addAll(int posn, Name n) throws InvalidNameException {
throw new InvalidNameException("UrlName does not support adding components");
}
@Override
public Name add(String comp) throws InvalidNameException {
throw new InvalidNameException("UrlName does not support adding components");
}
@Override
public Name add(int posn, String comp) throws InvalidNameException {
throw new InvalidNameException("UrlName does not support adding components");
}
@Override
public Object remove(int posn) throws InvalidNameException {
throw new InvalidNameException("UrlName does not support removing components");
}
@Override
@SuppressWarnings({ "PMD.ProperCloneImplementation", "PMD.CloneMethodReturnTypeMustMatchClassName",
"PMD.CloneThrowsCloneNotSupportedException" })
public Object clone() {
return new UrlName(url);
}
@Override
public String toString() {
return url;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy