public <T> T unmarshal(Class<T> clz, File file, boolean logXsd) throws JAXBException, IOException, XMLStreamException, SAXException {
    Unmarshaller u = jaxbContexts.get(clz).createUnmarshaller();

    XMLInputFactory xmlFactory = XMLInputFactory.newInstance();

    FileReader reader = new FileReader(file);
    XMLStreamReader xmlReader = xmlFactory.createXMLStreamReader(reader);

    xmlReader.nextTag();
    String xsdName = xmlReader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "noNamespaceSchemaLocation");

    InputStream xsdStream = null;

    if (null != xsdName) {
      if (logXsd) {
        LOG.info("Processing " + file.getAbsolutePath() + " with " + xsdName);
      }
      if (jaxbSchemas.containsKey(xsdName)) {
        u.setSchema(jaxbSchemas.get(xsdName));
      } else {

        xsdStream = clz.getClassLoader().getResourceAsStream(xsdName);

        if (null != xsdStream) {
          SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
          Schema schema = factory.newSchema(new StreamSource(xsdStream));

          u.setSchema(schema);

          jaxbSchemas.put(xsdName, schema);
        } else if (logXsd) {
          LOG.info("Schema '" + xsdName + "' for " + file.getAbsolutePath() + " was not found, ignoring");
        }
      }
    } else if (logXsd) {
      LOG.info("NOT processing " + file.getAbsolutePath() + "; there is no XSD");
    }

    try {
      return clz.cast(u.unmarshal(file));
    } catch (Exception unmarshalException) {

      Throwable cause = ExceptionUtils.getRootCause(unmarshalException);

      LOG.error("Cannot parse {}", file.getAbsolutePath());
      if (null != cause) {
        LOG.error(cause.getMessage(), cause);
      }

      throw unmarshalException;
    } finally {
      IOUtils.closeQuietly(xsdStream);
    }
  }
Unmarshal a file to it's corresponding object type.

@param clz     class of the object representation
@param file    file to unmarshal
@param logXsd  log XSD information

@return object representation of the specified file
@throws JAXBException if unable to unmarshal the file
@throws XMLStreamException
@throws SAXException
@throws FileNotFoundException
ambari-server/src/main/java/org/apache/ambari/server/stack/ModuleFileUnmarshaller.java