com.android.repository.impl.meta
Class SchemaModuleUtil

java.lang.Object
  extended by com.android.repository.impl.meta.SchemaModuleUtil

public class SchemaModuleUtil
extends java.lang.Object

Utilities for working with SchemaModules, including marshalling and unmarshalling with JAXB.


Constructor Summary
SchemaModuleUtil()
           
 
Method Summary
static org.w3c.dom.ls.LSResourceResolver createResourceResolver(java.util.Collection<SchemaModule> modules, ProgressIndicator progress)
          Create an LSResourceResolver that will use the supplied SchemaModules to find an XSD from its namespace.
static javax.xml.validation.Schema getSchema(java.util.Collection<SchemaModule> possibleModules, org.w3c.dom.ls.LSResourceResolver resourceResolver, ProgressIndicator progress)
          Creates a Schema from a collection of SchemaModules, with a given LSResourceResolver (probably obtained from createResourceResolver(Collection, ProgressIndicator).
static void marshal(javax.xml.bind.JAXBElement element, java.util.Collection<SchemaModule> possibleModules, java.io.OutputStream out, org.w3c.dom.ls.LSResourceResolver resourceResolver, ProgressIndicator progress)
          Transform the given JAXBElement into xml, using JAXB and the schemas provided by the given SchemaModules.
static java.lang.Object unmarshal(java.io.InputStream xml, java.util.Collection<SchemaModule> possibleModules, org.w3c.dom.ls.LSResourceResolver resourceResolver, boolean strict, ProgressIndicator progress)
          Use JAXB to create POJOs from the given XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaModuleUtil

public SchemaModuleUtil()
Method Detail

createResourceResolver

@Nullable
public static org.w3c.dom.ls.LSResourceResolver createResourceResolver(@NonNull
                                                                                java.util.Collection<SchemaModule> modules,
                                                                                @NonNull
                                                                                ProgressIndicator progress)
Create an LSResourceResolver that will use the supplied SchemaModules to find an XSD from its namespace. This must be used when marshalling/unmarshalling if any SchemaModules contain XSDs which import others without specifying a complete schemaLocation.


getSchema

@NonNull
public static javax.xml.validation.Schema getSchema(java.util.Collection<SchemaModule> possibleModules,
                                                            @Nullable
                                                            org.w3c.dom.ls.LSResourceResolver resourceResolver,
                                                            ProgressIndicator progress)
Creates a Schema from a collection of SchemaModules, with a given LSResourceResolver (probably obtained from createResourceResolver(Collection, ProgressIndicator). Any warnings or errors are logged to the given ProgressIndicator.


unmarshal

@Nullable
public static java.lang.Object unmarshal(@NonNull
                                                  java.io.InputStream xml,
                                                  @NonNull
                                                  java.util.Collection<SchemaModule> possibleModules,
                                                  @Nullable
                                                  org.w3c.dom.ls.LSResourceResolver resourceResolver,
                                                  boolean strict,
                                                  @NonNull
                                                  ProgressIndicator progress)
                                  throws javax.xml.bind.JAXBException
Use JAXB to create POJOs from the given XML.

Parameters:
xml - The XML to read. The stream will be closed after being read.
possibleModules - The SchemaModules that are available to parse the XML.
resourceResolver - Resolver for any imported XSDs.
progress - For logging.
Returns:
The unmarshalled object.
Throws:
javax.xml.bind.JAXBException - if there is an error during unmarshalling. TODO: maybe templatize and return a nicer type.

marshal

public static void marshal(@NonNull
                           javax.xml.bind.JAXBElement element,
                           @NonNull
                           java.util.Collection<SchemaModule> possibleModules,
                           @NonNull
                           java.io.OutputStream out,
                           @Nullable
                           org.w3c.dom.ls.LSResourceResolver resourceResolver,
                           @NonNull
                           ProgressIndicator progress)
Transform the given JAXBElement into xml, using JAXB and the schemas provided by the given SchemaModules.