org.netbeans.modules.xml.xam.dom
Class AbstractDocumentModel<T extends DocumentComponent<T>>

java.lang.Object
  extended by org.netbeans.modules.xml.xam.AbstractModel<T>
      extended by org.netbeans.modules.xml.xam.dom.AbstractDocumentModel<T>
All Implemented Interfaces:
java.util.EventListener, javax.swing.event.UndoableEditListener, DocumentModel<T>, Model<T>, Referenceable
Direct Known Subclasses:
BpelModelImpl, WSDLModel

public abstract class AbstractDocumentModel<T extends DocumentComponent<T>>
extends AbstractModel<T>
implements DocumentModel<T>

Author:
Chris Webster, Rico, Nam Nguyen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.netbeans.modules.xml.xam.AbstractModel
AbstractModel.ModelUndoableEdit, AbstractModel.ModelUndoableEditSupport
 
Nested classes/interfaces inherited from interface org.netbeans.modules.xml.xam.Model
Model.State
 
Field Summary
protected  DocumentModelAccess access
           
 
Fields inherited from class org.netbeans.modules.xml.xam.AbstractModel
ues
 
Fields inherited from interface org.netbeans.modules.xml.xam.Model
STATE_PROPERTY
 
Constructor Summary
AbstractDocumentModel(ModelSource source)
           
 
Method Summary
 void addChildComponent(Component target, Component child, int index)
          Add child component at specified index.
 boolean areSameNodes(org.w3c.dom.Node n1, org.w3c.dom.Node n2)
           
abstract  T createRootComponent(org.w3c.dom.Element root)
           
 AbstractDocumentComponent findComponent(AbstractDocumentComponent base, java.util.List<org.w3c.dom.Element> pathFromRoot, int current)
           
 DocumentComponent findComponent(org.w3c.dom.Element e)
           
 DocumentComponent findComponent(int position)
          Find component given a position into the Swing document.
 DocumentComponent findComponent(java.util.List<org.w3c.dom.Element> pathFromRoot)
          Find the component given a path to its element node from root.
protected  void firePropertyChangedEvents(SyncUnit unit)
           
protected  void firePropertyChangedEvents(SyncUnit unit, org.w3c.dom.Element oldElement)
           
 DocumentModelAccess getAccess()
           
static DocumentModelAccessProvider getAccessProvider()
           
 javax.swing.text.Document getBaseDocument()
           
protected abstract  ComponentUpdater<T> getComponentUpdater()
           
 org.w3c.dom.Document getDocument()
           
 java.util.Set<java.lang.String> getElementNames()
           
 java.util.Set<javax.xml.namespace.QName> getQNames()
          Returns QName of elements used in model.
 java.util.Map<javax.xml.namespace.QName,java.util.List<javax.xml.namespace.QName>> getQNameValuedAttributes()
          Returns QName of all attributes with QName value, sorted by containing element QName.
 java.lang.String getXPathExpression(DocumentComponent component)
          Return XPath expression for the given component.
protected  boolean isDomainElement(org.w3c.dom.Node e)
           
protected  boolean needsSync()
          This method is overridden by subclasses to determine if sync needs to be performed.
 ChangeInfo prepareChangeInfo(java.util.List<org.w3c.dom.Node> pathToRoot)
           
 SyncUnit prepareSyncUnit(ChangeInfo change, SyncUnit order)
           
 void processSyncUnit(SyncUnit syncOrder)
           
protected  void refresh()
          Refresh the domain model component trees.
 void removeChildComponent(Component child)
          Remove specified component from model.
protected  void setIdentifyingAttributes()
          Set the identifying attributes for underlying access to merge.
protected  void syncCompleted()
          This method is invoked when sync has completed.
protected  void syncStarted()
          This method is invoked when sync has started.
protected static java.lang.String toLocalName(java.lang.String tagName)
           
 
Methods inherited from class org.netbeans.modules.xml.xam.AbstractModel
addComponentListener, addPropertyChangeListener, addUndoableEditListener, addUndoableRefactorListener, createModelUndoableEdit, endTransaction, endTransaction, finishTransaction, fireComponentChangedEvent, firePropertyChangeEvent, getModelSource, getState, inSync, inUndoRedo, isAutoSyncActive, isIntransaction, removeComponentListener, removePropertyChangeListener, removeUndoableEditListener, removeUndoableRefactorListener, rollbackTransaction, setAutoSyncActive, setInSync, setInUndoRedo, setState, startedFiringEvents, startTransaction, sync, transactionCompleted, transactionStarted, undoableEditHappened, validateWrite
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.netbeans.modules.xml.xam.dom.DocumentModel
createComponent, getRootComponent
 
Methods inherited from interface org.netbeans.modules.xml.xam.Model
addComponentListener, addPropertyChangeListener, addUndoableEditListener, addUndoableRefactorListener, endTransaction, getModelSource, getState, inSync, isIntransaction, removeComponentListener, removePropertyChangeListener, removeUndoableEditListener, removeUndoableRefactorListener, startTransaction, sync
 

Field Detail

access

protected DocumentModelAccess access
Constructor Detail

AbstractDocumentModel

public AbstractDocumentModel(ModelSource source)
Method Detail

