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:Main.java

public static void serialize(Object o, OutputStream os, Boolean format) throws JAXBException {
    String pkg = o.getClass().getPackage().getName();
    JAXBContext jc = getCachedContext(pkg);
    Marshaller m = jc.createMarshaller();
    m.setEventHandler(new DefaultValidationEventHandler());
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, format);
    m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    m.marshal(o, os);//w  w  w  . ja  va2s  .co m
}

From source file:Main.java

public static Object tryInvoke(Object target, String methodName, Class<?>[] argTypes, Object... args) {
    try {/*from   www .ja  va 2 s . c  o m*/
        return target.getClass().getMethod(methodName, argTypes).invoke(target, args);
    } catch (NoSuchMethodException ignored) {
    } catch (IllegalAccessException ignored) {
    } catch (InvocationTargetException ignored) {
    }

    return null;
}

From source file:Main.java

public static void printExtras(Intent i) {
    if (i == null) {
        return;// www .  ja  va 2  s.  c o m
    }
    Bundle bundle = i.getExtras();
    if (bundle == null) {
        return;
    }
    Log.d("INTENT_EXTRAS", "++++ Printing extras: +++");
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        Log.d("INTENT_EXTRAS", String.format("%s %s (%s)", key, value.toString(), value.getClass().getName()));
    }
}

From source file:annis.test.TestHelper.java

private static String packagePath(Object instance) {
    return packagePath(instance.getClass());
}

From source file:ch.citux.td.util.Log.java

public static void d(Object caller, String message) {
    String tag = caller.getClass().getSimpleName();
    if (!StringUtils.isBlank(message)) {
        android.util.Log.d(tag, message);
    }//from  w  w w  .  j  a v a2s . com
}

From source file:ch.citux.td.util.Log.java

public static void v(Object caller, String message) {
    String tag = caller.getClass().getSimpleName();
    if (!StringUtils.isBlank(message)) {
        android.util.Log.v(tag, message);
    }/*from  ww w .  jav a  2s  .co  m*/
}

From source file:ch.citux.td.util.Log.java

public static void e(Object caller, String message) {
    String tag = caller.getClass().getSimpleName();
    if (!StringUtils.isBlank(message)) {
        android.util.Log.e(tag, message);
    }/*from w  w  w . j av  a2s . c  om*/
}

From source file:com.softfeeder.rules.core.Utils.java

/**
 * /*from ww  w .j a va  2 s  .  co  m*/
 * @param context
 * @param target
 */
public static void fieldsInjection(RuleContext context, Object target) {
    if (context != null) {
        for (Field field : target.getClass().getDeclaredFields()) {
            if (field.isAnnotationPresent(Inject.class)) {
                try {
                    BeanUtils.setProperty(target, field.getName(), context.getValue(field.getName()));
                } catch (InvocationTargetException | IllegalAccessException ex) {
                    LOG.info(String.format("Invalid field injection %s", ex.getMessage()));
                }
            }
        }
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <E> E[] arrayOf(Class<E> elementClass, Object arrayOrElement) {
    if (arrayOrElement == null) {
        return null;
    }/*from   ww w .  java2s  . c om*/
    if (arrayOrElement.getClass().isArray()) {
        return (E[]) arrayOrElement;
    }
    Object result = Array.newInstance(elementClass, 1);
    Array.set(result, 0, arrayOrElement);
    return (E[]) result;
}

From source file:Main.java

/**
 * //ww  w  .  j  a v  a 2 s .c  o m
 * @param object
 * @return
 * @throws JAXBException
 */
public static String pojoToXml(Object object) throws JAXBException {

    JAXBContext context = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    // marshaller.setProperty(Marshaller.JAXB_ENCODING, "U");
    StringWriter writer = new StringWriter();
    marshaller.marshal(object, writer);
    String xmlData = writer.toString();
    return xmlData;
}