Example usage for java.lang Object getClass

List of usage examples for java.lang Object getClass

Introduction

In this page you can find the example usage for java.lang Object getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java

/**
 * Check if the object is a {@link DynaBeanImpl} or a Proxy with a {@link DynaBeanImpl} as a {@link Proxy#getInvocationHandler(Object) invocation handler}.
 * @param object The object (or proxy)/*from w  ww  .  j  a  va  2 s  . co m*/
 * @return true if the object is a {@link DynaBeanImpl} instance or a {@link Proxy} with a {@link DynaBeanImpl} as an invocation handler. Return false otherwise ever if object is null 
 */
public static boolean checkDynaBean(Object object) {
    if (object != null) {
        return ((Proxy.isProxyClass(object.getClass())
                && DynaBeanImpl.class.isAssignableFrom(Proxy.getInvocationHandler(object).getClass()))
                || DynaBeanImpl.class.isAssignableFrom(object.getClass()));
    }
    return false;
}

From source file:net.projectmonkey.spring.acl.util.reflect.MethodUtil.java

public static Method getMethod(final Object domainObject, final String internalMethod,
        final Class<?>... argTypes) {
    return getMethod(domainObject.getClass(), internalMethod, argTypes);
}

From source file:net.datenwerke.transloader.primitive.WrapperConverter.java

private static char getTypeCode(Object wrapper) {
    Class primitiveType = ClassUtils.wrapperToPrimitive(wrapper.getClass());
    ObjectStreamField typeCodeProvider = new ObjectStreamField(IRRELEVANT, primitiveType);
    return typeCodeProvider.getTypeCode();
}

From source file:Main.java

public static <T> T getView(Object object, Class<T> t) {

    try {//from   w  ww.  j a  v  a  2s. c o m
        return (T) object;
    } catch (ClassCastException e) {

        throw new IllegalStateException(object.getClass().getSimpleName() + t.getSimpleName()
                + " does not implement contract interface", e);
    }
}

From source file:Main.java

public static Map<String, Object> optPublicFieldKeyValueMap(Object obj) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (obj != null) {
        Field[] fields = obj.getClass().getFields();
        for (Field f : fields) {
            try {
                boolean isStatic = Modifier.isStatic(f.getModifiers());
                if (!isStatic) {
                    Object value = f.get(obj);
                    if (value != null)
                        map.put(f.getName(), value);
                }/*from www  .jav a2  s . c  o  m*/
            } catch (Exception e) {

            }
        }
    }
    return map;
}

From source file:gov.nih.nci.cabig.ctms.web.taglibs.Functions.java

public static String classname(Object o) {
    return o == null ? null : o.getClass().getName();
}

From source file:Main.java

private static void recreateGB(Activity activity) throws IllegalArgumentException, IllegalAccessException,
        NoSuchMethodException, InvocationTargetException {
    Field Activity$mToken = scanField(Activity.class, "mToken");
    IBinder mToken = (IBinder) Activity$mToken.get(activity);
    Field Activity$mMainThread = scanField(Activity.class, "mMainThread");
    Object mMainThread = Activity$mMainThread.get(activity);
    Field ActivityThread$mAppThread = scanField(mMainThread.getClass(), "mAppThread");
    Object mAppThread = ActivityThread$mAppThread.get(mMainThread);
    // @formatter:off
    Method method = mAppThread.getClass().getMethod("scheduleRelaunchActivity", IBinder.class, List.class,
            List.class, int.class, boolean.class, Configuration.class);
    // @formatter:on
    method.invoke(mAppThread, mToken, null, null, 0, false, null);
}

From source file:Main.java

public static Method findMethod(Object target, List<String> possible_names, Class<?>... parameter_types) {
    if (target == null)
        return null;
    return findMethod(target.getClass(), possible_names, parameter_types);
}

From source file:com.astamuse.asta4d.web.form.flow.base.StepAwaredValidationFormHelper.java

static final Object getValidationTargetByAnnotation(Object form, String step) {
    String cacheKey = step + "@" + form.getClass().getName();
    Optional<Field> oField = ValidationTargetFieldCache.get(cacheKey);

    if (oField == null) {
        List<Field> list = new ArrayList<>(ClassUtil.retrieveAllFieldsIncludeAllSuperClasses(form.getClass()));
        Iterator<Field> it = list.iterator();
        while (it.hasNext()) {
            Field f = it.next();/*from  ww  w. j a  v  a2 s .c  o  m*/
            StepAwaredValidationTarget vtAnno = f.getAnnotation(StepAwaredValidationTarget.class);
            if (vtAnno == null) {
                continue;
            }
            String representingStep = vtAnno.value();
            if (step.equals(representingStep)) {
                oField = Optional.of(f);
                break;
            }
        }
        if (oField == null) {
            oField = Optional.empty();
        }
        if (Configuration.getConfiguration().isCacheEnable()) {
            Map<String, Optional<Field>> newCache = new HashMap<>(ValidationTargetFieldCache);
            newCache.put(cacheKey, oField);
            ValidationTargetFieldCache = newCache;
        }
    }

    if (oField.isPresent()) {
        try {
            return FieldUtils.readField(oField.get(), form, true);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    } else {
        return form;
    }
}

From source file:Main.java

/**
 * this method is responsible for converting any pojo to respective xml form
 * /*from  w  ww.  j a  va 2 s  .co  m*/
 * @param object
 * @param filePath
 * @throws JAXBException
 * @throws IOException
 */
public static File pojoToXml(Object object, String filePath) throws JAXBException, IOException {

    JAXBContext context = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    OutputStream os = new FileOutputStream(filePath);
    marshaller.marshal(object, os);
    File file = new File(filePath);
    return file;
}