use of org.apache.aries.application.modelling.WrappedServiceMetadata in project aries by apache.
the class AbstractParserProxy method parseCDRForServices.
/**
* Extract Service metadata from a ComponentDefinitionRegistry. When doing SCA modelling, we
* need to suppress anonymous services. We don't want to do that when we're modelling for
* provisioning dependencies.
* @param cdr ComponentDefinitionRegistry
* @param suppressAnonymousServices Unnamed services will not be returned if this is true
* @return List<WrappedServiceMetadata>
*/
private List<ExportedService> parseCDRForServices(ComponentDefinitionRegistry cdr, boolean suppressAnonymousServices) {
_logger.debug(LOG_ENTRY, "parseCDRForServices", new Object[] { cdr, suppressAnonymousServices });
List<ExportedService> result = new ArrayList<ExportedService>();
for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
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) {
processMultiValueProperty(serviceProps, key, value);
} 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();
}
// or auto-generated for an anonymous service. This must ALWAYS be set.
if (targetId != null && !targetId.startsWith(".")) {
// Don't set this for anonymous inner components
serviceProps.put("osgi.service.blueprint.compname", targetId);
if (serviceName == null || serviceName.equals("") || serviceName.startsWith(".")) {
serviceName = targetId;
}
}
if (serviceName != null && serviceName.startsWith("."))
serviceName = null;
// If suppressAnonymous services, do not expose services that have no name
if (!suppressAnonymousServices || (serviceName != null)) {
ExportedService wsm = _modellingManager.getExportedService(serviceName, ranking, interfaces, serviceProps);
result.add(wsm);
}
}
}
_logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
return result;
}
use of org.apache.aries.application.modelling.WrappedServiceMetadata in project aries by apache.
the class ParserProxyTest method basicTest1.
@Test
public void basicTest1() throws Exception {
File bpXml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml");
File bp2Xml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp2.xml");
List<URL> urls = new ArrayList<URL>();
urls.add((bpXml.toURI()).toURL());
urls.add((bp2Xml.toURI()).toURL());
List<? extends WrappedServiceMetadata> results = _parserProxy.parse(urls);
assertTrue("Four results expected, not " + results.size(), results.size() == 4);
Set<WrappedServiceMetadata> resultSet = new HashSet<WrappedServiceMetadata>(results);
Set<WrappedServiceMetadata> expectedResults = getTest1ExpectedResults();
assertEquals("Blueprint parsed xml is not as expected: " + resultSet.toString() + " != " + expectedResults, resultSet, expectedResults);
}
use of org.apache.aries.application.modelling.WrappedServiceMetadata in project aries by apache.
the class ParserProxyTest method testParseAllServiceElements.
@Test
public void testParseAllServiceElements() throws Exception {
File bpXml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp.xml");
File bp2Xml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bp2.xml");
List<WrappedServiceMetadata> services = new ArrayList<WrappedServiceMetadata>();
List<WrappedReferenceMetadata> references = new ArrayList<WrappedReferenceMetadata>();
FileInputStream fis = new FileInputStream(bpXml);
ParsedServiceElements bpelem = _parserProxy.parseAllServiceElements(fis);
services.addAll(bpelem.getServices());
references.addAll(bpelem.getReferences());
fis = new FileInputStream(bp2Xml);
bpelem = _parserProxy.parseAllServiceElements(fis);
services.addAll(bpelem.getServices());
references.addAll(bpelem.getReferences());
// We expect:
// bp.xml: 3 services and 2 references
// bp2.xml: 3 services and a reference list
//
assertTrue("Six services expected, not " + services.size(), services.size() == 6);
assertTrue("Three references expected, not " + references.size(), references.size() == 3);
Set<WrappedServiceMetadata> expectedServices = getTest2ExpectedServices();
// ServiceResultSet will contain some services with autogenerated names starting '.' so we can't
// use a straight Set.equals(). We could add the autogenerated names to the expected results but instead
// let's test that differsOnlyByName() works
int serviceMatchesFound = 0;
for (WrappedServiceMetadata result : services) {
Iterator<WrappedServiceMetadata> it = expectedServices.iterator();
while (it.hasNext()) {
WrappedServiceMetadata next = it.next();
if (result.equals(next) || result.identicalOrDiffersOnlyByName(next)) {
serviceMatchesFound++;
it.remove();
}
}
}
assertEquals("Parsed services are wrong: " + expectedServices + " unmatched ", 6, serviceMatchesFound);
Set<WrappedReferenceMetadata> expectedReferences = getTest2ExpectedReferences();
Set<WrappedReferenceMetadata> results = new HashSet<WrappedReferenceMetadata>(references);
assertTrue("Parsed references are not as we'd expected: " + results.toString() + " != " + expectedReferences, results.equals(expectedReferences));
}
use of org.apache.aries.application.modelling.WrappedServiceMetadata in project aries by apache.
the class ParserProxyTest method checkMultiValues.
@Test
public void checkMultiValues() throws Exception {
File bpXml = new File(resourceDir, "appModeller/test1.eba/bundle1.jar/OSGI-INF/blueprint/bpMultiValues.xml");
List<WrappedServiceMetadata> services = new ArrayList<WrappedServiceMetadata>();
FileInputStream fis = new FileInputStream(bpXml);
ParsedServiceElements bpelem = _parserProxy.parseAllServiceElements(fis);
services.addAll(bpelem.getServices());
assertEquals("Multi valued service not parsed correctly", services.size(), 1);
WrappedServiceMetadata wsm = services.get(0);
Map<String, Object> props = wsm.getServiceProperties();
String[] intents = (String[]) props.get("service.intents");
assertEquals("Service.intents[0] wrong", intents[0], "propagatesTransaction");
assertEquals("Service.intents[1] wrong", intents[1], "confidentiality");
}
use of org.apache.aries.application.modelling.WrappedServiceMetadata in project aries by apache.
the class ExportedServiceTest method checkEquality.
@Test
public void checkEquality() {
// public ExportedService (String name, int ranking, Collection<String> ifaces,
// Map<String, String> serviceProperties ) {
Map<String, Object> props = new HashMap<String, Object>();
props.put("away", "www.away.com");
props.put("home", "www.home.net");
WrappedServiceMetadata wsm1 = new ExportedServiceImpl(null, 0, Arrays.asList("a.b.c", "d.e.f"), props);
WrappedServiceMetadata wsm2 = new ExportedServiceImpl(null, 0, Arrays.asList("d.e.f", "a.b.c"), props);
assertTrue("Basic equality test", wsm1.equals(wsm2));
assertTrue("Basic equality test", wsm2.equals(wsm1));
assertTrue("Hashcodes equal", wsm1.hashCode() == wsm2.hashCode());
wsm2 = new ExportedServiceImpl(null, 0, Arrays.asList("d.e.f", "a.b.c", "g.e.f"), props);
assertFalse("Adding an interface makes them different", wsm1.equals(wsm2));
assertFalse("Adding an interface makes them different", wsm2.equals(wsm1));
assertFalse("Hashcodes should differ", wsm1.hashCode() == wsm2.hashCode());
props = new HashMap<String, Object>(props);
props.put("interim", "w3.interim.org");
wsm1 = new ExportedServiceImpl(null, 0, Arrays.asList("a.b.c", "d.e.f", "g.e.f"), props);
assertFalse("Adding a service property makes them different", wsm1.equals(wsm2));
assertFalse("Adding a service property makes them different", wsm2.equals(wsm1));
assertFalse("Hashcodes still different", wsm1.hashCode() == wsm2.hashCode());
}
Aggregations