Search in sources :

Example 1 with TypeClassInfo

use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.

the class AegisDatabinding method getParameterType.

private AegisType getParameterType(Service s, TypeMapping tm, MessagePartInfo param, int paramtype) {
    AegisType type = tm.getType(param.getTypeQName());
    if (type != null && type.getTypeClass() != param.getTypeClass()) {
        type = null;
    }
    int offset = 0;
    if (paramtype == OUT_PARAM) {
        offset = 1;
    }
    TypeCreator typeCreator = tm.getTypeCreator();
    if (type == null) {
        // Current author doesn't know how type can be non-null here.
        boolean usingComponentType = false;
        OperationInfo op = param.getMessageInfo().getOperation();
        Method m = getMethod(s, op);
        TypeClassInfo info;
        if (paramtype != FAULT_PARAM && m != null) {
            info = typeCreator.createClassInfo(m, param.getIndex() - offset);
        } else {
            info = typeCreator.createBasicClassInfo(param.getTypeClass());
        }
        Boolean nillable = info.getNillable();
        /*
             * Note that, for types from the mapping, the minOccurs, maxOccurs, and nillable from the 'info'
             * will be ignored by createTypeForClass below. So we need to override.
             */
        type = typeCreator.createTypeForClass(info);
        // if not writing outer, we don't need anything special.
        if (param.getMessageInfo().getOperation().isUnwrapped() && param.getTypeClass().isArray() && type.isWriteOuter()) {
            /*
                 * The service factory expects arrays going into the wrapper to be mapped to the array
                 * component type and will then add min=0/max=unbounded. That doesn't work for Aegis where we
                 * already created a wrapper ArrayType so we'll let it know we want the default.
                 */
            param.setProperty("minOccurs", "1");
            param.setProperty("maxOccurs", "1");
            if (nillable == null) {
                nillable = Boolean.TRUE;
            }
            param.setProperty("nillable", nillable);
        } else {
            if (nillable != null) {
                param.setProperty("nillable", nillable);
            }
            /*
                 * TypeClassInfo uses -1 to mean 'not specified'
                 */
            if (info.getMinOccurs() != -1) {
                param.setProperty("minOccurs", Long.toString(info.getMinOccurs()));
            }
            if (info.getMaxOccurs() != -1) {
                param.setProperty("maxOccurs", Long.toString(info.getMaxOccurs()));
            }
            if ((type instanceof ArrayType) && !type.isWriteOuter()) {
                param.setProperty("org.apache.cxf.aegis.outerType", type);
                ArrayType aType = (ArrayType) type;
                type = aType.getComponentType();
                usingComponentType = true;
            }
        }
        if (info.getMappedName() != null) {
            param.setConcreteName(info.getMappedName());
            param.setName(info.getMappedName());
        }
        if (!usingComponentType) {
            // param setting above?
            if (info.nonDefaultAttributes()) {
                tm.register(type);
            }
            type.setTypeMapping(tm);
        }
        part2Type.put(param, type);
    }
    return type;
}
Also used : OperationInfo(org.apache.cxf.service.model.OperationInfo) ArrayType(org.apache.cxf.aegis.type.basic.ArrayType) AegisType(org.apache.cxf.aegis.type.AegisType) TypeClassInfo(org.apache.cxf.aegis.type.TypeClassInfo) Method(java.lang.reflect.Method) TypeCreator(org.apache.cxf.aegis.type.TypeCreator)

Example 2 with TypeClassInfo

use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.

the class Java5TypeCreator method createClassInfo.

