Example usage for javax.xml.namespace QName getLocalPart

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

Introduction

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

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:com.example.soaplegacy.WsdlValidator.java

private void validateRpcLiteral(BindingOperation bindingOperation, Part[] parts, XmlObject msgXml,
        List<XmlError> errors, boolean isResponse, boolean strict) throws Exception {
    if (parts.length == 0)
        return;// w ww.  ja  va 2s.  c o  m

    XmlObject[] bodyParts = getRpcBodyPart(bindingOperation, msgXml, isResponse);

    if (bodyParts.length != 1) {
        errors.add(XmlError.forMessage(
                "Missing message wrapper element [" + WsdlUtils.getTargetNamespace(wsdlContext.getDefinition())
                        + "@" + bindingOperation.getName() + (isResponse ? "Response" : "")));
    } else {
        XmlObject wrapper = bodyParts[0];

        for (int i = 0; i < parts.length; i++) {
            Part part = parts[i];

            // skip attachment parts
            if (isResponse) {
                if (WsdlUtils.isAttachmentOutputPart(part, bindingOperation))
                    continue;
            } else {
                if (WsdlUtils.isAttachmentInputPart(part, bindingOperation))
                    continue;
            }

            // find part in message
            XmlObject[] children = wrapper.selectChildren(new QName(part.getName()));

            // not found?
            if (children.length != 1) {
                // try element name (loophole in basic-profile spec?)
                QName elementName = part.getElementName();
                if (elementName != null) {
                    bodyParts = msgXml.selectPath("declare namespace env='"
                            + wsdlContext.getSoapVersion().getEnvelopeNamespace() + "';"
                            + "declare namespace ns='" + wsdlContext.getDefinition().getTargetNamespace() + "';"
                            + "declare namespace ns2='" + elementName.getNamespaceURI() + "';"
                            + "$this/env:Envelope/env:Body/ns:" + bindingOperation.getName()
                            + (isResponse ? "Response" : "") + "/ns2:" + elementName.getLocalPart());

                    if (bodyParts.length == 1) {
                        SchemaGlobalElement elm = wsdlContext.getSchemaTypeLoader().findElement(elementName);
                        if (elm != null) {
                            validateMessageBody(errors, elm.getType(), bodyParts[0]);
                        } else
                            errors.add(XmlError.forMessage(
                                    "Missing part type in associated schema for [" + elementName + "]"));
                    } else
                        errors.add(XmlError.forMessage("Missing message part with name [" + elementName + "]"));
                } else {
                    errors.add(XmlError.forMessage("Missing message part [" + part.getName() + "]"));
                }
            } else {
                QName typeName = part.getTypeName();
                SchemaType type = wsdlContext.getSchemaTypeLoader().findType(typeName);
                if (type != null) {
                    validateMessageBody(errors, type, children[0]);
                } else {
                    errors.add(XmlError
                            .forMessage("Missing type in associated schema for part [" + part.getName() + "]"));
                }
            }
        }
    }
}

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

@NotNull
private <T> T unmarshalFromMapOrHeteroListToBean(@NotNull T bean, @NotNull XNode mapOrList,
        @Nullable Collection<String> keysToParse, @NotNull ParsingContext pc) throws SchemaException {
    @SuppressWarnings("unchecked")
    Class<T> beanClass = (Class<T>) bean.getClass();
    if (mapOrList instanceof MapXNode) {
        MapXNode map = (MapXNode) mapOrList;
        for (Entry<QName, XNode> entry : map.entrySet()) {
            QName key = entry.getKey();
            if (keysToParse != null && !keysToParse.contains(key.getLocalPart())) {
                continue;
            }// ww w  .  j  av a  2 s.com
            if (entry.getValue() == null) {
                continue;
            }
            unmarshalEntry(bean, beanClass, entry.getKey(), entry.getValue(), mapOrList, false, pc);
        }
    } else if (mapOrList.isHeterogeneousList()) {
        QName keyQName = getBeanMarshaller().getHeterogeneousListPropertyName(beanClass);
        unmarshalEntry(bean, beanClass, keyQName, mapOrList, mapOrList, true, pc);
    } else {
        throw new IllegalStateException("Not a map nor heterogeneous list: " + mapOrList.debugDump());
    }
    return bean;
}

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 w w .  j  a v a2  s .c o m
    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.DomToSchemaProcessor.java