getBaseDocument

public javax.swing.text.Document getBaseDocument()

createRootComponent

public abstract T createRootComponent(org.w3c.dom.Element root)

areSameNodes

public boolean areSameNodes(org.w3c.dom.Node n1,
                            org.w3c.dom.Node n2)
Specified by:
areSameNodes in interface DocumentModel<T extends DocumentComponent<T>>
Returns:
true if two DOM nodes have same identity.

getQNames

public java.util.Set<javax.xml.namespace.QName> getQNames()
Returns QName of elements used in model. Domain model implementation needs to override this to be able to embed elements outside of the domain such as child elements of documentation in schema model.

Returns:
full set of element QName's or null if there is no needs for distinction between domain and non-domain elements.

needsSync

protected boolean needsSync()
Description copied from class: AbstractModel
This method is overridden by subclasses to determine if sync needs to be performed. The default implementation simply returns true.

Overrides:
needsSync in class AbstractModel<T extends DocumentComponent<T>>

syncStarted

protected void syncStarted()
Description copied from class: AbstractModel
This method is invoked when sync has started. The default implementation does nothing.

Overrides:
syncStarted in class AbstractModel<T extends DocumentComponent<T>>

syncCompleted

protected void syncCompleted()
Description copied from class: AbstractModel
This method is invoked when sync has completed. The default implementation does nothing.

Overrides:
syncCompleted in class AbstractModel<T extends DocumentComponent<T>>

getComponentUpdater

protected abstract ComponentUpdater<T> getComponentUpdater()

getElementNames

public java.util.Set<java.lang.String> getElementNames()

prepareChangeInfo

public ChangeInfo prepareChangeInfo(java.util.List<org.w3c.dom.Node> pathToRoot)

prepareSyncUnit

public SyncUnit prepareSyncUnit(ChangeInfo change,
                                SyncUnit order)

firePropertyChangedEvents

protected void firePropertyChangedEvents(SyncUnit unit)

firePropertyChangedEvents

protected void firePropertyChangedEvents(SyncUnit unit,
                                         org.w3c.dom.Element oldElement)

toLocalName

protected static java.lang.String toLocalName(java.lang.String tagName)

processSyncUnit

public void processSyncUnit(SyncUnit syncOrder)

addChildComponent

public void addChildComponent(Component target,
                              Component child,
                              int index)
Description copied from interface: Model
Add child component at specified index.

Specified by:
addChildComponent in interface Model<T extends DocumentComponent<T>>
Parameters:
target - the parent component.
child - the child component to be added.
index - position among same type of child components, or -1 if not relevant.

removeChildComponent

public void removeChildComponent(Component child)
Description copied from interface: Model
Remove specified component from model.

Specified by:
removeChildComponent in interface Model<T extends DocumentComponent<T>>

findComponent

public DocumentComponent findComponent(org.w3c.dom.Element e)

findComponent

public DocumentComponent findComponent(java.util.List<org.w3c.dom.Element> pathFromRoot)
Find the component given a path to its element node from root. All elements, except for the target element should be in the latest version of the xdm tree. All components on the path will be updated with latest version elements. Note that returned component could be part of an embedded model, which could be of a different type of model.

Parameters:
pathFromRoot - list of elements from model root to backing element of target component.
Returns:
component backed by the last element on pathFromRoot or null if not found.

findComponent

public AbstractDocumentComponent findComponent(AbstractDocumentComponent base,
                                               java.util.List<org.w3c.dom.Element> pathFromRoot,
                                               int current)

findComponent

public DocumentComponent findComponent(int position)
Description copied from interface: DocumentModel
Find component given a position into the Swing document.

Specified by:
findComponent in interface DocumentModel<T extends DocumentComponent<T>>
Returns:
component if found.

getXPathExpression

public java.lang.String getXPathExpression(DocumentComponent component)
Description copied from interface: DocumentModel
Return XPath expression for the given component.

Specified by:
getXPathExpression in interface DocumentModel<T extends DocumentComponent<T>>

getDocument

public org.w3c.dom.Document getDocument()
Specified by:
getDocument in interface DocumentModel<T extends DocumentComponent<T>>
Returns:
the DOM Document node.

getAccess

public DocumentModelAccess getAccess()
Specified by:
getAccess in class AbstractModel<T extends DocumentComponent<T>>

getAccessProvider

public static DocumentModelAccessProvider getAccessProvider()

setIdentifyingAttributes

protected void setIdentifyingAttributes()
Set the identifying attributes for underlying access to merge.


isDomainElement

protected boolean isDomainElement(org.w3c.dom.Node e)

refresh

protected void refresh()
Description copied from class: AbstractModel
Refresh the domain model component trees. The model state should be VALID as the result of this call. Note: subclasses need to override to provide the actual refresh service.

Overrides:
refresh in class AbstractModel<T extends DocumentComponent<T>>

getQNameValuedAttributes

public java.util.Map<javax.xml.namespace.QName,java.util.List<javax.xml.namespace.QName>> getQNameValuedAttributes()
Returns QName of all attributes with QName value, sorted by containing element QName. Note: if domain model implementation return null, namespace consolidation will not attempt namespace prefix refactoring on each mutation of the underlying XDM DOM tree.