Java Code Examples for org.apache.ws.commons.schema.XmlSchemaElement#getSchemaType()

The following examples show how to use org.apache.ws.commons.schema.XmlSchemaElement#getSchemaType() . 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: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private CorbaType processElementType(XmlSchemaElement stype, QName defaultName, String uri)
    throws Exception {

    String name = null;
    QName schemaTypeName = null;
    XmlSchemaType schemaType = stype.getSchemaType();

    if (stype.getQName() == null) {
        if (stype.getRef().getTargetQName() == null) {
            schemaTypeName = defaultName;
        } else {
            name = stype.getRef().getTargetQName().getLocalPart();
            schemaType = findSchemaType(stype.getRef().getTargetQName());
        }
    } else {
        name = stype.getQName().getLocalPart();
    }
    if (schemaTypeName == null) {
        schemaTypeName = createQNameTargetNamespace(name);
    }
    CorbaType result = convertSchemaToCorbaType(schemaType, schemaTypeName,
                                                    schemaType, null, false);

    result.setQualified(getElementQualification(stype, uri));
    return result;
}
 
Example 2
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected XmlSchemaType lookUpType(Part part) {
    XmlSchemaType schemaType = null;
    for (XmlSchema xmlSchema : xmlSchemaList.getXmlSchemas()) {
        if (part.getElementName() != null) {
            XmlSchemaElement schemaElement = xmlSchema.getElementByName(part.getElementName());
            if (schemaElement != null) {
                schemaType = schemaElement.getSchemaType();
            }
        } else {
            if (part.getTypeName() != null) {
                schemaType = xmlSchema.getTypeByName(part.getTypeName());
            }
        }
        if (schemaType != null) {
            return schemaType;
        }
    }

    return schemaType;
}
 
Example 3
Source File: WSDLToCorbaHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private XmlSchemaType findTypeInSchema(XmlSchema xmlSchema, QName typeName) {
    XmlSchemaType schemaType = null;

    if (xmlSchema.getElementByName(typeName) != null) {
        XmlSchemaElement schemaElement = xmlSchema.getElementByName(typeName);
        schemaType = schemaElement.getSchemaType();
    } else if (xmlSchema.getTypeByName(typeName) != null) {
        schemaType = xmlSchema.getTypeByName(typeName);
    }
    if (schemaType != null) {
        return schemaType;
    }
    for (XmlSchemaExternal extSchema : xmlSchema.getExternals()) {
        if (!(extSchema instanceof XmlSchemaImport)) {
            schemaType = findTypeInSchema(extSchema.getSchema(), typeName);
            if (schemaType != null) {
                return schemaType;
            }
        }
    }

    return null;
}
 
Example 4
Source File: ParticleInfo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static void factorySetupType(XmlSchemaElement element, SchemaCollection schemaCollection,
                                     ParticleInfo elementInfo) {
    elementInfo.type = element.getSchemaType();
    if (elementInfo.type == null) {
        if (element.getSchemaTypeName() == null // no type at all -> anyType
            || element.getSchemaTypeName().equals(Constants.XSD_ANYTYPE)) {
            elementInfo.anyType = true;
        } else {
            elementInfo.type = schemaCollection.getTypeByQName(element.getSchemaTypeName());
            if (elementInfo.type == null
                && !element.getSchemaTypeName()
                        .getNamespaceURI().equals(Constants.URI_2001_SCHEMA_XSD)) {
                JavascriptUtils.unsupportedConstruct("MISSING_TYPE", element.getSchemaTypeName()
                        .toString(), element.getQName(), element);
            }
        }
    } else if (elementInfo.type.getQName() != null
        && Constants.XSD_ANYTYPE.equals(elementInfo.type.getQName())) {
        elementInfo.anyType = true;
    }
}
 
Example 5
Source File: Xsd2CobolTypesModelBuilder.java    From legstar-core2 with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map < String, Object > getProps(int fieldIndex,
        XmlSchemaElement xsdElement, RootCompositeType compositeTypes) {
    Map < String, Object > props;
    CobolAnnotations cobolAnnotations = new CobolAnnotations(xsdElement);

    if (xsdElement.getSchemaType() instanceof XmlSchemaComplexType) {
        props = getProps((XmlSchemaComplexType) xsdElement.getSchemaType(),
                compositeTypes);

    } else if (xsdElement.getSchemaType() instanceof XmlSchemaSimpleType) {
        props = getProps((XmlSchemaSimpleType) xsdElement.getSchemaType(),
                cobolAnnotations);
        if (props.get(ODO_OBJECT_PROP_NAME) != null) {
            odoObjectNames.put(cobolAnnotations.getCobolName(),
                    getFieldName(xsdElement));
        }

    } else {
        throw new Xsd2ConverterException("Unsupported xsd element of type "
                + xsdElement.getSchemaType().getQName() + " at line "
                + xsdElement.getLineNumber());
    }

    if (xsdElement.getMaxOccurs() > 1) {
        addArrayProps(xsdElement, cobolAnnotations, props);
    }
    
    if (xsdElement.getMinOccurs() == 0 &&  xsdElement.getMaxOccurs() == 1) {
        addOptionalProps(xsdElement, cobolAnnotations, props);
    }

    props.put(COBOL_NAME_PROP_NAME, cobolAnnotations.getCobolName());
    props.put(FIELD_INDEX_PROP_NAME, fieldIndex);
    return props;

}
 
