use of org.jboss.as.service.descriptor.JBossServiceAttributeConfig in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method addAttributes.
private void addAttributes(final JBossServiceAttributeConfig[] attributeConfigs, final List<ClassReflectionIndex> mBeanClassHierarchy, final MBeanServices mBeanServices, final ClassLoader classLoader) throws DeploymentUnitProcessingException {
if (attributeConfigs != null) {
final Service<Object> createDestroyService = mBeanServices.getCreateDestroyService();
for (final JBossServiceAttributeConfig attributeConfig : attributeConfigs) {
final String propertyName = attributeConfig.getName();
final Inject injectConfig = attributeConfig.getInject();
final ValueFactory valueFactoryConfig = attributeConfig.getValueFactory();
if (injectConfig != null) {
final Value<?> value = getValue(injectConfig);
final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
mBeanServices.addAttribute(injectConfig.getBeanName(), injector);
} else if (valueFactoryConfig != null) {
final Value<?> value = getValue(valueFactoryConfig, classLoader);
final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, value);
mBeanServices.addAttribute(valueFactoryConfig.getBeanName(), injector);
} else {
final Value<?> value = getValue(attributeConfig, mBeanClassHierarchy);
final Injector<Object> injector = getPropertyInjector(propertyName, mBeanClassHierarchy, createDestroyService, Values.injectedValue());
mBeanServices.addInjectionValue(injector, value);
}
}
}
}
use of org.jboss.as.service.descriptor.JBossServiceAttributeConfig in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method addAttributes.
private void addAttributes(final JBossServiceAttributeConfig[] attributeConfigs, final List<ClassReflectionIndex> mBeanClassHierarchy, final MBeanServices mBeanServices, final ClassLoader classLoader, final Object mBeanInstance) throws DeploymentUnitProcessingException {
if (attributeConfigs != null) {
for (final JBossServiceAttributeConfig attributeConfig : attributeConfigs) {
final String propertyName = attributeConfig.getName();
final Inject injectConfig = attributeConfig.getInject();
final ValueFactory valueFactoryConfig = attributeConfig.getValueFactory();
final Method setter = ReflectionUtils.getSetter(mBeanClassHierarchy, propertyName);
if (injectConfig != null) {
final DelegatingSupplier propertySupplier = getObjectSupplier(injectConfig);
mBeanServices.addAttribute(injectConfig.getBeanName(), setter, propertySupplier);
} else if (valueFactoryConfig != null) {
final DelegatingSupplier valueFactorySupplier = getObjectSupplier(valueFactoryConfig, classLoader);
mBeanServices.addAttribute(valueFactoryConfig.getBeanName(), setter, valueFactorySupplier);
} else {
final Supplier<Object> value = getObjectSupplier(attributeConfig, mBeanClassHierarchy);
mBeanServices.addValue(setter, value);
}
}
}
}
use of org.jboss.as.service.descriptor.JBossServiceAttributeConfig in project wildfly by wildfly.
the class ParsedServiceDeploymentProcessor method addServices.
private void addServices(final ServiceTarget target, final JBossServiceConfig mBeanConfig, final ClassLoader classLoader, final DeploymentReflectionIndex index, ServiceComponentInstantiator componentInstantiator, final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final String mBeanClassName = mBeanConfig.getCode();
final List<ClassReflectionIndex> mBeanClassHierarchy = getClassHierarchy(mBeanClassName, index, classLoader);
final Object mBeanInstance = newInstance(mBeanConfig, mBeanClassHierarchy, classLoader);
final String mBeanName = mBeanConfig.getName();
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final MBeanServices mBeanServices = new MBeanServices(mBeanName, mBeanInstance, mBeanClassHierarchy, target, componentInstantiator, deploymentUnit.getAttachmentList(org.jboss.as.ee.component.Attachments.WEB_SETUP_ACTIONS), classLoader, mbeanServerServiceName);
final JBossServiceDependencyConfig[] dependencyConfigs = mBeanConfig.getDependencyConfigs();
addDependencies(dependencyConfigs, mBeanClassHierarchy, mBeanServices, mBeanInstance);
final JBossServiceDependencyListConfig[] dependencyListConfigs = mBeanConfig.getDependencyConfigLists();
addDependencyLists(dependencyListConfigs, mBeanClassHierarchy, mBeanServices, mBeanInstance);
final JBossServiceAttributeConfig[] attributeConfigs = mBeanConfig.getAttributeConfigs();
addAttributes(attributeConfigs, mBeanClassHierarchy, mBeanServices, classLoader, mBeanInstance);
// register all mBean related services
mBeanServices.install();
}
use of org.jboss.as.service.descriptor.JBossServiceAttributeConfig 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());
}
}
}
Aggregations