List of usage examples for java.lang.reflect Modifier STATIC
int STATIC
To view the source code for java.lang.reflect Modifier STATIC.
Click Source Link
From source file:org.gvnix.addon.jpa.addon.query.JpaQueryMetadata.java
/** * Generate method to get the orderBy information * //w ww. j a va2 s.com * @param fieldsToProcess * @return */ private MethodMetadata getOrderByMethod(Map<FieldMetadata, AnnotationMetadata> fieldsToProcess) { // public Map<String,List<String>> getJpaQueryOrderBy() { // Check if a method with the same signature already exists in the // target type final MethodMetadata method = methodExists(GET_ORDERBY_DEFINITION, new ArrayList<AnnotatedJavaType>()); if (method != null) { // If it already exists, just return the method and omit its // generation via the ITD return method; } // Define method annotations (none in this case) List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(); // Define method throws types (none in this case) List<JavaType> throwsTypes = new ArrayList<JavaType>(); // Define method parameter types (none in this case) List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>(); // Define method parameter names (none in this case) List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(); // Create the method body InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); buildGetOrderByDefinitionMethodBody(bodyBuilder, fieldsToProcess); // Use the MethodMetadataBuilder for easy creation of MethodMetadata MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, GET_ORDERBY_DEFINITION, MAP_STRING_LIST_STRING, parameterTypes, parameterNames, bodyBuilder); methodBuilder.setAnnotations(annotations); methodBuilder.setThrowsTypes(throwsTypes); return methodBuilder.build(); // Build and return a MethodMetadata // instance }
From source file:org.disciple.db.Abatis.java
/** * JsonString//from w w w. ja va 2 s .c om * * @param jsonStr JSON String * @param beanClass Bean class * @param basePackage Base package name which includes all Bean classes * @return Object Bean * @throws Exception */ @SuppressWarnings({ "rawtypes", "unchecked" }) private Object parse(String jsonStr, Class beanClass, String basePackage) throws Exception { Object obj = null; JSONObject jsonObj = new JSONObject(jsonStr); // Check bean object if (beanClass == null) { Log.d(TAG, "Bean class is null"); return null; } // Read Class member fields Field[] props = beanClass.getDeclaredFields(); if (props == null || props.length == 0) { Log.d(TAG, "Class" + beanClass.getName() + " has no fields"); return null; } // Create instance of this Bean class obj = beanClass.newInstance(); // Set value of each member variable of this object for (int i = 0; i < props.length; i++) { String fieldName = props[i].getName(); // Skip public and static fields if (props[i].getModifiers() == (Modifier.PUBLIC | Modifier.STATIC)) { continue; } // Date Type of Field Class type = props[i].getType(); String typeName = type.getName(); // Check for Custom type if (typeName.equals("int")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getInt(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("long")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getLong(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("java.lang.String")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getString(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (typeName.equals("double")) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { m.invoke(obj, jsonObj.getDouble(fieldName)); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); } } else if (type.getName().equals(List.class.getName()) || type.getName().equals(ArrayList.class.getName())) { // Find out the Generic String generic = props[i].getGenericType().toString(); if (generic.indexOf("<") != -1) { String genericType = generic.substring(generic.lastIndexOf("<") + 1, generic.lastIndexOf(">")); if (genericType != null) { JSONArray array = null; try { array = jsonObj.getJSONArray(fieldName); } catch (Exception ex) { Log.d(TAG, ex.getMessage()); array = null; } if (array == null) { continue; } ArrayList arrayList = new ArrayList(); for (int j = 0; j < array.length(); j++) { arrayList.add(parse(array.getJSONObject(j).toString(), Class.forName(genericType), basePackage)); } // Set value Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); m.invoke(obj, arrayList); } } else { // No generic defined generic = null; } } else if (typeName.startsWith(basePackage)) { Class[] parms = { type }; Method m = beanClass.getDeclaredMethod(getBeanMethodName(fieldName, 1), parms); m.setAccessible(true); // Set value try { JSONObject customObj = jsonObj.getJSONObject(fieldName); if (customObj != null) { m.invoke(obj, parse(customObj.toString(), type, basePackage)); } } catch (JSONException ex) { Log.d(TAG, ex.getMessage()); } } else { // Skip Log.d(TAG, "Field " + fieldName + "#" + typeName + " is skip"); } } return obj; }
From source file:org.jaffa.qm.finder.apis.ExcelExportService.java
/** * Invokes the query method on the input service class passing the given criteria. * * @param criteriaClassName/*from w w w . java2s . c o m*/ * the name of the criteria class. * @param criteriaObject * criteria as a JSON structure. * @param serviceClassName * the name of the service class that should contain the method * 'public AGraphDataObject[] query(AGraphCriteria criteria)'. * @return the output from the query invocation. * @throws ClassNotFoundException * if either the criteria or the service class are invalid. * @throws NoSuchMethodException * if the 'public AGraphDataObject[] query(AGraphCriteria * criteria)' is not found on the service class. * @throws InstantiationException * if an error occurs in instantiating the service class. * @throws IllegalAccessException * if the query method is not accessible. * @throws IllegalArgumentException * if the input is invalid. * @throws InvocationTargetException * if an error occurs during invocation of the query method. */ private static Object[] invokeQueryService(String criteriaClassName, String criteriaObject, String serviceClassName, String serviceClassMethodName) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { if (log.isDebugEnabled()) log.debug("Invoking query service '" + serviceClassName + "' passing an instance of '" + criteriaClassName + "' having the criteria '" + criteriaObject + '\''); // convert the JSON criteria into a Java object Object criteria = jsonToBean(criteriaObject, criteriaClassName); // If no method name supplied, use default method "query" if (serviceClassMethodName == null || serviceClassMethodName.equals("")) serviceClassMethodName = "query"; // find the 'public AGraphDataObject[] query(AGraphCriteria criteria)' // method on the service class Class serviceClass = Class.forName(serviceClassName); Method m = serviceClass.getMethod(serviceClassMethodName, criteria.getClass()); // invoke the query method on the service Object service = m.getModifiers() == Modifier.STATIC ? null : serviceClass.newInstance(); Object[] output = null; if (m.getReturnType().isArray()) { output = (Object[]) m.invoke(service, criteria); } else { Object gqr = m.invoke(service, criteria); output = (Object[]) BeanHelper.getField(gqr, "graphs"); } if (log.isDebugEnabled()) log.debug("Query output: " + Arrays.toString(output)); return output; }
From source file:de.micromata.genome.util.bean.PrivateBeanUtils.java
/** * Find nested implementing./*from ww w .ja va 2 s . com*/ * * @param <T> the generic type * @param bean the bean * @param clazz the clazz * @param iface the iface * @param result the result * @param depth the depth * @param includeStatics the include statics */ @SuppressWarnings("unchecked") public static <T> void findNestedImplementing(Object bean, Class<?> clazz, Class<T> iface, List<T> result, int depth, boolean includeStatics) { if (iface.isAssignableFrom(clazz) == true) { result.add((T) bean); } if (depth == 0) { return; } for (Field f : clazz.getDeclaredFields()) { if (includeStatics == false && (f.getModifiers() & Modifier.STATIC) == Modifier.STATIC) { continue; } Object o = readField(bean, f); findNestedImplementing(o, iface, result, depth - 1, includeStatics); } if (clazz == Object.class || clazz.getSuperclass() == null) { return; } findNestedImplementing(bean, clazz.getSuperclass(), iface, result, depth, includeStatics); }
From source file:de.micromata.tpsb.doc.TpsbEnvUtils.java
public static boolean isAvailableForTpsbConsole(MethodInfo mi) { if (getAnnotation(mi, TpsbIgnore.class.getSimpleName()) != null) { return false; }/*from w ww. j a v a2 s .c om*/ if ((mi.getModifier() & Modifier.PUBLIC) != Modifier.PUBLIC) { return false; } if ((mi.getModifier() & Modifier.STATIC) == Modifier.STATIC) { return false; } return true; }
From source file:com.sworddance.beans.ProxyMapperImpl.java
/** * @param method//w w w .ja v a2 s .c o m * @param args * @param actualObject * @return * @throws IllegalAccessException * @throws InvocationTargetException */ private Object doInvoke(Method method, Object[] args) throws IllegalAccessException, InvocationTargetException { O actualObject; if ((method.getModifiers() & Modifier.STATIC) != Modifier.STATIC) { // not a static method actualObject = getRealObject(true, "need object to call a non-static method ", this, " method=", method, "(", join(args), ")"); } else { actualObject = null; } try { return method.invoke(actualObject, args); } catch (RuntimeException e) { // would like to log or annotate somehow .. // changing type of exception is bad so we will throw as an exception that will normally be unwrapped. throw new InvocationTargetException(e, this + " method=" + method + "(" + join(args) + ")"); } }
From source file:org.gvnix.addon.jpa.addon.audit.JpaAuditMetadata.java
/** * @return revision item class definition *//*from ww w . j a va 2s . c om*/ private ClassOrInterfaceTypeDetails getRevisionClass() { // Check class exists ClassOrInterfaceTypeDetails innerClass = governorTypeDetails.getDeclaredInnerType(revisonItemType); if (innerClass != null) { // If class exists (already pushed-in) we can do nothing return innerClass; } // Create class builder for inner class ClassOrInterfaceTypeDetailsBuilder classBuilder = new ClassOrInterfaceTypeDetailsBuilder(getId(), Modifier.PUBLIC + Modifier.STATIC, revisonItemType, PhysicalTypeCategory.CLASS); // Add revisionLog-provider required artifacts revisionLogBuilder.addCustomArtifactToRevisionItem(classBuilder); // Add Revision item common methods classBuilder.addMethod(createRevisionItemGetItemMethod()); classBuilder.addMethod(createRevisionItemGetRevisionNumberMethod()); classBuilder.addMethod(createRevisionItemGetRevisionUserMethod()); classBuilder.addMethod(createRevisionItemGetRevisionDateMethod()); classBuilder.addMethod(createRevisionItemIsCreateMethod()); classBuilder.addMethod(createRevisionItemIsUpdateMethod()); classBuilder.addMethod(createRevisionItemIsDeleteMethod()); classBuilder.addMethod(createRevisionItemGetTypeMethod()); // Build class definition from builder return classBuilder.build(); }
From source file:com.bosscs.spark.commons.utils.Utils.java
/** * Returns an instance clone./*from www. j av a 2 s . c o m*/ * this method gets every class property by reflection, including its parents properties * @param t * @param <T> * @return T object. */ public static <T> T cloneObjectWithParents(T t) throws IllegalAccessException, InstantiationException { T clone = (T) t.getClass().newInstance(); List<Field> allFields = new ArrayList<>(); Class parentClass = t.getClass().getSuperclass(); while (parentClass != null) { Collections.addAll(allFields, parentClass.getDeclaredFields()); parentClass = parentClass.getSuperclass(); } Collections.addAll(allFields, t.getClass().getDeclaredFields()); for (Field field : allFields) { int modifiers = field.getModifiers(); //We skip final and static fields if ((Modifier.FINAL & modifiers) != 0 || (Modifier.STATIC & modifiers) != 0) { continue; } field.setAccessible(true); Object value = field.get(t); if (Collection.class.isAssignableFrom(field.getType())) { Collection collection = (Collection) field.get(clone); if (collection == null) { collection = (Collection) field.get(t).getClass().newInstance(); } collection.addAll((Collection) field.get(t)); value = collection; } else if (Map.class.isAssignableFrom(field.getType())) { Map clonMap = (Map) field.get(t).getClass().newInstance(); clonMap.putAll((Map) field.get(t)); value = clonMap; } field.set(clone, value); } return clone; }
From source file:org.gvnix.addon.jpa.addon.audit.providers.envers.EnversRevisionLogMetadataBuilder.java
/** * @return creates getAuditReader() method */// ww w . j av a2 s . c om private MethodMetadata getAuditReaderStaticMethod() { return commonGetAuditReaderStaticMethod(context, AUDIT_READER_STATIC_METHOD, Modifier.PUBLIC + Modifier.STATIC, "return %s.get(entityManager());", null); }
From source file:org.eclipse.wb.internal.swing.model.property.editor.accelerator.KeyStrokePropertyEditor.java
/** * Prepares {@link Map}'s for key code/name conversion. *///from w w w . j a v a 2 s .com private static synchronized void prepareKeyMaps() { if (m_keyCodeToName == null) { m_keyFields = Lists.newArrayList(); m_keyCodeToName = Maps.newTreeMap(); m_keyNameToCode = Maps.newTreeMap(); // add fields try { int expected_modifiers = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; Field[] fields = KeyEvent.class.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (field.getModifiers() == expected_modifiers && field.getType() == Integer.TYPE && field.getName().startsWith("VK_")) { String name = field.getName().substring(3); Integer value = (Integer) field.get(null); m_keyFields.add(name); m_keyCodeToName.put(value, name); m_keyNameToCode.put(name, value); } } } catch (Throwable e) { DesignerPlugin.log(e); } } }