List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:com.spotify.heroic.shell.Tasks.java
public static String taskUsage(final Class<? extends ShellTask> task) { final TaskUsage u = task.getAnnotation(TaskUsage.class); if (u != null) { return u.value(); }//from ww w . j av a 2s . co m return String.format("<no @ShellTaskUsage annotation for %s>", task.getCanonicalName()); }
From source file:com.hurence.logisland.documentation.DocGenerator.java
/** * Generates the documentation for a particular configurable component. Will * check to see if an "additionalDetails.html" file exists and will link * that from the generated documentation. * * @param docsDir the work\docs\components dir to stick component * documentation in * @param componentClass the class to document * @throws InstantiationException ie/*from www. j a va 2 s.c o m*/ * @throws IllegalAccessException iae * @throws IOException ioe */ private static void document(final File docsDir, final Class<? extends ConfigurableComponent> componentClass, final String writerType) throws InstantiationException, IllegalAccessException, IOException, InitializationException, ClassNotFoundException { logger.info("Documenting: " + componentClass); final ConfigurableComponent component = PluginProxy .unwrap(PluginLoader.loadPlugin(componentClass.getCanonicalName())); final ConfigurableComponentInitializer initializer = getComponentInitializer(componentClass); initializer.initialize(component); final DocumentationWriter writer = getDocumentWriter(componentClass, writerType); final File baseDocumenationFile = new File(docsDir, OUTPUT_FILE + "." + writerType); try (final OutputStream output = new BufferedOutputStream( new FileOutputStream(baseDocumenationFile, true))) { writer.write(component, output); } catch (Exception e) { logger.error("Error occurred documenting " + componentClass, e); } finally { initializer.teardown(component); if (writerType.equals("json")) { try (final PrintWriter commaWriter = new PrintWriter( new FileOutputStream(baseDocumenationFile, true))) { commaWriter.println(","); } } } }
From source file:Main.java
public static <T extends BroadcastReceiver> void scheduleUpdate(Context context, Class<T> clazz) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(context, clazz); PendingIntent sender = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); Random random = new Random(System.currentTimeMillis()); long offset = random.nextLong() % (12 * 60 * 60 * 1000); long interval = (24 * 60 * 60 * 1000) + offset; String prefKey = "pref_scheduled_monitor_config_update_" + clazz.getCanonicalName(); long scheduledTime = preferences.getLong(prefKey, -1); if (scheduledTime == -1) { context.sendBroadcast(intent);/*from w ww . j a v a2 s .co m*/ } if (scheduledTime <= System.currentTimeMillis()) { context.sendBroadcast(intent); scheduledTime = System.currentTimeMillis() + interval; preferences.edit().putLong(prefKey, scheduledTime).commit(); Log.w("PeriodicActionUtils", "Scheduling for all new time: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } else { Log.w("PeriodicActionUtils", "Scheduling for time found in preferences: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); } am.cancel(sender); am.set(AlarmManager.RTC_WAKEUP, scheduledTime, sender); Log.w("PeriodicActionUtils", "Scheduled for: " + scheduledTime + " (" + clazz.getSimpleName() + ")"); }
From source file:me.st28.flexseries.flexcore.plugin.FlexPlugin.java
/** * Retrieves a registered {@link FlexModule} from any loaded {@link FlexPlugin}. * * @param clazz The class of the module. * @return The module matching the class. * @throws java.lang.IllegalArgumentException Thrown if there is no registered module matching the given class. *///from ww w.j a v a 2s . c om public static <T extends FlexModule> T getRegisteredModule(Class<T> clazz) { Validate.notNull(clazz, "Module class cannot be null."); if (!REGISTERED_MODULES.containsKey(clazz)) { throw new IllegalArgumentException( "No module with class '" + clazz.getCanonicalName() + "' is registered."); } FlexPlugin plugin = REGISTERED_MODULES.get(clazz); if (plugin.getModuleStatus(clazz) != ModuleStatus.ENABLED) { throw new ModuleDisabledException(plugin.getModule(clazz)); } return plugin.getModule(clazz); }
From source file:com.eucalyptus.entities.PersistenceContexts.java
public static boolean isEntityClass(Class candidate) { if (Ats.from(candidate).has(javax.persistence.Entity.class) && Ats.from(candidate).has(org.hibernate.annotations.Entity.class)) { if (!Ats.from(candidate).has(PersistenceContext.class)) { throw Exceptions .toUndeclared("Database entity does not have required @PersistenceContext annotation: " + candidate.getCanonicalName()); } else {//from w w w .j av a 2s .co m return true; } } else if (Ats.from(candidate).has(javax.persistence.Entity.class) && !Ats.from(candidate).has(org.hibernate.annotations.Entity.class)) { throw Exceptions.toUndeclared( "Database entity missing required annotation @org.hibernate.annotations.Entity. Database entities must have BOTH @javax.persistence.Entity and @org.hibernate.annotations.Entity annotations: " + candidate.getCanonicalName()); } else if (Ats.from(candidate).has(org.hibernate.annotations.Entity.class) && !Ats.from(candidate).has(javax.persistence.Entity.class)) { throw Exceptions.toUndeclared( "Database entity missing required annotation @javax.persistence.Entity. Database entities must have BOTH @javax.persistence.Entity and @org.hibernate.annotations.Entity annotations: " + candidate.getCanonicalName()); } else { return false; } }
From source file:org.red5.server.util.ScopeUtils.java
public static Object getScopeService(IScope scope, Class<?> intf, Class<?> defaultClass, boolean checkHandler) { if (scope == null || intf == null) { return null; }/* www . j a v a2s. c om*/ // We expect an interface assert intf.isInterface(); String attr = IPersistable.TRANSIENT_PREFIX + SERVICE_CACHE_PREFIX + intf.getCanonicalName(); if (scope.hasAttribute(attr)) { // return cached service return scope.getAttribute(attr); } Object handler = null; if (checkHandler) { IScope current = scope; while (current != null) { IScopeHandler scopeHandler = current.getHandler(); if (intf.isInstance(scopeHandler)) { handler = scopeHandler; break; } if (!current.hasParent()) { break; } current = current.getParent(); } } if (handler == null && IScopeService.class.isAssignableFrom(intf)) { // we've got an IScopeService, try to lookup bean Field key = null; Object serviceName = null; try { key = intf.getField("BEAN_NAME"); serviceName = key.get(null); if (serviceName instanceof String) { handler = getScopeService(scope, (String) serviceName, defaultClass); } } catch (Exception e) { log.debug("No string field 'BEAN_NAME' in that interface"); } } if (handler == null && defaultClass != null) { try { handler = defaultClass.newInstance(); } catch (Exception e) { log.error("", e); } } // cache service scope.setAttribute(attr, handler); return handler; }
From source file:net.pms.external.ExternalFactory.java
private static void purgeCode(String mainClass, URL newUrl) { Class<?> clazz1 = null; for (Class<?> clazz : externalListenerClasses) { if (mainClass.equals(clazz.getCanonicalName())) { clazz1 = clazz;//from w w w .ja v a 2s .c om break; } } if (clazz1 == null) { return; } externalListenerClasses.remove(clazz1); ExternalListener remove = null; for (ExternalListener list : externalListeners) { if (list.getClass().equals(clazz1)) { remove = list; break; } } RendererConfiguration.resetAllRenderers(); if (remove != null) { externalListeners.remove(remove); remove.shutdown(); LooksFrame frame = (LooksFrame) PMS.get().getFrame(); frame.getPt().removePlugin(remove); } for (int i = 0; i < 3; i++) { System.gc(); } URLClassLoader cl = (URLClassLoader) clazz1.getClassLoader(); URL[] urls = cl.getURLs(); for (URL url : urls) { String mainClass1 = getMainClass(url); if (mainClass1 == null || !mainClass.equals(mainClass1)) { continue; } File f = url2file(url); File f1 = url2file(newUrl); if (f1 == null || f == null) { continue; } if (!f1.getName().equals(f.getName())) { addToPurgeFile(f); } } }
From source file:Main.java
/** * Check application's R.id class and retrieve the value of the static * member with the given name./*from w ww .ja va2 s.co m*/ */ public static int getIdentifierFromR(Context context, String type, String name) { Class<?> rClass = null; try { rClass = Class.forName(context.getPackageName() + ".R$" + type); } catch (ClassNotFoundException e) { // No R.id class? This should never happen. throw new RuntimeException(e); } try { Field rField = rClass.getField(name); Object intValue; try { intValue = rField.get(null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } if (!(intValue instanceof Integer)) { throw new RuntimeException("Not an int: " + rClass.getCanonicalName() + "." + rField.getName()); } return ((Integer) intValue).intValue(); } catch (NoSuchFieldException e) { throw new RuntimeException("There is no such id in the R class: " + context.getPackageName() + ".R." + type + "." + name + ")"); } catch (SecurityException e) { throw new RuntimeException(e); } }
From source file:com.github.dozermapper.protobuf.util.ProtoUtils.java
/** * Gets the {@link Message.Builder} instance associated with the clazz * * @param clazz {@link Message} clazz/*from w ww . j av a 2 s . c o m*/ * @return {@link Message.Builder} instance associated with the clazz */ public static Message.Builder getBuilder(Class<? extends Message> clazz) { final Message.Builder protoBuilder; try { Method newBuilderMethod = clazz.getMethod("newBuilder"); protoBuilder = (Message.Builder) newBuilderMethod.invoke(null); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new MappingException("Failed to create Message.Builder for " + clazz.getCanonicalName(), e); } return protoBuilder; }
From source file:com.ryantenney.metrics.spring.Util.java
static String chooseName(String explicitName, boolean absolute, Class<?> klass, Member member, Object... arguments) {// www. j a va2 s . c o m if (explicitName != null && !explicitName.isEmpty()) { //if a method annotation, check arguments for @MetricParam and substitute values in explicitName String resolvedName = ""; if (member instanceof Method) { resolvedName = resolveName(explicitName, (Method) member, arguments); } else { resolvedName = explicitName; } if (absolute) { return resolvedName; } return name(klass.getCanonicalName(), resolvedName); } return name(name(klass.getCanonicalName(), member.getName())); }