Class DynamicStorageGenerator

  • Direct Known Subclasses:
    PCDataGenerator

    public class DynamicStorageGenerator
    extends java.lang.Object
    Factory for creating new DynamicStorage classes. Can be extended to decorate/modify the generated instances behavior.
    Since:
    0.3.2.0
    Author:
    Steve Kim, Mark Struberg rework to ASM
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int POLICY_EMPTY
      Constant to not generate type set/get methods.
      protected static int POLICY_EXCEPTION
      Constant to throw an exception on invalid index passed to type set/get methods
      protected static int POLICY_SILENT
      Constant to be as silent as possible during invalid index passed to set/get type methods.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.xbean.asm9.tree.FieldNode addBeanField​(ClassNodeTracker bc, java.lang.String name, java.lang.Class type)
      Add a bean field of the given name and type.
      protected DynamicStorage createFactory​(ClassNodeTracker bc)
      Create a stub factory instance for the given class.
      protected void declareClasses​(ClassNodeTracker bc)
      Add interface or superclass declarations to the generated class.
      protected void decorate​(java.lang.Object obj, ClassNodeTracker cls, int[] types)
      Decorate the generated class.
      protected java.lang.Class forType​(int type)
      Return the proper type for the given JavaTypes constant.
      DynamicStorage generateStorage​(int[] types, java.lang.Object obj)
      Generate a generic DynamicStorage instance with the given array of JavaTypes constants and the given object as the user key for generation.
      protected java.lang.String getClassName​(java.lang.Object obj)
      Return a class name to use for the given user key.
      protected int getCreateFieldMethods​(int type)
      Return the policy constant for how to create type methods.
      protected int getFieldAccess()
      Return the default field ACCESS constant for generated fields from Opcodes.
      protected java.lang.String getFieldName​(int index)
      Return the name for the generated field at the given index.
      protected java.lang.Class getWrapper​(int type)
      get the wrapper for the given JavaTypes constant.
      protected java.lang.Class getWrapper​(java.lang.Class c)
      Get the wrapper for the given type.
      protected boolean isCompatible​(int fieldType, int storageType)
      Return true if the given field type and storage type are compatible.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • POLICY_EXCEPTION

        protected static final int POLICY_EXCEPTION
        Constant to throw an exception on invalid index passed to type set/get methods
        See Also:
        Constant Field Values
      • POLICY_EMPTY

        protected static final int POLICY_EMPTY
        Constant to not generate type set/get methods.
        See Also:
        Constant Field Values
      • POLICY_SILENT

        protected static final int POLICY_SILENT
        Constant to be as silent as possible during invalid index passed to set/get type methods. On getting an Object, for example, null will be returned. However, on primitive gets, an exception will be thrown.
        See Also:
        Constant Field Values
    • Constructor Detail

      • DynamicStorageGenerator

        public DynamicStorageGenerator()
    • Method Detail

      • generateStorage

        public DynamicStorage generateStorage​(int[] types,
                                              java.lang.Object obj)
        Generate a generic DynamicStorage instance with the given array of JavaTypes constants and the given object as the user key for generation.
      • getClassName

        protected java.lang.String getClassName​(java.lang.Object obj)
        Return a class name to use for the given user key. By default, returns the stringified key prefixed by PREFIX.
      • getFieldAccess

        protected int getFieldAccess()
        Return the default field ACCESS constant for generated fields from Opcodes.
      • getFieldName

        protected java.lang.String getFieldName​(int index)
        Return the name for the generated field at the given index. Returns "field" + i by default.
      • getCreateFieldMethods

        protected int getCreateFieldMethods​(int type)
        Return the policy constant for how to create type methods.
      • decorate

        protected void decorate​(java.lang.Object obj,
                                ClassNodeTracker cls,
                                int[] types)
        Decorate the generated class.
      • declareClasses

        protected void declareClasses​(ClassNodeTracker bc)
        Add interface or superclass declarations to the generated class.
      • addBeanField

        protected org.apache.xbean.asm9.tree.FieldNode addBeanField​(ClassNodeTracker bc,
                                                                    java.lang.String name,
                                                                    java.lang.Class type)
        Add a bean field of the given name and type.
      • isCompatible

        protected boolean isCompatible​(int fieldType,
                                       int storageType)
        Return true if the given field type and storage type are compatible.
      • forType

        protected java.lang.Class forType​(int type)
        Return the proper type for the given JavaTypes constant.
      • getWrapper

        protected java.lang.Class getWrapper​(int type)
        get the wrapper for the given JavaTypes constant.
      • getWrapper

        protected java.lang.Class getWrapper​(java.lang.Class c)
        Get the wrapper for the given type.