org.apache.ws.commons.schema.XmlSchemaAnnotation Java Examples

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaAnnotation. 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: XsdAnnotationEmitterTest.java    From legstar-core2 with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Helper to check item level annotation emission. Get item level
 * annotations. We hook them directly in the schema because that simplifies
 * testing.
 * 
 * @param dataItem a COBOL data item
 * @param expected expected annotations as a string
 */
private void emitAnnotationAndCheck(final CobolDataItem dataItem,
        final String expected) {
    configProps.put(Cob2XsdConfig.ADD_LEGSTAR_ANNOTATIONS,
            Boolean.toString(true));
    Cob2XsdConfig config = new Cob2XsdConfig(configProps);
    XmlSchema xsd = getXmlSchema();
    XsdAnnotationEmitter emitter = new XsdAnnotationEmitter(xsd, config);
    XsdDataItem xsdDataItem = new XsdDataItem(dataItem, config, null, 0,
            new ArrayList < String >(), _errorHandler);
    XmlSchemaAnnotation annotation = emitter
            .createLegStarAnnotation(xsdDataItem);
    xsd.setAnnotation(annotation);
    check("<annotation>" + "<appinfo>" + expected + "</appinfo>"
            + "</annotation>", xsd, true);
}
 
Example #2
Source File: WSDLParameter.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static QName getSchemaTypeName(WSDLToCorbaBinding wsdlToCorbaBinding, XmlSchemaType schemaType,
                                       XmlSchemaAnnotation annotation, QName typeName, boolean nill)
    throws Exception {
    QName idltype = null;
    CorbaType corbaTypeImpl = null;

    corbaTypeImpl = wsdlToCorbaBinding.getHelper().convertSchemaToCorbaType(schemaType, typeName, null,
                                                                            annotation, false);
    if (corbaTypeImpl == null) {
        throw new Exception("Couldn't convert schema type to corba type : " + typeName);
    }
    if (nill) {
        QName qname = corbaTypeImpl.getQName();
        idltype = wsdlToCorbaBinding.getHelper().createQNameCorbaNamespace(qname.getLocalPart()
                                                                               + "_nil");
    } else {
        idltype = corbaTypeImpl.getQName();
    }
    return idltype;
}
 
