List of usage examples for java.lang Class toString
public String toString()
From source file:mitm.application.djigzo.james.MailAttributesUtils.java
/** * Returns the attribute value as a List of clazz. Null if the attribute does not exist *//*from w ww .ja v a 2 s.co m*/ @SuppressWarnings("unchecked") public static <T> List<T> getAttributeAsList(Mail mail, String attribute, Class<?> clazz) { Object rawValue = mail.getAttribute(attribute); List<T> result = null; if (rawValue != null) { if (rawValue instanceof Collection) { for (Object o : (Collection<?>) rawValue) { if (o != null && !ReflectionUtils.isInstanceOf(o.getClass(), clazz)) { throw new IllegalArgumentException("attribute is not an instance of " + clazz.toString()); } } result = new ArrayList<T>((Collection<T>) rawValue); } else if (rawValue.getClass().isArray()) { Object[] array = (Object[]) rawValue; result = new ArrayList<T>(array.length); for (Object o : array) { if (o != null && !ReflectionUtils.isInstanceOf(o.getClass(), clazz)) { throw new IllegalArgumentException("attribute is not an instance of " + clazz.toString()); } result.add((T) o); } } else { if (!ReflectionUtils.isInstanceOf(rawValue.getClass(), clazz)) { throw new IllegalArgumentException("attribute is not an instance of " + clazz.toString()); } result = new ArrayList<T>(1); result.add((T) rawValue); } } return result; }
From source file:org.apache.hadoop.hbase.util.JVMClusterUtil.java
/** * Creates a {@link MasterThread}.//from w w w .j a va2 s . c o m * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param cp consensus provider to use * @param hmc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Master added. */ public static JVMClusterUtil.MasterThread createMasterThread(final Configuration c, CoordinatedStateManager cp, final Class<? extends HMaster> hmc, final int index) throws IOException { HMaster server; try { server = hmc.getConstructor(Configuration.class, CoordinatedStateManager.class).newInstance(c, cp); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of Master: " + hmc.toString() + ((target.getCause() != null) ? target.getCause().getMessage() : ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.MasterThread(server, index); }
From source file:com.alibaba.wasp.util.JVMClusterUtil.java
/** * Creates a {@link FServerThread}./*www . j a va2 s. c o m*/ * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param hrsc Class to create. * @param index Used distinguishing the object returned. * @throws java.io.IOException * @return FServer added. */ public static JVMClusterUtil.FServerThread createFServerThread(final Configuration c, final Class<? extends FServer> hrsc, final int index) throws IOException { FServer server; try { Constructor<? extends FServer> ctor = hrsc.getConstructor(Configuration.class); ctor.setAccessible(true); server = ctor.newInstance(c); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of FServer: " + hrsc.toString() + ((target.getCause() != null) ? target.getCause().getMessage() : ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.FServerThread(server, index); }
From source file:org.jgentleframework.utils.Utils.java
/** * Creates the scope name./*w w w. j a v a 2 s . c o m*/ * * @param type * the type * @param targetClass * the target class * @param definition * the definition * @param mappingName * the mapping name * @return the string */ public static String createScopeName(Class<?> type, Class<?> targetClass, Definition definition, String mappingName) { Assertor.notNull(type); Assertor.notNull(targetClass); Assertor.notNull(definition); String scopeName = type.toString() + ":" + targetClass.toString() + ":" + definition.toString(); if (mappingName != null && !mappingName.isEmpty()) { scopeName = scopeName + ":" + mappingName; } return scopeName; // StringBuffer buffer = new StringBuffer(); // buffer.append(type.toString()); // buffer.append(":"); // buffer.append(targetClass.toString()); // buffer.append(":"); // buffer.append(definition.toString()); // if (mappingName != null && !mappingName.isEmpty()) { // buffer.append(":"); // buffer.append(mappingName); // } // return buffer.toString(); }
From source file:password.pwm.util.LocaleHelper.java
private static ResourceBundle getMessageBundle(final Locale locale, final Class bundleClass) { if (!PwmDisplayBundle.class.isAssignableFrom(bundleClass)) { LOGGER.warn(/*from w ww . j ava2 s. c o m*/ "attempt to resolve locale for non-DisplayBundleMarker class type " + bundleClass.toString()); return null; } final ResourceBundle messagesBundle; if (locale == null) { messagesBundle = ResourceBundle.getBundle(bundleClass.getName()); } else { messagesBundle = ResourceBundle.getBundle(bundleClass.getName(), locale); } return messagesBundle; }
From source file:net.minecraftforge.registries.GameData.java
public static <V extends IForgeRegistryEntry<V>> RegistryNamespacedDefaultedByKey<ResourceLocation, V> getWrapperDefaulted( Class<V> cls) { IForgeRegistry<V> reg = GameRegistry.findRegistry(cls); Validate.notNull(reg, "Attempted to get vanilla wrapper for unknown registry: " + cls.toString()); @SuppressWarnings("unchecked") RegistryNamespacedDefaultedByKey<ResourceLocation, V> ret = reg .getSlaveMap(NamespacedDefaultedWrapper.Factory.ID, NamespacedDefaultedWrapper.class); Validate.notNull(reg,// w w w . j a v a 2s . c o m "Attempted to get vanilla wrapper for registry created incorrectly: " + cls.toString()); return ret; }
From source file:net.minecraftforge.registries.GameData.java
public static <V extends IForgeRegistryEntry<V>> RegistryNamespaced<ResourceLocation, V> getWrapper( Class<V> cls) { IForgeRegistry<V> reg = GameRegistry.findRegistry(cls); Validate.notNull(reg, "Attempted to get vanilla wrapper for unknown registry: " + cls.toString()); @SuppressWarnings("unchecked") RegistryNamespaced<ResourceLocation, V> ret = reg.getSlaveMap(NamespacedWrapper.Factory.ID, NamespacedWrapper.class); Validate.notNull(reg,/*from www .jav a 2s . com*/ "Attempted to get vanilla wrapper for registry created incorrectly: " + cls.toString()); return ret; }
From source file:org.jgentleframework.context.JGentle.java
/** * Removes a given configurable class from registered list. * /*from w w w.j av a 2s . c om*/ * @param interfaze * the interface type of configurable class. * @return returns the removed configigurabke class if it existed, otherwise * returns null. */ @SuppressWarnings("unchecked") public static <T> T removeConfigClass(Class<T> interfaze) { Assertor.notNull(interfaze); if (!interfaze.isInterface()) { throw new JGentleRuntimeException(interfaze.toString() + " must be a interface."); } return (T) JGentle.configObjClassList.remove(interfaze); }
From source file:com.browseengine.bobo.serialize.JSONSerializer.java
public static JSONSerializable deSerialize(Class clz, JSONObject jsonObj) throws JSONSerializationException, JSONException { Iterator iter = jsonObj.keys(); if (!JSONSerializable.class.isAssignableFrom(clz)) { throw new JSONSerializationException(clz + " is not an instance of " + JSONSerializable.class); }// w w w . ja va 2 s . co m JSONSerializable retObj; try { retObj = (JSONSerializable) clz.newInstance(); } catch (Exception e1) { throw new JSONSerializationException( "trouble with no-arg instantiation of " + clz.toString() + ": " + e1.getMessage(), e1); } if (JSONExternalizable.class.isAssignableFrom(clz)) { ((JSONExternalizable) retObj).fromJSON(jsonObj); return retObj; } while (iter.hasNext()) { String key = (String) iter.next(); try { Field f = clz.getDeclaredField(key); if (f != null) { f.setAccessible(true); Class type = f.getType(); if (type.isArray()) { JSONArray array = jsonObj.getJSONArray(key); int len = array.length(); Class cls = type.getComponentType(); Object newArray = Array.newInstance(cls, len); for (int k = 0; k < len; ++k) { loadObject(newArray, cls, k, array); } f.set(retObj, newArray); } else { loadObject(retObj, f, jsonObj); } } } catch (Exception e) { throw new JSONSerializationException(e.getMessage(), e); } } return retObj; }
From source file:org.apache.hadoop.hbase.util.JVMClusterUtil.java
/** * Creates a {@link RegionServerThread}. * Call 'start' on the returned thread to make it run. * @param c Configuration to use.// w w w . j a v a 2 s .c o m * @param cp consensus provider to use * @param hrsc Class to create. * @param index Used distinguishing the object returned. * @throws IOException * @return Region server added. */ public static JVMClusterUtil.RegionServerThread createRegionServerThread(final Configuration c, CoordinatedStateManager cp, final Class<? extends HRegionServer> hrsc, final int index) throws IOException { HRegionServer server; try { Constructor<? extends HRegionServer> ctor = hrsc.getConstructor(Configuration.class, CoordinatedStateManager.class); ctor.setAccessible(true); server = ctor.newInstance(c, cp); } catch (InvocationTargetException ite) { Throwable target = ite.getTargetException(); throw new RuntimeException("Failed construction of RegionServer: " + hrsc.toString() + ((target.getCause() != null) ? target.getCause().getMessage() : ""), target); } catch (Exception e) { IOException ioe = new IOException(); ioe.initCause(e); throw ioe; } return new JVMClusterUtil.RegionServerThread(server, index); }