List of usage examples for java.lang Class getDeclaredField
@CallerSensitive public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
From source file:com.github.gekoh.yagen.ddl.TableConfig.java
private static JoinColumn getJoinColumn(AccessibleObject fieldOrMethod) { if (fieldOrMethod.isAnnotationPresent(JoinColumn.class)) { return fieldOrMethod.getAnnotation(JoinColumn.class); }/*from w w w .jav a 2 s. co m*/ if (fieldOrMethod.isAnnotationPresent(OneToMany.class)) { OneToMany o2m = fieldOrMethod.getAnnotation(OneToMany.class); try { if (fieldOrMethod.getAnnotation(JoinColumn.class) != null) { return fieldOrMethod.getAnnotation(JoinColumn.class); } else if (fieldOrMethod.isAnnotationPresent(JoinColumns.class)) { return null; // TODO: implement compound FK } else { Class<?> targetEntityClass = MappingUtils.determineTargetEntity(fieldOrMethod, o2m.targetEntity()); return targetEntityClass.getDeclaredField(o2m.mappedBy()).getAnnotation(JoinColumn.class); } } catch (NoSuchFieldException e) { throw new IllegalStateException(e); } } return null; }
From source file:com.ricemap.spateDB.operations.RangeQuery.java
/** * Performs a range query using MapReduce * /*w w w . j a v a 2 s. c o m*/ * @param fs * @param inputFile * @param queryRange * @param shape * @param output * @return * @throws IOException */ public static long rangeQueryMapReduce(FileSystem fs, Path inputFile, Path userOutputPath, Shape queryShape, Shape shape, boolean overwrite, boolean background, QueryInput query) throws IOException { JobConf job = new JobConf(FileMBR.class); FileSystem outFs = inputFile.getFileSystem(job); Path outputPath = userOutputPath; if (outputPath == null) { do { outputPath = new Path( inputFile.toUri().getPath() + ".rangequery_" + (int) (Math.random() * 1000000)); } while (outFs.exists(outputPath)); } else { if (outFs.exists(outputPath)) { if (overwrite) { outFs.delete(outputPath, true); } else { throw new RuntimeException("Output path already exists and -overwrite flag is not set"); } } } job.setJobName("RangeQuery"); job.setClass(SpatialSite.FilterClass, RangeFilter.class, BlockFilter.class); RangeFilter.setQueryRange(job, queryShape); // Set query range for // filter ClusterStatus clusterStatus = new JobClient(job).getClusterStatus(); job.setNumMapTasks(clusterStatus.getMaxMapTasks() * 5); job.setNumReduceTasks(3); // Decide which map function to use depending on how blocks are indexed // And also which input format to use if (SpatialSite.isRTree(fs, inputFile)) { // RTree indexed file LOG.info("Searching an RTree indexed file"); job.setInputFormat(RTreeInputFormat.class); } else { // A file with no local index LOG.info("Searching a non local-indexed file"); job.setInputFormat(ShapeInputFormat.class); } GlobalIndex<Partition> gIndex = SpatialSite.getGlobalIndex(fs, inputFile); // if (gIndex != null && gIndex.isReplicated()){ // job.setMapperClass(RangeQueryMap.class); Class<?> OutputKey = NullWritable.class; try { Class<?> c = shape.getClass(); Field f = c.getDeclaredField(query.field); f.setAccessible(true); if (f.getType().equals(Integer.TYPE)) { OutputKey = IntWritable.class; } else if (f.getType().equals(Double.TYPE)) { OutputKey = DoubleWritable.class; } else if (f.getType().equals(Long.TYPE)) { OutputKey = LongWritable.class; } } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } job.setMapOutputKeyClass(OutputKey); switch (query.type) { case Distinct: job.setMapperClass(DistinctQueryMap.class); job.setReducerClass(DistinctQueryReduce.class); job.setMapOutputValueClass(NullWritable.class); break; case Distribution: job.setMapperClass(DistributionQueryMap.class); job.setReducerClass(DistributionQueryReduce.class); job.setMapOutputValueClass(IntWritable.class); break; default: break; } // } // else // job.setMapperClass(RangeQueryMapNoDupAvoidance.class); // Set query range for the map function job.set(QUERY_SHAPE_CLASS, queryShape.getClass().getName()); job.set(QUERY_SHAPE, queryShape.toText(new Text()).toString()); job.set(QUERY_FIELD, query.field); // Set shape class for the SpatialInputFormat SpatialSite.setShapeClass(job, shape.getClass()); job.setOutputFormat(TextOutputFormat.class); ShapeInputFormat.setInputPaths(job, inputFile); TextOutputFormat.setOutputPath(job, outputPath); // Submit the job if (!background) { RunningJob runningJob = JobClient.runJob(job); Counters counters = runningJob.getCounters(); Counter outputRecordCounter = counters.findCounter(Task.Counter.MAP_OUTPUT_RECORDS); final long resultCount = outputRecordCounter.getValue(); // If outputPath not set by user, automatically delete it if (userOutputPath == null) outFs.delete(outputPath, true); return resultCount; } else { JobClient jc = new JobClient(job); lastRunningJob = jc.submitJob(job); return -1; } }
From source file:org.thoughtland.xlocation.Util.java
public static Activity getActivity() { // public static ActivityManagerService self() // frameworks/base/services/java/com/android/server/am/ActivityManagerService.java Object activity = null;// w w w . j a v a 2 s . c om try { Class<?> atClazz = Class.forName("android.app.ActivityThread"); Object activityThread = atClazz.getMethod("currentActivityThread").invoke(null); Field fActivities = atClazz.getDeclaredField("mActivities"); fActivities.setAccessible(true); Map<?, ?> activities = (Map<?, ?>) fActivities.get(activityThread); Object acr = activities.values().toArray()[0]; Field fActivity = acr.getClass().getDeclaredField("activity"); fActivity.setAccessible(true); activity = fActivity.get(acr); } catch (Throwable e) { } return (Activity) activity; }
From source file:info.guardianproject.netcipher.web.WebkitProxy.java
@TargetApi(21) // for android.util.ArrayMap methods @SuppressWarnings("rawtypes") private static boolean setWebkitProxyLollipop(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); try {// w w w.j ava 2 s. c om Class applictionClass = Class.forName("android.app.Application"); Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk"); mLoadedApkField.setAccessible(true); Object mloadedApk = mLoadedApkField.get(appContext); Class loadedApkClass = Class.forName("android.app.LoadedApk"); Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers"); mReceiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk); for (Object receiverMap : receivers.values()) { for (Object receiver : ((ArrayMap) receiverMap).keySet()) { Class clazz = receiver.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); onReceiveMethod.invoke(receiver, appContext, intent); } } } return true; } catch (ClassNotFoundException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (NoSuchFieldException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (IllegalAccessException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (NoSuchMethodException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (InvocationTargetException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } return false; }
From source file:info.guardianproject.netcipher.webkit.WebkitProxy.java
@TargetApi(21) // for android.util.ArrayMap methods @SuppressWarnings("rawtypes") private static boolean setWebkitProxyLollipop(Context appContext, String host, int port) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", Integer.toString(port)); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", Integer.toString(port)); try {/*from ww w .ja v a2 s .c o m*/ Class applictionClass = Class.forName("android.app.Application"); Field mLoadedApkField = applictionClass.getDeclaredField("mLoadedApk"); mLoadedApkField.setAccessible(true); Object mloadedApk = mLoadedApkField.get(appContext); Class loadedApkClass = Class.forName("android.app.LoadedApk"); Field mReceiversField = loadedApkClass.getDeclaredField("mReceivers"); mReceiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) mReceiversField.get(mloadedApk); for (Object receiverMap : receivers.values()) { for (Object receiver : ((ArrayMap) receiverMap).keySet()) { Class clazz = receiver.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); onReceiveMethod.invoke(receiver, appContext, intent); } } } return true; } catch (ClassNotFoundException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (NoSuchFieldException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (IllegalAccessException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (NoSuchMethodException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } catch (InvocationTargetException e) { Log.d("ProxySettings", "Exception setting WebKit proxy on Lollipop through ProxyChangeListener: " + e.toString()); } return false; }
From source file:com.github.hateoas.forms.spring.SpringActionDescriptor.java
private static Field getFormAnnotated(final String fieldName, Class<?> entity) throws NoSuchFieldException { while (entity != null) { try {/*www . j a v a 2s . co m*/ Field field = entity.getDeclaredField(fieldName); field.setAccessible(true); if (field.isAnnotationPresent(Select.class) || field.isAnnotationPresent(Input.class)) { return field; } break; } catch (NoSuchFieldException e) { entity = entity.getSuperclass(); } } return null; }
From source file:info.papdt.blacklight.support.Utility.java
public static View findActionSpinner(Activity activity) { ActionBar action = activity.getActionBar(); // Get ActionBarImpl class for ActionView object // Then get spinner from ActionView try {/*from w w w. j a v a2 s . c o m*/ Class<?> clazz = Class.forName("com.android.internal.app.ActionBarImpl"); Field f = clazz.getDeclaredField("mActionView"); f.setAccessible(true); Object actionView = f.get(action); clazz = Class.forName("com.android.internal.widget.ActionBarView"); f = clazz.getDeclaredField("mSpinner"); f.setAccessible(true); return (View) f.get(actionView); } catch (Exception e) { if (DEBUG) { Log.e(TAG, "Failed to find spinner"); Log.e(TAG, Log.getStackTraceString(e)); } return null; } }
From source file:org.thoughtland.xlocation.Util.java
public static Context getActivityContext() { // public static ActivityManagerService self() // frameworks/base/services/java/com/android/server/am/ActivityManagerService.java try {/*from w w w. java2 s . c om*/ Class<?> cam = Class.forName("com.android.server.am.ActivityManagerService"); Object am = cam.getMethod("self").invoke(null); if (am == null) return null; Field mContext = cam.getDeclaredField("mContext"); mContext.setAccessible(true); return (Context) mContext.get(am); } catch (Throwable e) { //Util.bug(null, ex); return null; } }
From source file:info.guardianproject.netcipher.web.WebkitProxy.java
@TargetApi(19) private static boolean setKitKatProxy(String appClass, Context appContext, String host, int port) { //Context appContext = webView.getContext().getApplicationContext(); if (host != null) { System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); }/*from ww w. j ava2 s . c o m*/ try { Class applictionCls = Class.forName(appClass); Field loadedApkField = applictionCls.getField("mLoadedApk"); loadedApkField.setAccessible(true); Object loadedApk = loadedApkField.get(appContext); Class loadedApkCls = Class.forName("android.app.LoadedApk"); Field receiversField = loadedApkCls.getDeclaredField("mReceivers"); receiversField.setAccessible(true); ArrayMap receivers = (ArrayMap) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((ArrayMap) receiverMap).keySet()) { Class clazz = rec.getClass(); if (clazz.getName().contains("ProxyChangeListener")) { Method onReceiveMethod = clazz.getDeclaredMethod("onReceive", Context.class, Intent.class); Intent intent = new Intent(Proxy.PROXY_CHANGE_ACTION); if (host != null) { /*********** optional, may be need in future *************/ final String CLASS_NAME = "android.net.ProxyProperties"; Class cls = Class.forName(CLASS_NAME); Constructor constructor = cls.getConstructor(String.class, Integer.TYPE, String.class); constructor.setAccessible(true); Object proxyProperties = constructor.newInstance(host, port, null); intent.putExtra("proxy", (Parcelable) proxyProperties); /*********** optional, may be need in future *************/ } onReceiveMethod.invoke(rec, appContext, intent); } } } return true; } catch (ClassNotFoundException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (NoSuchFieldException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (IllegalAccessException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (IllegalArgumentException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (NoSuchMethodException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (InvocationTargetException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } catch (InstantiationException e) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); String exceptionAsString = sw.toString(); Log.v(TAG, e.getMessage()); Log.v(TAG, exceptionAsString); } return false; }
From source file:net.sf.beanlib.hibernate3.Hibernate3SequenceGenerator.java
/** Returns the next sequence id from the specified sequence and session. */ public static long nextval(final String sequenceName, final Session session) { Object target = session;/*from ww w. j a v a2 s . com*/ if (Proxy.isProxyClass(session.getClass())) { // Dig out the underlying session. InvocationHandler invocationHandler = Proxy.getInvocationHandler(session); if (invocationHandler instanceof DtoCentricCloseSuppressingInvocationHandler) { // This is faster for we don't need to use reflection. DtoCentricCloseSuppressingInvocationHandler dch = (DtoCentricCloseSuppressingInvocationHandler) invocationHandler; target = dch.getTarget(); } else { Class<?> invocationHandlerClass = invocationHandler.getClass(); Class<?> invocationHandlerDeclaringClass = invocationHandlerClass.getDeclaringClass(); if (invocationHandlerDeclaringClass == HibernateTemplate.class) { String className = invocationHandlerClass.getName(); if (className.endsWith("CloseSuppressingInvocationHandler")) { // Assume this is the private class org.springframework.orm.hibernate3.HibernateTempate$CloseSuppressingInvocationHandler // Dig out the private target. // I know this is bad, but there doesn't seem to be a better way. Oh well. try { Field f = invocationHandlerClass.getDeclaredField("target"); f.setAccessible(true); target = f.get(invocationHandler); } catch (SecurityException e) { throw new RuntimeException(e); } catch (NoSuchFieldException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } } } SessionImpl sessionImpl; if (target instanceof SessionImpl) sessionImpl = (SessionImpl) target; else throw new IllegalStateException("Not yet know how to handle the given session!"); IdentifierGenerator idGenerator = createIdentifierGenerator(sequenceName, session); Serializable id = idGenerator.generate(sessionImpl, null); return (Long) id; }