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:com.link_intersystems.lang.Conversions.java
/** * short to int, long, float, or double/* w w w.j a v a 2s . com*/ */ private static boolean isPrimitiveShortWidening(Class<?> to) { boolean isWidening = isPrimitiveIntegerWidening(to); isWidening |= isIdentity(to, Integer.TYPE); return isWidening; }
From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java
@Override public Object getValue(String path, Class<?> type) { if (!rootConfig.containsKey(path)) { return null; }// www . java2 s . c o m if (type.equals(Byte.TYPE) || type.equals(Byte.class)) { return rootConfig.getByte(path, null); } else if (type.equals(Short.TYPE) || type.equals(Short.class)) { return rootConfig.getShort(path, null); } else if (type.equals(Integer.TYPE) || type.equals(Integer.class)) { return rootConfig.getInteger(path, null); } else if (type.equals(Long.TYPE) || type.equals(Long.class)) { return rootConfig.getLong(path, null); } else if (type.equals(Float.TYPE) || type.equals(Float.class)) { return rootConfig.getFloat(path, null); } else if (type.equals(Double.TYPE) || type.equals(Double.class)) { return rootConfig.getDouble(path, null); } else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class)) { return rootConfig.getBoolean(path, null); } else if (type.equals(String.class)) { return rootConfig.getString(path); } else if (type.equals(BigInteger.class)) { return rootConfig.getBigInteger(path); } else if (type.equals(BigDecimal.class)) { return rootConfig.getBigDecimal(path); } else if (type.equals(Properties.class)) { return rootConfig.getProperties(path); } else if (type.equals(String[].class)) { return rootConfig.getStringArray(path); } else if (type.equals(TimeInterval.class)) { String interval = rootConfig.getString(path); if (interval == null) { return null; } return new TimeInterval(interval); } return null; }
From source file:com.manydesigns.portofino.modules.ModuleRegistry.java
public void migrateAndInit(ServletContext servletContext) { for (Module module : modules) { int migrationVersion = module.getMigrationVersion(); String key = "module." + module.getId() + ".migration.version"; int installedVersion = configuration.getInt(key, -1); boolean migrationOk = true; Injections.inject(module, servletContext, null); if (installedVersion == -1) try { //Install logger.info("Installing module " + printModule(module) + "..."); installedVersion = module.install(); configuration.setProperty(key, installedVersion); configuration.save();//w ww . j ava2s. co m logger.info("Installed module " + printModule(module)); } catch (Throwable e) { logger.error("Could not install module " + printModule(module), e); migrationOk = false; } try { //Migrate while (installedVersion < migrationVersion) { logger.info("Migrating module " + printModule(module) + " from version " + installedVersion + "..."); Method method = module.getClass().getMethod("migrateFrom" + installedVersion); if (!Integer.TYPE.equals(method.getReturnType())) { throw new RuntimeException("Migration method " + method + " does not return int"); } Integer result = (Integer) method.invoke(module); if (result > installedVersion) { installedVersion = result; configuration.setProperty(key, result); configuration.save(); logger.info("Migrated module " + printModule(module)); } else { throw new RuntimeException("Migration returned version " + result + " while the installed one is " + installedVersion); } } } catch (Throwable e) { logger.error( "Could not migrate module " + printModule(module) + " from version " + installedVersion, e); migrationOk = false; } if (migrationOk) { //Init (skip if installation or migration failed) try { logger.debug("Initializing module " + printModule(module) + "..."); module.init(); logger.info("Initialized module " + printModule(module)); } catch (Throwable e) { logger.error("Could not initialize module " + printModule(module), e); } } } }
From source file:org.jboss.dashboard.database.hibernate.LOBHelper.java
public void oracleNullSafeSet(PreparedStatement statement, Object value, int index, ValueWriter vw) throws HibernateException, SQLException { try {/*from ww w .j a va 2s .c o m*/ // Invoke by reflection the Oracle classes Class oracleBlobClass = Class.forName(ORACLE_CLASS); Method createTempMethod = getMethod(oracleBlobClass, ORACLE_TEMP_METHOD, Connection.class, Boolean.TYPE, Integer.TYPE); Field durationSession = oracleBlobClass.getField(ORACLE_DURATION__SESSION); Object arglist[] = new Object[3]; Connection conn = statement.getConnection(); arglist[0] = conn; arglist[1] = Boolean.TRUE; arglist[2] = durationSession.get(null); Object tempBlob = null; // Needed to avoid JBoss AS class loading issues... Class connClassInCurrentClassLoader = Class.forName(conn.getClass().getName()); // Direct Oracle connection if (Class.forName(ORACLE_JDBC_ORACLE_CONNECTION).isAssignableFrom(connClassInCurrentClassLoader)) { tempBlob = createTempMethod.invoke(null, arglist); // null is valid because of static method } // JBoss AS data source wrapper connection. else if (WrappedConnection.class.isAssignableFrom(connClassInCurrentClassLoader)) { arglist[0] = ReflectionUtils.invokeMethod(conn, "getUnderlyingConnection", null); tempBlob = createTempMethod.invoke(null, arglist); // null is valid because of static method } // C3P0 pool managed connection. else if (NewProxyConnection.class.isAssignableFrom(connClassInCurrentClassLoader)) { NewProxyConnection castCon = (NewProxyConnection) conn; arglist[0] = C3P0ProxyConnection.RAW_CONNECTION; tempBlob = castCon.rawConnectionOperation(createTempMethod, C3P0ProxyConnection.RAW_CONNECTION, arglist); } // Apache's DBCP pool managed connection. else if (PoolableConnection.class.isAssignableFrom(connClassInCurrentClassLoader)) { arglist[0] = ((PoolableConnection) statement.getConnection()).getDelegate(); tempBlob = createTempMethod.invoke(null, arglist); // null is valid because of static method } else { boolean throwException = true; //check if we are running in websphere try { String wasConnectionWrapper = "com.ibm.ws.rsadapter.jdbc.WSJdbcConnection"; Class wasConnectionWrapperClass = Class.forName(wasConnectionWrapper); if (wasConnectionWrapperClass.isAssignableFrom(connClassInCurrentClassLoader)) { String helperClass = "com.ibm.websphere.rsadapter.WSCallHelper"; Class helper = Class.forName(helperClass); Method nativeConnMethod = helper.getMethod("getNativeConnection", new Class[] { Object.class }); Connection nativeConn = (Connection) nativeConnMethod.invoke(null, conn); if (Class.forName(ORACLE_JDBC_ORACLE_CONNECTION).isAssignableFrom(nativeConn.getClass())) { arglist[0] = nativeConn; tempBlob = createTempMethod.invoke(null, arglist); throwException = false; } } } catch (Throwable e) { e.printStackTrace(); // do nothing } if (throwException) { throw new HibernateException("JDBC connection object must be a oracle.jdbc.OracleConnection " + "a " + WrappedConnection.class.getName() + "a " + PoolableConnection.class.getName() + "or a " + NewProxyConnection.class.getName() + ". Connection class is " + connClassInCurrentClassLoader.getName()); } } Method openMethod = getMethod(oracleBlobClass, ORACLE_OPEN_METHOD, Integer.TYPE, null, null); Field fieldReadWrite = oracleBlobClass.getField(ORACLE_MODE__READWRITE); arglist = new Object[1]; arglist[0] = fieldReadWrite.get(null); //null is valid because of static field openMethod.invoke(tempBlob, arglist); Method getOutputStreamMethod = oracleBlobClass.getDeclaredMethod(ORACLE_GET_BINARY_OUTPUT_STREAM, null); OutputStream os = (OutputStream) getOutputStreamMethod.invoke(tempBlob, null); try { vw.writeValue(os, value); os.flush(); } finally { os.close(); } Method closeMethod = oracleBlobClass.getDeclaredMethod(ORACLE_CLOSE, null); closeMethod.invoke(tempBlob, null); statement.setBlob(index, (Blob) tempBlob); } catch (Exception e) { throw new HibernateException("Error in oracleNullSafeSet", e); } }
From source file:org.apache.click.util.RequestTypeConverter.java
/** * Return the converted value for the given value object and target type. * * @param value the value object to convert * @param toType the target class type to convert the value to * @return a converted value into the specified type *///w w w. ja v a 2 s . c om protected Object convertValue(Object value, Class<?> toType) { Object result = null; if (value != null) { // If array -> array then convert components of array individually 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) OgnlOps.longValue(value)); } else if ((toType == Double.class) || (toType == Double.TYPE)) { result = new Double(OgnlOps.doubleValue(value)); } else if ((toType == Boolean.class) || (toType == Boolean.TYPE)) { result = Boolean.valueOf(value.toString()); } else if ((toType == Byte.class) || (toType == Byte.TYPE)) { result = Byte.valueOf((byte) OgnlOps.longValue(value)); } else if ((toType == Character.class) || (toType == Character.TYPE)) { result = Character.valueOf((char) OgnlOps.longValue(value)); } else if ((toType == Short.class) || (toType == Short.TYPE)) { result = Short.valueOf((short) OgnlOps.longValue(value)); } else if ((toType == Long.class) || (toType == Long.TYPE)) { result = Long.valueOf(OgnlOps.longValue(value)); } else if ((toType == Float.class) || (toType == Float.TYPE)) { result = new Float(OgnlOps.doubleValue(value)); } else if (toType == BigInteger.class) { result = OgnlOps.bigIntValue(value); } else if (toType == BigDecimal.class) { result = bigDecValue(value); } else if (toType == String.class) { result = OgnlOps.stringValue(value); } else if (toType == java.util.Date.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.util.Date(time); } } else if (toType == java.sql.Date.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Date(time); } } else if (toType == java.sql.Time.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Time(time); } } else if (toType == java.sql.Timestamp.class) { long time = getTimeFromDateString(value.toString()); if (time > Long.MIN_VALUE) { result = new java.sql.Timestamp(time); } } } } else { if (toType.isPrimitive()) { result = OgnlRuntime.getPrimitiveDefaultValue(toType); } } return result; }
From source file:demo.config.PropertyConverter.java
/** * Converts the specified value to the target class. If the class is a * primitive type (Integer.TYPE, Boolean.TYPE, etc) the value returned will * use the wrapper type (Integer.class, Boolean.class, etc). * // ww w . j a v a2s . c om * @param cls * the target class of the converted value * @param value * the value to convert * @param params * optional parameters used for the conversion * @return the converted value * @throws ConversionException * if the value is not compatible with the requested type * * @since 1.5 */ static Object to(Class<?> cls, Object value, Object[] params) throws ConversionException { if (cls.isInstance(value)) { return value; // no conversion needed } if (Boolean.class.equals(cls) || Boolean.TYPE.equals(cls)) { return toBoolean(value); } else if (Character.class.equals(cls) || Character.TYPE.equals(cls)) { return toCharacter(value); } else if (Number.class.isAssignableFrom(cls) || cls.isPrimitive()) { if (Integer.class.equals(cls) || Integer.TYPE.equals(cls)) { return toInteger(value); } else if (Long.class.equals(cls) || Long.TYPE.equals(cls)) { return toLong(value); } else if (Byte.class.equals(cls) || Byte.TYPE.equals(cls)) { return toByte(value); } else if (Short.class.equals(cls) || Short.TYPE.equals(cls)) { return toShort(value); } else if (Float.class.equals(cls) || Float.TYPE.equals(cls)) { return toFloat(value); } else if (Double.class.equals(cls) || Double.TYPE.equals(cls)) { return toDouble(value); } else if (BigInteger.class.equals(cls)) { return toBigInteger(value); } else if (BigDecimal.class.equals(cls)) { return toBigDecimal(value); } } else if (Date.class.equals(cls)) { return toDate(value, (String) params[0]); } else if (Calendar.class.equals(cls)) { return toCalendar(value, (String) params[0]); } else if (URL.class.equals(cls)) { return toURL(value); } else if (Locale.class.equals(cls)) { return toLocale(value); } else if (isEnum(cls)) { return convertToEnum(cls, value); } else if (Color.class.equals(cls)) { return toColor(value); } else if (cls.getName().equals(INTERNET_ADDRESS_CLASSNAME)) { return toInternetAddress(value); } else if (InetAddress.class.isAssignableFrom(cls)) { return toInetAddress(value); } throw new ConversionException("The value '" + value + "' (" + value.getClass() + ")" + " can't be converted to a " + cls.getName() + " object"); }
From source file:org.enerj.apache.commons.collections.TestClosureUtils.java
public void testInvokeClosure() { StringBuffer buf = new StringBuffer("Hello"); ClosureUtils.invokerClosure("reverse").execute(buf); assertEquals("olleH", buf.toString()); buf = new StringBuffer("Hello"); ClosureUtils.invokerClosure("setLength", new Class[] { Integer.TYPE }, new Object[] { new Integer(2) }) .execute(buf);//from w w w.j av a2s . c om assertEquals("He", buf.toString()); }
From source file:com.link_intersystems.lang.reflect.criteria.MemberCriteriaTest.java
@Test public void notAllowdModifiers() throws IllegalAccessException { Field[] declaredFields = Modifier.class.getDeclaredFields(); int maxModifierValue = 0; for (Field field : declaredFields) { int modifiers = field.getModifiers(); if (Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers) && field.getType().equals(Integer.TYPE)) { try { Integer value = (Integer) field.get(Modifier.class); maxModifierValue = Math.max(maxModifierValue, value.intValue()); } catch (IllegalArgumentException e) { throw new AssertionError(e); }//from w w w . ja v a2s . com } } maxModifierValue = maxModifierValue << 2; try { memberCriteria.withModifiers(maxModifierValue); throw new AssertionError("modifiers are not allowed"); } catch (IllegalArgumentException e) { String message = e.getMessage(); assertTrue(message.startsWith("modifiers must be")); } }
From source file:edu.wisc.commons.httpclient.HttpParamsBean.java
public int getIntParameter(final String name, int defaultValue) { return getTypedParameter(name, defaultValue, Integer.TYPE, new Function<Object, Integer>() { public Integer apply(Object value) { final Integer intValue = Integer.valueOf(value.toString()); //If this parameter is supposed to be an int store it as such to save future parsing work delegate.setIntParameter(name, intValue); return intValue; }//from w w w . j a va2 s . c o m }); }
From source file:org.colombbus.tangara.net.CommandExceptionFactory.java
public static CommandException createException(HttpMethod method, int code, String msg, Throwable th) { CommandException cmdEx = null;//from www .j a v a2 s .c o m // MalformedCommandException // BadServerCmdException Class<?> exClass = null; switch (code) { case 1: // Could not connect to database case 2: // Could not select database case 3: // Connection count query failed case 4: // Old connection removing query failed case 7: // List user query failed case 10: // Insert registration query failed // FIXME, the remove registration has the same error code case 11: // Delete all objects query failed case 14: // List objects query failed case 15: // Insert object registration query failed. <sql error code> case 16: // Unregister object failed. <sql error code> case 17: // Fail to start transaction case 18: // Fail to commit transaction case 19: // Fail to analyse message case 20: // Fail to insert message case 21: // Fail to list messages case 22: // Fail to find a connection case 26: // Fail to update last connection time case 28: // Old connection message removing query failed case 29: // Fail to find previous unset messages case 30: // Fail to delete previous unset messages case 36: // QUERY_FAILURE The query execution failed [$query] exClass = InternalSeverCmdException.class; break; case 5: // No action defined case 6: // Unsupported action +$action case 8: // username parameter not defined case 9: // connectID parameter not defined case 12: // objectname parameter not defined case 13: // objectclass parameter not defined case 24: // ipAddress parameter not defined exClass = MalformedCommandException.class; break; case 23: // User $username already exists with address $ipAddress // // already connected case 25: // User already connected // already exists case 27: // Unknown user case 31: // Fail to get username from connectID $connectID case 32: // Fail to register avatar image of user $connectID case 34: // Fail to get avatar image of user $username exClass = BadParamCmdException.class; break; case 35: // NOT_CONNECTED The connectID $connectID does not exist exClass = UnknownUserCmdException.class; break; default: LOG.warn("unhandled error code " + code); exClass = CommandException.class; } try { Constructor<?> construct = null; Object[] args = null; if (th == null) { construct = exClass.getConstructor(String.class, Integer.TYPE, String.class); args = new Object[3]; args[0] = method.getPath(); args[1] = code; args[2] = msg; } else { construct = exClass.getConstructor(String.class, Integer.TYPE, String.class, Throwable.class); args = new Object[4]; args[0] = method.getPath(); args[1] = code; args[2] = msg; args[3] = th; } cmdEx = (CommandException) construct.newInstance(args); } catch (Throwable thEx) { LOG.error("Cannot instanciate the dedicated command exception", thEx); if (th == null) { cmdEx = new CommandException(method.getPath(), 0, msg); } else { cmdEx = new CommandException(method.getPath(), 0, msg, th); } } return cmdEx; }