schema.put("name", type.getName().getLocalPart() );
schema.put("namespace", type.getName().getNamespaceURI() );
schema.put("simple", type instanceof SimpleFeatureType );
JSONArr attributes = schema.putArray("attributes");
for( PropertyDescriptor d : type.getDescriptors() ){
PropertyType t = d.getType();
final String NAME = d.getName().getLocalPart();
String kind;
if (d instanceof GeometryDescriptor){
kind = "geometry";
}
else if( d instanceof AttributeDescriptor){
kind = "attribute";
}
else if (d instanceof AssociationDescriptor){
kind = "association";
}
else {
kind = "property";
}
JSONObj property = attributes.addObject()
.put("name", NAME )
.put("property", kind )
.put("type", t.getBinding().getSimpleName() );
if( d instanceof GeometryDescriptor){
GeometryDescriptor g = (GeometryDescriptor) d;
proj( property.putObject("proj"), g.getCoordinateReferenceSystem(), null );
}
if( details){
property
.put("namespace", d.getName().getNamespaceURI() )
.put("description", t.getDescription() )
.put("min-occurs",d.getMinOccurs() )
.put("max-occurs",d.getMaxOccurs() )
.put("nillable",d.isNillable());
int length = FeatureTypes.getFieldLength(d);
if( length != FeatureTypes.ANY_LENGTH ){
property.put("length", length );
}
if( d instanceof AttributeDescriptor){
AttributeDescriptor a = (AttributeDescriptor) d;
property.put("default-value", a.getDefaultValue() );
}
if( !t.getRestrictions().isEmpty() ){
JSONArr validate = property.putArray("validate");
for( Filter f : t.getRestrictions() ){
String cql;
try {
Filter clean = (Filter) f.accept( new DuplicatingFilterVisitor(){
public PropertyName visit(PropertyName e, Object extraData ){
String n = e.getPropertyName();