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:net.mindengine.blogix.db.readers.ObjectReader.java

private void setEntryItselfIntoObject(Entry entry, T objectInstance)
        throws IllegalArgumentException, IllegalAccessException {
    Field entryField = getObjectFields().get("entry");
    if (entryField != null) {
        if (entryField.getType().equals(Entry.class)) {
            entryField.setAccessible(true);
            entryField.set(objectInstance, entry);
        }//from w w  w  . j  a  v  a  2 s .  co  m
    }
}

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

@Override
@SuppressWarnings("unchecked")
public Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception {
    Object value;/*from   www.  j  a va  2s  .  c om*/

    try {
        value = new DataConfiguration(configuration).get(ClassUtils.primitiveToWrapper(field.getType()),
                prefix + key);

    } catch (ConversionException cause) {
        throw cause;
    }

    return value;
}

From source file:org.excalibur.service.deployment.server.context.handler.CreateNodeManagerHandler.java

private void configure(NodeManager manager, ApplicationContext context) {
    Mirror mirror = new Mirror();

    for (Field field : manager.getClass().getDeclaredFields()) {
        if (field.isAnnotationPresent(Autowired.class)) {
            mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
        } else if (field.isAnnotationPresent(Resource.class)) {
            Resource resource = field.getAnnotation(Resource.class);
            if (!isNullOrEmpty(resource.name())) {
                mirror.on(manager).set().field(field).withValue(context.getBean(resource.name()));
            } else {
                mirror.on(manager).set().field(field).withValue(context.getBean(field.getType()));
            }// w w w  .  j  a v  a  2 s .c o  m
        }
    }
}

From source file:blue.lapis.pore.impl.event.PoreEventImplTest.java

@Test
public void checkHandleField() {
    try {//from   w  w  w  .  j a va2  s  .co  m
        Field field = eventImpl.getDeclaredField("handle");
        checkSpongeEvent(eventImpl, field.getType());
    } catch (NoSuchFieldException e) {
        fail(eventImpl.getSimpleName() + ": missing handle field");
    }
}

From source file:fr.cvlaminck.merging.impl.mergers.object.DefaultObjectMerger.java

@Override
public <T> T merge(T left, T right, ObjectMergingStrategy strategy) {
    if (!strategy.getObject().isAssignableFrom(left.getClass()))
        throw new RuntimeException("Left object class is not a subclass of the object of the strategy"); //TODO create proper exception
    if (!strategy.getObject().isAssignableFrom(right.getClass()))
        throw new RuntimeException("Right object class is not a subclass of the object of the strategy"); //TODO create proper exception
    try {/* w  ww. j  a va2s .c om*/
        for (Field field : getPublicFieldsWithGetterAndSetter(strategy.getObject())) {
            ValueMerger valueMerger = valueMergers.getMerger(field.getType(),
                    strategy.getStrategyForField(field.getName(), field.getType()));
            if (valueMerger == null)
                throw new RuntimeException(String.format("No value merger configured for field %s of type %s",
                        field.getName(), field.getType())); //TODO create proper exception
            Object mergedValue = valueMerger.merge(field.get(left), field.get(right));
            field.set(left, mergedValue);
        }
    } catch (IllegalAccessException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
    return left;
}

From source file:ro.pippo.spring.AnnotationFieldValueProvider.java

private String getBeanName(Field field, String name) {
    if ((name == null) || name.isEmpty()) {
        Class<?> fieldType = field.getType();
        // check cache
        name = beanNameCache.get(fieldType);
        if (name == null) {
            name = getBeanNameOfClass(fieldType);
            if (name != null) {
                String tmpName = beanNameCache.putIfAbsent(fieldType, name);
                if (tmpName != null) {
                    name = tmpName;//from  ww w  .j  a v  a  2 s. c o m
                }
            }
        }
    }

    return name;
}

From source file:com.cloudera.livy.client.common.TestHttpMessages.java

private void checkEquals(String name, Field f, Object o1, Object o2) throws Exception {
    Object v1 = f.get(o1);/*from   w ww.  ja va  2s  . co  m*/
    Object v2 = f.get(o2);

    boolean match;
    if (!f.getType().isArray()) {
        match = v1.equals(v2);
    } else if (v1 instanceof byte[]) {
        match = Arrays.equals((byte[]) v1, (byte[]) v2);
    } else {
        throw new IllegalArgumentException("FIX ME: " + f.getType().getSimpleName());
    }

    assertTrue(String.format("Field %s of %s does not match after deserialization.", f.getName(), name), match);
}

From source file:com.cfs.util.AESCriptografia.java

public void decifrarObjetoComKey(Object objeto, String key) {
    try {/*ww  w . j  a  v a 2  s  . c om*/
        Field[] campos = objeto.getClass().getDeclaredFields();
        //            System.out.println("DEPURATION MASTER: START !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        for (Field campo : campos) {
            campo.setAccessible(true);
            if (campo.getType().equals(String.class)) {
                if (campo.getName().equals("key")) {
                    campo.set(objeto, campo.get(objeto));
                } else {
                    if (campo.get(objeto) == null) {
                        campo.set(objeto, "null");
                        System.out.println("[SET-NULL] " + campo.getName() + " = " + campo.get(objeto));
                    } else {
                        campo.set(objeto, decifrar(String.valueOf(campo.get(objeto)), key));
                        //                            System.out.println("[SET] " + campo.getName() + " = " + campo.get(objeto));
                    }
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cfs.util.AESCriptografia.java

public void cifrarObjeto(Object objeto) {
    try {//from ww w. j  ava 2  s .  c o m
        String chave = null;
        Method[] metodos = objeto.getClass().getMethods();
        for (Method metodo : metodos) {
            if (metodo.getName().startsWith("getKey")) {
                chave = String.valueOf(metodo.invoke(objeto));
            }
        }

        Field[] campos = objeto.getClass().getDeclaredFields();
        for (Field campo : campos) {
            campo.setAccessible(true);
            if (campo.getType().equals(String.class)) {
                if (campo.getName().equals("key")) {
                    campo.set(objeto, campo.get(objeto));
                } else {
                    campo.set(objeto, cifrar(String.valueOf(campo.get(objeto)), chave));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.cfs.util.AESCriptografia.java

public void decifrarObjeto(Object objeto) {
    try {//w ww. j  a v a 2 s.com
        String chave = null;
        Method[] metodos = objeto.getClass().getMethods();
        for (Method metodo : metodos) {
            if (metodo.getName().startsWith("getKey")) {
                chave = String.valueOf(metodo.invoke(objeto));
            }
        }

        Field[] campos = objeto.getClass().getDeclaredFields();
        for (Field campo : campos) {
            campo.setAccessible(true);
            if (campo.getType().equals(String.class)) {
                if (campo.getName().equals("key")) {
                    campo.set(objeto, campo.get(objeto));
                } else {
                    campo.set(objeto, decifrar(String.valueOf(campo.get(objeto)), chave));
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}