List<ExportedService> result = new ArrayList<ExportedService>();
Set<String> names = cdr.getComponentDefinitionNames();
for (String name: names) {
ComponentMetadata compMetadata = cdr.getComponentDefinition(name);
if (compMetadata instanceof ServiceMetadata) {
ServiceMetadata serviceMetadata = (ServiceMetadata)compMetadata;
String serviceName;
int ranking;
Collection<String> interfaces = new ArrayList<String>();
Map<String, Object> serviceProps = new HashMap<String, Object>();
ranking = serviceMetadata.getRanking();
for (Object i : serviceMetadata.getInterfaces()) {
interfaces.add((String)i);
}
// get the service properties
List<MapEntry> props = serviceMetadata.getServiceProperties();
for (MapEntry entry : props) {
String key = ((ValueMetadata)entry.getKey()).getStringValue();
Metadata value = entry.getValue();
if (value instanceof CollectionMetadata) {
List<Metadata> values = ((CollectionMetadata)value).getValues();
String[] theseValues = new String[values.size()];
for (int i=0; i < values.size(); i++) {
Metadata m = values.get(i);
theseValues[i] = ((ValueMetadata)m).getStringValue();
}
serviceProps.put(key, theseValues);
} else {
serviceProps.put(key, ((ValueMetadata)entry.getValue()).getStringValue());
}
}
// serviceName: use the service id unless that's not set,
// in which case we use the bean id.
serviceName = serviceMetadata.getId();
// If the Service references a Bean, export the bean id as a service property
// as per 121.6.5 p669 of the blueprint 1.0 specification
Target t = serviceMetadata.getServiceComponent();
String targetId = null;
if (t instanceof RefMetadata) {
targetId = ((RefMetadata)t).getComponentId();
} else if (t instanceof BeanMetadata) {
targetId = ((BeanMetadata)t).getId();