コード例 #1
0
 /**
  * generateXMLExampleJAXB.
  *
  * @param t a {@link com.mulesoft.jaxrs.raml.annotation.model.ITypeModel} object.
  * @return a {@link java.lang.String} object.
  */
 protected String generateXMLExampleJAXB(ITypeModel t) {
   JAXBRegistry rs = new JAXBRegistry();
   JAXBType jaxbModel = rs.getJAXBModel(t);
   if (jaxbModel != null) {
     XMLWriter writer = new XMLWriter();
     ExampleGenerator gen = new ExampleGenerator(writer);
     gen.generateXML(jaxbModel);
     return writer.toString();
   }
   return null;
 }
コード例 #2
0
  /**
   * afterSchemaGen.
   *
   * @param t a {@link com.mulesoft.jaxrs.raml.annotation.model.ITypeModel} object.
   * @param st
   * @param gotXSD
   */
  protected void afterSchemaGen(ITypeModel t, StructureType st) {

    JAXBRegistry rs = new JAXBRegistry();
    JAXBType jaxbModel = rs.getJAXBModel(t);

    if (jaxbModel == null) {
      return;
    }
    ISchemaType schemaModel = null;
    try {
      schemaModel = new SchemaModelBuilder().buildSchemaModel(jaxbModel, st);
    } catch (Exception e) {
      e.printStackTrace();
    }
    if (schemaModel == null) {
      return;
    }

    try {
      if (st == StructureType.COMMON) {
        String xmlExample = new XMLModelSerializer().serialize(schemaModel);
        writeString(xmlExample, constructFileLocation(t.getName(), EXAMPLE, XML));
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      String jsonExample = new JsonModelSerializer().serialize(schemaModel);
      writeString(jsonExample, constructFileLocation(t.getName(), EXAMPLE, JSON));
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      String jsonSchema = new JsonSchemaModelSerializer().serialize(schemaModel);
      spec.getCoreRaml()
          .addGlobalSchema(firstLetterToLowerCase(t.getName()), jsonSchema, true, true);
      writeString(jsonSchema, constructFileLocation(t.getName(), SCHEMA, JSON));
    } catch (Exception e) {
      e.printStackTrace();
    }
  }