List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:at.jku.rdfstats.hist.builder.HistogramBuilderFactory.java
/** register a new histogram builder impl class * /*from w w w.ja va2 s . com*/ * @param uri the datatype URI which the builder can handle * @param clazz */ public static void register(String uri, Class<? extends HistogramBuilder<?>> clazz) throws HistogramBuilderException { if (registeredBuilders.containsKey(uri)) throw new HistogramBuilderException("A histogram builder for data type URI <" + uri + "> is already registered: " + registeredBuilders.get(uri).getName()); registeredBuilders.put(uri, clazz); classHashtable.put(clazz.getCanonicalName().hashCode(), clazz); }
From source file:com.qcadoo.model.internal.classconverter.ModelXmlToClassConverterTest.java
@BeforeClass public static void init() throws Exception { MODEL_XML_TO_CLASSCONVERTER.setBeanClassLoader(ClassLoader.getSystemClassLoader()); for (Class<?> clazz : MODEL_XML_TO_CLASSCONVERTER.convert(Utils.FULL_FIRST_ENTITY_XML_RESOURCE, Utils.FULL_SECOND_ENTITY_XML_RESOURCE, Utils.FULL_THIRD_ENTITY_XML_RESOURCE, Utils.OTHER_FIRST_ENTITY_XML_RESOURCE, Utils.OTHER_SECOND_ENTITY_XML_RESOURCE)) { classes.put(clazz.getCanonicalName(), clazz); }//from w w w.ja v a 2 s.c om for (PropertyDescriptor propertyDescriptor : PropertyUtils.getPropertyDescriptors( classes.get(ClassNameUtils.getFullyQualifiedClassName("full", "firstEntity")))) { propertyDescriptors.put(propertyDescriptor.getName(), propertyDescriptor); } }
From source file:energy.usef.environment.tool.security.VaultService.java
/** * Executes a class's static main method with the current java executable and classpath in a separate process. * //w ww . ja va 2 s . co m * @param klass the class to call the static main method for * @param params the parameters to provide * @return the exit code of the process * @throws IOException * @throws InterruptedException */ public static int exec(@SuppressWarnings("rawtypes") Class klass, List<String> params) throws IOException, InterruptedException { String javaHome = System.getProperty("java.home"); String javaBin = javaHome + File.separator + "bin" + File.separator + "java"; String classpath = System.getProperty("java.class.path"); String className = klass.getCanonicalName(); // construct the command line List<String> command = new ArrayList<String>(); command.add(javaBin); command.add("-cp"); command.add(classpath); command.add(className); command.addAll(params); LOGGER.debug("executing class '{}' with params '{}' in classpath '{}' with java binary '{}'", className, params.toString(), classpath, javaBin); // build and start the Vault's process ProcessBuilder builder = new ProcessBuilder(command); Process process = builder.start(); process.waitFor(); // get the input and error streams of the process and log them InputStream in = process.getInputStream(); InputStream en = process.getErrorStream(); InputStreamReader is = new InputStreamReader(in); InputStreamReader es = new InputStreamReader(en); BufferedReader br = new BufferedReader(is); BufferedReader be = new BufferedReader(es); String read = br.readLine(); while (read != null) { LOGGER.debug(read); read = br.readLine(); } read = be.readLine(); while (read != null) { LOGGER.debug(read); read = be.readLine(); } br.close(); is.close(); in.close(); return process.exitValue(); }
From source file:fi.uta.infim.usaproxyreportgenerator.App.java
private static void setupDataProvider() { // A data provider class can be specified on the CLI. if (cli.hasOption("dataProvider")) { // Look for JAR files in the plugin dir File[] jars = PLUGINS_DIR.listFiles((FileFilter) new WildcardFileFilter("*.jar", IOCase.INSENSITIVE)); URL[] jarUrls = new URL[jars.length]; for (int i = 0; i < jars.length; ++i) { try { jarUrls[i] = jars[i].toURI().toURL(); } catch (MalformedURLException e) { // Skip URL if not valid continue; }//from w ww . j a va2 s. c om } ClassLoader loader = URLClassLoader.newInstance(jarUrls, ClassLoader.getSystemClassLoader()); String className = cli.getOptionValue("dataProvider"); // Try to load the named class using a class loader. Fall back to // default if this fails. try { @SuppressWarnings("unchecked") Class<? extends DataProvider> cliOptionClass = (Class<? extends DataProvider>) Class .forName(className, true, loader); if (!DataProvider.class.isAssignableFrom(cliOptionClass)) { throw new ClassCastException(cliOptionClass.getCanonicalName()); } dataProviderClass = cliOptionClass; } catch (ClassNotFoundException e) { System.out.flush(); System.err.println("Specified data provider class not found: " + e.getMessage()); System.err.println("Falling back to default provider."); } catch (ClassCastException e) { System.out.flush(); System.err.println("Specified data provider class is invalid: " + e.getMessage()); System.err.println("Falling back to default provider."); } System.err.flush(); } }
From source file:me.st28.flexseries.flexlib.plugin.FlexPlugin.java
/** * Retrieves the instance of a global module. * * @param module The class of the module. * @return The module matching the class. * @throws IllegalArgumentException Thrown if the provided module class is not registered. * @throws ModuleDisabledException Thrown if the module is disabled. *//* www . j a va 2 s. co m*/ public static <T extends FlexModule> T getGlobalModule(Class<T> module) { Validate.notNull(module, "Module class cannot be null."); if (!GLOBAL_MODULES.containsKey(module)) { throw new IllegalArgumentException( "No global module '" + module.getCanonicalName() + "' is registered."); } FlexModule moduleInst = GLOBAL_MODULES.get(module); ModuleStatus status = moduleInst.getStatus(); if (!status.isEnabled()) { throw new ModuleDisabledException(moduleInst); } return (T) moduleInst; }
From source file:org.red5.server.api.ScopeUtils.java
public static Object getScopeService(IScope scope, Class intf, Class defaultClass, boolean checkHandler) { if (scope == null || intf == null) { return null; }// w ww .ja v a 2s. co m // We expect an interface assert intf.isInterface(); if (scope.hasAttribute(IPersistable.TRANSIENT_PREFIX + SERVICE_CACHE_PREFIX + intf.getCanonicalName())) { // Return cached service return scope .getAttribute(IPersistable.TRANSIENT_PREFIX + SERVICE_CACHE_PREFIX + intf.getCanonicalName()); } 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 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)) serviceName = null; } catch (Exception e) { log.debug("No string field 'BEAN_NAME' in that interface"); } if (serviceName != null) handler = getScopeService(scope, (String) serviceName, defaultClass); } if (handler == null && defaultClass != null) { try { handler = defaultClass.newInstance(); } catch (Exception e) { log.error(e); } } // Cache service scope.setAttribute(IPersistable.TRANSIENT_PREFIX + SERVICE_CACHE_PREFIX + intf.getCanonicalName(), handler); return handler; }
From source file:Main.java
/** * this will return the init value with type name. *//* ww w . j av a 2 s.c o m*/ public static String getInitValueWithType(Class<?> type) { if (byte.class.equals(type)) { return "(byte) 0"; } else if (short.class.equals(type)) { return "(short) 0"; } else if (int.class.equals(type)) { return "0"; } else if (long.class.equals(type)) { return "0l"; } else if (float.class.equals(type)) { return "0f"; } else if (double.class.equals(type)) { return "0d"; } else if (char.class.equals(type)) { return "'\\0'"; } else if (boolean.class.equals(type)) { return "false"; } else { return "(" + type.getCanonicalName() + ") null"; } }
From source file:Main.java
public static String getInitCodeWithType(Class<?> type) { if (byte.class.equals(type)) { return "(byte) 0"; } else if (short.class.equals(type)) { return "(short) 0"; } else if (int.class.equals(type)) { return "0"; } else if (long.class.equals(type)) { return "0l"; } else if (float.class.equals(type)) { return "0f"; } else if (double.class.equals(type)) { return "0d"; } else if (char.class.equals(type)) { return "'\\0'"; } else if (boolean.class.equals(type)) { return "false"; } else {//from ww w .j a va 2 s. c o m return "(" + type.getCanonicalName() + ") null"; } }
From source file:com.eucalyptus.entities.PersistenceContexts.java
private static boolean isDuplicate(Class entity) { PersistenceContext ctx = Ats.from(entity).get(PersistenceContext.class); if (Ats.from(entity).has(MappedSuperclass.class) || Ats.from(entity).has(Embeddable.class)) { return false; } else if (ctx == null || ctx.name() == null) { RuntimeException ex = new RuntimeException( "Failed to register broken entity class: " + entity.getCanonicalName() + ". Ensure that the class has a well-formed @PersistenceContext annotation."); LOG.error(ex, ex);/*from ww w. jav a2 s. co m*/ return false; } else if (sharedEntities.contains(entity)) { Class old = sharedEntities.get(sharedEntities.indexOf(entity)); LOG.error("Duplicate entity definition detected: " + entity.getCanonicalName()); LOG.error("=> OLD: " + old.getProtectionDomain().getCodeSource().getLocation()); LOG.error("=> NEW: " + entity.getProtectionDomain().getCodeSource().getLocation()); throw BootstrapException.throwFatal("Duplicate entity definition in shared entities: " + entity.getCanonicalName() + ". See error logs for details."); } else if (entities.get(ctx.name()) != null && entities.get(ctx.name()).contains(entity)) { List<Class> context = entities.get(ctx.name()); Class old = context.get(context.indexOf(entity)); LOG.error("Duplicate entity definition detected: " + entity.getCanonicalName()); LOG.error("=> OLD: " + old.getProtectionDomain().getCodeSource().getLocation()); LOG.error("=> NEW: " + entity.getProtectionDomain().getCodeSource().getLocation()); throw BootstrapException.throwFatal("Duplicate entity definition in '" + ctx.name() + "': " + entity.getCanonicalName() + ". See error logs for details."); } else { return false; } }
From source file:com.flipkart.foxtrot.core.TestUtils.java
public static void registerActions(AnalyticsLoader analyticsLoader, ObjectMapper mapper) throws Exception { Reflections reflections = new Reflections("com.flipkart.foxtrot", new SubTypesScanner()); Set<Class<? extends Action>> actions = reflections.getSubTypesOf(Action.class); if (actions.isEmpty()) { throw new Exception("No analytics actions found!!"); }/* w ww. j a v a 2 s . co m*/ List<NamedType> types = new Vector<NamedType>(); for (Class<? extends Action> action : actions) { AnalyticsProvider analyticsProvider = action.getAnnotation(AnalyticsProvider.class); if (null == analyticsProvider.request() || null == analyticsProvider.opcode() || analyticsProvider.opcode().isEmpty() || null == analyticsProvider.response()) { throw new Exception("Invalid annotation on " + action.getCanonicalName()); } if (analyticsProvider.opcode().equalsIgnoreCase("default")) { logger.warn("Action " + action.getCanonicalName() + " does not specify cache token. " + "Using default cache."); } analyticsLoader.register(new ActionMetadata(analyticsProvider.request(), action, analyticsProvider.cacheable(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.request(), analyticsProvider.opcode())); types.add(new NamedType(analyticsProvider.response(), analyticsProvider.opcode())); logger.info("Registered action: " + action.getCanonicalName()); } mapper.getSubtypeResolver().registerSubtypes(types.toArray(new NamedType[types.size()])); }