Example usage for javax.xml.namespace QName getNamespaceURI

List of usage examples for javax.xml.namespace QName getNamespaceURI

Introduction

In this page you can find the example usage for javax.xml.namespace QName getNamespaceURI.

Prototype

public String getNamespaceURI() 

Source Link

Document

Get the Namespace URI of this QName.

Usage

From source file:org.eclipse.winery.common.Util.java

/**
 * Encodes the namespace and the localname of the given qname, separated by
 * "/"/* w  w w  .  j  av a  2s  .  com*/
 * 
 * @return <double encoded namespace>"/"<double encoded localname>
 */
public static String DoubleURLencode(QName qname) {
    String ns = Util.DoubleURLencode(qname.getNamespaceURI());
    String localName = Util.DoubleURLencode(qname.getLocalPart());
    return ns + "/" + localName;
}

From source file:org.eclipse.winery.common.Util.java

/**
 * //w ww.ja  va  2 s.c o m
 * @param repositoryUrl the URL to the repository
 * @param element the element directly nested below a definitions element in
 *            XML
 * @param qname the QName of the element
 * @param name (optional) if not null, the name to display as text in the
 *            reference. Default: localName of the QName
 * @return an <code>a</code> HTML element pointing to the given id
 */
public static String qname2href(String repositoryUrl, Class<? extends TExtensibleElements> element, QName qname,
        String name) {
    if (StringUtils.isEmpty(repositoryUrl)) {
        throw new IllegalArgumentException("Repository URL must not be empty.");
    }
    if (element == null) {
        throw new IllegalArgumentException("Element class must not be null.");
    }
    if (qname == null) {
        return "(none)";
    }

    String absoluteURL = repositoryUrl + "/" + Util.getURLpathFragmentForCollection(element) + "/"
            + Util.DoubleURLencode(qname.getNamespaceURI()) + "/" + Util.DoubleURLencode(qname.getLocalPart());

    if (name == null) {
        // fallback if no name is given
        name = qname.getLocalPart();
    }
    // sanitize name
    name = Functions.escapeXml(name);

    String res = "<a target=\"_blank\" data-qname=\"" + qname + "\" href=\"" + absoluteURL + "\">" + name
            + "</a>";
    return res;
}

From source file:org.eclipse.winery.common.Util.java

/**
 * @see {@link org.eclipse.winery.common.Util.makeCSSName(String, String)}
 *///from w ww.j a  v  a  2s . co m
public static String makeCSSName(QName qname) {
    return Util.makeCSSName(qname.getNamespaceURI(), qname.getLocalPart());
}

From source file:org.eclipse.winery.common.Util.java

public static SortedMap<String, SortedSet<String>> convertQNameListToNamespaceToLocalNameList(
        List<QName> list) {
    SortedMap<String, SortedSet<String>> res = new TreeMap<>();
    for (QName qname : list) {
        SortedSet<String> localNameSet = res.get(qname.getNamespaceURI());
        if (localNameSet == null) {
            localNameSet = new TreeSet<>();
            res.put(qname.getNamespaceURI(), localNameSet);
        }/*from   w w w  .  j  a  va2  s  .  c  o  m*/
        localNameSet.add(qname.getLocalPart());
    }
    return res;
}

From source file:org.eclipse.winery.repository.backend.BackendUtils.java

public static <T extends TOSCAComponentId> T getTOSCAcomponentId(Class<T> idClass, String qnameStr) {
    QName qname = QName.valueOf(qnameStr);
    return BackendUtils.getTOSCAcomponentId(idClass, qname.getNamespaceURI(), qname.getLocalPart(), false);
}

From source file:org.eclipse.winery.repository.backend.BackendUtils.java

public static <T extends TOSCAComponentId> T getTOSCAcomponentId(Class<T> idClass, QName qname) {
    // we got two implementation possibilities: one is to directly use the
    // QName constructor,
    // the other is to use a namespace, localname, urlencoded constructor
    // we opt for the latter one, which forces the latter constructor to
    // exist at all ids
    return BackendUtils.getTOSCAcomponentId(idClass, qname.getNamespaceURI(), qname.getLocalPart(), false);
}

