org.jboss.staxmapper.XMLElementWriter Java Examples
The following examples show how to use
org.jboss.staxmapper.XMLElementWriter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
@Override public void writeContent(XMLExtendedStreamWriter writer, ModelMarshallingContext context) throws XMLStreamException { String defaultNamespace = writer.getNamespaceContext().getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX); try { ModelNode subsystems = context.getModelNode().get(SUBSYSTEM); if (subsystems.has(mainSubsystemName)) { ModelNode subsystem = subsystems.get(mainSubsystemName); //We might have been removed XMLElementWriter<SubsystemMarshallingContext> subsystemWriter = context.getSubsystemWriter(mainSubsystemName); if (subsystemWriter != null) { subsystemWriter.writeContent(writer, new SubsystemMarshallingContext(subsystem, writer)); } }else{ writer.writeEmptyElement(Element.SUBSYSTEM.getLocalName()); } }catch (Throwable t){ Assert.fail("could not marshal subsystem xml: "+t.getMessage()+":\n"+ Arrays.toString(t.getStackTrace()).replaceAll(", ","\n")); } finally { writer.setDefaultNamespace(defaultNamespace); } writer.writeEndDocument(); }
Example #2
Source File: AbstractMgmtTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public String modelToXml(String subsystemName, String childType, XMLElementWriter<SubsystemMarshallingContext> parser) throws Exception { final ModelNode address = new ModelNode(); address.add("subsystem", subsystemName); address.protect(); final ModelNode operation = new ModelNode(); operation.get(OP).set("read-children-resources"); operation.get("child-type").set(childType); operation.get(RECURSIVE).set(true); operation.get(OP_ADDR).set(address); final ModelNode result = executeOperation(operation); Assert.assertNotNull(result); ModelNode dsNode = new ModelNode(); dsNode.get(childType).set(result); StringWriter strWriter = new StringWriter(); XMLExtendedStreamWriter writer = XMLExtendedStreamWriterFactory.create(XMLOutputFactory.newInstance() .createXMLStreamWriter(strWriter)); parser.writeContent(writer, new SubsystemMarshallingContext(dsNode, writer)); writer.flush(); return strWriter.toString(); }
Example #3
Source File: TestParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private ModelMarshallingContext sanitizeContext(final ModelMarshallingContext context) { if (writeSanitizers == null) { return context; } ModelNode model = context.getModelNode(); for (ModelWriteSanitizer sanitizer : writeSanitizers) { model = sanitizer.sanitize(model); } final ModelNode theModel = model; return new ModelMarshallingContext() { @Override public XMLElementWriter<SubsystemMarshallingContext> getSubsystemWriter(String subsystemName) { return context.getSubsystemWriter(subsystemName); } @Override public ModelNode getModelNode() { return theModel; } }; }
Example #4
Source File: TestParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private ModelMarshallingContext wrapPossibleHost(final ModelMarshallingContext context) { if (type == TestModelType.HOST) { return new ModelMarshallingContext() { @Override public XMLElementWriter<SubsystemMarshallingContext> getSubsystemWriter(String subsystemName) { return context.getSubsystemWriter(subsystemName); } @Override public ModelNode getModelNode() { return context.getModelNode().get(ModelDescriptionConstants.HOST, "master"); } }; } return context; }
Example #5
Source File: GitConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public GitConfigurationPersister(GitRepository gitRepository, ConfigurationFile file, QName rootElement, XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser, boolean suppressLoad) { super(file.getBootFile(), rootElement, rootParser, rootDeparser, suppressLoad); root = file.getConfigurationDir().getParentFile().toPath(); mainFile = file.getMainFile(); this.gitRepository = gitRepository; File baseDir = root.toFile(); try { File gitDir = new File(baseDir, Constants.DOT_GIT); if(!gitDir.exists()) { gitDir.mkdir(); } if (gitRepository.isBare()) { Git.init().setDirectory(baseDir).setGitDir(gitDir).call(); ServerLogger.ROOT_LOGGER.gitRespositoryInitialized(baseDir.getAbsolutePath()); } } catch (IllegalStateException | GitAPIException e) { ControllerLogger.ROOT_LOGGER.error(e); } }
Example #6
Source File: PatchXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public static void marshal(final Writer writer, final Patch patch) throws XMLStreamException { final XMLOutputFactory outputFactory = OUTPUT_FACTORY; final XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer); final XMLElementWriter<?> xmlWriter = XML1_0; MAPPER.deparseDocument(xmlWriter, patch, streamWriter); streamWriter.close(); }
Example #7
Source File: AbstractConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** {@inheritDoc} */ @Override public void marshallAsXml(final ModelNode model, final OutputStream output) throws ConfigurationPersistenceException { final XMLMapper mapper = XMLMapper.Factory.create(); final Map<String, XMLElementWriter<SubsystemMarshallingContext>> localSubsystemWriters = new HashMap<>(subsystemWriters); try { XMLStreamWriter streamWriter = null; try { streamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(output); final ModelMarshallingContext extensibleModel = new ModelMarshallingContext() { @Override public ModelNode getModelNode() { return model; } @Override public XMLElementWriter<SubsystemMarshallingContext> getSubsystemWriter(String extensionName) { //lazy create writer, but only once per config serialization XMLElementWriter<SubsystemMarshallingContext> result = localSubsystemWriters.get(extensionName); if (result == null) { Supplier<XMLElementWriter<SubsystemMarshallingContext>> supplier = subsystemWriterSuppliers.get(extensionName); if (supplier != null) { result = supplier.get(); localSubsystemWriters.put(extensionName, result); } } return result; } }; mapper.deparseDocument(rootDeparser, extensibleModel, streamWriter); streamWriter.close(); } finally { safeClose(streamWriter); } } catch (Exception e) { throw ControllerLogger.ROOT_LOGGER.failedToWriteConfiguration(e); } }
Example #8
Source File: XmlConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Construct a new instance. * * @param fileName the configuration base file name * @param rootElement the root element of the configuration file * @param rootParser the root model parser * @param rootDeparser the root model deparser */ public XmlConfigurationPersister(final File fileName, final QName rootElement, final XMLElementReader<List<ModelNode>> rootParser, final XMLElementWriter<ModelMarshallingContext> rootDeparser, final boolean suppressLoad) { super(rootDeparser); this.fileName = fileName; this.rootElement = rootElement; this.rootParser = rootParser; this.additionalParsers = new HashMap<QName, XMLElementReader<List<ModelNode>>>(); this.suppressLoad = suppressLoad; }
Example #9
Source File: CommonXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
protected static void writeSubsystems(final ModelNode profileNode, final XMLExtendedStreamWriter writer, final ModelMarshallingContext context) throws XMLStreamException { if (profileNode.hasDefined(SUBSYSTEM)) { Set<String> subsystemNames = profileNode.get(SUBSYSTEM).keys(); if (subsystemNames.size() > 0) { // establish traditional 'logging then alphabetical' ordering // note that logging first is just tradition; it's not necessary technically Set<String> alphabetical = new TreeSet<>(subsystemNames); if (alphabetical.contains("logging")) { subsystemNames = new LinkedHashSet<>(); subsystemNames.add("logging"); subsystemNames.addAll(alphabetical); } else { subsystemNames = alphabetical; } String defaultNamespace = writer.getNamespaceContext().getNamespaceURI(XMLConstants.DEFAULT_NS_PREFIX); for (String subsystemName : subsystemNames) { try { ModelNode subsystem = profileNode.get(SUBSYSTEM, subsystemName); XMLElementWriter<SubsystemMarshallingContext> subsystemWriter = context.getSubsystemWriter(subsystemName); if (subsystemWriter != null) { // FIXME -- remove when extensions are doing the registration subsystemWriter.writeContent(writer, new SubsystemMarshallingContext(subsystem, writer)); } } finally { writer.setDefaultNamespace(defaultNamespace); } } } } }
Example #10
Source File: BootstrapPersister.java From thorntail with Apache License 2.0 | 4 votes |
@Override public void registerSubsystemWriter(String name, XMLElementWriter<SubsystemMarshallingContext> writer) { delegate.registerSubsystemWriter(name, writer); }
Example #11
Source File: AbstractConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, Supplier<XMLElementWriter<SubsystemMarshallingContext>> writer) { subsystemWriterSuppliers.putIfAbsent(name, writer); }
Example #12
Source File: NullConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public NullConfigurationPersister(XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); }
Example #13
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public EmptyConfigurationPersister(XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); }
Example #14
Source File: GitConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public GitConfigurationPersister(GitRepository gitRepository, ConfigurationFile file, QName rootElement, XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser) { this(gitRepository, file, rootElement, rootParser, rootDeparser, false); }
Example #15
Source File: InterfaceManagementUnitTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public StringConfigurationPersister(List<ModelNode> bootOperations, XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); this.bootOperations = bootOperations; }
Example #16
Source File: TestParser.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public TestParser(TestModelType type, XMLElementReader<List<ModelNode>> reader, XMLElementWriter<ModelMarshallingContext> writer) { this.type = type; this.reader = reader; this.writer = writer; }
Example #17
Source File: StringConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public StringConfigurationPersister(List<ModelNode> bootOperations, XMLElementWriter<ModelMarshallingContext> rootDeparser, boolean persistXml) { super(rootDeparser); this.bootOperations = bootOperations; this.persistXml = persistXml; }
Example #18
Source File: PatchXml.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
protected static void marshal(final OutputStream os, final Patch patch, final XMLElementWriter<? extends Patch> xmlWriter) throws XMLStreamException { final XMLOutputFactory outputFactory = OUTPUT_FACTORY; final XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(os); MAPPER.deparseDocument(xmlWriter, patch, streamWriter); streamWriter.close(); }
Example #19
Source File: ExtensionRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerXMLElementWriter(Supplier<XMLElementWriter<SubsystemMarshallingContext>> writer) { writerRegistry.registerSubsystemWriter(name, writer); }
Example #20
Source File: BootstrapPersister.java From thorntail with Apache License 2.0 | 4 votes |
@Override public void registerSubsystemWriter(String name, Supplier<XMLElementWriter<SubsystemMarshallingContext>> supplier) { delegate.registerSubsystemWriter(name, supplier); }
Example #21
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public EmptyConfigurationPersister(XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); }
Example #22
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public EmptyConfigurationPersister(XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); }
Example #23
Source File: ConfigurationPersisterFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
BackupRemoteDomainXmlPersister(File file, File bootFile, QName rootElement, XMLElementReader<List<ModelNode>> rootParser, XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(file, rootElement, rootParser, rootDeparser); this.bootWriter = new XmlConfigurationPersister(bootFile, rootElement, rootParser, rootDeparser); this.file = file; this.bootFile = bootFile; }
Example #24
Source File: ConfigurationPersisterFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, XMLElementWriter<SubsystemMarshallingContext> deparser) { bootWriter.registerSubsystemWriter(name, deparser); super.registerSubsystemWriter(name, deparser); }
Example #25
Source File: ConfigurationPersisterFactory.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, Supplier<XMLElementWriter<SubsystemMarshallingContext>> writer) { bootWriter.registerSubsystemWriter(name, writer); super.registerSubsystemWriter(name, writer); }
Example #26
Source File: HostControllerConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, XMLElementWriter<SubsystemMarshallingContext> writer) { domainPersister.registerSubsystemWriter(name, writer); }
Example #27
Source File: HostControllerConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, Supplier<XMLElementWriter<SubsystemMarshallingContext>> writer) { domainPersister.registerSubsystemWriter(name, writer); }
Example #28
Source File: AbstractControllerTestBase.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public EmptyConfigurationPersister(XMLElementWriter<ModelMarshallingContext> rootDeparser) { super(rootDeparser); }
Example #29
Source File: ExtensionRegistry.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerXMLElementWriter(XMLElementWriter<SubsystemMarshallingContext> writer) { writerRegistry.registerSubsystemWriter(name, writer); }
Example #30
Source File: AbstractConfigurationPersister.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
@Override public void registerSubsystemWriter(String name, XMLElementWriter<SubsystemMarshallingContext> writer) { subsystemWriters.putIfAbsent(name, writer); }