ARoad0.gBase
Class FolderAbst

java.lang.Object
  extended by ARoad0.gBase.FolderAbst
All Implemented Interfaces:
BaseObject, BoundBean, Folder, ImmutableFolder, java.beans.PropertyChangeListener, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
ViewInBaseImpl, VirtualFolderImpl

public abstract class FolderAbst
extends java.lang.Object
implements Folder, java.io.Serializable

This abstract class is responsible for managing a folder of BaseObjects (even if most of the code is adapted to ACSObjects folder), where the members are added and removed from the container _without_ object deleting. This is the main differene with a Node which deletes its children when they are removed from it. It is a javabean with the following bound properties: 'OneBaseObjectInFolder' (when one base object is added or removed), 'Comment'. The subclasses have different managers on which they are registered: - BaseManagerImpl for ViewInBaseImpl, - ACSImpl for VirtualFolderImpl. The listeners are proper to the instance, outside gBase, transient (not serialized in this instance backup). They are called in any order. Excepted for 'OneBaseObjectInFolder', the listeners receive only a copy of the new value to protect the property. All the exceptions from the listeners are catched, and a dialog box is displayed to inform the user. Caution: no equals() nor clone() methods. See the Copyright.

See Also:
Serialized Form

Field Summary
protected  BaseError baseError_
           
protected  java.beans.PropertyChangeSupport changeSupport_
          manages all the property change listeners of this classes and its subclasses
protected  java.lang.String comment_
           
protected  boolean connectedToSeveralACS_
           
protected static int INITIAL_CAPACITY
           
protected static int INITIAL_CAPACITY_5
           
protected  java.util.List<ImmutableName> l_connectedACSNames_
          The connected ACS are the ACS of the BaseObjects, and it is empty if it is a view of non-ACSObjects like 'Architecture'.
protected  java.util.SortedMap<ImmutableName,BaseObject> m_BaseObjects_
           
protected  java.util.SortedMap<ImmutableName,ImmutableName> m_ObjectsNames_
          Used in the folder saving, to avoid some links to the ACSObjects, and then to not include the connected ACSs in the folder saving.
protected  ImmutableName name_
           
protected static int PRIME
           
static java.io.ObjectStreamField[] serialPersistentFields
          variable for the JDK 2 serialization.
private static long serialVersionUID
           
protected  java.lang.String type_
           
 
Constructor Summary
protected FolderAbst()
          Default constructor
protected FolderAbst(ImmutableName _name)
           
protected FolderAbst(ImmutableName _name, java.util.Map _m_BaseObjects)
          This constructor provides a FolderAbst instance from a map of base objects.
 
Method Summary
 void addEorBaseObject(BaseObject _obj)
          Adds a base object to the folder.
protected  void addOwnListening()
          This method registers the instance as a property event listener of 'OneBaseObject' on the ACS to detect the deleting of a folder object.
 void addPropertyChangeListener(java.beans.PropertyChangeListener _l)
          Adds a listener to the bean for the porperties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.
 void addPropertyChangeListener(java.lang.String _propertyName, java.beans.PropertyChangeListener _l)
          Add a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.
 boolean containsBaseObject(BaseObject _obj)
          Tests if a BaseObject is within the folder.
protected  void finalize()
          This method removes the object from the application space, but there is no guarantee that the JVM calls this method before the end of the application.
 void finalizeForBase()
          The folder is removed as an ACS listener.
protected  void finalizeForCopy()
          The folder is removed as an ACS listener.
protected  void finalizeFromDeserialization()
          The folder is NOT removed as an ACS listener.
