Search in sources :

Example 6 with ProcessingException

use of com.predic8.membrane.annot.ProcessingException in project service-proxy by membrane.

the class AttributeInfo method analyze.

private void analyze(Types typeUtils) {
    if (// already analyzed?
    xsdType != null)
        return;
    if (getE().getParameters().size() != 1)
        throw new ProcessingException("Setter is supposed to have 1 parameter.", getE());
    VariableElement ve = getE().getParameters().get(0);
    switch(ve.asType().getKind()) {
        case INT:
            xsdType = "spel_number";
            return;
        case LONG:
            xsdType = "spel_number";
            return;
        case BOOLEAN:
            xsdType = "spel_boolean";
            return;
        case DECLARED:
            TypeElement e = (TypeElement) typeUtils.asElement(ve.asType());
            if (e.getQualifiedName().toString().equals("java.lang.String")) {
                xsdType = "xsd:string";
                return;
            }
            if (e.getSuperclass().getKind() == TypeKind.DECLARED) {
                TypeElement superClass = ((TypeElement) typeUtils.asElement(e.getSuperclass()));
                if (superClass.getQualifiedName().toString().equals("java.lang.Enum")) {
                    isEnum = true;
                    // TODO: restriction, but be carefull about Spring EL usage, for example "#{config.XXX}"
                    xsdType = "xsd:string";
                    /*
					 *	<xsd:attribute name=\"target\" use=\"optional\" default=\"body\">\r\n" +
					 *		<xsd:simpleType>\r\n" +
					 *			<xsd:restriction base=\"xsd:string\">\r\n" +
					 *				<xsd:enumeration value=\"body\" />\r\n" +
					 *				<xsd:enumeration value=\"header\" />\r\n" +
					 *			</xsd:restriction>\r\n" +
					 *		</xsd:simpleType>\r\n" +
					 *	</xsd:attribute>\r\n"
					 */
                    return;
                }
            }
            isBeanReference = true;
            xsdType = "xsd:string";
            return;
        default:
            throw new ProcessingException("Not implemented: XSD type for " + ve.asType().getKind().toString(), this.getE());
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) ProcessingException(com.predic8.membrane.annot.ProcessingException)

Aggregations

ProcessingException (com.predic8.membrane.annot.ProcessingException)3 ChildElementInfo (com.predic8.membrane.annot.model.ChildElementInfo)3 ChildElementDeclarationInfo (com.predic8.membrane.annot.model.ChildElementDeclarationInfo)2 ElementInfo (com.predic8.membrane.annot.model.ElementInfo)2 AttributeInfo (com.predic8.membrane.annot.model.AttributeInfo)1 MainInfo (com.predic8.membrane.annot.model.MainInfo)1 Model (com.predic8.membrane.annot.model.Model)1 OtherAttributesInfo (com.predic8.membrane.annot.model.OtherAttributesInfo)1 TextContentInfo (com.predic8.membrane.annot.model.TextContentInfo)1 IOException (java.io.IOException)1 TreeSet (java.util.TreeSet)1 TypeElement (javax.lang.model.element.TypeElement)1 VariableElement (javax.lang.model.element.VariableElement)1 DeclaredType (javax.lang.model.type.DeclaredType)1 TypeMirror (javax.lang.model.type.TypeMirror)1