Example 6
Source File: ProcessorUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<WrapperElement> getWrappedElement(ToolContext context, QName partElement) {
    ServiceInfo serviceInfo = context.get(ServiceInfo.class);
    SchemaCollection schema = serviceInfo.getXmlSchemaCollection();

    XmlSchemaElement elementByName = schema.getElementByQName(partElement);

    XmlSchemaComplexType type = (XmlSchemaComplexType)elementByName.getSchemaType();

    XmlSchemaSequence seq = (XmlSchemaSequence)type.getParticle();

    List<WrapperElement> qnames = createWrappedElements(seq);

    //If it's extension
    if (seq == null && type.getContentModel() != null) {
        Object configuredMaxStackDepth = context.get(ToolConstants.CFG_MAX_EXTENSION_STACK_DEPTH);
        Integer maxStackDepth = Integer.valueOf(5);
        if (configuredMaxStackDepth instanceof Integer) {
            maxStackDepth = (Integer)configuredMaxStackDepth;
        } else if (configuredMaxStackDepth instanceof String) {
            maxStackDepth = Integer.valueOf((String)configuredMaxStackDepth);
        }
        qnames.addAll(createWrappedElementsFromExtension(schema, type, maxStackDepth));

    }

    return qnames;
}
 
Example 7
Source File: ParameterProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void processReturn(JavaMethod method, MessagePartInfo part) {
    String name = part == null ? "return" : part.getName().getLocalPart();
    String type = part == null ? "void" : ProcessorUtil.resolvePartType(part, context);

    String namespace = part == null ? null : ProcessorUtil.resolvePartNamespace(part);

    JavaReturn returnType = new JavaReturn(name, type, namespace);
    if (part != null) {
        returnType.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    }

    returnType.setQName(ProcessorUtil.getElementName(part));
    returnType.setStyle(JavaType.Style.OUT);
    if (namespace != null && type != null && !"void".equals(type)) {
        returnType.setClassName(ProcessorUtil.getFullClzName(part, context, false));
    }

    if (part != null && part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType)part.getXmlSchema(), method, part);
    } else if (part != null && part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement)part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType)element.getSchemaType(), method, part);
        }
    }

    method.setReturn(returnType);
}
 
Example 8
Source File: ParameterMapper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static JavaParameter map(JavaMethod jm, MessagePartInfo part,
                                JavaType.Style style, ToolContext context) {
    String name = ProcessorUtil.mangleNameToVariableName(part.getName().getLocalPart());
    String namespace = ProcessorUtil.resolvePartNamespace(part);
    String type = ProcessorUtil.resolvePartType(part, context);

    JavaParameter parameter = new JavaParameter(name, type, namespace);
    parameter.setPartName(part.getName().getLocalPart());
    if (part.getXmlSchema() instanceof XmlSchemaSimpleType) {
        processXmlSchemaSimpleType((XmlSchemaSimpleType)part.getXmlSchema(), jm, parameter, part);
    } else if (part.getXmlSchema() instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement)part.getXmlSchema();
        if (element.getSchemaType() instanceof XmlSchemaSimpleType) {
            processXmlSchemaSimpleType((XmlSchemaSimpleType)element.getSchemaType(), jm, parameter, part);
        }
    }
    parameter.setQName(ProcessorUtil.getElementName(part));
    parameter.setDefaultValueWriter(ProcessorUtil.getDefaultValueWriter(part, context));
    String fullJavaName = ProcessorUtil.getFullClzName(part, context, false);

    parameter.setClassName(fullJavaName);

    if (style == JavaType.Style.INOUT || style == JavaType.Style.OUT) {
        parameter.setHolder(true);
        parameter.setHolderName(javax.xml.ws.Holder.class.getName());
        String holderClass = fullJavaName;
        if (JAXBUtils.holderClass(fullJavaName) != null) {
            holderClass = JAXBUtils.holderClass(fullJavaName).getName();
        }
        parameter.setClassName(holderClass);
    }
    parameter.setStyle(style);

    return parameter;
}
 