private ComplexTypeDefinition getOrProcessComplexType(QName typeName) throws SchemaException {
    ComplexTypeDefinition complexTypeDefinition = schema.findComplexTypeDefinition(typeName);
    if (complexTypeDefinition != null) {
        return complexTypeDefinition;
    }//from   w  w  w . j a v  a2 s .c  om
    // 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.web.page.admin.server.PageTaskEdit.java

private Task updateTask(TaskDto dto, Task existingTask) throws SchemaException {

    if (!existingTask.getName().equals(dto.getName())) {
        existingTask.setName(WebMiscUtil.createPolyFromOrigString(dto.getName()));
    } // if they are equal, modifyObject complains ... it's probably a bug in repo; we'll fix it later?

    if ((existingTask.getDescription() == null && dto.getDescription() != null)
            || (existingTask.getDescription() != null
                    && !existingTask.getDescription().equals(dto.getDescription()))) {
        existingTask.setDescription(dto.getDescription());
    }//from w ww. j  a v a 2 s .  c o  m

    TaskAddResourcesDto resourceRefDto;
    if (dto.getResource() != null) {
        resourceRefDto = dto.getResource();
        ObjectReferenceType resourceRef = new ObjectReferenceType();
        resourceRef.setOid(resourceRefDto.getOid());
        resourceRef.setType(ResourceType.COMPLEX_TYPE);
        existingTask.setObjectRef(resourceRef);
    }

    if (!dto.getRecurring()) {
        existingTask.makeSingle();
    }
    existingTask.setBinding(dto.getBound() == true ? TaskBinding.TIGHT : TaskBinding.LOOSE);

    ScheduleType schedule = new ScheduleType();

    schedule.setEarliestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartBefore()));
    schedule.setLatestStartTime(MiscUtil.asXMLGregorianCalendar(dto.getNotStartAfter()));
    schedule.setMisfireAction(dto.getMisfire());
    if (existingTask.getSchedule() != null) {
        schedule.setLatestFinishTime(existingTask.getSchedule().getLatestFinishTime());
    }

    if (dto.getRecurring() == true) {

        if (dto.getBound() == false && dto.getCronSpecification() != null) {
            schedule.setCronLikePattern(dto.getCronSpecification());
        } else {
            schedule.setInterval(dto.getInterval());
        }
        existingTask.makeRecurring(schedule);
    } else {
        existingTask.makeSingle(schedule);
    }

    ThreadStopActionType tsa = dto.getThreadStop();
    //        if (tsa == null) {
    //            tsa = dto.getRunUntilNodeDown() ? ThreadStopActionType.CLOSE : ThreadStopActionType.RESTART;
    //        }
    existingTask.setThreadStopAction(tsa);

    SchemaRegistry registry = getPrismContext().getSchemaRegistry();
    if (dto.isDryRun()) {
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        PrismProperty dryRun = new PrismProperty(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        dryRun.setDefinition(def);
        dryRun.setRealValue(true);

        existingTask.addExtensionProperty(dryRun);
    } else {
        PrismProperty dryRun = existingTask.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_DRY_RUN);
        if (dryRun != null) {
            existingTask.deleteExtensionProperty(dryRun);
        }
    }

    if (dto.getKind() != null) {
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_KIND);
        PrismProperty kind = new PrismProperty(SchemaConstants.MODEL_EXTENSION_KIND);
        kind.setDefinition(def);
        kind.setRealValue(dto.getKind());

        existingTask.addExtensionProperty(kind);
    } else {
        PrismProperty kind = existingTask.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_KIND);

        if (kind != null) {
            existingTask.deleteExtensionProperty(kind);
        }
    }

    if (dto.getIntent() != null && StringUtils.isNotEmpty(dto.getIntent())) {
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_INTENT);
        PrismProperty intent = new PrismProperty(SchemaConstants.MODEL_EXTENSION_INTENT);
        intent.setDefinition(def);
        intent.setRealValue(dto.getIntent());

        existingTask.addExtensionProperty(intent);
    } else {
        PrismProperty intent = existingTask.getExtensionProperty(SchemaConstants.MODEL_EXTENSION_INTENT);

        if (intent != null) {
            existingTask.deleteExtensionProperty(intent);
        }
    }

    if (dto.getObjectClass() != null && StringUtils.isNotEmpty(dto.getObjectClass())) {
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        PrismProperty objectClassProperty = new PrismProperty(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);
        objectClassProperty.setRealValue(def);

        QName objectClass = null;
        for (QName q : model.getObject().getObjectClassList()) {
            if (q.getLocalPart().equals(dto.getObjectClass())) {
                objectClass = q;
            }
        }

        objectClassProperty.setRealValue(objectClass);
        existingTask.addExtensionProperty(objectClassProperty);

    } else {
        PrismProperty objectClass = existingTask
                .getExtensionProperty(SchemaConstants.OBJECTCLASS_PROPERTY_NAME);

        if (objectClass != null) {
            existingTask.deleteExtensionProperty(objectClass);
        }
    }

    if (dto.getWorkerThreads() != null) {
        PrismPropertyDefinition def = registry
                .findPropertyDefinitionByElementName(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
        PrismProperty workerThreads = new PrismProperty(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);
        workerThreads.setDefinition(def);
        workerThreads.setRealValue(dto.getWorkerThreads());

        existingTask.setExtensionProperty(workerThreads);
    } else {
        PrismProperty workerThreads = existingTask
                .getExtensionProperty(SchemaConstants.MODEL_EXTENSION_WORKER_THREADS);

        if (workerThreads != null) {
            existingTask.deleteExtensionProperty(workerThreads);
        }
    }

    return existingTask;
}

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

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement,
        QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();

    // if typeQName is not explicitly specified, we try to determine it from parsed value
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }/*from w w w.  ja  va2 s. co m*/
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContext.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(),
                            stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element "
                                + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName
                    + ", cannot serialize (schemaless serialization is disabled)");
        }
    }

    // typeName != null after this point

    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }

    Element element = null;

    if (typeQName.equals(ItemPath.XSD_TYPE)) {
        ItemPath itemPath = (ItemPath) xprim.getValue();
        if (itemPath != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            XPathHolder holder = new XPathHolder(itemPath);
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }

    } else {
        // not an ItemPathType

        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName
                        + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }

        if (typeQName.equals(DOMUtil.XSD_QNAME)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code,
                            e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart()
                                    + " in element " + DOMUtil.getQName(parentElement) + " to QName value "
                                    + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();

            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }

    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}

