org.netbeans.modules.xml.xam.dom
Class AbstractNamedComponentReference<T extends NamedReferenceable>

java.lang.Object
  extended by org.netbeans.modules.xml.xam.AbstractReference<T>
      extended by org.netbeans.modules.xml.xam.dom.AbstractNamedComponentReference<T>
All Implemented Interfaces:
NamedComponentReference<T>, Reference<T>
Direct Known Subclasses:
AbstractNamedComponentReference, GlobalReferenceImpl

public abstract class AbstractNamedComponentReference<T extends NamedReferenceable>
extends AbstractReference<T>
implements NamedComponentReference<T>

Abstract implementation of reference by name to a component. On writing, this indirection help serialize the referenced component as an attribute string value. On reading, the referenced can be resolved on demand.

Note: Client code should always check for brokeness before access the referenced.

Author:
rico, Nam Nguyen, Chris Webster

Field Summary
protected  java.lang.String localName
           
protected  java.lang.String prefix
           
protected  javax.xml.namespace.QName qname
           
 
Fields inherited from class org.netbeans.modules.xml.xam.AbstractReference
refString
 
Constructor Summary
AbstractNamedComponentReference(java.lang.Class<T> referencedType, AbstractDocumentComponent parent, java.lang.String ref)
          Constructor for reading.
AbstractNamedComponentReference(T referenced, java.lang.Class<T> referencedType, AbstractDocumentComponent parent)
          Constructor for writing.
 
Method Summary
protected  javax.xml.namespace.QName calculateQNameLocally()
          Calculate the QName based on the local information without loading the referenced object.
protected  void checkParentNotRemovedFromModel()
           
protected  void checkParentPartOfModel()
           
 boolean equals(java.lang.Object obj)
           
protected  java.lang.String getLocalName()
           
protected  AbstractDocumentComponent getParent()
          Returns parent referencing component.
protected  java.lang.String getPrefix()
           
 javax.xml.namespace.QName getQName()
          Note this method will first attempt to build the QName base on local lookup before trying to resolve the referenced.
protected  T getReferenced()
          Access method for referenced.
 java.lang.String getRefString()
           
 int hashCode()
           
 boolean references(T target)
          Return true if this reference refers to target.
 void refresh()
           
 
Methods inherited from class org.netbeans.modules.xml.xam.AbstractReference
getType, isBroken, setReferenced, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.netbeans.modules.xml.xam.dom.NamedComponentReference
getEffectiveNamespace
 
Methods inherited from interface org.netbeans.modules.xml.xam.Reference
get, getType, isBroken
 

Field Detail

prefix

protected java.lang.String prefix

localName

protected java.lang.String localName

qname

protected javax.xml.namespace.QName qname
Constructor Detail

AbstractNamedComponentReference

public AbstractNamedComponentReference(T referenced,
                                       java.lang.Class<T> referencedType,
                                       AbstractDocumentComponent parent)
Constructor for writing.

Parameters:
referenced - the component being referenced
referencedType - type of the referenced component
parent - referencing component on which the referenced is serialized as an attribute string value.

AbstractNamedComponentReference

public AbstractNamedComponentReference(java.lang.Class<T> referencedType,
                                       AbstractDocumentComponent parent,
                                       java.lang.String ref)
Constructor for reading.

Parameters:
referencedType - type of the referenced component
parent - referencing component on which the referenced is serialized as an attribute string value.
ref - the string value used in resolving.
Method Detail

references

public boolean references(T target)
Return true if this reference refers to target. This method is more efficient than invoking get

Specified by:
references in interface Reference<T extends NamedReferenceable>
Overrides:
references in class AbstractReference<T extends NamedReferenceable>

getRefString

public java.lang.String getRefString()
Specified by:
getRefString in interface Reference<T extends NamedReferenceable>
Overrides:
getRefString in class AbstractReference<T extends NamedReferenceable>
Returns:
string to use in persiting the reference as attribute value of the containing component

getPrefix

protected java.lang.String getPrefix()

getLocalName

protected java.lang.String getLocalName()

getReferenced

protected T getReferenced()
Description copied from class: AbstractReference
Access method for referenced.

Overrides:
getReferenced in class AbstractReference<T extends NamedReferenceable>

getQName

public javax.xml.namespace.QName getQName()
Note this method will first attempt to build the QName base on local lookup before trying to resolve the referenced. Subclasses need to override if local calculation is not desirable.

Specified by:
getQName in interface NamedComponentReference<T extends NamedReferenceable>
Returns:
QName of the referenced component.
Throws:
java.lang.IllegalStateException - if referencing component is discarded from the model.

getParent

protected AbstractDocumentComponent getParent()
Returns parent referencing component.

Overrides:
getParent in class AbstractReference<T extends NamedReferenceable>

checkParentPartOfModel

protected void checkParentPartOfModel()
Throws:
java.lang.IllegalStateException - if parent is not part of a model.

checkParentNotRemovedFromModel

protected void checkParentNotRemovedFromModel()
Throws:
java.lang.IllegalStateException - if parent is already removed from a model.

calculateQNameLocally

protected javax.xml.namespace.QName calculateQNameLocally()
Calculate the QName based on the local information without loading the referenced object.


equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class AbstractReference<T extends NamedReferenceable>

hashCode

public int hashCode()
Overrides:
hashCode in class AbstractReference<T extends NamedReferenceable>

refresh

public void refresh()