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:de.anhquan.config4j.internal.ConfigHandler.java
private Method findGetter(String key, Class<?> methodType) { String getMethodName = "get" + key; Method getter = null;//from ww w.j a va 2s .c o m try { getter = configType.getMethod(getMethodName); } catch (NoSuchMethodException e) { if (Boolean.TYPE.equals(methodType)) { try { getter = configType.getMethod("is" + key); } catch (NoSuchMethodException ex2) { } } } return getter; }
From source file:org.apache.cloudstack.storage.configdrive.ConfigDriveBuilderTest.java
@SuppressWarnings("unchecked") @Test(expected = CloudRuntimeException.class) public void writeFileTestwriteFileTestIOExceptionWhileWritingFile() throws Exception { PowerMockito.mockStatic(FileUtils.class); //Does not look good, I know... but this is the price of static methods. Method method = ReflectionUtils .getMethods(FileUtils.class, ReflectionUtils.withParameters(File.class, CharSequence.class, Charset.class, Boolean.TYPE)) .iterator().next();/*from w ww . j a v a2s . c o m*/ PowerMockito.when(FileUtils.class, method).withArguments(Mockito.any(File.class), Mockito.anyString(), Mockito.any(Charset.class), Mockito.anyBoolean()).thenThrow(IOException.class); ConfigDriveBuilder.writeFile(new File("folder"), "subfolder", "content"); }
From source file:be.fedict.eid.applet.service.impl.tlv.TlvParser.java
private static <T> T parseThrowing(byte[] file, Class<T> tlvClass) throws InstantiationException, IllegalAccessException, DataConvertorException, UnsupportedEncodingException { Field[] fields = tlvClass.getDeclaredFields(); Map<Integer, Field> tlvFields = new HashMap<Integer, Field>(); for (Field field : fields) { TlvField tlvFieldAnnotation = field.getAnnotation(TlvField.class); if (null == tlvFieldAnnotation) { continue; }/*from ww w .jav a2 s .co m*/ int tagId = tlvFieldAnnotation.value(); if (tlvFields.containsKey(new Integer(tagId))) { throw new IllegalArgumentException("TLV field duplicate: " + tagId); } tlvFields.put(new Integer(tagId), field); } T tlvObject = tlvClass.newInstance(); int idx = 0; while (idx < file.length - 1) { byte tag = file[idx]; idx++; byte lengthByte = file[idx]; int length = lengthByte & 0x7f; while ((lengthByte & 0x80) == 0x80) { idx++; lengthByte = file[idx]; length = (length << 7) + (lengthByte & 0x7f); } idx++; if (0 == tag) { idx += length; continue; } if (tlvFields.containsKey(new Integer(tag))) { Field tlvField = tlvFields.get(new Integer(tag)); Class<?> tlvType = tlvField.getType(); ConvertData convertDataAnnotation = tlvField.getAnnotation(ConvertData.class); byte[] tlvValue = copy(file, idx, length); Object fieldValue; if (null != convertDataAnnotation) { Class<? extends DataConvertor<?>> dataConvertorClass = convertDataAnnotation.value(); DataConvertor<?> dataConvertor = dataConvertorClass.newInstance(); fieldValue = dataConvertor.convert(tlvValue); } else if (String.class == tlvType) { fieldValue = new String(tlvValue, "UTF-8"); } else if (Boolean.TYPE == tlvType) { fieldValue = true; } else if (tlvType.isArray() && Byte.TYPE == tlvType.getComponentType()) { fieldValue = tlvValue; } else { throw new IllegalArgumentException("unsupported field type: " + tlvType.getName()); } LOG.debug("setting field: " + tlvField.getName()); if (null != tlvField.get(tlvObject) && false == tlvField.getType().isPrimitive()) { throw new RuntimeException("field was already set: " + tlvField.getName()); } tlvField.setAccessible(true); tlvField.set(tlvObject, fieldValue); } else { LOG.debug("unknown tag: " + (tag & 0xff) + ", length: " + length); } idx += length; } return tlvObject; }
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/*from ww w . j a v a 2s .co m*/ 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.steveash.typedconfig.resolver.type.simple.BooleanValueResolverFactory.java
@Override public boolean canResolveFor(ConfigBinding configBinding) { return configBinding.getDataType().isAssignableFrom(Boolean.class) || configBinding.getDataType().isAssignableFrom(Boolean.TYPE); }
From source file:org.projectforge.database.TableAttribute.java
/** * Creates a property and gets the information from the entity class. The JPA annotations Column, JoinColumn, Entity, Table and ID are * supported./*from ww w .j av a 2 s .co m*/ * @param clazz * @param property */ public TableAttribute(final Class<?> clazz, final String property) { this.property = property; this.name = property; final Method getterMethod = BeanHelper.determineGetter(clazz, property); if (getterMethod == null) { throw new IllegalStateException("Can't determine getter: " + clazz + "." + property); } final Class<?> dType = BeanHelper.determinePropertyType(getterMethod); final boolean primitive = dType.isPrimitive(); if (Boolean.class.isAssignableFrom(dType) == true || Boolean.TYPE.isAssignableFrom(dType) == true) { type = TableAttributeType.BOOLEAN; } else if (Integer.class.isAssignableFrom(dType) == true || Integer.TYPE.isAssignableFrom(dType) == true) { type = TableAttributeType.INT; } else if (String.class.isAssignableFrom(dType) == true || dType.isEnum() == true) { type = TableAttributeType.VARCHAR; } else if (BigDecimal.class.isAssignableFrom(dType) == true) { type = TableAttributeType.DECIMAL; } else if (java.sql.Date.class.isAssignableFrom(dType) == true) { type = TableAttributeType.DATE; } else if (java.util.Date.class.isAssignableFrom(dType) == true) { type = TableAttributeType.TIMESTAMP; } else if (java.util.Locale.class.isAssignableFrom(dType) == true) { type = TableAttributeType.LOCALE; } else { final Entity entity = dType.getAnnotation(Entity.class); final javax.persistence.Table table = dType.getAnnotation(javax.persistence.Table.class); if (entity != null && table != null && StringUtils.isNotEmpty(table.name()) == true) { this.foreignTable = table.name(); final String idProperty = JPAHelper.getIdProperty(dType); if (idProperty == null) { log.info("Id property not found for class '" + dType + "'): " + clazz + "." + property); } this.foreignAttribute = idProperty; final Column column = JPAHelper.getColumnAnnotation(dType, idProperty); if (column != null && StringUtils.isNotEmpty(column.name()) == true) { this.foreignAttribute = column.name(); } } else { log.info( "Unsupported property (@Entity, @Table and @Table.name expected for the destination class '" + dType + "'): " + clazz + "." + property); } type = TableAttributeType.INT; } final Id id = JPAHelper.getIdAnnotation(clazz, property); if (id != null) { this.primaryKey = true; this.nullable = false; } if (primitive == true) { nullable = false; } final Column column = JPAHelper.getColumnAnnotation(clazz, property); if (column != null) { if (isPrimaryKey() == false && primitive == false) { this.nullable = column.nullable(); } if (StringUtils.isNotEmpty(column.name()) == true) { this.name = column.name(); } if (type.isIn(TableAttributeType.VARCHAR, TableAttributeType.CHAR) == true) { this.length = column.length(); } if (type == TableAttributeType.DECIMAL) { this.precision = column.precision(); this.scale = column.scale(); } this.unique = column.unique(); } if (type == TableAttributeType.DECIMAL && this.scale == 0 && this.precision == 0) { throw new UnsupportedOperationException( "Decimal values should have a precision and scale definition: " + clazz + "." + property); } final JoinColumn joinColumn = JPAHelper.getJoinColumnAnnotation(clazz, property); if (joinColumn != null) { if (StringUtils.isNotEmpty(joinColumn.name()) == true) { this.name = joinColumn.name(); } } }
From source file:de.micromata.genome.util.bean.SoftCastPropertyUtilsBean.java
public Class<?> getWrappedClass(Class<?> target) { if (target.isPrimitive() == false) { return target; }/* w ww.j a v a2 s .co m*/ if (target == Integer.TYPE) { return Integer.class; } if (target == Long.TYPE) { return Long.class; } if (target == Byte.TYPE) { return Byte.class; } if (target == Short.TYPE) { return Short.class; } if (target == Float.TYPE) { return Short.class; } if (target == Double.TYPE) { return Double.class; } if (target == Character.TYPE) { return Character.class; } if (target == Boolean.TYPE) { return Boolean.class; } throw new RuntimeException("Unmapped basic type: " + target); }
From source file:ClassUtils.java
/** * Helper for invoking an instance method that takes a single parameter. * This method also handles parameters of primitive type. * /* w w w. jav a 2 s . c om*/ * @param cl * The class that the instance belongs to * @param instance * The object on which we will invoke the method * @param methodName * The method name * @param param * The parameter * @throws Throwable */ public static Object invokeMethod(Class cl, Object instance, String methodName, Object param) throws Throwable { Class paramClass; if (param instanceof Integer) paramClass = Integer.TYPE; else if (param instanceof Long) paramClass = Long.TYPE; else if (param instanceof Short) paramClass = Short.TYPE; else if (param instanceof Boolean) paramClass = Boolean.TYPE; else if (param instanceof Double) paramClass = Double.TYPE; else if (param instanceof Float) paramClass = Float.TYPE; else if (param instanceof Character) paramClass = Character.TYPE; else if (param instanceof Byte) paramClass = Byte.TYPE; else paramClass = param.getClass(); Method method = cl.getMethod(methodName, new Class[] { paramClass }); try { return method.invoke(instance, new Object[] { param }); } catch (InvocationTargetException e) { throw e.getCause(); } }
From source file:org.yccheok.jstock.gui.POIUtils.java
private static void handlePrimitive(Method method, Class<?> clazz) { if (clazz == Boolean.TYPE) { parameterTypeMap.put(Boolean.class, method); } else if (clazz == Character.TYPE) { parameterTypeMap.put(Character.class, method); } else if (clazz == Byte.TYPE) { parameterTypeMap.put(Byte.class, method); } else if (clazz == Short.TYPE) { parameterTypeMap.put(Short.class, method); } else if (clazz == Integer.TYPE) { parameterTypeMap.put(Integer.class, method); } else if (clazz == Long.TYPE) { parameterTypeMap.put(Long.class, method); } else if (clazz == Float.TYPE) { parameterTypeMap.put(Float.class, method); } else if (clazz == Double.TYPE) { parameterTypeMap.put(Double.class, method); } // ... and so on for the other six primitive types (void doesn't matter) }
From source file:org.eclim.command.Main.java
/** * Main method for executing the client. * * @param context The nailgun context.// w ww . j ava 2s. com */ public static final void nailMain(final NGContext context) { try { logger.debug("args: " + Arrays.toString(context.getArgs())); ArrayList<String> arguments = new ArrayList<String>(); for (String arg : context.getArgs()) { if (arg.startsWith("-D")) { String[] prop = StringUtils.split(arg.substring(2), '='); System.setProperty(prop[0], prop[1]); } else { arguments.add(arg); } } if (arguments.isEmpty() || arguments.contains("-?")) { int index = arguments.indexOf("-?"); String cmd = arguments.size() > index + 1 ? arguments.get(index + 1) : null; usage(cmd, context.out); System.exit(arguments.isEmpty() ? 1 : 0); } Options options = new Options(); final CommandLine commandLine = options .parse((String[]) arguments.toArray(new String[arguments.size()])); String commandName = commandLine.getValue(Options.COMMAND_OPTION); logger.debug("Main - command: {}", commandName); final Command command = commandLine.getCommand(); command.setContext(context); final Object[] results = new Object[1]; Display.getDefault().syncExec(new Runnable() { public void run() { try { results[0] = command.execute(commandLine); } catch (Exception e) { results[0] = e; } finally { command.cleanup(commandLine); } } }); Object result = results[0]; if (result != null) { if (result instanceof Throwable) { throw (Throwable) result; } GsonBuilder builder = new GsonBuilder(); if (commandLine.hasOption(Options.PRETTY_OPTION)) { builder = builder.setPrettyPrinting(); } if (commandLine.hasOption(Options.EDITOR_OPTION) && commandLine.getValue(Options.EDITOR_OPTION).equals("vim")) { builder = builder.registerTypeAdapter(Boolean.TYPE, new BooleanSerializer()) .registerTypeAdapter(Boolean.class, new BooleanSerializer()); } context.out.println(builder.create().toJson(result)); } } catch (ParseException e) { context.out.println(Services.getMessage(e.getClass().getName(), e.getMessage())); logger.debug("Main - exit on error"); System.exit(1); } catch (Throwable e) { logger.debug("Command triggered exception: " + Arrays.toString(context.getArgs()), e); e.printStackTrace(context.err); logger.debug("Main - exit on error"); System.exit(1); } }