Package it.freedomotic.exceptions

Examples of it.freedomotic.exceptions.DaoLayerException


       // } catch (InstantiationException ex) {
       //     throw new DaoLayerException(ex);
       // } catch (IllegalAccessException ex) {
       //     throw new DaoLayerException(ex);
        } catch (ClassNotFoundException ex) {
            throw new DaoLayerException("Class '" + pojo.getHierarchy() + "' not found. "
                    + "The related object plugin is not "
                    + "loaded succesfully or you have a wrong hierarchy "
                    + "value in your XML definition of the object."
                    + "The hierarchy value is composed by the package name plus the java file name "
                    + "like it.freedomotic.objects.impl.Light not it.freedomotic.objects.impl.ElectricDevice.Light");
View Full Code Here


    }

    @RequiresPermissions("objects:save")
    public static void saveObjects(File folder) throws DaoLayerException {
        if (objectList.isEmpty()) {
            throw new DaoLayerException("There are no object to persist, " + folder.getAbsolutePath()
                    + " will not be altered.");
        }

        if (!folder.isDirectory()) {
            throw new DaoLayerException(folder.getAbsoluteFile() + " is not a valid object folder. Skipped");
        }

        try {
            XStream xstream = FreedomXStream.getXstream();
            deleteObjectFiles(folder);

            // Create file
            StringBuilder summary = new StringBuilder();
            //print an header for the index.txt file
            summary.append("#Filename \t\t #EnvObjectName \t\t\t #EnvObjectType \t\t\t #Protocol \t\t\t #Address")
                    .append("\n");

            for (EnvObjectLogic envObject : objectList.values()) {
                String uuid = envObject.getPojo().getUUID();

                if ((uuid == null) || uuid.isEmpty()) {
                    envObject.getPojo().setUUID(UUID.randomUUID().toString());
                }

                if ((envObject.getPojo().getEnvironmentID() == null)
                        || envObject.getPojo().getEnvironmentID().isEmpty()) {
                    envObject.getPojo()
                            .setEnvironmentID(EnvironmentPersistence.getEnvironments().get(0).getPojo().getUUID());
                }

                String fileName = envObject.getPojo().getUUID() + ".xobj";
                FileWriter fstream = new FileWriter(folder + "/" + fileName);
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(xstream.toXML(envObject.getPojo())); //persist only the data not the logic
                summary.append(fileName).append("\t").append(envObject.getPojo().getName()).append("\t")
                        .append(envObject.getPojo().getType()).append("\t")
                        .append(envObject.getPojo().getProtocol()).append("\t")
                        .append(envObject.getPojo().getPhisicalAddress()).append("\n");
                //Close the output stream
                out.close();
                fstream.close();
            }

            //writing a summary .txt file with the list of commands in this folder
            FileWriter fstream = new FileWriter(folder + "/index.txt");
            BufferedWriter indexfile = new BufferedWriter(fstream);
            indexfile.write(summary.toString());
            //Close the output stream
            indexfile.close();
        } catch (IOException ex) {
            throw new DaoLayerException(ex);
        }
    }
View Full Code Here

        for (File file : files) {
            boolean deleted = file.delete();

            if (!deleted) {
                throw new DaoLayerException("Unable to delete file " + file.getAbsoluteFile());
            }
        }
    }
View Full Code Here

                return objectLogic;
            } catch (DaoLayerException daoLayerException) {
                LOG.warning(daoLayerException.getMessage());
            }
        } catch (IOException ex) {
            throw new DaoLayerException(ex.getMessage(), ex);
        } catch (XStreamException e) {
            throw new DaoLayerException(e.getMessage(), e);
        }
        //EnvObjectLogic objectLogic = EnvObjectFactory.save(pojo);
        //LOG.info("Created a new logic for " + objectLogic.getPojo().getName() + " of type " + objectLogic.getClass().getCanonicalName().toString());
        //add(objectLogic);
        return null;
