Search in sources :

Example 1 with Properties

use of org.eclipse.winery.model.tosca.TEntityTemplate.Properties in project winery by eclipse.

the class GenericArtifactsResource method storeProperties.

private void storeProperties(ArtifactTemplateId artifactTemplateId, DefinitionsChildId typeId, String name) {
    // We generate the properties by hand instead of using JAX-B as using JAX-B causes issues at org.eclipse.winery.common.ModelUtilities.getPropertiesKV(TEntityTemplate):
    // getAny() does not always return "w3c.dom.element" anymore
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        GenericArtifactsResource.LOGGER.error(e.getMessage(), e);
        return;
    }
    Document doc = builder.newDocument();
    String namespace = QNames.QNAME_ARTIFACT_TYPE_WAR.getNamespaceURI();
    Element root = doc.createElementNS(namespace, "WSProperties");
    doc.appendChild(root);
    Element element = doc.createElementNS(namespace, "ServiceEndpoint");
    Text text = doc.createTextNode("/services/" + name + "Port");
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "PortType");
    text = doc.createTextNode("{" + typeId.getNamespace().getDecoded() + "}" + name);
    element.appendChild(text);
    root.appendChild(element);
    element = doc.createElementNS(namespace, "InvocationType");
    text = doc.createTextNode("SOAP/HTTP");
    element.appendChild(text);
    root.appendChild(element);
    Properties properties = new Properties();
    properties.setAny(root);
    final IRepository repository = RepositoryFactory.getRepository();
    final TArtifactTemplate artifactTemplate = repository.getElement(artifactTemplateId);
    artifactTemplate.setProperties(properties);
    try {
        repository.setElement(artifactTemplateId, artifactTemplate);
    } catch (IOException e) {
        throw new WebApplicationException(e);
    }
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebApplicationException(javax.ws.rs.WebApplicationException) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) Text(org.w3c.dom.Text) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) Document(org.w3c.dom.Document) Properties(org.eclipse.winery.model.tosca.TEntityTemplate.Properties) IRepository(org.eclipse.winery.repository.backend.IRepository)

Aggregations

IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Properties (org.eclipse.winery.model.tosca.TEntityTemplate.Properties)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1 Text (org.w3c.dom.Text)1