List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.gohuinuo.common.utils.Collections3.java
/** * map?bean/*from w w w.j a v a 2s .c om*/ * * @param map * @param beanClass * @return */ public static Object map2Bean(Map map, Class<?> beanClass) { try { Object bean = beanClass.newInstance(); PropertyUtils.copyProperties(bean, map); return bean; } catch (Exception e) { throw new RuntimeException(beanClass.getCanonicalName() + "!"); } }
From source file:atg.tools.dynunit.util.ComponentUtil.java
/** * Creates a new component properties file in {@code parent} named {@code name} using the class {@code klass} and * configured with the given {@code properties}. * * @param parent//from ww w .j a v a 2s .co m * Directory to place the new component properties file. * @param name * Name of component to create. Determines the file name. * @param klass * Class of component to create. * @param properties * Any properties to set in the component properties file. * * @return Newly created (or recreated) component properties file. * * @throws IOException * if the properties file couldn't be written to. */ public static File newComponent(final File parent, final String name, final Class<?> klass, final Properties properties) throws IOException { logger.entry(parent, name, klass, properties); final File output = newComponent(parent, name, klass.getCanonicalName(), properties); return logger.exit(output); }
From source file:com.swordlord.gozer.builder.Parser.java
/** * Retrieve a Class/*from w ww .ja v a2 s . c om*/ * * @param pckgname * @param skipDollarClasses * @return the class */ public static Class<?>[] getClasses(String pckgname, boolean skipDollarClasses) { ArrayList<Class<?>> classes = new ArrayList<Class<?>>(); try { File directory = getClassesHelper(pckgname); if (directory.exists()) { // Get the list of the files contained in the package String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in .class files if (files[i].endsWith(".class")) { // get rid of the ".class" at the end String withoutclass = pckgname + '.' + files[i].substring(0, files[i].length() - 6); // in case we don't want $1 $2 etc. endings (i.e. common // in GUI classes) if (skipDollarClasses) { int dollar_occurence = withoutclass.indexOf("$"); if (dollar_occurence != -1) { withoutclass = withoutclass.substring(0, dollar_occurence); } } // add this class to our list but avoid duplicates boolean already_contained = false; for (Class<?> c : classes) { if (c.getCanonicalName().equals(withoutclass)) { already_contained = true; } } if (!already_contained) { classes.add(Class.forName(withoutclass)); } // REMARK this kind of checking is quite slow using // reflection, it would be better // to do the class.forName(...) stuff outside of this // method and change the method // to only return an ArrayList with fqcn Strings. Also // in reality we have the $1 $2 // etc. classes in our packages, so we are skipping some // "real" classes here } } } else { throw new ClassNotFoundException(pckgname + " does not appear to be a valid package"); } } catch (ClassNotFoundException e) { e.printStackTrace(); } Class<?>[] classesA = new Class[classes.size()]; classes.toArray(classesA); return classesA; }
From source file:com.alta189.bukkit.script.event.EventScanner.java
public static void scanBukkit() { Reflections reflections = new Reflections(new ConfigurationBuilder() .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.bukkit"))) .setUrls(ClasspathHelper.forClassLoader(ClasspathHelper.contextClassLoader(), ClasspathHelper.staticClassLoader()))); Set<Class<? extends Event>> classes = reflections.getSubTypesOf(Event.class); BScript plugin = BScript.getInstance(); plugin.info(// w ww .j av a 2 s . c o m "Found " + classes.size() + " classes extending " + Event.class.getCanonicalName() + " in Bukkit"); for (Class<? extends Event> clazz : classes) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { continue; } bukkitEvent.put(clazz.getSimpleName(), clazz); String className = clazz.getCanonicalName(); if (className == null) { className = clazz.getName(); } events.put(className, clazz); simpleNameEvents.put(clazz.getSimpleName(), clazz); plugin.debug(className); } }
From source file:hu.bme.mit.sette.common.model.runner.ParameterType.java
public static ParameterType primitiveFromJavaClass(Class<?> javaClass) { Validate.notNull(javaClass, "The Java class must not be null"); Validate.isTrue(ClassUtils.isPrimitiveOrWrapper(javaClass), "The represented type is not primitive [javaClass: %s]", javaClass.getName()); Class<?> primitiveClass; if (javaClass.isPrimitive()) { primitiveClass = javaClass;// ww w . ja va 2 s . c o m } else { primitiveClass = ClassUtils.wrapperToPrimitive(javaClass); } Validate.isTrue(primitiveClass != void.class, "the parameter type must not be void [javaClass: %s]", javaClass.getName()); return fromString(primitiveClass.getCanonicalName()); }
From source file:de.itsvs.cwtrpc.security.DefaultRpcAuthenticationFailureHandler.java
public static Expression createExceptionExpression(Class<? extends Exception> exceptionClass, boolean includeMessage) { final StringBuilder expressionString; final ExpressionParser parser; final Expression expression; expressionString = new StringBuilder(); expressionString.append("new "); expressionString.append(exceptionClass.getCanonicalName()); expressionString.append('('); if (includeMessage) { expressionString.append("message"); }//from w w w . j a va 2 s . c o m expressionString.append(')'); parser = new SpelExpressionParser(); expression = parser.parseExpression(expressionString.toString()); return expression; }
From source file:org.web4thejob.util.CoreUtil.java
public static String describeClass(Class<?> clazz) { List<String> classes = new ArrayList<String>(); classes.add(clazz.getCanonicalName()); for (Class<?> cls : ClassUtils.getAllInterfacesForClassAsSet(clazz)) { classes.add(cls.getCanonicalName()); }//from www .java 2 s. c o m return StringUtils.collectionToDelimitedString(classes, ", "); }
From source file:io.milton.common.FileUtils.java
public static String readResource(Class cl, String res) throws IOException { InputStream in = cl.getResourceAsStream(res); if (in == null) { throw new IOException( "Failed to read resource: " + res + " relative to class: " + cl.getCanonicalName()); }//from w ww.j a v a2s . co m ByteArrayOutputStream out = readIn(in); return out.toString(); }
From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java
private static void validateEclipseCsMetaXmlFile(File file, String pkg, Set<Class<?>> pkgModules) throws Exception { Assert.assertTrue("'checkstyle-metadata.xml' must exist in eclipsecs in inside " + pkg, file.exists()); final String input = new String(Files.readAllBytes(file.toPath()), UTF_8); final Document document = XmlUtil.getRawXml(file.getAbsolutePath(), input, input); final NodeList ruleGroups = document.getElementsByTagName("rule-group-metadata"); Assert.assertTrue(pkg + " checkstyle-metadata.xml must contain only one rule group", ruleGroups.getLength() == 1); for (int position = 0; position < ruleGroups.getLength(); position++) { final Node ruleGroup = ruleGroups.item(position); final Set<Node> children = XmlUtil.getChildrenElements(ruleGroup); validateEclipseCsMetaXmlFileRules(pkg, pkgModules, children); }// w ww. j a va 2 s .co m for (Class<?> module : pkgModules) { Assert.fail("Module not found in " + pkg + " checkstyle-metadata.xml: " + module.getCanonicalName()); } }
From source file:at.jku.rdfstats.hist.builder.HistogramBuilderFactory.java
/** unregister a histogram builder * //from w ww . ja v a 2 s . com * @param uri */ public static void unregister(String uri) { Class<? extends HistogramBuilder<?>> clazz = registeredBuilders.get(uri); if (clazz == null) log.warn("No histogram builder for data type URI <" + uri + "> registered, unregistration request ignored."); else { classHashtable.remove(clazz.getCanonicalName().hashCode()); registeredBuilders.remove(uri); } }