FileDocCategorySizeDatePackage
PersistenceClassElementImpl.javaAPI DocGlassfish v2 API11485Fri May 04 22:34:44 BST 2007com.sun.jdo.api.persistence.model.jdo.impl

PersistenceClassElementImpl

public class PersistenceClassElementImpl extends PersistenceElementImpl implements PersistenceClassElement.Impl
author
raccah
version
%I%

Fields Summary
private boolean
_isModified
Flag used to keep track of changes to this class element.
private int
_objectIdentityType
Object identity type of the class element.
private String
_keyClass
Primary key class of the class element.
private PersistenceElementCollection
_fields
Fields of the class element.
private PersistenceElementCollection
_groups
Concurrency groups of the class element.
Constructors Summary
public PersistenceClassElementImpl()
Create new PersistenceClassElementImpl with no corresponding name. This constructor should only be used for cloning and archiving.

		this(null);
	
public PersistenceClassElementImpl(String name)
Creates new PersistenceClassElementImpl with the corresponding name

param
name the name of the element

		super(name);

		if (name != null)
			_keyClass = name + ".Oid";				// NOI18N

		_objectIdentityType = PersistenceClassElement.APPLICATION_IDENTITY;
		_fields = new PersistenceElementCollection(this, PROP_FIELDS, 
			new PersistenceFieldElement[0]);
		_groups = new PersistenceElementCollection(this, PROP_GROUPS, 
			new ConcurrencyGroupElement[0]);
	
Methods Summary
public voidchangeConcurrencyGroups(ConcurrencyGroupElement[] groups, int action)
Change the set of concurrency groups.

