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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Register a child unit to this unit.void
Add a child unit to this unit.void
addListener
(IEventListener listener) Register a listener.boolean
Determine if this unit can be persisted.void
clearAllData
(Object key) Remove all pieces of custom unit data.int
Get the numbers of objects listening to this event source.void
dispose()
Dispose of the resources used by this unit.Save the state of this unit (it may be a partial state).Retrieve a map containing all key-value pairs of of custom unit data.Retrieve a read-only list of all direct children units.Get the list of contributions attached to the unit.long
Get the date of creation of this unit.Retrieve a piece of custom unit data.Get a description string for that unit.Retrieve a fresh formatter for that unit.Mandatory unit type.byte[]
The icon bytes representing units of such type.Get the list of command interpreters attached to the unit.List<? extends IEventListener>
Get a copy of the list of listeners.getLock()
Get the unit lock.getName()
Get the unit name.getNotes()
Get user-defined notes.Get a reference to the notification manager.Retrieve the creator (or parent) of this unit.Get the parent source.Retrieve the PDM used by this unit.Retrieve the PM used by this unit.Retrieve the optional real unit name.Get the status for the unit.long
getUid()
Retrieve an identifier that uniquely identifies the unit within itsproject
.Retrieve the unit processor used by this unit.getWrap()
Return the wrappedIUnit
void
initializePropertyObjects
(IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm) Initialize the property manager and property definition manager used by this unit.void
insertListener
(int index, IEventListener listener) Register a listener.boolean
Indicate if the unit has been disposedboolean
Verify if the unit was successfully processed.boolean
isStale()
Determine whether the unit was successfully processed, but is now considered to be stale (outdated content).boolean
isTransientChild
(IUnit unit) Check if a child unit is transient.void
Notify listeners that an event has occurred.void
This method is called by the engines after a unit has been fully deserialized.boolean
process()
Process the unit.void
removeChild
(IUnit unit) Remove a direct child of the current unit.void
removeListener
(IEventListener listener) Unregister a listener.void
Store a piece of custom unit data.void
Set the unit name.void
Set user-defined notes.void
setParent
(IUnitCreator parent) Set the parent unit or artifact.void
setParentSource
(IEventSource parentSource) Set a parent source.void
setRealName
(String name) Set the optional unit's real name.void
setUnitProcessor
(IUnitProcessor unitProcessor) Set the unit processor.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.pnfsoftware.jeb.core.units.IUnit
getExtraInputs, getInput, getParentArtifact, getParentProject, notifyGenericChange
-
Constructor Details
-
WrapperUnit
- Parameters:
unit
-IUnit
to be delegatedprovider
- provider that extends the unit behavior
-
-
Method Details
-
getWrap
Return the wrappedIUnit
-
addListener
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 interfaceIEventSource
- Parameters:
listener
- a listener of events generated by this source
-
insertListener
Description copied from interface:IEventSource
Register a listener. The implementor may allow duplicates.- Specified by:
insertListener
in interfaceIEventSource
- Parameters:
index
- insertion pointlistener
- 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 interfaceIEventSource
- Returns:
- the number of listeners
-
getListeners
Description copied from interface:IEventSource
Get a copy of the list of listeners.- Specified by:
getListeners
in interfaceIEventSource
- Returns:
-
getParentSource
Description copied from interface:IEventSource
Get the parent source.- Specified by:
getParentSource
in interfaceIEventSource
- Returns:
- the parent source, or null if none
-
notifyListeners
Description copied from interface:IEventSource
Notify listeners that an event has occurred.- Specified by:
notifyListeners
in interfaceIEventSource
- 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 interfaceIUnit
- Returns:
- true if the unit can be persisted, false if the unit must not be persisted
-
getChildren
Description copied from interface:IUnit
Retrieve a read-only list of all direct children units.- Specified by:
getChildren
in interfaceIUnit
- Returns:
- the children or an empty list, never null
-
getLock
Description copied from interface:IUnit
Get the unit lock. -
getCreationTimestamp
public long getCreationTimestamp()Description copied from interface:IUnit
Get the date of creation of this unit.- Specified by:
getCreationTimestamp
in interfaceIUnit
- Returns:
- the creation timestamp in milliseconds since the unix epoch
-
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 interfaceIUnit
- Returns:
- a description string
-
getFormatType
Description copied from interface:IUnit
Mandatory unit type. The type should be unique across all units. It should be the same as theidentifier
'stype
.- Specified by:
getFormatType
in interfaceIUnit
- Returns:
- the non-null unit type
-
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 interfaceIUnit
- 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 interfaceIUnit
- 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 itsproject
. -
getName
Description copied from interface:IUnit
Get the unit name.- Specified by:
getName
in interfaceIUnit
- Specified by:
getName
in interfaceIUnitCreator
- Returns:
- the unit name
-
getRealName
Description copied from interface:IUnit
Retrieve the optional real unit name.- Specified by:
getRealName
in interfaceIUnit
- Returns:
- potentially null
-
setRealName
Description copied from interface:IUnit
Set the optional unit's real name.- Specified by:
setRealName
in interfaceIUnit
-
getNotes
Description copied from interface:IUnit
Get user-defined notes. The notes can be textual data of any sort. -
getNotificationManager
Description copied from interface:IUnit
Get a reference to the notification manager.- Specified by:
getNotificationManager
in interfaceIUnit
- Returns:
- the notification manager, never null
-
getParent
Description copied from interface:IUnit
Retrieve the creator (or parent) of this unit. It can be a parentIUnit
or anIArtifact
, for top-level units.- Specified by:
getParent
in interfaceIUnit
- Specified by:
getParent
in interfaceIUnitCreator
- Returns:
- the parent
-
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 interfaceIUnit
- Returns:
- the property definition manager
-
getPropertyManager
Description copied from interface:IUnit
Retrieve the PM used by this unit.- Specified by:
getPropertyManager
in interfaceIUnit
- Returns:
- the property manager
-
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 aJ.UnitStatusChanged
event. -
getUnitProcessor
Description copied from interface:IUnit
Retrieve the unit processor used by this unit.- Specified by:
getUnitProcessor
in interfaceIUnit
- Returns:
- the processor
-
isProcessed
public boolean isProcessed()Description copied from interface:IUnit
Verify if the unit was successfully processed.- Specified by:
isProcessed
in interfaceIUnit
- 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()
isfalse
.- Specified by:
isStale
in interfaceIUnit
- Returns:
- whether the unit
stale
; this method should return false ifIUnit.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 interfaceIUnit
- 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 toIUnit.isProcessed()
should return true.
-
removeListener
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 interfaceIEventSource
- Parameters:
listener
- the listener to be removed
-
setName
Description copied from interface:IUnit
Set the unit name. -
setNotes
Description copied from interface:IUnit
Set user-defined notes. The notes can be textual data of any sort. -
setParent
Description copied from interface:IUnit
Set the parent unit or artifact. -
setParentSource
Description copied from interface:IEventSource
Set a parent source.- Specified by:
setParentSource
in interfaceIEventSource
- 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 interfaceIUnit
- Parameters:
parent
- the parent unit or artifactprocessor
- the processorpdm
- the property definition manager for units of this type
-
postDeserialization
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 interfaceIUnit
- Parameters:
prj
- the project to which this unit belongs
-
setUnitProcessor
Description copied from interface:IUnit
Set the unit processor. This method is called by the managing project or (engines) context.- Specified by:
setUnitProcessor
in interfaceIUnit
- Parameters:
unitProcessor
- the unit processor
-
getContributions
Description copied from interface:IUnit
Get the list of contributions attached to the unit.- Specified by:
getContributions
in interfaceIUnit
- Returns:
-
getInterpreters
Description copied from interface:IUnit
Get the list of command interpreters attached to the unit.- Specified by:
getInterpreters
in interfaceIUnit
- Returns:
- the interpreter, null if none
-
dispose
public void dispose()Description copied from interface:IUnit
Dispose of the resources used by this unit. -
isDisposed
public boolean isDisposed()Description copied from interface:IUnit
Indicate if the unit has been disposed- Specified by:
isDisposed
in interfaceIUnit
- Returns:
- disposal status
- See Also:
-
removeChild
Description copied from interface:IUnit
Remove a direct child of the current unit.- Specified by:
removeChild
in interfaceIUnit
- Parameters:
unit
- the unit removed
-
addChild
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. -
isTransientChild
Description copied from interface:IUnit
Check if a child unit is transient. By default, children units are persisted.- Specified by:
isTransientChild
in interfaceIUnit
- Parameters:
unit
- the child unit- Returns:
- true if the child is non-persisted
-
addChild
Description copied from interface:IUnit
Register a child unit to this unit. The child unit is persisted. Same asaddChild(child, true)
. -
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 interfaceIUnit
- Returns:
- a state object or null if unsupported
-
setData
Description copied from interface:IUserDataSupport
Store a piece of custom unit data.- Specified by:
setData
in interfaceIUserDataSupport
- Parameters:
key
- non-null keyvalue
- 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 areserializable
; 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
Description copied from interface:IUserDataSupport
Retrieve a piece of custom unit data.- Specified by:
getData
in interfaceIUserDataSupport
- 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
Description copied from interface:IUserDataSupport
Remove all pieces of custom unit data.- Specified by:
clearAllData
in interfaceIUserDataSupport
-
getAllData
Description copied from interface:IUserDataSupport
Retrieve a map containing all key-value pairs of of custom unit data.- Specified by:
getAllData
in interfaceIUserDataSupport
- Returns:
- a map
-