protected  void firePropertyChange(java.lang.String _propertyName, java.lang.Object _oldValue, java.lang.Object _newValue)
          Fire an event to every registered listener, in any order, for a bound property.
 java.lang.String getComment()
           
 boolean getConnectedToSeveralACS()
          Always false when the elements are not ACSObjects, like in an Architecture view, or for a VirtualFolder.
 BaseError getEorBaseError()
           
 java.util.List<ImmutableName> getEorL_ConnectedACSNames()
           
 java.util.SortedMap<ImmutableName,BaseObject> getEorM_BaseObjects()
          Gets all the base objects displayed in this folder.
 ImmutableName getFullName()
          The full name is unique for the Access Road program.
 ImmutableName getName()
          The name is unique for the Access Road program only for the ACSObjects.
 java.lang.String getNickName()
          This short name is NOT unique for the Access Road program nor the ACS if it is an ACS object.
 long getSerialVersionUID()
           
 java.lang.String getType()
          The type is defined at the creation of the object, by a subclass.
 int hashCode()
           
 boolean isEmpty()
          Caution: an empty folder is not equals to a new FolderAbst() instance, since it may have an non-null name and other non-null properties.
protected  java.lang.String prepareAfterRestoring()
          This method is called by BaseManagerImpl after the opening of the folder, to update m_BaseObjects_ and l_connectedACSNames_ from m_ObjectsNames_, and to check the open ACS and their objects which are in the restored view.
protected  void prepareBeforeSaving()
          This method must be called by BaseManagerImpl before the saving of the folder, to update m_ObjectsNames_ from m_BaseObjects_ which is not saved nor updated.
protected  java.lang.String prepareDataAfterRestoring()
          This method updates m_BaseObjects_ and l_connectedACSNames_ from m_ObjectsNames_, and checks up the open ACS and their objects which are in the restored view.
 void propertyChange(java.beans.PropertyChangeEvent _evt)
          Observes the changes in the base objects list from the ACS.
 void removeEorBaseObject(BaseObject _obj)
          Removes a base object to the folder.
protected  void removeOwnListening()
          This method unregister the instance as a property event listener of 'OneBaseObject' on the relevant ACS.
 void removePropertyChangeListener(java.beans.PropertyChangeListener _l)
          remove a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.
 void removePropertyChangeListener(java.lang.String _propertyName, java.beans.PropertyChangeListener _l)
          remove a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.
 void setComment(java.lang.String _s)
          Sets any comment related to this folder.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ARoad0.gBaseInterface.BaseObject
equals
 

Field Detail

type_

protected java.lang.String type_

PRIME

protected static final int PRIME
See Also:
Constant Field Values

INITIAL_CAPACITY

protected static final int INITIAL_CAPACITY
See Also:
Constant Field Values

INITIAL_CAPACITY_5

protected static final int INITIAL_CAPACITY_5
See Also:
Constant Field Values

name_

protected ImmutableName name_

baseError_

protected BaseError baseError_

m_BaseObjects_

protected transient java.util.SortedMap<ImmutableName,BaseObject> m_BaseObjects_

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

comment_

protected java.lang.String comment_

connectedToSeveralACS_

protected boolean connectedToSeveralACS_

l_connectedACSNames_

protected transient java.util.List<ImmutableName> l_connectedACSNames_
The connected ACS are the ACS of the BaseObjects, and it is empty if it is a view of non-ACSObjects like 'Architecture'. Transient list wich is filled, by the constructor and at the opening of the folder from the items in m_ObjectsNames_, by the method prepareAfterRestoring().


m_ObjectsNames_

protected java.util.SortedMap<ImmutableName,ImmutableName> m_ObjectsNames_
Used in the folder saving, to avoid some links to the ACSObjects, and then to not include the connected ACSs in the folder saving. Used only to save and restore, and by BaseManagerImpl.getElementsOfOneView() directly without updating. No initializing at the instance creation, so the default value is null. Is correct only after the call of prepareBeforeSaving(). The key is the BaseObject name, and the value is the ACS name if it is an ACSObject.


changeSupport_

protected transient java.beans.PropertyChangeSupport changeSupport_
manages all the property change listeners of this classes and its subclasses


serialPersistentFields

