public class Dom extends AbstractActiveDescriptor implements java.lang.reflect.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(ServiceLocator habitat,
DomDocument document,
Dom parent,
ConfigModel model) |
Dom(ServiceLocator habitat,
DomDocument document,
Dom parent,
ConfigModel model,
javax.xml.stream.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(java.lang.String xmlName,
java.lang.String value) |
void |
addListener(ConfigListener listener)
Add a new listener to configuration changes.
|
java.lang.String |
attribute(java.lang.String name)
Obtains the attribute value, after variable expansion.
|
void |
attribute(java.lang.String name,
java.lang.String value)
Updates the attribute value.
|
java.util.List<java.lang.String> |
attributes(java.lang.String name)
Obtains the plural attribute value.
|
boolean |
changeLeafElement(java.lang.String xmlName,
java.lang.String oldValue,
java.lang.String newValue) |
static java.lang.String |
convertName(java.lang.String name) |
protected <T extends Dom> |
copy(T parent)
Returns a copy of itself providing the parent for the new copy.
|
java.lang.Object |
create(ServiceHandle root) |
protected Creator |
createCreator(java.lang.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(java.lang.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 java.lang.annotation.Annotation> |
digAnnotation(java.lang.Class<?> target,
java.lang.Class<T> annotationType) |
static <T extends java.lang.annotation.Annotation> |
digAnnotation(java.lang.Class<?> target,
java.lang.Class<T> annotationType,
java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> visited) |
java.util.List<Dom> |
domNodeByTypeElements(java.lang.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(java.lang.String name)
Returns the child element by name
|
boolean |
equals(java.lang.Object o) |
java.lang.Object |
get() |
java.util.Set<java.lang.String> |
getAttributeNames()
Returns the list of attributes with a value on this config instance.
|
java.lang.Object |
getCache() |
java.util.Set<java.lang.reflect.Type> |
getContractTypes() |
java.util.Set<java.lang.String> |
getElementNames()
Returns the children name associated with this config instance.
|
java.lang.Long |
getFactoryLocatorId() |
java.lang.Long |
getFactoryServiceId() |
ServiceLocator |
getHabitat() |
java.lang.Class<?> |
getImplementationClass() |
java.util.List<Injectee> |
getInjectees() |
ConfigInjector |
getInjector()
Gets the
ConfigInjector instance that can be used to inject
this DOM to a bean. |
java.lang.String |
getKey()
Obtains the actual key value from this
Dom. |
javax.xml.stream.Location |
getLocation()
Where was this
Dom loaded from? |
<T extends ConfigBeanProxy> |
getProxyType()
Returns the proxy type for this configuration object
|
java.util.Set<java.lang.annotation.Annotation> |
getQualifierAnnotations() |
java.lang.Class<? extends java.lang.annotation.Annotation> |
getScopeAnnotation() |
ServiceLocator |
getServiceLocator() |
Dom |
getSymbolSpaceRoot(java.lang.String typeName)
Locates the DOM that serves as the symbol space root.
|
protected java.lang.Object |
getter(ConfigModel.Property target,
java.lang.reflect.Type t) |
int |
hashCode() |
void |
initializationCompleted() |
void |
inject(java.lang.Object target)
Performs injection to the given object.
|
void |
insertAfter(Dom reference,
java.lang.String name,
Dom newNode)
Inserts a new
Dom node right after the given DOM element. |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
InvocationHandler implementation that allows strongly-typed access
to the configuration. |
java.lang.Object |
invoke(java.lang.Object proxy,
java.lang.String methodName,
java.lang.Class[] argTypes,
java.lang.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
|
java.lang.String |
leafElement(java.lang.String name)
Picks up one leaf-element value.
|
java.util.List<java.lang.String> |
leafElements(java.lang.String name)
Picks up all leaf-element values of the given name.
|
<T> T |
nodeByTypeElement(java.lang.Class<T> baseType) |
<T> java.util.List<T> |
nodeByTypeElements(java.lang.Class<T> baseType) |
Dom |
nodeElement(java.lang.String name)
Picks up one node-element value.
|
java.util.List<Dom> |
nodeElements(java.lang.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.
|
java.lang.String |
rawAttribute(java.lang.String name)
Obtians the attribute value without variable expansion.
|
java.lang.String |
rawLeafElement(java.lang.String name)
Picks up one leaf-element value without variable expansion.
|
java.util.List<java.lang.String> |
rawLeafElements(java.lang.String name)
Picks up all leaf-element values of the given name, without variable expansion.
|
void |
releaseCache() |
void |
removeChild(Dom reference)
Removes an existing
NodeChild |
boolean |
removeLeafElement(java.lang.String xmlName,
java.lang.String element) |
boolean |
removeListener(ConfigListener listener)
Remove a listener
|
void |
replaceChild(Dom reference,
java.lang.String name,
Dom newNode)
Replaces an existing
NodeChild with another one. |
Dom |
resolveReference(java.lang.String key,
java.lang.String typeName)
Recursively decends the DOM tree and finds a DOM that has the given key
and the type name.
|
void |
setCache(java.lang.Object cacheMe) |
void |
setLeafElements(java.lang.String name,
java.lang.String... values)
Updates leaf-element values.
|
void |
setNodeElements(java.lang.String name,
Dom... values)
Updates node-element values.
|
protected void |
setter(ConfigModel.Property target,
java.lang.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(java.lang.String tagName,
javax.xml.stream.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, removeContractType, removeQualifierAnnotation, setFactoryId, setName, setReifiedaddAdvertisedContract, addMetadata, addMetadata, addQualifier, clearMetadata, getAdvertisedContracts, getClassAnalysisName, getDescriptorType, getDescriptorVisibility, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, isProxiable, pretty, readExternal, readObject, removeAdvertisedContract, removeAllMetadata, removeMetadata, removeQualifier, setClassAnalysisName, setDescriptorType, setDescriptorVisibility, setImplementation, setLoader, setLocatorId, setMetadata, setProxiable, 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, setRankingpublic final ConfigModel model
public final DomDocument document
public Dom(ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model, javax.xml.stream.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(ServiceLocator habitat, DomDocument document, Dom parent, ConfigModel model)
public void skipFromXml()
public void writeToXml()
public void initializationCompleted()
public void addDefaultChildren()
public 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 java.lang.String getKey()
Dom.public Dom parent()
public javax.xml.stream.Location getLocation()
Dom loaded from?public java.util.Set<java.lang.String> getAttributeNames()
ConfigModel.getAttributeNames.public java.util.Set<java.lang.String> getElementNames()
public java.lang.String attribute(java.lang.String name)
public java.lang.String rawAttribute(java.lang.String name)
public java.util.List<java.lang.String> attributes(java.lang.String name)
public void attribute(java.lang.String name,
java.lang.String value)
public Dom element(java.lang.String name)
name - of the elementpublic java.lang.String leafElement(java.lang.String name)
public void insertAfter(Dom reference, java.lang.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, java.lang.String name, Dom newNode)
NodeChild with another one.insertAfter(Dom, String, Dom)public void removeChild(Dom reference)
NodeChildpublic boolean addLeafElement(java.lang.String xmlName,
java.lang.String value)
public boolean removeLeafElement(java.lang.String xmlName,
java.lang.String element)
public boolean changeLeafElement(java.lang.String xmlName,
java.lang.String oldValue,
java.lang.String newValue)
public java.lang.String rawLeafElement(java.lang.String name)
public void setLeafElements(java.lang.String name,
java.lang.String... values)
Synchronized so that concurrenct modifications will work correctly.
public java.util.List<java.lang.String> leafElements(java.lang.String name)
public java.util.List<java.lang.String> rawLeafElements(java.lang.String name)
public Dom nodeElement(java.lang.String name)
public void setNodeElements(java.lang.String name,
Dom... values)
Synchronized so that concurrenct modifications will work correctly.
public java.util.List<Dom> nodeElements(java.lang.String elementName)
public java.util.List<Dom> domNodeByTypeElements(java.lang.Class baseType)
FromElement("*").public <T> java.util.List<T> nodeByTypeElements(java.lang.Class<T> baseType)
public <T> T nodeByTypeElement(java.lang.Class<T> baseType)
public void inject(java.lang.Object target)
public ConfigInjector getInjector()
ConfigInjector instance that can be used to inject
this DOM to a bean.public Dom getSymbolSpaceRoot(java.lang.String typeName)
public Dom resolveReference(java.lang.String key, java.lang.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(java.lang.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> java.lang.Class<T> getProxyType()
T - the proxy typepublic boolean isReified()
isReified in interface ActiveDescriptorisReified in class AbstractActiveDescriptorpublic java.lang.Class<?> getImplementationClass()
getImplementationClass in interface ActiveDescriptorpublic java.util.Set<java.lang.reflect.Type> getContractTypes()
getContractTypes in interface ActiveDescriptorgetContractTypes in class AbstractActiveDescriptorpublic java.lang.Class<? extends java.lang.annotation.Annotation> getScopeAnnotation()
getScopeAnnotation in interface ActiveDescriptorgetScopeAnnotation in class AbstractActiveDescriptorpublic java.util.Set<java.lang.annotation.Annotation> getQualifierAnnotations()
getQualifierAnnotations in interface ActiveDescriptorgetQualifierAnnotations in class AbstractActiveDescriptorpublic java.util.List<Injectee> getInjectees()
getInjectees in interface ActiveDescriptorgetInjectees in class AbstractActiveDescriptorpublic java.lang.Long getFactoryServiceId()
getFactoryServiceId in interface ActiveDescriptorgetFactoryServiceId in class AbstractActiveDescriptorpublic java.lang.Long getFactoryLocatorId()
getFactoryLocatorId in interface ActiveDescriptorgetFactoryLocatorId in class AbstractActiveDescriptorpublic java.lang.Object invoke(java.lang.Object proxy,
java.lang.reflect.Method method,
java.lang.Object[] args)
throws java.lang.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 java.lang.reflect.InvocationHandlerjava.lang.Throwablepublic java.lang.Object invoke(java.lang.Object proxy,
java.lang.String methodName,
java.lang.Class[] argTypes,
java.lang.Object[] args)
throws java.lang.Throwable
invoke(Object, Method, Object[]),
but instead of Method object, it takes the method name and argument types.java.lang.Throwableprotected java.lang.Object getter(ConfigModel.Property target, java.lang.reflect.Type t)
protected void setter(ConfigModel.Property target, java.lang.Object value) throws java.lang.Exception
java.lang.Exceptionpublic static java.lang.String convertName(java.lang.String name)
protected Creator createCreator(java.lang.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 java.lang.annotation.Annotation> T digAnnotation(java.lang.Class<?> target,
java.lang.Class<T> annotationType)
public static <T extends java.lang.annotation.Annotation> T digAnnotation(java.lang.Class<?> target,
java.lang.Class<T> annotationType,
java.util.List<java.lang.Class<? extends java.lang.annotation.Annotation>> visited)
public void writeTo(java.lang.String tagName,
javax.xml.stream.XMLStreamWriter w)
throws javax.xml.stream.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.javax.xml.stream.XMLStreamExceptionpublic void addListener(ConfigListener listener)
ObservableBeanaddListener in interface ObservableBeanlistener - new listenerpublic boolean removeListener(ConfigListener listener)
ObservableBeanremoveListener in interface ObservableBeanlistener - to removepublic java.lang.Object getCache()
getCache in interface SingleCachegetCache in class AbstractActiveDescriptorpublic boolean isCacheSet()
isCacheSet in interface SingleCacheisCacheSet in class AbstractActiveDescriptorpublic void setCache(java.lang.Object cacheMe)
setCache in interface SingleCachesetCache in class AbstractActiveDescriptorpublic void releaseCache()
releaseCache in interface SingleCachereleaseCache in class AbstractActiveDescriptorpublic java.lang.Object create(ServiceHandle root)
create in interface ActiveDescriptorpublic java.lang.Object get()
public ServiceLocator getServiceLocator()
public int hashCode()
hashCode in class DescriptorImplpublic boolean equals(java.lang.Object o)
equals in class DescriptorImplCopyright © 2013 Oracle Corporation. All Rights Reserved.