List of usage examples for java.lang Class getDeclaredMethod
@CallerSensitive public Method getDeclaredMethod(String name, Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException
From source file:org.allcolor.yahp.converter.CClassLoader.java
/** * Creates and allocates a memory URL/*from ww w.j av a 2 s . co m*/ * * @param entryName * name of the entry * @param entry * byte array of the entry * @return the created URL or null if an error occurs. */ public static URL createMemoryURL(final String entryName, final byte[] entry) { try { final Class c = ClassLoader.getSystemClassLoader() .loadClass("org.allcolor.yahp.converter.CMemoryURLHandler"); final Method m = c.getDeclaredMethod("createMemoryURL", new Class[] { String.class, byte[].class }); m.setAccessible(true); return (URL) m.invoke(null, new Object[] { entryName, entry }); } catch (final Exception ignore) { ignore.printStackTrace(); return null; } }
From source file:com.android.launcher3.Utilities.java
public static String getSystemProperty(String property, String defaultValue) { try {/*from ww w .j a v a 2s. com*/ Class clazz = Class.forName("android.os.SystemProperties"); Method getter = clazz.getDeclaredMethod("get", String.class); String value = (String) getter.invoke(null, property); if (!TextUtils.isEmpty(value)) { return value; } } catch (Exception e) { Log.d(TAG, "Unable to read system properties"); } return defaultValue; }
From source file:com.bstek.dorado.idesupport.initializer.CommonRuleTemplateInitializer.java
protected List<AutoChildTemplate> getChildTemplates(RuleTemplate ruleTemplate, TypeInfo typeInfo, XmlNodeInfo xmlNodeInfo, InitializerContext initializerContext) throws Exception { List<AutoChildTemplate> childTemplates = new ArrayList<AutoChildTemplate>(); if (xmlNodeInfo != null) { for (XmlSubNode xmlSubNode : xmlNodeInfo.getSubNodes()) { TypeInfo propertyTypeInfo = TypeInfo.parse(xmlSubNode.propertyType()); List<AutoChildTemplate> childRulesBySubNode = getChildTemplatesBySubNode(ruleTemplate, typeInfo, xmlSubNode.propertyName(), xmlSubNode, propertyTypeInfo, initializerContext); if (childRulesBySubNode != null) { childTemplates.addAll(childRulesBySubNode); }//from www . j a v a 2s . co m } } Class<?> type = typeInfo.getType(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { Method readMethod = propertyDescriptor.getReadMethod(); if (readMethod != null) { if (readMethod.getDeclaringClass() != type) { try { readMethod = type.getDeclaredMethod(readMethod.getName(), readMethod.getParameterTypes()); } catch (NoSuchMethodException e) { continue; } } List<AutoChildTemplate> childTemplatesBySubNode = null; XmlSubNode xmlSubNode = readMethod.getAnnotation(XmlSubNode.class); if (xmlSubNode != null) { TypeInfo propertyTypeInfo; Class<?> propertyType = propertyDescriptor.getPropertyType(); if (Collection.class.isAssignableFrom(propertyType)) { propertyTypeInfo = TypeInfo.parse((ParameterizedType) readMethod.getGenericReturnType(), true); propertyType = propertyTypeInfo.getType(); } else { propertyTypeInfo = new TypeInfo(propertyType, false); } childTemplatesBySubNode = getChildTemplatesBySubNode(ruleTemplate, typeInfo, propertyDescriptor.getName(), xmlSubNode, propertyTypeInfo, initializerContext); } if (childTemplatesBySubNode != null) { IdeSubObject ideSubObject = readMethod.getAnnotation(IdeSubObject.class); if (ideSubObject != null && !ideSubObject.visible()) { for (AutoChildTemplate childTemplate : childTemplatesBySubNode) { childTemplate.setVisible(false); } } childTemplates.addAll(childTemplatesBySubNode); } } } return childTemplates; }
From source file:com.yangtsaosoftware.pebblemessenger.services.PebbleCenter.java
private void endCall() { TelephonyManager telMag = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); Class<TelephonyManager> c = TelephonyManager.class; Method mthEndCall;//ww w. j a v a2 s. co m try { mthEndCall = c.getDeclaredMethod("getITelephony", (Class[]) null); mthEndCall.setAccessible(true); ITelephony iTel = (ITelephony) mthEndCall.invoke(telMag, (Object[]) null); iTel.endCall(); } catch (Exception e) { e.printStackTrace(); } /*Context context = getApplicationContext(); AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); Constants.log("speakerset", String.format("AudioManager before mode:%d speaker mod:%s", audioManager.getMode(), String.valueOf(audioManager.isSpeakerphoneOn()))); Intent meidaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON); KeyEvent keyEvent = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK); meidaButtonIntent.putExtra(Intent.EXTRA_KEY_EVENT, keyEvent); context.sendOrderedBroadcast(meidaButtonIntent, "android.permission.CALL_PRIVILEGED");*/ }
From source file:com.atlassian.jira.functest.framework.AdministrationImpl.java
private void reflectivelyInvoke(final Object self, final Class<?> clazz, final String methodName, final Class[] paramType, final Object[] params) { Preconditions.checkNotNull(self, "cannot invoke %s on null object", methodName); Method method = null;/*from w ww . j av a 2 s . c o m*/ try { method = clazz.getDeclaredMethod(methodName, paramType); method.setAccessible(true); method.invoke(self, params); } catch (NoSuchMethodException e) { throw new RuntimeException(String.format( "Error getting method '%s(%s)' for %s : possibly a library update has changed this method", methodName, Arrays.toString(paramType), clazz.getName()), e); } catch (InvocationTargetException e) { throw new RuntimeException(String.format( "Error invoking method '%s(%s)' for %s : exception raised during method invocation : %s", e.getCause().getMessage(), methodName, Arrays.toString(paramType), clazz.getName()), e.getCause()); } catch (IllegalAccessException e) { throw new RuntimeException(String.format( "Error invoking method '%s(%s)' for %s : possibly a security manager has prevented access to this method", methodName, Arrays.toString(paramType), clazz.getName()), e); } finally { if (method != null) { method.setAccessible(false); } } }
From source file:com.horizondigital.delta.UpdateService.java
private boolean setPermissions(String path, int mode, int uid, int gid) { try {/*from ww w. j av a 2s . c om*/ Class<?> FileUtils = getClassLoader().loadClass("android.os.FileUtils"); Method setPermissions = FileUtils.getDeclaredMethod("setPermissions", new Class[] { String.class, int.class, int.class, int.class }); return ((Integer) setPermissions.invoke(null, new Object[] { path, Integer.valueOf(mode), Integer.valueOf(uid), Integer.valueOf(gid) }) == 0); } catch (Exception e) { // A lot of voodoo could go wrong here, return failure instead of crash Logger.ex(e); } return false; }
From source file:eu.chainfire.opendelta.UpdateService.java
private boolean setPermissions(String path, int mode, int uid, int gid) { try {//from w ww .ja va2 s .com Class<?> FileUtils = getClassLoader().loadClass("android.os.FileUtils"); Method setPermissions = FileUtils.getDeclaredMethod("setPermissions", new Class[] { String.class, int.class, int.class, int.class }); return ((Integer) setPermissions.invoke(null, new Object[] { path, Integer.valueOf(mode), Integer.valueOf(uid), Integer.valueOf(gid) }) == 0); } catch (Exception e) { // A lot of voodoo could go wrong here, return failure instead of // crash Logger.ex(e); } return false; }
From source file:org.apache.axis.transport.http.AxisServlet.java
/** * Attempts to invoke a plugin for the query string supplied in the URL. * * @param request the servlet's HttpServletRequest object. * @param response the servlet's HttpServletResponse object. * @param writer the servlet's PrintWriter object. *//*ww w . j a v a 2 s . co m*/ private boolean processQuery(HttpServletRequest request, HttpServletResponse response, PrintWriter writer) throws AxisFault { // Attempt to instantiate a plug-in handler class for the query string // handler classes defined in the HTTP transport. String path = request.getServletPath(); String queryString = request.getQueryString(); String serviceName; AxisEngine engine = getEngine(); Iterator i = this.transport.getOptions().keySet().iterator(); if (queryString == null) { return false; } String servletURI = request.getContextPath() + path; String reqURI = request.getRequestURI(); // chop off '/'. if (servletURI.length() + 1 < reqURI.length()) { serviceName = reqURI.substring(servletURI.length() + 1); } else { serviceName = ""; } while (i.hasNext() == true) { String queryHandler = (String) i.next(); if (queryHandler.startsWith("qs.") == true) { // Only attempt to match the query string with transport // parameters prefixed with "qs:". String handlerName = queryHandler.substring(queryHandler.indexOf(".") + 1).toLowerCase(); // Determine the name of the plugin to invoke by using all text // in the query string up to the first occurence of &, =, or the // whole string if neither is present. int length = 0; boolean firstParamFound = false; while (firstParamFound == false && length < queryString.length()) { char ch = queryString.charAt(length++); if (ch == '&' || ch == '=') { firstParamFound = true; --length; } } if (length < queryString.length()) { queryString = queryString.substring(0, length); } if (queryString.toLowerCase().equals(handlerName) == true) { // Query string matches a defined query string handler name. // If the defined class name for this query string handler is blank, // just return (the handler is "turned off" in effect). if (this.transport.getOption(queryHandler).equals("")) { return false; } try { // Attempt to dynamically load the query string handler // and its "invoke" method. MessageContext msgContext = createMessageContext(engine, request, response); Class plugin = Class.forName((String) this.transport.getOption(queryHandler)); Method pluginMethod = plugin.getDeclaredMethod("invoke", new Class[] { msgContext.getClass() }); String url = HttpUtils.getRequestURL(request).toString(); // Place various useful servlet-related objects in // the MessageContext object being delivered to the // plugin. msgContext.setProperty(MessageContext.TRANS_URL, url); msgContext.setProperty(HTTPConstants.PLUGIN_SERVICE_NAME, serviceName); msgContext.setProperty(HTTPConstants.PLUGIN_NAME, handlerName); msgContext.setProperty(HTTPConstants.PLUGIN_IS_DEVELOPMENT, new Boolean(isDevelopment())); msgContext.setProperty(HTTPConstants.PLUGIN_ENABLE_LIST, new Boolean(enableList)); msgContext.setProperty(HTTPConstants.PLUGIN_ENGINE, engine); msgContext.setProperty(HTTPConstants.PLUGIN_WRITER, writer); msgContext.setProperty(HTTPConstants.PLUGIN_LOG, log); msgContext.setProperty(HTTPConstants.PLUGIN_EXCEPTION_LOG, exceptionLog); // Invoke the plugin. pluginMethod.invoke(plugin.newInstance(), new Object[] { msgContext }); writer.close(); return true; } catch (InvocationTargetException ie) { reportTroubleInGet(ie.getTargetException(), response, writer); // return true to prevent any further processing return true; } catch (Exception e) { reportTroubleInGet(e, response, writer); // return true to prevent any further processing return true; } } } } return false; }
From source file:com.aurel.track.ApplicationStarter.java
private ApplicationBean initLicSys(TSiteBean site) { ApplicationBean applicationBean = ApplicationBean.getInstance(); try {//from w ww. j a va 2 s . c o m Class<LicenseManager> clazz = (Class<LicenseManager>) Class .forName("com.trackplus.license.LicenseManagerImpl"); if (clazz != null) { Class<Object>[] args = null; Object[] params = null; Method m = clazz.getDeclaredMethod("getInstance", args); LicenseManager lm = (LicenseManager) m.invoke(null, params); applicationBean.setLicenseManager(lm); } } catch (Exception e) { // This is quite normal, the plug-in may not be there. } if (InitDatabase.getFirstTime()) { Map<Integer, Object> siteBeanValues = new HashMap<Integer, Object>(); siteBeanValues.put(TSiteBean.COLUMNIDENTIFIERS.LICENSEKEY, ""); siteBeanValues.put(TSiteBean.COLUMNIDENTIFIERS.NUMBEROFUSERS, new Integer(5)); try { siteBeanValues.put(TSiteBean.COLUMNIDENTIFIERS.EXPDATE, DateTimeUtils.getInstance().parseISODate("2012-12-01")); } catch (Exception e) { LOGGER.error("Problem converting license expiration date"); } siteDAO.loadAndSaveSynchronized(siteBeanValues); } applicationBean.setActualUsers(); printInetAdressInfo(); if (site.getInstDate() == null || "".equals(site.getInstDate())) { site.setInstDate(new Long(new Date().getTime()).toString()); } try { applicationBean.setInstDate(new Long(site.getInstDate()).longValue()); } catch (Exception e) { LOGGER.info("Setting install date to " + new Date()); } try { applicationBean.initLic(site.getLicenseExtension()); } catch (Exception ex) { LOGGER.error(ExceptionUtils.getStackTrace(ex)); } site.setNumberOfUsers(new Integer( applicationBean.getMaxNumberOfFullUsers() + applicationBean.getMaxNumberOfLimitedUsers())); site.setNumberOfFullUsers(applicationBean.getMaxNumberOfFullUsers()); site.setNumberOfLimitedUsers(applicationBean.getMaxNumberOfLimitedUsers()); if (applicationBean.getLicenseHolder() != null) { site.setLicenseHolder(applicationBean.getLicenseHolder()); } site.setExpDate(applicationBean.getExpDate()); applicationBean.setSiteParams(site); applicationBean.setSiteBean(site); getServletConfig().getServletContext().setAttribute(Constants.APPLICATION_BEAN, applicationBean); return applicationBean; }
From source file:byps.http.HHttpServlet.java
protected BClient createForwardClientToOtherServer(BTransport transport) throws BException { BClient clientR = null;//from w w w . ja v a2s . c o m BApiDescriptor apiDesc = getApiDescriptor(); String clientClassName = apiDesc.basePackage + ".BClient_" + apiDesc.name; try { Class<?> clazz = Class.forName(clientClassName); Method m = clazz.getDeclaredMethod("createClientR", BTransport.class); clientR = (BClient) m.invoke(null, transport); } catch (Throwable e) { throw new BException(BExceptionC.INTERNAL, "Failed to create forward client", e); } return clientR; }