Пример #1
0
 @Override
 public NamedAssociationState namedAssociationValueOf(QualifiedName stateName) {
   try {
     JSONObject namedAssociations = state.getJSONObject(JSONKeys.NAMED_ASSOCIATIONS);
     JSONObject jsonValues = namedAssociations.optJSONObject(stateName.name());
     if (jsonValues == null) {
       jsonValues = new JSONObject();
       namedAssociations.put(stateName.name(), jsonValues);
     }
     return new JSONNamedAssociationState(this, jsonValues);
   } catch (JSONException e) {
     throw new EntityStoreException(e);
   }
 }
Пример #2
0
 @Override
 public ManyAssociationState manyAssociationValueOf(QualifiedName stateName) {
   try {
     JSONObject manyAssociations = state.getJSONObject(JSONKeys.MANY_ASSOCIATIONS);
     JSONArray jsonValues = manyAssociations.optJSONArray(stateName.name());
     if (jsonValues == null) {
       jsonValues = new JSONArray();
       manyAssociations.put(stateName.name(), jsonValues);
     }
     return new JSONManyAssociationState(this, jsonValues);
   } catch (JSONException e) {
     throw new EntityStoreException(e);
   }
 }
Пример #3
0
  private void initialize() {
    this.type = GenericAssociationInfo.associationTypeOf(accessor);
    this.qualifiedName = QualifiedName.fromAccessor(accessor);
    this.immutable = metaInfo.get(Immutable.class) != null;
    this.aggregated = metaInfo.get(Aggregated.class) != null;

    final Queryable queryable = accessor.getAnnotation(Queryable.class);
    this.queryable = queryable == null || queryable.value();
  }
Пример #4
0
 @Override
 public void setAssociationValue(QualifiedName stateName, EntityReference newEntity) {
   try {
     cloneStateIfGlobalStateLoaded();
     state
         .getJSONObject(JSONKeys.ASSOCIATIONS)
         .put(stateName.name(), newEntity == null ? null : newEntity.identity());
     markUpdated();
   } catch (JSONException e) {
     throw new EntityStoreException(e);
   }
 }
Пример #5
0
  @Override
  public EntityReference associationValueOf(QualifiedName stateName) {
    try {
      Object jsonValue = state.getJSONObject(JSONKeys.ASSOCIATIONS).opt(stateName.name());
      if (jsonValue == null) {
        return null;
      }

      EntityReference value =
          jsonValue == JSONObject.NULL
              ? null
              : EntityReference.parseEntityReference((String) jsonValue);
      return value;
    } catch (JSONException e) {
      throw new EntityStoreException(e);
    }
  }
Пример #6
0
 @Override
 public Object propertyValueOf(QualifiedName stateName) {
   try {
     Object json = state.getJSONObject(JSONKeys.PROPERTIES).opt(stateName.name());
     if (JSONObject.NULL.equals(json)) {
       return null;
     } else {
       PropertyDescriptor descriptor =
           entityDescriptor.state().findPropertyModelByQualifiedName(stateName);
       if (descriptor == null) {
         return null;
       }
       return valueSerialization.deserialize(descriptor.valueType(), json.toString());
     }
   } catch (ValueSerializationException | JSONException e) {
     throw new EntityStoreException(e);
   }
 }
Пример #7
0
  private static void addProperties(
      Map<Type, ValueType> typeMap,
      Class valueTypeClass,
      Class compositeType,
      List<PropertyType> types) {
    for (Method method : valueTypeClass.getDeclaredMethods()) {
      Type returnType = method.getGenericReturnType();
      if (returnType instanceof ParameterizedType
          && ((ParameterizedType) returnType).getRawType().equals(Property.class)) {
        Type propType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
        RDF rdfAnnotation = method.getAnnotation(RDF.class);
        String rdf = rdfAnnotation == null ? null : rdfAnnotation.value();
        Queryable queryableAnnotation = method.getAnnotation(Queryable.class);
        boolean queryable = queryableAnnotation == null || queryableAnnotation.value();
        ValueType propValueType = newValueType(typeMap, propType, valueTypeClass, compositeType);
        PropertyType propertyType =
            new PropertyType(
                QualifiedName.fromMethod(method),
                propValueType,
                rdf,
                queryable,
                PropertyType.PropertyTypeEnum.IMMUTABLE);
        types.add(propertyType);
      }
    }

    // Add methods from subinterface
    for (Type subType : valueTypeClass.getGenericInterfaces()) {
      // Handles generic type variables
      Class subClass;
      if (subType instanceof ParameterizedType) {
        subClass = (Class) ((ParameterizedType) subType).getRawType();
      } else {
        subClass = (Class) subType;
      }

      addProperties(typeMap, subClass, valueTypeClass, types);
    }
  }
Пример #8
0
 @Override
 public void setPropertyValue(QualifiedName stateName, Object newValue) {
   try {
     Object jsonValue;
     if (newValue == null || ValueType.isPrimitiveValue(newValue)) {
       jsonValue = newValue;
     } else {
       String serialized = valueSerialization.serialize(newValue);
       if (serialized.startsWith("{")) {
         jsonValue = new JSONObject(serialized);
       } else if (serialized.startsWith("[")) {
         jsonValue = new JSONArray(serialized);
       } else {
         jsonValue = serialized;
       }
     }
     cloneStateIfGlobalStateLoaded();
     state.getJSONObject(JSONKeys.PROPERTIES).put(stateName.name(), jsonValue);
     markUpdated();
   } catch (ValueSerializationException | JSONException e) {
     throw new EntityStoreException(e);
   }
 }