protected void addStates(SchemaImpl schema, SchemaFactory factory) { String type = factory.getBaseType(schema.getId()); Set<String> validStates = this.validStates.get(type); Field stateField = schema.getResourceFields().get(ObjectMetaDataManager.STATE_FIELD); if (validStates != null && stateField instanceof FieldImpl) { FieldImpl field = (FieldImpl) stateField; field.setOptions(new ArrayList<String>(validStates)); field.setTypeEnum(FieldType.ENUM); } }
protected FieldType assignSimpleType(Class<?> clzType, FieldImpl field) { FieldType result = null; if (clzType.isEnum()) { result = FieldType.ENUM; } else { outer: for (FieldType type : FieldType.values()) { Class<?>[] clzs = type.getClasses(); if (clzs == null) continue; for (Class<?> clz : clzs) { if (clz.isAssignableFrom(clzType)) { result = type; if ((Number.class.isAssignableFrom(clzType) || Boolean.class.isAssignableFrom(clzType)) && !clz.isPrimitive() && field != null) { field.setNullable(true); } break outer; } } } } if (field != null) { field.setTypeEnum(result); } return result; }
protected void addField(SchemaImpl schema, String name, FieldType type, String... options) { Field f = schema.getResourceFields().get(name); if (f != null) { return; } FieldImpl newField = new FieldImpl(); newField.setTypeEnum(type); newField.setName(name); if (type == FieldType.ENUM) { newField.setOptions(Arrays.asList(options)); } else { newField.setNullable(true); } schema.getResourceFields().put(name, newField); }
protected void assignType(PropertyDescriptor prop, FieldImpl field, io.github.ibuildthecloud.gdapi.annotation.Field f) { if (f.type() != FieldType.NONE) { field.setTypeEnum(f.type()); return; } if (!StringUtils.isEmpty(f.typeString())) { field.setType(f.typeString()); return; } if (f.password()) { field.setTypeEnum(FieldType.PASSWORD); return; } assignSimpleType(prop.getPropertyType(), field); List<TypeAndName> types = new ArrayList<FieldType.TypeAndName>(); Method readMethod = prop.getReadMethod(); if (readMethod != null) { getTypes(readMethod.getGenericReturnType(), types); } if (types.size() == 1) { field.setType(types.get(0).getName()); } else if (types.size() > 1) { types.remove(0); field.setSubTypesList(types); } }