param
groups the new concurrency groups
param
action {@link #ADD}, {@link #REMOVE}, or {@link #SET}
exception
ModelException if impossible

		_groups.changeElements(groups, action);
	
public voidchangeFields(PersistenceFieldElement[] fields, int action)
Change the set of fields.

param
fields the new fields
param
action {@link #ADD}, {@link #REMOVE}, or {@link #SET}
exception
ModelException if impossible

		_fields.changeElements(fields, action);
	
protected final voidfirePropertyChange(java.lang.String name, java.lang.Object o, java.lang.Object n)
Fires property change event. This method overrides that of PersistenceElementImpl to update the persistence class element's modified status.

param
name property name
param
o old value
param
n new value

		// even though o == null and n == null will signify a change, that 
		// is consistent with PropertyChangeSupport's behavior and is 
		// necessary for this to work
		boolean noChange = ((o != null) && (n != null) && o.equals(n));

		super.firePropertyChange(name, o, n);

		if (!(PROP_MODIFIED.equals(name)) && !noChange)
			setModified(true);
	
protected final voidfireVetoableChange(java.lang.String name, java.lang.Object o, java.lang.Object n)
Fires vetoable change event. This method overrides that of PersistenceElementImpl to give listeners a chance to block changes on the persistence class element modified status.

param
name property name
param
o old value
param
n new value
exception
PropertyVetoException when the change is vetoed by a listener

		// even though o == null and n == null will signify a change, that 
		// is consistent with PropertyChangeSupport's behavior and is 
		// necessary for this to work
		boolean noChange = ((o != null) && (n != null) && o.equals(n));

		super.fireVetoableChange(name, o, n);

		if (!(PROP_MODIFIED.equals(name)) && !noChange)
			fireVetoableChange(PROP_MODIFIED, Boolean.FALSE, Boolean.TRUE);
	
public ConcurrencyGroupElementgetConcurrencyGroup(java.lang.String name)
Find a concurrency group by name.

param
name the name to match
return
the concurrency group, or null if it does not exist

		return (ConcurrencyGroupElement)_groups.getElement(name);
	
public ConcurrencyGroupElement[]getConcurrencyGroups()
Get all concurrency groups.

return
the concurrency groups

		return (ConcurrencyGroupElement[])_groups.getElements();
	
public PersistenceFieldElementgetField(java.lang.String name)
Find a field by name.

param
name the name to match
return
the field, or null if it does not exist

		return (PersistenceFieldElement)_fields.getElement(name);
	
public PersistenceElementCollectiongetFieldCollection()
Returns the field collection of this class element. This method should only be used internally and for cloning and archiving.

return
the field collection of this class element

		return _fields;
	
public PersistenceFieldElement[]getFields()
Get all fields.

return
the fields

		return (PersistenceFieldElement[])_fields.getElements();
	
public PersistenceElementCollectiongetGroupCollection()
Returns the concurrency group collection of this class element. This method should only be used internally and for cloning and archiving.

return
the concurrency group collection of this class element

		return _groups;
	
public java.lang.StringgetKeyClass()
Get the fully qualified name of the primary key class for this class element. This value is only used if getObjectIdentityType returns APPLICATION_IDENTITY

return
the fully qualified key class name, null if the identity type is not managed by the application
see
#setObjectIdentityType
see
PersistenceClassElement#APPLICATION_IDENTITY

		return ((PersistenceClassElement.APPLICATION_IDENTITY == 
			getObjectIdentityType()) ? _keyClass : null);
	
public intgetObjectIdentityType()
Get the object identity type of this class element.

return
the object identity type, one of {@link PersistenceClassElement#APPLICATION_IDENTITY}, {@link PersistenceClassElement#DATABASE_IDENTITY}, or {@link PersistenceClassElement#UNMANAGED_IDENTITY}. The default is APPLICATION_IDENTITY.

		return _objectIdentityType;
	
public booleanisModified()
Gets the modified flag for this persistence class.

return
true if there have been (property) changes to this class, false otherwise.

 return _isModified; 
public voidsetFieldCollection(PersistenceElementCollection collection)
Set the field collection of this class element to the supplied collection. This method should only be used internally and for cloning and archiving.

param
collection the field collection of this class element

		_fields = collection;
	
public voidsetGroupCollection(PersistenceElementCollection collection)
Set the concurrency group collection of this class element to the supplied collection. This method should only be used internally and for cloning and archiving.

param
collection the concurrency group collection of this class element

		_groups = collection;
	
public voidsetKeyClass(java.lang.String name)
Set the primary key class for this class element.

param
name - the fully qualified name which represents the primary key class. This value is only used if getObjectIdentityType returns APPLICATION_IDENTITY
exception
ModelException if impossible
see
#setObjectIdentityType
see
PersistenceClassElement#APPLICATION_IDENTITY

		String old = getKeyClass();
		
		try
		{
			fireVetoableChange(PROP_KEY_CLASS, old, name);
			_keyClass = name;
			firePropertyChange(PROP_KEY_CLASS, old, name);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
public voidsetModified(boolean flag)
Set the modified flag for this persistence class to flag. This is usually set to true by property changes and false after a save.

param
flag if true, this class is marked as modified; if false, it is marked as unmodified.

		boolean oldFlag = isModified();

		if (flag != oldFlag)
		{
			_isModified = flag;
			firePropertyChange(PROP_MODIFIED, JavaTypeHelper.valueOf(oldFlag), 
				JavaTypeHelper.valueOf(flag));
		}
	
public voidsetObjectIdentityType(int type)
Set the object identity type of this class element.

param
type - an integer indicating the object identity type, one of: {@link PersistenceClassElement#APPLICATION_IDENTITY}, {@link PersistenceClassElement#DATABASE_IDENTITY}, or {@link PersistenceClassElement#UNMANAGED_IDENTITY}
exception
ModelException if impossible

		Integer old = new Integer(getObjectIdentityType());
		Integer newType = new Integer(type);

		try
		{
			fireVetoableChange(PROP_IDENTITY, old, newType);
			_objectIdentityType = type;
			firePropertyChange(PROP_IDENTITY, old, newType);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}