Class ClassReference

All Implemented Interfaces:
EventListener, IGProp<String>, Cloneable
Direct Known Subclasses:
EditorClassReference

public class ClassReference extends StringProp
The Class Reference property class hold the reference to a Java class. It includes support for Java Refactoring in Eclipse as well as Reference Validation.
Author:
Christopher Mindus
  • Field Details

    • implementsInterface

      protected String implementsInterface
      The required Interface, or null for none.
    • requiredAnnotation

      protected String requiredAnnotation
      The required annotation, or null for none.
  • Constructor Details

    • ClassReference

      protected ClassReference()
      Creates a Class Reference property with no name and with a null value.
    • ClassReference

      public ClassReference(Atom propertyAtom)
      Creates a Class Reference property with the specified name with a null value.
      Parameters:
      propertyAtom - the property atom.
    • ClassReference

      public ClassReference(Atom propertyAtom, String newValue)
      Creates a Class Reference property with the specified name and value.
      Parameters:
      propertyAtom - the property atom.
      newValue - the new string value for the property.
  • Method Details

    • getClassReference

      public static ClassReference getClassReference(PropCnr pc, String id)
      Gets a ClassReference instance from a property. The IClassReferenceOwner interfaces is searched for upwards in the property tree and from there the ClassReference instance is returned.
      Parameters:
      pc - The property container to start search on.
      id - The ID of the ClassReference property, used when multiple are present in the container.
      Returns:
      The ClassReference instance, of null if none is found.
    • isPropPrivateAtCreation

      protected boolean isPropPrivateAtCreation()
      Called upon creation of the property to check it's private state. This is used by properties that are not distributed to the remote party.
      Overrides:
      isPropPrivateAtCreation in class GProp<String>
      Returns:
      true, always.
    • equalsErrors

      protected boolean equalsErrors(PropError pe1, PropError pe2, int how)
      Processes error property verification. The default processing is to verify the two error properties pe1 and pe2 for equality if includeErrors is 0 or 1, and returns true if the value is 2=no comparison with error properties.

      Override to verify property errors for reference properties.

      Overrides:
      equalsErrors in class GProp<String>
      Parameters:
      pe1 - The first error property, may be null.
      pe2 - The second error property, may be null.
      how - Flags EQC_* values for equal checking.
      Returns:
      Equality flag depending on includeErrors value.
    • clone

      public ClassReference clone()
      Creates a clone out of this property. The cloning is overridden by the super classes in order to handle cloning of its class variables appropriately.

      Cloning is used for "virtualization" of a property tree in the server. Client property classes will therefore throw CloneNotSupportedException.

      Once a tree has been cloned, the change-flag is reset, and the create-flag is set. All listeners are also removed! The new cloned property is an orphan, i.e. has no parent set.

      Note that the cloning process is done WITHOUT thread synchronization for performance reasons, thus no modifications should be done to the tree!

      Overrides:
      clone in class StringProp
      Returns:
      A new cloned String property.
    • setPropValue

      public boolean setPropValue(String newValue)
      Sets a new value for this property. If any listener is present and the value has changed compare to the last value, the listener is informed.
      Overrides:
      setPropValue in class StringProp
      Parameters:
      newValue - the new value.
      Returns:
      boolean true for value has changed, false for same value as current value.
    • initializeElement

      protected void initializeElement(Element element)
      Called when the XML file for the property tree is serialized from properties. The property should fill attributes and nodes with appropriate information.
      Overrides:
      initializeElement in class GProp<String>
      Parameters:
      element - The Element to initialize.
    • initializeProp

      protected void initializeProp(Element element) throws PropException
      Called to initialize the property from an Element. The property should initialize itself from attributes and nodes with appropriate information.
      Overrides:
      initializeProp in class GProp<String>
      Parameters:
      element - The Element.
      Throws:
      PropException - when the initialization fails.
    • onPrepare

      protected void onPrepare(IAppOwner appOwner, IModuleOwner moduleOwner, boolean isPostCall, List<Throwable> errors) throws PropException
      Called when the application is being prepared. The order of onPrepare calls is always parent first, the children. The method is called twice, first time with isPostCall set to false, then a second time with true.
      Overrides:
      onPrepare in class GProp<String>
      Parameters:
      appOwner - The application owner.
      moduleOwner - The Module owner.
      isPostCall - Flag indicating this is a post-call.
      errors - A list of errors that occurred but did not cause an abort.
      Throws:
      PropException - For property errors during the application preparation to need to abort.
    • virtualize

      protected final ClassReference virtualize(IAppSessionGyro appGyro, IClientSessionGyro clientGyro, VirtualSpace virtualSpace) throws CloneNotSupportedException, PropException
      Call this method to "virtualize" a property tree. This method is used at runtime in the Server for the application session of virtual instances of VirtualSpace, but also virtual instances of panels, for the individual client session. The VirtualSpace is virtualized once for the application session and is shared for parallel client sessions.

      This method is similar to cloning, but enables references that are already resolved to remain if they point to a shared instance, e.g. the VirtualSpace pointing to its participants in the application property container shared instance, or a panel with references to text IDs, assets, etc.

      Overrides:
      virtualize in class GProp<String>
      Parameters:
      appGyro - The application gyro instance performing the virtualization.
      clientGyro - The client gyro session, can be null if not initialized from the client gyro.
      virtualSpace - The virtualized VirtualSpace.
      Returns:
      The virtualized property.
      Throws:
      CloneNotSupportedException - If a subclass doesn't allow cloning, e.g. the client properties.
      PropException - For property errors during the virtualization.
    • onVirtualizationCompleted

      protected void onVirtualizationCompleted(IAppSessionGyro appGyro, IClientSessionGyro clientGyro, VirtualSpace virtualSpace, boolean isPostResolve)
      Called when virtualization completed.

      This method is called to the entire tree of the newly virtualized property container.

      Overrides:
      onVirtualizationCompleted in class GProp<String>
      Parameters:
      appGyro - The application gyro instance performing the virtualization.
      clientGyro - The client gyro session, can be null if not initialized from the client gyro.
      virtualSpace - The virtualized VirtualSpace.
      isPostResolve - Flag indicating this call is done after references are attempted to be resolved.
    • getMethod

      public Method getMethod(String methodName, List<Throwable> errors, Class<?>... parameterTypes)
      Gets the method in the loaded runtime class with the specified parameters types.
      Parameters:
      methodName - The method name.
      errors - A list of errors that occurred but did not cause an abort.
      parameterTypes - The list of parameters.
      Returns:
      The method loaded, or null if not found (and the error is added to the list).
    • getRuntimeClass

      public Class<?> getRuntimeClass()
      Gets the loaded class for runtime.
      Returns:
      The loaded class, or null for none.
    • getRuntimeInstance

      public Object getRuntimeInstance()
      Gets the runtime instance of the class.
      Returns:
      The instance that was created during virtualization, or null if there is no loaded class for this reference or if virtualization has not taken place.
    • getRuntimeInstance

      public <T> T getRuntimeInstance(Class<T> instanceClass)
      Gets the runtime instance of the class.
      Parameters:
      instanceClass - The class the runtime instance should be assignable from.
      Returns:
      The instance that was created during virtualization, or null if there is no loaded class for this reference or if virtualization has not taken place. It is also null if the instance is not an instance of the specified class instanceClass.
    • onPropDispose

      protected void onPropDispose()
      Disposal of the instance.
      Overrides:
      onPropDispose in class GProp<String>
    • verifyInterface

      public boolean verifyInterface(Class<?> interfaceClass, List<Throwable> errors)
      Validates that the class implements an interface. This method is generally called during the "prepare" phase of the application.
      Returns:
      true if the runtime class is defined and implements the interface, false otherwise. When a defined class does not implement the interface, an error is added.