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 String obj2Xml(Object obj, String encoding) {
    String result = null;/* w w  w  .  jav  a  2 s.c om*/
    try {
        JAXBContext context = JAXBContext.newInstance(obj.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);
        StringWriter writer = new StringWriter();
        marshaller.marshal(obj, writer);
        result = writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

public static String marshal(Object object) throws Exception {
    StringWriter string = new StringWriter();
    JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE);
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); //$NON-NLS-1$
    marshaller.marshal(object, string);/*  w w w  .j av  a 2  s . c  o  m*/
    return string.toString();
}

From source file:com.dangdang.ddframe.job.lite.spring.util.AopTargetUtils.java

private static Object getProxyTargetObjectForCglibAndSpring4(final Object proxy) {
    Field h;/*from w  w  w. j  a  v a  2  s .c  o m*/
    try {
        h = proxy.getClass().getDeclaredField("CGLIB$CALLBACK_0");
        h.setAccessible(true);
        Object dynamicAdvisedInterceptor = h.get(proxy);
        Field advised = dynamicAdvisedInterceptor.getClass().getDeclaredField("advised");
        advised.setAccessible(true);
        return ((AdvisedSupport) advised.get(dynamicAdvisedInterceptor)).getTargetSource().getTarget();
        // CHECKSTYLE:OFF
    } catch (final Exception ex) {
        // CHECKSTYLE:ON
        throw new JobSystemException(ex);
    }
}

From source file:Main.java

public static String marshallToStringNoValidation(final Object xmlObject) throws JAXBException {
    StringWriter writer = new StringWriter();
    JAXBContext context = JAXBContext.newInstance(xmlObject.getClass());
    Marshaller jaxbMarshaller = context.createMarshaller();
    jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    jaxbMarshaller.marshal(xmlObject, writer);
    return writer.toString();
}

From source file:com.infullmobile.jenkins.plugin.restrictedregister.util.Utils.java

public static String getDescriptorDisplayName(Object object) {
    return String.format(Locale.US, DESCRIPTOR_NAME_FORMAT, object.getClass().getSimpleName());
}

From source file:de.interseroh.report.controller.ParameterFormFormatter.java

/**
 *
 * Checks if value is not null, is not an empty array
 *
 * @param value//from  ww  w.j  a v  a 2 s  .  c  o m
 * @return true if value contains a value
 */
public static boolean isNotNullOrEmptyArray(Object value) {
    return value != null //
            && (!value.getClass().isArray() || ((Object[]) value).length > 0);
}

From source file:de.fabianonline.telegram_backup.mediafilemanager.AbstractMediaFileManager.java

public static void throwUnexpectedObjectError(Object o) {
    throw new RuntimeException("Unexpected " + o.getClass().getName());
}

From source file:Main.java

public static void marshall(Object object, Result result, Marshaller.Listener listener) throws JAXBException {
    Marshaller marshaller = createMarshaller(object.getClass(), listener);
    marshaller.marshal(object, result);//from  w w w .  j  a v a 2  s  .c  om
}

From source file:Main.java

public static void marshall(Object object, Writer writer, Marshaller.Listener listener) throws JAXBException {
    Marshaller marshaller = createMarshaller(object.getClass(), listener);
    marshaller.marshal(object, writer);/*from www.  j a  va 2  s .c o m*/
}

From source file:Main.java

public static String convertToXml(Object obj, String encoding) {
    String result = null;//from   w w  w  . j a v a 2s.co  m
    try {
        JAXBContext context = JAXBContext.newInstance(obj.getClass());
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding);

        StringWriter writer = new StringWriter();
        marshaller.marshal(obj, writer);
        result = writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return result;
}