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.deegree.services.wfs.query.QueryAnalyzer.java

/**
 * Repairs a {@link ValueReference} that contains the local name of a {@link FeatureType}'s property or a prefixed
 * name, but without a correct namespace binding.
 * <p>//from ww w . j  a  va2s  .  com
 * This types of propertynames especially occurs in WFS 1.0.0 requests.
 * </p>
 * 
 * @param propName
 *            property name to be repaired, must be "simple", i.e. contain only of a QName
 * @param typeName
 *            feature type specification from the query, must not be <code>null</code>
 * @throws OWSException
 *             if no match could be found
 */
private void repairSimpleUnqualified(ValueReference propName, TypeName typeName) throws OWSException {

    FeatureType ft = service.lookupFeatureType(typeName.getFeatureTypeName());

    List<QName> propNames = new ArrayList<QName>();
    // TODO which GML version
    for (PropertyType pt : ft.getPropertyDeclarations()) {
        propNames.add(pt.getName());
    }

    QName match = QNameUtils.findBestMatch(propName.getAsQName(), propNames);
    if (match == null) {
        String msg = "Specified PropertyName '" + propName.getAsText() + "' does not exist for feature type '"
                + ft.getName() + "'.";
        throw new OWSException(msg, INVALID_PARAMETER_VALUE, "PropertyName");
    }
    if (!match.equals(propName.getAsQName())) {
        LOG.debug("Repairing unqualified PropertyName: " + QNameUtils.toString(propName.getAsQName()) + " -> "
                + QNameUtils.toString(match));
        // vague match
        String text = match.getLocalPart();
        if (!match.getPrefix().equals(DEFAULT_NS_PREFIX)) {
            text = match.getPrefix() + ":" + match.getLocalPart();
        }
        NamespaceBindings nsContext = new NamespaceBindings();
        nsContext.addNamespace(match.getPrefix(), match.getNamespaceURI());
        propName.set(text, nsContext);
    }
}

From source file:org.deegree.services.wfs.WebFeatureService.java

private Collection<FeatureType> getAllFeatureTypes() {
    Comparator<FeatureType> comp = new Comparator<FeatureType>() {
        @Override/*from   w ww . j  ava2 s. c o  m*/
        public int compare(FeatureType ftMd1, FeatureType ftMd2) {
            QName a = ftMd1.getName();
            QName b = ftMd2.getName();
            int order = a.getNamespaceURI().compareTo(b.getNamespaceURI());
            if (order == 0) {
                order = a.getLocalPart().compareTo(b.getLocalPart());
            }
            return order;
        }
    };
    Collection<FeatureType> sortedFts = new TreeSet<FeatureType>(comp);
    for (FeatureType ft : service.getFeatureTypes()) {
        FeatureStore fs = service.getStore(ft.getName());
        if (fs.isMapped(ft.getName())) {
            sortedFts.add(ft);
        }
    }
    return sortedFts;
}

From source file:org.deegree.services.wps.provider.sextante.SextanteProcesslet.java

/**
 * This method determines all namespaces of a {@link Feature}. If the {@link Feature} is a {@link FeatureCollection}
 * , the first {@link Feature} of the {@link FeatureCollection} is used to determine the namespaces.
 * /*from w  w  w .  j  a  va  2s .  c om*/
 * @param f
 *            {@link Feature}.
 * 
 * @return {@link HashMap} of namespaces. The key is the prefix and the value the namespace URI.
 */
static HashMap<String, String> determinePropertyNamespaces(Feature f) {

    Feature propertyTypeFeature = f;

    if (f instanceof FeatureCollection) {
        FeatureCollection fc = (FeatureCollection) f;
        Iterator<Feature> it = fc.iterator();
        if (it.hasNext()) {
            propertyTypeFeature = it.next();
        }
    }

    HashMap<String, String> namespaces = new HashMap<String, String>();

    List<Property> props = propertyTypeFeature.getProperties();
    for (int i = 0; i < props.size(); i++) {
        QName name = props.get(i).getName();
        namespaces.put(name.getNamespaceURI(), name.getPrefix());
    }

    return namespaces;
}

