de.jreality.scene.data
Class AttributeEntityUtility

java.lang.Object
  extended by de.jreality.scene.data.AttributeEntityUtility

public class AttributeEntityUtility
extends java.lang.Object

This class handles a whole set of Attributes, that belong together somehow. A typical application is i.e. a Texture object, that consists of many attributes, that should be set and get from an appearance as one entity. Define the entity by a an interface that consists of set/get method pairs - all these attributes will be handled by the Reader/Writer proxy. Use this interface either as a Writer on an Appearance or a set of Appearances:

 Appearance app = new Appearance();
 MyEntityInterface mif = (MyEntityInterface) AttributeEntityFactory
     .createAttributeEntity(MyEntityInterface.class, "myEntityName", app);
 mif.setAttribute1(value1);
 mif.setAttribute2(value2);
 
And use it to read the values from an EffectiveAppearance:
 
  EffectiveAppearance ea = ...
  MyEntityInterface mif = (MyEntityInterface) AttributeEntityFactory.createAttributeEntity(MyEntityInterface.class, "myEntityName", ea);
  value1 = mif.getAttribute1();
  value2 = mif.getAttribute2();
  
 

Note: Instances that act on Appearances can call set- and get-Methods, instances acting on EffectiveAppearances can ONLY use get-Methods.

The given prefix is used as a name prefix for the single attributes. i.e. in the above example the attribute "attribute1" is stored in the Appearance(s) as setAttribute("myEntityName:attribute1"); To read the values again one needs to use the same prefix as used while writing.

Naming conventions

  • Attributes are named just like the methods without the prefix set or get and with a small first character (not really, its simply javaBeans naming convetions). i.e. set/getTestDouble -> testDouble
  • Default values are defined as constants in the interface. the name for a default constant is defined as follows:
    every uppercase letter L that follows a number or a lowercase letter is replaced by _L. Then the resulting string is converted to upper case. then _DEFAULT is appended.
    examples:
    testDouble -> TEST_DOUBLE_DEFAULT
    testURL -> TEST_URL_DEFAULT
    23AttrTest42String -> 23_ATTR_TEST42_STRING_DEFAULT
    TODO: possibly change name

    Author:
    weissman

    Method Summary
    static AttributeEntity createAttributeEntity(java.lang.Class clazz, java.lang.String prefix, Appearance a, boolean readDefaults)
              Create an implementation of the AttributeEntityfor reading from and/or writing to an Appearance - writes tag to the appearance.
    static AttributeEntity createAttributeEntity(java.lang.Class clazz, java.lang.String prefix, EffectiveAppearance ea)
              Create an implementation of the AttributeEntityfor reading from an EffectiveAppearance.
    static AttributeEntity getAttributeEntity(java.lang.Class clazz, java.lang.String prefix, Appearance a, boolean readDefaults)
              Create an implementation of the AttributeEntityfor reading from and/or writing to an Appearance - this does not tag the appearance.
    static boolean hasAttributeEntity(java.lang.Class clazz, java.lang.String prefix, Appearance a)
               
    static boolean hasAttributeEntity(java.lang.Class clazz, java.lang.String prefix, EffectiveAppearance eap)
              returns true if the appearance is tagged with the given class or if 1.
     
    Methods inherited from class java.lang.Object
    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Method Detail

    createAttributeEntity

    public static AttributeEntity createAttributeEntity(java.lang.Class clazz,
                                                        java.lang.String prefix,
                                                        Appearance a,
                                                        boolean readDefaults)
    Create an implementation of the AttributeEntityfor reading from and/or writing to an Appearance - writes tag to the appearance.


    getAttributeEntity

    public static AttributeEntity getAttributeEntity(java.lang.Class clazz,
                                                     java.lang.String prefix,
                                                     Appearance a,
                                                     boolean readDefaults)
    Create an implementation of the AttributeEntityfor reading from and/or writing to an Appearance - this does not tag the appearance.


    createAttributeEntity

    public static AttributeEntity createAttributeEntity(java.lang.Class clazz,
                                                        java.lang.String prefix,
                                                        EffectiveAppearance ea)
    Create an implementation of the AttributeEntityfor reading from an EffectiveAppearance.


    hasAttributeEntity

    public static boolean hasAttributeEntity(java.lang.Class clazz,
                                             java.lang.String prefix,
                                             EffectiveAppearance eap)
    returns true if the appearance is tagged with the given class or if 1. clazz declares a DEFAULT_ENTITY class or 2. clazz == DEFAULT_ENTITY

    Parameters:
    clazz -
    prefix -
    eap -
    Returns:

    hasAttributeEntity

    public static boolean hasAttributeEntity(java.lang.Class clazz,
                                             java.lang.String prefix,
                                             Appearance a)