Examples of EnvObjectLogic


Examples of it.freedomotic.objects.EnvObjectLogic

        //  }
        return envLogic;
    }

    public EnvObjectLogic join(String clazz, String name, String protocol, String address) {
        EnvObjectLogic loaded = null;
        ObjectPluginPlaceholder objectPlugin = (ObjectPluginPlaceholder) clientStorage.get(clazz);

        if (objectPlugin == null) {
            LOG.warning("Doesn't exist an object class called " + clazz);

            return null;
        }

        File templateFile = objectPlugin.getTemplate();

        try {
            loaded = EnvObjectPersistence.loadObject(templateFile);
        } catch (DaoLayerException ex) {
            LOG.severe("Cannot join an object taken from template file " + templateFile);
        }

        //changing the name and other properties invalidates related trigger and commands
        //call init() again after this changes
        if ((name != null) && !name.isEmpty()) {
            loaded.getPojo().setName(name);
        } else {
            loaded.getPojo().setName(protocol);
        }

        loaded = EnvObjectPersistence.add(loaded, EnvObjectPersistence.MAKE_UNIQUE);
        loaded.getPojo().setProtocol(protocol);
        loaded.getPojo().setPhisicalAddress(address);
        loaded.setRandomLocation();

        //set the PREFERRED MAPPING of the protocol plugin (if any is defined in its manifest)
        Client addon = clientStorage.getClientByProtocol(protocol);

        if (addon != null) {
            for (int i = 0; i < addon.getConfiguration().getTuples().size(); i++) {
                Map tuple = addon.getConfiguration().getTuples().getTuple(i);
                String regex = (String) tuple.get("object.class");

                if ((regex != null) && clazz.matches(regex)) {
                    //map object behaviors to hardware triggers
                    for (Behavior behavior : loaded.getPojo().getBehaviors()) {
                        String triggerName = (String) tuple.get(behavior.getName());
                        if (triggerName != null) {
                            loaded.addTriggerMapping(TriggerPersistence.getTrigger(triggerName),
                                    behavior.getName());
                        }
                    }

                    for (String action : loaded.getPojo().getActions().stringPropertyNames()) {
                        String commandName = (String) tuple.get(action);

                        if (commandName != null) {
                            loaded.setAction(action,
                                    CommandPersistence.getHardwareCommand(commandName));
                        }
                    }
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.