@Override public void encodePostColumnCreateTable(AttributeDescriptor att, StringBuffer sql) { // make geometry columns non null in order to be able to index them if (att instanceof GeometryDescriptor && !att.isNillable()) { if (!sql.toString().trim().endsWith(" NOT NULL")) { sql.append(" NOT NULL"); } } }
public boolean isNillable() { return getDescriptor().isNillable(); }
/** * Provides a defautlValue for attributeType. * * <p>Will return null if attributeType isNillable(), or attempt to use Reflection, or * attributeType.parse( null ) * * @param attributeType * @return null for nillable attributeType, attempt at reflection * @deprecated Please {@link AttributeDescriptor#getDefaultValue()} */ public static Object defaultValue(AttributeDescriptor attributeType) throws IllegalAttributeException { Object value = attributeType.getDefaultValue(); if (value == null && !attributeType.isNillable()) { return null; // sometimes there is no valid default value :-( } return value; }
/** * Creates standard xml attributes present on all xs:element elements. These are name, * maxOccurs, minOccurs and nillable. * * @param attribute the attribute type from which the information is retrieved * @return an org.xml.sax.helpers.AttributesImpl object that contains the standard * attributes */ protected AttributesImpl createStandardAttributes(AttributeDescriptor attribute) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "", attribute.getLocalName()); if (attribute.isNillable() && attribute.getMinOccurs() == 0) { atts.addAttribute("", "minOccurs", "minOccurs", "", "0"); atts.addAttribute("", "nillable", "nillable", "", "true"); } else { atts.addAttribute("", "minOccurs", "minOccurs", "", "1"); atts.addAttribute("", "nillable", "nillable", "", "false"); } return atts; } }
/** Ensure that attributeContent is a good value for descriptor. */ public static void validate(AttributeDescriptor descriptor, Object value) throws IllegalAttributeException { if (descriptor == null) { throw new NullPointerException("Attribute descriptor required for validation"); } if (value == null) { if (!descriptor.isNillable()) { throw new IllegalArgumentException( descriptor.getName() + " requires a non null value"); } } else { validate(descriptor.getType(), value, false); } }
/** Initializes builder state from another attribute descriptor. */ public void init(AttributeDescriptor descriptor) { init(descriptor.getType()); minOccurs = descriptor.getMinOccurs(); maxOccurs = descriptor.getMaxOccurs(); isNillable = descriptor.isNillable(); userData = descriptor.getUserData(); }
private Object convert(Object value, AttributeDescriptor descriptor) { if (value == null) { // if the content is null and the descriptor says isNillable is false, // then set the default value if (!descriptor.isNillable()) { value = descriptor.getDefaultValue(); if (value == null) { // no default value, try to generate one value = DataUtilities.defaultValue(descriptor.getType().getBinding()); } } } else { // make sure the type of the value and the binding of the type match up value = super.convert(value, descriptor); } return value; }
/** * Creates the column definition as used by the ArcSDE Java API, for the given AttributeType. * * @param type the source attribute definition. * @return an <code>SeColumnDefinition</code> object matching the properties of the source * AttributeType. * @throws SeException if the SeColumnDefinition constructor throws it due to some invalid * parameter */ public static SeColumnDefinition createSeColumnDefinition(AttributeDescriptor type) throws SeException { SeColumnDefinition colDef = null; String colName = type.getLocalName(); boolean nillable = type.isNillable(); SdeTypeDef def = getSdeType(type.getType().getBinding()); int sdeColType = def.colDefType; int fieldLength = def.size; int fieldScale = def.scale; colDef = new SeColumnDefinition(colName, sdeColType, fieldLength, fieldScale, nillable); return colDef; }
/** * Create a complex attribute for XS.AnyType, since it's defined as a simple type. We need a * complex attribute so we can set xlink:href in it. * * @param value * @param descriptor * @param id * @return */ public Attribute addComplexAnyTypeAttribute( Object value, AttributeDescriptor descriptor, String id) { // need to create a complex attribute for any type, so we can have client properties // for xlink:href and so we chain features etc. Map<Object, Object> userData = descriptor.getUserData(); descriptor = new AttributeDescriptorImpl( ANYTYPE_TYPE, descriptor.getName(), descriptor.getMinOccurs(), descriptor.getMaxOccurs(), descriptor.isNillable(), descriptor.getDefaultValue()); descriptor.getUserData().putAll(userData); return createComplexAttribute(value, ANYTYPE_TYPE, descriptor, id); }
public NonFeatureTypeProxy( final AttributeType type, final FeatureTypeMapping mapping, Collection<PropertyDescriptor> schema) { super(type.getName(), null); subject = type; AttributeDescriptor originalTarget = mapping.getTargetFeature(); int maxOccurs = originalTarget.getMaxOccurs(); int minOccurs = originalTarget.getMinOccurs(); boolean nillable = originalTarget.isNillable(); Object defaultValue = originalTarget.getDefaultValue(); Name name = originalTarget.getName(); // create a new descriptor with the wrapped type and set it to the mapping ComplexFeatureTypeFactoryImpl typeFactory = new ComplexFeatureTypeFactoryImpl(); AttributeDescriptor descriptor = typeFactory.createAttributeDescriptor( this, name, minOccurs, maxOccurs, nillable, defaultValue); descriptor.getUserData().putAll(originalTarget.getUserData()); mapping.setTargetFeature(descriptor); // smuggle FEATURE_LINK descriptor schema.add(ComplexFeatureConstants.FEATURE_CHAINING_LINK); this.descriptors = schema; }
private AttributeDescriptor reprojectAttribute(AttributeDescriptor descr) { if (reprojection != null && descr.getType() instanceof FeatureType) { AttributeDescriptor ad = ftf.createAttributeDescriptor( reprojectType((FeatureType) descr.getType()), descr.getName(), descr.getMinOccurs(), descr.getMaxOccurs(), descr.isNillable(), descr.getDefaultValue()); ad.getUserData().putAll(descr.getUserData()); return ad; } else { return descr; } }
public void init(PropertyDescriptor descriptor) { init(); namespace = descriptor.getName().getNamespaceURI(); name = descriptor.getName().getLocalPart(); minOccurs = descriptor.getMinOccurs(); maxOccurs = descriptor.getMaxOccurs(); if (descriptor instanceof AttributeDescriptor) { AttributeDescriptor attribute = (AttributeDescriptor) descriptor; isNillable = attribute.isNillable(); propertyType = attribute.getType(); } if (descriptor instanceof AssociationDescriptor) { AssociationDescriptor association = (AssociationDescriptor) descriptor; propertyType = association.getType(); } }
/** * Sets all the attribute specific state from a single descriptor. * * <p>This method is convenience for: <code> * builder.minOccurs( descriptor.getMinOccurs() ).maxOccurs( descriptor.getMaxOccurs() ) * .nillable( descriptor.isNillable() )... * </code> */ public SimpleFeatureTypeBuilder descriptor(AttributeDescriptor descriptor) { minOccurs(descriptor.getMinOccurs()); maxOccurs(descriptor.getMaxOccurs()); nillable(descriptor.isNillable()); // namespaceURI( descriptor.getName().getNamespaceURI() ); defaultValue(descriptor.getDefaultValue()); if (descriptor instanceof GeometryDescriptor) { crs(((GeometryDescriptor) descriptor).getCoordinateReferenceSystem()); } return this; }
/** * Checkes the two feature types are equal, taking into consideration the eventual modification * the datastore had to perform in order to actually manage the type (change in names case, for * example) */ protected void assertAttributesEqual(AttributeDescriptor expected, AttributeDescriptor actual) { assertEquals(aname(expected.getName()), actual.getName()); assertEquals(expected.getMinOccurs(), actual.getMinOccurs()); assertEquals(expected.getMaxOccurs(), actual.getMaxOccurs()); assertEquals(expected.isNillable(), actual.isNillable()); assertEquals(expected.getDefaultValue(), actual.getDefaultValue()); AttributeType texpected = expected.getType(); AttributeType tactual = actual.getType(); if (Number.class.isAssignableFrom(texpected.getBinding())) { assertTrue(Number.class.isAssignableFrom(tactual.getBinding())); } else if (Geometry.class.isAssignableFrom(texpected.getBinding())) { assertTrue(Geometry.class.isAssignableFrom(tactual.getBinding())); } else { assertTrue(texpected.getBinding().isAssignableFrom(tactual.getBinding())); } }
@Override protected SimpleFeatureType buildTargetFeatureType() { SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder(); for (AttributeDescriptor ad : delegate.getSchema().getAttributeDescriptors()) { if (ad instanceof GeometryDescriptor) { GeometryDescriptor gd = (GeometryDescriptor) ad; Class<?> binding = ad.getType().getBinding(); if (Point.class.isAssignableFrom(binding)) { tb.add(ad); } else { tb.minOccurs(ad.getMinOccurs()); tb.maxOccurs(ad.getMaxOccurs()); tb.nillable(ad.isNillable()); tb.add(ad.getLocalName(), Point.class, gd.getCoordinateReferenceSystem()); } } else { tb.add(ad); } } tb.setName(delegate.getSchema().getName()); return tb.buildFeatureType(); }
public void testAttributeDefaultValue() { SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("buggy"); builder.nillable(false).defaultValue(12).add("attrWithDefault", Integer.class); builder.nillable(true).defaultValue(null).add("attrWithoutDefault", Integer.class); SimpleFeatureType featureType = builder.buildFeatureType(); assertFalse(featureType.getDescriptor("attrWithDefault").isNillable()); assertEquals(12, featureType.getDescriptor("attrWithDefault").getDefaultValue()); assertTrue(featureType.getDescriptor("attrWithoutDefault").isNillable()); assertNull(featureType.getDescriptor("attrWithoutDefault").getDefaultValue()); }
/** * Checkes the two feature types are equal, taking into consideration the eventual modification * the datastore had to perform in order to actually manage the type (change in names case, for * example) */ protected void assertFeatureTypesEqual(SimpleFeatureType expected, SimpleFeatureType actual) { for (int i = 0; i < expected.getAttributeCount(); i++) { AttributeDescriptor expectedAttribute = expected.getDescriptor(i); AttributeDescriptor actualAttribute = actual.getDescriptor(i); assertAttributesEqual(expectedAttribute, actualAttribute); } // make sure the geometry is nillable and has minOccurrs to 0 if (expected.getGeometryDescriptor() != null) { AttributeDescriptor dg = actual.getGeometryDescriptor(); assertTrue(dg.isNillable()); assertEquals(0, dg.getMinOccurs()); } }
public void testGetDescriptor() { assertNotNull(feature.getDescriptor()); assertSame(feature.getType(), feature.getDescriptor().getType()); assertTrue(feature.getDescriptor().isNillable()); assertEquals(0, feature.getDescriptor().getMinOccurs()); assertEquals(Integer.MAX_VALUE, feature.getDescriptor().getMaxOccurs()); }
private AttributeDescriptor override(AttributeDescriptor type, AttributeDescriptor override) { int max = override.getMaxOccurs(); if (max < 0) max = type.getMinOccurs(); int min = override.getMinOccurs(); if (min < 0) min = type.getMinOccurs(); String name = override.getLocalName(); if (name == null) name = type.getLocalName(); List restrictions = override(type.getType().getRestrictions(), override.getType().getRestrictions()); Class javaType = override.getType().getBinding(); if (javaType == null) javaType = type.getType().getBinding(); boolean isNilable = override.isNillable(); Object defaultValue = override.getDefaultValue(); if (defaultValue == null) defaultValue = type.getDefaultValue(); // WARNING cannot copy metadata! return new AttributeDescriptorImpl( new AttributeTypeImpl( new NameImpl(name), javaType, false, false, restrictions, null, null), new NameImpl(name), min, max, isNilable, defaultValue); }
public void testGetSchemaRoad() throws IOException { SimpleFeatureType expected = td.roadType; SimpleFeatureType actual = dataStore.getSchema(tname("road")); assertEquals("name", aname(expected.getName()), actual.getName()); // assertEquals( "compare", 0, DataUtilities.compare( expected, actual )); assertEquals("attributeCount", expected.getAttributeCount(), actual.getAttributeCount()); for (int i = 0; i < expected.getAttributeCount(); i++) { AttributeDescriptor expectedAttribute = expected.getDescriptor(i); AttributeDescriptor actualAttribute = actual.getDescriptor(i); assertAttributesEqual(expectedAttribute, actualAttribute); } // make sure the geometry is nillable and has minOccurrs to 0 AttributeDescriptor dg = actual.getGeometryDescriptor(); assertTrue(dg.isNillable()); assertEquals(0, dg.getMinOccurs()); // assertEquals(expected, actual); }