@Override
public TypeClassInfo createClassInfo(Method m, int index) {
    if (index >= 0) {
        TypeClassInfo info;
        Type genericType = m.getGenericParameterTypes()[index];
        if (genericType instanceof Class) {
            info = nextCreator.createClassInfo(m, index);
        } else {
            info = new TypeClassInfo();
            info.setDescription("method " + m.getName() + " parameter " + index);
            info.setType(genericType);
        }
        Class<?> paramTypeClass = annotationReader.getParamType(m, index);
        info.setAegisTypeClass(castToAegisTypeClass(paramTypeClass));
        String paramName = annotationReader.getParamTypeName(m, index);
        if (paramName != null) {
            info.setTypeName(createQName(m.getParameterTypes()[index], genericType, paramName, annotationReader.getParamNamespace(m, index)));
        }
        return info;
    }
    Type genericReturnType = m.getGenericReturnType();
    TypeClassInfo info;
    if (genericReturnType instanceof Class) {
        info = nextCreator.createClassInfo(m, index);
    } else {
        info = new TypeClassInfo();
        info.setDescription("method " + m.getName() + " parameter " + index);
        info.setType(genericReturnType);
    }
    if (m.getParameterAnnotations() != null && m.getAnnotations().length > 0) {
        info.setAnnotations(m.getAnnotations());
    }
    info.setAegisTypeClass(castToAegisTypeClass(annotationReader.getReturnType(m)));
    String returnName = annotationReader.getReturnTypeName(m);
    if (returnName != null) {
        info.setTypeName(createQName(m.getReturnType(), genericReturnType, returnName, annotationReader.getReturnNamespace(m)));
    }
    return info;
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AegisType(org.apache.cxf.aegis.type.AegisType) TypeClassInfo(org.apache.cxf.aegis.type.TypeClassInfo)

Example 3 with TypeClassInfo

use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.

the class Java5TypeCreator method getOrCreateParameterizedType.

protected AegisType getOrCreateParameterizedType(TypeClassInfo generic, int index, boolean map) {
    Type paramType;
    Map<String, Type> pm = generic.getTypeVars();
    if (map) {
        if (pm == null) {
            pm = new HashMap<>();
        } else {
            pm = new HashMap<>(pm);
        }
        paramType = getComponentTypeForMap(generic.getType(), pm, index == 0);
    } else {
        paramType = getComponentType(generic.getType(), index);
    }
    if (paramType instanceof WildcardType) {
        WildcardType wct = (WildcardType) paramType;
        paramType = wct.getUpperBounds()[0];
    }
    if (paramType instanceof TypeVariable) {
        TypeVariable<?> v = (TypeVariable<?>) paramType;
        LOG.log(Level.WARNING, "Could not map TypeVariable named {0} from {1} with initial mapping {2} to " + "a known class.  Using Object.", new Object[] { v.getName(), generic.getType().toString(), generic.getTypeVars() });
    }
    if (paramType == null) {
        return createObjectType();
    }
    /* null arises when the index-th parameter to generic is something list List<T> */
    Class<?> clazz = TypeUtil.getTypeRelatedClass(paramType);
    if (clazz == null) {
        return createObjectType();
    }
    if (!Collection.class.isAssignableFrom(clazz) && !Map.class.isAssignableFrom(clazz)) {
        return getTopCreator().createType(clazz);
    }
    TypeClassInfo info = createBasicClassInfo(clazz);
    info.setDescription(clazz.toString());
    info.setType(paramType, paramType instanceof ParameterizedType ? pm : null);
    return createTypeForClass(info);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) BeanType(org.apache.cxf.aegis.type.basic.BeanType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AegisType(org.apache.cxf.aegis.type.AegisType) WildcardType(java.lang.reflect.WildcardType) TypeVariable(java.lang.reflect.TypeVariable) TypeClassInfo(org.apache.cxf.aegis.type.TypeClassInfo)

Example 4 with TypeClassInfo

use of org.apache.cxf.aegis.type.TypeClassInfo in project cxf by apache.

the class Java5TypeCreator method createClassInfo.

/*
     * Apparently, this callers must notice collection types and not call this.
     */
@Override
public TypeClassInfo createClassInfo(PropertyDescriptor pd) {
    Type genericType = pd.getReadMethod().getGenericReturnType();
    TypeClassInfo info = createBasicClassInfo(pd.getPropertyType());
    // override basicClassInfo's of the type.
    info.setType(genericType);
    info.setAnnotations(pd.getReadMethod().getAnnotations());
    info.setAegisTypeClass(castToAegisTypeClass(annotationReader.getType(pd.getReadMethod())));
    info.setFlat(annotationReader.isFlat(pd.getReadMethod().getAnnotations()));
    return info;
}
Also used : BeanType(org.apache.cxf.aegis.type.basic.BeanType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) AegisType(org.apache.cxf.aegis.type.AegisType) TypeClassInfo(org.apache.cxf.aegis.type.TypeClassInfo)

Aggregations

AegisType (org.apache.cxf.aegis.type.AegisType)4 TypeClassInfo (org.apache.cxf.aegis.type.TypeClassInfo)4 ParameterizedType (java.lang.reflect.ParameterizedType)3 Type (java.lang.reflect.Type)3 WildcardType (java.lang.reflect.WildcardType)3 BeanType (org.apache.cxf.aegis.type.basic.BeanType)3 Method (java.lang.reflect.Method)1 TypeVariable (java.lang.reflect.TypeVariable)1 TypeCreator (org.apache.cxf.aegis.type.TypeCreator)1 ArrayType (org.apache.cxf.aegis.type.basic.ArrayType)1 OperationInfo (org.apache.cxf.service.model.OperationInfo)1