public static final java.io.ObjectStreamField[] serialPersistentFields
variable for the JDK 2 serialization. m_BaseObjects_ and l_connectedACSNames_ are not persistent, and they are updated by prepareAfterRestoring().

Constructor Detail

FolderAbst

protected FolderAbst()
Default constructor


FolderAbst

protected FolderAbst(ImmutableName _name)
              throws CreateError
Parameters:
_name - is copied.
Throws:
CreateError - if the folder name is null, or if it contains a character that is not a letter

FolderAbst

protected FolderAbst(ImmutableName _name,
                     java.util.Map _m_BaseObjects)
              throws CreateError
This constructor provides a FolderAbst instance from a map of base objects. Called by ViewInBaseImpl and VirtualFolderImpl. l_connectedACSNames_ is filled only by ACSObject ACS names, so it does not work for Architecture views with only ACSs as elements.

Parameters:
_name - ImmutableName of the folder. It is copied.
_m_BaseObjects - is the map (name, object) of the folder objects. It is copied. May be null.
Throws:
CreateError - if _m_BaseObjects contains a null, no BaseObject, or empty-name object.
Method Detail

getSerialVersionUID

public long getSerialVersionUID()
Returns:
long the serialVersionUID used by the serialization process.

getName

public final ImmutableName getName()
Description copied from interface: BaseObject
The name is unique for the Access Road program only for the ACSObjects.

Specified by:
getName in interface BaseObject
Returns:
ImmutableName of this folder. Not null after the finalization.

getFullName

public ImmutableName getFullName()
The full name is unique for the Access Road program. Its is equal to the ACS name.

Specified by:
getFullName in interface BaseObject
Returns:
a copy of the name. Should be null after the finalization.

getNickName

public java.lang.String getNickName()
This short name is NOT unique for the Access Road program nor the ACS if it is an ACS object. It is often the last component name. Overridden in ViewInBaseImpl.

Specified by:
getNickName in interface BaseObject
Returns:
the nick name. May be null.

getEorBaseError

public BaseError getEorBaseError()
Returns:
an External Object Reference to the baseError instance

getType

public java.lang.String getType()
The type is defined at the creation of the object, by a subclass. For VirtualFolders only, it is used like a Basic type. setType() is defined in VirtualFolderImpl and fires a 'VirtualFolderType' event. For views, there is one immutable type per class.

Specified by:
getType in interface ImmutableFolder
Returns:
type of the folder

getConnectedToSeveralACS

public boolean getConnectedToSeveralACS()
Always false when the elements are not ACSObjects, like in an Architecture view, or for a VirtualFolder.

Specified by:
getConnectedToSeveralACS in interface ImmutableFolder
Returns:
boolean true if the folder is connected to ACSObjects belonging to different ACS.

getEorL_ConnectedACSNames

public java.util.List<ImmutableName> getEorL_ConnectedACSNames()
Specified by:
getEorL_ConnectedACSNames in interface ImmutableFolder
Returns:
List of names of the ACS having ACS Objects displayed in the folder. Never null.

isEmpty

public boolean isEmpty()
Caution: an empty folder is not equals to a new FolderAbst() instance, since it may have an non-null name and other non-null properties.

Specified by:
isEmpty in interface ImmutableFolder
Returns:
boolean true if equal to a folder wich does not contain objects.

hashCode

public final int hashCode()
Specified by:
hashCode in interface BaseObject
Overrides:
hashCode in class java.lang.Object
Returns:
int derived from the name hashcode.

containsBaseObject

public boolean containsBaseObject(BaseObject _obj)
Tests if a BaseObject is within the folder.

Specified by:
containsBaseObject in interface ImmutableFolder
Parameters:
_obj - BaseObject to test
Returns:
boolean true if the folder references this instance

getEorM_BaseObjects

public java.util.SortedMap<ImmutableName,BaseObject> getEorM_BaseObjects()
Gets all the base objects displayed in this folder.

