use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.
the class BlueprintContainerImpl method instantiateEagerComponents.
protected void instantiateEagerComponents() {
List<String> components = new ArrayList<String>();
for (String name : componentDefinitionRegistry.getComponentDefinitionNames()) {
ComponentMetadata component = componentDefinitionRegistry.getComponentDefinition(name);
boolean eager = component.getActivation() == ComponentMetadata.ACTIVATION_EAGER;
if (component instanceof BeanMetadata) {
BeanMetadata local = (BeanMetadata) component;
eager &= MetadataUtil.isSingletonScope(local);
}
if (eager) {
components.add(name);
}
}
LOGGER.debug("Instantiating components: {}", components);
try {
repository.createAll(components);
} catch (ComponentDefinitionException e) {
throw e;
} catch (Throwable t) {
throw new ComponentDefinitionException("Unable to instantiate components", t);
}
}
use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.
the class BeanRecipe method runBeanProcPostInit.
private Object runBeanProcPostInit(Object obj) {
String beanName = getName();
BeanMetadata beanData = (BeanMetadata) blueprintContainer.getComponentDefinitionRegistry().getComponentDefinition(beanName);
List<BeanProcessor> processors = blueprintContainer.getProcessors(BeanProcessor.class);
//The start link of the chain, that provides the
//original, unprocessed bean to the head of the chain.
BeanProcessor.BeanCreator initialBeanCreator = new BeanProcessor.BeanCreator() {
public Object getBean() {
Object obj = getInstance();
//getinit, getdestroy, addpartial object don't need calling again.
//however, property injection does.
setProperties(obj);
//as this is the post init chain, new beans need to go thru
//the pre-init chain, and then have init called, before
//being passed along the post-init chain.
obj = runBeanProcPreInit(obj);
runBeanProcInit(getInitMethod(obj), obj);
return obj;
}
};
BeanProcessor.BeanCreator currentCreator = initialBeanCreator;
for (BeanProcessor processor : processors) {
obj = processor.afterInit(obj, getName(), currentCreator, beanData);
currentCreator = new BeanCreatorChain(currentCreator, processor, beanData, beanName, BeanCreatorChain.ChainType.After);
}
return obj;
}
use of org.osgi.service.blueprint.reflect.BeanMetadata in project karaf by apache.
the class NamespaceHandler method parsePropertyPlaceholder.
public ComponentMetadata parsePropertyPlaceholder(Element element, ParserContext context) {
MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
metadata.setProcessor(true);
metadata.setId(getId(context, element));
metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
metadata.setRuntimeClass(EncryptablePropertyPlaceholder.class);
metadata.setInitMethod("init");
String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "ENC(";
metadata.addProperty("placeholderPrefix", createValue(context, prefix));
String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) : ")";
metadata.addProperty("placeholderSuffix", createValue(context, suffix));
String encryptorRef = element.hasAttribute("encryptor-ref") ? element.getAttribute("encryptor-ref") : null;
if (encryptorRef != null) {
metadata.addProperty("encryptor", createRef(context, encryptorRef));
}
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element e = (Element) node;
if (JASYPT_NAMESPACE_1_0.equals(e.getNamespaceURI())) {
String name = e.getLocalName() != null ? e.getLocalName() : e.getNodeName();
if (ENCRYPTOR_ELEMENT.equals(name)) {
if (encryptorRef != null) {
throw new ComponentDefinitionException("Only one of " + ENCRYPTOR_REF_ATTRIBUTE + " attribute or " + ENCRYPTOR_ELEMENT + " element is allowed");
}
BeanMetadata encryptor = context.parseElement(BeanMetadata.class, metadata, e);
metadata.addProperty("encryptor", encryptor);
}
}
}
}
PlaceholdersUtils.validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
return metadata;
}
use of org.osgi.service.blueprint.reflect.BeanMetadata in project opennms by OpenNMS.
the class OnmsVaadinUIFactory method validate.
/**
* Verify that the current UIFactory is set up correctly.
*/
private void validate() {
// Verify that the uiBean is a subclass of UI
final Object instance = m_blueprintContainer.getComponentInstance(m_uiBeanId);
if (!(instance instanceof UI)) {
throw new IllegalStateException("The bean with id " + m_uiBeanId + " must be of type " + com.vaadin.ui.UI.class);
}
// Verify that the scope is prototype and NOT singleton
final ComponentMetadata componentMetadata = Objects.requireNonNull(m_blueprintContainer.getComponentMetadata(m_uiBeanId));
if (!(componentMetadata instanceof BeanMetadata)) {
throw new IllegalStateException("The referenced id is not a bean");
}
if (!BeanMetadata.SCOPE_PROTOTYPE.equals(((BeanMetadata) componentMetadata).getScope())) {
throw new IllegalStateException("The scope of the defined bean with id " + m_uiBeanId + " must be " + BeanMetadata.SCOPE_PROTOTYPE + " but is " + BeanMetadata.SCOPE_SINGLETON);
}
}
use of org.osgi.service.blueprint.reflect.BeanMetadata in project aries by apache.
the class SpringBeanProcessor method getProcessors.
private <T> List<T> getProcessors(Class<T> type) {
List<T> processors = new ArrayList<T>();
if (!creatingProcessor) {
creatingProcessor = true;
for (BeanMetadata bean : blueprintContainer.getMetadata(BeanMetadata.class)) {
Class clazz = null;
if (bean instanceof ExtendedBeanMetadata) {
clazz = ((ExtendedBeanMetadata) bean).getRuntimeClass();
}
if (clazz == null && bean.getClassName() != null) {
try {
clazz = bundleContext.getBundle().loadClass(bean.getClassName());
} catch (ClassNotFoundException e) {
}
}
if (clazz == null) {
continue;
}
if (type.isAssignableFrom(clazz)) {
Object p = blueprintContainer.getComponentInstance(bean.getId());
processors.add(type.cast(p));
}
}
creatingProcessor = false;
}
return processors;
}
Aggregations