List of usage examples for java.lang Class getModifiers
@HotSpotIntrinsicCandidate public native int getModifiers();
From source file:com.weibo.api.motan.core.extension.ExtensionLoader.java
private void checkClassPublic(Class<T> clz) { if (!Modifier.isPublic(clz.getModifiers())) { failThrows(clz, "Error is not a public class"); }//from w w w . j a v a2 s .c om }
From source file:Main.java
public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass) throws ClassNotFoundException { Class<?> firstCls = obj.getClass(); Long unoTypePtr = unoTypes.get(firstCls.getName()); if (unoTypePtr != null) { return (long) unoTypePtr; } else {/*from ww w . j a v a 2s . c o m*/ if (typeHasFallbackClass) { Class<?> itf = unoFallbacks.get(fallbackTypePtr); if (itf == null) { throw new ClassNotFoundException( "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr); } Class<?> currentCls = firstCls; while (true) { if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) { Long potential = unoTypes.get(currentCls.getName()); if (potential != null) { unoTypes.put(firstCls.getName(), potential); return (long) potential; } } else { unoTypes.put(firstCls.getName(), fallbackTypePtr); return fallbackTypePtr; } currentCls = currentCls.getSuperclass(); if (currentCls == null) { unoTypes.put(firstCls.getName(), fallbackTypePtr); return fallbackTypePtr; } } } else { Class<?> currentCls = firstCls; while (true) { currentCls = currentCls.getSuperclass(); if (currentCls == null) { unoTypes.put(firstCls.getName(), fallbackTypePtr); return fallbackTypePtr; } else { Long potential = unoTypes.get(currentCls.getName()); if (potential != null) { if (Modifier.isAbstract(currentCls.getModifiers())) { Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls); if (fallbackClassPtr != null) { unoTypes.put(firstCls.getName(), fallbackClassPtr); return fallbackClassPtr; } } else { unoTypes.put(firstCls.getName(), potential); return (long) potential; } } } } } } }
From source file:org.apache.syncope.core.logic.init.ClassPathScanImplementationLookup.java
@Override @SuppressWarnings("unchecked") public void load() { classNames = new EnumMap<>(Type.class); for (Type type : Type.values()) { classNames.put(type, new HashSet<String>()); }/*w ww.jav a2 s .co m*/ reportletClasses = new HashMap<>(); accountRuleClasses = new HashMap<>(); passwordRuleClasses = new HashMap<>(); ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider( false); scanner.addIncludeFilter(new AssignableTypeFilter(Reportlet.class)); scanner.addIncludeFilter(new AssignableTypeFilter(AccountRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PasswordRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(MappingItemTransformer.class)); scanner.addIncludeFilter(new AssignableTypeFilter(SchedTaskJobDelegate.class)); scanner.addIncludeFilter(new AssignableTypeFilter(ReconciliationFilterBuilder.class)); scanner.addIncludeFilter(new AssignableTypeFilter(LogicActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PropagationActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PullActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PushActions.class)); scanner.addIncludeFilter(new AssignableTypeFilter(PullCorrelationRule.class)); scanner.addIncludeFilter(new AssignableTypeFilter(Validator.class)); scanner.addIncludeFilter(new AssignableTypeFilter(NotificationRecipientsProvider.class)); for (BeanDefinition bd : scanner.findCandidateComponents(StringUtils.EMPTY)) { try { Class<?> clazz = ClassUtils.resolveClassName(bd.getBeanClassName(), ClassUtils.getDefaultClassLoader()); boolean isAbsractClazz = Modifier.isAbstract(clazz.getModifiers()); if (Reportlet.class.isAssignableFrom(clazz) && !isAbsractClazz) { ReportletConfClass annotation = clazz.getAnnotation(ReportletConfClass.class); if (annotation == null) { LOG.warn("Found Reportlet {} without declared configuration", clazz.getName()); } else { classNames.get(Type.REPORTLET_CONF).add(annotation.value().getName()); reportletClasses.put(annotation.value(), (Class<? extends Reportlet>) clazz); } } if (AccountRule.class.isAssignableFrom(clazz) && !isAbsractClazz) { AccountRuleConfClass annotation = clazz.getAnnotation(AccountRuleConfClass.class); if (annotation == null) { LOG.warn("Found account policy rule {} without declared configuration", clazz.getName()); } else { classNames.get(Type.ACCOUNT_RULE_CONF).add(annotation.value().getName()); accountRuleClasses.put(annotation.value(), (Class<? extends AccountRule>) clazz); } } if (PasswordRule.class.isAssignableFrom(clazz) && !isAbsractClazz) { PasswordRuleConfClass annotation = clazz.getAnnotation(PasswordRuleConfClass.class); if (annotation == null) { LOG.warn("Found password policy rule {} without declared configuration", clazz.getName()); } else { classNames.get(Type.PASSWORD_RULE_CONF).add(annotation.value().getName()); passwordRuleClasses.put(annotation.value(), (Class<? extends PasswordRule>) clazz); } } if (MappingItemTransformer.class.isAssignableFrom(clazz) && !isAbsractClazz && !clazz.equals(JEXLMappingItemTransformerImpl.class)) { classNames.get(Type.MAPPING_ITEM_TRANSFORMER).add(clazz.getName()); } if (SchedTaskJobDelegate.class.isAssignableFrom(clazz) && !isAbsractClazz && !PullJobDelegate.class.isAssignableFrom(clazz) && !PushJobDelegate.class.isAssignableFrom(clazz) && !GroupMemberProvisionTaskJobDelegate.class.isAssignableFrom(clazz)) { classNames.get(Type.TASKJOBDELEGATE).add(bd.getBeanClassName()); } if (ReconciliationFilterBuilder.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.RECONCILIATION_FILTER_BUILDER).add(bd.getBeanClassName()); } if (LogicActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.LOGIC_ACTIONS).add(bd.getBeanClassName()); } if (PropagationActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PROPAGATION_ACTIONS).add(bd.getBeanClassName()); } if (PullActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PULL_ACTIONS).add(bd.getBeanClassName()); } if (PushActions.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.PUSH_ACTIONS).add(bd.getBeanClassName()); } if (PullCorrelationRule.class.isAssignableFrom(clazz) && !isAbsractClazz && !PlainAttrsPullCorrelationRule.class.isAssignableFrom(clazz)) { classNames.get(Type.PULL_CORRELATION_RULE).add(bd.getBeanClassName()); } if (Validator.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.VALIDATOR).add(bd.getBeanClassName()); } if (NotificationRecipientsProvider.class.isAssignableFrom(clazz) && !isAbsractClazz) { classNames.get(Type.NOTIFICATION_RECIPIENTS_PROVIDER).add(bd.getBeanClassName()); } } catch (Throwable t) { LOG.warn("Could not inspect class {}", bd.getBeanClassName(), t); } } classNames = Collections.unmodifiableMap(classNames); reportletClasses = Collections.unmodifiableMap(reportletClasses); accountRuleClasses = Collections.unmodifiableMap(accountRuleClasses); passwordRuleClasses = Collections.unmodifiableMap(passwordRuleClasses); LOG.debug("Implementation classes found: {}", classNames); }
From source file:com.bstek.dorado.data.JsonUtils.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static Object internalToJavaCollection(ArrayNode arrayNode, AggregationDataType dataType, Class<Collection<?>> targetType, boolean proxy, JsonConvertContext context) throws Exception { Class<Collection> creationType = null; if (dataType != null) { creationType = (Class<Collection>) dataType.getCreationType(); }// w ww.j a v a 2s . co m boolean shouldConvertToArray = false; Collection collection = null; if (creationType != null) { if (targetType != null && !targetType.isAssignableFrom(creationType)) { throw new IllegalArgumentException("Java type mismatch. expect [" + targetType + "]."); } if (!Collection.class.isAssignableFrom(creationType)) { if (creationType.isArray()) { shouldConvertToArray = true; } else { throw new IllegalArgumentException( "Java type mismatch. expect [java.util.Collection] or [Array]."); } } else { if (!Modifier.isAbstract(creationType.getModifiers())) { collection = creationType.newInstance(); } } } else if (targetType != null) { if (targetType.isArray()) { shouldConvertToArray = true; } else if (!Modifier.isAbstract(targetType.getModifiers())) { collection = targetType.newInstance(); } else if (Set.class.isAssignableFrom(targetType)) { collection = new HashSet<Object>(); } } if (collection == null) { collection = new ArrayList<Object>(); } boolean isFirstElement = true; DataType elementDataType = ((dataType != null) ? dataType.getElementDataType() : null); Iterator<JsonNode> it = arrayNode.iterator(); while (it.hasNext()) { JsonNode jsonNode = it.next(); if (jsonNode instanceof ObjectNode) { ObjectNode objectNode = (ObjectNode) jsonNode; if (isFirstElement && elementDataType == null) { String dataTypeName = JsonUtils.getString(objectNode, DATATYPE_PROPERTY); if (StringUtils.isNotEmpty(dataTypeName)) { elementDataType = getDataType(dataTypeName, context); } } collection.add( internalToJavaEntity(objectNode, (EntityDataType) elementDataType, null, proxy, context)); } else if (jsonNode instanceof ValueNode) { collection.add(toJavaValue(((ValueNode) jsonNode), elementDataType, context)); } else { throw new IllegalArgumentException("Value type mismatch. expect [JSON Value]."); } isFirstElement = false; } if (context != null && context.getEntityListCollection() != null) { context.getEntityListCollection().add(collection); } if (shouldConvertToArray) { return collection.toArray(); } else { if (dataType != null) { collection = EntityUtils.toEntity(collection, dataType); } return collection; } }
From source file:org.syncope.core.rest.controller.ReportController.java
@PreAuthorize("hasRole('REPORT_LIST')") @RequestMapping(method = RequestMethod.GET, value = "/reportletClasses") public ModelAndView getReportletClasses() { CachingMetadataReaderFactory cachingMetadataReaderFactory = new CachingMetadataReaderFactory(); Set<String> reportletClasses = new HashSet<String>(); try {/*from w ww .j a va 2 s . c om*/ for (Resource resource : resResolver.getResources("classpath*:**/*.class")) { ClassMetadata metadata = cachingMetadataReaderFactory.getMetadataReader(resource) .getClassMetadata(); if (ArrayUtils.contains(metadata.getInterfaceNames(), Reportlet.class.getName()) || AbstractReportlet.class.getName().equals(metadata.getSuperClassName())) { try { Class jobClass = Class.forName(metadata.getClassName()); if (!Modifier.isAbstract(jobClass.getModifiers())) { reportletClasses.add(jobClass.getName()); } } catch (ClassNotFoundException e) { LOG.error("Could not load class {}", metadata.getClassName(), e); } } } } catch (IOException e) { LOG.error("While searching for class implementing {}", Reportlet.class.getName(), e); } ModelAndView result = new ModelAndView(); result.addObject(reportletClasses); return result; }
From source file:org.apache.flink.api.java.typeutils.PojoTypeInfo.java
@PublicEvolving public PojoTypeInfo(Class<T> typeClass, List<PojoField> fields) { super(typeClass); checkArgument(Modifier.isPublic(typeClass.getModifiers()), "POJO %s is not public", typeClass); this.fields = fields.toArray(new PojoField[fields.size()]); Arrays.sort(this.fields, new Comparator<PojoField>() { @Override//from w w w .ja v a 2s .c o m public int compare(PojoField o1, PojoField o2) { return o1.getField().getName().compareTo(o2.getField().getName()); } }); int counterFields = 0; for (PojoField field : fields) { counterFields += field.getTypeInformation().getTotalFields(); } totalFields = counterFields; }
From source file:main.server.DemoPageProvider.java
public DemoPageProvider(ServletContext sc) { pageDir = new File(System.getProperty("user.dir", ""), "war/WEB-INF/pages"); if (!pageDir.isDirectory()) { pageDir = new File(sc.getRealPath("WEB-INF/pages")); useSession = true;/*from w ww. j av a 2 s . c o m*/ log.info("Saving pages to session: " + pageDir); } else { log.info("Loading and saving pages from " + pageDir); } // discover our classes (in a real app they would be Spring beans or // something similar) ClassFinder cf = new ClassFinder(sc, "main"); // find all PortletFactory's and alias them so fully qualified class // names don't end up in the XML for (Class cls : cf.findClasses("$Factory", PortletFactory.class)) { log.info("Portlet factory: " + cls.getName()); xmlIO.alias(cls); } // create an instance of each DataProvider for (Class cls : cf.findClasses("DataProvider", WidgetDataProvider.class)) { int mod = cls.getModifiers(); if (!Modifier.isAbstract(mod) && !Modifier.isInterface(mod)) { log.info("Data provider: " + cls.getName()); try { add((WidgetDataProvider) cls.newInstance()); } catch (Exception e) { log.error(e, e); } } } }
From source file:org.eclipse.wb.internal.core.databinding.ui.editor.contentproviders.ChooseClassUiContentProvider.java
/** * This method calculate state and sets or clear error message. Subclasses maybe override this * method for observe special states./*from www . ja v a 2 s . co m*/ */ protected void calculateFinish() { String className = getClassName(); // route events if (m_router != null) { m_router.handle(); } // check state if (className.length() == 0) { // empty class setErrorMessage(m_configuration.getEmptyClassErrorMessage()); } else { // check clear of default value (maybe not class) if (m_configuration.isDefaultString(className) || className.equals(m_configuration.getClearValue()) || ArrayUtils.indexOf(m_configuration.getDefaultValues(), className) != -1) { setErrorMessage(null); return; } // check load class Class<?>[][] constructorsParameters = m_configuration.getConstructorsParameters(); String errorMessagePrefix = m_configuration.getErrorMessagePrefix(); // boolean noConstructor = false; try { Class<?> testClass = loadClass(className); // check permissions int modifiers = testClass.getModifiers(); if (!Modifier.isPublic(modifiers)) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateNotPublic); return; } if (!m_configuration.isChooseInterfaces() && Modifier.isAbstract(modifiers)) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateAbstract); return; } // check constructor if (m_checkClasses) { m_checkClasses = false; if (constructorsParameters != null) { for (int i = 0; i < constructorsParameters.length; i++) { Class<?>[] constructorParameters = constructorsParameters[i]; for (int j = 0; j < constructorParameters.length; j++) { Class<?> constructorParameterClass = constructorParameters[j]; if (constructorParameterClass.isArray()) { String parameterClassName = constructorParameterClass.getComponentType() .getName(); if (parameterClassName.startsWith("org.eclipse")) { constructorParameters[j] = Array .newInstance(loadClass(parameterClassName), new int[1]).getClass(); } } else { String parameterClassName = constructorParameterClass.getName(); if (parameterClassName.startsWith("org.eclipse")) { constructorParameters[j] = loadClass(parameterClassName); } } } } } } if (constructorsParameters != null) { noConstructor = true; for (int i = 0; i < constructorsParameters.length; i++) { try { testClass.getConstructor(constructorsParameters[i]); noConstructor = false; break; } catch (SecurityException e) { } catch (NoSuchMethodException e) { } } } } catch (ClassNotFoundException e) { setErrorMessage(errorMessagePrefix + Messages.ChooseClassUiContentProvider_validateNotExist); return; } // prepare error message for constructor if (noConstructor) { StringBuffer parameters = new StringBuffer(errorMessagePrefix); parameters.append(Messages.ChooseClassUiContentProvider_validatePublicConstructor); for (int i = 0; i < constructorsParameters.length; i++) { Class<?>[] constructorParameters = constructorsParameters[i]; if (i > 0) { parameters.append(" "); } parameters.append(ClassUtils.getShortClassName(className)); parameters.append("("); for (int j = 0; j < constructorParameters.length; j++) { if (j > 0) { parameters.append(", "); } parameters.append(ClassUtils.getShortClassName(constructorParameters[j])); } parameters.append(")"); } parameters.append("."); setErrorMessage(parameters.toString()); } else { setErrorMessage(null); } } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void validateType(ModelType<?> type, ModelSchemaExtractionContext<?> extractionContext) { Class<?> typeClass = type.getConcreteClass(); if (!typeClass.isInterface() && !Modifier.isAbstract(typeClass.getModifiers())) { throw new InvalidManagedModelElementTypeException(extractionContext, "must be defined as an interface or an abstract class."); }// w w w .j a v a2 s . com if (typeClass.getTypeParameters().length > 0) { throw new InvalidManagedModelElementTypeException(extractionContext, "cannot be a parameterized type."); } Constructor<?> customConstructor = findCustomConstructor(typeClass); if (customConstructor != null) { throw invalidMethod(extractionContext, "custom constructors are not allowed", customConstructor); } ensureNoInstanceScopedFields(extractionContext, typeClass); ensureNoProtectedOrPrivateMethods(extractionContext, typeClass); }
From source file:org.nuunframework.cli.NuunCliPlugin.java
protected Specification<Class<?>> classIsAbstract() { return new AbstractSpecification<Class<?>>() { @Override//from w w w .j a v a 2 s .c o m public boolean isSatisfiedBy(Class<?> candidate) { return candidate != null && Modifier.isAbstract(candidate.getModifiers()); } }; }