List of usage examples for java.lang.reflect Modifier isPublic
public static boolean isPublic(int mod)
From source file:com.paladin.mvc.ActionServlet.java
/** * ???{method}// w w w . j a v a 2 s . co m * * @param _action * @param _method * @return */ private Method getActionMethod(final Object _action, final String _method) { String key = _action.getClass().getSimpleName() + '.' + _method; Method m = methods.get(key); if (m != null) return m; for (Method method : _action.getClass().getMethods()) { if (Modifier.isPublic(method.getModifiers()) && method.getName().equals(_method)) { synchronized (methods) { methods.put(key, method); } return method; } } return null; }
From source file:org.apache.openjpa.enhance.PCSubclassValidator.java
private void checkMethodIsSubclassable(Method meth, FieldMetaData fmd) { String className = fmd.getDefiningMetaData().getDescribedType().getName(); if (!(Modifier.isProtected(meth.getModifiers()) || Modifier.isPublic(meth.getModifiers()))) addError(loc.get("subclasser-private-accessors-unsupported", className, meth.getName()), fmd); if (Modifier.isFinal(meth.getModifiers())) addError(loc.get("subclasser-final-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isNative(meth.getModifiers())) addContractViolation(loc.get("subclasser-native-methods-not-allowed", className, meth.getName()), fmd); if (Modifier.isStatic(meth.getModifiers())) addError(loc.get("subclasser-static-methods-not-supported", className, meth.getName()), fmd); }
From source file:org.cruxframework.crux.core.server.rest.core.registry.ResourceRegistry.java
/** * //from w ww . ja v a 2 s. c om * @param base * @param clazz * @param method * @param restMethodNames */ protected RestMethodRegistrationInfo processMethod(String base, Class<?> clazz, Method method, Set<String> restMethodNames) { if (method != null) { Path path = method.getAnnotation(Path.class); String httpMethod = null; try { httpMethod = HttpMethodHelper.getHttpMethod(method.getAnnotations()); } catch (InvalidRestMethod e) { logger.error( "Invalid Method: " + method.getDeclaringClass().getName() + "." + method.getName() + "().", e); } boolean pathPresent = path != null; boolean restAnnotationPresent = pathPresent || (httpMethod != null); UriBuilder builder = new UriBuilder(); if (base != null) builder.path(base); if (clazz.isAnnotationPresent(Path.class)) { builder.path(clazz); } if (path != null) { builder.path(method); } String pathExpression = builder.getPath(); if (pathExpression == null) { pathExpression = ""; } if (restAnnotationPresent && !Modifier.isPublic(method.getModifiers())) { logger.error("Rest annotations found at non-public method: " + method.getDeclaringClass().getName() + "." + method.getName() + "(); Only public methods may be exposed as resource methods."); } else if (httpMethod != null) { if (restMethodNames.contains(method.getName())) { logger.error("Overloaded rest method: " + method.getDeclaringClass().getName() + "." + method.getName() + " found. It is not supported for Crux REST services."); } else { ResourceMethod invoker = new ResourceMethod(clazz, method, httpMethod); rootSegment.addPath(pathExpression, invoker); restMethodNames.add(method.getName()); size++; return new RestMethodRegistrationInfo(pathExpression, invoker); } } else { if (restAnnotationPresent) { logger.error("Method: " + method.getDeclaringClass().getName() + "." + method.getName() + "() declares rest annotations, but it does not inform the methods it must handle. Use one of @PUT, @POST, @GET or @DELETE."); } else if (logger.isDebugEnabled()) { logger.debug("Method: " + method.getDeclaringClass().getName() + "." + method.getName() + "() ignored. It is not a rest method."); } } } return null; }
From source file:org.getobjects.foundation.kvc.KVCWrapper.java
/** * Uses JavaBeans introspection to find all the properties of the * bean class. This method sets the {@link #accessors} variable (it will * have been null), and adds all the well-defined JavaBeans properties. * * <p>Subclasses may invoke this method before adding thier own accessors. * * <p>This method is invoked from within a synchronized block. Subclasses * do not have to worry about synchronization. **//* w w w. j a v a 2 s . co m*/ protected void buildPropertyAccessors() { /* * Acquire all usable field accessors first. */ if (this.accessors != null) return; /** * Construct field accessors for names which aren't occupied * by properties, yet. Imagine this as a "last resort". */ final Map<String, FieldAccessor> propertyFieldAccessorMap = new HashMap<String, FieldAccessor>(); final Field fields[] = this.clazz.getFields(); for (Field field : fields) { final int mods = field.getModifiers(); // Skip static variables and non-public instance variables. if ((Modifier.isPublic(mods) == false) || (Modifier.isStatic(mods))) continue; propertyFieldAccessorMap.put(field.getName(), new FieldAccessor(field)); } /** * Retrieve all property descriptors now */ PropertyDescriptor[] props; try { props = this.getPropertyDescriptors(this.clazz); } catch (Exception e) { logger.error("Error during getPropertyDescriptors()", e); throw new DynamicInvocationException(e); } // TBD: instead build the table locally, and then apply to an // atomic reference?! this.accessors = new ConcurrentHashMap<String, IPropertyAccessor>(16); if (logger.isDebugEnabled()) logger.debug("Recording properties for \"" + this.clazz.getName() + "\""); for (PropertyDescriptor pd : props) { final String name = pd.getName(); if (logger.isDebugEnabled()) logger.debug("Recording property \"" + name + "\""); final Method getter = pd.getReadMethod(); final Method setter = pd.getWriteMethod(); final FieldAccessor fa = propertyFieldAccessorMap.get(name); final Class type = pd.getPropertyType(); final PropertyAccessor pa = PropertyAccessor.getPropertyAccessor(name, type, getter, setter, fa); this.accessors.put(name, pa); } /** * Use field accessors for names which are not occupied, yet. * This is the default fallback. */ for (String name : propertyFieldAccessorMap.keySet()) { if (!this.accessors.containsKey(name)) this.accessors.put(name, propertyFieldAccessorMap.get(name)); } }
From source file:org.gradle.build.docs.dsl.SourceMetaDataVisitor.java
private void maybeAddPropertyFromField(GroovySourceAST t) { GroovySourceAST parentNode = getParentNode(); boolean isField = parentNode != null && parentNode.getType() == OBJBLOCK; if (!isField) { return;/* ww w. j a va 2s.c o m*/ } int modifiers = extractModifiers(t); boolean isConst = getCurrentClass().isInterface() || (Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)); if (isConst) { visitConst(t); return; } boolean isProp = groovy && !Modifier.isStatic(modifiers) && !Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers) && !Modifier.isPrivate(modifiers); if (!isProp) { return; } ASTIterator children = new ASTIterator(t); children.skip(MODIFIERS); String propertyName = extractIdent(t); TypeMetaData propertyType = extractTypeName(children.current); ClassMetaData currentClass = getCurrentClass(); MethodMetaData getterMethod = currentClass .addMethod(String.format("get%s", StringUtils.capitalize(propertyName)), propertyType, ""); currentClass.addReadableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), getterMethod); if (!Modifier.isFinal(modifiers)) { MethodMetaData setterMethod = currentClass .addMethod(String.format("set%s", StringUtils.capitalize(propertyName)), TypeMetaData.VOID, ""); setterMethod.addParameter(propertyName, propertyType); currentClass.addWriteableProperty(propertyName, propertyType, getJavaDocCommentsBeforeNode(t), setterMethod); } }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void defaultAccessMethods() { memberCriteria.membersOfType(Method.class); memberCriteria.withAccess(AccessType.DEFAULT); ClassCriteria classCriteria = new ClassCriteria(); Iterable<Class<?>> classIterable = classCriteria.getIterable(Class.class); Iterable<Member> memberIterable = memberCriteria.getIterable(classIterable); assertTrue(memberIterable.iterator().hasNext()); for (Member member : memberIterable) { assertTrue("member must be a method", member instanceof Method); int modifiers = member.getModifiers(); assertFalse(Modifier.isPublic(modifiers)); assertFalse(Modifier.isProtected(modifiers)); assertFalse(Modifier.isPrivate(modifiers)); }/*from w ww . j a va2 s .c o m*/ }
From source file:com.nridge.core.base.field.data.DataBeanBag.java
/** * Accepts a POJO containing one or more public fields and * creates a DataBag from them. The DataBeanObject1 test * class provides a reference example.//from w w w. j a va2 s . c om * * @param anObject POJO instance. * * @return Data bag instance populated with field information. * * @throws NSException Thrown if object is null. * @throws NoSuchFieldException Thrown if field does not exist. * @throws IllegalAccessException Thrown if access is illegal. */ public static DataBag fromFieldsToBag(Object anObject) throws NSException, NoSuchFieldException, IllegalAccessException { DataField dataField; boolean isPublicAccess; if (anObject == null) throw new NSException("Object is null"); DataBag dataBag = new DataBag(anObject.toString()); Class<?> objClass = anObject.getClass(); Field[] fieldArray = objClass.getDeclaredFields(); for (Field objField : fieldArray) { isPublicAccess = Modifier.isPublic(objField.getModifiers()); if (!isPublicAccess) objField.setAccessible(true); dataField = reflectField(anObject, objField); dataBag.add(dataField); } return dataBag; }
From source file:org.apache.apex.malhar.stream.api.impl.ApexStreamImpl.java
private void checkArguments(Operator op, Operator.InputPort inputPort, Operator.OutputPort outputPort) { if (op == null) { throw new IllegalArgumentException("Operator can not be null"); }/*from w ww.j av a 2s . c o m*/ boolean foundInput = inputPort == null; boolean foundOutput = outputPort == null; for (Field f : op.getClass().getFields()) { int modifiers = f.getModifiers(); if (!Modifier.isPublic(modifiers) || !Modifier.isTransient(modifiers)) { continue; } Object obj = null; try { obj = f.get(op); } catch (IllegalAccessException e) { // NonAccessible field is not a valid port object } if (obj == outputPort) { foundOutput = true; } if (obj == inputPort) { foundInput = true; } } if (!foundInput || !foundOutput) { throw new IllegalArgumentException("Input port " + inputPort + " and/or Output port " + outputPort + " is/are not owned by Operator " + op); } }
From source file:com.alibaba.dubbo.config.spring.AnnotationBean.java
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (!isMatchPackage(bean)) { return bean; }/*from w w w .ja va 2s .co m*/ Method[] methods = bean.getClass().getMethods(); for (Method method : methods) { String name = method.getName(); if (name.length() > 3 && name.startsWith("set") && method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers())) { try { Reference reference = method.getAnnotation(Reference.class); if (reference != null) { Object value = refer(reference, method.getParameterTypes()[0]); if (value != null) { method.invoke(bean, new Object[] {}); } } } catch (Throwable e) { logger.error("Failed to init remote service reference at method " + name + " in class " + bean.getClass().getName() + ", cause: " + e.getMessage(), e); } } } Field[] fields = bean.getClass().getDeclaredFields(); for (Field field : fields) { try { if (!field.isAccessible()) { field.setAccessible(true); } Reference reference = field.getAnnotation(Reference.class); if (reference != null) { Object value = refer(reference, field.getType()); if (value != null) { field.set(bean, value); } } } catch (Throwable e) { logger.error("Failed to init remote service reference at filed " + field.getName() + " in class " + bean.getClass().getName() + ", cause: " + e.getMessage(), e); } } return bean; }
From source file:name.ikysil.beanpathdsl.codegen.Context.java
private boolean isExcluded(Class<?> clazz) { if (clazz.isPrimitive() || clazz.isAnonymousClass() || clazz.isLocalClass() || clazz.isInterface() || clazz.isSynthetic() || clazz.isEnum() || !Modifier.isPublic(clazz.getModifiers()) || (clazz.getPackage() == null)) { return true; }// w w w. j ava 2 s .com IncludedClass includedConfig = includedClasses.get(clazz); if (includedConfig != null) { return false; } ExcludedClass excludedConfig = excludedClasses.get(clazz); if (excludedConfig != null) { return true; } for (ExcludedPackage excludedPackage : excludedPackages) { if (excludedPackage.match(clazz.getPackage())) { return true; } } return false; }