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:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

public <C extends Containerable> PrismContainerDefinition<C> findContainerDefinitionByType(QName typeName) {
    if (StringUtils.isEmpty(typeName.getNamespaceURI())) {
        // Maybe not optimal but sufficient way: we resolve complex type definition, and from it we get qualified type name.
        // This is then used to find container definition in the traditional way.
        ComplexTypeDefinition complexTypeDefinition = resolveGlobalTypeDefinitionWithoutNamespace(
                typeName.getLocalPart());
        if (complexTypeDefinition == null) {
            return null;
        }/* w w  w  .  j  a  v  a  2 s  .c  o m*/
        typeName = complexTypeDefinition.getTypeName();
    }
    PrismSchema schema = findSchemaByNamespace(typeName.getNamespaceURI());
    if (schema == null) {
        return null;
    }
    return schema.findContainerDefinitionByType(typeName);
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

public <T extends Objectable> PrismObjectDefinition<T> findObjectDefinitionByType(QName typeName) {
    if (StringUtils.isEmpty(typeName.getNamespaceURI())) {
        // a quick hack (todo do it seriously)
        ComplexTypeDefinition ctd = resolveGlobalTypeDefinitionWithoutNamespace(typeName.getLocalPart());
        if (ctd == null) {
            return null;
        }//  w w  w  .  j a v  a2  s . c  o  m
        typeName = ctd.getTypeName();
    }
    PrismSchema schema = findSchemaByNamespace(typeName.getNamespaceURI());
    if (schema == null) {
        //TODO: check for confilicted objects
        //         Iterator<PrismSchema> schemaIterator = getSchemas().iterator();
        //         while (schemaIterator.hasNext()){
        //            schema = schemaIterator.next();
        //            if (schema == null){
        //               continue;
        //            }
        //            PrismObjectDefinition<T> def = schema.findObjectDefinitionByTypeAssumeNs(typeName);
        //            if (def != null){
        //               return def;
        //            }
        //            
        //         }
        return null;
    }
    return schema.findObjectDefinitionByType(typeName);
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

/**
 * Looks for a top-level definition for the specified element name (in all schemas). 
 *///from  w  ww . j a  v  a2  s  .  c  o  m
public ItemDefinition resolveGlobalItemDefinition(QName elementQName) throws SchemaException {
    String elementNamespace = elementQName.getNamespaceURI();
    if (StringUtils.isEmpty(elementNamespace)) {
        return resolveGlobalItemDefinitionWithoutNamespace(elementQName.getLocalPart(), ItemDefinition.class);
    }
    PrismSchema schema = findSchemaByNamespace(elementNamespace);
    if (schema == null) {
        return null;
    }
    ItemDefinition itemDefinition = schema.findItemDefinition(elementQName, ItemDefinition.class);
    return itemDefinition;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

private QName resolveElementNameIfNeeded(QName elementName, boolean exceptionIfAmbiguous) {
    if (StringUtils.isNotEmpty(elementName.getNamespaceURI())) {
        return elementName;
    }/* w  w  w. ja  v a2s.c  om*/
    ItemDefinition itemDef = resolveGlobalItemDefinitionWithoutNamespace(elementName.getLocalPart(),
            ItemDefinition.class, exceptionIfAmbiguous);
    if (itemDef != null) {
        return itemDef.getName();
    } else {
        return null;
    }
}

From source file:microsoft.exchange.webservices.data.core.EwsXmlReader.java

/**
 * Determines whether current element is a end element.
 *
 * @param xmlNamespace the xml namespace
 * @param localName    the local name/*from   ww  w  . jav a2s .  com*/
 * @return boolean
 */
public boolean isEndElement(XmlNamespace xmlNamespace, String localName) {

    boolean isEndElement = false;
    /*
     * if(localName.equals("Body")) { return true; } else
     */
    if (this.presentEvent.isEndElement()) {
        EndElement endElement = this.presentEvent.asEndElement();
        QName qName = endElement.getName();
        isEndElement = qName.getLocalPart().equals(localName)
                && (qName.getPrefix().equals(EwsUtilities.getNamespacePrefix(xmlNamespace))
                        || qName.getNamespaceURI().equals(EwsUtilities.getNamespaceUri(xmlNamespace)));

    }
    return isEndElement;
}

From source file:org.bedework.util.dav.DavUtil.java

/**
 * @param cl the client/* ww w .  j a v  a 2 s .co m*/
 * @param path to resource
 * @param props   null for a default set
 * @param depthHeader to set depth of operation
 * @return List<Element> from multi-status response
 * @throws Throwable
 */
public List<Element> propfind(final BasicHttpClient cl, final String path, final Collection<QName> props,
        final Header depthHeader) throws Throwable {
    final StringWriter sw = new StringWriter();
    final XmlEmit xml = getXml();

    addNs(xml, WebdavTags.namespace);

    xml.startEmit(sw);

    xml.openTag(WebdavTags.propfind);
    xml.openTag(WebdavTags.prop);
    xml.emptyTag(WebdavTags.displayname);
    xml.emptyTag(WebdavTags.resourcetype);

    if (props != null) {
        for (final QName pr : props) {
            if (pr.equals(WebdavTags.displayname)) {
                continue;
            }

            if (pr.equals(WebdavTags.resourcetype)) {
                continue;
            }

            addNs(xml, pr.getNamespaceURI());
            xml.emptyTag(pr);
        }
    }

    xml.closeTag(WebdavTags.prop);
    xml.closeTag(WebdavTags.propfind);

    final byte[] content = sw.toString().getBytes();

    final int res = sendRequest(cl, "PROPFIND", path, depthHeader, "text/xml", // contentType,
            content.length, // contentLen,
            content);

    if (res == HttpServletResponse.SC_NOT_FOUND) {
        return null;
    }

    final int SC_MULTI_STATUS = 207; // not defined for some reason
    if (res != SC_MULTI_STATUS) {
        if (debug()) {
            debug("Got response " + res + " for path " + path);
        }

        //throw new Exception("Got response " + res + " for path " + path);
        return null;
    }

    final Document doc = parseContent(cl.getResponseBodyAsStream());

    final Element root = doc.getDocumentElement();

    /*    <!ELEMENT multistatus (response+, responsedescription?) > */

    expect(root, WebdavTags.multistatus);

    return getChildren(root);
}

From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java

private void addPureXpath(StringBuilder sb) {
    if (!absolute && segments.isEmpty()) {
        // Empty segment list gives a "local node" XPath
        sb.append(".");
        return;/*from   w w  w  . j  ava  2  s .  c  o  m*/
    }

    if (absolute) {
        sb.append("/");
    }

    boolean first = true;

    for (PathHolderSegment seg : segments) {

        if (seg.isIdValueFilter()) {

            sb.append("[");
            sb.append(seg.getValue());
            sb.append("]");

        } else {

            if (!first) {
                sb.append("/");
            } else {
                first = false;
            }

            if (seg.isVariable()) {
                sb.append("$");
            }
            QName qname = seg.getQName();

            if (ObjectReferencePathSegment.QNAME.equals(qname)) {
                sb.append(ObjectReferencePathSegment.SYMBOL);
            } else if (ParentPathSegment.QNAME.equals(qname)) {
                sb.append(ParentPathSegment.SYMBOL);
            } else if (IdentifierPathSegment.QNAME.equals(qname)) {
                sb.append(IdentifierPathSegment.SYMBOL);
            } else if (!StringUtils.isEmpty(qname.getPrefix())) {
                sb.append(qname.getPrefix()).append(':').append(qname.getLocalPart());
            } else {
                if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
                    String prefix = GlobalDynamicNamespacePrefixMapper
                            .getPreferredPrefix(qname.getNamespaceURI());
                    seg.setQNamePrefix(prefix); // hack - we modify the path segment here (only the form, not the meaning), but nevertheless it's ugly
                    sb.append(seg.getQName().getPrefix()).append(':').append(seg.getQName().getLocalPart());
                } else {
                    // no namespace, no prefix
                    sb.append(qname.getLocalPart());
                }
            }
        }
    }
}

From source file:com.evolveum.midpoint.prism.marshaller.XPathHolder.java

private void addPureXpath(StringBuilder sb) {
    if (!absolute && segments.isEmpty()) {
        // Empty segment list gives a "local node" XPath
        sb.append(".");
        return;/* w  ww .  jav a2 s.c  om*/
    }

    if (absolute) {
        sb.append("/");
    }

    boolean first = true;

    for (XPathSegment seg : segments) {

        if (seg.isIdValueFilter()) {

            sb.append("[");
            sb.append(seg.getValue());
            sb.append("]");

        } else {

            if (!first) {
                sb.append("/");
            } else {
                first = false;
            }

            if (seg.isVariable()) {
                sb.append("$");
            }
            QName qname = seg.getQName();

            if (ObjectReferencePathSegment.QNAME.equals(qname)) {
                sb.append(ObjectReferencePathSegment.SYMBOL);
            } else if (ParentPathSegment.QNAME.equals(qname)) {
                sb.append(ParentPathSegment.SYMBOL);
            } else if (IdentifierPathSegment.QNAME.equals(qname)) {
                sb.append(IdentifierPathSegment.SYMBOL);
            } else if (!StringUtils.isEmpty(qname.getPrefix())) {
                sb.append(qname.getPrefix() + ":" + qname.getLocalPart());
            } else {
                if (StringUtils.isNotEmpty(qname.getNamespaceURI())) {
                    String prefix = GlobalDynamicNamespacePrefixMapper
                            .getPreferredPrefix(qname.getNamespaceURI());
                    seg.setQNamePrefix(prefix); // hack - we modify the path segment here (only the form, not the meaning), but nevertheless it's ugly
                    sb.append(seg.getQName().getPrefix() + ":" + seg.getQName().getLocalPart());
                } else {
                    // no namespace, no prefix
                    sb.append(qname.getLocalPart());
                }
            }
        }
    }
}

From source file:org.eclipse.winery.repository.client.WineryRepositoryClient.java

@Override
@SuppressWarnings("unchecked")
public <T extends TEntityType> T getType(QName qname, Class<T> type) {
    T res = null;/*  w  ww . j a v  a 2 s  .com*/
    if (this.entityTypeDataCache.containsKey(type)) {
        Map<QName, TEntityType> map = this.entityTypeDataCache.get(type);
        if (map.containsKey(qname)) {
            res = (T) map.get(qname);
        }
    }

    if (res == null) {
        // not yet seen, try to fetch resource

        for (WebResource wr : this.repositoryResources) {
            String path = Util.getURLpathFragmentForCollection(type);

            TDefinitions definitions = WineryRepositoryClient.getDefinitions(wr, path, qname.getNamespaceURI(),
                    qname.getLocalPart());

            if (definitions == null) {
                // in case of an error, just try the next one
                continue;
            }

            res = (T) definitions.getServiceTemplateOrNodeTypeOrNodeTypeImplementation().get(0);
            this.cache(res, qname);
            break;
        }
    }

    return res;
}

From source file:com.evolveum.midpoint.prism.schema.SchemaRegistry.java

/**
 * Returns true if specified element has a definition that matches specified type
 * in the known schemas.//from   w w  w  .  ja v  a 2s.co m
 */
public boolean hasImplicitTypeDefinition(QName elementName, QName typeName) {
    elementName = resolveElementNameIfNeeded(elementName, false);
    if (elementName == null) {
        return false;
    }
    PrismSchema schema = findSchemaByNamespace(elementName.getNamespaceURI());
    if (schema == null) {
        return false;
    }
    ItemDefinition itemDefinition = schema.findItemDefinition(elementName, ItemDefinition.class);
    if (itemDefinition == null) {
        return false;
    }
    return QNameUtil.match(typeName, itemDefinition.getTypeName());
}