List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java
@Cache public List<Class> getStereotypes() { try {/*from w ww . ja va 2s. co m*/ List<Class> buildList = new ArrayList<Class>(); // TODO: this shouldn't be hard-coded ClassFinder cf = new ClassFinder("", true); cf.addSuperClassFilter(Stereotype.class); Set<Class> results = cf.find(); for (Class clazz : results) { // mustn't add abstract classes or stereotypes if (!Modifier.isAbstract(clazz.getModifiers())) { buildList.add(clazz); } } Collections.sort(buildList, new Comparator() { public int compare(Object o1, Object o2) { Class c1 = (Class) o1; Class c2 = (Class) o2; return c1.getName().compareTo(c2.getName()); } }); // overwrite top level list with new list return buildList; } catch (ClassNotFoundException ex) { Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex); throw new IllegalStateException("Unable to load list of stereotypes.", ex); } }
From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java
@Cache public List<Class<? extends Component>> getComponents() { try {// w w w.j a v a 2s . c o m Thread.currentThread().setContextClassLoader(getApplicationClassLoader()); List<Class<? extends Component>> buildList = new ArrayList<Class<? extends Component>>(); // TODO: this shouldn't be hard-coded ClassFinder cf = new ClassFinder("", true); cf.addSuperClassFilter(Component.class); Set<Class> results = cf.find(); for (Class clazz : results) { // mustn't add abstract classes or stereotypes if (!Modifier.isAbstract(clazz.getModifiers()) && !PublishedComponent.class.isAssignableFrom(clazz) && !Stereotype.class.isAssignableFrom(clazz)) { buildList.add(clazz); } } Collections.sort(buildList, new Comparator() { public int compare(Object o1, Object o2) { Class c1 = (Class) o1; Class c2 = (Class) o2; return c1.getName().compareTo(c2.getName()); } }); return buildList; } catch (ClassNotFoundException ex) { Logger.getLogger(PrototypeEditor.class.getName()).log(Level.SEVERE, null, ex); throw new IllegalStateException("Unable to load list of components.", ex); } }
From source file:grails.plugins.DefaultGrailsPluginManager.java
private List<GrailsPlugin> findCorePlugins() { CorePluginFinder finder = new CorePluginFinder(application); finder.setParentApplicationContext(parentCtx); List<GrailsPlugin> grailsCorePlugins = new ArrayList<GrailsPlugin>(); final Class<?>[] corePluginClasses = finder.getPluginClasses(); for (Class<?> pluginClass : corePluginClasses) { if (pluginClass != null && !Modifier.isAbstract(pluginClass.getModifiers()) && pluginClass != DefaultGrailsPlugin.class) { final BinaryGrailsPluginDescriptor binaryDescriptor = finder.getBinaryDescriptor(pluginClass); GrailsPlugin plugin;// ww w . j a va2s .co m if (binaryDescriptor != null) { plugin = createBinaryGrailsPlugin(pluginClass, binaryDescriptor); } else { plugin = createGrailsPlugin(pluginClass); } plugin.setApplicationContext(applicationContext); grailsCorePlugins.add(plugin); } } return grailsCorePlugins; }
From source file:fi.vm.sade.organisaatio.service.converter.ConverterFactory.java
public <DTO> DTO convertToDTO(OrganisaatioBaseEntity entity, Class<? extends DTO> resultClass) { DTO dto = null;/*from www. j a v a 2 s. c om*/ // if resultClass is abstractclass, get resultclass from entity, but ensure it is resultclass' subclass if (Modifier.isAbstract(resultClass.getModifiers())) { Class temp = entity.getDTOClass(); if (!resultClass.isAssignableFrom(temp)) { throw new IllegalArgumentException( "cannot convert, resultClass is abstract and not not assignable from entity's dtoclass, resultClass: " + resultClass + ", entity.dtoclass: " + entity.getDTOClass()); } resultClass = temp; } // create object and convert basic fields with dozer if (entity != null) { dto = mapper.map(entity, resultClass); } // convert other fields with custom converter Converter converter = getConverterForDto(resultClass); if (converter != null) { converter.setValuesToDTO(entity, dto); } if (entity instanceof Puhelinnumero) { ((PuhelinnumeroDTO) dto).setTyyppi(PuhelinNumeroTyyppi.fromValue(((Puhelinnumero) entity).getTyyppi())); } else if (entity instanceof Osoite) { ((OsoiteDTO) dto).setOsoiteTyyppi(OsoiteTyyppi.fromValue(((Osoite) entity).getOsoiteTyyppi())); } else if (entity instanceof YhteystietoElementti) { ((YhteystietoElementtiDTO) dto) .setTyyppi(YhteystietoElementtiTyyppi.fromValue(((YhteystietoElementti) entity).getTyyppi())); } //DEBUGSAWAY:log.debug("convertToDTO: " + entity + " -> " + dto); return dto; }
From source file:org.force66.beantester.valuegens.ValueGeneratorFactory.java
public ValueGenerator<?> forClass(Class<?> targetClass) { Validate.notNull(targetClass, "Null class not allowed"); ValueGenerator<?> generator = registeredGeneratorMap.get(targetClass); if (generator == null) { for (ValueGenerator<?> gen : STOCK_GENERATORS) { if (gen.canGenerate(targetClass)) { registeredGeneratorMap.put(targetClass, gen); return gen; }/*from ww w. j a va2 s . c o m*/ } } else { return generator; } if (targetClass.isInterface()) { InterfaceValueGenerator gen = new InterfaceValueGenerator(targetClass); this.registerGenerator(targetClass, gen); return gen; } else if (Modifier.isAbstract(targetClass.getModifiers())) { return null; // generator not possible on abstract classes } else if (targetClass.isEnum()) { return registerGenericGenerator(targetClass, targetClass.getEnumConstants()); } else if (targetClass.isArray()) { ArrayValueGenerator gen = new ArrayValueGenerator(targetClass, this); this.registerGenerator(targetClass, gen); return gen; } else if (Class.class.equals(targetClass)) { return registerGenericGenerator(targetClass, new Object[] { Object.class }); } else { return registerGenericGenerator(targetClass, new Object[] { InstantiationUtils.safeNewInstance(this, targetClass) }); } }
From source file:com.azure.webapi.MobileServiceClient.java
/** * Validates the class has an id property defined * /* w w w.j av a 2 s .co m*/ * @param clazz */ private <E> void validateClass(Class<E> clazz) { if (clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers())) { throw new IllegalArgumentException( "The class type used for creating a MobileServiceTable must be a concrete class"); } int idPropertyCount = 0; for (Field field : clazz.getDeclaredFields()) { SerializedName serializedName = field.getAnnotation(SerializedName.class); if (serializedName != null) { if (serializedName.value().equalsIgnoreCase("id")) { idPropertyCount++; } } else { if (field.getName().equalsIgnoreCase("id")) { idPropertyCount++; } } } if (idPropertyCount != 1) { throw new IllegalArgumentException( "The class representing the MobileServiceTable must have a single id property defined"); } }
From source file:org.eclipse.winery.repository.export.ZipExporter.java
/** * Writes a complete CSAR containing all necessary things reachable from the given service * template// w w w. j a v a 2s . co m * * @param id the id of the service template to export * @param out the outputstream to write to * @throws JAXBException */ public void writeZip(TOSCAComponentId entryId, OutputStream out) throws ArchiveException, IOException, XMLStreamException, JAXBException { ZipExporter.logger.trace("Starting CSAR export with {}", entryId.toString()); Map<RepositoryFileReference, String> refMap = new HashMap<RepositoryFileReference, String>(); Collection<String> definitionNames = new ArrayList<>(); final ArchiveOutputStream zos = new ArchiveStreamFactory().createArchiveOutputStream("zip", out); TOSCAExportUtil exporter = new TOSCAExportUtil(); Map<String, Object> conf = new HashMap<>(); ExportedState exportedState = new ExportedState(); TOSCAComponentId currentId = entryId; do { logger.info("begin to scan class:" + System.currentTimeMillis()); Reflections reflections = new Reflections("org.eclipse.winery.repository.ext"); Set<Class<? extends ExportFileGenerator>> implenmetions = reflections .getSubTypesOf(org.eclipse.winery.repository.ext.export.custom.ExportFileGenerator.class); logger.info("end to scan class:" + System.currentTimeMillis()); Iterator<Class<? extends ExportFileGenerator>> it = implenmetions.iterator(); Collection<TOSCAComponentId> referencedIds = null; String defName = ZipExporter.getDefinitionsPathInsideCSAR(currentId); definitionNames.add(defName); zos.putArchiveEntry(new ZipArchiveEntry(defName)); try { referencedIds = exporter.exportTOSCA(currentId, zos, refMap, conf, null); } catch (IllegalStateException e) { // thrown if something went wrong inside the repo out.close(); // we just rethrow as there currently is no error stream. throw e; } zos.closeArchiveEntry(); while (it.hasNext()) { Class<? extends ExportFileGenerator> exportClass = it.next(); logger.trace("the " + exportClass.toString() + "begin to write file"); try { if (!Modifier.isAbstract(exportClass.getModifiers())) { ExportFileGenerator fileGenerator = exportClass.newInstance(); referencedIds = exporter.exportTOSCA(currentId, zos, refMap, conf, fileGenerator); } } catch (InstantiationException e) { logger.error("export error occur while instancing " + exportClass.toString(), e); out.close(); } catch (IllegalAccessException e) { logger.error("export error occur", e); out.close(); } } exportedState.flagAsExported(currentId); exportedState.flagAsExportRequired(referencedIds); currentId = exportedState.pop(); } while (currentId != null); // if we export a ServiceTemplate, data for the self-service portal might exist if (entryId instanceof ServiceTemplateId) { this.addSelfServiceMetaData((ServiceTemplateId) entryId, refMap); addCsarMeta((ServiceTemplateId) entryId, zos); } // write custom file CustomizedFileInfos customizedResult = null; if (entryId instanceof ServiceTemplateId) { customizedResult = this.exportCustomFiles((ServiceTemplateId) entryId, zos); } // write manifest directly after the definitions to have it more at the beginning of the ZIP // rather than having it at the very end this.addManifest(entryId, definitionNames, refMap, zos); this.addManiYamlfest(entryId, exporter.getYamlExportDefResultList(), refMap, zos, exporter); this.addCheckSumFest( getCheckSums(exporter.getYamlExportDefResultList(), customizedResult.getCustomizedFileResults()), zos); // used for generated XSD schemas TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer; try { transformer = tFactory.newTransformer(); } catch (TransformerConfigurationException e1) { ZipExporter.logger.debug(e1.getMessage(), e1); throw new IllegalStateException("Could not instantiate transformer", e1); } // write all referenced files for (RepositoryFileReference ref : refMap.keySet()) { String archivePath = refMap.get(ref); ZipExporter.logger.trace("Creating {}", archivePath); ArchiveEntry archiveEntry = new ZipArchiveEntry("xml/" + archivePath); zos.putArchiveEntry(archiveEntry); if (ref instanceof DummyRepositoryFileReferenceForGeneratedXSD) { ZipExporter.logger.trace("Special treatment for generated XSDs"); Document document = ((DummyRepositoryFileReferenceForGeneratedXSD) ref).getDocument(); DOMSource source = new DOMSource(document); StreamResult result = new StreamResult(zos); try { transformer.transform(source, result); } catch (TransformerException e) { ZipExporter.logger.debug("Could not serialize generated xsd", e); } } else { try (InputStream is = Repository.INSTANCE.newInputStream(ref)) { IOUtils.copy(is, zos); } catch (Exception e) { ZipExporter.logger.error("Could not copy file content to ZIP outputstream", e); } } // add plan files/artifact templantes to yaml folder updatePlanDef(archivePath, ref, zos, customizedResult.getPlanInfos()); zos.closeArchiveEntry(); } addPlan2Zip(customizedResult.getPlanInfos(), zos); this.addNamespacePrefixes(zos); zos.finish(); zos.close(); }
From source file:org.zanata.seam.SeamAutowire.java
private <T> Class<T> getImplClass(Class<T> fieldClass) { // If the bean type is an interface, try to find a declared // implementation // TODO field class might a concrete superclass // of the impl class if (Modifier.isAbstract(fieldClass.getModifiers()) && this.beanImpls.containsKey(fieldClass)) { fieldClass = (Class<T>) this.beanImpls.get(fieldClass); }/* w w w . j a va 2s. c om*/ return (Class<T>) fieldClass; }
From source file:com.laxser.blitz.web.impl.module.ModulesBuilderImpl.java
private boolean isCandidate(Class<?> clazz) { if (clazz.isAnnotationPresent(Ignored.class)) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's present by @Ignored : " + clazz.getName()); }// www . jav a 2 s.c o m return false; } if (!Modifier.isPublic(clazz.getModifiers())) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's not a public class: " + clazz.getName()); } return false; } if (Modifier.isAbstract(clazz.getModifiers())) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's a abstract class: " + clazz.getName()); } return false; } if (clazz.getDeclaringClass() != null) { if (logger.isDebugEnabled()) { logger.debug("Ignores bean definition because it's a inner class: " + clazz.getName()); } return false; } return true; }
From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java
private void handleClassFile(final File f, final JarEntry j) throws IOException, RuntimeException { final String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", ""); try {/* ww w. jav a2s .c o m*/ final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess); final Ats ats = Ats.inClassHierarchy(candidate); if ((this.allowedClassNames.isEmpty() || this.allowedClassNames.contains(candidate.getName()) || this.allowedClassNames.contains(candidate.getCanonicalName()) || this.allowedClassNames.contains(candidate.getSimpleName())) && (ats.has(Workflow.class) || ats.has(Activities.class)) && !Modifier.isAbstract(candidate.getModifiers()) && !Modifier.isInterface(candidate.getModifiers()) && !candidate.isLocalClass() && !candidate.isAnonymousClass()) { if (ats.has(Workflow.class)) { this.workflowClasses.add(candidate); LOG.debug("Discovered workflow implementation class: " + candidate.getName()); } else { this.activityClasses.add(candidate); LOG.debug("Discovered activity implementation class: " + candidate.getName()); } } } catch (final ClassNotFoundException e) { LOG.debug(e, e); } }