use of org.osgi.service.blueprint.reflect.Metadata in project cxf by apache.
the class EndpointDefinitionParser method parse.
public Metadata parse(Element element, ParserContext context) {
// Endpoint definition
MutableBeanMetadata cxfBean = context.createMetadata(MutableBeanMetadata.class);
if (!StringUtils.isEmpty(getIdOrName(element))) {
cxfBean.setId(getIdOrName(element));
} else {
cxfBean.setId("cxf.endpoint." + UUID.randomUUID().toString());
}
cxfBean.setRuntimeClass(EP_CLASS);
boolean isAbstract = false;
boolean publish = true;
NamedNodeMap atts = element.getAttributes();
String bus = null;
Metadata impl = null;
for (int i = 0; i < atts.getLength(); i++) {
Attr node = (Attr) atts.item(i);
String val = node.getValue();
String pre = node.getPrefix();
String name = node.getLocalName();
if ("createdFromAPI".equals(name) || "abstract".equals(name)) {
cxfBean.setScope(BeanMetadata.SCOPE_PROTOTYPE);
isAbstract = true;
} else if ("publish".equals(name)) {
publish = Boolean.parseBoolean(val);
} else if ("bus".equals(name)) {
bus = val;
} else if (isAttribute(pre, name)) {
if ("endpointName".equals(name) || "serviceName".equals(name)) {
QName q = parseQName(element, val);
cxfBean.addProperty(name, createValue(context, q));
} else if ("depends-on".equals(name)) {
cxfBean.addDependsOn(val);
} else if ("implementor".equals(name)) {
if (val.startsWith("#")) {
impl = createRef(context, val.substring(1));
} else {
impl = createObjectOfClass(context, val);
}
} else if (!"name".equals(name)) {
cxfBean.addProperty(name, createValue(context, val));
}
}
}
Element elem = DOMUtils.getFirstElement(element);
while (elem != null) {
String name = elem.getLocalName();
if ("properties".equals(name)) {
Metadata map = parseMapData(context, cxfBean, elem);
cxfBean.addProperty(name, map);
} else if ("binding".equals(name)) {
setFirstChildAsProperty(elem, context, cxfBean, "bindingConfig");
} else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name) || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name) || "features".equals(name) || "schemaLocations".equals(name) || "handlers".equals(name)) {
Metadata list = parseListData(context, cxfBean, elem);
cxfBean.addProperty(name, list);
} else if ("implementor".equals(name)) {
impl = context.parseElement(Metadata.class, cxfBean, elem);
} else {
setFirstChildAsProperty(elem, context, cxfBean, name);
}
elem = DOMUtils.getNextElement(elem);
}
if (StringUtils.isEmpty(bus)) {
bus = "cxf";
}
cxfBean.addArgument(this.getBusRef(context, bus), Bus.class.getName(), 0);
cxfBean.addArgument(impl, Object.class.getName(), 1);
if (!isAbstract) {
if (publish) {
cxfBean.setInitMethod("publish");
}
cxfBean.setDestroyMethod("stop");
}
// We don't want to delay the registration of our Server
cxfBean.setActivation(ComponentMetadata.ACTIVATION_EAGER);
return cxfBean;
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class AbstractParserProxy method traverse.
/**
* Traverse to find all nested {@link ComponentMetadata} instances
* @param metadata
* @param output
*/
private void traverse(Metadata metadata, Set<ComponentMetadata> output) {
if (metadata instanceof ComponentMetadata) {
traverseComponent((ComponentMetadata) metadata, output);
} else if (metadata instanceof CollectionMetadata) {
CollectionMetadata collection = (CollectionMetadata) metadata;
for (Metadata v : collection.getValues()) traverse(v, output);
} else if (metadata instanceof MapMetadata) {
MapMetadata map = (MapMetadata) metadata;
for (MapEntry e : map.getEntries()) {
traverse(e.getKey(), output);
traverse(e.getValue(), output);
}
}
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class AbstractPropertyPlaceholder method processCollectionMetadata.
protected Metadata processCollectionMetadata(CollectionMetadata metadata) {
List<Metadata> values = new ArrayList<Metadata>(metadata.getValues());
if (!!!values.isEmpty()) {
try {
if (metadata instanceof MutableCollectionMetadata) {
processingStack.add("Collection type: " + metadata.getValueType() + "->");
MutableCollectionMetadata mcm = (MutableCollectionMetadata) metadata;
for (Metadata value : values) {
mcm.removeValue(value);
}
for (Metadata value : values) {
mcm.addValue(processMetadata(value));
}
} else {
printWarning(metadata, "Collection type: " + metadata.getValueType());
processingStack.add("Collection type: " + metadata.getValueType() + "->");
for (Metadata value : values) {
processMetadata(value);
}
}
} finally {
processingStack.removeLast();
}
}
return metadata;
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class Parser method parseBeanArgument.
private BeanArgument parseBeanArgument(ComponentMetadata enclosingComponent, Element element) {
int index = element.hasAttribute(INDEX_ATTRIBUTE) ? Integer.parseInt(element.getAttribute(INDEX_ATTRIBUTE)) : -1;
String type = element.hasAttribute(TYPE_ATTRIBUTE) ? element.getAttribute(TYPE_ATTRIBUTE) : null;
Metadata value = parseArgumentOrPropertyValue(element, enclosingComponent);
return new BeanArgumentImpl(value, type, index);
}
use of org.osgi.service.blueprint.reflect.Metadata in project aries by apache.
the class Parser method parseRegistrationListener.
public RegistrationListener parseRegistrationListener(Element element, ComponentMetadata enclosingComponent) {
RegistrationListenerImpl listener = new RegistrationListenerImpl();
Metadata listenerComponent = null;
// Parse attributes
if (element.hasAttribute(REF_ATTRIBUTE)) {
listenerComponent = new RefMetadataImpl(element.getAttribute(REF_ATTRIBUTE));
}
String registrationMethod = null;
if (element.hasAttribute(REGISTRATION_METHOD_ATTRIBUTE)) {
registrationMethod = element.getAttribute(REGISTRATION_METHOD_ATTRIBUTE);
listener.setRegistrationMethod(registrationMethod);
}
String unregistrationMethod = null;
if (element.hasAttribute(UNREGISTRATION_METHOD_ATTRIBUTE)) {
unregistrationMethod = element.getAttribute(UNREGISTRATION_METHOD_ATTRIBUTE);
listener.setUnregistrationMethod(unregistrationMethod);
}
if (registrationMethod == null && unregistrationMethod == null) {
throw new ComponentDefinitionException("One of " + REGISTRATION_METHOD_ATTRIBUTE + " or " + UNREGISTRATION_METHOD_ATTRIBUTE + " must be set");
}
// Parse elements
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 (isBlueprintNamespace(e.getNamespaceURI())) {
if (nodeNameEquals(e, REF_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
String component = e.getAttribute(COMPONENT_ID_ATTRIBUTE);
if (component == null || component.length() == 0) {
throw new ComponentDefinitionException("Element " + REF_ELEMENT + " must have a valid " + COMPONENT_ID_ATTRIBUTE + " attribute");
}
listenerComponent = new RefMetadataImpl(component);
} else if (nodeNameEquals(e, BEAN_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseBeanMetadata(e, false);
} else if (nodeNameEquals(e, REFERENCE_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseReference(e, false);
} else if (nodeNameEquals(e, SERVICE_ELEMENT)) {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseService(e, false);
}
} else {
if (listenerComponent != null) {
throw new ComponentDefinitionException("Only one of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element can be set");
}
listenerComponent = parseCustomElement(e, enclosingComponent);
}
}
}
if (listenerComponent == null) {
throw new ComponentDefinitionException("One of " + REF_ATTRIBUTE + " attribute, " + REF_ELEMENT + ", " + BEAN_ELEMENT + ", " + REFERENCE_ELEMENT + ", " + SERVICE_ELEMENT + " or custom element must be set");
}
listener.setListenerComponent((Target) listenerComponent);
return listener;
}
Aggregations