Java Code Examples for org.apache.cxf.common.util.ReflectionUtil#getDeclaredFields()

The following examples show how to use org.apache.cxf.common.util.ReflectionUtil#getDeclaredFields() . 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: JAXBDataBinding.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static Field getElField(String partName, final Class<?> wrapperType) {
    String fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
    Field[] fields = ReflectionUtil.getDeclaredFields(wrapperType);
    for (Field field : fields) {
        XmlElement el = field.getAnnotation(XmlElement.class);
        if (el != null
            && partName.equals(el.name())) {
            return field;
        }

        XmlElementRef xmlElementRefAnnotation = field.getAnnotation(XmlElementRef.class);
        if (xmlElementRefAnnotation != null && partName.equals(xmlElementRefAnnotation.name())) {
            return field;
        }

        if (field.getName().equals(fieldName)) {
            return field;
        }
    }
    return null;
}
 
Example 2
Source File: JAXRSUtils.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static Response copyResponseIfNeeded(Response response) {
    if (!(response instanceof ResponseImpl)) {
        Response r = fromResponse(response).build();
        Field[] declaredFields = ReflectionUtil.getDeclaredFields(response.getClass());
        for (Field f : declaredFields) {
            Class<?> declClass = f.getType();
            if (declClass == Annotation[].class) {
                try {
                    Annotation[] fieldAnnotations =
                        ReflectionUtil.accessDeclaredField(f, response, Annotation[].class);
                    ((ResponseImpl)r).setEntityAnnotations(fieldAnnotations);
                } catch (Throwable ex) {
                    LOG.warning("Custom annotations if any can not be copied");
                }
                break;
            }
        }
        return r;
    }
    return response;
}
 
Example 3
Source File: AbstractResourceInfo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void findContextFields(Class<?> cls, Object provider) {
    if (cls == Object.class || cls == null) {
        return;
    }
    for (Field f : ReflectionUtil.getDeclaredFields(cls)) {
        for (Annotation a : f.getAnnotations()) {
            if (a.annotationType() == Context.class
                && (f.getType().isInterface() || f.getType() == Application.class)) {
                contextFields = addContextField(contextFields, f);
                checkContextClass(f.getType());
                if (!InjectionUtils.VALUE_CONTEXTS.contains(f.getType().getName())) {
                    addToMap(getFieldProxyMap(true), f, getFieldThreadLocalProxy(f, provider));
                }
            }
        }
    }
    findContextFields(cls.getSuperclass(), provider);
}
 
Example 4
Source File: BeanResourceInfo.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void setParamField(Class<?> cls) {
    if (Object.class == cls || cls == null) {
        return;
    }
    for (Field f : ReflectionUtil.getDeclaredFields(cls)) {
        for (Annotation a : f.getAnnotations()) {
            if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
                if (paramFields == null) {
                    paramFields = new ArrayList<>();
                }
                paramsAvailable = true;
                paramFields.add(f);
            }
        }
    }
    setParamField(cls.getSuperclass());
}
 
Example 5
Source File: CXFService.java    From cxf with Apache License 2.0 5 votes vote down vote up
private ServiceImpl findDelegate() {
    for (Field f : ReflectionUtil.getDeclaredFields(Service.class)) {
        if (ServiceDelegate.class.equals(f.getType())) {
            ServiceDelegate del = ReflectionUtil.accessDeclaredField(f, this, ServiceDelegate.class);
            if (del instanceof ServiceImpl) {
                return (ServiceImpl)del;
            }
            throw new WebServiceException("Delegate of class " + del.getClass() + " is not a CXF delegate.  "
                                          + " Check the classpath to make sure CXF is loaded first.");
        }
    }
    throw new WebServiceException("Could not find CXF service delegate");
}
 
Example 6
Source File: AnnotationProcessor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void processFields(AnnotationVisitor visitor, Class<? extends Object> targetClass) {
    if (targetClass.getSuperclass() != null) {
        processFields(visitor, targetClass.getSuperclass());
    }
    for (Field element : ReflectionUtil.getDeclaredFields(targetClass)) {
        for (Class<? extends Annotation> clz : annotationTypes) {
            Annotation ann = element.getAnnotation(clz);
            if (ann != null) {
                visitor.visitField(element, ann);
            }
        }
    }
}