List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:com.dangdang.ddframe.job.spring.util.AopTargetUtils.java
private static Object getProxyTargetObjectForCglibAndSpring4(final Object proxy) { Field h;//from w w w. j av 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 JobException(ex); } }
From source file:annis.test.TestHelper.java
public static String[] springFiles(Object instance, String... contextFiles) { return springFiles(instance.getClass(), contextFiles); }
From source file:azkaban.utils.TestUtils.java
/** * Reads a resource into a String//w ww . j a v a 2 s .c om * * @param name Relative path to the resource (relative to the parent object's package) * @param parent Instance of the class to use in finding the resource. The resource is looked up in the same package * where the class of the parent object is in. * @return Resource content as a String * @throws IOException if an I/O error occurs */ public static String readResource(final String name, final Object parent) throws IOException { try (final InputStream is = parent.getClass().getResourceAsStream(name)) { return IOUtils.toString(is, Charsets.UTF_8).trim(); } }
From source file:com.trenako.web.infrastructure.SearchCriteriaUrlBuilder.java
private static String extractValue(Object obj) { String val; if (obj.getClass().equals(String.class)) { // don't use reflection for strings return obj.toString(); } else if (obj.getClass().isEnum()) { val = safeGetProperty(obj, "label"); } else if (obj.getClass().equals(LocalizedEnum.class)) { LocalizedEnum<?> le = (LocalizedEnum<?>) obj; val = le.getKey(); } else {//from www . j a v a2s. c om val = safeGetProperty(obj, "slug"); } return val; }
From source file:com.vanda.beivandalibnetwork.utils.CommonUtils.java
/** * ?/* www.j av a 2s. c o m*/ * @param clazz1 * @param clazz2 * @return */ public static boolean isAssignable(Object obj, Class<?> clazz) { return isAssignable(obj == null ? null : obj.getClass(), clazz); }
From source file:FieldModification.java
/** * Sets all int fields in an object to 0. * * @param obj The object to operate on./*from w ww . ja v a 2s . com*/ * * @throws RuntimeException If there is a reflection problem. */ public static void initPublicIntFields2(final Object obj) { try { final Integer value = new Integer(0); Field[] fields = obj.getClass().getFields(); for (int idx = 0; idx < fields.length; idx++) { if (fields[idx].getType() == int.class) { fields[idx].set(obj, value); } } } catch (final IllegalAccessException ex) { throw new RuntimeException(ex); } }
From source file:Main.java
public static void marshall(Object object, OutputStream os, Marshaller.Listener listener) throws JAXBException { Marshaller marshaller = createMarshaller(object.getClass(), listener); marshaller.marshal(object, os);/*from w w w . j ava2s. c om*/ }
From source file:nz.co.senanque.logging.HashIdLogger.java
public static void log(Object object, String id, BeanFactory beanFactory) { if (logger.isDebugEnabled()) { logger.debug("{}@{} {} {}", object.getClass(), System.identityHashCode(object), id, beanFactory); }/*from w ww . ja v a 2 s . c om*/ }
From source file:com.yahoo.elide.utils.coerce.CoerceUtil.java
/** * Convert value to target class.//from ww w. j a va 2 s .c o m * * @param value value to convert * @param cls class to convert to * @return coerced value */ public static Object coerce(Object value, Class<?> cls) { if (value == null || cls == null || cls.isAssignableFrom(value.getClass())) { return value; } try { return ConvertUtils.convert(value, cls); } catch (ConversionException | InvalidAttributeException | IllegalArgumentException e) { throw new InvalidValueException(value); } }
From source file:Main.java
public static void setMember(Object object, String memberName, Object value) throws IllegalAccessException, NoSuchFieldException { Field declaredField = getField(object.getClass(), memberName); declaredField.setAccessible(true);//from ww w .ja va2 s . co m declaredField.set(object, value); }