List of usage examples for java.lang Object getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:Main.java
/** * Get the cookie of an asset using an undocumented API call that is marked * as "no to be used by applications" in its source code * /*from w w w .j a va 2 s .c o m*/ * @see <a href="http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/android/content/res/AssetManager.java#612">AssetManager.java#612</a> * @return the cookie */ private static int addAssets(final File APKFILE, final Object ASSETMANAGERINSTANCE) { try { Method addAssetPath = ASSETMANAGERINSTANCE.getClass().getMethod("addAssetPath", new Class[] { String.class }); return (Integer) addAssetPath.invoke(ASSETMANAGERINSTANCE, APKFILE.getAbsolutePath()); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return -1; }
From source file:Main.java
/** * Object to XML/* w ww.j a va2 s . c o m*/ * * @param object * @return */ public static String convertToXML(Object object) { try { System.out.println(mMap.containsKey(object.getClass()) + "---mmap-----"); if (!mMap.containsKey(object.getClass())) { JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass()); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // marshaller.setProperty(CharacterEscapeHandler.class.getName(), // new CharacterEscapeHandler() { // public void escape(char[] ac, int i, int j, boolean // flag,Writer writer) throws IOException { // writer.write( ac, i, j ); } // }); mMap.put(object.getClass(), marshaller); } System.out.println("----mmap--" + mMap.toString()); StringWriter stringWriter = new StringWriter(); mMap.get(object.getClass()).marshal(object, stringWriter); return stringWriter.getBuffer().toString(); } catch (JAXBException e) { e.printStackTrace(); } return null; }
From source file:io.wcm.caravan.commons.httpasyncclient.impl.HttpClientTestUtils.java
private static Object getField(Object object, String fieldName) { return getField(object, object.getClass(), fieldName); }
From source file:Main.java
public static Map<String, String> toMap(Object javaBean) { Map<String, String> result = new HashMap<String, String>(); Method[] methods = javaBean.getClass().getDeclaredMethods(); for (Method method : methods) { try {// w w w. ja v a2 s .com if (method.getName().startsWith("get")) { String field = method.getName(); field = field.substring(field.indexOf("get") + 3); field = field.toLowerCase().charAt(0) + field.substring(1); Object value = method.invoke(javaBean, (Object[]) null); if (value != null) { result.put(field, value.toString()); } } } catch (Exception e) { } } return result; }
From source file:Main.java
@SuppressWarnings("rawtypes") private static Object joinArrays(Object paramObject1, Object paramObject2) { Class localClass = paramObject1.getClass().getComponentType(); int i = Array.getLength(paramObject1); int j = i + Array.getLength(paramObject2); Object localObject = Array.newInstance(localClass, j); int k = 0;/* ww w. jav a 2 s. c om*/ while (k < i) { Array.set(localObject, k, Array.get(paramObject1, k)); k++; } while (k < j) { Array.set(localObject, k, Array.get(paramObject2, k - i)); k++; } return localObject; }
From source file:Main.java
public static Map toMap(Object javaBean) { Map result = new HashMap(); Method[] methods = javaBean.getClass().getDeclaredMethods(); for (Method method : methods) { try {/*from w w w. ja va 2 s . c o m*/ if (method.getName().startsWith("get")) { String field = method.getName(); field = field.substring(field.indexOf("get") + 3); field = field.toLowerCase().charAt(0) + field.substring(1); Object value = method.invoke(javaBean, (Object[]) null); result.put(field, null == value ? "" : value.toString()); } } catch (Exception e) { e.printStackTrace(); } } return result; }
From source file:cat.albirar.framework.dynabean.impl.DynaBeanFactoryUtils.java
/** * Extract a dynaBean from proxy or return directly if isn't proxy. * @param dynaBean The dynabean (proxified or not) <b>REQUIRED</b> * @return The {@link DynaBeanImpl} deproxified if needed * @throws IllegalArgumentException If the dynaBean is not of the class {@link DynaBeanImpl} *//*from www .ja v a2 s . c o m*/ public static DynaBeanImpl<?> deproxifyDynabean(Object dynaBean) { Object db; if (Proxy.isProxyClass(dynaBean.getClass())) { db = Proxy.getInvocationHandler(dynaBean); } else { db = dynaBean; } Assert.isTrue(DynaBeanImpl.class.isAssignableFrom(db.getClass()), "The dynaBean should to be a true dynaBean"); return (DynaBeanImpl<?>) db; }
From source file:com.sdl.odata.datasource.jpa.ODataProxyProcessor.java
/** * Checks if the given entity is @Entity based object. * * @param entity fieldType// www .j av a 2 s . c om * @return isEntityFlag */ private static boolean isJPAEntity(Object entity) { return entity != null && entity.getClass().getAnnotation(Entity.class) != null; }
From source file:Main.java
public static void actionBarSetDisplayHomeAsUpEnabled(Object actionBar, boolean arg) { if (actionBar == null) return;/* w ww . j a va2 s . c o m*/ try { Method m = actionBar.getClass().getMethod("setDisplayHomeAsUpEnabled", boolean.class); m.invoke(actionBar, arg); } catch (NoSuchMethodException ignore) { } catch (InvocationTargetException ignore) { } catch (IllegalAccessException ignore) { } }
From source file:Main.java
public static Map<String, Object> getProperties(Object bean) { Map<String, Object> map = new HashMap<String, Object>(); for (Method method : bean.getClass().getMethods()) { String name = method.getName(); if ((name.length() > 3 && name.startsWith("get") || name.length() > 2 && name.startsWith("is")) && Modifier.isPublic(method.getModifiers()) && method.getParameterTypes().length == 0 && method.getDeclaringClass() != Object.class) { int i = name.startsWith("get") ? 3 : 2; String key = name.substring(i, i + 1).toLowerCase() + name.substring(i + 1); try { map.put(key, method.invoke(bean, new Object[0])); } catch (Exception e) { }/*from www. j a va2 s.c o m*/ } } return map; }