List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.autentia.common.util.ejb.JBossUtils.java
/** * Devuelve el nombre del ear en el que se encuentra la clase <code>clazz</code>. "" si no est en un ear. * <p>/*from w w w. j a v a 2 s.c om*/ * Este mtodo esta probado para JBoss 4.2.2GA. * * @param clazz clase que se est buscando. * @return el nombre del ear en el que se encuentra la clase <code>clazz</code>. "" si no est en un ear. */ public static String getEarName(Class<?> clazz) { String cn = File.separator + clazz.getCanonicalName(); cn = cn.replace('.', File.separatorChar); cn += ".class"; final URL url = Thread.currentThread().getContextClassLoader().getResource(cn); final String path = url.getPath(); if (log.isDebugEnabled()) { log.debug(clazz.getCanonicalName() + " is in path: " + path); } final int indexOfEar = path.indexOf(".ear"); final int indexOfExclamationChar = path.indexOf("!"); if (indexOfEar > -1 && indexOfExclamationChar > -1 && indexOfEar < indexOfExclamationChar) { // JBoss despliega los ear en un directorio temporal del estilo: .../tmp34545nombreDelEar.ear-contents/... int beginTempDir = path.lastIndexOf(File.separatorChar, indexOfEar); int i = beginTempDir; boolean reachedDigit = false; while (i < indexOfEar) { if (Character.isDigit(path.charAt(i))) { reachedDigit = true; } else if (reachedDigit) { break; } i++; } final String prefix = path.substring(i, indexOfEar) + File.separator; log.debug(clazz.getCanonicalName() + " is inside ear: " + prefix); return prefix; } log.debug(clazz.getCanonicalName() + " is not inside an ear."); return ""; }
From source file:me.hurel.hqlbuilder.internal.ProxyUtil.java
public static boolean ignoreClass(Class<?> objectClass) { return objectClass.getCanonicalName().startsWith("java."); }
From source file:gobblin.metrics.context.filter.ContextFilterFactory.java
/** * Modify the configuration to set the {@link ContextFilter} class. * @param config Input {@link Config}.//w w w.j a v a 2 s . c o m * @param klazz Class of desired {@link ContextFilter}. * @return Modified {@link Config}. */ public static Config setContextFilterClass(Config config, Class<? extends ContextFilter> klazz) { return config.withValue(CONTEXT_FILTER_CLASS, ConfigValueFactory.fromAnyRef(klazz.getCanonicalName())); }
From source file:org.rapidoid.json.JSON.java
public static String save(Object value) { Object ser = Beany.serialize(value); Class<?> cls = value != null ? value.getClass() : null; Map<String, Object> map = U.map("_", cls.getCanonicalName(), "v", ser); return jacksonStringify(map); }
From source file:com.denimgroup.threadfix.remote.response.ResponseParser.java
@SuppressWarnings("unchecked") // the JSON String preservation broke this public static <T> RestResponse<T> getRestResponse(String responseString, int responseCode, Class<T> internalClass) { LOGGER.debug("Parsing response for type " + internalClass.getCanonicalName()); RestResponse<T> response = new RestResponse<T>(); if (responseString != null && responseString.trim().indexOf('{') == 0) { try {/*w w w. ja va2 s . c o m*/ Gson gson = getGson(); response = gson.fromJson(responseString, getTypeReference()); // turn everything into an object String innerJson = gson.toJson(response.object); // turn the inner object back into a string if (response.object instanceof String) { // No need to do any more work response.object = (T) innerJson; LOGGER.debug("Parsed inner object as JSON String correctly."); } else { // turn the inner object into the correctly typed object response.object = gson.fromJson(innerJson, internalClass); LOGGER.debug("Parsed result into " + internalClass.getName() + " correctly."); } } catch (JsonSyntaxException e) { LOGGER.error("Encountered JsonSyntaxException", e); } } response.responseCode = responseCode; response.jsonString = responseString; LOGGER.debug("Setting response code to " + responseCode + "."); return response; }
From source file:com.wavemaker.tools.apidocs.tools.parser.util.MethodUtils.java
public static String getMethodUniqueIdentifierId(Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(); for (Class parameterType : parameterTypes) { hashCodeBuilder.append(parameterType.getCanonicalName()); }/*from w ww .ja va 2 s .c o m*/ return method.getName() + "-" + parameterTypes.length + "-" + hashCodeBuilder.toHashCode(); }
From source file:info.archinnov.achilles.internal.validation.Validator.java
public static void validateInstantiable(Class<?> arg) { validateNotNull(arg, "The class should not be null"); String canonicalName = arg.getCanonicalName(); try {/*from w w w . j a v a 2s . co m*/ instantiator.instantiate(arg); } catch (NoClassDefFoundError | InstantiationError e) { throw new AchillesBeanMappingException(format( "Cannot instantiate the class '%s'. Please ensure the class is not an abstract class, an interface, an array class, a primitive type, or void and have a nullary (default) constructor and is declared public", canonicalName)); } }
From source file:com.yahoo.elide.core.filter.FilterPredicate.java
/** * Build an HQL friendly alias for a class. * * @param type The type to alias//from www. j a v a2 s .c o m * @return type name alias that will likely not conflict with other types or with reserved keywords. */ public static String getTypeAlias(Class<?> type) { return type.getCanonicalName().replace(PERIOD, UNDERSCORE); }
From source file:com.adaptris.core.management.ManagementComponentFactory.java
private static List<String> paramTypes(Class[] params) { List<String> result = new ArrayList<>(); for (Class p : params) { if (p != null) { result.add(p.getCanonicalName()); }/* w ww . j a va 2 s.co m*/ } return result; }
From source file:com.carmanconsulting.cassidy.util.CassidyUtils.java
public static <T> T instantiate(Class<T> type) { try {/*from w w w. ja v a2s . co m*/ LOGGER.debug("Instantiating object of type {}...", type.getCanonicalName()); return Validate.notNull(type.newInstance()); } catch (InstantiationException e) { throw new CassidyException(String.format("Unable to instantiate object of type %s.", type.getName()), e); } catch (IllegalAccessException e) { throw new CassidyException( String.format("Type %s has no accessible default constructor.", type.getName()), e); } }