public abstract class

AbstractUnit

extends JebEventSource
implements IUnit
java.lang.Object
   ↳ com.pnfsoftware.jeb.core.events.JebEventSource
     ↳ com.pnfsoftware.jeb.core.units.AbstractUnit
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

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 IUnitFormatter for more information.
  • Derived classes that wish to implement custom persistence should implement a custom deserializer.

Summary

Public Constructors
AbstractUnit(String formatType, String name, IUnit parent)
Build a new child from parent IUnit
AbstractUnit(String formatType, String name, IUnitProcessor unitProcessor, IUnitCreator parent, IPropertyDefinitionManager pdm)
Initialize a new unit object.
Protected Constructors
AbstractUnit()
Public Methods
void addChild(IUnit unit)
Sub-classes overriding this method must override related methods consistently.
void addChild(IUnit unit, boolean persisted)
Sub-classes overriding this method must override related methods consistently.
void addChildUnit(IUnit unit)
Sub-classes overriding this method must override related methods consistently.
final void addNotification(IUnitNotification notification)
boolean canBePersisted()
Determine if this unit can be persisted.
void dispose()
Sub-classes overriding this method must override related methods consistently.
List<? extends IUnit> getChildren()
Sub-classes overriding this method must override related methods consistently.
ICommandInterpreter getCommandInterpreter()
Get a command interpreter provided by the unit, if any.
long getCreationTimestamp()
Get the date of creation of this unit.
String getDescription()
Get a description string for that unit.
String getFormatType()
Mandatory unit type.
IUnitFormatter getFormatter()
Retrieve a fresh formatter for that unit.
byte[] getIconData()
The icon bytes representing units of such type.
String getName()
Get the unit name.
String getNotes()
Get user-defined notes.
IUnitNotificationManager getNotificationManager()
Get a reference to the notification manager.
IUnitCreator getParent()
Retrieve the creator (or parent) of this unit.
IPropertyDefinitionManager getPropertyDefinitionManager()
Retrieve the PDM used by this unit.
IPropertyManager getPropertyManager()
Retrieve the PM used by this unit.
String getStatus()
Get the status for the unit.
IUnitProcessor getUnitProcessor()
Retrieve the unit processor used by this unit.
void initializePropertyObjects(IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm)
Overrides are allowed.
boolean isProcessed()
Verify if the unit was successfully processed.
boolean isTransientChild(IUnit unit)
Sub-classes overriding this method must override related methods consistently.
void onPropertyChange(String fqPropertyName)
This method is called when a project property is changed.
void removeChild(IUnit unit)
Sub-classes overriding this method must override related methods consistently.
void setName(String name)
Set the unit name.
void setNotes(String notes)
Set user-defined notes.
void setParent(IUnitCreator parent)
Set the parent unit or artifact.
final void setProcessed(boolean processed)
Mark the unit as processed and notify the client.
void setProcessed(boolean processed, boolean notify)
Mark the unit as processed and optionally notify clients by issuing a UnitChange event.
void setStatus(String status)
Set the plugin status.
void setStatus(String status, boolean notify)
void setUnitProcessor(IUnitProcessor processor)
Set the unit processor.
String toString()
Protected Methods
void addChild(IUnit unit, boolean persisted, boolean notify)
void removeChild(IUnit unit, boolean notify)
[Expand]
Inherited Methods
From class com.pnfsoftware.jeb.core.events.JebEventSource
From class java.lang.Object
From interface com.pnfsoftware.jeb.core.units.IUnit
From interface com.pnfsoftware.jeb.util.events.IEventSource

Public Constructors

public AbstractUnit (String formatType, String name, IUnit parent)

Build a new child from parent IUnit

Parameters
formatType the mandatory format type, normally one provided by the identifier
name the unit name
parent the parent unit

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 identifier
name the unit name
unitProcessor the unit processor
parent the parent unit or artifact
pdm optional an optional property definition manager

Protected Constructors

protected AbstractUnit ()

Public Methods

public void addChild (IUnit unit)

Sub-classes overriding this method must override related methods consistently.

Parameters
unit the child unit

public void addChild (IUnit unit, boolean persisted)

Sub-classes overriding this method must override related methods consistently.

Parameters
unit the child unit
persisted true if the unit should be persisted upon project saving

