Java Code Examples for org.apache.ws.commons.schema.XmlSchemaAppInfo#setMarkup()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaAppInfo#setMarkup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XsdAnnotationEmitter.java    From legstar-core2 with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Create an XML Schema annotation with markup corresponding to the original
 * COBOL data item attributes.
 * 
 * @param xsdDataItem COBOL data item decorated with XSD attributes
 * @return an XML schema annotation
 */
public XmlSchemaAnnotation createLegStarAnnotation(
        final XsdDataItem xsdDataItem) {

    Document doc = _docBuilder.newDocument();
    Element el = doc.createElementNS(getCOXBNamespace(), getCOXBElements());
    Element elc = doc.createElementNS(getCOXBNamespace(), getCOXBElement());

    elc.setAttribute(CobolMarkup.LEVEL_NUMBER,
            Integer.toString(xsdDataItem.getLevelNumber()));
    elc.setAttribute(CobolMarkup.COBOL_NAME, xsdDataItem.getCobolName());
    elc.setAttribute(CobolMarkup.TYPE, xsdDataItem.getCobolType()
            .toString());

    if (xsdDataItem.getCobolType() != CobolTypes.GROUP_ITEM) {
        if (xsdDataItem.getPicture() != null) {
            elc.setAttribute(CobolMarkup.PICTURE, xsdDataItem.getPicture());
        }
        if (xsdDataItem.getUsage() != null) {
            elc.setAttribute(CobolMarkup.USAGE,
                    xsdDataItem.getUsageForCobol());
        }
        if (xsdDataItem.isJustifiedRight()) {
            elc.setAttribute(CobolMarkup.IS_JUSTIFIED_RIGHT, "true");
        }
        if (xsdDataItem.getTotalDigits() > 0) {
            elc.setAttribute(CobolMarkup.IS_SIGNED,
                    (xsdDataItem.isSigned()) ? "true" : "false");
            elc.setAttribute(CobolMarkup.TOTAL_DIGITS,
                    Integer.toString(xsdDataItem.getTotalDigits()));
            if (xsdDataItem.getFractionDigits() > 0) {
                elc.setAttribute(CobolMarkup.FRACTION_DIGITS,
                        Integer.toString(xsdDataItem.getFractionDigits()));
            }
            if (xsdDataItem.isSignLeading()) {
                elc.setAttribute(CobolMarkup.IS_SIGN_LEADING, "true");
            }
            if (xsdDataItem.isSignSeparate()) {
                elc.setAttribute(CobolMarkup.IS_SIGN_SEPARATE, "true");
            }
        }
    }

    /*
     * Annotations transfer the COBOL occurs semantic (as opposed to the XSD
     * semantic). No depending on => fixed size array
     */
    if (xsdDataItem.getCobolMaxOccurs() > 0) {
        elc.setAttribute(CobolMarkup.MAX_OCCURS,
                Integer.toString(xsdDataItem.getCobolMaxOccurs()));
        if (xsdDataItem.getDependingOn() == null) {
            elc.setAttribute(CobolMarkup.MIN_OCCURS,
                    Integer.toString(xsdDataItem.getCobolMaxOccurs()));
        } else {
            elc.setAttribute(CobolMarkup.DEPENDING_ON,
                    xsdDataItem.getDependingOn());
            elc.setAttribute(CobolMarkup.MIN_OCCURS,
                    Integer.toString(xsdDataItem.getCobolMinOccurs()));
        }
    }

    if (xsdDataItem.isODOObject()) {
        elc.setAttribute(CobolMarkup.IS_ODO_OBJECT, "true");
    }
    if (xsdDataItem.getRedefines() != null) {
        elc.setAttribute(CobolMarkup.REDEFINES, xsdDataItem.getRedefines());
    }
    if (xsdDataItem.isRedefined()) {
        elc.setAttribute(CobolMarkup.IS_REDEFINED, "true");
        elc.setAttribute(CobolMarkup.UNMARSHAL_CHOICE_STRATEGY, "");
    }

    if (xsdDataItem.getValue() != null
            && xsdDataItem.getValue().length() > 0) {
        elc.setAttribute(CobolMarkup.VALUE, ValueUtil.resolveFigurative(
                xsdDataItem.getValue(), xsdDataItem.getMaxStorageLength(),
                getConfig().quoteIsQuote()));
    }

    if (xsdDataItem.getSrceLine() > 0) {
        elc.setAttribute(CobolMarkup.SRCE_LINE,
                Integer.toString(xsdDataItem.getSrceLine()));
    }

    el.appendChild(elc);

    XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
    appInfo.setMarkup(el.getChildNodes());

    /* Create annotation */
    XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
    annotation.getItems().add(appInfo);
    return annotation;
}
 
Example 2
Source File: ObjectReferenceVisitor.java    From cxf with Apache License 2.0 4 votes vote down vote up
private void isDuplicateReference(QName referenceName, QName bindingName, Scope refScope,
                                  XmlSchemaType wsaType, AST node) {
    XmlSchema refSchema = null;
    if (!mapper.isDefaultMapping()) {
        String tns = mapper.map(refScope.getParent());
        String refSchemaFileName = getWsdlVisitor().getOutputDir()
            + System.getProperty("file.separator")
            + refScope.getParent().toString("_") + ".xsd";
        refSchema = manager.getXmlSchema(tns);
        if (refSchema == null) {
            refSchema = manager.createXmlSchema(tns, wsdlVisitor.getSchemas());
        }
        addWSAddressingImport(refSchema);
        manager.addXmlSchemaImport(schema, refSchema, refSchemaFileName);
    } else {
        refSchema = schema;
    }

    // Check to see if we have already defined an element for this reference type.  If
    // we have, then there is no need to add it to the schema again.
    if (!isReferenceSchemaTypeDefined(referenceName, refSchema)) {
        // We need to add a new element definition to the schema section of our WSDL.
        // For custom endpoint types, this should contain an annotation which points
        // to the binding which will be used for this endpoint type.
        XmlSchemaElement refElement = new XmlSchemaElement(schema, true);
        refElement.setName(referenceName.getLocalPart());
        refElement.setSchemaType(wsaType);
        refElement.setSchemaTypeName(wsaType.getQName());

        // Create an annotation which contains the CORBA binding for the element
        XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
        XmlSchemaAppInfo appInfo = new XmlSchemaAppInfo();
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);

            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.newDocument();
            Element el = doc.createElement("appinfo");
            el.setTextContent("corba:binding=" + bindingName.getLocalPart());
            // TODO: This is correct but the appinfo markup is never added to the
            // schema.  Investigate.
            appInfo.setMarkup(el.getChildNodes());
        } catch (ParserConfigurationException ex) {
            throw new RuntimeException("[ObjectReferenceVisitor: error creating endpoint schema]");
        }

        annotation.getItems().add(appInfo);

        refElement.setAnnotation(annotation);
    }
}