From source file:org.eclipse.winery.repository.backend.BackendUtils.java

/**
 * Derives Winery's Properties Definition from an existing properties
 * definition/* w  w  w.j a  va  2  s .com*/
 * 
 * @param ci the entity type to try to modify the WPDs
 * @param errors the list to add errors to
 */
public static void deriveWPD(TEntityType ci, List<String> errors) {
    BackendUtils.logger.trace("deriveWPD");
    PropertiesDefinition propertiesDefinition = ci.getPropertiesDefinition();
    QName element = propertiesDefinition.getElement();
    if (element == null) {
        BackendUtils.logger.debug("only works for an element definition, not for types");
    } else {
        BackendUtils.logger.debug(
                "Looking for the definition of {" + element.getNamespaceURI() + "}" + element.getLocalPart());
        // fetch the XSD defining the element
        XSDImportsResource importsRes = new XSDImportsResource();
        Map<String, RepositoryFileReference> mapFromLocalNameToXSD = importsRes
                .getMapFromLocalNameToXSD(element.getNamespaceURI(), false);
        RepositoryFileReference ref = mapFromLocalNameToXSD.get(element.getLocalPart());
        if (ref == null) {
            String msg = "XSD not found for " + element.getNamespaceURI() + " / " + element.getLocalPart();
            BackendUtils.logger.debug(msg);
            errors.add(msg);
            return;
        }

        XSModel xsModel = BackendUtils.getXSModel(ref);
        XSElementDeclaration elementDeclaration = xsModel.getElementDeclaration(element.getLocalPart(),
                element.getNamespaceURI());
        if (elementDeclaration == null) {
            String msg = "XSD model claimed to contain declaration for {" + element.getNamespaceURI() + "}"
                    + element.getLocalPart() + ", but it did not.";
            BackendUtils.logger.debug(msg);
            errors.add(msg);
            return;
        }

        // go through the XSD definition and
        XSTypeDefinition typeDefinition = elementDeclaration.getTypeDefinition();
        if (typeDefinition instanceof XSComplexTypeDefinition) {
            XSComplexTypeDefinition cTypeDefinition = (XSComplexTypeDefinition) typeDefinition;
            XSParticle particle = cTypeDefinition.getParticle();
            if (particle == null) {
                BackendUtils.logger.debug(
                        "XSD does not follow the requirements put by winery: Complex type does not contain particles");
            } else {
                XSTerm term = particle.getTerm();
                if (term instanceof XSModelGroup) {
                    XSModelGroup modelGroup = (XSModelGroup) term;
                    if (modelGroup.getCompositor() == XSModelGroup.COMPOSITOR_SEQUENCE) {
                        XSObjectList particles = modelGroup.getParticles();
                        int len = particles.getLength();
                        boolean everyThingIsASimpleType = true;
                        PropertyDefinitionKVList list = new PropertyDefinitionKVList();
                        if (len != 0) {
                            for (int i = 0; i < len; i++) {
                                XSParticle innerParticle = (XSParticle) particles.item(i);
                                XSTerm innerTerm = innerParticle.getTerm();
                                if (innerTerm instanceof XSElementDeclaration) {
                                    XSElementDeclaration innerElementDeclaration = (XSElementDeclaration) innerTerm;
                                    String name = innerElementDeclaration.getName();
                                    XSTypeDefinition innerTypeDefinition = innerElementDeclaration
                                            .getTypeDefinition();
                                    if (innerTypeDefinition instanceof XSSimpleType) {
                                        XSSimpleType xsSimpleType = (XSSimpleType) innerTypeDefinition;
                                        String typeNS = xsSimpleType.getNamespace();
                                        String typeName = xsSimpleType.getName();
                                        if (typeNS.equals(XMLConstants.W3C_XML_SCHEMA_NS_URI)) {
                                            PropertyDefinitionKV def = new PropertyDefinitionKV();
                                            def.setKey(name);
                                            // convention at WPD: use "xsd" as prefix for XML Schema Definition
                                            def.setType("xsd:" + typeName);
                                            list.add(def);
                                        } else {
                                            everyThingIsASimpleType = false;
                                            break;
                                        }
                                    } else {
                                        everyThingIsASimpleType = false;
                                        break;
                                    }
                                } else {
                                    everyThingIsASimpleType = false;
                                    break;
                                }
                            }
                        }
                        if (everyThingIsASimpleType) {
                            // everything went allright, we can add a WPD
                            WinerysPropertiesDefinition wpd = new WinerysPropertiesDefinition();
                            wpd.setIsDerivedFromXSD(Boolean.TRUE);
                            wpd.setElementName(element.getLocalPart());
                            wpd.setNamespace(element.getNamespaceURI());
                            wpd.setPropertyDefinitionKVList(list);
                            ModelUtilities.replaceWinerysPropertiesDefinition(ci, wpd);
                            BackendUtils.logger.debug("Successfully generated WPD");
                        } else {
                            BackendUtils.logger.debug(
                                    "XSD does not follow the requirements put by winery: Not all types in the sequence are simple types");
                        }
                    } else {
                        BackendUtils.logger.debug(
                                "XSD does not follow the requirements put by winery: Model group is not a sequence");
                    }
                } else {
                    BackendUtils.logger
                            .debug("XSD does not follow the requirements put by winery: Not a model group");
                }
            }
        } else {
            BackendUtils.logger
                    .debug("XSD does not follow the requirements put by winery: No Complex Type Definition");
        }
    }
}