Example #3
Source File: WSDLParameter.java    From cxf with Apache License 2.0 6 votes vote down vote up
private boolean isObjectReference(SchemaCollection schemaList, QName name) {
    for (XmlSchema schema : schemaList.getXmlSchemas()) {
        XmlSchemaElement element = schema.getElementByName(name);
        if (element != null) {
            XmlSchemaAnnotation annotation = element.getAnnotation();
            if (annotation != null) {
                List<XmlSchemaAnnotationItem> annotationColl = annotation.getItems();
                for (XmlSchemaAnnotationItem item : annotationColl) {
                    if (item instanceof XmlSchemaAppInfo) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example #4
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private CorbaType processComplexType(XmlSchemaComplexType complex, QName defaultName,
                                         XmlSchemaAnnotation annotation,
                                         boolean anonymous) throws Exception {
    CorbaType corbatype = null;
    if (isLiteralArray(complex)) {
        corbatype = processLiteralArray(complex, defaultName, anonymous);
    } else if (WSDLTypes.isOMGUnion(complex)) {
        corbatype = processOMGUnion(complex, defaultName);
    } else if (WSDLTypes.isUnion(complex)) {
        corbatype = processRegularUnion(complex, defaultName);
    } else if (complex.getQName() != null && isIDLObjectType(complex.getQName())) {
        // process it.
        corbatype = WSDLTypes.processObject(def, complex, annotation, checkPrefix(complex.getQName()),
                                            defaultName, idlNamespace);
    } else {
        // Deal the ComplexType as Struct
        corbatype = processStruct(complex, defaultName);
    }
    return corbatype;
}
 
Example #5
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Get the DidRefSource for a reference schema type
 */
DidRefSource getRefSource(XmlSchemaComplexType refSchema) {
    DidRefSource refSource = null;
    String schemaName = refSchema.getName();
    if (refSourceCache.containsKey(schemaName)) {
        refSource = refSourceCache.get(schemaName);
        // if a cached refSource is found create return new DidRefSource of same type
        if (refSource != null) {
            DidRefSource cachedRefSource = refSource;
            refSource = new DidRefSource();
            refSource.setEntityType(cachedRefSource.getEntityType());
        }
    } else {
        XmlSchemaAnnotation annotation = refSchema.getAnnotation();
        if (annotation == null) {
            LOG.debug("Annotation missing from refSchema: {}", refSchema.getName());
        } else {
            refSource = parseAnnotationForRef(annotation);
            refSourceCache.put(schemaName, refSource);
        }
    }
    return refSource;
}
 
Example #6
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an annotation for keyfields and add to a map
 */
private Map<String, String> parseAnnotationForKeyField(XmlSchemaAnnotation annotation) {
    Map<String, String> keyField = new HashMap<String, String>();

    XmlSchemaAppInfo appInfo = getAppInfo(annotation);
    if (appInfo != null) {
        NodeList nodes = appInfo.getMarkup();
        for (int nodeIdx = 0; nodeIdx < nodes.getLength(); nodeIdx++) {
            Node node = nodes.item(nodeIdx);
            if (node instanceof Element) {
                String key = node.getLocalName().trim();
                String value = node.getFirstChild().getNodeValue().trim();

                if (key.equals(REF_TYPE) || key.equals(KEY_FIELD_NAME)) {
                    keyField.put(key, value);
                }
            }
        }
    }
    return keyField;
}
 
Example #7
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an annotation for recordType annotation
 */
private String parseAnnotationForRecordType(XmlSchemaAnnotation annotation) {
    String recordType = null;
    XmlSchemaAppInfo appInfo = getAppInfo(annotation);
    if (appInfo != null) {
        NodeList nodes = appInfo.getMarkup();
        for (int nodeIdx = 0; nodeIdx < nodes.getLength(); nodeIdx++) {
            Node node = nodes.item(nodeIdx);
            if (node instanceof Element) {
                String key = node.getLocalName().trim();
                String value = node.getFirstChild().getNodeValue().trim();

                if (key.equals(RECORD_TYPE)) {
                    recordType = value;
                    break;
                }
            }
        }
    }
    return recordType;
}
 
Example #8
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
/**
 * Parse an annotation for naturalKeys annotation
 */
private String parseAnnotationForNaturalKeys(XmlSchemaAnnotation annotation) {
    String naturalKeys = null;

    XmlSchemaAppInfo appInfo = getAppInfo(annotation);
    if (appInfo != null) {
        NodeList nodes = appInfo.getMarkup();
        for (int nodeIdx = 0; nodeIdx < nodes.getLength(); nodeIdx++) {
            Node node = nodes.item(nodeIdx);
            if (node instanceof Element) {
                String key = node.getLocalName().trim();
                String value = node.getFirstChild().getNodeValue().trim();

                if (key.equals("naturalKeys")) {
                    naturalKeys = value;
                    break;
                }
            }
        }
    }
    return naturalKeys;
}
 
Example #9
Source File: CobolAnnotations.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * XSD elements are annotated with COBOL markup that we extract here.
 * 
 * @param xsdElement the XSD element
 * @return the COBOL markup
 */
private static Element getCobolXsdAnnotations(XmlSchemaElement xsdElement) {
    XmlSchemaAnnotation annotation = xsdElement.getAnnotation();
    if (annotation == null || annotation.getItems().size() == 0) {
        throw new IllegalArgumentException("Xsd element of type "
                + xsdElement.getSchemaType().getQName()
                + " at line " + xsdElement.getLineNumber()
                + " does not have COBOL annotations");
    }

    XmlSchemaAppInfo appinfo = (XmlSchemaAppInfo) annotation.getItems()
            .get(0);
    if (appinfo.getMarkup() == null) {
        throw new IllegalArgumentException("Xsd element of type "
                + xsdElement.getSchemaType().getQName()
                + " does not have any markup in its annotations");
    }
    Node node = null;
    boolean found = false;
    for (int i = 0; i < appinfo.getMarkup().getLength(); i++) {
        node = appinfo.getMarkup().item(i);
        if (node instanceof Element
                && node.getLocalName().equals(CobolMarkup.ELEMENT)
                && node.getNamespaceURI().equals(CobolMarkup.NS)) {
            found = true;
            break;
        }
    }
    if (!found) {
        throw new IllegalArgumentException("Xsd element of type "
                + xsdElement.getSchemaType().getQName()
                + " at line " + xsdElement.getLineNumber()
                + " does not have any COBOL annotations");
    }
    return (Element) node;
}
 
Example #10
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public CorbaType convertSchemaToCorbaType(XmlSchemaType stype,
                                              QName defaultName,
                                              XmlSchemaType parent,
                                              XmlSchemaAnnotation annotation,
                                              boolean anonymous)
    throws Exception {
    CorbaType corbaTypeImpl = null;
    if (!isAddressingNamespace(stype.getQName())) {
        // need to determine if its a primitive type.
        if (stype instanceof XmlSchemaComplexType) {
            corbaTypeImpl = processComplexType((XmlSchemaComplexType)stype,
                                                          defaultName, annotation, anonymous);
        } else if (stype instanceof XmlSchemaSimpleType) {
            corbaTypeImpl = processSimpleType((XmlSchemaSimpleType)stype,
                                              defaultName, anonymous);
        }  else if (xmlSchemaList.getElementByQName(stype.getQName()) != null) {
            XmlSchemaElement el = xmlSchemaList.getElementByQName(stype.getQName());
            //REVISIT, passing ns uri because of a bug in XmlSchema (Bug: WSCOMMONS-69)
            corbaTypeImpl = processElementType(el,
                                               defaultName,
                                               stype.getQName().getNamespaceURI());
        } else {
            throw new Exception("Couldn't convert schema " + stype.getQName() + " to corba type");
        }
    }

    if (corbaTypeImpl != null && !isDuplicate(corbaTypeImpl)) {
        typeMappingType.getStructOrExceptionOrUnion().add(corbaTypeImpl);
    }

    return corbaTypeImpl;
}
 
Example #11
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Extract entity configs
 */
private Map<String, DidEntityConfig> extractEntityConfigs() {
    Map<String, DidEntityConfig> extractedEntityConfigs = new HashMap<String, DidEntityConfig>();

    // Iterate XML Schema items
    for (Entry<String, XmlSchemaComplexType> complexType : complexTypes.entrySet()) {

        // exclude IdentityTypes which may also contain referenceTypes but shouldn't result in
        // an EntityConfig
        if (complexType.getKey().contains(IDENTITY_TYPE)) {
            continue;
        }

        DidEntityConfig entityConfig = extractEntityConfig(complexType.getValue());
        if (entityConfig != null) {
            // extract the entity annotations
            XmlSchemaAnnotation annotation = complexType.getValue().getAnnotation();
            if (annotation != null) {
                String recordType = parseAnnotationForRecordType(annotation);
                if (recordType != null) {
                    extractedEntityConfigs.put(recordType, entityConfig);
                } else {
                    LOG.error("Failed to extract DidEntityConfig for type " + complexType.getKey()
                            + ", couldn't find recordType annotation");
                }
            } else {
                LOG.error("Failed to extract DidEntityConfig for type " + complexType.getKey()
                        + " - null annotation");
            }
        }
    }

    return extractedEntityConfigs;
}
 
Example #12
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Parse an annotation for DidRefSource data
 */
private DidRefSource parseAnnotationForRef(XmlSchemaAnnotation annotation) {
    DidRefSource refSource = null;

    boolean applyKeyFields = false;
    String refType = null;

    XmlSchemaAppInfo appInfo = getAppInfo(annotation);
    if (appInfo != null) {
        // get applyKeyFields and refType from appInfo
        NodeList nodes = appInfo.getMarkup();
        for (int nodeIdx = 0; nodeIdx < nodes.getLength(); nodeIdx++) {
            Node node = nodes.item(nodeIdx);
            if (node instanceof Element) {

                String key = node.getLocalName().trim();
                String value = node.getFirstChild().getNodeValue().trim();

                if (key.equals(APPLY_KEY_FIELDS)) {
                    if (value.equals("true")) {
                        applyKeyFields = true;
                    }
                } else if (key.equals(REF_TYPE)) {
                    refType = value;
                }
            }
        }
        if (applyKeyFields && refType != null) {
            refSource = new DidRefSource();
            refSource.setEntityType(refType);
        }
    }

    return refSource;
}
 
Example #13
Source File: DidSchemaParser.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
public Map<String, List<DidNaturalKey>> extractNaturalKeys() {
    Map<String, List<DidNaturalKey>> entitiesWithKeys = new HashMap<String, List<DidNaturalKey>> ();
    for (XmlSchemaComplexType complexType : complexTypes.values()) {
        XmlSchemaAnnotation annotation = complexType.getAnnotation();
        String naturalKeys = parseAnnotationForNaturalKeys(annotation);
        if(naturalKeys != null) {
            entitiesWithKeys.put(parseAnnotationForRecordType(annotation), getNaturalKeysForEntity(complexType, naturalKeys));

        }
    }
    return entitiesWithKeys;
}
 
Example #14
Source File: Xsd2UmlConvert.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * The xs:annotation is parsed into {@link TaggedValue} with one entry per
 * xs:documentation or xs:appinfo.
 */
private static final List<TaggedValue> annotations(final XmlSchemaAnnotated schemaType, final Xsd2UmlConfig config) {
    if (schemaType == null) {
        return EMPTY_TAGGED_VALUES;
    }
    final XmlSchemaAnnotation annotation = schemaType.getAnnotation();
    if (annotation == null) {
        return EMPTY_TAGGED_VALUES;
    } else {
        final List<TaggedValue> taggedValues = new LinkedList<TaggedValue>();
        final XmlSchemaObjectCollection children = annotation.getItems();
        
        for (int childIdx = 0; childIdx < children.getCount(); ++childIdx) {
            
            final XmlSchemaObject child = children.getItem(childIdx);
            if (child instanceof XmlSchemaDocumentation) {
                final XmlSchemaDocumentation documentation = (XmlSchemaDocumentation) child;
                taggedValues.add(documentation(documentation, config));
            } else if (child instanceof XmlSchemaAppInfo) {
                final XmlSchemaAppInfo appInfo = (XmlSchemaAppInfo) child;
                taggedValues.addAll(config.getPlugin().tagsFromAppInfo(appInfo, config));
            } else {
                throw new AssertionError(child);
            }
        }
        
        return taggedValues;
    }
}
 
Example #15
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 #16
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);
    }
}