List of usage examples for java.lang Class getCanonicalName
public String getCanonicalName()
From source file:ca.uhn.fhir.context.FhirContext.java
@SuppressWarnings("unchecked") private static List<Class<? extends IBaseResource>> toCollection(Class<?>[] theResourceTypes) { ArrayList<Class<? extends IBaseResource>> retVal = new ArrayList<Class<? extends IBaseResource>>(1); for (Class<?> clazz : theResourceTypes) { if (!IResource.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException( clazz.getCanonicalName() + " is not an instance of " + IResource.class.getSimpleName()); }/* w ww . j av a2 s. com*/ retVal.add((Class<? extends IResource>) clazz); } return retVal; }
From source file:at.jku.rdfstats.hist.builder.HistogramBuilderFactory.java
private static HistogramBuilder<?> newInstance(Class<? extends HistogramBuilder<?>> clazz, String typeUri, int preferredSize, RDFStatsConfiguration conf) throws HistogramBuilderException { if (typeUri == null) throw new HistogramBuilderException("Type URI cannot be null."); try {/*from w ww . j av a 2s. c o m*/ Constructor<? extends HistogramBuilder<?>> constr = clazz .getConstructor(new Class[] { RDFStatsConfiguration.class, String.class, int.class }); HistogramBuilder<?> builder = constr.newInstance(new Object[] { conf, typeUri, preferredSize }); return builder; } catch (NoSuchMethodException e) { throw new HistogramBuilderException("Couldn't create histogram builder (datatype URI: " + typeUri + "), implementation '" + clazz.getCanonicalName() + "' is invalid.", e); } catch (Exception e) { throw new HistogramBuilderException("Couldn't create histogram builder (datatype URI: " + typeUri + "), please call HistogramBuilderFactory.supports() first to check if a type is supported.", e); } }
From source file:com.flexive.shared.EJBLookup.java
/** * Build the correct JNDI name to request for lookups depending on the discovered lookup strategy * * @param appName EJB application name/* w ww . j a va 2s .c om*/ * @param type the class to lookup * @return JNDI name */ private static <T> String buildName(String appName, Class<T> type) { switch (used_strategy) { case APP_SIMPLENAME_LOCAL: return appName + "/" + type.getSimpleName() + "/local"; case APP_SIMPLENAME_REMOTE: return appName + "/" + type.getSimpleName() + "/remote"; case COMPLEXNAME: return type.getCanonicalName(); case SIMPLENAME: return type.getSimpleName(); case SIMPLENAME_LOCAL: return type.getSimpleName() + "/local"; case SIMPLENAME_REMOTE: return type.getSimpleName() + "/remote"; case JAVA_COMP_ENV: return "java:comp/env/" + type.getSimpleName(); case GERONIMO_LOCAL: return "/" + type.getSimpleName() + "Local"; case GERONIMO_REMOTE: return "/" + type.getSimpleName() + "Remote"; case MAPPED_NAME_REMOTE: return type.getSimpleName() + "#" + type.getCanonicalName(); case EJB31_MODULE: // EJB 3.1: EJB packaged in module return "java:module/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; case EJB31_APP_MODULE: // EJB 3.1: flexive-ejb module in EAR return "java:app/flexive-ejb/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; case EJB31_EMBEDDED: // EJB 3.1: embedded container with global paths return "java:global/" + EJB31_EMBEDDED_APPNAME + "/" + type.getSimpleName() + "!" + type.getCanonicalName() + "Local"; default: throw new FxLookupException("Unsupported/unknown lookup strategy " + used_strategy + "!") .asRuntimeException(); } }
From source file:org.web4thejob.util.converter.ClassToStringConverter.java
@Override public String convert(Class<?> source) { return source.getCanonicalName(); }
From source file:com.eucalyptus.upgrade.TestHarness.java
@SuppressWarnings("unchecked") private static Multimap<Class, Method> getTestMethods() throws Exception { final Multimap<Class, Method> testMethods = ArrayListMultimap.create(); List<Class> classList = Lists.newArrayList(); for (File f : new File(System.getProperty("euca.home") + "/usr/share/eucalyptus").listFiles()) { if (f.getName().startsWith("eucalyptus") && f.getName().endsWith(".jar") && !f.getName().matches(".*-ext-.*")) { try { JarFile jar = new JarFile(f); Enumeration<JarEntry> jarList = jar.entries(); for (JarEntry j : Collections.list(jar.entries())) { if (j.getName().matches(".*\\.class.{0,1}")) { String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", ""); try { Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess); for (final Method m : candidate.getDeclaredMethods()) { if (Iterables.any(testAnnotations, new Predicate<Class<? extends Annotation>>() { public boolean apply(Class<? extends Annotation> arg0) { return m.getAnnotation(arg0) != null; } })) { System.out.println("Added test class: " + candidate.getCanonicalName()); testMethods.put(candidate, m); }// w w w . j a v a 2 s . c om } } catch (ClassNotFoundException e) { } } } jar.close(); } catch (Exception e) { System.out.println(e.getMessage()); continue; } } } return testMethods; }
From source file:com.vmware.photon.controller.common.xenon.ServiceHostUtils.java
/** * Constructs a URI to start service under. * * @param host/*from w w w . ja v a 2 s. c om*/ * @param service * @param path * @return */ private static URI buildServiceUri(ServiceHost host, Class service, String path) { URI serviceUri; String error; if (path != null) { serviceUri = UriUtils.buildUri(host, path); error = String.format("Invalid path for starting service [%s]", path); } else { serviceUri = UriUtils.buildUri(host, service); error = String.format("No SELF_LINK field in class %s", service.getCanonicalName()); } if (serviceUri == null) { throw new InvalidParameterException(error); } return serviceUri; }
From source file:com.vmware.photon.controller.common.dcp.ServiceHostUtils.java
/** * Starts a service specified by the class type on the host. * * @param host/*w w w .ja v a 2 s. c o m*/ * @param service * @throws InstantiationException * @throws IllegalAccessException */ public static void startService(ServiceHost host, Class service) throws InstantiationException, IllegalAccessException { checkArgument(host != null, "host cannot be null"); checkArgument(service != null, "service cannot be null"); Service instance = (Service) service.newInstance(); final URI serviceUri = UriUtils.buildUri(host, service); if (serviceUri == null) { throw new InvalidParameterException( String.format("No SELF_LINK field in class %s", service.getCanonicalName())); } Operation.CompletionHandler completionHandler = new Operation.CompletionHandler() { @Override public void handle(Operation operation, Throwable throwable) { if (throwable != null) { logger.debug("Start service {[]} failed: {}", serviceUri, throwable); } } }; Operation op = Operation.createPost(serviceUri).setCompletion(completionHandler); host.startService(op, instance); }
From source file:org.openmrs.module.kenyaemr.converter.ClassToStringConverter.java
/** * @see org.springframework.core.convert.converter.Converter#convert(Object) *///from w ww . ja v a 2s. c om @Override public String convert(Class clazz) { return clazz != null ? clazz.getCanonicalName() : ""; }
From source file:com.github.sevntu.checkstyle.internal.ChecksTest.java
private static void validateSonarFile(Document document, Set<Class<?>> modules) { final NodeList rules = document.getElementsByTagName("rule"); for (int position = 0; position < rules.getLength(); position++) { final Node rule = rules.item(position); final Set<Node> children = XmlUtil.getChildrenElements(rule); final String key = SevntuXmlUtil.findElementByTag(children, "key").getTextContent(); final Class<?> module = findModule(modules, key); modules.remove(module);/*from w w w . j av a 2s . co m*/ Assert.assertNotNull("Unknown class found in sonar: " + key, module); final String moduleName = module.getName(); final Node name = SevntuXmlUtil.findElementByTag(children, "name"); Assert.assertNotNull(moduleName + " requires a name in sonar", name); Assert.assertFalse(moduleName + " requires a name in sonar", name.getTextContent().isEmpty()); final Node categoryNode = SevntuXmlUtil.findElementByTag(children, "category"); String expectedCategory = module.getCanonicalName(); final int lastIndex = expectedCategory.lastIndexOf('.'); expectedCategory = expectedCategory.substring(expectedCategory.lastIndexOf('.', lastIndex - 1) + 1, lastIndex); Assert.assertNotNull(moduleName + " requires a category in sonar", categoryNode); final Node categoryAttribute = categoryNode.getAttributes().getNamedItem("name"); Assert.assertNotNull(moduleName + " requires a category name in sonar", categoryAttribute); Assert.assertEquals(moduleName + " requires a valid category in sonar", expectedCategory, categoryAttribute.getTextContent()); final Node description = SevntuXmlUtil.findElementByTag(children, "description"); Assert.assertNotNull(moduleName + " requires a description in sonar", description); final Node configKey = SevntuXmlUtil.findElementByTag(children, "configKey"); final String expectedConfigKey = "Checker/TreeWalker/" + key; Assert.assertNotNull(moduleName + " requires a configKey in sonar", configKey); Assert.assertEquals(moduleName + " requires a valid configKey in sonar", expectedConfigKey, configKey.getTextContent()); validateSonarProperties(module, SevntuXmlUtil.findElementsByTag(children, "param")); } for (Class<?> module : modules) { Assert.fail("Module not found in sonar: " + module.getCanonicalName()); } }
From source file:org.moserp.common.repository.SequenceService.java
public void resetSequence(Class<?> entityClass) { String key = entityClass.getCanonicalName(); Query query = new Query(Criteria.where("_id").is(key)); mongoTemplate.remove(query, Sequence.class); }