Search in sources :

Example 6 with Model

use of com.manydesigns.portofino.model.Model in project Portofino by ManyDesigns.

the class Persistence method loadXmlModel.

// **************************************************************************
// Model loading
// **************************************************************************
public synchronized void loadXmlModel() {
    try {
        JAXBContext jc = createModelJAXBContext();
        Unmarshaller um = jc.createUnmarshaller();
        FileObject appModelFile = getModelFile();
        if (appModelFile.exists()) {
            logger.info("Loading legacy xml model from file: {}", appModelFile.getName().getPath());
            try (InputStream inputStream = appModelFile.getContent().getInputStream()) {
                model = (Model) um.unmarshal(inputStream);
            } catch (Exception e) {
                String msg = "Cannot load/parse model: " + appModelFile;
                logger.error(msg, e);
            }
        } else {
            logger.info("Loading model from directory: {}", getModelDirectory().getName().getPath());
            model = new Model();
        }
        FileObject modelDir = getModelDirectory();
        if (modelDir.exists()) {
            for (FileObject databaseDir : modelDir.getChildren()) {
                loadXmlDatabase(um, model, databaseDir);
            }
        }
        initModel();
    } catch (Exception e) {
        logger.error("Cannot load/parse model", e);
    }
}
Also used : InputStream(java.io.InputStream) Model(com.manydesigns.portofino.model.Model) JAXBContext(javax.xml.bind.JAXBContext) FileObject(org.apache.commons.vfs2.FileObject) Unmarshaller(javax.xml.bind.Unmarshaller) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Aggregations

Model (com.manydesigns.portofino.model.Model)6 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)3 ClassAccessor (com.manydesigns.elements.reflection.ClassAccessor)1 PropertyAccessor (com.manydesigns.elements.reflection.PropertyAccessor)1 QueryStringWithParameters (com.manydesigns.elements.text.QueryStringWithParameters)1 TableCriteria (com.manydesigns.portofino.persistence.TableCriteria)1 TableAccessor (com.manydesigns.portofino.reflection.TableAccessor)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Predicate (javax.persistence.criteria.Predicate)1 JAXBContext (javax.xml.bind.JAXBContext)1 JAXBException (javax.xml.bind.JAXBException)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 FileObject (org.apache.commons.vfs2.FileObject)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1 Session (org.hibernate.Session)1