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:catalina.mbeans.MBeanFactory.java
/** * Create a new HttpsConnector//from w ww .ja va2 s .c o m * * @param parent MBean Name of the associated parent component * @param address The IP address on which to bind * @param port TCP port number to listen on * * @exception Exception if an MBean cannot be created or registered */ public String createHttpsConnector(String parent, String address, int port) throws Exception { Object retobj = null; try { // Create a new CoyoteConnector instance // use reflection to avoid j-t-c compile-time circular dependencies Class cls = Class.forName("org.apache.coyote.tomcat4.CoyoteConnector"); Constructor ct = cls.getConstructor(null); retobj = ct.newInstance(null); Class partypes1[] = new Class[1]; // Set address String str = new String(); partypes1[0] = str.getClass(); Method meth1 = cls.getMethod("setAddress", partypes1); Object arglist1[] = new Object[1]; arglist1[0] = address; meth1.invoke(retobj, arglist1); // Set port number Class partypes2[] = new Class[1]; partypes2[0] = Integer.TYPE; Method meth2 = cls.getMethod("setPort", partypes2); Object arglist2[] = new Object[1]; arglist2[0] = new Integer(port); meth2.invoke(retobj, arglist2); // Set scheme Class partypes3[] = new Class[1]; partypes3[0] = str.getClass(); Method meth3 = cls.getMethod("setScheme", partypes3); Object arglist3[] = new Object[1]; arglist3[0] = new String("https"); meth3.invoke(retobj, arglist3); // Set secure Class partypes4[] = new Class[1]; partypes4[0] = Boolean.TYPE; Method meth4 = cls.getMethod("setSecure", partypes4); Object arglist4[] = new Object[1]; arglist4[0] = new Boolean(true); meth4.invoke(retobj, arglist4); // Set factory Class serverSocketFactoryCls = Class.forName("org.apache.catalina.net.ServerSocketFactory"); Class coyoteServerSocketFactoryCls = Class .forName("org.apache.coyote.tomcat4.CoyoteServerSocketFactory"); Constructor factoryConst = coyoteServerSocketFactoryCls.getConstructor(null); Object factoryObj = factoryConst.newInstance(null); Class partypes5[] = new Class[1]; partypes5[0] = serverSocketFactoryCls; Method meth5 = cls.getMethod("setFactory", partypes5); Object arglist5[] = new Object[1]; arglist5[0] = factoryObj; meth5.invoke(retobj, arglist5); } catch (Exception e) { throw new MBeanException(e); } try { // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("name")); service.addConnector((Connector) retobj); } catch (Exception e) { // FIXME // disply error message // the user needs to use keytool to configure SSL first // addConnector will fail otherwise return null; } // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("CoyoteConnector"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), (Connector) retobj); return (oname.toString()); }
From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java
/** * Convert a <code>ResultSet</code> column into an object. Simple * implementations could just call <code>rs.getObject(index)</code> while * more complex implementations could perform type manipulation to match * the column's type to the bean property type. * * <p>/*from w w w . j a v a2 s .c o m*/ * This implementation calls the appropriate <code>ResultSet</code> getter * method for the given property type to perform the type conversion. If * the property type doesn't match one of the supported * <code>ResultSet</code> types, <code>getObject</code> is called. * </p> * * @param rs The <code>ResultSet</code> currently being processed. It is * positioned on a valid row before being passed into this method. * * @param index The current column index being processed. * * @param propType The bean property type that this column needs to be * converted into. * * @throws SQLException if a database access error occurs * * @return The object from the <code>ResultSet</code> at the given column * index after optional type processing or <code>null</code> if the column * value was SQL NULL. */ protected Object processColumn(ResultSet rs, int index, Class<?> propType) throws SQLException { if (!propType.isPrimitive() && rs.getObject(index) == null) { return null; } if (propType.equals(String.class)) { return rs.getString(index); } else if (propType.equals(Integer.TYPE) || propType.equals(Integer.class)) { return Integer.valueOf(rs.getInt(index)); } else if (propType.equals(Boolean.TYPE) || propType.equals(Boolean.class)) { return Boolean.valueOf(rs.getBoolean(index)); } else if (propType.equals(Long.TYPE) || propType.equals(Long.class)) { return Long.valueOf(rs.getLong(index)); } else if (propType.equals(Double.TYPE) || propType.equals(Double.class)) { return Double.valueOf(rs.getDouble(index)); } else if (propType.equals(Float.TYPE) || propType.equals(Float.class)) { return Float.valueOf(rs.getFloat(index)); } else if (propType.equals(Short.TYPE) || propType.equals(Short.class)) { return Short.valueOf(rs.getShort(index)); } else if (propType.equals(Byte.TYPE) || propType.equals(Byte.class)) { return Byte.valueOf(rs.getByte(index)); } else if (propType.equals(Timestamp.class)) { return rs.getTimestamp(index); } else if (propType.equals(SQLXML.class)) { return rs.getSQLXML(index); } else { return rs.getObject(index); } }
From source file:com.thinkbiganalytics.policy.BasePolicyAnnotationTransformer.java
public Object convertStringToObject(String value, Class type) { if (type.isEnum()) { return Enum.valueOf(type, value); } else if (String.class.equals(type)) { return value; }//from ww w .ja v a 2 s . c o m if (StringUtils.isBlank(value)) { return null; } else if (Number.class.equals(type)) { return NumberUtils.createNumber(value); } else if (Integer.class.equals(type) || Integer.TYPE.equals(type)) { return new Integer(value); } else if (Long.class.equals(type) || Long.TYPE.equals(type)) { return Long.valueOf(value); } else if (Double.class.equals(type) || Double.TYPE.equals(type)) { return Double.valueOf(value); } else if (Float.class.equals(type) || Float.TYPE.equals(type)) { return Float.valueOf(value); } else if (Pattern.class.equals(type)) { return Pattern.compile(value); } else if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) { return BooleanUtils.toBoolean(value); } else { throw new IllegalArgumentException( "Unable to convert the value " + value + " to an object of type " + type.getName()); } }
From source file:rb.app.RBSystem.java
/** * Evaluate theta_q_l (for the n^th output) at the current parameter. */// ww w . ja v a 2 s . c o m public double eval_theta_q_l(int n, int q_l) { Method meth; try { // Get a reference to get_n_L_functions, which does not // take any arguments Class partypes[] = new Class[3]; partypes[0] = Integer.TYPE; partypes[1] = Integer.TYPE; partypes[2] = double[].class; meth = mAffineFnsClass.getMethod("evaluateL", partypes); } catch (NoSuchMethodException nsme) { throw new RuntimeException("getMethod for evaluateL failed", nsme); } Double theta_val; try { Object arglist[] = new Object[3]; arglist[0] = new Integer(n); arglist[1] = new Integer(q_l); arglist[2] = current_parameters.getArray(); Object theta_obj = meth.invoke(mTheta, arglist); theta_val = (Double) theta_obj; } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite.getCause()); } return theta_val.doubleValue(); }
From source file:com.sun.faces.el.impl.Coercions.java
/** * Coerces a long to the given primitive number class *//*from ww w. j a v a 2s. com*/ static Number coerceToPrimitiveNumber(long pValue, Class pClass) throws ElException { if (pClass == Byte.class || pClass == Byte.TYPE) { return PrimitiveObjects.getByte((byte) pValue); } else if (pClass == Short.class || pClass == Short.TYPE) { return PrimitiveObjects.getShort((short) pValue); } else if (pClass == Integer.class || pClass == Integer.TYPE) { return PrimitiveObjects.getInteger((int) pValue); } else if (pClass == Long.class || pClass == Long.TYPE) { return PrimitiveObjects.getLong(pValue); } else if (pClass == Float.class || pClass == Float.TYPE) { return PrimitiveObjects.getFloat((float) pValue); } else if (pClass == Double.class || pClass == Double.TYPE) { return PrimitiveObjects.getDouble((double) pValue); } else { return PrimitiveObjects.getInteger(0); } }
From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java
private final Class<?> getClassForName(String type) { try {/*from w w w. j a va2 s . c o m*/ if (type.equals("boolean") || type.equals("java.lang.Boolean")) { return Boolean.TYPE; } else if (type.equals("byte") || type.equals("java.lang.Byte")) { return Byte.TYPE; } else if (type.equals("char") || type.equals("java.lang.Character")) { return Character.TYPE; } else if (type.equals("double") || type.equals("java.lang.Double")) { return Double.TYPE; } else if (type.equals("float") || type.equals("java.lang.Float")) { return Float.TYPE; } else if (type.equals("int") || type.equals("java.lang.Integer")) { return Integer.TYPE; } else if (type.equals("long") || type.equals("java.lang.Long")) { return Long.TYPE; } else if (type.equals("short") || type.equals("java.lang.Short")) { return Short.TYPE; } else if (type.equals("String")) { return Class.forName("java.lang." + type, true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } if (type.endsWith("[]")) { // see http://stackoverflow.com/questions/3442090/java-what-is-this-ljava-lang-object final StringBuilder arrayTypeNameBuilder = new StringBuilder(30); int index = 0; while ((index = type.indexOf('[', index)) != -1) { arrayTypeNameBuilder.append('['); index++; } arrayTypeNameBuilder.append('L'); // always needed for Object arrays // remove bracket from type name get array component type type = type.replace("[]", ""); arrayTypeNameBuilder.append(type); arrayTypeNameBuilder.append(';'); // finalize object array name return Class.forName(arrayTypeNameBuilder.toString(), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } else { return Class.forName(ResourceList.getClassNameFromResourcePath(type), true, TestGenerationContext.getInstance().getClassLoaderForSUT()); } } catch (final ClassNotFoundException e) { throw new RuntimeException(e); } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns the virtual machine's Class object for the named primitive type.<br/> * If the type is not a primitive type, {@code null} is returned. * * @param name the name of the type/* ww w . j a v a2 s. c o m*/ * @return the Class instance representing the primitive type */ private static Class<?> getPrimitiveType(String name) { name = StringUtils.defaultIfEmpty(name, ""); if (name.equals("int")) return Integer.TYPE; if (name.equals("short")) return Short.TYPE; if (name.equals("long")) return Long.TYPE; if (name.equals("float")) return Float.TYPE; if (name.equals("double")) return Double.TYPE; if (name.equals("byte")) return Byte.TYPE; if (name.equals("char")) return Character.TYPE; if (name.equals("boolean")) return Boolean.TYPE; if (name.equals("void")) return Void.TYPE; return null; }
From source file:com.offbynull.coroutines.instrumenter.MethodAnalyzer.java
private CacheVariables allocateCacheVariableSlots(VariableTable varTable, TypeTracker invocationReturnTypes, boolean invocationFoundWrappedInTryCatch) { Variable intReturnCacheVar = null;//from w w w. j av a 2s . c o m Variable longReturnCacheVar = null; Variable floatReturnCacheVar = null; Variable doubleReturnCacheVar = null; Variable objectReturnCacheVar = null; Variable throwableCacheVar = null; if (invocationReturnTypes.intFound) { intReturnCacheVar = varTable.acquireExtra(Integer.TYPE); } if (invocationReturnTypes.longFound) { longReturnCacheVar = varTable.acquireExtra(Long.TYPE); } if (invocationReturnTypes.floatFound) { floatReturnCacheVar = varTable.acquireExtra(Float.TYPE); } if (invocationReturnTypes.doubleFound) { doubleReturnCacheVar = varTable.acquireExtra(Double.TYPE); } if (invocationReturnTypes.objectFound) { objectReturnCacheVar = varTable.acquireExtra(Object.class); } if (invocationFoundWrappedInTryCatch) { throwableCacheVar = varTable.acquireExtra(Throwable.class); } return new CacheVariables(intReturnCacheVar, longReturnCacheVar, floatReturnCacheVar, doubleReturnCacheVar, objectReturnCacheVar, throwableCacheVar); }
From source file:net.naijatek.myalumni.util.fileupload.FileUpload.java
/** * <p> Returns the <code>Method</code> object to_email be used to_email obtain a new * <code>FileItem</code> instance. * /*from w ww. ja va 2s . com*/ * <p> For performance reasons, we cache the method once it has been * looked up, since method lookup is one of the more expensive aspects * of reflection. * * @return The <code>newInstance()</code> method to_email be invoked. * * @exception FileUploadException if an error occurs. */ protected Method getNewInstanceMethod() throws FileUploadException { // If the method is already cached, just return it. if (this.newInstanceMethod != null) { return this.newInstanceMethod; } // Load the FileUpload implementation class. ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); Class fileItemClass = null; if (classLoader == null) { classLoader = getClass().getClassLoader(); } try { fileItemClass = classLoader.loadClass(fileItemClassName); } catch (Exception e) { throw new FileUploadException(e.toString()); } if (fileItemClass == null) { throw new FileUploadException("Failed to load FileItem class: " + fileItemClassName); } // Find the newInstance() method. Class[] parameterTypes = new Class[] { String.class, String.class, String.class, Integer.TYPE, Integer.TYPE }; Method newInstanceMethod = MethodUtils.getAccessibleMethod(fileItemClass, "newInstance", parameterTypes); if (newInstanceMethod == null) { throw new FileUploadException( "Failed find newInstance() method in FileItem class: " + fileItemClassName); } // Cache the method so that all this only happens once. this.newInstanceMethod = newInstanceMethod; return newInstanceMethod; }
From source file:org.apache.jasper.compiler.JspUtil.java
/** * Produces a String representing a call to the EL interpreter. * @param expression a String containing zero or more "${}" expressions * @param expectedType the expected type of the interpreted result * @param fnmapvar Variable pointing to a function map. * @param XmlEscape True if the result should do XML escaping * @return a String representing a call to the EL interpreter. *///from w w w. j a v a2 s . c o m public static String interpreterCall(boolean isTagFile, String expression, Class expectedType, String fnmapvar, boolean XmlEscape) { /* * Determine which context object to use. */ String jspCtxt = null; if (isTagFile) jspCtxt = "this.getJspContext()"; else jspCtxt = "pageContext"; /* * Determine whether to use the expected type's textual name * or, if it's a primitive, the name of its correspondent boxed * type. */ String targetType = expectedType.getName(); String primitiveConverterMethod = null; if (expectedType.isPrimitive()) { if (expectedType.equals(Boolean.TYPE)) { targetType = Boolean.class.getName(); primitiveConverterMethod = "booleanValue"; } else if (expectedType.equals(Byte.TYPE)) { targetType = Byte.class.getName(); primitiveConverterMethod = "byteValue"; } else if (expectedType.equals(Character.TYPE)) { targetType = Character.class.getName(); primitiveConverterMethod = "charValue"; } else if (expectedType.equals(Short.TYPE)) { targetType = Short.class.getName(); primitiveConverterMethod = "shortValue"; } else if (expectedType.equals(Integer.TYPE)) { targetType = Integer.class.getName(); primitiveConverterMethod = "intValue"; } else if (expectedType.equals(Long.TYPE)) { targetType = Long.class.getName(); primitiveConverterMethod = "longValue"; } else if (expectedType.equals(Float.TYPE)) { targetType = Float.class.getName(); primitiveConverterMethod = "floatValue"; } else if (expectedType.equals(Double.TYPE)) { targetType = Double.class.getName(); primitiveConverterMethod = "doubleValue"; } } if (primitiveConverterMethod != null) { XmlEscape = false; } /* * Build up the base call to the interpreter. */ // XXX - We use a proprietary call to the interpreter for now // as the current standard machinery is inefficient and requires // lots of wrappers and adapters. This should all clear up once // the EL interpreter moves out of JSTL and into its own project. // In the future, this should be replaced by code that calls // ExpressionEvaluator.parseExpression() and then cache the resulting // expression objects. The interpreterCall would simply select // one of the pre-cached expressions and evaluate it. // Note that PageContextImpl implements VariableResolver and // the generated Servlet/SimpleTag implements FunctionMapper, so // that machinery is already in place (mroth). targetType = toJavaSourceType(targetType); StringBuffer call = new StringBuffer( "(" + targetType + ") " + "org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate" + "(" + Generator.quote(expression) + ", " + targetType + ".class, " + "(PageContext)" + jspCtxt + ", " + fnmapvar + ", " + XmlEscape + ")"); /* * Add the primitive converter method if we need to. */ if (primitiveConverterMethod != null) { call.insert(0, "("); call.append(")." + primitiveConverterMethod + "()"); } return call.toString(); }