List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:com.tower.service.test.SoafwTesterMojo.java
/** * ??&& public protected//from w w w. ja va 2 s . com * * @param file * @return */ private void load(String classesDir, File file, int length) { if (file.isDirectory()) { File[] files = file.listFiles(); int len = files.length; for (int i = 0; i < len; i++) { load(classesDir, files[i], length); } } else { String path = file.getAbsolutePath(); if (path.indexOf(classesDir) == 0 && path.length() > length) { String pkgPath = path.substring(length); try { String os = System.getProperty("os.name"); String exp = File.separator; if (os.toLowerCase().indexOf("window") >= 0) { exp = "\\\\"; } String tmpFile = null; if (pkgPath.endsWith(".class")) { tmpFile = pkgPath.replaceAll(exp, "."); if (tmpFile.endsWith(".class") && !tmpFile.endsWith("Mapper.class")) { String clsName = tmpFile.replaceAll(".class", ""); Class cls = cl.loadClass(clsName); int modf = cls.getModifiers(); if (modf != 1537 && modf != 1025) {// ?? && if (clsName.endsWith("ImplTest")) { testImpl.put(clsName, 1); } else if (clsName.endsWith("Impl")) { defines.put(clsName, 1); } else {// ?? errorImpl.put(clsName, 1); } } } } } catch (Exception e) { this.getLog().error(e); } catch (Error er) { this.getLog().error(er); } } } }
From source file:at.ac.tuwien.infosys.jcloudscale.classLoader.caching.fileCollectors.FileCollectorAbstract.java
/** * Collects the list of required files without content. * @param clazz the class that related files should be collected for. (joda style) * @return List of files that are required for specified class or * null if none are required. /*from w w w. j av a 2 s. c om*/ */ protected List<ClassLoaderFile> collectRequiredFiles(Class<?> clazz) { FileDependency fileDependency = clazz.getAnnotation(FileDependency.class); if (fileDependency == null) return null; List<ClassLoaderFile> files = new ArrayList<ClassLoaderFile>(); if (fileDependency.dependencyProvider().equals(IFileDependencyProvider.class)) {// we have static files // ContentType contentType = fileDependency.accessType() == FileAccess.ReadOnly ? // ContentType.ROFILE : ContentType.RWFILE; ContentType contentType = ContentType.ROFILE; String[] fileNames = fileDependency.files(); if (fileNames == null || fileNames.length == 0) return null; for (String filename : fileNames) { File file = RemoteClassLoaderUtils.getRelativePathFile(filename); if (!file.exists()) { log.severe("Class " + clazz.getName() + " set file " + filename + " as required, but the file is missing at " + file.getAbsolutePath()); continue; } files.add(new ClassLoaderFile(filename, file.lastModified(), file.length(), contentType)); } } else {// we have dynamic file list, let's process it. Class<? extends IFileDependencyProvider> dependentFilesProviderClass = fileDependency .dependencyProvider(); if (dependentFilesProviderClass == null) return null; //checking if we can create this class if (dependentFilesProviderClass.isInterface() || Modifier.isAbstract(dependentFilesProviderClass.getModifiers())) throw new JCloudScaleException("Class " + clazz.getName() + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName() + " as dependency provider. However, dependency provider class is either abstract or interface."); if (dependentFilesProviderClass.getEnclosingClass() != null && !Modifier.isStatic(dependentFilesProviderClass.getModifiers())) throw new JCloudScaleException("Class " + clazz.getName() + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName() + " as dependency provider. However, dependency provider class is internal and not static. The class has to be static in this case."); Constructor<? extends IFileDependencyProvider> constructor = null; try { constructor = dependentFilesProviderClass.getDeclaredConstructor(); } catch (NoSuchMethodException ex) { throw new JCloudScaleException(ex, "Class " + clazz.getName() + "is anotated with @FileDependency and has class " + dependentFilesProviderClass.getName() + " as dependency provider. However, dependency provider class cannot be created as it has no parameterless constructor."); } try { if (!constructor.isAccessible()) constructor.setAccessible(true); IFileDependencyProvider provider = constructor.newInstance(); for (DependentFile dependentFile : provider.getDependentFiles()) { File file = RemoteClassLoaderUtils.getRelativePathFile(dependentFile.filePath); if (!file.exists()) { log.severe("Class " + clazz.getName() + " set file " + dependentFile.filePath + " as required, but the file is missing."); continue; } // ContentType contentType = dependentFile.accessType == FileAccess.ReadOnly ? // ContentType.ROFILE : ContentType.RWFILE; ContentType contentType = ContentType.ROFILE; files.add(new ClassLoaderFile(file.getPath(), file.lastModified(), file.length(), contentType)); } } catch (Exception ex) { log.severe("Dependent files provider " + dependentFilesProviderClass.getName() + " for class " + clazz.getName() + " threw exception during execution:" + ex.toString()); throw new JCloudScaleException(ex, "Dependent files provider " + dependentFilesProviderClass.getName() + " for class " + clazz.getName() + " threw exception during execution."); } } return files; }
From source file:com.kjt.service.common.SoafwTesterMojo.java
/** * ??&& public protected/*from w w w. j av a2s . c om*/ * * @param file * @return */ private Map<String, Integer> load(String classesDir, File file, int length) { if (file.isDirectory()) { File[] files = file.listFiles(); int len = files.length; for (int i = 0; i < len; i++) { load(classesDir, files[i], length); } } else { String path = file.getAbsolutePath(); if (path.indexOf(classesDir) == 0 && path.length() > length) { String pkgPath = path.substring(length); try { String os = System.getProperty("os.name"); String exp = File.separator; if (os.toLowerCase().indexOf("window") >= 0) { exp = "\\\\"; } String tmpFile = pkgPath.replaceAll(exp, "."); if (tmpFile.endsWith(".class") && !tmpFile.endsWith("Mapper.class")) { String clsName = tmpFile.replaceAll(".class", ""); Class cls = cl.loadClass(clsName); int modf = cls.getModifiers(); if (modf != 1537 && modf != 1025) {// ?? && if (clsName.endsWith("ImplTest")) { testImpl.put(clsName, 1); } else if (clsName.endsWith("Impl")) { defines.put(clsName, 1); } else {// ?? errorImpl.put(clsName, 1); } } } } catch (Exception e) { this.getLog().error(e); } catch (Error er) { this.getLog().error(er); } } } return defines; }
From source file:cn.webwheel.DefaultMain.java
@SuppressWarnings("unchecked") private void autoMap(String root, String pkg, String name) { Class cls; try {//from w w w .ja va 2s . com cls = Class.forName(pkg + "." + name); } catch (ClassNotFoundException e) { return; } if (cls.isMemberClass() && !Modifier.isStatic(cls.getModifiers())) { return; } if (cls.isAnonymousClass() || cls.isLocalClass() || !Modifier.isPublic(cls.getModifiers()) || Modifier.isAbstract(cls.getModifiers())) { return; } name = name.replace('$', '.'); for (Method method : cls.getMethods()) { String pathPrefix = pkg.substring(root.length()).replace('.', '/') + '/'; String path = pathPrefix + name + '.' + method.getName(); Action action = getAction(cls, method); if (action == null) continue; if (!action.value().isEmpty()) { if (action.value().startsWith("?")) { path = path + action.value(); } else if (action.value().startsWith(".")) { path = pathPrefix + name + action.value(); } else if (!action.value().startsWith("/")) { path = pathPrefix + action.value(); } else { path = action.value(); } } ActionBinder binder = map(path); if (!action.rest().isEmpty()) { String rest = action.rest(); if (!rest.startsWith("/")) rest = pathPrefix + rest; binder = binder.rest(rest); } SetterConfig cfg = binder.with(cls, method); if (!action.charset().isEmpty()) { cfg = cfg.setCharset(action.charset()); } if (action.fileUploadFileSizeMax() != 0) { cfg = cfg.setFileUploadFileSizeMax(action.fileUploadFileSizeMax()); } if (action.fileUploadSizeMax() != 0) { cfg.setFileUploadSizeMax(action.fileUploadSizeMax()); } if (action.setterPolicy() != SetterPolicy.Auto) { cfg.setSetterPolicy(action.setterPolicy()); } } }
From source file:cross.applicationContext.ReflectionApplicationContextGenerator.java
/** * Create a bean element for the given class. * * @param clazz the target class/*from w w w. ja v a2s .c om*/ * @return the bean element or a list of beans for each service provider * available */ public List<?> createElement(Class<?> clazz) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { return createServiceProviderElements(clazz); } if (clazz.getConstructors().length == 0) { log.warn("Class {} has no public no-argument constructor!", clazz); return Collections.emptyList(); } Object obj; try { obj = clazz.newInstance(); //build a "bean" element for each class buildBeanElement(obj); return Arrays.asList(obj); } catch (InstantiationException | IllegalAccessException ex) { Logger.getLogger(ReflectionApplicationContextGenerator.class.getName()).log(Level.SEVERE, null, ex); } return Collections.emptyList(); }
From source file:org.springframework.beans.TypeConverterDelegate.java
private boolean canCreateCopy(Class<?> requiredType) { return (!requiredType.isInterface() && !Modifier.isAbstract(requiredType.getModifiers()) && Modifier.isPublic(requiredType.getModifiers()) && ClassUtils.hasConstructor(requiredType)); }
From source file:org.structr.core.module.ModuleService.java
public Class getNodeEntityClass(final String name) { Class ret = GenericNode.class; if ((name != null) && (!name.isEmpty())) { ret = nodeEntityClassCache.get(name); if (ret == null) { for (String possiblePath : nodeEntityPackages) { if (possiblePath != null) { try { Class nodeClass = Class.forName(possiblePath + "." + name); if (!Modifier.isAbstract(nodeClass.getModifiers())) { nodeEntityClassCache.put(name, nodeClass); // first match wins break; }//ww w . ja va 2 s . c o m } catch (ClassNotFoundException ex) { // ignore } } } } } return (ret); }
From source file:org.structr.core.module.ModuleService.java
public Class getRelationshipClass(final String name) { Class ret = AbstractNode.class; if ((name != null) && (name.length() > 0)) { ret = relationshipClassCache.get(name); if (ret == null) { for (String possiblePath : relationshipPackages) { if (possiblePath != null) { try { Class nodeClass = Class.forName(possiblePath + "." + name); if (!Modifier.isAbstract(nodeClass.getModifiers())) { relationshipClassCache.put(name, nodeClass); // first match wins break; }//from ww w .j av a 2s .c o m } catch (ClassNotFoundException ex) { // ignore } } } } } return (ret); }
From source file:com.github.helenusdriver.driver.impl.CreateSchemasImpl.java
/** * Find all keyspaces./*from w w w .ja va 2s. c o m*/ * * @author paouelle * * @return a map of all the keyspaces along with the list of POJO class info * associated with them * @throws IllegalArgumentException if an @Entity annotated class is missing the * Keyspace annotation or two entities defines the same keyspace with * different options or an @Entitiy annotated class doesn't represent * a valid POJO class or if no entities are found */ private Map<Keyspace, List<ClassInfoImpl<?>>> findKeyspaces() { final Map<String, Keyspace> keyspaces = new HashMap<>(25); final Map<Keyspace, List<ClassInfoImpl<?>>> cinfos = new HashMap<>(25); final Reflections reflections = new Reflections(pkg); // search for all POJO annotated classes with @Entity for (final Class<?> clazz : reflections .getTypesAnnotatedWith(com.github.helenusdriver.persistence.Entity.class, true)) { // skip abstract POJO classes if (Modifier.isAbstract(clazz.getModifiers())) { continue; } final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz); final Keyspace k = cinfo.getKeyspace(); final Keyspace old = keyspaces.put(k.name(), k); List<ClassInfoImpl<?>> cs = cinfos.get(k); if (cs == null) { cs = new ArrayList<>(25); cinfos.put(k, cs); } cs.add(cinfo); if ((old != null) && !k.equals(old)) { // duplicate annotation found with different attribute throw new IllegalArgumentException("two different @Keyspace annotations found with class '" + clazz.getName() + "': " + old + " and: " + k); } } // search for all POJO annotated classes with @RootEntity for (final Class<?> clazz : reflections .getTypesAnnotatedWith(com.github.helenusdriver.persistence.RootEntity.class, true)) { // skip classes that are not directly annotated if (ReflectionUtils.findFirstClassAnnotatedWith(clazz, com.github.helenusdriver.persistence.RootEntity.class) != clazz) { continue; } final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz); final Keyspace k = cinfo.getKeyspace(); final Keyspace old = keyspaces.put(k.name(), k); List<ClassInfoImpl<?>> cs = cinfos.get(k); if (cs == null) { cs = new ArrayList<>(25); cinfos.put(k, cs); } cs.add(cinfo); if ((old != null) && !k.equals(old)) { // duplicate annotation found with different attribute throw new IllegalArgumentException("two different @Keyspace annotations found with class '" + clazz.getName() + "': " + old + " and: " + k); } } // search for all POJO annotated classes with @UDTEntity for (final Class<?> clazz : reflections .getTypesAnnotatedWith(com.github.helenusdriver.persistence.UDTEntity.class, true)) { // skip abstract POJO classes if (Modifier.isAbstract(clazz.getModifiers())) { continue; } final ClassInfoImpl<?> cinfo = mgr.getClassInfoImpl(clazz); final Keyspace k = cinfo.getKeyspace(); final Keyspace old = keyspaces.put(k.name(), k); List<ClassInfoImpl<?>> cs = cinfos.get(k); if (cs == null) { cs = new ArrayList<>(25); cinfos.put(k, cs); } cs.add(cinfo); if ((old != null) && !k.equals(old)) { // duplicate annotation found with different attribute throw new IllegalArgumentException("two different @Keyspace annotations found with class '" + clazz.getName() + "': " + old + " and: " + k); } } org.apache.commons.lang3.Validate.isTrue(!cinfos.isEmpty(), "no classes annotated with @Entity, @RootEntity, or @UDTEntity found in package: %s", pkg); return cinfos; }
From source file:net.sf.juffrou.reflect.JuffrouTypeConverterDelegate.java
private boolean canCreateCopy(Class requiredType) { return (!requiredType.isInterface() && !Modifier.isAbstract(requiredType.getModifiers()) && Modifier.isPublic(requiredType.getModifiers()) && ClassUtils.hasConstructor(requiredType)); }