Пример #1
0
  private static ValueType newValueType(
      Map<Type, ValueType> typeMap, Type type, Class declaringClass, Class compositeType) {
    ValueType valueType = null;
    if (CollectionType.isCollection(type)) {
      if (type instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) type;
        Type collectionType = pt.getActualTypeArguments()[0];
        if (collectionType instanceof TypeVariable) {
          TypeVariable collectionTypeVariable = (TypeVariable) collectionType;
          collectionType =
              Classes.resolveTypeVariable(collectionTypeVariable, declaringClass, compositeType);
        }
        ValueType collectedType =
            newValueType(typeMap, collectionType, declaringClass, compositeType);
        valueType = new CollectionType(nameOf(type), collectedType);
      } else {
        valueType =
            new CollectionType(
                nameOf(type), newValueType(typeMap, Object.class, declaringClass, compositeType));
      }
    } else if (ValueCompositeType.isValueComposite(type)) {
      if (typeMap != null) {
        valueType = typeMap.get(type);
      }

      if (valueType == null) {
        Class valueTypeClass = Classes.getRawClass(type);

        List<PropertyType> types = new ArrayList<PropertyType>();
        valueType = new ValueCompositeType(nameOf(valueTypeClass), types);
        if (typeMap == null) {
          typeMap = new HashMap<Type, ValueType>();
        }
        typeMap.put(type, valueType);

        addProperties(typeMap, valueTypeClass, compositeType, types);

        Collections.sort(types); // Sort by property name
      }
    } else if (EnumType.isEnum(type)) {
      valueType = new EnumType(nameOf(type));
    } else if (StringType.isString(type)) {
      valueType = new StringType();
    } else if (NumberType.isNumber(type)) {
      valueType = new NumberType(nameOf(type));
    } else if (BooleanType.isBoolean(type)) {
      valueType = new BooleanType();
    } else if (DateType.isDate(type)) {
      valueType = new DateType();
    } else if (EntityReferenceType.isEntityReference(type)) {
      valueType = new EntityReferenceType(nameOf(type));
    } else {
      // TODO: shouldn't we check that the type is a Serializable?
      valueType = new SerializableType(nameOf(type));
    }

    return valueType;
  }
Пример #2
0
  @Override
  public void bind(Resolution resolution) throws BindingException {
    builderInfo =
        new AssociationInfo() {
          @Override
          public boolean isImmutable() {
            return false;
          }

          @Override
          public QualifiedName qualifiedName() {
            return qualifiedName;
          }

          @Override
          public Type type() {
            return type;
          }

          @Override
          public void checkConstraints(Object value) throws ConstraintViolationException {
            AssociationModel.this.checkConstraints(value);
          }
        };

    if (type instanceof TypeVariable) {

      Class mainType = first(resolution.model().types());
      type =
          Classes.resolveTypeVariable(
              (TypeVariable) type, ((Member) accessor).getDeclaringClass(), mainType);
    }
  }
    public Field fieldGroupFieldsAdded(
        @Optional DomainEvent event, Field fieldGroup, String id, Field fieldGroupField) {

      FieldValueDefinition.Data definition = (FieldValueDefinition.Data) fieldGroupField;

      EntityBuilder<Field> fieldBuilder =
          module.unitOfWorkFactory().currentUnitOfWork().newEntityBuilder(Field.class, id);
      fieldBuilder.instanceFor(Mandatory.Data.class).mandatory().set(fieldGroupField.isMandatory());
      fieldBuilder.instanceFor(Notable.Data.class).note().set(fieldGroupField.getNote());
      fieldBuilder
          .instanceFor(Describable.Data.class)
          .description()
          .set(fieldGroupField.getDescription());
      fieldBuilder
          .instanceFor(Datatype.Data.class)
          .datatype()
          .set(((Datatype.Data) fieldGroupField).datatype().get());
      fieldBuilder
          .instanceFor(Statistical.Data.class)
          .statistical()
          .set(((Statistical.Data) fieldGroupField).statistical().get());

      FieldValue fieldValue = definition.fieldValue().get();
      fieldBuilder.instanceFor(FieldValueDefinition.Data.class).fieldValue().set(fieldValue);

      String fieldId =
          Classes.interfacesOf(fieldValue.getClass()).iterator().next().getSimpleName();
      fieldId =
          fieldGroup.getDescription()
              + "_"
              + fieldId.substring(0, fieldId.length() - "FieldValue".length());
      fieldId += data.groupFields().count() + 1;
      fieldBuilder.instanceFor(FieldId.Data.class).fieldId().set(fieldId);

      Field createdFieldGroupField = fieldBuilder.newInstance();

      return createdFieldGroupField;
    }