Package com.pnfsoftware.jeb.core.units
Class AbstractUnit
java.lang.Object
com.pnfsoftware.jeb.core.events.JebEventSource
com.pnfsoftware.jeb.core.units.AbstractUnit
- All Implemented Interfaces:
IUnitCreator,IUserDataSupport,IUnit,IEventSource
- Direct Known Subclasses:
AbstractBinaryUnit,AbstractInteractiveUnit,ContainerUnit
Skeleton implementation for an
IUnit. It is highly recommended that plugins extend this
class or one of the its subclasses instead of implementing IUnit entirely.
Implementors must implement their own constructor; the default constructor is used for deserialization only. Example of a typical unit constructor:
public DerivedClass(String name, IUnitProcessor unitProcessor, IUnitCreator parent,
IPropertyDefinitionManager pdm) {
super(..., name, unitProcessor, parent, pdm);
...
}
Notes on persistence:
- By default,
canBePersisted()returns true. - This class persist the non-transient children units only.
- The formatter allows storing of persisted and transient presentation. Refer to
IUnitFormatterfor more information. - Derived classes that wish to implement custom persistence should implement a custom serialization methods.
-
Field Summary
Fields inherited from class com.pnfsoftware.jeb.core.events.JebEventSource
onEventCallCount -
Constructor Summary
ConstructorsConstructorDescriptionAbstractUnit(String formatType, String name, IUnit parent) Build a new child from parentIUnitAbstractUnit(String formatType, String name, IUnitProcessor unitProcessor, IUnitCreator parent, IPropertyDefinitionManager pdm) Initialize a new unit object. -
Method Summary
Modifier and TypeMethodDescriptionvoidSub-classes overriding this method must override related methods consistently.voidSub-classes overriding this method must override related methods consistently.protected voidfinal voidaddNotification(IUnitNotification notification) booleanDetermine if this unit can be persisted.voidclearAllData(Object key) Remove all pieces of custom unit data.voiddispose()Sub-classes overriding this method must call thesuperimplementation last.protected voidfinalize()The default implementation returns null.Retrieve a map containing all key-value pairs of of custom unit data.Sub-classes overriding this method must override related methods consistently.Get the list of contributions attached to the unit.longGet 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.getLock()The default implementation returns a pass-through lock that never locks.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.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.longgetUid()Retrieve an identifier that uniquely identifies the unit within itsproject.Retrieve the unit processor used by this unit.booleanvoidinitializePropertyObjects(IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm) Overrides are allowed.voidRESERVED FOR INTERNAL USE.booleanfinal booleanIndicate if the unit has been disposedbooleanVerify if the unit was successfully processed.booleanisStale()The default implementation returnsfalse.booleanisTransientChild(IUnit unit) Sub-classes overriding this method must override related methods consistently.voidLog an error message using the current class logger, and optionally create a persistent unit notification as well.voidLog an exception using the current class logger.voidLog an information message using the current class logger, and optionally create a persistent unit notification as well.voidLog a trace message using the current class logger.voidLog a warning message using the current class logger, and optionally create a persistent unit notification as well.voidonPropertyChange(String fqPropertyName) This method is called when a project property is changed.voidTo be overridden by subclasses if necessary.booleanprocess()The default implementation callsprocessInternal(), and makes sure that a status string is set on error, or nullified on success.protected booleanPlugins may override this method instead of the traditionalprocess().final voidremoveChild(IUnit unit) Sub-classes overriding this method must override related methods consistently.protected voidremoveChild(IUnit unit, boolean notify) booleanprotected booleanvoidStore a piece of custom unit data.voidSet the unit name.voidSet user-defined notes.voidsetParent(IUnitCreator parent) Set the parent unit or artifact.final voidsetProcessed(boolean processed) Mark the unit as processed and, if processed, notify the client.voidsetProcessed(boolean processed, boolean notify) Mark the unit as processed and, if processed, optionally notify clients by issuing aJ.UnitChangeevent.voidsetRealName(String name) Set the optional unit's real name.final voidSet the plugin status.voidvoidsetUnitProcessor(IUnitProcessor processor) Set the unit processor.toString()Methods inherited from class com.pnfsoftware.jeb.core.events.JebEventSource
addListener, countListeners, getListeners, getParentSource, insertListener, notifyListeners, notifyListeners, notifyListeners, removeListener, setParentSourceMethods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.pnfsoftware.jeb.util.events.IEventSource
addListener, countListeners, getListeners, getParentSource, insertListener, notifyListeners, removeListener, setParentSourceMethods inherited from interface com.pnfsoftware.jeb.core.units.IUnit
execprvfunc, getExtraInputs, getInput, getParentArtifact, getParentProject, notifyGenericChange
-
Constructor Details
-
AbstractUnit
Build a new child from parentIUnit- Parameters:
formatType- the mandatory format type, normally one provided by the identifiername- the unit nameparent- the parent unit
-
AbstractUnit
public AbstractUnit(String formatType, String name, IUnitProcessor unitProcessor, IUnitCreator parent, IPropertyDefinitionManager pdm) Initialize a new unit object.The PDM is provided by the IUnitIdentifier (if created from there). Else, it can be provided manually by the caller. If pdm is null, an unattached PDM will be created with no property and a region name matching the unit formatType.
- Parameters:
formatType- the mandatory format type, normally one provided by the identifiername- the desired unit name; if null or blank, a name will be auto-generated; slashes and back-slashes will be replaced by underscores; leading and trailing WSP characters will be removedunitProcessor- the unit processorparent- the parent unit or artifact; if null, this unit cannot be attached to a project; practically, this field should never be nullpdm- optional an optional property definition manager
-
-
Method Details
-
initializePropertyObjects
public void initializePropertyObjects(IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm) Overrides are allowed. If so,super.initializePropertyObjects()must be called first.- Specified by:
initializePropertyObjectsin interfaceIUnit- Parameters:
parent- the parent unit or artifactprocessor- the processorpdm- the property definition manager for units of this type
-
postDeserialization
To be overridden by subclasses if necessary. The default implementation does nothing.- Specified by:
postDeserializationin interfaceIUnit- Parameters:
prj- the project to which this unit belongs
-
onPropertyChange
This method is called when a project property is changed. The default implementation does nothing: Implementors may safely override. Note that project-wide properties are being tracked, not solely those defined by the current unit's identifier. -
getPropertyDefinitionManager
Description copied from interface:IUnitRetrieve the PDM used by this unit. For consistency, it is recommend that all units of a given type return equivalent PDMs.- Specified by:
getPropertyDefinitionManagerin interfaceIUnit- Returns:
- the property definition manager
-
getPropertyManager
Description copied from interface:IUnitRetrieve the PM used by this unit.- Specified by:
getPropertyManagerin interfaceIUnit- Returns:
- the property manager
-
getUid
public long getUid()Description copied from interface:IUnitRetrieve an identifier that uniquely identifies the unit within itsproject. -
getFormatType
Description copied from interface:IUnitMandatory unit type. The type should be unique across all units. It should be the same as theidentifier'stype.- Specified by:
getFormatTypein interfaceIUnit- Returns:
- the non-null unit type
-
getIconData
public byte[] getIconData()Description copied from interface:IUnitThe 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:
getIconDatain interfaceIUnit- Returns:
- the BMP or PNG bytes of an icon
-
setUnitProcessor
Description copied from interface:IUnitSet the unit processor. This method is called by the managing project or (engines) context.- Specified by:
setUnitProcessorin interfaceIUnit- Parameters:
processor- the unit processor
-
getUnitProcessor
Description copied from interface:IUnitRetrieve the unit processor used by this unit.- Specified by:
getUnitProcessorin interfaceIUnit- Returns:
- the processor
-
getCreationTimestamp
public long getCreationTimestamp()Description copied from interface:IUnitGet the date of creation of this unit.- Specified by:
getCreationTimestampin interfaceIUnit- Returns:
- the creation timestamp in milliseconds since the unix epoch
-
getName
Description copied from interface:IUnitGet the unit name.- Specified by:
getNamein interfaceIUnit- Specified by:
getNamein interfaceIUnitCreator- Returns:
- the unit name
-
setName
Description copied from interface:IUnitSet the unit name. -
getRealName
Description copied from interface:IUnitRetrieve the optional real unit name.- Specified by:
getRealNamein interfaceIUnit- Returns:
- potentially null
-
setRealName
Description copied from interface:IUnitSet the optional unit's real name.- Specified by:
setRealNamein interfaceIUnit
-
getNotes
Description copied from interface:IUnitGet user-defined notes. The notes can be textual data of any sort. -
setNotes
Description copied from interface:IUnitSet user-defined notes. The notes can be textual data of any sort. -
setParent
Description copied from interface:IUnitSet the parent unit or artifact. -
getParent
Description copied from interface:IUnitRetrieve the creator (or parent) of this unit. It can be a parentIUnitor anIArtifact, for top-level units.- Specified by:
getParentin interfaceIUnit- Specified by:
getParentin interfaceIUnitCreator- Returns:
- the parent
-
getStatus
Description copied from interface:IUnitGet the status for the unit. Plugins should set a status if processing failed. Implementors must notify their listeners by issuing aJ.UnitStatusChangedevent. -
setStatus
Set the plugin status. This method also takes care of notifying listeners by issuing aJ.UnitStatusChangedevent.- Parameters:
status- the new status
-
setStatus
-
getLock
The default implementation returns a pass-through lock that never locks. -
isProcessed
public boolean isProcessed()Description copied from interface:IUnitVerify if the unit was successfully processed.- Specified by:
isProcessedin interfaceIUnit- Returns:
- true if the unit was successfully processed
-
isStale
public boolean isStale()The default implementation returnsfalse.- Specified by:
isStalein interfaceIUnit- Returns:
- whether the unit
stale; this method should return false ifIUnit.isProcessed()returns false
-
setProcessed
public final void setProcessed(boolean processed) Mark the unit as processed and, if processed, notify the client. Same assetProcessed(processed, true).- Parameters:
processed-
-
setProcessed
public void setProcessed(boolean processed, boolean notify) Mark the unit as processed and, if processed, optionally notify clients by issuing aJ.UnitChangeevent. Implementors wishing to override this method must also overrideisProcessed().- Parameters:
processed-
-
process
public boolean process()The default implementation callsprocessInternal(), and makes sure that a status string is set on error, or nullified on success. processInternal() is never called isisProcessed()returns true.Plugins may decide to override this method, if they need finer control over processing (we recommend overriding processInternal(); in that case, processInternal() should be ignored.
- Specified by:
processin 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.UnitProcessedevent. If processing succeeded, subsequent calls toIUnit.isProcessed()should return true.
-
processInternal
protected boolean processInternal()Plugins may override this method instead of the traditionalprocess(). (If this method is overridden, implementors must NOT overrideprocess().) This method is called only ifisProcessed()returnedfalse.- Returns:
- success indicator
-
getDescription
Description copied from interface:IUnitGet a description string for that unit.The unit must be processed before calling this method.
- Specified by:
getDescriptionin interfaceIUnit- Returns:
- a description string
-
canBePersisted
public boolean canBePersisted()Description copied from interface:IUnitDetermine 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:
canBePersistedin interfaceIUnit- Returns:
- true if the unit can be persisted, false if the unit must not be persisted
-
hasChildren
public boolean hasChildren() -
getChildren
Sub-classes overriding this method must override related methods consistently.- Specified by:
getChildrenin interfaceIUnit- Returns:
- the children or an empty list, never null
-
addChild
Sub-classes overriding this method must override related methods consistently. -
addChild
Sub-classes overriding this method must override related methods consistently. -
addChild
-
isTransientChild
Sub-classes overriding this method must override related methods consistently.- Specified by:
isTransientChildin interfaceIUnit- Parameters:
unit- the child unit- Returns:
- true if the child is non-persisted
-
internalSwapChildren
public void internalSwapChildren()RESERVED FOR INTERNAL USE. -
dispose
public void dispose()Sub-classes overriding this method must call thesuperimplementation last. -
isDisposed
public final boolean isDisposed()Description copied from interface:IUnitIndicate if the unit has been disposed- Specified by:
isDisposedin interfaceIUnit- Returns:
- disposal status
- See Also:
-
isDeserialized
public boolean isDeserialized() -
removeChild
Sub-classes overriding this method must override related methods consistently.- Specified by:
removeChildin interfaceIUnit- Parameters:
unit- the unit removed
-
removeChild
-
setChild
-
setChild
-
getFormatter
Description copied from interface:IUnitRetrieve 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:
getFormatterin interfaceIUnit- Returns:
- a new formatter, never null
-
getNotificationManager
Description copied from interface:IUnitGet a reference to the notification manager.- Specified by:
getNotificationManagerin interfaceIUnit- Returns:
- the notification manager, never null
-
addNotification
-
getContributions
Description copied from interface:IUnitGet the list of contributions attached to the unit.- Specified by:
getContributionsin interfaceIUnit- Returns:
-
getInterpreters
Description copied from interface:IUnitGet the list of command interpreters attached to the unit.- Specified by:
getInterpretersin interfaceIUnit- Returns:
- the interpreter, null if none
-
generateQuickState
The default implementation returns null.- Specified by:
generateQuickStatein interfaceIUnit- Returns:
- a state object or null if unsupported
-
toString
-
logTrace
Log a trace message using the current class logger.- Parameters:
format-params-
-
logInfo
Log an information message using the current class logger, and optionally create a persistent unit notification as well.- Parameters:
recordNotification-format-params-
-
logWarn
Log a warning message using the current class logger, and optionally create a persistent unit notification as well.- Parameters:
recordNotification-format-params-
-
logError
Log an error message using the current class logger, and optionally create a persistent unit notification as well.- Parameters:
recordNotification-format-params-
-
logException
Log an exception using the current class logger.- Parameters:
e-
-
setData
Description copied from interface:IUserDataSupportStore a piece of custom unit data.- Specified by:
setDatain 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:IUserDataSupportRetrieve a piece of custom unit data.- Specified by:
getDatain 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:IUserDataSupportRemove all pieces of custom unit data.- Specified by:
clearAllDatain interfaceIUserDataSupport
-
getAllData
Description copied from interface:IUserDataSupportRetrieve a map containing all key-value pairs of of custom unit data.- Specified by:
getAllDatain interfaceIUserDataSupport- Returns:
- a map
-
finalize
-