Search in sources :

Example 1 with MemorySchemaOutputResolver

use of org.platformlayer.xml.MemorySchemaOutputResolver in project platformlayer by platformlayer.

the class ServiceResource method getSchema.

@GET
@Path("schema")
@Produces({ XML })
public String getSchema() throws IOException, JAXBException {
    ServiceProvider serviceProvider = getServiceProvider();
    String namespace = null;
    List<Class<?>> javaClasses = Lists.newArrayList();
    for (ModelClass<?> modelClass : serviceProvider.getModels().all()) {
        javaClasses.add(modelClass.getJavaClass());
        String modelNamespace = modelClass.getPrimaryNamespace();
        if (namespace == null) {
            namespace = modelNamespace;
        } else if (!namespace.equals(modelNamespace)) {
            throw new IllegalStateException();
        }
    }
    JAXBContext jaxbContext = JAXBContext.newInstance(javaClasses.toArray(new Class<?>[javaClasses.size()]));
    MemorySchemaOutputResolver schemaOutputResolver = new MemorySchemaOutputResolver();
    jaxbContext.generateSchema(schemaOutputResolver);
    Map<String, StringWriter> writers = schemaOutputResolver.getWriters();
    StringWriter writer = writers.get(namespace);
    if (writer == null) {
        throw new IllegalArgumentException();
    }
    return writer.getBuffer().toString();
}
Also used : MemorySchemaOutputResolver(org.platformlayer.xml.MemorySchemaOutputResolver) StringWriter(java.io.StringWriter) ServiceProvider(org.platformlayer.xaas.services.ServiceProvider) ModelClass(org.platformlayer.xaas.services.ModelClass) JAXBContext(javax.xml.bind.JAXBContext) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StringWriter (java.io.StringWriter)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 JAXBContext (javax.xml.bind.JAXBContext)1 ModelClass (org.platformlayer.xaas.services.ModelClass)1 ServiceProvider (org.platformlayer.xaas.services.ServiceProvider)1 MemorySchemaOutputResolver (org.platformlayer.xml.MemorySchemaOutputResolver)1