List of usage examples for java.lang Boolean TYPE
Class TYPE
To view the source code for java.lang Boolean TYPE.
Click Source Link
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 ww . j a v a 2s . co m 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:fragment.web.HomeControllerTest.java
@Test public void testHomeRouting() throws Exception { logger.debug("Testing routing...."); DispatcherTestServlet servlet = this.getServletInstance(); Method expected = locateMethod(controller.getClass(), "home", new Class[] { Tenant.class, String.class, Boolean.TYPE, ModelMap.class, HttpSession.class, HttpServletRequest.class }); Method handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/home")); Assert.assertEquals(expected, handler); expected = locateMethod(controller.getClass(), "forum", new Class[] { HttpServletResponse.class, ModelMap.class }); handler = servlet.recognize(getRequestTemplate(HttpMethod.GET, "/forum")); Assert.assertEquals(expected, handler); expected = locateMethod(controller.getClass(), "acceptCookies", new Class[] {}); handler = servlet.recognize(getRequestTemplate(HttpMethod.POST, "/acceptCookies")); Assert.assertEquals(expected, handler); }
From source file:nl.strohalm.cyclos.controls.customization.fields.EditCustomFieldPossibleValueAction.java
public DataBinder<CustomFieldPossibleValue> getDataBinder() { if (dataBinder == null) { final BeanBinder<CustomFieldPossibleValue> binder = BeanBinder.instance(CustomFieldPossibleValue.class); binder.registerBinder("id", PropertyBinder.instance(Long.class, "id", IdConverter.instance())); binder.registerBinder("field", PropertyBinder.instance(CustomField.class, "field")); binder.registerBinder("parent", PropertyBinder.instance(CustomFieldPossibleValue.class, "parent")); binder.registerBinder("value", PropertyBinder.instance(String.class, "value")); binder.registerBinder("enabled", PropertyBinder.instance(Boolean.TYPE, "enabled")); binder.registerBinder("defaultValue", PropertyBinder.instance(Boolean.TYPE, "defaultValue")); dataBinder = binder;/*from ww w. java 2 s. c o m*/ } return dataBinder; }
From source file:org.apache.ode.il.DynamicService.java
@SuppressWarnings("unchecked") private static Object convertFromOM(Class<?> clazz, OMElement elmt) { // Here comes the nasty code... if (elmt == null || elmt.getText().length() == 0 && !elmt.getChildElements().hasNext()) return null; else if (clazz.equals(String.class)) { return elmt.getText(); } else if (clazz.equals(Boolean.class) || clazz.equals(Boolean.TYPE)) { return (elmt.getText().equals("true") || elmt.getText().equals("yes")) ? Boolean.TRUE : Boolean.FALSE; } else if (clazz.equals(QName.class)) { // The getTextAsQName is buggy, it sometimes return the full text without extracting namespace return OMUtils.getTextAsQName(elmt); } else if (clazz.equals(ProcessInfoCustomizer.class)) { return new ProcessInfoCustomizer(elmt.getText()); } else if (Node.class.isAssignableFrom(clazz)) { return OMUtils.toDOM(elmt.getFirstElement()); } else if (clazz.equals(Long.TYPE) || clazz.equals(Long.class)) { return Long.parseLong(elmt.getText()); } else if (clazz.equals(Integer.TYPE) || clazz.equals(Integer.class)) { return Integer.parseInt(elmt.getText()); } else if (clazz.isArray()) { ArrayList<Object> alist = new ArrayList<Object>(); Iterator<OMElement> children = elmt.getChildElements(); Class<?> targetClazz = clazz.getComponentType(); while (children.hasNext()) alist.add(parseType(targetClazz, ((OMElement) children.next()).getText())); return alist.toArray((Object[]) Array.newInstance(targetClazz, alist.size())); } else if (XmlObject.class.isAssignableFrom(clazz)) { try {//ww w . j a va2 s .c om Class beanFactory = clazz.forName(clazz.getCanonicalName() + "$Factory"); elmt.setNamespace(elmt.declareDefaultNamespace("")); elmt.setLocalName("xml-fragment"); return beanFactory.getMethod("parse", XMLStreamReader.class).invoke(null, elmt.getXMLStreamReaderWithoutCaching()); } catch (ClassNotFoundException e) { throw new RuntimeException( "Couldn't find class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean", e); } catch (IllegalAccessException e) { throw new RuntimeException( "Couldn't access class " + clazz.getCanonicalName() + ".Factory to instantiate xml bean", e); } catch (InvocationTargetException e) { throw new RuntimeException("Couldn't access xml bean parse method on class " + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e); } catch (NoSuchMethodException e) { throw new RuntimeException("Couldn't find xml bean parse method on class " + clazz.getCanonicalName() + ".Factory " + "to instantiate xml bean", e); } } else throw new RuntimeException( "Couldn't use element " + elmt + " to obtain a management method parameter."); }
From source file:org.openflexo.antar.binding.TypeUtils.java
public static Class toPrimitive(Class<?> aClass) { if (isDouble(aClass)) { return Double.TYPE; }/*w w w . j a v a 2 s .c om*/ if (isFloat(aClass)) { return Float.TYPE; } if (isLong(aClass)) { return Long.TYPE; } if (isInteger(aClass)) { return Integer.TYPE; } if (isShort(aClass)) { return Short.TYPE; } if (isByte(aClass)) { return Byte.TYPE; } if (isBoolean(aClass)) { return Boolean.TYPE; } if (isChar(aClass)) { return Character.TYPE; } return aClass; }
From source file:io.openmessaging.rocketmq.utils.BeanUtils.java
public static void setProperties(Class<?> clazz, Object obj, String methodName, Object value) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Class<?> parameterClass = getMethodClass(clazz, methodName); Method setterMethod = clazz.getMethod(methodName, parameterClass); if (parameterClass == Boolean.TYPE) { setterMethod.invoke(obj, Boolean.valueOf(value.toString())); } else if (parameterClass == Integer.TYPE) { setterMethod.invoke(obj, Integer.valueOf(value.toString())); } else if (parameterClass == Double.TYPE) { setterMethod.invoke(obj, Double.valueOf(value.toString())); } else if (parameterClass == Float.TYPE) { setterMethod.invoke(obj, Float.valueOf(value.toString())); } else if (parameterClass == Long.TYPE) { setterMethod.invoke(obj, Long.valueOf(value.toString())); } else/*from w w w . j a v a 2 s . co m*/ setterMethod.invoke(obj, value); }
From source file:com.flipkart.polyguice.config.ApacheCommonsConfigProvider.java
@Override public Object getValue(String path, Class<?> type) { if (!rootConfig.containsKey(path)) { return null; }/*from w ww. j a v a 2 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:org.jcommon.com.util.JsonUtils.java
public static String toJson(Object o, boolean encode) { StringBuilder sb = new StringBuilder(); Class<?> type = null;/*from w ww. j a va2 s . com*/ sb.append("{"); try { java.lang.reflect.Field[] fs = o.getClass().getDeclaredFields(); String name, value; for (java.lang.reflect.Field f : fs) { value = null; name = f.getName(); type = f.getType(); java.lang.reflect.Method m = getMethod(o.getClass(), "get" + name); if (m == null) m = getMethod(o.getClass(), "is" + name); if (m != null) { if (String.class == type) { value = (String) m.invoke(o); } else if (java.lang.Integer.class == type || Integer.TYPE == type) { value = String.valueOf((Integer) m.invoke(o)); } else if (java.lang.Boolean.class == type || Boolean.TYPE == type) { value = String.valueOf((Boolean) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { value = String.valueOf((Long) m.invoke(o)); } else if (java.lang.Float.class == type || Float.TYPE == type) { value = String.valueOf((Float) m.invoke(o)); } else if (java.lang.Long.class == type || Long.TYPE == type) { logger.info("not map Class:" + type); } } if (value != null) { if (encode) sb.append("\"" + CoderUtils.encode(name) + "\"" + ":\"" + CoderUtils.encode(value) + "\""); else sb.append("\"" + name + "\"" + ":\"" + value + "\""); sb.append(","); } } } catch (Throwable t) { logger.error("", t); } if (sb.lastIndexOf(",") == sb.length() - 1) sb.deleteCharAt(sb.length() - 1); sb.append("}"); return sb.toString(); }
From source file:org.zlogic.vogon.web.TomcatConfigurer.java
/** * Configures SSL for Tomcat container/* w w w. j a v a 2 s . c o m*/ * * @param container ConfigurableEmbeddedServletContainer instance to * configure */ private void configureSSL(ConfigurableEmbeddedServletContainer container) { if (serverTypeDetector.getKeystoreFile().isEmpty() || serverTypeDetector.getKeystorePassword().isEmpty()) { log.debug(messages.getString("KEYSTORE_FILE_OR_PASSWORD_NOT_DEFINED")); return; } log.info(MessageFormat.format(messages.getString("USING_KEYSTORE_WITH_PASSWORD"), new Object[] { serverTypeDetector.getKeystoreFile(), serverTypeDetector.getKeystorePassword().replaceAll(".{1}", "*") })); //NOI18N Object connector; Class connectorClass = null; try { log.debug(messages.getString("CONFIGURING_CONNECTOR")); connectorClass = getClass().getClassLoader().loadClass("org.apache.catalina.connector.Connector"); //NOI18N connector = connectorClass.newInstance(); connectorClass.getMethod("setPort", Integer.TYPE).invoke(connector, 8443); //NOI18N connectorClass.getMethod("setSecure", Boolean.TYPE).invoke(connector, true); //NOI18N connectorClass.getMethod("setScheme", String.class).invoke(connector, "https"); //NOI18N connectorClass.getMethod("setURIEncoding", String.class).invoke(connector, utf8Charset.name()); //NOI18N } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException(messages.getString("CANNOT_CONFIGURE_CONNECTOR"), ex); } Object proto; try { log.debug(messages.getString("CONFIGURING_PROTOCOLHANDLER_PARAMETERS")); proto = connectorClass.getMethod("getProtocolHandler").invoke(connector); //NOI18N Class protoClass = proto.getClass(); log.debug(java.text.MessageFormat.format(messages.getString("CONFIGURING_PROTOCOLHANDLER_CLASS"), new Object[] { protoClass.getCanonicalName() })); protoClass.getMethod("setSSLEnabled", Boolean.TYPE).invoke(proto, true); //NOI18N protoClass.getMethod("setKeystorePass", String.class).invoke(proto, serverTypeDetector.getKeystorePassword()); //NOI18N protoClass.getMethod("setKeystoreType", String.class).invoke(proto, "JKS"); //NOI18N protoClass.getMethod("setKeyAlias", String.class).invoke(proto, "vogonkey"); //NOI18N protoClass.getMethod("setKeystoreFile", String.class).invoke(proto, new File(serverTypeDetector.getKeystoreFile()).getAbsolutePath()); //NOI18N } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException(messages.getString("CANNOT_CONFIGURE_PROTOCOLHANDLER"), ex); } try { log.debug(messages.getString("ADDING_CONNECTOR_TO_TOMCATEMBEDDEDSERVLETCONTAINERFACTORY")); Object connectors = Array.newInstance(connectorClass, 1); Array.set(connectors, 0, connector); container.getClass().getMethod("addAdditionalTomcatConnectors", connectors.getClass()).invoke(container, connectors); //NOI18N } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { throw new RuntimeException( messages.getString("CANNOT_ADD_CONNECTOR_TO_TOMCATEMBEDDEDSERVLETCONTAINERFACTORY"), ex); } }
From source file:cc.aileron.accessor.TypeConvertorImpl.java
/** * default constractor// w w w. j a v a2 s.co m */ @Inject public TypeConvertorImpl() { map.put(Boolean.TYPE, new C() { @Override public Boolean convert(final java.lang.Number number) { return number.intValue() != 0; } }); map.put(Byte.TYPE, new C() { @Override public Byte convert(final java.lang.Number number) { return number.byteValue(); } }); map.put(Short.TYPE, new C() { @Override public Short convert(final java.lang.Number number) { return number.shortValue(); } }); map.put(Integer.TYPE, new C() { @Override public Integer convert(final java.lang.Number number) { return number.intValue(); } }); map.put(Long.TYPE, new C() { @Override public Long convert(final java.lang.Number number) { return number.longValue(); } }); map.put(Float.TYPE, new C() { @Override public Float convert(final java.lang.Number number) { return number.floatValue(); } }); map.put(Double.TYPE, new C() { @Override public Double convert(final java.lang.Number number) { return number.doubleValue(); } }); }