try {
type = Type.valueOf(typeName);
} catch (IllegalArgumentException e) {
throw ScriptRuntime.constructError("Error", "Unsupported field type: " + typeName);
}
AttributeTypeBuilder builder = new AttributeTypeBuilder();
builder.setName(name);
builder.setBinding(type.getBinding());
Object descObj = getOptionalMember(config, "description", String.class);
if (descObj != null) {
builder.setDescription((String) descObj);
}
CoordinateReferenceSystem crs = null;
if (config.has("projection", config)) {
Object projObj = config.get("projection", config);
if (projObj instanceof Projection) {
crs = ((Projection) projObj).unwrap();
} else if (projObj instanceof String) {
crs = new Projection(getParentScope(), (String) projObj).unwrap();
} else if (projObj != null){
throw ScriptRuntime.constructError("Error", "Invalid projection object.");
}
}
if (crs != null) {
builder.setCRS(crs);
}
Object minOccursObj = getOptionalMember(config, "minOccurs", Number.class);
int minOccurs = -1;
if (minOccursObj != null) {
minOccurs = ((Number) minOccursObj).intValue();
if (minOccurs < -1) {
throw ScriptRuntime.constructError("Error", "Invalid minOccurs value: " + Context.toString(minOccursObj));
}
builder.setMinOccurs(minOccurs);
}
Object maxOccursObj = getOptionalMember(config, "maxOccurs", Number.class);
int maxOccurs = -1;
if (maxOccursObj instanceof Number) {
maxOccurs = ((Number) maxOccursObj).intValue();
if (maxOccurs < minOccurs || maxOccurs == 0) {
throw ScriptRuntime.constructError("Error", "Invalid maxOccurs value: " + Context.toString(maxOccursObj));
}
builder.setMaxOccurs(maxOccurs);
} else if (minOccurs > -1) {
maxOccurs = minOccurs == 0 ? 1 : minOccurs;
builder.setMaxOccurs(maxOccurs);
}
Object isNillableObj = getOptionalMember(config, "isNillable", Boolean.class);
if (isNillableObj != null) {
builder.setNillable((Boolean) isNillableObj);
}
if (config.has("defaultValue", config)) {
Object defaultValue = config.get("defaultValue", config);
if (defaultValue != null) {
builder.setDefaultValue(jsToJava(defaultValue));
}
}
descriptor = builder.buildDescriptor(name);
}