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.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

/**
 * Handle the simple type/*w w w.  j a  v a 2 s .  c  o  m*/
 *
 * @param simpleType
 * @param dom4jEl
 */
private void handleSimpleType(XmlSchemaSimpleType simpleType, Element dom4jEl) {

    /* if (content != null) {
    logger.debug(I18nHelper.str("simple.type.has.content"));
            
    if (content instanceof XmlSchemaSimpleTypeRestriction) {
        baseTypeName = ((XmlSchemaSimpleTypeRestriction) content).getBaseTypeName();
        //todo: handle base type which is itself another declared simple type
    }
            
     } else {
    logger.trace(I18nHelper.str("simple.type.has.no.content.must.be.a.base.schema.type"));
    baseTypeName = new QName(Constants.URI_2001_SCHEMA_XSD, simpleType.getName());
     }
    */

    XmlSchemaSimpleTypeContent content = simpleType.getContent();
    QName baseTypeName = null;

    QName name = simpleType.getQName();
    if (name != null && name.getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
        baseTypeName = name;
    } else if (content != null) {
        logger.debug("simple type has content");

        if (content instanceof XmlSchemaSimpleTypeRestriction) {
            baseTypeName = ((XmlSchemaSimpleTypeRestriction) content).getBaseTypeName();
            //todo: handle base type which is itself another declared simple type
        }

    }

    if (options.getDefVals().equals(DefaultValues.DEFAULT)) {
        String val = SampleValueProvider.get(baseTypeName);
        if (StringUtils.isNotEmpty(val)) {
            dom4jEl.setText(val);
            logger.debug("Adding sample value '{}' for simple type base {}", val, baseTypeName);
        } else {
            logger.warn("Could not get sample value for base type name {}", baseTypeName);
        }
    }

}

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

private ComplexTypeDefinition getOrProcessComplexType(QName typeName) throws SchemaException {
    ComplexTypeDefinition complexTypeDefinition = schema.findComplexTypeDefinition(typeName);
    if (complexTypeDefinition != null) {
        return complexTypeDefinition;
    }/*w  w  w .j  a v a  2 s  .  c o  m*/
    // The definition is not yet processed (or does not exist). Let's try to process it.
    XSComplexType complexType = xsSchemaSet.getComplexType(typeName.getNamespaceURI(), typeName.getLocalPart());
    return processComplexTypeDefinition(complexType);
}

From source file:com.evolveum.midpoint.prism.parser.PrismBeanConverter.java

private <T, S> void unmarshallToAny(T bean, Method getter, QName elementName, XNode xsubnode)
        throws SchemaException {
    Class<T> beanClass = (Class<T>) bean.getClass();

    Class objectFactoryClass = inspector.getObjectFactoryClass(elementName.getNamespaceURI());
    Object objectFactory = instantiateObjectFactory(objectFactoryClass);
    Method elementFactoryMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass,
            elementName.getLocalPart());
    Class<S> subBeanClass = (Class<S>) elementFactoryMethod.getParameterTypes()[0];

    if (xsubnode instanceof ListXNode) {
        for (XNode xsubSubNode : ((ListXNode) xsubnode)) {
            S subBean = unmarshall(xsubSubNode, subBeanClass);
            unmarshallToAnyValue(bean, beanClass, subBean, objectFactoryClass, objectFactory,
                    elementFactoryMethod, getter);
        }//w w w.  ja  v  a  2s .co m
    } else {
        S subBean = unmarshall(xsubnode, subBeanClass);
        unmarshallToAnyValue(bean, beanClass, subBean, objectFactoryClass, objectFactory, elementFactoryMethod,
                getter);
    }

}

From source file:com.evolveum.midpoint.web.component.wizard.resource.SchemaHandlingStep.java

