package org.xins.common.types.standard;
import org.xins.common.service.DescriptorBuilder;
import org.xins.common.service.GroupDescriptor;
import org.xins.common.service.TargetDescriptor;
import org.xins.common.types.Type;
import org.xins.common.types.TypeValueException;
import org.xins.common.MandatoryArgumentChecker;
public class Descriptor extends Type {
public static final Descriptor SINGLETON = new Descriptor();
private Descriptor() {
super("_descriptor", org.xins.common.service.Descriptor.class);
}
public static org.xins.common.service.Descriptor fromStringForRequired(String string)
throws IllegalArgumentException, TypeValueException {
MandatoryArgumentChecker.check("string", string);
return (org.xins.common.service.Descriptor) SINGLETON.fromString(string);
}
public static org.xins.common.service.Descriptor fromStringForOptional(String string)
throws TypeValueException {
return (org.xins.common.service.Descriptor) SINGLETON.fromString(string);
}
public static String toString(org.xins.common.service.Descriptor value) {
if (value == null) {
return null;
}
return toString(value, "descriptor");
}
private static String toString(org.xins.common.service.Descriptor value, String prefix) {
StringBuffer buffer = new StringBuffer(255);
buffer.append(prefix);
buffer.append("=");
if (value instanceof GroupDescriptor) {
GroupDescriptor group = (GroupDescriptor)value;
org.xins.common.service.Descriptor[] targets = group.getMembers();
buffer.append("group, ");
buffer.append(group.getType().toString());
buffer.append(", ");
for (int i = 0; i < targets.length; i++) {
buffer.append(prefix);
buffer.append(i + 1);
if (i < targets.length - 1) {
buffer.append(", ");
}
}
for (int i = 0; i < targets.length; i++) {
buffer.append('\n');
String targetPrefix = prefix + "." + prefix + i;
buffer.append(toString(targets[i], targetPrefix));
}
} else if (value instanceof TargetDescriptor) {
TargetDescriptor target = (TargetDescriptor)value;
buffer.append("service, ");
buffer.append(target.getURL());
buffer.append(", ");
buffer.append(target.getTotalTimeOut());
buffer.append(", ");
buffer.append(target.getConnectionTimeOut());
buffer.append(", ");
buffer.append(target.getSocketTimeOut());
}
return buffer.toString();
}
protected final boolean isValidValueImpl(String string) {
if (string == null) {
return false;
}
try {
DescriptorBuilder.build(string);
return true;
} catch (Exception ex) {
return false;
}
}
protected final Object fromStringImpl(String string)
throws TypeValueException {
try {
return DescriptorBuilder.build(string);
} catch (Exception ex) {
throw new TypeValueException(SINGLETON, string);
}
}
public final String toString(Object value)
throws IllegalArgumentException, ClassCastException, TypeValueException {
MandatoryArgumentChecker.check("value", value);
return toString((org.xins.common.service.Descriptor) value);
}
public String getDescription() {
return "A XINS descriptor. It can be a single service descriptor or a group descriptor.";
}
}