Class MergeAnnotation

  • All Implemented Interfaces:
    Serializable, Annotation, Changeable

    public class MergeAnnotation
    extends AbstractChangeable
    implements Annotation, Serializable
    Merged view onto a list of underlying Annotation objects. Currently immutable (but reflects changes to underlying objects). Annotations near the beginning of the list will have properties that take precedence. It is possible to get the ordering of the annotations, or to change it by removing and re-adding methods. This Annotation implementation is immutable.
    Since:
    1.2 Use these when you have a list of Annotation instances that need to be viewed as one. For example, if you have annotation for a feature from a local database, in-memory objects and a web-page, you could build three Annotation instances and merge them using a MergeAnnotation.
    Author:
    Thomas Down, Matthew Pocock, Greg Cox, Francois Pepin
    See Also:
    Serialized Form
    • Field Detail

      • ANNOTATION_CHANGED

        public static final ChangeType ANNOTATION_CHANGED
        ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.
      • ANNOTATION_ADD

        public static final ChangeType ANNOTATION_ADD
        ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.
      • ANNOTATION_REMOVE

        public static final ChangeType ANNOTATION_REMOVE
        ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.
    • Method Detail

      • addAnnotation

        public void addAnnotation​(Annotation ann)
                           throws ChangeVetoException
        Add a new Annotation to to the end of the list to be merged. Use this to alter the Annotations being merged
        Parameters:
        ann - the Annotation to add
        Throws:
        ChangeVetoException - if the annotation could not be added
      • getAnnotations

        public List getAnnotations()
        Gets an unmodifiable view of the list of Annotations that are part of the MergeAnnotation. Lower indices Annotation have precedence if 2 Annotations share the same property.
        Returns:
        an unmodifiable List of the Annotations that form this MergeAnnotation.
      • getChangeSupport

        protected ChangeSupport getChangeSupport​(ChangeType changeType)
        Description copied from class: AbstractChangeable
        Called to retrieve the ChangeSupport for this object.

        Your implementation of this method should have the following structure:

         ChangeSupport cs = super.getChangeSupport(ct);
        
         if(someForwarder == null && ct.isMatching(SomeInterface.SomeChangeType)) {
           someForwarder = new ChangeForwarder(...
        
           this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange);
         }
        
         return cs;
         
        It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register & unregister the forwarder in the code that does the ChangeEvent handling in setter methods.
        Overrides:
        getChangeSupport in class AbstractChangeable
      • setProperty

        public void setProperty​(Object key,
                                Object value)
                         throws ChangeVetoException
        Description copied from interface: Annotation

        Set the value of a property.

        This method throws an exception if either properties can not be added to this object, or that this particular property is immutable or illegal within the implementation.

        Normal raw access to the property. For cleverer access, use methods in AnnotationType.
        Specified by:
        setProperty in interface Annotation
        Parameters:
        key - the key object
        value - the new value for this key
        Throws:
        ChangeVetoException - if this annotation object can't be changed, or if the change was vetoed.
      • getProperty

        public Object getProperty​(Object key)
        Description copied from interface: Annotation

        Retrieve the value of a property by key.

        Unlike the Map collections, it will complain if the key does not exist. It will only return null if the key is defined and has value null.

        Normal raw access to the property. For cleverer access, use methods in AnnotationType.
        Specified by:
        getProperty in interface Annotation
        Parameters:
        key - the key of the property to retrieve
        Returns:
        the object associated with that key
      • containsProperty

        public boolean containsProperty​(Object key)
        Description copied from interface: Annotation
        Returns whether there the property is defined. Normal raw access to the property. For cleverer access, use methods in AnnotationType.
        Specified by:
        containsProperty in interface Annotation
        Parameters:
        key - the key Object to search for
        Returns:
        true if this Annotation knows about the key, false otherwise
      • keys

        public Set keys()
        Description copied from interface: Annotation
        Get a set of key objects.
        Specified by:
        keys in interface Annotation
        Returns:
        a Set of key objects
      • asMap

        public Map asMap()
        Description copied from interface: Annotation
        Return a map that contains the same key/values as this Annotation.

        If the annotation changes, the map may not reflect this. The Map may be unmodifiable.

        Specified by:
        asMap in interface Annotation
        Returns:
        a Map