From source file:org.deegree.tools.feature.gml.SchemaAnalyzer.java

public String toString(QName elementName) {
    XSElementDeclaration elementDecl = schema.getElementDeclaration(elementName.getNamespaceURI(),
            elementName.getLocalPart());
    return toString(elementDecl);
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPTypeLibUtil.java

/**
 * Removes the type from the model. Remember this is an IO operation. This
 * just modifies the WTP EMF model. Returns true if the type was found in
 * the definition and was successfully removed, Otherwise returns false.
 * Editor will be dirty after successful execution of this operation.
 *
 * @param definition the definition/*from w  w w.  j  av a2  s. co m*/
 * @param qname the qname
 * @return true, if successful
 */
public static boolean removeType(Definition definition, QName qname) {
    if (hasSchema(definition, qname.getNamespaceURI())) {
        XSDTypeDefinition xsdTypeDefinition = getType(definition, qname);
        if (xsdTypeDefinition != null) {
            return xsdTypeDefinition.getSchema().getContents().remove(xsdTypeDefinition);
        }
    }
    return false;
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPTypeLibUtil.java

private static XSDTypeDefinition getType(Definition definition, QName qname) {
    XSDTypeDefinition typeDefinition = null;
    for (XSDSchema schema : getXSDSchema(definition, qname.getNamespaceURI())) {
        typeDefinition = getXSDTypeDefinition(schema, qname);
        break;/* www .ja v a 2 s .  c om*/
    }
    return typeDefinition;
}

From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPTypeLibUtil.java

private static XSDTypeDefinition getXSDTypeDefinition(XSDSchema schema, QName typeQName) {

    for (Object objTypeDefinition : schema.getTypeDefinitions()) {
        if (objTypeDefinition instanceof XSDTypeDefinition) {
            XSDTypeDefinition typeDefinition = (XSDTypeDefinition) objTypeDefinition;
            if (StringUtils.equals(typeQName.getLocalPart(), typeDefinition.getName())
                    && StringUtils.equals(typeQName.getNamespaceURI(), typeDefinition.getTargetNamespace())) {
                return typeDefinition;
            }/* w ww.j a v  a2  s  . com*/
        }

    }
    return null;
}

From source file:org.eclipse.swordfish.internal.core.interceptor.CxfDecoratingInterceptor.java

private void unwrapEnvelope(Message outMessage, Exchange messageExchange)
        throws ParserConfigurationException, IOException, SAXException, TransformerException {
    if (!messageExchange.getProperties().containsKey(PROCESSED_BY_CXF_DECORATING_INTERCEPTOR)
            || !((Boolean) messageExchange.getProperties().get(PROCESSED_BY_CXF_DECORATING_INTERCEPTOR))) {
        return;/*from   w ww.ja  v a2 s .  c  om*/
    }
    String message = XmlUtil.toStringFromSource(outMessage.getBody(Source.class));
    if (message.contains(":Body")) {
        int index = message.indexOf(">") + 1;
        String xmlPrefix = message.substring(0, index);
        if (envelopeIsEmpty(message)) {
            Document document = DomUtil.createDocument();
            QName operation = messageExchange.getOperation();
            DomUtil.createElement(document, new QName(operation.getNamespaceURI(),
                    operation.getLocalPart() + "Response", operation.getPrefix()));
            outMessage.setBody(new DOMSource(document));
            return;
        }
        String cutMessage = message.substring(index);
        int startIndex = cutMessage.indexOf(":Body");
        startIndex = cutMessage.indexOf(">", startIndex) + 1;
        int endIndex = cutMessage.indexOf(":Body", startIndex);// end   of body
        endIndex = cutMessage.substring(0, endIndex).lastIndexOf("</");
        String bodyMessage = cutMessage.substring(startIndex, endIndex);
        bodyMessage = xmlPrefix + bodyMessage;
        outMessage.setBody(new SourceTransformer().toDOMSource(new StringSource(bodyMessage)));
    }
}

From source file:org.eclipse.swordfish.internal.core.util.smx.ServiceMixSupport.java

public static DocumentFragment getEndpointReference(EndpointDescription description) {
    try {/*from   w  w  w . j  a v  a 2s .c  om*/
        Assert.notNull(description);

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        Document doc = factory.newDocumentBuilder().newDocument();
        Element endpRef = doc.createElementNS(JbiConstants.WSA_NS, "EndpointReference");
        endpRef.setPrefix(JbiConstants.WSA_PREFIX);
        Element address = doc.createElementNS(JbiConstants.WSA_NS, "Address");
        address.setPrefix(JbiConstants.WSA_PREFIX);
        address.appendChild(doc.createTextNode(description.getAddress()));
        endpRef.appendChild(address);

        QName serviceName = description.getServiceName();
        Element metadata = doc.createElementNS(JbiConstants.WSA_NS, "Metadata");
        metadata.setPrefix(JbiConstants.WSA_PREFIX);
        Element service = doc.createElementNS(JbiConstants.WSA_NS, "ServiceName");
        service.setAttribute("EndpointName", description.getName());
        service.setPrefix(JbiConstants.WSAW_PREFIX);
        service.appendChild(
                doc.createTextNode(serviceName.getNamespaceURI() + "/" + serviceName.getLocalPart()));
        metadata.appendChild(service);
        endpRef.appendChild(metadata);

        doc.appendChild(endpRef);
        DocumentFragment frag = doc.createDocumentFragment();
        frag.appendChild(doc.getDocumentElement());
        return frag;
    } catch (Exception e) {
        throw new RuntimeException("Unexpected failure of enpoint reference creation", e);
    }
}

From source file:org.eclipse.swordfish.internal.resolver.backend.remote.SwordfishRegistryProvider.java

public List<ServiceDescription<?>> getServiceProviderDescriptions(QName interfaceName) {
    List<ServiceDescription<?>> descriptions = new ArrayList<ServiceDescription<?>>();

    try {/* w ww  .j  a  v a 2  s. c om*/
        checkProperties();

        URL descripionBaseUrl = getResourceUrl(getRegistryURL().toString(), DESCRIPTION_CONTEXT);

        Map<String, String> properties = new HashMap<String, String>();
        properties.put("type", "portType");
        properties.put("targetNamespace", interfaceName.getNamespaceURI());
        properties.put("name", interfaceName.getLocalPart());

        ClientRequest request = RegistryProxyFactory.getInstance().createRequest();
        request.setURI(descripionBaseUrl.toURI());
        request.setProperties(properties);
        request.setEntityType(WSDLList.class);

        ClientResponse response = getProxy().get(request);
        if (!response.getStatus().equals(Status.SUCCESS)) {
            handleFailure(response);
        }

        WSDLList descriptionUrls = WSDLList.class.cast(response.getEntity());
        for (String url : descriptionUrls.getUrl()) {
            URL nextDescriptionUrl = getResourceUrl(descripionBaseUrl.toString(), url);
            ServiceDescription<?> description = getWsdlReader().readDescription(nextDescriptionUrl);
            descriptions.add(description);

            if (LOG.isDebugEnabled()) {
                LOG.debug("Successfully retrieved service description: " + description.getServiceName()
                        + " for portType: " + interfaceName);
            }
        }
    } catch (SwordfishException se) {
        throw se;
    } catch (Exception e) {
        LOG.error("Error resolving endpoint - couldn't retrieve " + "service description for port type "
                + interfaceName, e);
        throw new SwordfishException("Error resolving endpoint - couldn't retrieve "
                + "service description for port type " + interfaceName, e);
    }
    return descriptions;
}