View Full Code Here

     * @throws DaoLayerException
     */
    @Override
    public void save(Environment environment) throws DaoLayerException {
        if (!directory.isDirectory()) {
            throw new DaoLayerException(directory.getAbsoluteFile() + " is not a valid environment folder. Skipped");
        }

        if (this.isSavedAsNewEnvironment()) {
            try {
                saveAs(environment);
            } catch (IOException ex) {
                throw new DaoLayerException(ex);
            }
        } else {
            delete(environment);

            try {
                // Create file
                StringBuilder summary = new StringBuilder();
                //print an header for the index.txt file
                summary.append("#Filename \t\t #EnvName").append("\n");

                String uuid = environment.getUUID();

                if ((uuid == null) || uuid.isEmpty()) {
                    environment.setUUID(UUID.randomUUID().toString());
                }

                String fileName = environment.getUUID() + ".xenv";
                serialize(environment,
                        new File(directory + "/" + fileName));
                summary.append(fileName).append("\t").append(environment.getName()).append("\n");

                //writing a summary .txt file with the list of commands in this folder
                FileWriter fstream = new FileWriter(directory + "/index.txt");
                BufferedWriter indexfile = new BufferedWriter(fstream);
                indexfile.write(summary.toString());
                //Close the output stream
                indexfile.close();
            } catch (IOException ex) {
                throw new DaoLayerException(ex);
            }
        }
    }
View Full Code Here

     */
    @Override
    public Collection<Environment> load()
            throws DaoLayerException {
        if (directory == null) {
            throw new DaoLayerException("Cannot load environments from null directory");
        }

        // This filter only returns env files
        FileFilter envFileFilter =
                new FileFilter() {
View Full Code Here

        String xml;

        try {
            xml = DOMValidateDTD.validate(file, Info.getApplicationPath() + "/config/validator/environment.dtd");
        } catch (IOException ex) {
            throw new DaoLayerException(ex.getMessage(), ex);
        }

        Environment pojo = null;

        try {
            pojo = (Environment) xstream.fromXML(xml);

            return pojo;
        } catch (XStreamException e) {
            throw new DaoLayerException("XML parsing error. Readed XML is \n" + xml, e);
        }

//        EnvironmentLogic envLogic = new EnvironmentLogic();
//        if (pojo == null) {
//            throw new IllegalStateException("Object data cannot be null at this stage");
View Full Code Here

            LOG.warning("There is no environment to persist, " + folder.getAbsolutePath() + " will not be altered.");
            return;
        }
       
        if (folder.exists() && !folder.isDirectory()) {
            throw new DaoLayerException(folder.getAbsoluteFile() + " is not a valid environment folder. Skipped");
        }
        createFolderStructure(folder);
        deleteEnvFiles(folder);

        try {
            // Create file
            StringBuilder summary = new StringBuilder();
            //print an header for the index.txt file
            summary.append("#Filename \t\t #EnvName").append("\n");

            for (EnvironmentLogic environment : environments) {
                String uuid = environment.getPojo().getUUID();

                if ((uuid == null) || uuid.isEmpty()) {
                    environment.getPojo().setUUID(UUID.randomUUID().toString());
                }

                String fileName = environment.getPojo().getUUID() + ".xenv";
                save(environment,
                        new File(folder + "/" + fileName));
                summary.append(fileName).append("\t").append(environment.getPojo().getName()).append("\n");
            }

            //writing a summary .txt file with the list of commands in this folder
            FileWriter fstream = new FileWriter(folder + "/index.txt");
            BufferedWriter indexfile = new BufferedWriter(fstream);
            indexfile.write(summary.toString());
            //Close the output stream
            indexfile.close();
        } catch (IOException e) {
            throw new DaoLayerException(e.getCause());
        }
    }
View Full Code Here

        for (File file : files) {
            boolean deleted = file.delete();

            if (!deleted) {
                throw new DaoLayerException("Unable to delete file " + file.getAbsoluteFile());
            }
        }
    }
View Full Code Here

     */
    @Deprecated
    public synchronized static boolean loadEnvironmentsFromDir(File folder, boolean makeUnique)
            throws DaoLayerException {
        if (folder == null) {
            throw new DaoLayerException("Cannot");
        }

        environments.clear();

        boolean check = true;
View Full Code Here

TOP

Related Classes of it.freedomotic.exceptions.DaoLayerException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.