Class XmlRootHandleImpl<T>
- All Implemented Interfaces:
XmlRootHandle<T>
- Author:
- jwells
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(VetoableChangeListener... listeners) Adds a change listener to be invoked before any property is set or a bean is added.voidaddRoot()This method can be used if the root of the tree has no required fields, and is the combination ofXmlService.createBean(Class)andXmlRootHandle.addRoot(Object).voidIf this handle does not already have a root bean this method will add the one givenGets the current list of change listenersgetPackageNamespace(Class<?> clazz) getReadOnlyRoot(boolean representDefaults) This method returns a read-only copy of the existing tree.getRoot()Gets the root of the JavaBean treeReturns the root interface of this handlegetURI()Represents the original URI from which this tree was parsed (or null if this tree did not come from a URI)Creates a copy of this tree that is not advertised.booleanReturns true if this handles root and children are advertised in theHubbooleanReturns true if this handles root and children are advertised in it service locatorbooleanTrue if this handle is currently validating changesThis method will lock the bean tree represented by this XmlRootHandle and start a transaction.voidmarshal(OutputStream outputStream) Will marshal this tree into the given stream.voidmarshal(OutputStream outputStream, Map<String, Object> options) Will marshal this tree into the given stream.voidoverlay(XmlRootHandle<T> newRoot) This method overlays the current root and children with the root and children from newRoot.voidremoveChangeListener(VetoableChangeListener... listeners) Removes a change listener.If this handle has a root this method will delete it and all children, leaving the root of this tree nullvoidDoes javax validation on the root bean from the root.voidStops this root handle from doing javax validation on modificationstoString()
-
Method Details
-
getRoot
Description copied from interface:XmlRootHandleGets the root of the JavaBean tree- Specified by:
getRootin interfaceXmlRootHandle<T>- Returns:
- The root of the JavaBean tree. Will only return null if the tree has not yet been created
-
getRootClass
Description copied from interface:XmlRootHandleReturns the root interface of this handle- Specified by:
getRootClassin interfaceXmlRootHandle<T>- Returns:
- The root class or interface of this handle. Will not return null
-
getURI
Description copied from interface:XmlRootHandleRepresents the original URI from which this tree was parsed (or null if this tree did not come from a URI)- Specified by:
getURIin interfaceXmlRootHandle<T>- Returns:
- The original URI from which this tree was parsed, or null if this tree did not come from a URI
-
isAdvertisedInLocator
public boolean isAdvertisedInLocator()Description copied from interface:XmlRootHandleReturns true if this handles root and children are advertised in it service locator- Specified by:
isAdvertisedInLocatorin interfaceXmlRootHandle<T>- Returns:
- true if the root and children are advertised in the associated service locator
-
isAdvertisedInHub
public boolean isAdvertisedInHub()Description copied from interface:XmlRootHandleReturns true if this handles root and children are advertised in theHub- Specified by:
isAdvertisedInHubin interfaceXmlRootHandle<T>- Returns:
- true if the root and children are
advertised in the associated
Hub
-
overlay
Description copied from interface:XmlRootHandleThis method overlays the current root and children with the root and children from newRoot. newRoot must have the same rootClass and must NOT be advertised in either the locator or the hub. The system will calculate the set of changes needed to convert this root into the root from newRoot.All nodes that are at the same spot in the tree (have the same xpath and same instance name) will not be modified, but will instead have attributes changed. All nodes present in newRoot but not in this root will be considered adds. All nodes not present in newRoot but in this root will be considered deletes
The URI will not be modified by this call, nor will the state of advertisement
- Specified by:
overlayin interfaceXmlRootHandle<T>- Parameters:
newRoot- The non-null root that will be overlayed onto this handle
-
getXmlRootCopy
Description copied from interface:XmlRootHandleCreates a copy of this tree that is not advertised. Modifications can be made to this copy and then merged back into the parent in a single transactionThere is no requirement to call
XmlRootCopy.merge()since the parent keeps no track of children. However, theXmlRootCopy.merge()method will fail if a modification has been made to the parent since the time the copy was created- Specified by:
getXmlRootCopyin interfaceXmlRootHandle<T>- Returns:
- A non-null copy of this root that can be modified and then merged back in a single transaction
-
addRoot
Description copied from interface:XmlRootHandleIf this handle does not already have a root bean this method will add the one given- Specified by:
addRootin interfaceXmlRootHandle<T>- Parameters:
newRoot- The non-null instance of the root type of this handle
-
addRoot
public void addRoot()Description copied from interface:XmlRootHandleThis method can be used if the root of the tree has no required fields, and is the combination ofXmlService.createBean(Class)andXmlRootHandle.addRoot(Object). This method will throw an exception from the validator (if validation is enabled) if the root type has required fields or fails other validation- Specified by:
addRootin interfaceXmlRootHandle<T>
-
removeRoot
Description copied from interface:XmlRootHandleIf this handle has a root this method will delete it and all children, leaving the root of this tree null- Specified by:
removeRootin interfaceXmlRootHandle<T>- Returns:
- The root that was deleted, or null if the root was already null
-
getReadOnlyRoot
Description copied from interface:XmlRootHandleThis method returns a read-only copy of the existing tree. Any method that would change anything in this tree will fail. Methods that are customized will also failIf representsDefaults is true then getters for unset fields will return the default value. If representsDefaults is false then getters for unset fields will return null (or 0 (and false) for scalars). Setting representsDefault to false is useful if this tree is to be used to marshall back to XML, since JAXB will then not write the values back out to the file
- Specified by:
getReadOnlyRootin interfaceXmlRootHandle<T>- Parameters:
representDefaults- If true getters will return default values, if false getters will return null (or zero/false for scalars)- Returns:
- A read-only copy of this xml tree or null if there is no current root for this handle
-
addChangeListener
Description copied from interface:XmlRootHandleAdds a change listener to be invoked before any property is set or a bean is added. The listener must be suitable for storage in a HashSet.Rules for change listener:
- Adds of beans with children will get called back for each child and sub-child added
- Add listener callbacks will happen parent first but children at the same level are handled in any order
- When adding a bean the following events will be generated:
- An event with an empty string as the propertyName, oldValue null, newValue and source set to the added bean
- An event for the parent being added to with propertyName, oldValue the old list or array or direct child, new value the new list or array or direct child
- Remove listener callbacks will happen child first but children at the same level are handled in any order
- When removing a bean the following events will be generated:
- An event with an empty string as the propertyName, oldValue the removed bean, newValue null, and source set to the removed bean
- An event for the parent being removed from with propertyName, oldValue the old list or array or direct child, new value the new list or array or null for the direct child
- Listeners are run in the order in which they are added
- If a listener throws a PropertyVetoException subsequent listeners are NOT called and the update will not happen
- If a listener throws any exception other than PropertyVertoException subsequent listeners WILL be called and the update will not happen
- If any exceptions happen in any listeners they will end up all being reported in a MultiException
- Specified by:
addChangeListenerin interfaceXmlRootHandle<T>- Parameters:
listeners- non-null listeners to be called whenever a property is changed in any bean in this root. Must be suitable for storage in a HashSet
-
removeChangeListener
Description copied from interface:XmlRootHandleRemoves a change listener. The listener must be suitable for lookup in a HashSet- Specified by:
removeChangeListenerin interfaceXmlRootHandle<T>
-
getChangeListeners
Description copied from interface:XmlRootHandleGets the current list of change listeners- Specified by:
getChangeListenersin interfaceXmlRootHandle<T>- Returns:
- The non-null but possibly empty list of change listeners to be called when a bean is added, removed or modified
-
lockForTransaction
Description copied from interface:XmlRootHandleThis method will lock the bean tree represented by this XmlRootHandle and start a transaction. Any changes made while this transaction is in-flight will not be visible to any other thread until this transaction is committed. This transaction MUST be committed or abandoned before any other thread can get access to any beans in this tree.In particular, the code using this transaction should logically behave like the following code:
XmlHandleTransaction
transaction = root.lockForTransaction(); try { // Do many many edits all at once } finally { transaction.commit(); } - Specified by:
lockForTransactionin interfaceXmlRootHandle<T>- Returns:
- The never null transaction object that must either be abandoned or committed before the write lock on this bean tree is released
- Throws:
IllegalStateException- if this bean tree is not allowed to have a transaction started on it
-
startValidating
public void startValidating()Description copied from interface:XmlRootHandleDoes javax validation on the root bean from the root. This will cause every change hereafter to be validated- Specified by:
startValidatingin interfaceXmlRootHandle<T>
-
stopValidating
public void stopValidating()Description copied from interface:XmlRootHandleStops this root handle from doing javax validation on modifications- Specified by:
stopValidatingin interfaceXmlRootHandle<T>
-
isValidating
public boolean isValidating()Description copied from interface:XmlRootHandleTrue if this handle is currently validating changes- Specified by:
isValidatingin interfaceXmlRootHandle<T>
-
marshal
Description copied from interface:XmlRootHandleWill marshal this tree into the given stream. Will hold the read lock of this tree while it does so that the tree cannot change underneath while it is being written out. It will use a basic indentation and new-line scheme- Specified by:
marshalin interfaceXmlRootHandle<T>- Parameters:
outputStream- A non-closed output stream. This method will not close the output stream- Throws:
IOException- On any exception that might happen
-
marshal
Description copied from interface:XmlRootHandleWill marshal this tree into the given stream. Will hold the read lock of this tree while it does so that the tree cannot change underneath while it is being written out. It will use a basic indentation and new-line scheme- Specified by:
marshalin interfaceXmlRootHandle<T>- Parameters:
outputStream- A non-closed output stream. This method will not close the output streamoptions- optional (possibly null) options from the caller- Throws:
IOException- On any exception that might happen
-
getPackageNamespace
-
toString
-