private Object defaultValue() { if (defaultValue == null && !isNillable && binding != null) { defaultValue = DataUtilities.defaultValue(binding); } return defaultValue; }
public ChoiceAttributeTypeImpl( Name name, Class<?>[] types, Class<?> defaultType, boolean nillable, int min, int max, Object defaultValue, List<Filter> filter) { super(name, defaultType, false, false, filter, null, toDescription(types)); if (defaultValue == null && !isNillable) { defaultValue = DataUtilities.defaultValue(defaultType); } this.minOccurs = min; this.maxOccurs = max; }
public void testDefaultValueArray() throws Exception { assertArrayEquals(new byte[] {}, (byte[]) DataUtilities.defaultValue(byte[].class)); assertArrayEquals(new String[] {}, (String[]) DataUtilities.defaultValue(String[].class)); }
public void testDefaultValue() throws IllegalAttributeException { assertNull(DataUtilities.defaultValue(roadType.getDescriptor("name"))); assertNull(DataUtilities.defaultValue(roadType.getDescriptor("id"))); assertNull(DataUtilities.defaultValue(roadType.getDescriptor("geom"))); }
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; }
private Object defaultValue(){ if( defaultValue == null && !isNillable && binding != null){ defaultValue = DataUtilities.defaultValue( binding ); } return defaultValue; }
public void setBinding(Class binding) { this.binding = binding; //JD: tidbit here if ( !isDefaultValueSet ) { //genereate a good default value based on class try { defaultValue = DataUtilities.defaultValue(binding); } catch( Exception e ) { //do nothing } } }
if (!nillable) { try { Object defaultValue = DataUtilities.defaultValue(type); AttributeTypeBuilder build = new AttributeTypeBuilder(); build.setName(eg.getName());
/** * DOCUMENT ME! * * @param featureType DOCUMENT ME! * @param values DOCUMENT ME! * * @return DOCUMENT ME! * * @throws IllegalAttributeException DOCUMENT ME! * @throws ArrayIndexOutOfBoundsException DOCUMENT ME! */ public static Object[] defaultValues(FeatureType featureType, Object[] values) throws IllegalAttributeException { if (values == null) { values = new Object[featureType.getAttributeCount()]; } else if (values.length != featureType.getAttributeCount()) { throw new ArrayIndexOutOfBoundsException("values"); } for (int i = 0; i < featureType.getAttributeCount(); i++) { values[i] = defaultValue(featureType.getAttributeType(i)); } return values; }
private Object convert(Object value, AttributeDescriptor descriptor) { //make sure the type of the value and the binding of the type match up if ( value != null ) { Class<?> target = descriptor.getType().getBinding(); Object converted = Converters.convert(value, target); if(converted != null) value = converted; } else { //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()); } } } return value; }