package org.xins.common.types.standard;
import java.net.MalformedURLException;
import org.xins.common.service.TargetDescriptor;
import org.xins.common.types.Type;
import org.xins.common.types.TypeValueException;
import org.xins.common.MandatoryArgumentChecker;
public final class URL extends Type {
public static final URL SINGLETON = new org.xins.common.types.standard.URL();
private URL() {
super("_url", String.class);
}
public static String fromStringForRequired(String string)
throws TypeValueException, IllegalArgumentException {
if (string == null) {
throw new IllegalArgumentException("string == null");
} else if (!SINGLETON.isValidValue(string)) {
throw new TypeValueException(SINGLETON, string);
} else {
return string;
}
}
public static String fromStringForOptional(String string)
throws TypeValueException {
if (!SINGLETON.isValidValue(string)) {
throw new TypeValueException(SINGLETON, string);
} else {
return string;
}
}
protected boolean isValidValueImpl(String value) {
try {
new TargetDescriptor(value);
return true;
} catch (MalformedURLException muex) {
return false;
}
}
protected Object fromStringImpl(String string) throws TypeValueException {
if (!isValidValue(string)) {
throw new TypeValueException(this, string);
}
return string;
}
public String toString(Object value)
throws IllegalArgumentException, ClassCastException, TypeValueException {
MandatoryArgumentChecker.check("value", value);
return (String) value;
}
public String getDescription() {
return "A URL.";
}
}