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);
}
}
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));
}
}
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);
}
}
}
Aggregations