本文整理了Java中org.jvnet.hk2.config.DomDocument
类的一些代码示例,展示了DomDocument
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DomDocument
类的具体详情如下:
包路径:org.jvnet.hk2.config.DomDocument
类名称:DomDocument
[英]Represents a whole DOM tree.
[中]表示整个DOM树。
代码示例来源:origin: javaee/glassfish
/**
* Obtains a {@link ConfigModel} for the given class (Which should have {@link Configured} annotation on it.)
*/
public ConfigModel buildModel(Class<?> clazz) {
return buildModel(clazz.getName());
}
代码示例来源:origin: javaee/glassfish
public DomDocument parse(XMLStreamReader in) throws XMLStreamException {
DomDocument document = new DomDocument(habitat);
parse(in, document);
return document;
}
代码示例来源:origin: javaee/glassfish
public static Class<? extends ConfigBeanProxy> getElementTypeByName(ConfigBeanProxy parent, String elementName)
throws ClassNotFoundException {
final Dom parentDom = Dom.unwrap(parent);
DomDocument document = parentDom.document;
ConfigModel.Property a = parentDom.model.elements.get(elementName);
if (a!=null) {
if (a.isLeaf()) {
// dochez : I am not too sure, but that should be a String @Element
return null;
} else {
ConfigModel childModel = ((ConfigModel.Node) a).model;
return (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
}
}
// global lookup
ConfigModel model = document.getModelByElementName(elementName);
if (model!=null) {
return (Class<? extends ConfigBeanProxy>) model.classLoaderHolder.loadClass(model.targetTypeName);
}
return null;
}
代码示例来源:origin: javaee/glassfish
/**
* Allocate a new ConfigBean object as part of the Transaction
* associated with this configuration object. This will eventually
* be moved to a factory.
*
* @param type the request configuration object type
* @return the properly constructed configuration object
*/
public ConfigBean allocate(Class<?> type) {
return (ConfigBean) document.make(getHabitat(), null, this, document.buildModel(type));
}
代码示例来源:origin: javaee/glassfish
/**
* probably a bit slow, calculates all the @Configured interfaces subclassing, useful
* to find all possible subclasses of a type.
*
* @throws ClassNotFoundException
*/
private void initXRef() throws ClassNotFoundException {
// force initialization of all the config models.
for (ServiceHandle<?> i : habitat.getAllServiceHandles(ConfigInjector.class)) {
buildModel((ActiveDescriptor<? extends ConfigInjector>) i.getActiveDescriptor());
}
for (ConfigModel cm : models.values()) {
Class targetType = cm.classLoaderHolder.loadClass(cm.targetTypeName);
do {
Class[] intfs = targetType.getInterfaces();
for (Class intf : intfs) {
if (intf.isAnnotationPresent(Configured.class)) {
addXRef(intf, cm);
}
}
targetType = targetType.getSuperclass();
} while (targetType!=null);
}
}
代码示例来源:origin: javaee/glassfish
/* package */ void ensureConstraints(List<Child> children) {
Set<String> nullElements = new HashSet<String>(model.getElementNames());
for (Child child : children) {
nullElements.remove(child.name);
}
for (String s : nullElements) {
ConfigModel.Property p = model.getElement(s);
for (String annotation : p.getAnnotations()) {
if (annotation.equals(NotNull.class.getName())) {
if (p instanceof ConfigModel.Node) {
ConfigModel childModel = ((ConfigModel.Node) p).model;
Dom child = document.make(getHabitat(), null, this, childModel);
child.register();
children.add(new Dom.NodeChild(s, child));
// recursive call to ensure the children constraints are also respected
List<Child> grandChildren = new ArrayList<Child>();
child.ensureConstraints(grandChildren);
if (!grandChildren.isEmpty()) {
child.setChildren(grandChildren);
}
child.initializationCompleted();
}
}
}
}
}
代码示例来源:origin: org.glassfish.main.core/kernel
@Override
public <T extends Container> T parseContainerConfig(ServiceLocator habitat, final URL configuration, Class<T> configType) throws IOException {
// I don't use the GlassFish document here as I don't need persistence
final DomDocument doc = new DomDocument<GlassFishConfigBean>(habitat) {
@Override
public Dom make(final ServiceLocator habitat, XMLStreamReader xmlStreamReader, GlassFishConfigBean dom, ConfigModel configModel) {
// by default, people get the translated view.
return new GlassFishConfigBean(habitat,this, dom, configModel, xmlStreamReader);
}
};
// add the new container configuration to the server config
final T container = doc.getRoot().createProxy(configType);
try {
ConfigSupport.apply(new SingleConfigCode<Config>() {
@Override
public Object run(Config config) throws PropertyVetoException, TransactionFailure {
config.getContainers().add(container);
return null;
}
}, config);
} catch(TransactionFailure e) {
logger.log(Level.SEVERE, KernelLoggerInfo.exceptionAddContainer, e);
}
return container;
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
}, Dom.unwrap(domain));
final Virtualizations defaultConfig = document.getRoot().createProxy(Virtualizations.class);
ConfigSupport.apply(new SingleConfigCode<Virtualizations>() {
@Override
代码示例来源:origin: org.glassfish.admin/config-api
public void transactionCommited(List<PropertyChangeEvent> changes) {
for (ConfigurationPersistence pers : habitat.getAllByContract(ConfigurationPersistence.class)) {
try {
if (doc.getRoot().getProxyType().equals(Domain.class)) {
Dom domainRoot = doc.getRoot();
domainRoot.attribute("version", Version.getBuildVersion());
}
pers.save(doc);
} catch (IOException e) {
logger.log(Level.SEVERE, "GlassFishDocument.IOException",
new String[] { e.getMessage() });
logger.log(Level.FINE, e.getMessage(), e);
} catch (XMLStreamException e) {
logger.log(Level.SEVERE, "GlassFishDocument.XMLException",
new String[] { e.getMessage() });
logger.log(Level.SEVERE, e.getMessage(), e);
}
}
}
代码示例来源:origin: org.glassfish.main.admingui/console-plugin-service
ConsoleConfig config = (ConsoleConfig) doc.getRoot().get();
代码示例来源:origin: org.glassfish.admin/config-api
throws ClassNotFoundException {
ConfigModel cm = document.buildModel(parent);
for (String elementName : cm.getElementNames()) {
ConfigModel.Property prop = cm.getElement(elementName);
List<ConfigModel> subChildrenModels = document.getAllModelsImplementing(
childCM.classLoaderHolder.get().loadClass(childTypeName));
if (subChildrenModels!=null) {
代码示例来源:origin: org.glassfish.main.common/amx-core
/** works only for @Configured types */
public static Class[] getTypesImplementing(final Class<?> clazz)
{
final DomDocument domDoc = new DomDocument(InjectedValues.getInstance().getHabitat());
try
{
final List<ConfigModel> models = domDoc.getAllModelsImplementing(clazz);
final Class[] interfaces = new Class[models == null ? 0 : models.size()];
if (models != null)
{
int i = 0;
for (final ConfigModel model : models)
{
final String classname = model.targetTypeName;
final Class<?> intf = model.classLoaderHolder.loadClass(classname);
interfaces[i] = intf;
//System.out.println( "Loaded: " + intf + " with tagName of " + model.getTagName() );
++i;
}
}
return interfaces;
}
catch (final Exception e)
{
AMXLoggerInfo.getLogger().log( Level.INFO, AMXLoggerInfo.cantGetTypesImplementing,
new Object[] {clazz, e.getLocalizedMessage()} );
throw new RuntimeException(e);
}
}
代码示例来源:origin: javaee/glassfish
/**
* Performs translation with null pass-through.
*/
private String t(String s) {
if(s==null) return null;
return document.getTranslator().translate(s);
}
代码示例来源:origin: javaee/glassfish
/**
* Calculates all @Configured interfaces subclassing the passed interface type.
*
* @param intf a @Configured interface
* @return List of all @Configured subclasses
* @throws ClassNotFoundException
*/
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
if (implementorsOf.size()==0) {
initXRef();
}
return implementorsOf.getOne(intf);
}
代码示例来源:origin: javaee/glassfish
ConfigModel model = document.getModelByElementName(in.getLocalName());
if(model==null) {
String localName = in.getLocalName();
代码示例来源:origin: javaee/glassfish
final Dom dom = document.make(habitat, in, parent, model);
dom.fillAttributes(in);
children = new ArrayList<Dom.Child>();
dom.ensureConstraints(children);
dom.setChildren(children);
dom.register();
代码示例来源:origin: org.glassfish.main.admin/server-mgmt
URL domainURL = domainXMLFile.toURI().toURL();
DomDocument doc = parser.parse(domainURL);
Dom domDomain = doc.getRoot();
Domain domain = domDomain.createProxy(Domain.class);
DomainXmlVerifier validator = new DomainXmlVerifier(domain);
代码示例来源:origin: org.glassfish.main.admin/config-api
public void transactionCommited(List<PropertyChangeEvent> changes) {
if (!isGlassFishDocumentChanged(changes)) {
return;
}
for (ConfigurationPersistence pers : habitat.<ConfigurationPersistence>getAllServices(ConfigurationPersistence.class)) {
try {
if (doc.getRoot().getProxyType().equals(Domain.class)) {
Dom domainRoot = doc.getRoot();
domainRoot.attribute("version", Version.getBuildVersion());
}
pers.save(doc);
} catch (IOException e) {
logger.log(Level.SEVERE,
ConfigApiLoggerInfo.glassFishDocumentIOException,e);
} catch (XMLStreamException e) {
logger.log(Level.SEVERE,
ConfigApiLoggerInfo.glassFishDocumentXmlException,e);
}
}
}
代码示例来源:origin: eclipse-ee4j/glassfish
ConsoleConfig config = (ConsoleConfig) doc.getRoot().get();
代码示例来源:origin: org.glassfish.hk2/config
/**
* Allocate a new ConfigBean object as part of the Transaction
* associated with this configuration object. This will eventually
* be moved to a factory.
*
* @param type the request configuration object type
* @return the properly constructed configuration object
*/
public ConfigBean allocate(Class<?> type) {
return (ConfigBean) document.make(habitat, null, this, document.buildModel(type));
}
内容来源于网络,如有侵权,请联系作者删除!