List of usage examples for java.lang Class isPrimitive
@HotSpotIntrinsicCandidate public native boolean isPrimitive();
From source file:com.github.nmorel.gwtjackson.client.AbstractConfiguration.java
/** * Return a {@link PrimitiveTypeConfiguration} to configure serializer and/or deserializer for the given primitive type. *///from www. ja v a 2s . co m protected PrimitiveTypeConfiguration primitiveType(Class type) { if (!type.isPrimitive()) { throw new IllegalArgumentException("Type " + type + " is not a primitive. Call type(Class) instead"); } return new PrimitiveTypeConfiguration(type); }
From source file:com.github.nmorel.gwtjackson.client.AbstractConfiguration.java
/** * Return a {@link KeyTypeConfiguration} to configure key serializer and/or deserializer for the given type. *//*from w w w . j a v a2 s . c om*/ protected <T> KeyTypeConfiguration<T> key(Class<T> type) { if (type.isPrimitive()) { throw new IllegalArgumentException("Primitive types cannot be used as a map's key"); } return new KeyTypeConfiguration<T>(type); }
From source file:com.github.nmorel.gwtjackson.client.AbstractConfiguration.java
/** * Return a {@link TypeConfiguration} to configure serializer and/or deserializer for the given type. *///from w ww . j a va 2s .c o m protected <T> TypeConfiguration<T> type(Class<T> type) { if (type.isPrimitive()) { throw new IllegalArgumentException( "Type " + type + " is a primitive. Call primitiveType(Class) instead"); } return new TypeConfiguration<T>(type); }
From source file:com.github.erchu.beancp.MapperImpl.java
@SuppressWarnings({ "TooBroadCatch", "UseSpecificCatch" }) private <D> D constructObjectUsingDefaultConstructor(final Class<D> destinationClass) throws MappingException { try {//from w w w . j a va 2s.c om if (destinationClass.isPrimitive()) { return (D) ClassUtils.primitiveToWrapper(destinationClass); } else { return (D) destinationClass.newInstance(); } } catch (Exception ex) { throw new MappingException("Cannot create destination instance.", ex); } }
From source file:cn.powerdash.libsystem.common.converter.DeepConverter.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w . ja v a2 s.c om*/ public Object convert(Object value, Class targetClass, Object context) { if (targetClass != null && value != null) { Class<? extends Object> sourceClass = value.getClass(); if (targetClass.equals(sourceClass)) { return value; } // primitive type if (sourceClass.isPrimitive() || targetClass.isPrimitive()) { return value; } // collection if (Collection.class.isAssignableFrom(sourceClass) && Collection.class.isAssignableFrom(targetClass)) { // not supported return null; } else if (Timestamp.class.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(String.class)) { return new SimpleDateFormat(TIMESTAMP_FORMAT).format((Timestamp) value); } else if (Date.class.isAssignableFrom(sourceClass) && targetClass.isAssignableFrom(String.class)) { return new SimpleDateFormat(DATE_FORMAT).format((Date) value); } else if (java.util.Date.class.isAssignableFrom(targetClass) && sourceClass.isAssignableFrom(String.class)) { try { return DateUtils.parseDate(value.toString(), new String[] { "yyyy-MM-dd" }); } catch (ParseException e) { return null; } } else if (targetClass.isAssignableFrom(sourceClass)) { return value; } // complex type if (targetClass.getClassLoader() != null && sourceClass.getClassLoader() != null) { return ConverterService.convert(value, targetClass, null); } } return null; }
From source file:com.evolveum.midpoint.web.component.assignment.ACAttributeValuePanel.java
private InputPanel createTypedInputComponent(String id, PrismPropertyDefinition definition) { QName valueType = definition.getTypeName(); final String baseExpression = ACValueConstructionDto.F_VALUE; InputPanel panel;//from www. j ava 2 s . c o m if (DOMUtil.XSD_DATETIME.equals(valueType)) { panel = new DatePanel(id, new PropertyModel<XMLGregorianCalendar>(getModel(), baseExpression)); } else if (ProtectedStringType.COMPLEX_TYPE.equals(valueType)) { panel = new PasswordPanel(id, new PropertyModel<ProtectedStringType>(getModel(), baseExpression)); } else if (DOMUtil.XSD_BOOLEAN.equals(valueType)) { panel = new TriStateComboPanel(id, new PropertyModel<Boolean>(getModel(), baseExpression)); } else if (SchemaConstants.T_POLY_STRING_TYPE.equals(valueType)) { panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression + ".orig"), String.class); } else { Class type = XsdTypeMapper.getXsdToJavaMapping(valueType); if (type != null && type.isPrimitive()) { type = ClassUtils.primitiveToWrapper(type); } panel = new TextPanel<String>(id, new PropertyModel<String>(getModel(), baseExpression), type); if (ObjectType.F_NAME.equals(definition.getName())) { panel.getBaseFormComponent().setRequired(true); } } return panel; }
From source file:com.bstek.dorado.idesupport.robot.EntityDataTypeReflectionRobot.java
public Node execute(Node node, Properties properties) throws Exception { ConfigureStore configureStore = Configure.getStore(); configureStore.set("core.contextConfigLocation", CONFIG_LOCATIONS); CommonContext.init();/*w w w .ja v a 2 s . co m*/ try { Context context = Context.getCurrent(); XmlParserHelper xmlParserHelper = (XmlParserHelper) context.getServiceBean("xmlParserHelper"); XmlParser dataTypeParser = xmlParserHelper.getXmlParser(EntityDataType.class); DataConfigManager dataConfigManager = (DataConfigManager) context.getServiceBean("dataConfigManager"); dataConfigManager.initialize(); DataParseContext parseContext = new DataParseContext(); parseContext.setDataTypeDefinitionManager( (DataTypeDefinitionManager) context.getServiceBean("dataTypeDefinitionManager")); parseContext.setDataProviderDefinitionManager( (DataProviderDefinitionManager) context.getServiceBean("dataProviderDefinitionManager")); parseContext.setDataResolverDefinitionManager( (DataResolverDefinitionManager) context.getServiceBean("dataResolverDefinitionManager")); DataTypeDefinition dataTypeDefinition = (DataTypeDefinition) dataTypeParser.parse(node, parseContext); Class<?> matchType = dataTypeDefinition.getMatchType(); if (matchType != null) { if (matchType == null || matchType.isPrimitive() || matchType.isArray()) { throw new IllegalArgumentException("[matchType] undefined or not a valid class."); } node = node.cloneNode(true); reflectAndComplete((Element) node, matchType); } } finally { CommonContext.dispose(); } return node; }
From source file:com.gzj.tulip.jade.statement.JdbcStatement.java
public JdbcStatement(StatementMetaData statementMetaData, SQLType sqlType, Interpreter[] interpreters, Querier querier) {/*from www.j a v a 2s .c o m*/ this.metaData = statementMetaData; AfterInvocation afterInvocationAnnotation = metaData.getMethod().getAnnotation(AfterInvocation.class); if (afterInvocationAnnotation != null) { try { this.afterInvocationCallback = afterInvocationAnnotation.value().newInstance(); } catch (InstantiationException e) { throw new IllegalArgumentException(e); } catch (IllegalAccessException e) { throw new IllegalArgumentException(e); } } else { this.afterInvocationCallback = nullAfterInvocationCallback; } this.interpreters = (interpreters == null) ? new Interpreter[0] : interpreters; this.querier = querier; this.sqlType = sqlType; if (sqlType == SQLType.WRITE) { Method method = statementMetaData.getMethod(); Class<?>[] types = method.getParameterTypes(); Class<?> returnType = statementMetaData.getReturnType(); if (returnType.isPrimitive()) { returnType = ClassUtils.primitiveToWrapper(returnType); } //change by guozijian 2016-2-09-29 //?SQL??? //???updateinsert??? SQL sqlAnnotation = method.getAnnotation(SQL.class); if (types.length > 0 && List.class.isAssignableFrom(types[0]) && (sqlAnnotation == null // @SQL || StringUtils.isBlank(sqlAnnotation.value()))) // SQL { //TODO ?List????? //if (types.length > 0 && List.class.isAssignableFrom(types[0])) { this.batchUpdate = true; if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) { // ????@ReturnGeneratedKeys throw new InvalidDataAccessApiUsageException( "batch update method cannot return generated keys: " + method); } if (returnType != void.class && returnType != int[].class // && returnType != Integer.class && returnType != Boolean.class) { throw new InvalidDataAccessApiUsageException( "error return type, only support type of {void,boolean,int,int[]}: " + method); } } else { this.batchUpdate = false; if (metaData.getMethod().getAnnotation(ReturnGeneratedKeys.class) != null) { metaData.getReturnGeneratedKeys().checkMethodReturnType(metaData.getReturnType(), metaData); } else if (returnType != void.class && returnType != Boolean.class && returnType != Integer.class) { throw new InvalidDataAccessApiUsageException( "error return type, only support type of {void,boolean,int}:" + method); } } } else { this.batchUpdate = false; } this.logPrefix = "\n @method:" + this.metaData; }
From source file:com.yosanai.java.swing.editor.ObjectEditorTableModel.java
public boolean isPrimitive(Class<?> classObj) { boolean ret = false; ret = null != classObj && (classObj.isPrimitive() || classObj.isEnum() || classObj.equals(Integer.class) || classObj.equals(Float.class) || classObj.equals(Double.class) || classObj.equals(Date.class) || classObj.equals(String.class) || classObj.equals(Boolean.class) || Number.class.isAssignableFrom(classObj)); return ret;/*from w w w . j a va2s . c o m*/ }
From source file:net.sf.json.util.DynaBeanToBeanMorpher.java
/** * DOCUMENT ME!/*from w w w . ja va2 s .com*/ * * @param clazz DOCUMENT ME! */ private void validateClass(Class clazz) { if (clazz == null) { throw new IllegalArgumentException("target class is null"); } else if (clazz.isPrimitive()) { throw new IllegalArgumentException("target class is a primitive"); } else if (clazz.isArray()) { throw new IllegalArgumentException("target class is an array"); } else if (clazz.isInterface()) { throw new IllegalArgumentException("target class is an interface"); } else if (DynaBean.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a DynaBean"); } else if (Number.class.isAssignableFrom(clazz) || Boolean.class.isAssignableFrom(clazz) || Character.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a wrapper"); } else if (String.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a String"); } else if (Collection.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a Collection"); } else if (Map.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("target class is a Map"); } }