Example 9
Source File: CorbaUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static XmlSchemaType getXmlSchemaType(ServiceInfo serviceInfo, QName name) {
    XmlSchemaType result = null;
    if ((name != null) && (serviceInfo != null)) {
        SchemaCollection col = serviceInfo.getXmlSchemaCollection();
        result = col.getTypeByQName(name);
        if (result == null) {
            //check the name, if it is an element
            XmlSchemaElement el = col.getElementByQName(name);
            if (el != null) {
                result = el.getSchemaType();
            }
        }
    }
    return result;
}
 
Example 10
Source File: JavascriptUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * We really don't want to take the attitude that 'all base64Binary elements are candidates for MTOM'.
 * So we look for clues.
 * @param schemaObject
 * @return
 */
private boolean treatAsMtom(XmlSchemaObject schemaObject) {
    if (schemaObject == null) {
        return false;
    }

    Map<Object, Object> metaInfoMap = schemaObject.getMetaInfoMap();
    if (metaInfoMap != null) {
        Map<?, ?> attribMap = (Map<?, ?>)metaInfoMap.get(Constants.MetaDataConstants.EXTERNAL_ATTRIBUTES);
        Attr ctAttr = (Attr)attribMap.get(MimeAttribute.MIME_QNAME);
        if (ctAttr != null) {
            return true;
        }
    }

    if (schemaObject instanceof XmlSchemaElement) {
        XmlSchemaElement element = (XmlSchemaElement) schemaObject;
        if (element.getSchemaType() == null) {
            return false;
        }
        QName typeName = element.getSchemaType().getQName();
        // We could do something much more complex in terms of evaluating whether the type
        // permits the contentType attribute. This, however, is enough to clue us in for what Aegis
        // does.
        if (new QName("http://www.w3.org/2005/05/xmlmime", "base64Binary").equals(typeName)) {
            return true;
        }

    }

    return false;
}
 
Example 11
Source File: ReflectionServiceFactoryBean.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Code elsewhere in this function will fill in the name of the type of an
 * element but not the reference to the type. This function fills in the
 * type references. This does not set the type reference for elements that
 * are declared as refs to other elements. It is a giant pain to find them,
 * since they are not (generally) root elements and the code would have to
 * traverse all the types to find all of them. Users should look them up
 * through the collection, that's what it is for.
 */
private void fillInSchemaCrossreferences() {
    Service service = getService();
    for (ServiceInfo serviceInfo : service.getServiceInfos()) {
        SchemaCollection schemaCollection = serviceInfo.getXmlSchemaCollection();

        // First pass, fill in any types for which we have a name but no
        // type.
        for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
            Map<QName, XmlSchemaElement> elementsTable = schemaInfo.getSchema().getElements();
            for (XmlSchemaElement element : elementsTable.values()) {
                if (element.getSchemaType() == null) {
                    QName typeName = element.getSchemaTypeName();
                    if (typeName != null) {
                        XmlSchemaType type = schemaCollection.getTypeByQName(typeName);
                        if (type == null) {
                            Message message = new Message("REFERENCE_TO_UNDEFINED_TYPE", LOG, element
                                .getQName(), typeName, service.getName());
                            LOG.severe(message.toString());
                        } else {
                            element.setSchemaType(type);
                        }
                    }
                }
            }

        }
    }
}
 
Example 12
Source File: ServiceModelUtil.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static List<String> getOperationInputPartNames(OperationInfo operation) {
    List<String> names = new ArrayList<>();
    List<MessagePartInfo> parts = operation.getInput().getMessageParts();
    if (parts == null || parts.isEmpty()) {
        return names;
    }

    for (MessagePartInfo part : parts) {
        XmlSchemaAnnotated schema = part.getXmlSchema();

        if (schema instanceof XmlSchemaElement
            && ((XmlSchemaElement)schema).getSchemaType() instanceof XmlSchemaComplexType) {
            XmlSchemaElement element = (XmlSchemaElement)schema;
            XmlSchemaComplexType cplxType = (XmlSchemaComplexType)element.getSchemaType();
            XmlSchemaSequence seq = (XmlSchemaSequence)cplxType.getParticle();
            if (seq == null || seq.getItems() == null) {
                return names;
            }
            for (int i = 0; i < seq.getItems().size(); i++) {
                XmlSchemaElement elChild = (XmlSchemaElement)seq.getItems().get(i);
                names.add(elChild.getName());
            }
        } else {
            names.add(part.getConcreteName().getLocalPart());
        }
    }
    return names;
}
 
