Esempio n. 1
0
  public File writeFile(File outdirFile, String fileName) throws IOException {
    fileName += RestConstants.SNAPSHOT_FILENAME_EXTENTION;
    final File file = new File(outdirFile, fileName);

    FileOutputStream fileOutputStream = new FileOutputStream(file);

    JsonBuilder jsonBuilder = new JsonBuilder(JsonBuilder.Pretty.INDENTED);
    SchemaToJsonEncoder encoder = new SchemaToJsonEncoder(jsonBuilder);

    jsonBuilder.writeStartObject();
    jsonBuilder.writeFieldName(Snapshot.MODELS_KEY);
    jsonBuilder.writeStartArray();

    List<NamedDataSchema> models = generateModelList();

    for (DataSchema model : models) {
      encoder.encode(model);
    }

    jsonBuilder.writeEndArray();

    jsonBuilder.writeFieldName(Snapshot.SCHEMA_KEY);
    jsonBuilder.writeStartObject();
    jsonBuilder.writeProperties(_topLevelSchema.data());
    jsonBuilder.writeEndObject();

    jsonBuilder.writeEndObject();

    try {
      fileOutputStream.write(jsonBuilder.result().getBytes());
    } finally {
      fileOutputStream.close();
    }
    return file;
  }
Esempio n. 2
0
 private void findModelsAssocation(
     ResourceSchema resourceSchema,
     Map<String, NamedDataSchema> foundTypes,
     List<NamedDataSchema> typeOrder) {
   AssociationSchema association = resourceSchema.getAssociation();
   if (association != null) {
     for (AssocKeySchema assocKeySchema : association.getAssocKeys()) {
       String type = assocKeySchema.getType();
       recordType(type, foundTypes, typeOrder);
     }
     if (association.hasFinders()) {
       for (FinderSchema restMethodSchema : association.getFinders()) {
         findModelsFinder(restMethodSchema, foundTypes, typeOrder);
       }
     }
     if (association.hasMethods()) {
       for (RestMethodSchema restMethodSchema : association.getMethods()) {
         findModelsMethod(restMethodSchema, foundTypes, typeOrder);
       }
     }
     if (association.hasActions()) {
       for (ActionSchema actionSchema : association.getActions()) {
         findModelsAction(actionSchema, foundTypes, typeOrder);
       }
     }
     if (association.hasEntity()) {
       EntitySchema entitySchema = association.getEntity();
       findModelsEntity(entitySchema, foundTypes, typeOrder);
     }
   }
 }
Esempio n. 3
0
 private void findModelsCollection(
     ResourceSchema resourceSchema,
     Map<String, NamedDataSchema> foundTypes,
     List<NamedDataSchema> typeOrder) {
   CollectionSchema collection = resourceSchema.getCollection();
   if (collection != null) {
     IdentifierSchema identifier = collection.getIdentifier();
     findModelsIdentifier(identifier, foundTypes, typeOrder);
     if (collection.hasFinders()) {
       for (FinderSchema restMethodSchema : collection.getFinders()) {
         findModelsFinder(restMethodSchema, foundTypes, typeOrder);
       }
     }
     if (collection.hasMethods()) {
       for (RestMethodSchema restMethodSchema : collection.getMethods()) {
         findModelsMethod(restMethodSchema, foundTypes, typeOrder);
       }
     }
     if (collection.hasActions()) {
       for (ActionSchema actionSchema : collection.getActions()) {
         findModelsAction(actionSchema, foundTypes, typeOrder);
       }
     }
     if (collection.hasEntity()) {
       EntitySchema entity = collection.getEntity();
       findModelsEntity(entity, foundTypes, typeOrder);
     }
   }
 }
Esempio n. 4
0
 private void findModelsActionSet(
     ResourceSchema resourceSchema,
     Map<String, NamedDataSchema> foundTypes,
     List<NamedDataSchema> typeOrder) {
   ActionsSetSchema actionsSet = resourceSchema.getActionsSet();
   if (actionsSet != null) {
     if (actionsSet.hasActions()) {
       for (ActionSchema actionSchema : actionsSet.getActions()) {
         findModelsAction(actionSchema, foundTypes, typeOrder);
       }
     }
   }
 }
Esempio n. 5
0
  private void findModelsResource(
      ResourceSchema resourceSchema,
      Map<String, NamedDataSchema> foundTypes,
      List<NamedDataSchema> typeOrder) {
    String schema = resourceSchema.getSchema();
    if (schema != null) {
      recordType(schema, foundTypes, typeOrder);
    }

    findModelsActionSet(resourceSchema, foundTypes, typeOrder);

    findModelsAssocation(resourceSchema, foundTypes, typeOrder);

    findModelsCollection(resourceSchema, foundTypes, typeOrder);

    findModelsSimple(resourceSchema, foundTypes, typeOrder);
  }
Esempio n. 6
0
 private void findModelsSimple(
     ResourceSchema resourceSchema,
     Map<String, NamedDataSchema> foundTypes,
     List<NamedDataSchema> typeOrder) {
   SimpleSchema simple = resourceSchema.getSimple();
   if (simple != null) {
     if (simple.hasMethods()) {
       for (RestMethodSchema restMethodSchema : simple.getMethods()) {
         findModelsMethod(restMethodSchema, foundTypes, typeOrder);
       }
     }
     if (simple.hasActions()) {
       for (ActionSchema actionSchema : simple.getActions()) {
         findModelsAction(actionSchema, foundTypes, typeOrder);
       }
     }
     if (simple.hasEntity()) {
       EntitySchema entity = simple.getEntity();
       findModelsEntity(entity, foundTypes, typeOrder);
     }
   }
 }