Class Dom
- All Implemented Interfaces:
Externalizable,Serializable,InvocationHandler,org.glassfish.hk2.api.ActiveDescriptor,org.glassfish.hk2.api.Descriptor,org.glassfish.hk2.api.SingleCache,ObservableBean
- Direct Known Subclasses:
ConfigBean
InvocationHandler that loads configuration from XML.
This object also captures all the configuration values in a typeless way, so that the loading of the actual classes can be deferred as much as possible.
This is the ActiveDescriptor that gets registered into ServiceLocator,
so one can access this object by
ServiceLocator.getServiceHandle(Class, String, Annotation...) family
of methods.
- Author:
- Kohsuke Kawaguchi
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal DomDocumentOwner of the DOM tree.final ConfigModelModel drives the interpretation of this DOM. -
Constructor Summary
ConstructorsConstructorDescriptionDom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model) Dom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model, XMLStreamReader in) Copy constructor, used to get a deep copy of the passed instance -
Method Summary
Modifier and TypeMethodDescriptionvoidWhen a new Dom object is created, ensures that all @NotNull annotated elements have a value.booleanaddLeafElement(String xmlName, String value) voidaddListener(ConfigListener listener) Add a new listener to configuration changes.Obtains the attribute value, after variable expansion.voidUpdates the attribute value.attributes(String name) Obtains the plural attribute value.booleanchangeLeafElement(String xmlName, String oldValue, String newValue) static StringconvertName(String name) protected <T extends Dom>
Tcopy(T parent) Returns a copy of itself providing the parent for the new copy.create(org.glassfish.hk2.api.ServiceHandle root) protected CreatorThis is how we inject the configuration into the created object.<T extends ConfigBeanProxy>
TCreates a strongly-typed proxy to access values in thisDomobject,<T extends ConfigBeanProxy>
TcreateProxy(Class<T> proxyType) Creates a strongly-typed proxy to access values in thisDomobject, by using the specified interface type as the proxy type.static <T extends Annotation>
TdigAnnotation(Class<?> target, Class<T> annotationType) static <T extends Annotation>
TdigAnnotation(Class<?> target, Class<T> annotationType, List<Class<? extends Annotation>> visited) domNodeByTypeElements(Class baseType) Picks up all node elements that are assignable to the given type, except those who are matched by other named elements in the model.Returns the child element by namebooleanget()Returns the list of attributes with a value on this config instance.getCache()Returns the children name associated with this config instance.org.glassfish.hk2.api.ServiceLocatorClass<?>List<org.glassfish.hk2.api.Injectee>Gets theConfigInjectorinstance that can be used to inject this DOM to a bean.getKey()Obtains the actual key value from thisDom.Where was thisDomloaded from?<T extends ConfigBeanProxy>
Class<T>Returns the proxy type for this configuration objectClass<? extends Annotation>org.glassfish.hk2.api.ServiceLocatorgetSymbolSpaceRoot(String typeName) Locates the DOM that serves as the symbol space root.protected Objectgetter(ConfigModel.Property target, Type t) inthashCode()voidvoidPerforms injection to the given object.voidinsertAfter(Dom reference, String name, Dom newNode) Inserts a newDomnode right after the given DOM element.InvocationHandlerimplementation that allows strongly-typed access to the configuration.Another version of theinvoke(Object, Method, Object[]), but instead ofMethodobject, it takes the method name and argument types.booleanbooleanThis ensures no-one tried to reify this descriptor, which has an impl class the interfaceleafElement(String name) Picks up one leaf-element value.leafElements(String name) Picks up all leaf-element values of the given name.<T> TnodeByTypeElement(Class<T> baseType) <T> List<T>nodeByTypeElements(Class<T> baseType) nodeElement(String name) Picks up one node-element value.nodeElements(String elementName) Picks up all node-elements that have the given element name.parent()If this DOM is a child of another DOM, the parent pointer.rawAttribute(String name) Obtians the attribute value without variable expansion.rawLeafElement(String name) Picks up one leaf-element value without variable expansion.rawLeafElements(String name) Picks up all leaf-element values of the given name, without variable expansion.voidrelease()voidvoidremoveChild(Dom reference) Removes an existingDom.NodeChildbooleanremoveLeafElement(String xmlName, String element) booleanremoveListener(ConfigListener listener) Remove a listenervoidreplaceChild(Dom reference, String name, Dom newNode) Replaces an existingDom.NodeChildwith another one.resolveReference(String key, String typeName) Recursively decends the DOM tree and finds a DOM that has the given key and the type name.voidvoidvoidsetLeafElements(String name, String... values) Updates leaf-element values.voidsetNodeElements(String name, Dom... values) Updates node-element values.protected voidsetter(ConfigModel.Property target, Object value) voidThis method should be invoked if this Dom should not be persisted to the domain.xml file.static Domunwrap(ConfigBeanProxy proxy) Unwraps the proxy and returns the underlyingDomobject.voidwriteTo(String tagName, XMLStreamWriter w) Writes back this element.voidThis method should be invoked if this Dom needs to be persisted to domain.xml fileMethods inherited from class org.glassfish.hk2.utilities.AbstractActiveDescriptor
addContractType, addQualifierAnnotation, dispose, getScopeAsAnnotation, removeContractType, removeQualifierAnnotation, setFactoryId, setName, setReified, setScopeAnnotation, setScopeAsAnnotationMethods inherited from class org.glassfish.hk2.utilities.DescriptorImpl
addAdvertisedContract, addMetadata, addMetadata, addQualifier, clearMetadata, descriptorEquals, getAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, isProxyForSameScope, pretty, readExternal, readObject, removeAdvertisedContract, removeAllMetadata, removeMetadata, removeQualifier, setClassAnalysisName, setDescriptorType, setDescriptorVisibility, setImplementation, setLoader, setLocatorId, setMetadata, setProxiable, setProxyForSameScope, setRanking, setScope, setServiceId, toString, writeExternal, writeObjectMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.glassfish.hk2.api.Descriptor
getAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, isProxyForSameScope, setRanking
-
Field Details
-
model
Model drives the interpretation of this DOM. -
document
Owner of the DOM tree.
-
-
Constructor Details
-
Dom
public Dom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model, XMLStreamReader in) - Parameters:
in- If provided, this is used to record the source location where this DOM object is loaded from. Otherwise this can be null.
-
Dom
public Dom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model) -
Dom
Copy constructor, used to get a deep copy of the passed instance- Parameters:
source- the instance to copy
-
-
Method Details
-
skipFromXml
public void skipFromXml()This method should be invoked if this Dom should not be persisted to the domain.xml file. -
writeToXml
public void writeToXml()This method should be invoked if this Dom needs to be persisted to domain.xml file -
initializationCompleted
public void initializationCompleted() -
addDefaultChildren
public void addDefaultChildren()When a new Dom object is created, ensures that all @NotNull annotated elements have a value. -
getHabitat
public org.glassfish.hk2.api.ServiceLocator getHabitat() -
copy
Returns a copy of itself providing the parent for the new copy.- Parameters:
parent- the parent instance for the cloned copy- Returns:
- the cloned copy
-
unwrap
Unwraps the proxy and returns the underlyingDomobject.- Returns:
- null if the given instance is not actually a proxy to a DOM.
-
getKey
Obtains the actual key value from thisDom. -
parent
If this DOM is a child of another DOM, the parent pointer. Otherwise null. -
getLocation
Where was thisDomloaded from? -
getAttributeNames
Returns the list of attributes with a value on this config instance. This is by definition a subset of the attributes names as known to the model .- Returns:
- list of attributes names which have values on this config instance
-
getElementNames
Returns the children name associated with this config instance. This is by definition a subset of the element names as known to the model {#see ConfigModel.getElementNames(). -
attribute
Obtains the attribute value, after variable expansion.- Returns:
- null if the attribute is not found.
-
rawAttribute
Obtians the attribute value without variable expansion.- Returns:
- null if the attribute is not found.
-
attributes
Obtains the plural attribute value. Values are separate by ',' and surrounding whitespaces are ignored.- Returns:
- null if the attribute doesn't exist. This is a distinct state from the empty list, which indicates that the attribute was there but no values were found.
-
attribute
Updates the attribute value. This would trigger the re-injection of the value. -
element
Returns the child element by name- Parameters:
name- of the element- Returns:
- child element
-
leafElement
Picks up one leaf-element value. -
insertAfter
Inserts a newDomnode right after the given DOM element.- Parameters:
reference- If null, the new element will be inserted at the very beginning.name- The element name of the newly inserted item. "*" to indicate that the element name be determined by the model of the new node.
-
replaceChild
Replaces an existingDom.NodeChildwith another one.- See Also:
-
removeChild
Removes an existingDom.NodeChild -
addLeafElement
-
removeLeafElement
-
changeLeafElement
-
rawLeafElement
Picks up one leaf-element value without variable expansion. -
setLeafElements
Updates leaf-element values.Synchronized so that concurrenct modifications will work correctly.
-
leafElements
Picks up all leaf-element values of the given name.- Returns:
- Can be empty but never null.
-
rawLeafElements
Picks up all leaf-element values of the given name, without variable expansion.- Returns:
- can be empty, but never null (even if such element name is not defined in the model.)
-
nodeElement
Picks up one node-element value. -
setNodeElements
Updates node-element values.Synchronized so that concurrenct modifications will work correctly.
-
nodeElements
Picks up all node-elements that have the given element name. -
domNodeByTypeElements
Picks up all node elements that are assignable to the given type, except those who are matched by other named elements in the model. Used to implementFromElement("*"). -
nodeByTypeElements
-
nodeByTypeElement
-
inject
Performs injection to the given object. -
getInjector
Gets theConfigInjectorinstance that can be used to inject this DOM to a bean. -
getSymbolSpaceRoot
Locates the DOM that serves as the symbol space root.- Returns:
- always non-null.
-
resolveReference
Recursively decends the DOM tree and finds a DOM that has the given key and the type name.TODO: the current algorithm does a full tree scan. Expand the model so that we can detect deadends that are statically known not to contain the kind we are looking for, and use that to cut the search space.
-
createProxy
Creates a strongly-typed proxy to access values in thisDomobject, by using the specified interface type as the proxy type. -
createProxy
Creates a strongly-typed proxy to access values in thisDomobject, -
getProxyType
Returns the proxy type for this configuration object- Type Parameters:
T- the proxy type- Returns:
- the class object for the proxy type
-
isReified
public boolean isReified()This ensures no-one tried to reify this descriptor, which has an impl class the interface- Specified by:
isReifiedin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
isReifiedin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor- Returns:
- always true
-
getImplementationClass
- Specified by:
getImplementationClassin interfaceorg.glassfish.hk2.api.ActiveDescriptor
-
getImplementationType
- Specified by:
getImplementationTypein interfaceorg.glassfish.hk2.api.ActiveDescriptor
-
setImplementationType
- Overrides:
setImplementationTypein classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getContractTypes
- Specified by:
getContractTypesin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getContractTypesin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getScopeAnnotation
- Specified by:
getScopeAnnotationin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getScopeAnnotationin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getQualifierAnnotations
- Specified by:
getQualifierAnnotationsin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getQualifierAnnotationsin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getInjectees
- Specified by:
getInjecteesin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getInjecteesin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getFactoryServiceId
- Specified by:
getFactoryServiceIdin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getFactoryServiceIdin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
getFactoryLocatorId
- Specified by:
getFactoryLocatorIdin interfaceorg.glassfish.hk2.api.ActiveDescriptor- Overrides:
getFactoryLocatorIdin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
invoke
InvocationHandlerimplementation that allows strongly-typed access to the configuration.TODO: it might be a great performance improvement to have APT generate code that does this during the development time by looking at the interface.
- Specified by:
invokein interfaceInvocationHandler- Throws:
Throwable
-
invoke
public Object invoke(Object proxy, String methodName, Class[] argTypes, Object[] args) throws Throwable Another version of theinvoke(Object, Method, Object[]), but instead ofMethodobject, it takes the method name and argument types.- Throws:
Throwable
-
getter
-
setter
- Throws:
Exception
-
convertName
-
createCreator
This is how we inject the configuration into the created object.There are two kinds — one where @
Configuredis put on a bean and that is placedinto Habitat, and the other is where @Configuredis onConfigBeanProxysubtype, in which case the proxy toDomwill be placed into the habitat. -
digAnnotation
-
digAnnotation
public static <T extends Annotation> T digAnnotation(Class<?> target, Class<T> annotationType, List<Class<? extends Annotation>> visited) -
writeTo
Writes back this element.- Parameters:
tagName- The tag name of this element to be written. If null, this DOM node must be a global element and its tag name will be used.w- Receives XML infoset stream.- Throws:
XMLStreamException
-
release
public void release() -
addListener
Description copied from interface:ObservableBeanAdd a new listener to configuration changes.- Specified by:
addListenerin interfaceObservableBean- Parameters:
listener- new listener
-
removeListener
Description copied from interface:ObservableBeanRemove a listener- Specified by:
removeListenerin interfaceObservableBean- Parameters:
listener- to remove- Returns:
- true if listener removal was successful.
-
getCache
- Specified by:
getCachein interfaceorg.glassfish.hk2.api.SingleCache- Overrides:
getCachein classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
isCacheSet
public boolean isCacheSet()- Specified by:
isCacheSetin interfaceorg.glassfish.hk2.api.SingleCache- Overrides:
isCacheSetin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
setCache
- Specified by:
setCachein interfaceorg.glassfish.hk2.api.SingleCache- Overrides:
setCachein classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
releaseCache
public void releaseCache()- Specified by:
releaseCachein interfaceorg.glassfish.hk2.api.SingleCache- Overrides:
releaseCachein classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
create
- Specified by:
createin interfaceorg.glassfish.hk2.api.ActiveDescriptor
-
get
-
getServiceLocator
public org.glassfish.hk2.api.ServiceLocator getServiceLocator() -
hashCode
public int hashCode()- Overrides:
hashCodein classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-
equals
- Overrides:
equalsin classorg.glassfish.hk2.utilities.AbstractActiveDescriptor
-