Class WrapperUnit<T extends IUnit>

java.lang.Object
com.pnfsoftware.jeb.core.units.impl.WrapperUnit<T>
All Implemented Interfaces:
IUnitCreator, IUserDataSupport, IUnit, com.pnfsoftware.jeb.corei.IWrap<T>, IEventSource
Direct Known Subclasses:
BinaryWrapperUnit, InteractiveWrapperUnit

@Ser public class WrapperUnit<T extends IUnit> extends Object implements IUnit, com.pnfsoftware.jeb.corei.IWrap<T>
Simple wrapper (decorator) unit that delegates its job to the provided IUnit. This decorator allows the additions of output documents as well as a customization of the unit's format type using the IUnitProvider. For other changes in the IUnit, it is required to extend this class.
  • Constructor Details

    • WrapperUnit

      public WrapperUnit(T unit, IUnitProvider provider)
      Parameters:
      unit - IUnit to be delegated
      provider - provider that extends the unit behavior
  • Method Details

    • getWrap

      public T getWrap()
      Return the wrapped IUnit
      Specified by:
      getWrap in interface com.pnfsoftware.jeb.corei.IWrap<T extends IUnit>
      Returns:
      the wrapped IUnit
    • addListener

      public void addListener(IEventListener listener)
      Description copied from interface: IEventSource
      Register a listener. The listener is appended to the existing list of listeners. The implementor may allow duplicates.
      Specified by:
      addListener in interface IEventSource
      Parameters:
      listener - a listener of events generated by this source
    • insertListener

      public void insertListener(int index, IEventListener listener)
      Description copied from interface: IEventSource
      Register a listener. The implementor may allow duplicates.
      Specified by:
      insertListener in interface IEventSource
      Parameters:
      index - insertion point
      listener - a listener of events generated by this source
    • countListeners

      public int countListeners()
      Description copied from interface: IEventSource
      Get the numbers of objects listening to this event source.
      Specified by:
      countListeners in interface IEventSource
      Returns:
      the number of listeners
    • getListeners

      public List<? extends IEventListener> getListeners()
      Description copied from interface: IEventSource
      Get a copy of the list of listeners.
      Specified by:
      getListeners in interface IEventSource
      Returns:
    • getParentSource

      public IEventSource getParentSource()
      Description copied from interface: IEventSource
      Get the parent source.
      Specified by:
      getParentSource in interface IEventSource
      Returns:
      the parent source, or null if none
    • notifyListeners

      public void notifyListeners(IEvent e)
      Description copied from interface: IEventSource
      Notify listeners that an event has occurred.
      Specified by:
      notifyListeners in interface IEventSource
      Parameters:
      e - the event to be propagated
    • canBePersisted

      public boolean canBePersisted()
      Description copied from interface: IUnit
      Determine if this unit can be persisted. This method can be used by parent units and client code to verify if a child unit can legally be persisted.
      Specified by:
      canBePersisted in interface IUnit
      Returns:
      true if the unit can be persisted, false if the unit must not be persisted
    • getChildren

      public List<? extends IUnit> getChildren()
      Description copied from interface: IUnit
      Retrieve a read-only list of all direct children units.
      Specified by:
      getChildren in interface IUnit
      Returns:
      the children or an empty list, never null
    • getLock

      public IUnitLock getLock()
      Description copied from interface: IUnit
      Get the unit lock.
      Specified by:
      getLock in interface IUnit
      Returns:
    • getCreationTimestamp

      public long getCreationTimestamp()
      Description copied from interface: IUnit
      Get the date of creation of this unit.
      Specified by:
      getCreationTimestamp in interface IUnit
      Returns:
      the creation timestamp in milliseconds since the unix epoch
    • getDescription

      public String getDescription()
      Description copied from interface: IUnit
      Get a description string for that unit.

      The unit must be processed before calling this method.

      Specified by:
      getDescription in interface IUnit
      Returns:
      a description string
    • getFormatType

      public String getFormatType()
      Description copied from interface: IUnit
      Mandatory unit type. The type should be unique across all units. It should be the same as the identifier's type.
      Specified by:
      getFormatType in interface IUnit
      Returns:
      the non-null unit type
    • getFormatter

      public IUnitFormatter getFormatter()
      Description copied from interface: IUnit
      Retrieve a fresh formatter for that unit. Formatters are used to produce document outputs, that represent the unit in whole or in part.

      The unit must be processed before calling this method.

      Specified by:
      getFormatter in interface IUnit
      Returns:
      a new formatter, never null
    • getIconData

      public byte[] getIconData()
      Description copied from interface: IUnit
      The icon bytes representing units of such type. Typically, the data represents a 16x16 BMP or PNG image. Clients may use this data to represent labels for such units in a graphical way.
      Specified by:
      getIconData in interface IUnit
      Returns:
      the BMP or PNG bytes of an icon
    • getUid

      public long getUid()
      Description copied from interface: IUnit
      Retrieve an identifier that uniquely identifies the unit within its project.
      Specified by:
      getUid in interface IUnit
      Returns:
      a strictly positive long integer
    • getName

      public String getName()
      Description copied from interface: IUnit
      Get the unit name.
      Specified by:
      getName in interface IUnit
      Specified by:
      getName in interface IUnitCreator
      Returns:
      the unit name
    • getRealName

      public String getRealName()
      Description copied from interface: IUnit
      Retrieve the optional real unit name.
      Specified by:
      getRealName in interface IUnit
      Returns:
      potentially null
    • setRealName

      public void setRealName(String name)
      Description copied from interface: IUnit
      Set the optional unit's real name.
      Specified by:
      setRealName in interface IUnit
    • getNotes

      public String getNotes()
      Description copied from interface: IUnit
      Get user-defined notes. The notes can be textual data of any sort.
      Specified by:
      getNotes in interface IUnit
      Returns:
      the notes
    • getNotificationManager

      public IUnitNotificationManager getNotificationManager()
      Description copied from interface: IUnit
      Get a reference to the notification manager.
      Specified by:
      getNotificationManager in interface IUnit
      Returns:
      the notification manager, never null
    • getParent

      public IUnitCreator getParent()
      Description copied from interface: IUnit
      Retrieve the creator (or parent) of this unit. It can be a parent IUnit or an IArtifact, for top-level units.
      Specified by:
      getParent in interface IUnit
      Specified by:
      getParent in interface IUnitCreator
      Returns:
      the parent
    • getPropertyDefinitionManager

      public IPropertyDefinitionManager getPropertyDefinitionManager()
      Description copied from interface: IUnit
      Retrieve the PDM used by this unit. For consistency, it is recommend that all units of a given type return equivalent PDMs.
      Specified by:
      getPropertyDefinitionManager in interface IUnit
      Returns:
      the property definition manager
    • getPropertyManager

      public IPropertyManager getPropertyManager()
      Description copied from interface: IUnit
      Retrieve the PM used by this unit.
      Specified by:
      getPropertyManager in interface IUnit
      Returns:
      the property manager
    • getStatus

      public String getStatus()
      Description copied from interface: IUnit
      Get the status for the unit. Plugins should set a status if processing failed. Implementors must notify their listeners by issuing a J.UnitStatusChanged event.
      Specified by:
      getStatus in interface IUnit
      Returns:
      a status string, used by clients to inform users about the status of this unit. null signifies that the unit is in an OK or unknown state
    • getUnitProcessor

      public IUnitProcessor getUnitProcessor()
      Description copied from interface: IUnit
      Retrieve the unit processor used by this unit.
      Specified by:
      getUnitProcessor in interface IUnit
      Returns:
      the processor
    • isProcessed

      public boolean isProcessed()
      Description copied from interface: IUnit
      Verify if the unit was successfully processed.
      Specified by:
      isProcessed in interface IUnit
      Returns:
      true if the unit was successfully processed
    • isStale

      public boolean isStale()
      Description copied from interface: IUnit
      Determine whether the unit was successfully processed, but is now considered to be stale (outdated content). Re-processing is encouraged but not mandatory.

      The result is irrelevant if IUnit.isProcessed() is false.

      Specified by:
      isStale in interface IUnit
      Returns:
      whether the unit stale; this method should return false if IUnit.isProcessed() returns false
    • process

      public boolean process()
      Description copied from interface: IUnit
      Process the unit. Processing almost always involves parsing, eg, for a code disassembler unit, processing could mean disassembling machine code. This method is called by the unit producer, typically, those are:
      • a unit identifier who successfully identified input data, and who was later called by a processor
      • a parent unit doing the identification itself, and calling a child unit process() directly
      Specified by:
      process in interface IUnit
      Returns:
      true if processing is or was successful (in the latter case, process() should do nothing but return true), or false is processing failed. The unit should also notify clients by issuing a J.UnitProcessed event. If processing succeeded, subsequent calls to IUnit.isProcessed() should return true.
    • removeListener

      public void removeListener(IEventListener listener)
      Description copied from interface: IEventSource
      Unregister a listener. If the implementor allows duplicates in addListener(), it should deal with those consistently.
      Specified by:
      removeListener in interface IEventSource
      Parameters:
      listener - the listener to be removed
    • setName

      public void setName(String name)
      Description copied from interface: IUnit
      Set the unit name.
      Specified by:
      setName in interface IUnit
      Parameters:
      name - the unit name
    • setNotes

      public void setNotes(String notes)
      Description copied from interface: IUnit
      Set user-defined notes. The notes can be textual data of any sort.
      Specified by:
      setNotes in interface IUnit
      Parameters:
      notes - the notes
    • setParent

      public void setParent(IUnitCreator parent)
      Description copied from interface: IUnit
      Set the parent unit or artifact.
      Specified by:
      setParent in interface IUnit
      Parameters:
      parent - the parent
    • setParentSource

      public void setParentSource(IEventSource parentSource)
      Description copied from interface: IEventSource
      Set a parent source.
      Specified by:
      setParentSource in interface IEventSource
      Parameters:
      parentSource - the optional parent source
    • initializePropertyObjects

      public void initializePropertyObjects(IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm)
      Description copied from interface: IUnit
      Initialize the property manager and property definition manager used by this unit.

      Code that needs access to the unit's property manager right after deserialization can safely do so after execution of this method.

      Specified by:
      initializePropertyObjects in interface IUnit
      Parameters:
      parent - the parent unit or artifact
      processor - the processor
      pdm - the property definition manager for units of this type
    • postDeserialization

      public void postDeserialization(IRuntimeProject prj)
      Description copied from interface: IUnit
      This method is called by the engines after a unit has been fully deserialized. Final repairs (eg, retrieving and re-connecting global objects that were not serialized) may be done by this method. The unit's project and engines are now accessible.
      Specified by:
      postDeserialization in interface IUnit
      Parameters:
      prj - the project to which this unit belongs
    • setUnitProcessor

      public void setUnitProcessor(IUnitProcessor unitProcessor)
      Description copied from interface: IUnit
      Set the unit processor. This method is called by the managing project or (engines) context.
      Specified by:
      setUnitProcessor in interface IUnit
      Parameters:
      unitProcessor - the unit processor
    • getContributions

      public List<IUnitContribution> getContributions()
      Description copied from interface: IUnit
      Get the list of contributions attached to the unit.
      Specified by:
      getContributions in interface IUnit
      Returns:
    • getInterpreters

      public List<IUnitInterpreter> getInterpreters()
      Description copied from interface: IUnit
      Get the list of command interpreters attached to the unit.
      Specified by:
      getInterpreters in interface IUnit
      Returns:
      the interpreter, null if none
    • dispose

      public void dispose()
      Description copied from interface: IUnit
      Dispose of the resources used by this unit.
      Specified by:
      dispose in interface IUnit
    • isDisposed

      public boolean isDisposed()
      Description copied from interface: IUnit
      Indicate if the unit has been disposed
      Specified by:
      isDisposed in interface IUnit
      Returns:
      disposal status
      See Also:
    • removeChild

      public void removeChild(IUnit unit)
      Description copied from interface: IUnit
      Remove a direct child of the current unit.
      Specified by:
      removeChild in interface IUnit
      Parameters:
      unit - the unit removed
    • addChild

      public void addChild(IUnit unit, boolean persisted)
      Description copied from interface: IUnit
      Add a child unit to this unit. Implementations must check for duplicate and also notify clients by emitting the right event.
      Specified by:
      addChild in interface IUnit
      Parameters:
      unit - the child unit
      persisted - true if the unit should be persisted upon project saving
    • isTransientChild

      public boolean isTransientChild(IUnit unit)
      Description copied from interface: IUnit
      Check if a child unit is transient. By default, children units are persisted.
      Specified by:
      isTransientChild in interface IUnit
      Parameters:
      unit - the child unit
      Returns:
      true if the child is non-persisted
    • addChild

      public void addChild(IUnit unit)
      Description copied from interface: IUnit
      Register a child unit to this unit. The child unit is persisted. Same as addChild(child, true).
      Specified by:
      addChild in interface IUnit
      Parameters:
      unit - the child unit
    • generateQuickState

      public IQuickStateObject generateQuickState()
      Description copied from interface: IUnit
      Save the state of this unit (it may be a partial state). Implementation of this method is optional.
      Specified by:
      generateQuickState in interface IUnit
      Returns:
      a state object or null if unsupported
    • setData

      public void setData(Object key, Object value, boolean persist)
      Description copied from interface: IUserDataSupport
      Store a piece of custom unit data.
      Specified by:
      setData in interface IUserDataSupport
      Parameters:
      key - non-null key
      value - optional value (may be null)
      persist - if false, the piece of data is transient and will not be persisted to disk when saving the project to a JEB database; if true, the piece of data will be persisted, in which case, user of this method must ensure that both key and value are serializable; if unsure, it is recommended to either not persist the data, or if persistence is a requirement, use only key/value types that are guaranteed to be persisted, such as any basic types (String, boxed primitive types, primitive types, arrays or lists of those, etc.)
    • getData

      public Object getData(Object key)
      Description copied from interface: IUserDataSupport
      Retrieve a piece of custom unit data.
      Specified by:
      getData in interface IUserDataSupport
      Parameters:
      key - non-null key
      Returns:
      value (null may indicate that the key-value pair is not present or that the stored value is null)
    • clearAllData

      public void clearAllData(Object key)
      Description copied from interface: IUserDataSupport
      Remove all pieces of custom unit data.
      Specified by:
      clearAllData in interface IUserDataSupport
    • getAllData

      public Map<Object,Object> getAllData()
      Description copied from interface: IUserDataSupport
      Retrieve a map containing all key-value pairs of of custom unit data.
      Specified by:
      getAllData in interface IUserDataSupport
      Returns:
      a map