Example usage for java.lang.reflect Field getType

List of usage examples for java.lang.reflect Field getType

Introduction

In this page you can find the example usage for java.lang.reflect Field getType.

Prototype

public Class<?> getType() 

Source Link

Document

Returns a Class object that identifies the declared type for the field represented by this Field object.

Usage

From source file:it.unibas.spicy.persistence.object.operators.AnalyzeFields.java

private PersistentProperty generateField(Field field) {
    String fieldName = field.getName();
    String typeName = field.getType().getSimpleName();
    PersistentProperty property = new PersistentProperty(fieldName, typeName);
    return property;
}

From source file:be.fedict.eid.dss.ws.ServiceConsumerInstanceResolver.java

private void injectServices(T endpoint, SignatureVerificationService signatureVerificationService,
        DocumentService documentService) {

    LOG.debug("injecting services into JAX-WS endpoint...");
    Field[] fields = endpoint.getClass().getDeclaredFields();
    for (Field field : fields) {

        EJB ejbAnnotation = field.getAnnotation(EJB.class);
        if (null == ejbAnnotation) {
            continue;
        }/*from www .  j a  v a 2 s. c om*/
        if (field.getType().equals(SignatureVerificationService.class)) {
            field.setAccessible(true);
            try {
                field.set(endpoint, signatureVerificationService);
            } catch (Exception e) {
                throw new RuntimeException("injection error: " + e.getMessage(), e);
            }
        } else if (field.getType().equals(DocumentService.class)) {
            field.setAccessible(true);
            try {
                field.set(endpoint, documentService);
            } catch (Exception e) {
                throw new RuntimeException("injection error: " + e.getMessage(), e);
            }
        }

    }
}

From source file:net.jaspr.chatalerts.network.message.NetworkMessage.java

@Override
public final void toBytes(ByteBuf buf) {
    try {/*from  w  w  w.  java2s.c  o  m*/
        Class<?> clazz = getClass();
        Field[] clFields = getClassFields(clazz);
        for (Field f : clFields) {
            Class<?> type = f.getType();
            if (acceptField(f, type))
                writeField(f, type, buf);
        }
    } catch (Exception e) {
        throw new RuntimeException("Error at writing packet " + this, e);
    }
}

From source file:management.limbr.test.util.PojoTester.java

@SuppressWarnings("unchecked")
public void test() {
    Class<T> clazz = (Class<T>) pojo.getClass();

    for (Field field : clazz.getDeclaredFields()) {
        String fieldName = field.getName();
        Method getter = findGetter(clazz, fieldName, field.getType().equals(Boolean.class));
        if (getter != null) {
            testGetter(getter, field);/* ww w.  jav a  2  s.c  om*/
        }

        Method setter = findSetter(clazz, fieldName, field.getType());
        if (setter != null) {
            testSetter(setter, field);
        }
    }
}

From source file:springfox.documentation.spring.web.readers.parameter.ModelAttributeParameterExpander.java

private Class<?> fieldType(AlternateTypeProvider alternateTypeProvider, Field field) {
    Class<?> type = field.getType();
    ResolvedType resolvedType = resolver.resolve(type);
    ResolvedType alternativeType = alternateTypeProvider.alternateFor(resolvedType);
    Class<?> erasedType = alternativeType.getErasedType();
    if (type != erasedType) {
        LOG.debug("Found alternative type [{}] for field: [{}-{}]", erasedType, field, type);
    }/*from  www .j a v  a 2  s.c  o m*/
    return erasedType;
}

From source file:com.CodeSeance.JSeance.CodeGenXML.XMLElements.Node.java

public void loadAttributes(Context context) {
    ContextManager contextManager = context.getManager();
    for (Field field : this.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(XMLAttribute.class)) {
            Class type = field.getType();

            String attributeName = field.getAnnotation(XMLAttribute.class).attributeName();
            if ("".equals(attributeName) || attributeName == null) {
                attributeName = field.getName();
            }//from w  w w.  ja  v  a 2 s. c  om

            String stringValue = element.getAttribute(attributeName);
            try {
                field.set(this, replaceJSAndConvert(contextManager, stringValue, type));
            } catch (IllegalAccessException ex) {
                // This is due to a programming error, member field should be public
                assert false : ex;
            }
        } else if (field.isAnnotationPresent(XMLTextContent.class)) {
            Class type = field.getType();
            try {
                field.set(this, replaceJSAndConvert(contextManager, element.getTextContent(), type));
            } catch (IllegalAccessException ex) {
                // This is due to a programming error, member field should be public
                assert false : ex;
            }
        }
    }
}

From source file:com.redhat.rcm.maven.plugin.buildmetadata.data.MetaDataProviderBuilder.java

private void setNonNullProperty(final MetaDataProvider instance, final String propertyName,
        final Object propertyValue, final Class<?> propertyType) throws MojoExecutionException {
    if (propertyValue != null) {
        final Class<? extends MetaDataProvider> metaDataProviderClass = instance.getClass();
        try {// ww w  . ja  va2s.c  o m
            final Field field = findField(metaDataProviderClass, propertyName);
            final Class<?> type = field.getType();
            if (type.isAssignableFrom(propertyType)) {
                field.setAccessible(true);
                field.set(instance, propertyValue);
            }
        } catch (final NoSuchFieldException e) {
            // OK, no such field, so we do not set it.
        } catch (final Exception e) {
            throw new MojoExecutionException("Cannot set property '" + propertyName
                    + "' for the instance of class '" + metaDataProviderClass.getName() + "'.", e);
        }
    }
}

From source file:com.google.gwt.dev.shell.mac.WebKitDispatchAdapter.java

public long getField(String member) {
    int dispId = getDispId(member);
    if (dispId < 0) {
        return BrowserShellMac.jsUndefined();
    }/*  w  w  w  .j  a  v a  2s  .c  om*/
    if (!javaDispatch.isField(dispId)) {
        return BrowserShellMac.jsUndefined();
    }
    Field field = javaDispatch.getField(dispId);
    JsValueSaf jsValue = new JsValueSaf();
    JsValueGlue.set(jsValue, classLoader, field.getType(), javaDispatch.getFieldValue(dispId));
    long jsval = jsValue.getJsValue();
    return jsval;
}

From source file:br.gov.frameworkdemoiselle.internal.implementation.ConfigurationEnumValueExtractor.java

@Override
public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception {
    String value = configuration.getString(prefix + key);

    if (value != null && !value.trim().equals("")) {
        Object enums[] = field.getType().getEnumConstants();

        for (int i = 0; i < enums.length; i++) {
            if (((Enum<?>) enums[i]).name().equals(value)) {
                return enums[i];
            }/* ww  w.  j  a  va  2 s  .c  o m*/
        }
    } else {
        return null;
    }

    throw new ConversionException(getBundle().getString("configuration-not-conversion", value,
            field.getDeclaringClass().getCanonicalName()));
}