Search in sources :

Example 1 with JBossServiceXmlDescriptorParser

use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser in project wildfly by wildfly.

the class ServiceDeploymentParsingProcessor method deploy.

/**
     * Process a deployment for jboss-service.xml files. Will parse the xml file and attach a configuration discovered
     * during processing.
     *
     * @param phaseContext the deployment unit context
     * @throws DeploymentUnitProcessingException
     */
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = phaseContext.getDeploymentUnit().getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    if (deploymentRoot == null || !deploymentRoot.exists())
        return;
    VirtualFile serviceXmlFile = null;
    if (deploymentRoot.isDirectory()) {
        serviceXmlFile = deploymentRoot.getChild(SERVICE_DESCRIPTOR_PATH);
    } else if (deploymentRoot.getName().toLowerCase(Locale.ENGLISH).endsWith(SERVICE_DESCRIPTOR_SUFFIX)) {
        serviceXmlFile = deploymentRoot;
    }
    if (serviceXmlFile == null || !serviceXmlFile.exists())
        return;
    final XMLMapper xmlMapper = XMLMapper.Factory.create();
    final JBossServiceXmlDescriptorParser jBossServiceXmlDescriptorParser = new JBossServiceXmlDescriptorParser(JBossDescriptorPropertyReplacement.propertyReplacer(phaseContext.getDeploymentUnit()));
    xmlMapper.registerRootElement(new QName("urn:jboss:service:7.0", "server"), jBossServiceXmlDescriptorParser);
    xmlMapper.registerRootElement(new QName(null, "server"), jBossServiceXmlDescriptorParser);
    InputStream xmlStream = null;
    try {
        xmlStream = serviceXmlFile.openStream();
        final XMLStreamReader reader = inputFactory.createXMLStreamReader(xmlStream);
        final ParseResult<JBossServiceXmlDescriptor> result = new ParseResult<JBossServiceXmlDescriptor>();
        xmlMapper.parseDocument(result, reader);
        final JBossServiceXmlDescriptor xmlDescriptor = result.getResult();
        if (xmlDescriptor != null)
            phaseContext.getDeploymentUnit().putAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY, xmlDescriptor);
        else
            throw SarLogger.ROOT_LOGGER.failedXmlParsing(serviceXmlFile);
    } catch (Exception e) {
        throw SarLogger.ROOT_LOGGER.failedXmlParsing(e, serviceXmlFile);
    } finally {
        VFSUtils.safeClose(xmlStream);
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLMapper(org.jboss.staxmapper.XMLMapper) JBossServiceXmlDescriptor(org.jboss.as.service.descriptor.JBossServiceXmlDescriptor) XMLStreamReader(javax.xml.stream.XMLStreamReader) ParseResult(org.jboss.as.service.descriptor.ParseResult) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) JBossServiceXmlDescriptorParser(org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException)

Example 2 with JBossServiceXmlDescriptorParser

use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser in project wildfly by wildfly.

the class JBossServiceXmlDescriptorParserTestCase method setupParser.

@Before
public void setupParser() throws Exception {
    parser = new JBossServiceXmlDescriptorParser(propertyReplacer);
    xmlMapper = XMLMapper.Factory.create();
    xmlMapper.registerRootElement(new QName(JBossServiceXmlDescriptorParser.NAMESPACE, "server"), parser);
    inputFactory = XMLInputFactory.newInstance();
}
Also used : QName(javax.xml.namespace.QName) JBossServiceXmlDescriptorParser(org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser) Before(org.junit.Before)

Aggregations

QName (javax.xml.namespace.QName)2 JBossServiceXmlDescriptorParser (org.jboss.as.service.descriptor.JBossServiceXmlDescriptorParser)2 InputStream (java.io.InputStream)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)1 JBossServiceXmlDescriptor (org.jboss.as.service.descriptor.JBossServiceXmlDescriptor)1 ParseResult (org.jboss.as.service.descriptor.ParseResult)1 XMLMapper (org.jboss.staxmapper.XMLMapper)1 VirtualFile (org.jboss.vfs.VirtualFile)1 Before (org.junit.Before)1