Specified by:
getEorM_BaseObjects in interface ImmutableFolder
Returns:
unmodifiableSortedMap of the folder BaseObjects. Never null.

addEorBaseObject

public void addEorBaseObject(BaseObject _obj)
                      throws CreateError
Adds a base object to the folder. Fires the event 'OneBaseObjectInFolder'. If the argument is from a new ACS, registers this instance as listener of 'OneBaseObject' from this ACS, and fires the change property 'ConnectedACS'. Caution: this instance is not registered in _obj, and this is done by the subclasses. Overridden method.

Specified by:
addEorBaseObject in interface Folder
Parameters:
_obj - non-null BaseObject to add in the folder
Throws:
CreateError - if the name is null, or the object name is null or empty, or if the name is already known by the folder.

removeEorBaseObject

public void removeEorBaseObject(BaseObject _obj)
                         throws CreateError
Removes a base object to the folder. Fires the events 'OneBaseObjectInFolder'. Overridden method.

Specified by:
removeEorBaseObject in interface Folder
Parameters:
_obj - non-null BaseObject to remove in the folder
Throws:
CreateError - if the object name is empty, or the object is not known by the folder.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent _evt)
Observes the changes in the base objects list from the ACS. This is for the 'OneBaseObject' bound property, to remove a folder object. Overridden method that is called by all the overridding methods.

Specified by:
propertyChange in interface Folder
Specified by:
propertyChange in interface java.beans.PropertyChangeListener
Parameters:
_evt - PropertyChangeEvent

setComment

public void setComment(java.lang.String _s)
Sets any comment related to this folder. It is a bound property.

Specified by:
setComment in interface Folder
Parameters:
_s - comment which is associated to the folder.

getComment

public java.lang.String getComment()
Specified by:
getComment in interface ImmutableFolder
Returns:
String: comment which is associated to the folder. May be null.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener _l)
Adds a listener to the bean for the porperties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.

Specified by:
addPropertyChangeListener in interface BoundBean
Specified by:
addPropertyChangeListener in interface Folder
Parameters:
_l - PropertyChangeListener to add. Caution: the listener must NOT have specific hashCode() and equals() methods, to work with HashSet in the removing operations.

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String _propertyName,
                                      java.beans.PropertyChangeListener _l)
Add a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.

Specified by:
addPropertyChangeListener in interface BoundBean
Specified by:
addPropertyChangeListener in interface Folder
Parameters:
_propertyName - is the name of the property
_l - PropertyChangeListener to add. Caution: the listener must NOT have specific hashCode() and equals() methods, to work with HashSet in the removing operations.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener _l)
remove a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.

Specified by:
removePropertyChangeListener in interface BoundBean
Specified by:
removePropertyChangeListener in interface Folder
Parameters:
_l - PropertyChangeListener to remove

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String _propertyName,
                                         java.beans.PropertyChangeListener _l)
remove a listener to the bean for the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment'.

Specified by:
removePropertyChangeListener in interface BoundBean
Specified by:
removePropertyChangeListener in interface Folder
Parameters:
_propertyName - String is the name of the property
_l - PropertyChangeListener to remove

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
derived from the nick name

finalizeForBase

public void finalizeForBase()
                     throws UpDateError
The folder is removed as an ACS listener. "OneBaseObjectInFolder" events are not fired to listeners. All properties are set to null, but the name is not cleared. Called by the subclass methods.

Throws:
UpDateError - is not thrown

firePropertyChange

protected void firePropertyChange(java.lang.String _propertyName,
                                  java.lang.Object _oldValue,
                                  java.lang.Object _newValue)
Fire an event to every registered listener, in any order, for a bound property. Called by add/removeEorBaseObject() methods and the subclasses. For the properties 'OneBaseObjectInFolder', 'ConnectedACS', 'Comment' in this class, and 'OneMoreCriteria', 'OneLessCriteria' in the subclass NoThanViewInBase. There is a method with another arguments in the subclass EPRViewInBase.