From source file:org.eclipse.winery.repository.backend.consistencycheck.QNameValidator.java

private void validateQName(QName qname) {
    if (qname != null && StringUtils.isEmpty(qname.getNamespaceURI())) {
        errorLogger.log(String.format("Referenced element \"%s\" is not a full QName", qname));
    }/*  w  w w .ja v a2  s . c  o m*/
}

From source file:org.eclipse.winery.repository.resources.API.APIResource.java

@GET
@Path("getallartifacttemplatesofcontaineddeploymentartifacts")
@Produces(MediaType.APPLICATION_JSON)/* ww  w  . j a  v  a 2s.  c  om*/
public Response getAllArtifactTemplatesOfContainedDeploymentArtifacts(
        @QueryParam("servicetemplate") String serviceTemplateQNameString,
        @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter")
                .build();
    }

    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);

    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!Repository.INSTANCE.exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);

    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils
            .getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils
                    .getArtifactTemplatesOfReferencedDeploymentArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }

    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}

From source file:org.eclipse.winery.repository.resources.API.APIResource.java

/**
 * Implementation similar to getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only
 * difference is "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
 * "getArtifactTemplatesOfReferencedDeploymentArtifacts".
 *//*from ww w  .  j a v a2  s  .c  om*/
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(
        @QueryParam("servicetemplate") String serviceTemplateQNameString,
        @QueryParam("nodetemplateid") String nodeTemplateId) {
    if (StringUtils.isEmpty(serviceTemplateQNameString)) {
        return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter")
                .build();
    }
    QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);

    ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
    if (!Repository.INSTANCE.exists(serviceTemplateId)) {
        return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
    }
    ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);

    Collection<QName> artifactTemplates = new ArrayList<>();
    List<TNodeTemplate> allNestedNodeTemplates = BackendUtils
            .getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
    for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
        if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
            Collection<QName> ats = BackendUtils
                    .getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate);
            artifactTemplates.addAll(ats);
        }
    }

    // convert QName list to select2 data
    Select2DataWithOptGroups res = new Select2DataWithOptGroups();
    for (QName qName : artifactTemplates) {
        res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
    }
    return Response.ok().entity(res.asSortedSet()).build();
}