List of usage examples for java.lang.reflect Modifier isFinal
public static boolean isFinal(int mod)
From source file:org.makersoft.activesql.builder.GenericStatementBuilder.java
public GenericStatementBuilder(Configuration configuration, Class<?> entityClass) { super(configuration); this.entityClass = entityClass; String resource = entityClass.getName().replace('.', '/') + ".java (best guess)"; assistant = new MapperBuilderAssistant(configuration, resource); entity = entityClass.getAnnotation(Entity.class); mapperType = entity.mapper();/*from w w w. j a va 2 s . c om*/ if (!mapperType.isAssignableFrom(Void.class)) { namespace = mapperType.getName(); } else { namespace = entityClass.getName(); } assistant.setCurrentNamespace(namespace); databaseId = super.getConfiguration().getDatabaseId(); lang = super.getConfiguration().getDefaultScriptingLanuageInstance(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~ Table table = entityClass.getAnnotation(Table.class); if (table == null) { tableName = CaseFormatUtils.camelToUnderScore(entityClass.getSimpleName()); } else { tableName = table.name(); } ///~~~~~~~~~~~~~~~~~~~~~~ idField = AnnotationUtils.findDeclaredFieldWithAnnoation(Id.class, entityClass); versionField = AnnotationUtils.findDeclaredFieldWithAnnoation(Version.class, entityClass); ReflectionUtils.doWithFields(entityClass, new FieldCallback() { @Override public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException { columnFields.add(field); } }, new FieldFilter() { @Override public boolean matches(Field field) { if (Modifier.isStatic(field.getModifiers()) || Modifier.isFinal(field.getModifiers())) { return false; } for (Annotation annotation : field.getAnnotations()) { if (Transient.class.isAssignableFrom(annotation.getClass()) || Id.class.isAssignableFrom(annotation.getClass())) { return false; } } return true; } }); }
From source file:org.codehaus.marmalade.el.commonsEl.CommonsElExpressionEvaluator.java
private Object set(Object target, String property, Object value) throws ExpressionEvaluationException { Object result = null;/* w w w . j a v a2s. co m*/ try { Method method = findMethod(target, property, value); if (method != null) { result = method.invoke(target, new Object[] { value }); } else { Field field = target.getClass().getField(property); int fieldModifiers = field.getModifiers(); if (Modifier.isPublic(fieldModifiers) && !Modifier.isFinal(fieldModifiers) && field.getType().isAssignableFrom(value.getClass())) { field.set(target, value); result = value; } else { throw new ExpressionEvaluationException( "Cannot set property: \'" + property + "\' on target: " + target); } } } catch (IllegalArgumentException e) { throw new ExpressionEvaluationException("Error assigning value to property field.", e); } catch (IllegalAccessException e) { throw new ExpressionEvaluationException("Error assigning value to property field.", e); } catch (SecurityException e) { throw new ExpressionEvaluationException("Error assigning value to property field.", e); } catch (NoSuchFieldException e) { throw new ExpressionEvaluationException("Property not found: \'" + property + "\' on target: " + target, e); } catch (InvocationTargetException e) { throw new ExpressionEvaluationException("Error assigning value via property method.", e); } return result; }
From source file:org.apache.openjpa.jdbc.meta.DiscriminatorMappingInfo.java
/** * Synchronize internal information with the mapping data for the given * discriminator./*from w ww . ja va2 s . c om*/ */ public void syncWith(Discriminator disc) { clear(false); // set io before syncing cols setColumnIO(disc.getColumnIO()); syncColumns(disc, disc.getColumns(), disc.getValue() != null && !(disc.getValue() instanceof String)); syncIndex(disc, disc.getIndex()); if (disc.getValue() == Discriminator.NULL) _value = "null"; else if (disc.getValue() != null) _value = disc.getValue().toString(); if (disc.getStrategy() == null || disc.getStrategy() instanceof SuperclassDiscriminatorStrategy) return; // explicit discriminator strategy if: // - unmapped class and discriminator is mapped // - final base class and discriminator is mapped // - table-per-class subclass and discriminator is mapped // - mapped subclass and doesn't rely on superclass discriminator // - mapped base class and doesn't use value-map strategy with value // and isn't a final class that uses the final strategy ClassMapping cls = disc.getClassMapping(); String strat = disc.getStrategy().getAlias(); boolean sync = false; if (!cls.isMapped() || (cls.getJoinablePCSuperclassMapping() != null && Modifier.isFinal(cls.getDescribedType().getModifiers())) || (cls.getJoinablePCSuperclassMapping() == null && cls.getMappedPCSuperclassMapping() != null)) sync = !NoneDiscriminatorStrategy.ALIAS.equals(strat); else sync = cls.getJoinablePCSuperclassMapping() != null || _value == null || !ValueMapDiscriminatorStrategy.ALIAS.equals(strat); if (sync) setStrategy(strat); }
From source file:org.pentaho.platform.engine.security.acls.PentahoAclEntry.java
private static void initializePermissionsArray() { if (null == PentahoAclEntry.validPermissions) { int maxPower = -1; Field[] fields = IPentahoAclEntry.class.getDeclaredFields(); for (Field field : fields) { // if field is public static final int if (int.class == field.getType() && Modifier.isPublic(field.getModifiers()) && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()) && field.getName().startsWith(PERMISSION_PREFIX)) { if (PentahoAclEntry.logger.isDebugEnabled()) { PentahoAclEntry.logger.debug("Candidate field: " + field.getName()); //$NON-NLS-1$ }/*w ww .ja va2 s . c o m*/ // power of two (0-based) double powerOfTwo = -1; try { powerOfTwo = Math.log(field.getInt(null)) / Math.log(2); } catch (IllegalArgumentException e) { //ignore } catch (IllegalAccessException e) { //ignore } // if log calculation results in an integer if (powerOfTwo == (int) powerOfTwo) { if (powerOfTwo > maxPower) { if (PentahoAclEntry.logger.isDebugEnabled()) { PentahoAclEntry.logger.debug("Found new power of two."); //$NON-NLS-1$ } maxPower = (int) powerOfTwo; } } } } if (PentahoAclEntry.logger.isDebugEnabled()) { PentahoAclEntry.logger.debug("Max power of two: " + maxPower); //$NON-NLS-1$ } int numberOfPermutations = (int) Math.pow(2, maxPower + 1); PentahoAclEntry.validPermissions = new int[numberOfPermutations + 1]; for (int i = 0; i < numberOfPermutations; i++) { PentahoAclEntry.validPermissions[i] = i; } PentahoAclEntry.validPermissions[PentahoAclEntry.validPermissions.length - 1] = PentahoAclEntry.PERM_FULL_CONTROL; } }
From source file:org.jboss.dashboard.ui.config.components.factory.FactoryComponentFormatter.java
protected void serviceProperties(Component component) { Set properties = new TreeSet(); if (component.getScope().equals(Component.SCOPE_GLOBAL) || component.getScope().equals(Component.SCOPE_VOLATILE)) { Object obj = null;//from ww w .j a v a2 s. co m try { obj = component.getObject(); } catch (LookupException e) { log.error("Error: ", e); } if (obj instanceof Map) { properties.addAll(((Map) obj).keySet()); } else if (obj instanceof List) { for (int i = 0; i < ((List) obj).size(); i++) { properties.add(new Integer(i)); } } else { Method[] methods = obj.getClass().getMethods(); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; String propertyName = getPropertyName(method); if (propertyName != null && isGetter(method)) properties.add(propertyName); } Field[] fields = obj.getClass().getFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (Modifier.isPublic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) { properties.add(field.getName()); } } } if (!properties.isEmpty()) { String propertyType = ""; String fullPropertyType = ""; renderFragment("propertiesStart"); int indexStyle = 0; for (Iterator it = properties.iterator(); it.hasNext();) { indexStyle++; Object property = it.next(); Object value = null; if (obj instanceof Map) { value = ((Map) obj).get(property); propertyType = "String"; fullPropertyType = "java.lang.String []"; } else if (obj instanceof List) { value = ((List) obj).get(((Integer) property).intValue()); propertyType = "String"; fullPropertyType = "java.lang.String []"; } else { String propertyName = (String) property; // Find a getter. String propertyAccessorSuffix = Character.toUpperCase(propertyName.charAt(0)) + (propertyName.length() > 1 ? propertyName.substring(1) : ""); String getterName = "get" + propertyAccessorSuffix; String booleanGetterName = "is" + propertyAccessorSuffix; Method getter = null; Class propertyClass = null; try { getter = obj.getClass().getMethod(getterName, new Class[0]); if (getter != null) try { value = getter.invoke(obj, new Object[0]); propertyClass = getter.getReturnType(); } catch (IllegalAccessException e) { log.error("Error:", e); } catch (InvocationTargetException e) { log.error("Error:", e); } } catch (NoSuchMethodException e) { log.debug("No getter " + getterName + " found."); try { getter = obj.getClass().getMethod(booleanGetterName, new Class[0]); if (getter != null) try { value = getter.invoke(obj, new Object[0]); propertyClass = getter.getReturnType(); } catch (IllegalAccessException iae) { log.error("Error:", iae); } catch (InvocationTargetException ite) { log.error("Error:", ite); } } catch (NoSuchMethodException e1) { log.debug("No getter " + booleanGetterName + " found."); } } if (propertyClass == null) { //Find field try { Field field = obj.getClass().getField(propertyName); if (field != null) { value = field.get(obj); propertyClass = field.getType(); } } catch (NoSuchFieldException e) { log.error("Error: ", e); } catch (IllegalAccessException e) { log.error("Error: ", e); } } if (propertyClass.isArray()) { String componentTypeClass = propertyClass.getComponentType().getName(); if (componentTypeClass.indexOf('.') != -1) { propertyType = componentTypeClass.substring(componentTypeClass.lastIndexOf('.') + 1) + "[]"; } else { propertyType = componentTypeClass + " []"; } fullPropertyType = componentTypeClass + " []"; } else if (propertyClass.isPrimitive()) { propertyType = propertyClass.getName(); fullPropertyType = propertyType; } else { if (propertyClass.getName().indexOf('.') != -1) { propertyType = propertyClass.getName() .substring(propertyClass.getName().lastIndexOf('.') + 1); } else { propertyType = propertyClass.getName(); } fullPropertyType = propertyClass.getName(); } } if (value == null) { value = ""; } else if (value instanceof String || value instanceof Integer || value instanceof Short || value instanceof Character || value instanceof Long || value instanceof Byte || value instanceof Boolean || value instanceof Float || value instanceof Double || value.getClass().isPrimitive()) { } else if (value.getClass().isArray()) { int length = Array.getLength(value); String componentType = value.getClass().getComponentType().getName(); value = componentType + " [" + length + "]"; } else { value = value.getClass().getName(); } Map configuredValues = component.getComponentConfiguredProperties(); List configuredValue = (List) configuredValues.get(property); StringBuffer sb = new StringBuffer(); if (configuredValue != null) for (int i = 0; i < configuredValue.size(); i++) { PropertyChangeProcessingInstruction instruction = (PropertyChangeProcessingInstruction) configuredValue .get(i); if (instruction instanceof PropertyAddProcessingInstruction) { sb.append("\n+").append(instruction.getPropertyValue()); } else if (instruction instanceof PropertySubstractProcessingInstruction) { sb.append("\n-").append(instruction.getPropertyValue()); } else if (instruction instanceof PropertySetProcessingInstruction) { sb.setLength(0); sb.append(" ").append(instruction.getPropertyValue()); } } setAttribute("configuredValue", StringUtils.replace(sb.toString(), ",", ", ")); setAttribute("propertyType", propertyType); setAttribute("fullPropertyType", fullPropertyType); setAttribute("propertyName", property); setAttribute("propertyValue", value); setAttribute("estilo", indexStyle % 2 == 0 ? "skn-even_row" : "skn-odd_row"); renderFragment("outputProperty"); } renderFragment("propertiesEnd"); } } }
From source file:org.xulux.utils.BooleanUtilsTest.java
public void testConstructor() { assertNotNull(new BooleanUtils()); Constructor[] cons = BooleanUtils.class.getDeclaredConstructors(); assertEquals(1, cons.length);// ww w. j a v a 2 s . com assertEquals(true, Modifier.isPublic(cons[0].getModifiers())); assertEquals(true, Modifier.isPublic(BooleanUtils.class.getModifiers())); assertEquals(false, Modifier.isFinal(BooleanUtils.class.getModifiers())); }
From source file:code.elix_x.excore.utils.nbt.mbt.encoders.NBTClassEncoder.java
public void populate(MBT mbt, NBTTagCompound nbt, Object o) { Class clazz = o.getClass();//from ww w.ja v a 2s . com try { while (clazz != null && clazz != Object.class) { if (!clazz.isAnnotationPresent(MBTIgnore.class)) { for (Field field : clazz.getDeclaredFields()) { if (!field.isAnnotationPresent(MBTIgnore.class)) { field.setAccessible(true); if (nbt.hasKey(field.getName())) { if (encodeStatic || !Modifier.isStatic(field.getModifiers())) { if (Modifier.isFinal(field.getModifiers())) { if (encodeFinal) { Field modifiers = Field.class.getDeclaredField("modifiers"); modifiers.setAccessible(true); modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL); if (field.getGenericType() instanceof ParameterizedType) { Type[] types = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments(); Class[] clas = new Class[] {}; for (Type type : types) { if (type instanceof Class) { clas = ArrayUtils.add(clas, (Class) type); } } field.set(o, mbt.fromNBT(nbt.getTag(field.getName()), field.getType(), clas)); } else { field.set(o, mbt.fromNBT(nbt.getTag(field.getName()), field.getType())); } } } else { if (field.getGenericType() instanceof ParameterizedType) { Type[] types = ((ParameterizedType) field.getGenericType()) .getActualTypeArguments(); Class[] clas = new Class[] {}; for (Type type : types) { if (type instanceof Class) { clas = ArrayUtils.add(clas, (Class) type); } } field.set(o, mbt.fromNBT(nbt.getTag(field.getName()), field.getType(), clas)); } else { field.set(o, mbt.fromNBT(nbt.getTag(field.getName()), field.getType())); } } } } } } } clazz = encodeSuper ? clazz.getSuperclass() : Object.class; } } catch (IllegalArgumentException e) { Throwables.propagate(e); } catch (IllegalAccessException e) { Throwables.propagate(e); } catch (NoSuchFieldException e) { Throwables.propagate(e); } catch (SecurityException e) { Throwables.propagate(e); } }
From source file:com.geodevv.testing.irmina.IrminaContextLoader.java
private boolean isStaticNonPrivateAndNonFinal(Class<?> clazz) { Assert.notNull(clazz, "Class must not be null"); int modifiers = clazz.getModifiers(); return (Modifier.isStatic(modifiers) && !Modifier.isPrivate(modifiers) && !Modifier.isFinal(modifiers)); }
From source file:com.ankang.report.pool.AbstractReportAliasPool.java
private void mountPrams(LinkedHashMap<String, Class<?>> paramsType, Method method) { Class<?>[] parameterTypes = method.getParameterTypes(); Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < parameterTypes.length; i++) { if (annotations.length < i) { throw new ReportException( "Please add an effective note for the argument, such as: HTTPParam, RequestParam"); }//w w w . java 2 s . c om if ((ReportRequest.class.isAssignableFrom(parameterTypes[i])) || (!parameterTypes[i].isPrimitive() && !parameterTypes[i].toString().matches("^.+java\\..+$") && parameterTypes[i].toString().matches("^class.+$"))) { Field[] fields = parameterTypes[i].getDeclaredFields(); for (Field field : fields) { if (!Modifier.isFinal(field.getModifiers()) || !Modifier.isStatic(field.getModifiers())) { paramsType.put(field.getName(), field.getType()); } } } else { if (annotations.length >= i && annotations[i].length > 0) { paramsType.put(matchPrams(annotations[i][0]), parameterTypes[i]); } } } }
From source file:org.apache.cocoon.forms.datatype.EnumSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { try {//from ww w. j a v a2 s .c o m contentHandler.startElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL, XMLUtils.EMPTY_ATTRIBUTES); // Create void element if (nullable) { AttributesImpl voidAttrs = new AttributesImpl(); voidAttrs.addCDATAAttribute("value", ""); contentHandler.startElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL, voidAttrs); if (this.nullText != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.startElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(nullText.toCharArray(), 0, nullText.length()); contentHandler.endElement(FormsConstants.I18N_NS, TEXT_EL, FormsConstants.I18N_PREFIX_COLON + TEXT_EL); contentHandler.endElement(FormsConstants.INSTANCE_NS, LABEL_EL, FormsConstants.INSTANCE_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(FormsConstants.INSTANCE_NS, ITEM_EL, FormsConstants.INSTANCE_PREFIX_COLON + ITEM_EL); } // Test if we have an apache enum class boolean apacheEnumDone = false; if (Enum.class.isAssignableFrom(clazz)) { Iterator iter = EnumUtils.iterator(clazz); if (iter != null) { apacheEnumDone = true; while (iter.hasNext()) { Enum element = (Enum) iter.next(); String stringValue = clazz.getName() + "." + element.getName(); generateItem(contentHandler, stringValue); } } } // If it's not an apache enum or we didn't manage to read the enum list, then proceed with common method. if (!apacheEnumDone) { Field fields[] = clazz.getDeclaredFields(); for (int i = 0; i < fields.length; ++i) { int mods = fields[i].getModifiers(); if (Modifier.isPublic(mods) && Modifier.isStatic(mods) && Modifier.isFinal(mods) && fields[i].get(null).getClass().equals(clazz)) { String stringValue = clazz.getName() + "." + fields[i].getName(); generateItem(contentHandler, stringValue); } } } // End the selection-list contentHandler.endElement(FormsConstants.INSTANCE_NS, SELECTION_LIST_EL, FormsConstants.INSTANCE_PREFIX_COLON + SELECTION_LIST_EL); } catch (Exception e) { throw new SAXException("Got exception trying to get enum's values", e); } }