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

MappingElementImpl

public abstract class MappingElementImpl extends Object implements com.sun.jdo.api.persistence.model.mapping.MappingElement
author
raccah
version
%I%

Fields Summary
private static final ResourceBundle
_messages
I18N message handler
private PropertyChangeSupport
_support
Property change support
private transient VetoableChangeSupport
_vetoableSupport
Vetoable change support
String
_name
Constructors Summary
public MappingElementImpl()
Create new MappingElementImpl with no corresponding name. This constructor should only be used for cloning and archiving.


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

param
name the name of the element

		super();
		_name = name;
	
Methods Summary
public synchronized voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)
Add a property change listener.

param
l the listener to add

		if (_support == null)
		{
			synchronized(this)
			{
				// new test under synchronized block
				if (_support == null)
					_support = new PropertyChangeSupport(this);
			}
		}

		_support.addPropertyChangeListener(l);
	
public synchronized voidaddVetoableChangeListener(java.beans.VetoableChangeListener l)
Add a vetoable change listener.

param
l the listener to add

		if (_vetoableSupport == null)
			_vetoableSupport = new VetoableChangeSupport(this);

		_vetoableSupport.addVetoableChangeListener(l);
	
public intcompareTo(java.lang.Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. The specified object must be mapping element, meaning it must be an instance of class MappingElementImpl or any subclass. If not a ClassCastException is thrown. The order of MappingElementImpl objects is defined by the order of their names. Mapping elements without name are considered to be less than any named mapping element.

param
o the Object to be compared.
return
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
exception
ClassCastException - if the specified object is null or is not an instance of MappingElementImpl

        // null is not allowed
        if (o == null)
            throw new ClassCastException();
        if (o == this)
            return 0;

        String thisName = getName();
        // the following statement throws a ClassCastException if o is not a MappingElementImpl
        String otherName = ((MappingElementImpl)o).getName();
        // if this does not have a name it should compare less than any named object
        if (thisName == null)
            return (otherName == null) ? 0 : -1;
        // if this is named and o does not have a name it should compare greater
        if (otherName == null)
            return 1;
        // now we know that this and o are named mapping elements => 
        // use locale-sensitive String comparison 
        int ret = Collator.getInstance().compare(thisName, otherName);
        // if both names are equal, both objects might have different types. 
        // If so order both objects by their type names (necessary to be consistent with equals)
        if ((ret == 0) && (getClass() != o.getClass()))
            ret = getClass().getName().compareTo(o.getClass().getName());
        return ret;
    
public booleanequals(java.lang.Object obj)
Overrides Object's equals method by comparing the name of this mapping element with the name of the argument obj. The method returns false if obj does not have the same dynamic type as this mapping element.

return
true if this object is the same as the obj argument; false otherwise.
param
obj the reference object with which to compare.

        if (obj == null)
            return false;
        if (obj == this)
            return true;

        // check for the right class and then do the name check by calling compareTo.
        return (getClass() == obj.getClass()) && (compareTo(obj) == 0);
    
protected voidfirePropertyChange(java.lang.String name, java.lang.Object o, java.lang.Object n)
Fires property change event.

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

		if (_support != null)
			_support.firePropertyChange(name, o, n);
	
protected voidfireVetoableChange(java.lang.String name, java.lang.Object o, java.lang.Object n)
Fires vetoable change event.

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

		if (_vetoableSupport != null)
			_vetoableSupport.fireVetoableChange(name, o, n);
	
protected static final java.util.ResourceBundlegetMessages()

return
I18N message handler for this element

 return _messages; 
public java.lang.StringgetName()
Get the name of this mapping element.

return
the name

 return _name; 
public inthashCode()
Overrides Object's hashCode method to return the hashCode of this mapping element's name.

return
a hash code value for this object.

        return (getName()==null) ? 0 : getName().hashCode();
    
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)
Remove a property change listener.

param
l the listener to remove

		if (_support != null)
			_support.removePropertyChangeListener(l);
	
public synchronized voidremoveVetoableChangeListener(java.beans.VetoableChangeListener l)
Remove a vetoable change listener.

param
l the listener to remove

		if (_vetoableSupport != null)
			_vetoableSupport.removeVetoableChangeListener(l);
	
public voidsetName(java.lang.String name)
Set the name of this mapping element.

param
name the name
exception
ModelException if impossible

		String old = getName();
		
		try
		{
			fireVetoableChange(PROP_NAME, old, name);
			_name = name;
			firePropertyChange(PROP_NAME, old, name);
		}
		catch (PropertyVetoException e)
		{
			throw new ModelVetoException(e);
		}
	
public java.lang.StringtoString()
Overrides Object's toString method to return the name of this mapping element.

return
a string representation of the object

 return getName();