@Test void linkInvalidPolicy() { Service service = new Service(); service.setPolicy("policy"); assertThrows(WriteException.class, () -> linker.link(service, null, null)); }
@Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } }
ServiceLinker implements EntityLinker<Service> { @Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } } }
ServiceLinker implements EntityLinker<Service> { @Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } } @Inject  ServiceLinker(DocumentTools documentTools, PolicyXMLSimplifier policyXMLSimplifier); }
ServiceLinker implements EntityLinker<Service> { @Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } } @Inject  ServiceLinker(DocumentTools documentTools, PolicyXMLSimplifier policyXMLSimplifier); @Override Class<Service> getEntityClass(); @Override void link(Service service, Bundle bundle, Bundle targetBundle); }
ServiceLinker implements EntityLinker<Service> { @Override public void link(Service service, Bundle bundle, Bundle targetBundle) { try { Element policyElement = DocumentUtils.stringToXML(documentTools, service.getPolicy()); policyXMLSimplifier.simplifyPolicyXML(policyElement, service.getName(), bundle, targetBundle); service.setPolicyXML(policyElement); } catch (DocumentParseException e) { throw new WriteException("Exception linking and simplifying service: " + service.getName() + " Message: " + e.getMessage(), e); } service.setPath(getServicePath(bundle, service)); Element servicePropertiesElement = getSingleChildElement(service.getServiceDetailsElement(), PROPERTIES); NodeList propertyNodes = servicePropertiesElement.getElementsByTagName(PROPERTY); for (int i = 0; i < propertyNodes.getLength(); i++) { if (propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().startsWith("property.ENV.")) { ServiceEnvironmentProperty serviceEnvironmentProperty = new ServiceEnvironmentProperty( service.getName() + "." + propertyNodes.item(i).getAttributes().getNamedItem("key").getTextContent().substring(13), getSingleChildElement((Element) propertyNodes.item(i), STRING_VALUE).getTextContent()); targetBundle.getEntities(ServiceEnvironmentProperty.class).put(serviceEnvironmentProperty.getName(), serviceEnvironmentProperty); } } } @Inject  ServiceLinker(DocumentTools documentTools, PolicyXMLSimplifier policyXMLSimplifier); @Override Class<Service> getEntityClass(); @Override void link(Service service, Bundle bundle, Bundle targetBundle);  }