Parameters:
_propertyName - name of the changing property
_oldValue - of the property
_newValue - of the property. No operation if equal to _oldValue and if the two values are not null.

finalizeFromDeserialization

protected void finalizeFromDeserialization()
The folder is NOT removed as an ACS listener. "OneBaseObjectInFolder" change is NOT fired to listeners. m_BaseObjects_ is cleared whitout finalizing the objects, since they are from open ACS (see prepareAfterRestoring()). All properties are set to null, INCLUDING the name. Overridden by EPRViewInBaseImpl and VirtualFolderImpl. Called by BaseManagerImpl.openView() when prepareAfterRestoring() throws an exception, and by getElementsOfOneView() in all cases.


finalizeForCopy

protected void finalizeForCopy()
The folder is removed as an ACS listener. "OneBaseObjectInFolder" change is NOT fired to listeners. All properties are set to null, including the name. Overridden in ViewInBase subclass, not in VirtualFolder.


finalize

protected void finalize()
                 throws java.lang.Throwable
This method removes the object from the application space, but there is no guarantee that the JVM calls this method before the end of the application.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable

addOwnListening

protected void addOwnListening()
This method registers the instance as a property event listener of 'OneBaseObject' on the ACS to detect the deleting of a folder object. Also done in addEorBaseObject(). This method is necessary because the subclasses add some complementary processings. Called by the constructors, copy(), prepareAfterRestoring() methods, and by the identical subclass methods.


removeOwnListening

protected void removeOwnListening()
This method unregister the instance as a property event listener of 'OneBaseObject' on the relevant ACS. Called by finalizeForBase() and the subclasses.


prepareBeforeSaving

protected void prepareBeforeSaving()
This method must be called by BaseManagerImpl before the saving of the folder, to update m_ObjectsNames_ from m_BaseObjects_ which is not saved nor updated. It is not necessary to clear m_BaseObjects_ since it is transient. According to the same way, the subclasses maps are not cleared, since they are derived from m_BaseObjects_ and also transient. Overridden by NoThanViewInBase which calls this method.


prepareAfterRestoring

protected java.lang.String prepareAfterRestoring()
                                          throws DialogError
This method is called by BaseManagerImpl after the opening of the folder, to update m_BaseObjects_ and l_connectedACSNames_ from m_ObjectsNames_, and to check the open ACS and their objects which are in the restored view. The folder has to be closed if it contains an object from a closed or removed ACS. It is not necessary to call this method when ACSImpl.closeVirtualFolders() has been called to save the ACS, since the workable properties of the VirtualFolders remains usable after closeVirtualFolders(). Noop if the folder objects has been restored or has never been saved, having a non-empty BaseObjects map. Overridden method, but called by the subclasses at the first line.

Returns:
a non-null message if some objects has been removed from the folder, or null.
Throws:
DialogError - if the folder contains an object from a closed or removed ACS, before the registering of the folder as listener; the exception message should be shown to the user, and this instance has to be finalized through finalizeFromDeserialization().

prepareDataAfterRestoring

protected java.lang.String prepareDataAfterRestoring()
                                              throws DialogError
This method updates m_BaseObjects_ and l_connectedACSNames_ from m_ObjectsNames_, and checks up the open ACS and their objects which are in the restored view. The folder has to be closed if it contains an object from a closed or removed ACS.

If this method is called by BaseManagerImpl.getElementsOfOneView() for a closed view, it is used for updating m_BaseObjects_ and l_connectedACSNames_, then to finalize the instance with finalizeFromDeserialization(). Clears m_BaseObjects_ if it is not null. Called by prepareAfterRestoring() and BaseManagerImpl.getElementsOfOneView().

Returns:
a non-null message if some objects has been removed from the folder, or null.
Throws:
DialogError - if the folder contains an object from a closed or removed ACS; the exception message should be shown to the user, and this instance has to be finalized through finalizeFromDeserialization().