public class Dom extends org.glassfish.hk2.utilities.AbstractActiveDescriptor implements InvocationHandler, ObservableBean
Inhabitant 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) family
of methods.
| Modifier and Type | Field and Description |
|---|---|
DomDocument |
document
Owner of the DOM tree.
|
ConfigModel |
model
Model drives the interpretation of this DOM.
|
| Constructor and Description |
|---|
Dom(Dom source,
Dom parent)
Copy constructor, used to get a deep copy of the passed instance
|
Dom(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) |
| Modifier and Type | Method and Description |
|---|---|
void |
addDefaultChildren()
When a new Dom object is created, ensures that all @NotNull annotated
elements have a value.
|
boolean |
addLeafElement(String xmlName,
String value) |
void |
addListener(ConfigListener listener)
Add a new listener to configuration changes.
|
String |
attribute(String name)
Obtains the attribute value, after variable expansion.
|
void |
attribute(String name,
String value)
Updates the attribute value.
|
List<String> |
attributes(String name)
Obtains the plural attribute value.
|
boolean |
changeLeafElement(String xmlName,
String oldValue,
String newValue) |
static String |
convertName(String name) |
protected <T extends Dom> |
copy(T parent)
Returns a copy of itself providing the parent for the new copy.
|
Object |
create(org.glassfish.hk2.api.ServiceHandle root) |
protected Creator |
createCreator(Class c)
This is how we inject the configuration into the created object.
|
<T extends ConfigBeanProxy> |
createProxy()
Creates a strongly-typed proxy to access values in this
Dom object, |
<T extends ConfigBeanProxy> |
createProxy(Class<T> proxyType)
Creates a strongly-typed proxy to access values in this
Dom object,
by using the specified interface type as the proxy type. |
static <T extends Annotation> |
digAnnotation(Class<?> target,
Class<T> annotationType) |
static <T extends Annotation> |
digAnnotation(Class<?> target,
Class<T> annotationType,
List<Class<? extends Annotation>> visited) |
List<Dom> |
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.
|
Dom |
element(String name)
Returns the child element by name
|
boolean |
equals(Object o) |
Object |
get() |
Set<String> |
getAttributeNames()
Returns the list of attributes with a value on this config instance.
|
Object |
getCache() |
Set<Type> |
getContractTypes() |
Set<String> |
getElementNames()
Returns the children name associated with this config instance.
|
Long |
getFactoryLocatorId() |
Long |
getFactoryServiceId() |
org.glassfish.hk2.api.ServiceLocator |
getHabitat() |
Class<?> |
getImplementationClass() |
Type |
getImplementationType() |
List<org.glassfish.hk2.api.Injectee> |
getInjectees() |
ConfigInjector |
getInjector()
Gets the
ConfigInjector instance that can be used to inject
this DOM to a bean. |
String |
getKey()
Obtains the actual key value from this
Dom. |
Location |
getLocation()
Where was this
Dom loaded from? |
<T extends ConfigBeanProxy> |
getProxyType()
Returns the proxy type for this configuration object
|
Set<Annotation> |
getQualifierAnnotations() |
Class<? extends Annotation> |
getScopeAnnotation() |
org.glassfish.hk2.api.ServiceLocator |
getServiceLocator() |
Dom |
getSymbolSpaceRoot(String typeName)
Locates the DOM that serves as the symbol space root.
|
protected Object |
getter(ConfigModel.Property target,
Type t) |
int |
hashCode() |
void |
initializationCompleted() |
void |
inject(Object target)
Performs injection to the given object.
|
void |
insertAfter(Dom reference,
String name,
Dom newNode)
Inserts a new
Dom node right after the given DOM element. |
Object |
invoke(Object proxy,
Method method,
Object[] args)
InvocationHandler implementation that allows strongly-typed access
to the configuration. |
Object |
invoke(Object proxy,
String methodName,
Class[] argTypes,
Object[] args)
Another version of the
invoke(Object, Method, Object[]),
but instead of Method object, it takes the method name and argument types. |
boolean |
isCacheSet() |
boolean |
isReified()
This ensures no-one tried to reify this descriptor, which has an impl class
the interface
|
String |
leafElement(String name)
Picks up one leaf-element value.
|
List<String> |
leafElements(String name)
Picks up all leaf-element values of the given name.
|
<T> T |
nodeByTypeElement(Class<T> baseType) |
<T> List<T> |
nodeByTypeElements(Class<T> baseType) |
Dom |
nodeElement(String name)
Picks up one node-element value.
|
List<Dom> |
nodeElements(String elementName)
Picks up all node-elements that have the given element name.
|
Dom |
parent()
If this DOM is a child of another DOM, the parent pointer.
|
String |
rawAttribute(String name)
Obtians the attribute value without variable expansion.
|
String |
rawLeafElement(String name)
Picks up one leaf-element value without variable expansion.
|
List<String> |
rawLeafElements(String name)
Picks up all leaf-element values of the given name, without variable expansion.
|
void |
release() |
void |
releaseCache() |
void |
removeChild(Dom reference)
Removes an existing
NodeChild |
boolean |
removeLeafElement(String xmlName,
String element) |
boolean |
removeListener(ConfigListener listener)
Remove a listener
|
void |
replaceChild(Dom reference,
String name,
Dom newNode)
Replaces an existing
NodeChild with another one. |
Dom |
resolveReference(String key,
String typeName)
Recursively decends the DOM tree and finds a DOM that has the given key
and the type name.
|
void |
setCache(Object cacheMe) |
void |
setImplementationType(Type t) |
void |
setLeafElements(String name,
String... values)
Updates leaf-element values.
|
void |
setNodeElements(String name,
Dom... values)
Updates node-element values.
|
protected void |
setter(ConfigModel.Property target,
Object value) |
void |
skipFromXml()
This method should be invoked if this Dom should not be persisted
to the domain.xml file.
|
static Dom |
unwrap(ConfigBeanProxy proxy)
Unwraps the proxy and returns the underlying
Dom object. |
void |
writeTo(String tagName,
XMLStreamWriter w)
Writes back this element.
|
void |
writeToXml()
This method should be invoked if this Dom needs to be persisted to
domain.xml file
|
addContractType, addQualifierAnnotation, dispose, getScopeAsAnnotation, removeContractType, removeQualifierAnnotation, setFactoryId, setName, setReified, setScopeAnnotation, setScopeAsAnnotationaddAdvertisedContract, 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, writeObjectclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, isProxyForSameScope, setRankingpublic final ConfigModel model
public final DomDocument document
public Dom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model, XMLStreamReader in)
in - If provided, this is used to record the source location where this DOM object is loaded from.
Otherwise this can be null.public Dom(org.glassfish.hk2.api.ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model)
public void skipFromXml()
public void writeToXml()
public void initializationCompleted()
public void addDefaultChildren()
public org.glassfish.hk2.api.ServiceLocator getHabitat()
protected <T extends Dom> T copy(T parent)
parent - the parent instance for the cloned copypublic static Dom unwrap(ConfigBeanProxy proxy)
Dom object.public Dom parent()
public Set<String> getAttributeNames()
ConfigModel.getAttributeNames.public Set<String> getElementNames()
public String attribute(String name)
public String rawAttribute(String name)
public List<String> attributes(String name)
public void attribute(String name, String value)
public Dom element(String name)
name - of the elementpublic void insertAfter(Dom reference, String name, Dom newNode)
Dom node right after the given DOM element.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.public void replaceChild(Dom reference, String name, Dom newNode)
NodeChild with another one.insertAfter(Dom, String, Dom)public void removeChild(Dom reference)
NodeChildpublic boolean changeLeafElement(String xmlName, String oldValue, String newValue)
public String rawLeafElement(String name)
public void setLeafElements(String name, String... values)
Synchronized so that concurrenct modifications will work correctly.
public List<String> leafElements(String name)
public List<String> rawLeafElements(String name)
public void setNodeElements(String name, Dom... values)
Synchronized so that concurrenct modifications will work correctly.
public List<Dom> nodeElements(String elementName)
public List<Dom> domNodeByTypeElements(Class baseType)
FromElement("*").public <T> T nodeByTypeElement(Class<T> baseType)
public void inject(Object target)
public ConfigInjector getInjector()
ConfigInjector instance that can be used to inject
this DOM to a bean.public Dom getSymbolSpaceRoot(String typeName)
public Dom resolveReference(String key, String typeName)
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.
public <T extends ConfigBeanProxy> T createProxy(Class<T> proxyType)
Dom object,
by using the specified interface type as the proxy type.public <T extends ConfigBeanProxy> T createProxy()
Dom object,public <T extends ConfigBeanProxy> Class<T> getProxyType()
T - the proxy typepublic boolean isReified()
isReified in interface org.glassfish.hk2.api.ActiveDescriptorisReified in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Class<?> getImplementationClass()
getImplementationClass in interface org.glassfish.hk2.api.ActiveDescriptorpublic Type getImplementationType()
getImplementationType in interface org.glassfish.hk2.api.ActiveDescriptorpublic void setImplementationType(Type t)
setImplementationType in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Set<Type> getContractTypes()
getContractTypes in interface org.glassfish.hk2.api.ActiveDescriptorgetContractTypes in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Class<? extends Annotation> getScopeAnnotation()
getScopeAnnotation in interface org.glassfish.hk2.api.ActiveDescriptorgetScopeAnnotation in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Set<Annotation> getQualifierAnnotations()
getQualifierAnnotations in interface org.glassfish.hk2.api.ActiveDescriptorgetQualifierAnnotations in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic List<org.glassfish.hk2.api.Injectee> getInjectees()
getInjectees in interface org.glassfish.hk2.api.ActiveDescriptorgetInjectees in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Long getFactoryServiceId()
getFactoryServiceId in interface org.glassfish.hk2.api.ActiveDescriptorgetFactoryServiceId in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Long getFactoryLocatorId()
getFactoryLocatorId in interface org.glassfish.hk2.api.ActiveDescriptorgetFactoryLocatorId in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable
InvocationHandler implementation 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.
invoke in interface InvocationHandlerThrowablepublic Object invoke(Object proxy, String methodName, Class[] argTypes, Object[] args) throws Throwable
invoke(Object, Method, Object[]),
but instead of Method object, it takes the method name and argument types.Throwableprotected Object getter(ConfigModel.Property target, Type t)
protected void setter(ConfigModel.Property target, Object value) throws Exception
Exceptionprotected Creator createCreator(Class c)
There are two kinds — one where @Configured is put on
a bean and that is placedinto Habitat, and the other is
where @Configured is on ConfigBeanProxy subtype,
in which case the proxy to Dom will be placed into the habitat.
public static <T extends Annotation> T digAnnotation(Class<?> target, Class<T> annotationType)
public static <T extends Annotation> T digAnnotation(Class<?> target, Class<T> annotationType, List<Class<? extends Annotation>> visited)
public void writeTo(String tagName, XMLStreamWriter w) throws XMLStreamException
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.XMLStreamExceptionpublic void release()
public void addListener(ConfigListener listener)
ObservableBeanaddListener in interface ObservableBeanlistener - new listenerpublic boolean removeListener(ConfigListener listener)
ObservableBeanremoveListener in interface ObservableBeanlistener - to removepublic Object getCache()
getCache in interface org.glassfish.hk2.api.SingleCachegetCache in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic boolean isCacheSet()
isCacheSet in interface org.glassfish.hk2.api.SingleCacheisCacheSet in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic void setCache(Object cacheMe)
setCache in interface org.glassfish.hk2.api.SingleCachesetCache in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic void releaseCache()
releaseCache in interface org.glassfish.hk2.api.SingleCachereleaseCache in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic Object create(org.glassfish.hk2.api.ServiceHandle root)
create in interface org.glassfish.hk2.api.ActiveDescriptorpublic Object get()
public org.glassfish.hk2.api.ServiceLocator getServiceLocator()
public int hashCode()
hashCode in class org.glassfish.hk2.utilities.AbstractActiveDescriptorpublic boolean equals(Object o)
equals in class org.glassfish.hk2.utilities.AbstractActiveDescriptorCopyright © 2009-2017 Oracle Corporation. All Rights Reserved.