use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptor in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method deploy.
/**
* Process a deployment for JbossService configuration. Will install a {@code JBossService} for each configured service.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
if (serviceXmlDescriptor == null) {
// Skip deployments without a service xml descriptor
return;
}
// assert module
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
if (module == null)
throw SarLogger.ROOT_LOGGER.failedToGetAttachment("module", deploymentUnit);
// assert reflection index
final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
if (reflectionIndex == null)
throw SarLogger.ROOT_LOGGER.failedToGetAttachment("reflection index", deploymentUnit);
// install services
final ClassLoader classLoader = module.getClassLoader();
final List<JBossServiceConfig> serviceConfigs = serviceXmlDescriptor.getServiceConfigs();
final ServiceTarget target = phaseContext.getServiceTarget();
final Map<String, ServiceComponentInstantiator> serviceComponents = deploymentUnit.getAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS);
for (final JBossServiceConfig serviceConfig : serviceConfigs) {
addServices(target, serviceConfig, classLoader, reflectionIndex, serviceComponents != null ? serviceComponents.get(serviceConfig.getName()) : null, phaseContext);
}
}
use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptor in project wildfly by wildfly.
the class SarModuleDependencyProcessor method deploy.
/**
* Add dependencies for modules required for manged bean deployments, if managed bean configurations are attached
* to the deployment.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
if (serviceXmlDescriptor == null) {
// Skip deployments with out a service xml descriptor
return;
}
moduleSpecification.addSystemDependency(new ModuleDependency(Module.getBootModuleLoader(), JBOSS_MODULES_ID, false, false, false, false));
moduleSpecification.addSystemDependency(new ModuleDependency(Module.getBootModuleLoader(), JBOSS_AS_SYSTEM_JMX_ID, true, false, false, false));
// depend on Properties editor module which uses ServiceLoader approach to load the appropriate org.jboss.common.beans.property.finder.PropertyEditorFinder
moduleSpecification.addSystemDependency(new ModuleDependency(Module.getBootModuleLoader(), PROPERTIES_EDITOR_MODULE_ID, false, false, true, false));
// All SARs require the ability to register MBeans.
moduleSpecification.addPermissionFactory(REGISTER_PERMISSION_FACTORY);
}
use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptor 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);
}
}
use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptor in project wildfly by wildfly.
the class JBossServiceXmlDescriptorParserTestCase method testParse.
@Test
public void testParse() throws Exception {
final File testXmlFile = getResourceFile(JBossServiceXmlDescriptorParserTestCase.class, "/test/serviceXmlDeployment.jar/META-INF/jboss-service.xml");
final ParseResult<JBossServiceXmlDescriptor> jBossServiceXmlDescriptorParseResult = new ParseResult<JBossServiceXmlDescriptor>();
InputStream inputStream = null;
try {
inputStream = new FileInputStream(testXmlFile);
final XMLStreamReader reader = inputFactory.createXMLStreamReader(inputStream);
xmlMapper.parseDocument(jBossServiceXmlDescriptorParseResult, reader);
} finally {
if (inputStream != null)
inputStream.close();
}
final JBossServiceXmlDescriptor xmlDescriptor = jBossServiceXmlDescriptorParseResult.getResult();
assertNotNull(xmlDescriptor);
final List<JBossServiceConfig> serviceConfigs = xmlDescriptor.getServiceConfigs();
assertEquals(3, serviceConfigs.size());
for (JBossServiceConfig jBossServiceConfig : serviceConfigs) {
assertEquals("org.jboss.as.service.LegacyService", jBossServiceConfig.getCode());
if (jBossServiceConfig.getName().equals("jboss.test.service")) {
final JBossServiceConstructorConfig constructorConfig = jBossServiceConfig.getConstructorConfig();
assertNotNull(constructorConfig);
final JBossServiceConstructorConfig.Argument[] arguments = constructorConfig.getArguments();
assertEquals(1, arguments.length);
assertEquals(String.class.getName(), arguments[0].getType());
assertEquals("Test Value", arguments[0].getValue());
} else if (jBossServiceConfig.getName().equals("jboss.test.service.second")) {
assertNull(jBossServiceConfig.getConstructorConfig());
final JBossServiceDependencyConfig[] dependencyConfigs = jBossServiceConfig.getDependencyConfigs();
assertEquals(1, dependencyConfigs.length);
assertEquals("jboss.test.service", dependencyConfigs[0].getDependencyName());
assertEquals("other", dependencyConfigs[0].getOptionalAttributeName());
final JBossServiceAttributeConfig[] attributeConfigs = jBossServiceConfig.getAttributeConfigs();
assertEquals(1, attributeConfigs.length);
assertEquals("somethingElse", attributeConfigs[0].getName());
assertNull(attributeConfigs[0].getInject());
final JBossServiceAttributeConfig.ValueFactory valueFactory = attributeConfigs[0].getValueFactory();
assertNotNull(valueFactory);
assertEquals("jboss.test.service", valueFactory.getBeanName());
assertEquals("appendSomethingElse", valueFactory.getMethodName());
final JBossServiceAttributeConfig.ValueFactoryParameter[] parameters = valueFactory.getParameters();
assertEquals(1, parameters.length);
assertEquals("java.lang.String", parameters[0].getType());
assertEquals("more value", parameters[0].getValue());
} else if (jBossServiceConfig.getName().equals("jboss.test.service.third")) {
assertNull(jBossServiceConfig.getConstructorConfig());
final JBossServiceAttributeConfig[] attributeConfigs = jBossServiceConfig.getAttributeConfigs();
assertEquals(2, attributeConfigs.length);
assertEquals("other", attributeConfigs[0].getName());
assertNull(attributeConfigs[0].getValueFactory());
final JBossServiceAttributeConfig.Inject inject = attributeConfigs[0].getInject();
assertNotNull(inject);
assertEquals("jboss.test.service.second", inject.getBeanName());
assertEquals("other", inject.getPropertyName());
assertEquals("somethingElse", attributeConfigs[1].getName());
assertNull(attributeConfigs[1].getValueFactory());
assertNull(attributeConfigs[1].getInject());
assertEquals("Another test value", attributeConfigs[1].getValue());
}
}
}
use of org.jboss.as.service.descriptor.JBossServiceXmlDescriptor in project wildfly by wildfly.
the class ServiceComponentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final JBossServiceXmlDescriptor serviceXmlDescriptor = deploymentUnit.getAttachment(JBossServiceXmlDescriptor.ATTACHMENT_KEY);
if (serviceXmlDescriptor == null) {
// Skip deployments without a service xml descriptor
return;
}
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
// not an EE deployment
return;
}
final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final Map<String, ServiceComponentInstantiator> serviceComponents = new HashMap<String, ServiceComponentInstantiator>();
for (final JBossServiceConfig serviceConfig : serviceXmlDescriptor.getServiceConfigs()) {
ServiceComponentDescription componentDescription = new ServiceComponentDescription(serviceConfig.getName(), serviceConfig.getCode(), moduleDescription, deploymentUnit.getServiceName(), applicationClassesDescription);
moduleDescription.addComponent(componentDescription);
serviceComponents.put(serviceConfig.getName(), new ServiceComponentInstantiator(deploymentUnit, componentDescription));
}
deploymentUnit.putAttachment(ServiceAttachments.SERVICE_COMPONENT_INSTANTIATORS, serviceComponents);
}
Aggregations