Example 13
Source File: SchemaCollection.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void addElementCrossImportsElement(XmlSchema schema, XmlSchemaElement item) {
    XmlSchemaElement element = item;
    XmlSchemaUtils.addImportIfNeeded(schema, element.getRef().getTargetQName());
    XmlSchemaUtils.addImportIfNeeded(schema, element.getSchemaTypeName());
    // if there's an anonymous type, it might have element refs in it.
    XmlSchemaType schemaType = element.getSchemaType();
    if (!crossImportsAdded(schema, schemaType)) {
        addCrossImportsType(schema, schemaType);
    }
}
 
Example 14
Source File: WSDLToDataService.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private static List<QueryParam> getQueryParamsFromAxisOperation(Map<QName, Document> modelMap,
                                                                   Map<QName, String> elementMap, AxisOperation axisOperation) throws
                                                                                                                               DataServiceFault {
	AxisMessage axisMessage = getAxisMessageFromOperation(axisOperation, "in");
	if (axisMessage == null) {
		throw new DataServiceFault(
				"Valid in message cannot be found for the operation '"
						+ axisOperation.getName() + "'");
	}
	XmlSchemaElement inMsgElement = axisMessage.getSchemaElement();
	/* no query params - return empty list */
	if (inMsgElement == null) {
		return new ArrayList<QueryParam>();
	}
	
	XmlSchemaType inMsgType = inMsgElement.getSchemaType();
	if (!(inMsgType instanceof XmlSchemaComplexType)) {
		throw new DataServiceFault(
				"Xmlschema complex type is expected for the in message of the operation '"
						+ axisOperation.getName() + "'");
	}
		
	QName inMsgTypeName = inMsgElement.getQName();
	String elementName = elementMap.get(inMsgTypeName);
	Document operationDoc = modelMap.get(new QName(inMsgTypeName.getNamespaceURI(), elementName));
	ModelBean operationBean = createModelBean(modelMap, operationDoc);
	List<QueryParam> queryParams = new ArrayList<QueryParam>();
	
	String tmpType;
	List<ModelProperty> props = operationBean.getProperties();
	ModelProperty prop;
	int count = props.size();
	for (int i = 0; i < count; i++) {
		prop = props.get(i);
		tmpType = prop.getSimpleType();
		if (tmpType == null) {
			if (prop.getType().isSimple()) {
				tmpType = prop.getType().getProperties().get(0).getSimpleType();
			} else {
				throw new DataServiceFault(
						"A list of elements with simple types are expected at the in message of the operation '"
						+ axisOperation.getName() + "'");
			}
		}
		queryParams.add(new QueryParam(
                   prop.getName(),
                   DBUtils.getSQLTypeFromXsdType(tmpType),
                   DBConstants.QueryTypes.IN,
                   prop.isArray() ? DBConstants.QueryParamTypes.ARRAY :
					DBConstants.QueryParamTypes.SCALAR,
                   i + 1, // ordinal
                   null, null, new ArrayList<Validator>(), false, false));
	}

	return queryParams;
}
 
Example 15
Source File: XsdToNeutralSchemaRepo.java    From secure-data-service with Apache License 2.0 4 votes vote down vote up
private NeutralSchema parseElement(XmlSchemaElement element, XmlSchema schema) {

        QName elementTypeName = element.getSchemaTypeName();

        // Derive Element Schema
        XmlSchemaType elementSchemaType = element.getSchemaType();

        // Element annotations override type annotations.
        if (element.getAnnotation() != null) {
            elementSchemaType.setAnnotation(element.getAnnotation());
        }

        NeutralSchema elementSchema = null;
        if (elementSchemaType != null) {
            if (elementSchemaType.getName() != null) {
                elementSchema = this.parse(elementSchemaType, schema);
            } else {
                elementSchema = this.parse(elementSchemaType, element.getName(), schema);
            }
        } else if (elementTypeName != null) {
            elementSchema = getSchemaFactory().createSchema(elementTypeName);
        }

        if (elementSchema != null) {

            // List Schema
            if (element.getMaxOccurs() > 1) {
                ListSchema listSchema = (ListSchema) getSchemaFactory().createSchema("list");
                listSchema.getList().add(elementSchema);
                listSchema.updateAnnotations();
                elementSchema = listSchema;
            }
        }




        Long min = element.getMinOccurs();
        Long max = element.getMaxOccurs();
        QName type = element.getSchemaTypeName();

        if(min != null) {
            elementSchema.getProperties().put("minCardinality", min);
        }
        if( max != null) {
            elementSchema.getProperties().put("maxCardinality", max);
        }
        if(type != null) {
            elementSchema.getProperties().put("elementType", type.toString());
        }

        return elementSchema;
    }