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 with name attribute. If attribute does not exist or is null default * value is returned. The type T is checked to see if it is an instance of clazz. *//*from w w w . j a va 2 s. c om*/ @SuppressWarnings("unchecked") public static <T> T getAttributeValue(Mail mail, String attribute, T defaultValue, Class<?> clazz) { if (defaultValue != null && !ReflectionUtils.isInstanceOf(defaultValue.getClass(), clazz)) { throw new IllegalArgumentException("defaultValue is not an instance of " + clazz.toString()); } Object rawValue = mail.getAttribute(attribute); T value = null; if (rawValue != null) { if (!ReflectionUtils.isInstanceOf(rawValue.getClass(), clazz)) { throw new IllegalArgumentException("attribute is not an instance of " + clazz.toString()); } value = (T) rawValue; } if (value == null) { value = defaultValue; } return value; }
From source file:Main.java
private static String getTypeByClass(Class<?> type) throws Exception { if (type.equals(String.class)) { return "TEXT"; }//from w ww . ja v a 2 s.com if (type.equals(Long.class) || type.equals(Integer.class) || type.equals(long.class) || type.equals(Date.class)) { return "INTEGER"; } if (type.equals(Boolean.class)) { return "BOOLEAN"; } Exception exception = new Exception( CONVERSION_CLASS_NOT_FOUND_EXCEPTION.concat(" - Class: ").concat(type.toString())); throw exception; }
From source file:org.apache.hama.bsp.BSPTask.java
@SuppressWarnings("unchecked") private final static <KEYIN, VALUEIN, KEYOUT, VALUEOUT, M extends Writable> void runBSP(final BSPJob job, BSPPeerImpl<KEYIN, VALUEIN, KEYOUT, VALUEOUT, M> bspPeer, final BytesWritable rawSplit, final BSPPeerProtocol umbilical) throws Exception { Class<?> workClass = job.getConfiguration().getClass("bsp.work.class", BSP.class); BSP<KEYIN, VALUEIN, KEYOUT, VALUEOUT, M> bsp = (BSP<KEYIN, VALUEIN, KEYOUT, VALUEOUT, M>) ReflectionUtils .newInstance(workClass, job.getConfiguration()); LOG.debug("bsp.work.class: " + workClass.toString()); // The policy is to throw the first exception and log the remaining. Exception firstException = null; try {// w ww.ja v a 2 s.c o m bsp.setup(bspPeer); bsp.bsp(bspPeer); } catch (Exception e) { LOG.error("Error running bsp setup and bsp function.", e); firstException = e; } finally { try { bsp.cleanup(bspPeer); } catch (Exception e) { LOG.error("Error cleaning up after bsp executed.", e); if (firstException == null) firstException = e; } finally { try { bspPeer.close(); } catch (Exception e) { LOG.error("Error closing BSP Peer.", e); if (firstException == null) firstException = e; } if (firstException != null) throw firstException; } } }
From source file:org.pircbotx.TestUtils.java
public static String getRootName(Class aClass) { String name = aClass.getSimpleName(); if (StringUtils.endsWith(name, "Event")) return name.split("Event")[0]; else if (StringUtils.endsWith(name, "Listener")) return name.split("Listener")[0]; //Can't get anything, error out throw new IllegalArgumentException("Cannot get root of class name " + aClass.toString()); }
From source file:net.big_oh.common.jdbc.JdbcDriverProxy.java
private static final List<? extends JDBCEventListener> buildListenersListFromPropertiesFile() { Properties props = PropertyUtil.loadProperties(JdbcDriverProxy.class.getSimpleName().toLowerCase()); List<JDBCEventListener> listeners = new ArrayList<JDBCEventListener>(); String[] listenerClassNames = props.getProperty(JDBCEventListener.class.getSimpleName() + "s", "") .split(","); for (String listenerClassName : listenerClassNames) { if (!StringUtils.isBlank(listenerClassName)) { try { Class<?> listenerClass = Class.forName(listenerClassName); JDBCEventListener listener = (JDBCEventListener) listenerClass.newInstance(); listeners.add(listener); logger.info("Registered a new JDBC event listener: " + listenerClass.toString()); } catch (ClassNotFoundException cnfe) { logger.error("Failed to find a JDBC event listener class named '" + listenerClassName + "'", cnfe);/*from w ww . j a v a 2 s . c o m*/ } catch (InstantiationException e) { logger.error( "Failed to instantiate a JDBC event listener class named '" + listenerClassName + "'", e); } catch (IllegalAccessException e) { logger.error(e); } } } return listeners; }
From source file:com.alibaba.wasp.util.JVMClusterUtil.java
/** * Creates a {@link MasterThread}.//from w ww . ja v a 2 s. c o m * Call 'start' on the returned thread to make it run. * @param c Configuration to use. * @param hmc Class to create. * @param index Used distinguishing the object returned. * @throws java.io.IOException * @return Master added. */ public static JVMClusterUtil.MasterThread createMasterThread(final Configuration c, final Class<? extends FMaster> hmc, final int index) throws IOException { FMaster server; try { server = hmc.getConstructor(Configuration.class).newInstance(c); } 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.beetle.framework.util.ObjectUtil.java
public final static void populate(Object obj, Map<String, Object> map) { Set<?> s = map.entrySet(); Iterator<?> it = s.iterator(); while (it.hasNext()) { String key = ""; Object o = null;//www . ja va 2s .c o m @SuppressWarnings("rawtypes") Map.Entry me = (Map.Entry) it.next(); try { key = me.getKey().toString(); o = me.getValue(); if (o == null) { continue; } setValue(key, obj, o); } catch (IllegalArgumentException e) { Class<Object> type = ObjectUtil.getType(key, obj); String tstr = type.toString(); if (tstr.equals(Integer.class.toString())) { ObjectUtil.setValue(key, obj, Integer.valueOf(o.toString())); } else if (tstr.equals(Long.class.toString())) { ObjectUtil.setValue(key, obj, Long.valueOf(o.toString())); } else if (tstr.equals(Float.class.toString())) { ObjectUtil.setValue(key, obj, Float.valueOf(o.toString())); } else if (tstr.equals(Double.class.toString())) { ObjectUtil.setValue(key, obj, Double.valueOf(o.toString())); } else if (tstr.equals(Short.class.toString())) { ObjectUtil.setValue(key, obj, Short.valueOf(o.toString())); } else if (tstr.equals(Byte.class.toString())) { ObjectUtil.setValue(key, obj, Byte.valueOf(o.toString())); } else if (tstr.equals(Date.class.toString())) { if (o instanceof Date) { ObjectUtil.setValue(key, obj, (Date) o); } else { long time = ((Double) o).longValue(); ObjectUtil.setValue(key, obj, new Date(time)); } } else if (tstr.equals(java.sql.Timestamp.class.toString())) { if (o instanceof java.sql.Timestamp) { ObjectUtil.setValue(key, obj, (Date) o); } else { long time = ((Double) o).longValue(); ObjectUtil.setValue(key, obj, new java.sql.Timestamp(time)); } } else { throw e; } tstr = null; type = null; } } }
From source file:com.sonicle.webtop.core.app.util.ClassHelper.java
public static Class loadClass(String className, Class requiredParentClass, String targetDescription) { String tdesc = StringUtils.defaultIfBlank(targetDescription, "Target"); try {//from w w w . ja va 2s . com Class clazz = Class.forName(className); if (!requiredParentClass.isAssignableFrom(clazz)) throw new ClassCastException(); return clazz; } catch (ClassNotFoundException ex) { LOGGER.debug("{} class not found [{}]", tdesc, className); } catch (ClassCastException ex) { LOGGER.warn("A valid {} class must extends '{}' class", tdesc, requiredParentClass.toString()); } catch (Throwable t) { LOGGER.error("Unable to load class [{}]", className, t); } return null; }
From source file:io.fabric8.core.jmx.BeanUtils.java
public static List<String> getFields(Class clazz) { List<String> answer = new ArrayList<String>(); try {//w w w .j a v a 2s . c om for (PropertyDescriptor desc : PropertyUtils.getPropertyDescriptors(clazz)) { if (desc.getReadMethod() != null) { answer.add(desc.getName()); } } } catch (Exception e) { throw new FabricException("Failed to get property descriptors for " + clazz.toString(), e); } // few tweaks to maintain compatibility with existing views for now... if (clazz.getSimpleName().equals("Container")) { answer.add("parentId"); answer.add("versionId"); answer.add("profileIds"); answer.add("childrenIds"); answer.remove("fabricService"); } else if (clazz.getSimpleName().equals("Profile")) { answer.add("id"); answer.add("parentIds"); answer.add("childIds"); answer.add("containerCount"); answer.add("containers"); answer.add("fileConfigurations"); } else if (clazz.getSimpleName().equals("Version")) { answer.add("id"); answer.add("defaultVersion"); } return answer; }
From source file:com.qingstor.sdk.utils.QSJSONUtil.java
private static Object getParseValue(Class type, Object value) { if (String.class.equals(type)) { return value.toString(); } else if (Integer.class.equals(type) || "int".equals(type.toString())) { return Integer.parseInt(value.toString()); } else if (Double.class.equals(type) || "double".equals(type.toString())) { return Double.parseDouble(value.toString()); } else if (Long.class.equals(type) || "long".equals(type.toString())) { return Long.parseLong(value.toString()); } else if (Float.class.equals(type) || "float".equals(type.toString())) { return Float.parseFloat(value.toString()); }// w w w .j av a 2s . c o m return value; }