public void addChildUnit (IUnit unit)

Sub-classes overriding this method must override related methods consistently.

Parameters
unit the child unit

public final void addNotification (IUnitNotification notification)

public boolean canBePersisted ()

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.

Returns
  • true if the unit can be persisted, false if the unit must not be persisted

public void dispose ()

Sub-classes overriding this method must override related methods consistently.

public List<? extends IUnit> getChildren ()

Sub-classes overriding this method must override related methods consistently.

Returns
  • the children or an empty list, never null

public ICommandInterpreter getCommandInterpreter ()

Get a command interpreter provided by the unit, if any.

Returns
  • the interpreter, null if none

public long getCreationTimestamp ()

Get the date of creation of this unit.

Returns
  • the creation timestamp in milliseconds since the unix epoch

public String getDescription ()

Get a description string for that unit.

Returns
  • a description string

public String getFormatType ()

Mandatory unit type. The type should be unique across all units. It should be the same as the identifier's type.

Returns
  • the non-null unit type

public IUnitFormatter getFormatter ()

Retrieve a fresh formatter for that unit. Formatters are used to produce document outputs, that represent the unit in whole or in part.

Returns
  • a new formatter, never null

public byte[] getIconData ()

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.

Returns
  • the BMP or PNG bytes of an icon

public String getName ()

Get the unit name.

Returns
  • the unit name

public String getNotes ()

Get user-defined notes. The notes can be textual data of any sort.

Returns
  • the notes

public IUnitNotificationManager getNotificationManager ()

Get a reference to the notification manager.

Returns
  • the notification manager, never null

public IUnitCreator getParent ()

Retrieve the creator (or parent) of this unit. It can be a parent unit or a live artifact, for top-level units.

Returns
  • the parent

public IPropertyDefinitionManager getPropertyDefinitionManager ()

Retrieve the PDM used by this unit. For consistency, it is recommend that all units of a given type return equivalent PDMs.

Returns
  • the property definition manager

public IPropertyManager getPropertyManager ()

Retrieve the PM used by this unit.

Returns
  • the property manager

public String getStatus ()

Get the status for the unit. Plugins should set a status if processing failed. Implementors must notify their listeners by issuing a UnitStatusChanged event.

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

public IUnitProcessor getUnitProcessor ()

Retrieve the unit processor used by this unit.

Returns
  • the processor

public void initializePropertyObjects (IUnitCreator parent, IUnitProcessor processor, IPropertyDefinitionManager pdm)

Overrides are allowed. If so, super.initializePropertyObjects() must be called first.

Parameters
parent the parent unit or artifact
processor the processor
pdm the property definition manager for units of this type

public boolean isProcessed ()

Verify if the unit was successfully processed.

Returns
  • true if the unit was successfully processed

public boolean isTransientChild (IUnit unit)

Sub-classes overriding this method must override related methods consistently.

Parameters
unit the child unit
Returns
  • true if the child is non-persisted

public void onPropertyChange (String fqPropertyName)

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.

public void removeChild (IUnit unit)

Sub-classes overriding this method must override related methods consistently.

Parameters
unit the unit removed

public void setName (String name)

Set the unit name.

Parameters
name the unit name

public void setNotes (String notes)

Set user-defined notes. The notes can be textual data of any sort.

Parameters
notes the notes

public void setParent (IUnitCreator parent)

Set the parent unit or artifact.

Parameters
parent the parent

public final void setProcessed (boolean processed)

Mark the unit as processed and notify the client. Same as setProcessed(processed, true).

public void setProcessed (boolean processed, boolean notify)

Mark the unit as processed and optionally notify clients by issuing a UnitChange event. Implementors wishing to override this method must also override isProcessed() .

public void setStatus (String status)

Set the plugin status. This method also takes care of notifying listeners by issuing a UnitStatusChanged event.

Parameters
status the new status

public void setStatus (String status, boolean notify)

public void setUnitProcessor (IUnitProcessor processor)

Set the unit processor. This method is called by the managing project or (engines) context.

Parameters
processor the unit processor

public String toString ()

Protected Methods

protected void addChild (IUnit unit, boolean persisted, boolean notify)

protected void removeChild (IUnit unit, boolean notify)