@Test(expected = IllegalArgumentException.class) public void append_invalidName_throwsIllegalArgumentException() throws Exception { ComplexFeatureBuilder builder = new ComplexFeatureBuilder(FakeTypes.Mine.MINETYPE_TYPE); try { builder.append(new NameImpl("invalid_descriptor_name"), null); } catch (IllegalArgumentException iae) { ExceptionChecker.assertExceptionMessage( iae, "The name 'invalid_descriptor_name' is not a valid descriptor name for the type 'urn:org:example:MineType'."); } }
public void append(Name name, Property value) { PropertyDescriptor propertyDescriptor = featureType.getDescriptor(name); if (propertyDescriptor == null) { throw new IllegalArgumentException( String.format( "The name '%s' is not a valid descriptor name for the type '%s'.", name, this.featureType.getName())); } Class<?> expectedClass = propertyDescriptor.getType().getBinding(); if (value != null) { Class<?> providedClass = value.getType().getBinding(); if (!providedClass.equals(expectedClass) && !expectedClass.isAssignableFrom(providedClass)) { throw new IllegalArgumentException( String.format( "The value provided contains an object of '%s' but the method expects an object of '%s'.", providedClass, expectedClass)); } } else { if (propertyDescriptor.isNillable()) { value = (Property) expectedClass.cast(null); } else { value = (Property) expectedClass.cast(null); } } ArrayList<Property> valueList; if (values.containsKey(name)) { valueList = values.get(name); int maxOccurs = propertyDescriptor.getMaxOccurs(); if (valueList.size() == maxOccurs) { throw new IndexOutOfBoundsException( String.format( "You can't add another object with the name of '%s' because you already have the maximum number (%s) allowed by the property descriptor.", name, maxOccurs)); } } else { valueList = new ArrayList<Property>(); values.put(name, valueList); } valueList.add(value); }
ComplexFeatureBuilder extends FeatureBuilder<FeatureType, Feature> { public void append(Name name, Property value) { PropertyDescriptor propertyDescriptor = featureType.getDescriptor(name); if (propertyDescriptor == null) { throw new IllegalArgumentException( String.format( "The name '%s' is not a valid descriptor name for the type '%s'.", name, this.featureType.getName())); } Class<?> expectedClass = propertyDescriptor.getType().getBinding(); if (value != null) { Class<?> providedClass = value.getType().getBinding(); if (!providedClass.equals(expectedClass) && !expectedClass.isAssignableFrom(providedClass)) { throw new IllegalArgumentException( String.format( "The value provided contains an object of '%s' but the method expects an object of '%s'.", providedClass, expectedClass)); } } else { if (propertyDescriptor.isNillable()) { value = (Property) expectedClass.cast(null); } else { value = (Property) expectedClass.cast(null); } } ArrayList<Property> valueList; if (values.containsKey(name)) { valueList = values.get(name); int maxOccurs = propertyDescriptor.getMaxOccurs(); if (valueList.size() == maxOccurs) { throw new IndexOutOfBoundsException( String.format( "You can't add another object with the name of '%s' because you already have the maximum number (%s) allowed by the property descriptor.", name, maxOccurs)); } } else { valueList = new ArrayList<Property>(); values.put(name, valueList); } valueList.add(value); } }
ComplexFeatureBuilder extends FeatureBuilder<FeatureType, Feature> { public void append(Name name, Property value) { PropertyDescriptor propertyDescriptor = featureType.getDescriptor(name); if (propertyDescriptor == null) { throw new IllegalArgumentException( String.format( "The name '%s' is not a valid descriptor name for the type '%s'.", name, this.featureType.getName())); } Class<?> expectedClass = propertyDescriptor.getType().getBinding(); if (value != null) { Class<?> providedClass = value.getType().getBinding(); if (!providedClass.equals(expectedClass) && !expectedClass.isAssignableFrom(providedClass)) { throw new IllegalArgumentException( String.format( "The value provided contains an object of '%s' but the method expects an object of '%s'.", providedClass, expectedClass)); } } else { if (propertyDescriptor.isNillable()) { value = (Property) expectedClass.cast(null); } else { value = (Property) expectedClass.cast(null); } } ArrayList<Property> valueList; if (values.containsKey(name)) { valueList = values.get(name); int maxOccurs = propertyDescriptor.getMaxOccurs(); if (valueList.size() == maxOccurs) { throw new IndexOutOfBoundsException( String.format( "You can't add another object with the name of '%s' because you already have the maximum number (%s) allowed by the property descriptor.", name, maxOccurs)); } } else { valueList = new ArrayList<Property>(); values.put(name, valueList); } valueList.add(value); } ComplexFeatureBuilder(FeatureType featureType); protected  ComplexFeatureBuilder(FeatureType featureType, FeatureFactory factory);  ComplexFeatureBuilder(AttributeDescriptor ad); protected  ComplexFeatureBuilder(AttributeDescriptor ad, FeatureFactory factory); }
ComplexFeatureBuilder extends FeatureBuilder<FeatureType, Feature> { public void append(Name name, Property value) { PropertyDescriptor propertyDescriptor = featureType.getDescriptor(name); if (propertyDescriptor == null) { throw new IllegalArgumentException( String.format( "The name '%s' is not a valid descriptor name for the type '%s'.", name, this.featureType.getName())); } Class<?> expectedClass = propertyDescriptor.getType().getBinding(); if (value != null) { Class<?> providedClass = value.getType().getBinding(); if (!providedClass.equals(expectedClass) && !expectedClass.isAssignableFrom(providedClass)) { throw new IllegalArgumentException( String.format( "The value provided contains an object of '%s' but the method expects an object of '%s'.", providedClass, expectedClass)); } } else { if (propertyDescriptor.isNillable()) { value = (Property) expectedClass.cast(null); } else { value = (Property) expectedClass.cast(null); } } ArrayList<Property> valueList; if (values.containsKey(name)) { valueList = values.get(name); int maxOccurs = propertyDescriptor.getMaxOccurs(); if (valueList.size() == maxOccurs) { throw new IndexOutOfBoundsException( String.format( "You can't add another object with the name of '%s' because you already have the maximum number (%s) allowed by the property descriptor.", name, maxOccurs)); } } else { valueList = new ArrayList<Property>(); values.put(name, valueList); } valueList.add(value); } ComplexFeatureBuilder(FeatureType featureType); protected  ComplexFeatureBuilder(FeatureType featureType, FeatureFactory factory);  ComplexFeatureBuilder(AttributeDescriptor ad); protected  ComplexFeatureBuilder(AttributeDescriptor ad, FeatureFactory factory); @Override Feature buildFeature(String id); void append(Name name, Property value); }
ComplexFeatureBuilder extends FeatureBuilder<FeatureType, Feature> { public void append(Name name, Property value) { PropertyDescriptor propertyDescriptor = featureType.getDescriptor(name); if (propertyDescriptor == null) { throw new IllegalArgumentException( String.format( "The name '%s' is not a valid descriptor name for the type '%s'.", name, this.featureType.getName())); } Class<?> expectedClass = propertyDescriptor.getType().getBinding(); if (value != null) { Class<?> providedClass = value.getType().getBinding(); if (!providedClass.equals(expectedClass) && !expectedClass.isAssignableFrom(providedClass)) { throw new IllegalArgumentException( String.format( "The value provided contains an object of '%s' but the method expects an object of '%s'.", providedClass, expectedClass)); } } else { if (propertyDescriptor.isNillable()) { value = (Property) expectedClass.cast(null); } else { value = (Property) expectedClass.cast(null); } } ArrayList<Property> valueList; if (values.containsKey(name)) { valueList = values.get(name); int maxOccurs = propertyDescriptor.getMaxOccurs(); if (valueList.size() == maxOccurs) { throw new IndexOutOfBoundsException( String.format( "You can't add another object with the name of '%s' because you already have the maximum number (%s) allowed by the property descriptor.", name, maxOccurs)); } } else { valueList = new ArrayList<Property>(); values.put(name, valueList); } valueList.add(value); } ComplexFeatureBuilder(FeatureType featureType); protected  ComplexFeatureBuilder(FeatureType featureType, FeatureFactory factory);  ComplexFeatureBuilder(AttributeDescriptor ad); protected  ComplexFeatureBuilder(AttributeDescriptor ad, FeatureFactory factory); @Override Feature buildFeature(String id); void append(Name name, Property value);  }