Search in sources :

Example 1 with PropertyResolver

use of org.jboss.metadata.property.PropertyResolver in project teiid by teiid.

the class VDBParserDeployer method parseVDBXML.

private VDBMetaData parseVDBXML(VirtualFile file, DeploymentUnit deploymentUnit, DeploymentPhaseContext phaseContext, boolean xmlDeployment) throws DeploymentUnitProcessingException {
    try {
        VDBMetadataParser.validate(file.openStream());
        PropertyResolver propertyResolver = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_RESOLVER);
        PropertyReplacer replacer = PropertyReplacers.resolvingReplacer(propertyResolver);
        String vdbContents = replacer.replaceProperties(ObjectConverterUtil.convertToString(file.openStream()));
        // $NON-NLS-1$
        VDBMetaData vdb = VDBMetadataParser.unmarshell(new ByteArrayInputStream(vdbContents.getBytes("UTF-8")));
        ServiceController<?> sc = phaseContext.getServiceRegistry().getService(TeiidServiceNames.OBJECT_SERIALIZER);
        ObjectSerializer serializer = ObjectSerializer.class.cast(sc.getValue());
        if (serializer.buildVdbXml(vdb).exists()) {
            vdb = VDBMetadataParser.unmarshell(new FileInputStream(serializer.buildVdbXml(vdb)));
        }
        vdb.setStatus(Status.LOADING);
        if (xmlDeployment) {
            vdb.setXmlDeployment(true);
        } else {
            String name = deploymentUnit.getName();
            // $NON-NLS-1$
            String fileName = StringUtil.getLastToken(name, "/");
            int index = fileName.indexOf('.');
            int lastIndex = fileName.lastIndexOf('.');
            if (index > 0 && index != lastIndex && fileName.substring(0, index).equals(vdb.getName())) {
                vdb.setVersion(name.substring(index + 1, lastIndex));
            }
        }
        deploymentUnit.putAttachment(TeiidAttachments.VDB_METADATA, vdb);
        // $NON-NLS-1$ //$NON-NLS-2$
        LogManager.logDetail(LogConstants.CTX_RUNTIME, "VDB " + file.getName() + " has been parsed.");
        return vdb;
    } catch (XMLStreamException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    } catch (IOException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    } catch (SAXException e) {
        throw new DeploymentUnitProcessingException(IntegrationPlugin.Event.TEIID50017.name(), e);
    }
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) IOException(java.io.IOException) PropertyResolver(org.jboss.metadata.property.PropertyResolver) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer)

Example 2 with PropertyResolver

use of org.jboss.metadata.property.PropertyResolver in project wildfly by wildfly.

the class DeploymentPropertyResolverProcessor method deploy.

public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    DeploymentUnit current = deploymentUnit;
    final List<PropertyResolver> propertyResolvers = new ArrayList<PropertyResolver>();
    do {
        final Properties deploymentProperties = current.getAttachment(Attachments.DEPLOYMENT_PROPERTIES);
        if (deploymentProperties != null) {
            propertyResolvers.add(new PropertiesPropertyResolver(deploymentProperties));
        }
        current = current.getParent();
    } while (current != null);
    if (!propertyResolvers.isEmpty()) {
        deploymentUnit.addToAttachmentList(Attachments.DEPLOYMENT_PROPERTY_RESOLVERS, new CompositePropertyResolver(propertyResolvers));
    }
}
Also used : PropertiesPropertyResolver(org.jboss.metadata.property.PropertiesPropertyResolver) ArrayList(java.util.ArrayList) PropertyResolver(org.jboss.metadata.property.PropertyResolver) PropertiesPropertyResolver(org.jboss.metadata.property.PropertiesPropertyResolver) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver) Properties(java.util.Properties) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) CompositePropertyResolver(org.jboss.metadata.property.CompositePropertyResolver)

Example 3 with PropertyResolver

use of org.jboss.metadata.property.PropertyResolver in project wildfly by wildfly.

the class DsXmlDeploymentParsingProcessor method deploy.

/**
 * Process a deployment for standard ra deployment files. Will parse the xml
 * file and attach a configuration discovered during processing.
 *
 * @param phaseContext the deployment unit context
 * @throws DeploymentUnitProcessingException
 */
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    boolean resolveProperties = Util.shouldResolveJBoss(deploymentUnit);
    final PropertyResolver propertyResolver = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_RESOLVER);
    final PropertyReplacer propertyReplacer = deploymentUnit.getAttachment(org.jboss.as.ee.metadata.property.Attachments.FINAL_PROPERTY_REPLACER);
    final Set<VirtualFile> files = dataSources(deploymentUnit);
    boolean loggedDeprication = false;
    for (VirtualFile f : files) {
        InputStream xmlStream = null;
        try {
            xmlStream = new FileInputStream(f.getPhysicalFile());
            DsXmlParser parser = new DsXmlParser(propertyResolver, propertyReplacer);
            parser.setSystemPropertiesResolved(resolveProperties);
            DataSources dataSources = parser.parse(xmlStream);
            if (dataSources != null) {
                if (!loggedDeprication) {
                    loggedDeprication = true;
                    ConnectorLogger.ROOT_LOGGER.deprecated();
                }
                for (DataSource ds : dataSources.getDataSource()) {
                    if (ds.getDriver() == null) {
                        throw ConnectorLogger.ROOT_LOGGER.FailedDeployDriverNotSpecified(ds.getJndiName());
                    }
                }
                deploymentUnit.addToAttachmentList(DATA_SOURCES_ATTACHMENT_KEY, dataSources);
            }
        } catch (Exception e) {
            throw new DeploymentUnitProcessingException(e.getMessage(), e);
        } finally {
            VFSUtils.safeClose(xmlStream);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) PropertyResolver(org.jboss.metadata.property.PropertyResolver) FileInputStream(java.io.FileInputStream) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) DataSource(org.jboss.jca.common.api.metadata.ds.DataSource) DataSources(org.jboss.jca.common.api.metadata.ds.DataSources) DsXmlParser(org.jboss.as.connector.deployers.ds.DsXmlParser) PropertyReplacer(org.jboss.metadata.property.PropertyReplacer) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

PropertyResolver (org.jboss.metadata.property.PropertyResolver)3 FileInputStream (java.io.FileInputStream)2 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)2 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)2 PropertyReplacer (org.jboss.metadata.property.PropertyReplacer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 DsXmlParser (org.jboss.as.connector.deployers.ds.DsXmlParser)1 DataSource (org.jboss.jca.common.api.metadata.ds.DataSource)1 DataSources (org.jboss.jca.common.api.metadata.ds.DataSources)1 CompositePropertyResolver (org.jboss.metadata.property.CompositePropertyResolver)1 PropertiesPropertyResolver (org.jboss.metadata.property.PropertiesPropertyResolver)1 VirtualFile (org.jboss.vfs.VirtualFile)1 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)1 SAXException (org.xml.sax.SAXException)1