From source file:gov.nih.nci.cacis.common.util.ExtractSchematron.java

private void postprocessFlavorContexts() {
    for (final QName flavorType : this.flavorUsages.keySet()) {
        // the contexts for flavor usage are the contexts to the flavor type's immediate non-flavor supertype, which
        // by now will include the xsi:type contexts to that type's parents, with the addition of
        // [@flavorId=flavorType]

        final TypeUsage flavorUsage = this.flavorUsages.get(flavorType);
        final TypeUsage parentNonFlavorTypeUsage = this.datatypeUsages.get(getDatatypeParent(flavorType));

        if (parentNonFlavorTypeUsage == null) {
            throw new IllegalStateException(
                    "Flavor type " + flavorType + " has a missing or undefined non-flavor parent type");
        }/*from   w  w  w.  ja v  a2s  .c  o m*/

        for (final String context : parentNonFlavorTypeUsage.getContexts()) {
            flavorUsage.getContexts().add(addFlavorId(context, flavorType.getLocalPart()));
        }
    }
}

From source file:com.evolveum.midpoint.prism.lex.dom.DomLexicalWriter.java

private void serializePrimitiveElementOrAttribute(PrimitiveXNode<?> xprim, Element parentElement,
        QName elementOrAttributeName, boolean asAttribute) throws SchemaException {
    QName typeQName = xprim.getTypeQName();

    // if typeQName is not explicitly specified, we try to determine it from parsed value
    // TODO we should probably set typeQName when parsing the value...
    if (typeQName == null && xprim.isParsed()) {
        Object v = xprim.getValue();
        if (v != null) {
            typeQName = XsdTypeMapper.toXsdType(v.getClass());
        }/*  w  ww.j  a va2  s . co m*/
    }

    if (typeQName == null) { // this means that either xprim is unparsed or it is empty
        if (com.evolveum.midpoint.prism.PrismContextImpl.isAllowSchemalessSerialization()) {
            // We cannot correctly serialize without a type. But this is needed
            // sometimes. So just default to string
            String stringValue = xprim.getStringValue();
            if (stringValue != null) {
                if (asAttribute) {
                    DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(),
                            stringValue);
                    DOMUtil.setNamespaceDeclarations(parentElement, xprim.getRelevantNamespaceDeclarations());
                } else {
                    Element element;
                    try {
                        element = createElement(elementOrAttributeName, parentElement);
                        appendCommentIfPresent(element, xprim);
                    } catch (DOMException e) {
                        throw new DOMException(e.code, e.getMessage() + "; creating element "
                                + elementOrAttributeName + " in element " + DOMUtil.getQName(parentElement));
                    }
                    parentElement.appendChild(element);
                    DOMUtil.setElementTextContent(element, stringValue);
                    DOMUtil.setNamespaceDeclarations(element, xprim.getRelevantNamespaceDeclarations());
                }
            }
            return;
        } else {
            throw new IllegalStateException("No type for primitive element " + elementOrAttributeName
                    + ", cannot serialize (schemaless serialization is disabled)");
        }
    }

    // typeName != null after this point

    if (StringUtils.isBlank(typeQName.getNamespaceURI())) {
        typeQName = XsdTypeMapper.determineQNameWithNs(typeQName);
    }

    Element element = null;

    if (ItemPathType.COMPLEX_TYPE.equals(typeQName)) {
        //ItemPathType itemPathType = //ItemPathType.asItemPathType(xprim.getValue());         // TODO fix this hack
        ItemPathType itemPathType = (ItemPathType) xprim.getValue();
        if (itemPathType != null) {
            if (asAttribute) {
                throw new UnsupportedOperationException(
                        "Serializing ItemPath as an attribute is not supported yet");
            }
            ItemPathHolder holder = new ItemPathHolder(itemPathType.getItemPath());
            element = holder.toElement(elementOrAttributeName, parentElement.getOwnerDocument());
            parentElement.appendChild(element);
        }

    } else {
        // not an ItemPathType

        if (!asAttribute) {
            try {
                element = createElement(elementOrAttributeName, parentElement);
            } catch (DOMException e) {
                throw new DOMException(e.code, e.getMessage() + "; creating element " + elementOrAttributeName
                        + " in element " + DOMUtil.getQName(parentElement));
            }
            appendCommentIfPresent(element, xprim);
            parentElement.appendChild(element);
        }

        if (DOMUtil.XSD_QNAME.equals(typeQName)) {
            QName value = (QName) xprim.getParsedValueWithoutRecording(DOMUtil.XSD_QNAME);
            value = setQNamePrefixExplicitIfNeeded(value);
            if (asAttribute) {
                try {
                    DOMUtil.setQNameAttribute(parentElement, elementOrAttributeName.getLocalPart(), value);
                } catch (DOMException e) {
                    throw new DOMException(e.code,
                            e.getMessage() + "; setting attribute " + elementOrAttributeName.getLocalPart()
                                    + " in element " + DOMUtil.getQName(parentElement) + " to QName value "
                                    + value);
                }
            } else {
                DOMUtil.setQNameValue(element, value);
            }
        } else {
            // not ItemType nor QName
            String value = xprim.getGuessedFormattedValue();

            if (asAttribute) {
                DOMUtil.setAttributeValue(parentElement, elementOrAttributeName.getLocalPart(), value);
            } else {
                DOMUtil.setElementTextContent(element, value);
            }
        }

    }
    if (!asAttribute && xprim.isExplicitTypeDeclaration()) {
        DOMUtil.setXsiType(element, setQNamePrefixExplicitIfNeeded(typeQName));
    }
}

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;/*from   w w w  .  j a v a2 s.com*/
    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;
    }/* www  . java2s  .  c om*/
    // 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);
}