use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.
the class TxNamespaceHandler method parseElement.
private void parseElement(Element elt, ParserContext pc) {
LOGGER.debug("parser asked to parse element {} ", elt.getNodeName());
ComponentDefinitionRegistry cdr = pc.getComponentDefinitionRegistry();
if ("enable".equals(elt.getLocalName())) {
Node n = elt.getChildNodes().item(0);
if ((n == null || Boolean.parseBoolean(n.getNodeValue())) && !cdr.containsComponentDefinition(ANNOTATION_PARSER_BEAN_NAME)) {
LOGGER.debug("Enabling annotation based transactions");
MutableBeanMetadata meta = createAnnotationParserBean(pc, cdr);
cdr.registerComponentDefinition(meta);
}
}
}
use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.
the class ExtNamespaceHandler method parsePropertyPlaceholder.
private Metadata parsePropertyPlaceholder(ParserContext context, Element element) {
MutableBeanMetadata metadata = context.createMetadata(MutableBeanMetadata.class);
metadata.setProcessor(true);
metadata.setId(getId(context, element));
metadata.setScope(BeanMetadata.SCOPE_SINGLETON);
metadata.setRuntimeClass(PropertyPlaceholder.class);
metadata.setInitMethod("init");
String prefix = element.hasAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_PREFIX_ATTRIBUTE) : "${";
metadata.addProperty("placeholderPrefix", createValue(context, prefix));
String suffix = element.hasAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_SUFFIX_ATTRIBUTE) : "}";
metadata.addProperty("placeholderSuffix", createValue(context, suffix));
metadata.addProperty("blueprintContainer", createRef(context, "blueprintContainer"));
String nullValue = element.hasAttribute(PLACEHOLDER_NULL_VALUE_ATTRIBUTE) ? element.getAttribute(PLACEHOLDER_NULL_VALUE_ATTRIBUTE) : null;
if (nullValue != null) {
metadata.addProperty("nullValue", createValue(context, nullValue));
}
String defaultsRef = element.hasAttribute(DEFAULTS_REF_ATTRIBUTE) ? element.getAttribute(DEFAULTS_REF_ATTRIBUTE) : null;
if (defaultsRef != null) {
metadata.addProperty("defaultProperties", createRef(context, defaultsRef));
}
String ignoreMissingLocations = element.hasAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) ? element.getAttribute(IGNORE_MISSING_LOCATIONS_ATTRIBUTE) : null;
if (ignoreMissingLocations != null) {
metadata.addProperty("ignoreMissingLocations", createValue(context, ignoreMissingLocations));
}
String systemProperties = element.hasAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) ? element.getAttribute(SYSTEM_PROPERTIES_ATTRIBUTE) : null;
if (systemProperties != null) {
metadata.addProperty("systemProperties", createValue(context, systemProperties));
}
String evaluator = element.hasAttribute(EVALUATOR_ATTRIBUTE) ? element.getAttribute(EVALUATOR_ATTRIBUTE) : null;
if (evaluator != null) {
throw new IllegalStateException("Evaluators are not supported outside OSGi");
}
// Parse elements
List<String> locations = new ArrayList<String>();
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 (isExtNamespace(e.getNamespaceURI())) {
if (nodeNameEquals(e, DEFAULT_PROPERTIES_ELEMENT)) {
if (defaultsRef != null) {
throw new ComponentDefinitionException("Only one of " + DEFAULTS_REF_ATTRIBUTE + " attribute or " + DEFAULT_PROPERTIES_ELEMENT + " element is allowed");
}
Metadata props = parseDefaultProperties(context, metadata, e);
metadata.addProperty("defaultProperties", props);
} else if (nodeNameEquals(e, LOCATION_ELEMENT)) {
locations.add(getTextValue(e));
}
}
}
}
if (!locations.isEmpty()) {
metadata.addProperty("locations", createList(context, locations));
}
validatePlaceholder(metadata, context.getComponentDefinitionRegistry());
return metadata;
}
use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.
the class ExtNamespaceHandler method parseBeanArgument.
private ComponentMetadata parseBeanArgument(ParserContext context, Element element) {
MutableBeanMetadata mbm = (MutableBeanMetadata) context.getEnclosingComponent();
BeanArgument arg = context.parseElement(BeanArgument.class, mbm, element);
int index = 0;
for (Node node = element.getPreviousSibling(); node != null; node = node.getPreviousSibling()) {
if (nodeNameEquals(node, ARGUMENT)) {
index++;
}
}
List<BeanArgument> args = new ArrayList<BeanArgument>(mbm.getArguments());
if (index == args.size()) {
mbm.addArgument(arg);
} else {
for (BeanArgument ba : args) {
mbm.removeArgument(ba);
}
args.add(index, arg);
for (BeanArgument ba : args) {
mbm.addArgument(ba);
}
}
return mbm;
}
use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.
the class ExtNamespaceHandler method mergeList.
private void mergeList(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
Metadata m1 = getProperty(bean1, name);
Metadata m2 = getProperty(bean2, name);
if (m1 == null && m2 != null) {
((MutableBeanMetadata) bean1).addProperty(name, m2);
} else if (m1 != null && m2 != null) {
if (!(m1 instanceof MutableCollectionMetadata) || !(m2 instanceof MutableCollectionMetadata)) {
throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
}
MutableCollectionMetadata c1 = (MutableCollectionMetadata) m1;
MutableCollectionMetadata c2 = (MutableCollectionMetadata) m2;
for (Metadata v : c2.getValues()) {
c1.addValue(v);
}
}
}
use of org.apache.aries.blueprint.mutable.MutableBeanMetadata in project aries by apache.
the class ExtNamespaceHandler method mergeMap.
private void mergeMap(ExtendedBeanMetadata bean1, MutableBeanMetadata bean2, String name) {
Metadata m1 = getProperty(bean1, name);
Metadata m2 = getProperty(bean2, name);
if (m1 == null && m2 != null) {
((MutableBeanMetadata) bean1).addProperty(name, m2);
} else if (m1 != null && m2 != null) {
if (!(m1 instanceof MutableMapMetadata) || !(m2 instanceof MutableMapMetadata)) {
throw new ComponentDefinitionException("Unable to merge " + name + " list properties");
}
MutableMapMetadata c1 = (MutableMapMetadata) m1;
MutableMapMetadata c2 = (MutableMapMetadata) m2;
for (MapEntry e : c2.getEntries()) {
c1.addEntry(e);
}
}
}
Aggregations