Class AttributeBuilder

  • Direct Known Subclasses:
    AppSchemaAttributeBuilder

    public class AttributeBuilder
    extends Object
    Builder for attributes.
    Author:
    Justin Deoliveira (The Open Planning Project)
    • Field Detail

      • ANYTYPE_TYPE

        protected static final ComplexType ANYTYPE_TYPE
    • Constructor Detail

      • AttributeBuilder

        public AttributeBuilder​(FeatureFactory attributeFactory)
    • Method Detail

      • getFeatureFactory

        public FeatureFactory getFeatureFactory()
        Returns the underlying attribute factory.
      • setFeatureFactory

        public void setFeatureFactory​(FeatureFactory attributeFactory)
        Sets the underlying attribute factory.
      • init

        public void init()
        Initializes the builder to its initial state, the same state it is in directly after being instantiated.
      • init

        public void init​(Attribute attribute)
        Initializes the state of the builder based on a previously built attribute.

        This method is useful when copying another attribute.

      • setNamespaceURI

        public void setNamespaceURI​(String namespace)
        This namespace will be used when constructing attribute names.
      • getNamespaceURI

        public String getNamespaceURI()
        This namespace will be used when constructing attribute names.
        Returns:
        namespace will be used when constructing attribute names.
      • setType

        public void setType​(AttributeType type)
        Sets the type of the attribute being built.

        When building a complex attribute, this type is used a reference to obtain the types of contained attributes.

      • setDescriptor

        public void setDescriptor​(AttributeDescriptor descriptor)
        Sets the descriptor of the attribute being built.

        When building a complex attribute, this type is used a reference to obtain the types of contained attributes.

      • getType

        public AttributeType getType()
        Returns:
        The type of the attribute being built.
      • getCRS

        public CoordinateReferenceSystem getCRS​(Object geom)
        Returns:
        The coordinate reference system of the feature, or null if not set.
      • setDefaultGeometry

        public void setDefaultGeometry​(Object defaultGeometry)
        Sets the default geometry of the feature.
      • getDefaultGeometry

        public Object getDefaultGeometry()
        Returns:
        The default geometry of the feature.
      • add

        public Attribute add​(Object value,
                             String name)
        Adds an attribute to the complex attribute being built.

        This method uses the result of getNamespaceURI() to build a qualified attribute name.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        name - The name of the attribute.
        value - The value of the attribute.
      • associate

        public void associate​(Attribute value,
                              String name)
        Adds an association to the complex attribute being built.

        This method uses the result of getNamespaceURI() to build a qualified attribute name.

        This method uses the type supplied in setType(AttributeType) in order to determine the association type.

        Parameters:
        value - The value of the association, an attribute.
        name - The name of the association.
      • add

        public Attribute add​(Object value,
                             String name,
                             String namespaceURI)
        Adds an attribute to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        value - The value of the attribute.
        name - The name of the attribute.
        namespaceURI - The namespace of the attribute.
      • associate

        public void associate​(Attribute attribute,
                              String name,
                              String namespaceURI)
        Adds an association to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the association type.

        Parameters:
        attribute - The value of the association, an attribute.
        name - The name of the association.
        namespaceURI - The namespace of the association
      • add

        public Attribute add​(Object value,
                             Name name)
        Adds an attribute to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        name - The name of the attribute.
        value - The value of the attribute.
      • associate

        public void associate​(Attribute value,
                              Name name)
        Adds an association to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the association type.

        Parameters:
        value - The value of the association, an attribute.
        name - The name of the association.
      • add

        public Attribute add​(String id,
                             Object value,
                             String name)
        Adds an attribute to the complex attribute being built.

        The result of getNamespaceURI() to build a qualified attribute name.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        id - The id of the attribute.
        name - The name of the attribute.
        value - The value of the attribute.
      • add

        public Attribute add​(String id,
                             Object value,
                             String name,
                             String namespaceURI)
        Adds an attribute to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        id - The id of the attribute.
        value - The value of the attribute.
        name - The name of the attribute.
        namespaceURI - The namespace of the attribute.
      • add

        public Attribute add​(String id,
                             Object value,
                             Name name)
        Adds an attribute to the complex attribute being built.

        This method uses the type supplied in setType(AttributeType) in order to determine the attribute type.

        Parameters:
        id - The id of the attribute.
        name - The name of the attribute.
        value - The value of the attribute.
      • properties

        protected List<Property> properties()
        Convenience accessor for properties list which does the null check.
      • create

        protected Attribute create​(Object value,
                                   AttributeType type,
                                   AttributeDescriptor descriptor,
                                   String id)
        Factors out attribute creation code, needs to be called with either one of type or descriptor null.
      • build

        public Attribute build()
        Builds the attribute.

        The class of the attribute built is determined from its type set with setType(AttributeType).

        Returns:
        The build attribute.
      • build

        public Attribute build​(String id)
        Builds the attribute.

        The class of the attribute built is determined from its type set with setType(AttributeType).

        Parameters:
        id - The id of the attribute, or null.
        Returns:
        The build attribute.
      • addAnyTypeValue

        public Attribute addAnyTypeValue​(Object value,
                                         AttributeType type,
                                         AttributeDescriptor descriptor,
                                         String id)
        Special case for any type. Skip validating existence in the schema, since anyType legally can be casted into anything.
        Parameters:
        value - the value to be set
        type - the type of the value
        descriptor - the attribute descriptor of anyType type
      • addComplexAnyTypeAttribute

        public Attribute addComplexAnyTypeAttribute​(Object value,
                                                    AttributeDescriptor descriptor,
                                                    String id)
        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.
      • getDescriptor

        public AttributeDescriptor getDescriptor()
        Returns:
        The descriptor of the attribute being built or null there is no descriptor (this occurs if setType() was used).
      • getCRS

        public CoordinateReferenceSystem getCRS()
        Returns:
        The coordinate reference system of the feature, or null if not set.
      • getProperties

        protected List<Property> getProperties()
        Convenience accessor for properties list which does the null check.
      • buildSimple

        public Attribute buildSimple​(String id,
                                     Object value)