Examples of EnvObjectLogic


Examples of it.freedomotic.objects.EnvObjectLogic

                    0,
                    0);
            drawer.createCallout(callout1);
        } else if (c.getProperty("command").equals("GRAPH-DATA")) { // show GUI
            // get related object from address
            EnvObjectLogic obj = (EnvObjectLogic) getApi().getObjectByAddress("harvester", c.getProperty("event.object.address")).toArray()[0];
            // open GraphWindow related to the object
            if (obj.getBehavior("data") != null) { // has a 'data' behavior
                if (!obj.getBehavior("data").getValueAsString().isEmpty()) {
                    GraphPanel gw = graphs.get(obj.getPojo().getUUID());
                    if (gw != null) {
                        gw.reDraw();
                    } else {
                        gw = new GraphPanel(this, obj);
                        graphs.put(obj.getPojo().getUUID(), gw);
                    }
                }

                //sendBack(c);
            }
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

    public void startOnEnv(EnvironmentLogic env) {
        if (env==null){
            throw new IllegalArgumentException("Cannot place an object on a null environment");
        }
        EnvObjectLogic obj = EnvObjectPersistence.add(object, EnvObjectPersistence.MAKE_UNIQUE);
        obj.setEnvironment(env);
    }
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

            affectedObjects = EnvObjectPersistence.getObjectByAddress(protocol, address);

            if (affectedObjects.isEmpty()) { //there isn't an object with this protocol and address

                if ((clazz != null) && !clazz.isEmpty()) {
                    EnvObjectLogic joined = environmentPersistence.join(clazz, name, protocol, address);
                    affectedObjects.add(joined);
                }
            }
        }
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

                                    Command resolvedCommand = commandResolver.resolve(command);
                                    //doing so we bypass messaging system gaining better performances
                                    BehaviorManager.parseCommand(resolvedCommand);
                                } else {
                                    //if the event has a target object we include also object info
                                    EnvObjectLogic targetObject =
                                            EnvObjectPersistence.getObjectByName(event.getProperty("object.name"));

                                    if (targetObject != null) {
                                        commandResolver.addContext("current.",
                                                targetObject.getExposedProperties());
                                        commandResolver.addContext("current.",
                                                targetObject.getExposedBehaviors());
                                    }

                                    final Command resolvedCommand = commandResolver.resolve(command);

                                    //it's not a user level command for objects (eg: turn it on), it is for another kind of actuator
                                    Command reply = busService.send(resolvedCommand); //blocking wait until executed

                                    if (reply == null) {
                                        LOG.log(Level.WARNING,
                                                "Unreceived reply within given time ({0}ms) for command {1}",
                                                new Object[]{command.getReplyTimeout(), command.getName()});
                                    } else {
                                        if (reply.isExecuted()) {
                                            LOG.log(Level.FINE, "Executed succesfully {0}", command.getName());
                                        } else {
                                            LOG.log(Level.WARNING, "Unable to execute command{0}", command.getName());
                                        }
                                    }
                                }
                            }
                        } catch (Exception e) {
                            LOG.severe("Exception while merging event parameters into reaction.\n");
                            LOG.severe(Freedomotic.getStackTraceInfo(e));

                            return;
                        }

                        String info =
                                "Executing automation '" + reaction.toString() + "' takes "
                                + (System.currentTimeMillis() - event.getCreation()) + "ms.";
                        LOG.info(info);

                        MessageEvent message = new MessageEvent(null, info);
                        message.setType("callout"); //display as callout on frontends
                        busService.send(message);
                    }
                }

                if (!found) {
                    LOG.log(Level.CONFIG, "No valid reaction bound to trigger ''{0}''", trigger.getName());
                }
            }

            /**
             * Resolves the additional conditions of the reaction in input. Now
             * it just takes the statement attribute and value and check if they
             * are equal to the target behavior name and value respectively.
             * This should be improved to allow also REGEX and other statement
             * resolution.
             */
            private boolean checkAdditionalConditions(Reaction rea) {
                boolean result = true;
                for (Condition condition : rea.getConditions()) {
                    //System.out.println("DEBUG: check condition " + condition.getTarget());
                    EnvObjectLogic object = EnvObjectPersistence.getObjectByName(condition.getTarget());
                    Statement statement = condition.getStatement();
                    if (object != null) {
                        BehaviorLogic behavior = object.getBehavior(statement.getAttribute());
                        //System.out.println("DEBUG: " + object.getPojo().getName() + " "
                        //+ " behavior: " + behavior.getName() + " " + behavior.getValueAsString());
                        boolean eval = behavior.getValueAsString().equalsIgnoreCase(statement.getValue());
                        if (statement.getLogical().equalsIgnoreCase("AND")) {
                            result = result && eval;
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

    private static void applyToSingleObject(Command userLevelCommand) {

        // gets a reference to an EnvObject using the key 'object' in the user
        // level command
        EnvObjectLogic obj = EnvObjectPersistence
                .getObjectByName(userLevelCommand.getProperty(Command.PROPERTY_OBJECT));

        // if the object exists
        if (obj != null) {

            // gets the behavior name in the user level command
            String behaviorName = userLevelCommand.getProperty(Command.PROPERTY_BEHAVIOR);
            BehaviorLogic behavior = obj.getBehavior(behaviorName);

            // if this behavior exists in object obj
            if (behavior != null) {

                LOG.log(Level.CONFIG,
                        "User level command ''{0}'' request changing behavior {1} of object ''{2}'' "
                        + "from value ''{3}'' to value ''{4}''",
                        new Object[]{userLevelCommand.getName(), behavior.getName(), obj.getPojo().getName(), behavior.getValueAsString(), userLevelCommand.getProperties().getProperty("value")});

                // true means a command must be fired
                behavior.filterParams(userLevelCommand.getProperties(), true);

            } else {
                LOG.log(Level.WARNING,
                        "Behavior ''{0}'' is not a valid behavior for object ''{1}''. "
                        + "Please check ''behavior'' parameter spelling in command {2}",
                        new Object[]{behaviorName, obj.getPojo().getName(), userLevelCommand.getName()});
            }
        } else {
            LOG.log(Level.WARNING,"Object ''{0}"
                    + "'' don''t exist in this environment. "
                    + "Please check ''object'' parameter spelling in command {1}",
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

                    try {
                        // retrieve a list of configured objects with "zway" protocol
                        ArrayList<EnvObjectLogic> objectsList = EnvObjectPersistence.getObjectByProtocol("zway");
                        if (objectsList.size() > 0) {
                            for (Iterator it = objectsList.iterator(); it.hasNext();) {
                                EnvObjectLogic object = (EnvObjectLogic) it.next();
                                // read status for each object
                                readStatus(board, object);
                                System.out.println("Object address:" + object.getPojo().getPhisicalAddress() + " type:" + object.getPojo().getType());
                            }
                        }
                    } catch (MalformedURLException ex) {
                        Logger.getLogger(ZWay.class.getName()).log(Level.SEVERE, null, ex);
                    } catch (IOException ex) {
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

        if (zone.getPojo().getObjects().isEmpty()) {
            panel.add(new JLabel("No objects in this zone"));
        }

        for (final EnvObject objPojo : zone.getPojo().getObjects()) {
            final EnvObjectLogic obj = EnvObjectPersistence.getObjectByUUID(objPojo.getUUID());

            //a coloumn with object name
            JLabel icon = new JLabel(renderSingleObject(obj.getPojo()));
            icon.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    mouseClickObject(obj);
                }
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (!roomEditMode) {
            EnvObjectLogic obj = mouseOnObject(e.getPoint());

            if (obj != null) {
                //single click on an object
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (e.getClickCount() == 1) {
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

    }

    @Override
    public void mouseMoved(MouseEvent e) {
        if (!roomEditMode) {
            EnvObjectLogic obj = mouseOnObject(e.getPoint());

            if ((obj == null) && (selectedObject != null)) {
                removeIndicators();
                mouseExitsObject(selectedObject);
                callouts.clear("object.description");
View Full Code Here

Examples of it.freedomotic.objects.EnvObjectLogic

            Room room = (Room) zone;
            room.init(this);
            Iterator<EnvObjectLogic> it = EnvObjectPersistence.iterator();
            //check if this rooms has gates
            while (it.hasNext()) {
                EnvObjectLogic obj = it.next();
                if (obj instanceof Gate) {
                    Gate gate = (Gate) obj;
                    gate.evaluateGate();
                }
            }
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.