List of usage examples for java.lang Class isAnnotationPresent
@Override public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass)
From source file:com.activeandroid.sebbia.Cache.java
private static boolean isDoNotGenerate(Class<?> clazz) { if (clazz.isAnnotationPresent(DoNotGenerate.class)) return true; if (clazz.getSuperclass() != null) return isDoNotGenerate(clazz.getSuperclass()); return false; }
From source file:com.quartercode.femtoweb.impl.ActionUriResolver.java
/** * Returns the {@link Action} which is mapped to the given URI and located in the given package or a subpackage. * See {@link Context#getAction(String)} for more information. * * @param actionBasePackage The name of the package the action class must be located in somehow (subpackages are allowed). * For example, the URI {@code /some/test} and the package {@code com.quartercode.femtowebtest.actions} would result in the * class name {@code com.quartercode.femtowebtest.actions.some.TestAction}. * @param uri The URI whose mapped action class should be returned. * @return The action class which is mapped to the given URI. * @throws ActionNotFoundException If no action class is mapped to the given URI. */// w w w. j a v a 2 s .c o m @SuppressWarnings("unchecked") public static Class<? extends Action> getAction(String actionBasePackage, String uri) throws ActionNotFoundException { // Remove any "/" from the start and the end of the URI String trimmedUri = StringUtils.strip(uri, "/"); // Replace all "/" with ".", add the action base package to the front, capitalize the last URI part, append "Action" to the last URI part // Example: "/path/to/someTest" -> "path.to.SomeTest") String[] uriComponents = splitAtLastSeparator(trimmedUri, "/"); String actionFQCNPackage = uriComponents[0].replace('/', '.'); String actionFQCNName = StringUtils.capitalize(uriComponents[1]) + "Action"; String actionFQCN = joinNonBlankItems(".", actionBasePackage, actionFQCNPackage, actionFQCNName); try { Class<?> c = Class.forName(actionFQCN); if (!Action.class.isAssignableFrom(c) || c.isAnnotationPresent(IgnoreAction.class)) { throw new ActionNotFoundException(uri, actionFQCN); } else { return (Class<? extends Action>) c; } } catch (ClassNotFoundException e) { throw new ActionNotFoundException(e, uri, actionFQCN); } }
From source file:org.openengsb.core.util.JsonUtils.java
private static Object convertArgument(String className, Object arg) { try {/*from w w w .j a v a 2 s .c o m*/ Class<?> type = findType(className); if (type.isAnnotationPresent(Model.class)) { return MODEL_MAPPER.convertValue(arg, type); } return MAPPER.convertValue(arg, type); } catch (ClassNotFoundException e) { LOGGER.error("could not convert argument " + arg, e); return arg; } }
From source file:org.constretto.spring.EnvironmentAnnotationConfigurer.java
@SuppressWarnings("unchecked") public static Environment findEnvironmentAnnotation(Class beanClass) { if (beanClass.isAnnotationPresent(Environment.class)) { return (Environment) beanClass.getAnnotation(Environment.class); } else {//w w w .j a va 2 s .com return findEnvironmentMetaAnnotation(new HashSet<Annotation>(), beanClass.getAnnotations()); } }
From source file:org.broadleafcommerce.common.cache.HydratedSetup.java
private static String getInheritanceHierarchyRoot(Class<?> myEntityClass) { String myEntityName = myEntityClass.getName(); if (inheritanceHierarchyRoots.containsKey(myEntityName)) { return inheritanceHierarchyRoots.get(myEntityName); }/*from w w w .jav a 2 s .c om*/ Class<?> currentClass = myEntityClass; boolean eof = false; while (!eof) { Class<?> superclass = currentClass.getSuperclass(); if (superclass.equals(Object.class) || !superclass.isAnnotationPresent(Entity.class)) { eof = true; } else { currentClass = superclass; } } if (!currentClass.isAnnotationPresent(Cache.class)) { currentClass = myEntityClass; } inheritanceHierarchyRoots.put(myEntityName, currentClass.getName()); return inheritanceHierarchyRoots.get(myEntityName); }
From source file:it.uniroma2.sag.kelp.data.representation.structure.StructureElementFactory.java
/** * Returns the identifier of a given class * //from ww w . jav a 2s .c o m * @param c * the class whose identifier is requested * @return the class identifier */ public static String getStructureElementIdentifier(Class<? extends StructureElement> c) { String structureElementAbbreviation; if (c.isAnnotationPresent(JsonTypeName.class)) { JsonTypeName info = c.getAnnotation(JsonTypeName.class); structureElementAbbreviation = info.value(); } else { structureElementAbbreviation = c.getSimpleName().toUpperCase(); } return structureElementAbbreviation; }
From source file:org.openengsb.core.util.JsonUtils.java
/** * Converts an object in JSON format to the given class. Throws an IOException if the conversion could not be * performed./*from w w w .j av a2s . c o m*/ */ public static <T> T convertObject(String json, Class<T> clazz) throws IOException { try { if (clazz.isAnnotationPresent(Model.class)) { return MODEL_MAPPER.readValue(json, clazz); } return MAPPER.readValue(json, clazz); } catch (IOException e) { String error = String.format("Unable to parse given json '%s' into class '%s'.", json, clazz.getName()); LOGGER.error(error, e); throw new IOException(error, e); } }
From source file:uk.co.techblue.docusign.client.DocuSignClient.java
@SuppressWarnings("unused") private static void initializeAutoScanProviderFactory() { try {/* w w w .j a v a2 s.c om*/ final ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance(); final Iterable<Class<?>> providerClasses = DocuSignUtils .getClasses("uk.co.techblue.docusign.resteasy.providers"); for (final Class<?> provider : providerClasses) { if (provider.isAnnotationPresent(Provider.class)) { providerFactory.registerProvider(provider); } } RegisterBuiltin.register(providerFactory); } catch (ClassNotFoundException cnfe) { logger.error("Error occurred while registering custom resteasy providers", cnfe); } catch (IOException ioe) { logger.error("Error occurred while registering custom resteasy providers", ioe); } catch (Exception e) { logger.error("Error occurred while registering custom resteasy providers", e); } }
From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java
private static Set<Class> findClasses(File directory, String packageName, Class annotation) throws ClassNotFoundException, IOException { Set<Class> classes = new HashSet<Class>(); if (!directory.exists()) { String fullPath = directory.toString(); String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); JarFile jarFile = new JarFile(jarPath); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.endsWith(".class") && !entryName.contains("$")) { String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); Class cls = loader.loadClass(className); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls);// w w w. jav a 2 s .c o m } } } else { File[] files = directory.listFiles(); for (File file : files) { if (file.isDirectory()) { assert !file.getName().contains("."); classes.addAll(findClasses(file, packageName + "." + file.getName(), annotation)); } else if (file.getName().endsWith(".class")) { Class cls = loader.loadClass( packageName + '.' + file.getName().substring(0, file.getName().length() - 6)); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls); } } } return classes; }
From source file:com.darkstar.beanCartography.utils.NameUtils.java
/** * @param clazz class to check// w ww. j a va 2 s . com * @return <code>true</code> if the class has a name annotation on it */ public static boolean hasBusinessName(Class<?> clazz) { Preconditions.checkNotNull(clazz, "Class cannot be null"); return clazz.isAnnotationPresent(NamedClass.class); }