private String formatItemInfo(ResourceItemDefinitionType item, ItemPathType ref, String displayName,
        List<MappingType> inbounds, MappingType outbound) {
    StringBuilder sb = new StringBuilder();
    if (ref != null && !ref.getItemPath().isEmpty()) {
        QName name = ItemPathUtil.getOnlySegmentQNameRobust(ref);
        if (name != null) {
            String prefix = SchemaConstants.NS_ICF_SCHEMA.equals(name.getNamespaceURI()) ? "icfs" : "ri";
            sb.append(prefix);// www.j  av a2s  .  com
            sb.append(": ");
            sb.append(name.getLocalPart());
        }
    } else {
        sb.append("-");
    }
    String duplicateInfo = getDuplicateInfo(item);
    if (duplicateInfo != null) {
        sb.append(" (").append(duplicateInfo).append(")");
    }
    if (displayName != null) {
        sb.append(" (").append(displayName).append(")");
    }
    if (!inbounds.isEmpty()) {
        sb.append(" | ");
        sb.append(getString("SchemaHandlingStep.in", ""));
        boolean first = true;
        for (MappingType inbound : inbounds) {
            if (inbound != null && inbound.getTarget() != null) {
                if (first)
                    first = false;
                else
                    sb.append(", ");
                sb.append(formatPath(inbound.getTarget().getPath()));
            }
        }
    }
    if (outbound != null) {
        sb.append(" | ").append(getString("SchemaHandlingStep.out")).append(": ");
        boolean first = true;
        for (VariableBindingDefinitionType source : outbound.getSource()) {
            if (source != null) {
                if (first)
                    first = false;
                else
                    sb.append(", ");
                sb.append(formatPath(source.getPath()));
            }
        }
    }
    return sb.toString();
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

/**
 * Create a Dom4j QName value using the given XMLSchema attribute instance data
 * The attribute's form value is qualified or is a globally-declared attribute
 *
 * @param attribute local attribute with form = qualified / global attribute
 * @return/*from   w w w .  j av  a  2s.c om*/
 */

private org.dom4j.QName getDom4jQNameForAttribute(XmlSchemaAttribute attribute) {
    QName attrQName = attribute.getQName();
    String name = attribute.getName();
    String nsUri = attrQName.getNamespaceURI();

    XmlSchema currentSchema = (!schemaStack.isEmpty() ? schemaStack.peek() : null);

    if (StringUtils.isEmpty(nsUri)) {
        nsUri = (currentSchema != null ? currentSchema.getTargetNamespace() : "");
        logger.debug("Attribute ns was empty; Setting it to current schema tns [{}]", nsUri);
    }

    org.dom4j.QName dom4jQName = null;
    if (StringUtils.isEmpty(nsUri)) {
        dom4jQName = org.dom4j.QName.get(name);
    } else {

        String prefix = nsMap.getPrefix(nsUri);
        logger.debug("Got prefix [{}] for ns uri: [{}]", prefix, nsUri);

        if (StringUtils.isEmpty(prefix)) {
            prefix = DEFAULT_PREFIX + prefixCounter++;
            nsMap.put(prefix, nsUri);
            logger.debug("Generated prefix {} for ns uri: {}", prefix, nsUri);
        }

        logger.trace("Qualifying attribute with prefix [{}] and ns [{}]", prefix, nsUri);
        dom4jQName = org.dom4j.QName.get(name, prefix, nsUri);
    }

    return dom4jQName;
}

From source file:com.stratumsoft.xmlgen.SchemaTypeXmlGenerator.java

private org.dom4j.QName createDom4jQName(QName qname, XmlSchemaForm form) {
    org.dom4j.QName dom4jQname = null;

    if (qname != null) {
        String nsUri = qname.getNamespaceURI();
        Namespace ns = null;/*from w w  w  . j  a va  2s. co m*/
        if (StringUtils.isNotEmpty(nsUri)) {
            if (form == XmlSchemaForm.QUALIFIED) {
                String prefix = nsMap.getPrefix(nsUri);

                if (StringUtils.isEmpty(prefix)) {
                    prefix = DEFAULT_PREFIX + prefixCounter++;
                    nsMap.add(prefix, nsUri);
                }

                ns = new Namespace(prefix, nsUri);
            }
        }
        dom4jQname = new org.dom4j.QName(qname.getLocalPart(), ns);
    }
    return dom4jQname;
}

From source file:com.twinsoft.convertigo.engine.util.WsReference.java

private static XmlHttpTransaction createSoapTransaction(XmlSchema xmlSchema, WsdlInterface iface,
        WsdlOperation operation, Project project, HttpConnector httpConnector)
        throws ParserConfigurationException, SAXException, IOException, EngineException {
    XmlHttpTransaction xmlHttpTransaction = null;
    WsdlRequest request;//w  w w .  ja v a2 s . c  om
    String requestXml;
    String transactionName, comment;
    String operationName;

    if (operation != null) {
        comment = operation.getDescription();
        try {
            comment = (comment.equals("")
                    ? operation.getBindingOperation().getDocumentationElement().getTextContent()
                    : comment);
        } catch (Exception e) {
        }
        operationName = operation.getName();
        transactionName = StringUtils.normalize("C" + operationName);
        xmlHttpTransaction = new XmlHttpTransaction();
        xmlHttpTransaction.bNew = true;
        xmlHttpTransaction.setHttpVerb(HttpMethodType.POST);
        xmlHttpTransaction.setName(transactionName);
        xmlHttpTransaction.setComment(comment);

        // Set encoding (UTF-8 by default)
        xmlHttpTransaction.setEncodingCharSet("UTF-8");
        xmlHttpTransaction.setXmlEncoding("UTF-8");

        // Ignore SOAP elements in response
        xmlHttpTransaction.setIgnoreSoapEnveloppe(true);

        // Adds parameters
        XMLVector<XMLVector<String>> parameters = new XMLVector<XMLVector<String>>();
        XMLVector<String> xmlv;
        xmlv = new XMLVector<String>();
        xmlv.add(HeaderName.ContentType.value());
        xmlv.add(MimeType.TextXml.value());
        parameters.add(xmlv);

        xmlv = new XMLVector<String>();
        xmlv.add("Host");
        xmlv.add(httpConnector.getServer());
        parameters.add(xmlv);

        xmlv = new XMLVector<String>();
        xmlv.add("SOAPAction");
        xmlv.add(""); // fix #4215 - SOAPAction header must be empty
        parameters.add(xmlv);

        xmlv = new XMLVector<String>();
        xmlv.add("user-agent");
        xmlv.add("Convertigo EMS " + Version.fullProductVersion);
        parameters.add(xmlv);

        xmlHttpTransaction.setHttpParameters(parameters);

        QName qname = null;
        boolean bRPC = false;
        String style = operation.getStyle();
        if (style.toUpperCase().equals("RPC"))
            bRPC = true;

        // Set SOAP response element
        if (bRPC) {
            try {
                MessagePart[] parts = operation.getDefaultResponseParts();
                if (parts.length > 0) {
                    String ename = parts[0].getName();
                    if (parts[0].getPartType().name().equals("CONTENT")) {
                        MessagePart.ContentPart mpcp = (MessagePart.ContentPart) parts[0];
                        qname = mpcp.getSchemaType().getName();
                        if (qname != null) {
                            // response is based on an element defined with a type
                            // operationResponse element name; element name; element type
                            String responseQName = operationName + "Response;" + ename + ";" + "{"
                                    + qname.getNamespaceURI() + "}" + qname.getLocalPart();
                            xmlHttpTransaction.setResponseElementQName(responseQName);
                        }
                    }
                }
            } catch (Exception e) {
            }
        } else {
            try {
                qname = operation.getResponseBodyElementQName();
                if (qname != null) {
                    QName refName = new QName(qname.getNamespaceURI(), qname.getLocalPart());
                    xmlHttpTransaction.setXmlElementRefAffectation(new XmlQName(refName));
                }
            } catch (Exception e) {
            }
        }

        // Create request/response
        request = operation.addNewRequest("Test" + transactionName);
        requestXml = operation.createRequest(true);
        request.setRequestContent(requestXml);
        //responseXml = operation.createResponse(true);

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document requestDoc = db.parse(new InputSource(new StringReader(requestXml)));
        //Document responseDoc = db.parse(new InputSource(new StringReader(responseXml)));

        Element enveloppe = requestDoc.getDocumentElement();
        String soapenvNamespace = enveloppe.getNamespaceURI();

        // Retrieve variables
        Element header = (Element) requestDoc.getDocumentElement()
                .getElementsByTagNameNS(soapenvNamespace, "Header").item(0);
        Element body = (Element) requestDoc.getDocumentElement()
                .getElementsByTagNameNS(soapenvNamespace, "Body").item(0);

        //System.out.println(XMLUtils.prettyPrintDOM(requestDoc));

        // Extract variables
        List<RequestableHttpVariable> variables = new ArrayList<RequestableHttpVariable>();
        extractSoapVariables(xmlSchema, variables, header, null, false, null);
        extractSoapVariables(xmlSchema, variables, body, null, false, null);

        // Serialize request/response into template xml files
        String projectName = project.getName();
        String connectorName = httpConnector.getName();
        String templateDir = Engine.PROJECTS_PATH + "/" + projectName + "/soap-templates/" + connectorName;
        File dir = new File(templateDir);
        if (!dir.exists())
            dir.mkdirs();

        String requestTemplateName = "/soap-templates/" + connectorName + "/" + xmlHttpTransaction.getName()
                + ".xml";
        String requestTemplate = Engine.PROJECTS_PATH + "/" + projectName + requestTemplateName;

        xmlHttpTransaction.setRequestTemplate(requestTemplateName);
        saveTemplate(requestDoc, requestTemplate);

        // Adds variables
        for (RequestableHttpVariable variable : variables) {
            //System.out.println("adding "+ variable.getName());
            xmlHttpTransaction.add(variable);
        }

        xmlHttpTransaction.hasChanged = true;
    }

    return xmlHttpTransaction;
}

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

private ComplexTypeDefinition getOrProcessComplexType(QName typeName) throws SchemaException {
    ComplexTypeDefinition complexTypeDefinition = schema.findComplexTypeDefinition(typeName);
    if (complexTypeDefinition != null) {
        return complexTypeDefinition;
    }//from  ww  w  .java  2  s  . co m
    // The definition is not yet processed (or does not exist). Let's try to
    // process it.
    XSComplexType complexType = xsSchemaSet.getComplexType(typeName.getNamespaceURI(), typeName.getLocalPart());
    return processComplexTypeDefinition(complexType);
}

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

private <T, S> void unmarshallToAnyUsingGetter(T bean, Method getter, QName elementName, XNode xsubnode,
        ParsingContext pc) throws SchemaException {
    Class<T> beanClass = (Class<T>) bean.getClass();

    Class objectFactoryClass = inspector.getObjectFactoryClass(elementName.getNamespaceURI());
    Object objectFactory = instantiateObjectFactory(objectFactoryClass);
    Method elementFactoryMethod = inspector.findElementMethodInObjectFactory(objectFactoryClass,
            elementName.getLocalPart());
    Class<S> subBeanClass = (Class<S>) elementFactoryMethod.getParameterTypes()[0];

    if (xsubnode instanceof ListXNode) {
        for (XNode xsubSubNode : ((ListXNode) xsubnode)) {
            S subBean = unmarshal(xsubSubNode, subBeanClass, pc);
            unmarshallToAnyValue(bean, beanClass, subBean, objectFactoryClass, objectFactory,
                    elementFactoryMethod, getter, pc);
        }/*from   ww  w  .  jav  a 2 s . c o  m*/
    } else {
        S subBean = unmarshal(xsubnode, subBeanClass, pc);
        unmarshallToAnyValue(bean, beanClass, subBean, objectFactoryClass, objectFactory, elementFactoryMethod,
                getter, pc);
    }
}

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

private QName getRealElementName(XNode node, QName key, ParsingContext pc) throws SchemaException {
    if (node.getElementName() == null) {
        return key;
    }//  www  .  ja  va2  s. c  o  m
    String elementNS = node.getElementName().getNamespaceURI();
    String keyNS = key.getNamespaceURI();
    if (StringUtils.isNotEmpty(elementNS) && StringUtils.isNotEmpty(keyNS) && !elementNS.equals(keyNS)) {
        pc.warnOrThrow(LOGGER, "Namespaces for actual element (" + node.getElementName()
                + ") and it's place in schema (" + key + " are different.");
        return key; // fallback
    } else {
        return node.getElementName();
    }
}