List of usage examples for java.lang Integer TYPE
Class TYPE
To view the source code for java.lang Integer TYPE.
Click Source Link
From source file:Main.java
@SuppressLint("NewApi") @SuppressWarnings("all") private static boolean setProxyKK(WebView webView, String host, int port, String applicationClassName) { Context appContext = webView.getContext().getApplicationContext(); if (null == host) { System.clearProperty("http.proxyHost"); System.clearProperty("http.proxyPort"); System.clearProperty("https.proxyHost"); System.clearProperty("https.proxyPort"); } else {//ww w . j a v a 2 s .com System.setProperty("http.proxyHost", host); System.setProperty("http.proxyPort", port + ""); System.setProperty("https.proxyHost", host); System.setProperty("https.proxyPort", port + ""); } try { Class applictionCls = Class.forName(applicationClassName); 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); Map receivers = (Map) receiversField.get(loadedApk); for (Object receiverMap : receivers.values()) { for (Object rec : ((Map) 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); /*********** 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); } } } Log.d(LOG_TAG, "Setting proxy with >= 4.4 API successful!"); return true; } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } return false; }
From source file:com.sf.ddao.crud.ops.CheckIfDirtyOperation.java
public boolean execute(Context context) throws Exception { final MethodCallCtx callCtx = CtxHelper.get(context, MethodCallCtx.class); final Object[] args = callCtx.getArgs(); final Method method = callCtx.getMethod(); for (Object arg : args) { if (arg instanceof DirtyableBean) { DirtyableBean dirtyableBean = (DirtyableBean) arg; if (!dirtyableBean.beanIsDirty()) { if (method.getReturnType() == Integer.TYPE || method.getReturnType() == Integer.class) { callCtx.setLastReturn(0); }// www . j av a 2 s. c o m log.debug("Bean '{}' is not dirty and doesn't have to be updated" + arg); return PROCESSING_COMPLETE; } } } return CONTINUE_PROCESSING; }
From source file:com.haulmont.cuba.core.config.ConfigDefaultMethod.java
@Override public Object invoke(ConfigHandler handler, Object[] args, Object proxy) { try {/*from w w w. j a va 2 s . com*/ if (SystemUtils.IS_JAVA_1_8) { // hack to invoke default method of an interface reflectively Constructor<MethodHandles.Lookup> lookupConstructor = MethodHandles.Lookup.class .getDeclaredConstructor(Class.class, Integer.TYPE); if (!lookupConstructor.isAccessible()) { lookupConstructor.setAccessible(true); } return lookupConstructor.newInstance(configInterface, MethodHandles.Lookup.PRIVATE) .unreflectSpecial(configMethod, configInterface).bindTo(proxy).invokeWithArguments(args); } else { return MethodHandles.lookup() .findSpecial(configInterface, configMethod.getName(), MethodType.methodType(configMethod.getReturnType(), configMethod.getParameterTypes()), configInterface) .bindTo(proxy).invokeWithArguments(args); } } catch (Throwable throwable) { throw new RuntimeException("Error invoking default method of config interface", throwable); } }
From source file:net.jetrix.config.ServerRuleSet.java
public void addRuleInstances(Digester digester) { // server parameters digester.addCallMethod("tetrinet-server/name", "setName", 0); digester.addCallMethod("tetrinet-server", "setHost", 1); digester.addCallParam("tetrinet-server", 0, "host"); digester.addCallMethod("tetrinet-server/language", "setLocale", 0); digester.addCallMethod("tetrinet-server/timeout", "setTimeout", 0, new Class[] { Integer.TYPE }); digester.addCallMethod("tetrinet-server/max-channels", "setMaxChannels", 0, new Class[] { Integer.TYPE }); digester.addCallMethod("tetrinet-server/max-players", "setMaxPlayers", 0, new Class[] { Integer.TYPE }); digester.addCallMethod("tetrinet-server/max-connections", "setMaxConnections", 0, new Class[] { Integer.TYPE }); digester.addCallMethod("tetrinet-server/op-password", "setOpPassword", 0); digester.addCallMethod("tetrinet-server/admin-password", "setAdminPassword", 0); digester.addCallMethod("tetrinet-server/access-log", "setAccessLogPath", 1); digester.addCallParam("tetrinet-server/access-log", 0, "path"); digester.addCallMethod("tetrinet-server/error-log", "setErrorLogPath", 1); digester.addCallParam("tetrinet-server/error-log", 0, "path"); digester.addCallMethod("tetrinet-server/channels", "setChannelsFile", 1); digester.addCallParam("tetrinet-server/channels", 0, "path"); // command definitions digester.addObjectCreate("*/command", null, "class"); digester.addSetNext("*/command", "addCommand", "net.jetrix.commands.Command"); digester.addCallMethod("*/command", "setAccessLevel", 1, new Class[] { Integer.TYPE }); digester.addCallParam("*/command", 0, "access-level"); // listeners/* w w w . jav a 2 s . c om*/ digester.addObjectCreate("*/listener", null, "class"); digester.addSetProperties("*/listener"); digester.addCallMethod("*/listener", "setAutoStart", 1, new Class[] { Boolean.TYPE }); digester.addCallParam("*/listener", 0, "auto-start"); digester.addSetNext("*/listener", "addListener", "net.jetrix.Listener"); // services digester.addObjectCreate("*/service", null, "class"); digester.addSetProperties("*/service"); digester.addCallMethod("*/service", "setAutoStart", 1, new Class[] { Boolean.TYPE }); digester.addCallParam("*/service", 0, "auto-start"); digester.addSetProperty("*/service/param", "name", "value"); digester.addSetNext("*/service", "addService", "net.jetrix.Service"); // banlist digester.addCallMethod("tetrinet-server/ban/host", "addBannedHost", 0); // datasource digester.addObjectCreate("*/datasource", "net.jetrix.config.DataSourceConfig"); digester.addSetNext("*/datasource", "addDataSource", "net.jetrix.config.DataSourceConfig"); digester.addCallMethod("*/datasource", "setName", 1); digester.addCallParam("*/datasource", 0, "name"); digester.addCallMethod("*/datasource/driver", "setDriver", 0); digester.addCallMethod("*/datasource/url", "setUrl", 0); digester.addCallMethod("*/datasource/username", "setUsername", 0); digester.addCallMethod("*/datasource/password", "setPassword", 0); digester.addCallMethod("*/datasource/min-idle", "setMinIdle", 0); digester.addCallMethod("*/datasource/max-active", "setMaxActive", 0); // mail session digester.addObjectCreate("*/mailserver", "net.jetrix.config.MailSessionConfig"); digester.addSetNext("*/mailserver", "setMailSessionConfig", "net.jetrix.config.MailSessionConfig"); digester.addCallMethod("*/mailserver", "setHostname", 1); digester.addCallParam("*/mailserver", 0, "host"); digester.addCallMethod("*/mailserver", "setPort", 1, new Class[] { Integer.TYPE }); digester.addCallParam("*/mailserver", 0, "port"); digester.addCallMethod("*/mailserver", "setAuth", 1, new Class[] { Boolean.TYPE }); digester.addCallParam("*/mailserver", 0, "auth"); digester.addCallMethod("*/mailserver", "setUsername", 1); digester.addCallParam("*/mailserver", 0, "username"); digester.addCallMethod("*/mailserver", "setPassword", 1); digester.addCallParam("*/mailserver", 0, "password"); digester.addCallMethod("*/mailserver", "setDebug", 1, new Class[] { Boolean.TYPE }); digester.addCallParam("*/mailserver", 0, "debug"); // extended properties digester.addCallMethod("*/properties/property", "setProperty", 2); digester.addCallParam("*/properties/property", 0, "name"); digester.addCallParam("*/properties/property", 1, "value"); }
From source file:com.github.dozermapper.core.converters.EnumConverter.java
@SuppressWarnings({ "unchecked", "rawtypes" }) public Object convert(Class destClass, Object srcObj) { if (null == srcObj) { MappingUtils.throwMappingException("Cannot convert null to enum of type " + destClass); }/* w ww . j a v a 2 s . com*/ try { if ((srcObj.getClass().equals(Byte.class)) || (srcObj.getClass().equals(Byte.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Byte) srcObj).intValue()); } else if ((srcObj.getClass().equals(Short.class)) || (srcObj.getClass().equals(Short.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Short) srcObj).intValue()); } else if ((srcObj.getClass().equals(Integer.class)) || (srcObj.getClass().equals(Integer.TYPE))) { return EnumUtils.getEnumList(destClass).get((Integer) srcObj); } else if ((srcObj.getClass().equals(Long.class)) || (srcObj.getClass().equals(Long.TYPE))) { return EnumUtils.getEnumList(destClass).get(((Long) srcObj).intValue()); } else { return Enum.valueOf(destClass, srcObj.toString()); } } catch (Exception e) { MappingUtils.throwMappingException("Cannot convert [" + srcObj + "] to enum of type " + destClass, e); } return srcObj; }
From source file:edu.northwestern.bioinformatics.studycalendar.core.editors.ControlledVocabularyEditor.java
public void setAsText(String text) throws IllegalArgumentException { AbstractControlledVocabularyObject newValue; if (text == null) { newValue = null;//from w ww.j a va 2 s. c om } else if (blankAsNull && StringUtils.isBlank(text)) { newValue = null; } else { Integer id = new Integer(text); try { Method lookupMethod = enumClass.getMethod(LOOKUP_METHOD, Integer.TYPE); newValue = (AbstractControlledVocabularyObject) lookupMethod.invoke(null, id); } catch (NoSuchMethodException e) { throw new StudyCalendarError(enumClass.getName() + " is missing lookup method " + LOOKUP_METHOD, e); } catch (IllegalAccessException e) { throw new StudyCalendarSystemException(e); } catch (InvocationTargetException e) { throw new StudyCalendarSystemException(e); } } setValue(newValue); }
From source file:com.link_intersystems.lang.reflect.MethodInvokingTransformerTest.java
@Before public void setup() { argumentResolver = new InvocationArgumentsResolver() { public Object[] getArguments(Object invokedObject, Method invokedMethod) { return new Object[] { 1 }; }//from w ww. j a va 2 s .com }; charAtMethod = MethodUtils.getAccessibleMethod(String.class, "charAt", Integer.TYPE); }
From source file:Main.java
/** * This method converts a given number into a target class. This method does not change the value (except when * explicitly casting to a more general type, e.g. from double to int), just the internal type representation. While * this is unnecessary while using normal java code, reflection based access to method parameters is a bit more * difficult. As far as possible, this method will prevent the ArgumentMismatch error when passing numbers as * parameters./* w w w .j a v a 2 s .c o m*/ * <p/> * If the value can not be converted to the given target class, it will be returned unchanged. * * @param targetClass Class to which the number should be converted, if possible. * @param value Number value to convert. * @return 'value' converted to an instance of 'targetClass'. */ public static Object convertNumber(final Class targetClass, final Number value) { if (targetClass.equals(Double.class) || targetClass.equals(Double.TYPE)) return value.doubleValue(); if (targetClass.equals(Integer.class) || targetClass.equals(Integer.TYPE)) return value.intValue(); if (targetClass.equals(Long.class) || targetClass.equals(Long.TYPE)) return value.longValue(); if (targetClass.equals(Short.class) || targetClass.equals(Short.TYPE)) return value.shortValue(); if (targetClass.equals(Byte.class) || targetClass.equals(Byte.TYPE)) return value.byteValue(); if (targetClass.equals(Character.class) || targetClass.equals(Character.TYPE)) return value.intValue(); if (targetClass.equals(Float.class) || targetClass.equals(Float.TYPE)) return value.floatValue(); return value; }
From source file:com.base.dao.sql.ReflectionUtils.java
public static Object convertValue(Object value, Class toType) { Object result = null;/*from w ww. ja va 2s . c o m*/ if (value != null) { if (value.getClass().isArray() && toType.isArray()) { Class componentType = toType.getComponentType(); result = Array.newInstance(componentType, Array.getLength(value)); for (int i = 0, icount = Array.getLength(value); i < icount; i++) { Array.set(result, i, convertValue(Array.get(value, i), componentType)); } } else { if ((toType == Integer.class) || (toType == Integer.TYPE)) result = Integer.valueOf((int) longValue(value)); if ((toType == Double.class) || (toType == Double.TYPE)) result = new Double(doubleValue(value)); if ((toType == Boolean.class) || (toType == Boolean.TYPE)) result = booleanValue(value) ? Boolean.TRUE : Boolean.FALSE; if ((toType == Byte.class) || (toType == Byte.TYPE)) result = Byte.valueOf((byte) longValue(value)); if ((toType == Character.class) || (toType == Character.TYPE)) result = new Character((char) longValue(value)); if ((toType == Short.class) || (toType == Short.TYPE)) result = Short.valueOf((short) longValue(value)); if ((toType == Long.class) || (toType == Long.TYPE)) result = Long.valueOf(longValue(value)); if ((toType == Float.class) || (toType == Float.TYPE)) result = new Float(doubleValue(value)); if (toType == BigInteger.class) result = bigIntValue(value); if (toType == BigDecimal.class) result = bigDecValue(value); if (toType == String.class) result = stringValue(value); if (toType == Date.class) { result = DateUtils.toDate(stringValue(value)); } if (Enum.class.isAssignableFrom(toType)) result = enumValue((Class<Enum>) toType, value); } } else { if (toType.isPrimitive()) { result = primitiveDefaults.get(toType); } } return result; }
From source file:org.exolab.castor.xml.parsing.primitive.objects.PrimitiveObjectFactory.java
private PrimitiveObjectFactory() { typeHandlers.put(String.class, PrimitiveString.class); typeHandlers.put(Enum.class, PrimitiveEnum.class); typeHandlers.put(Integer.TYPE, PrimitiveInteger.class); typeHandlers.put(Integer.class, PrimitiveInteger.class); typeHandlers.put(Boolean.TYPE, PrimitiveBoolean.class); typeHandlers.put(Boolean.class, PrimitiveBoolean.class); typeHandlers.put(Double.TYPE, PrimitiveDouble.class); typeHandlers.put(Double.class, PrimitiveDouble.class); typeHandlers.put(Long.TYPE, PrimitiveLong.class); typeHandlers.put(Long.class, PrimitiveLong.class); typeHandlers.put(Character.TYPE, PrimitiveChar.class); typeHandlers.put(Character.class, PrimitiveChar.class); typeHandlers.put(Short.TYPE, PrimitiveShort.class); typeHandlers.put(Short.class, PrimitiveShort.class); typeHandlers.put(Float.TYPE, PrimitiveFloat.class); typeHandlers.put(Float.class, PrimitiveFloat.class); typeHandlers.put(Byte.TYPE, PrimitiveByte.class); typeHandlers.put(Byte.class, PrimitiveByte.class); typeHandlers.put(BigInteger.class, PrimitiveBigInteger.class); typeHandlers.put(BigDecimal.class, PrimitiveBigDecimal.class); }