Package de.mnl.srcpd4cu.util

Examples of de.mnl.srcpd4cu.util.CommandExecutionException


                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            DeviceGroup deviceGroup
                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(GettableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
                long address = CommandUtil.consumeNumber(args);
                device = deviceGroup.getDevice(address);
                if (device == null) {
                    if (!deviceGroup.allowImplicitCreation()) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    device = deviceGroup.createDevice(address);
                    if (!(device instanceof InitializableDevice)
                        || !(device instanceof GettableDevice)) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    ((InitializableDevice)device).init
                        (session, deviceGroup,
                         ((InitializableDevice)device).getDescription());
                    device.addStateChangeListener(session.getServer());
                }
            }
            if (!(device instanceof GettableDevice)) {
                throw new CommandExecutionException
                    (ERROR_UNSUPPORTED_OPERATION);
            }
            String info;
            if (args.size() > 0) {
                if (device instanceof AddressableStateProvider) {
                    synchronized (device) {
                        info = ((AddressableStateProvider)device)
                            .getState(session, args);
                    }
                } else {
                    throw new CommandExecutionException(ERROR_LIST_TOO_LONG);
                }
            } else {
                synchronized (device) {
                    String[] states
                        = ((GettableDevice)device).getState(session);
                    if (states.length != 1) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_OPERATION);
                    }
                    info = states[0];
                }
            }
View Full Code Here


    @Override
    public void set(SessionDevice session, String args)
        throws CommandExecutionException {
        String[] splitArgs = args.split(" ", 2);
        if (splitArgs.length < 1) {
            throw new CommandExecutionException(Command.ERROR_LIST_TOO_SHORT);
        }
        if (splitArgs[0].equals("ON")) {
            doSetState(State.ON);
        } else if (splitArgs[0].equals("OFF")) {
            doSetState(State.OFF);
        } else {
            throw new CommandExecutionException(Command.ERROR_WRONG_VALUE);
        }
        if (splitArgs.length > 1) {
            optionalAddition = splitArgs[1];
        } else {
            optionalAddition = null;
View Full Code Here

    public void init
        (SessionDevice session, DeviceGroup deviceGroup, String args)
            throws CommandExecutionException {
        String[] stdArgs = args.split(" ");
        if (stdArgs.length < 1) {
            throw new CommandExecutionException(Command.ERROR_LIST_TOO_SHORT);
        }
        protocol = stdArgs[0];
        if (!protocol.matches("^[MNSP]$")) {
            throw new CommandExecutionException(Command.ERROR_WRONG_VALUE);
        }
        init(deviceGroup, protocol);
    }
View Full Code Here

     */
    @Override
    public String getState(SessionDevice session, List<String> args)
            throws CommandExecutionException {
        if (args.size() < 1) {
            throw new CommandExecutionException(Command.ERROR_LIST_TOO_SHORT);
        }
        int port = (int)CommandUtil.consumeNumber(args);
        return Integer.toString(port) + " " + doGet(port);
    }
View Full Code Here

    public void set(SessionDevice session, String args)
            throws CommandExecutionException {
        List<String> argsList
            = new ArrayList<String>(Arrays.asList(args.split(" ")));
        if (argsList.size() < 3) {
            throw new CommandExecutionException(Command.ERROR_LIST_TOO_SHORT);
        }
        int port = (int)CommandUtil.consumeNumber(argsList);
        int value = (int)CommandUtil.consumeNumber(argsList);
        int delay = (int)CommandUtil.consumeNumber(argsList);
        knownPorts.add(port);
View Full Code Here

    public String getState(SessionDevice session, List<String> args)
            throws CommandExecutionException {
        Device device = CommandUtil
            .findDevice(session, getDeviceGroup().getBus(), args, false);
        if (!(device instanceof InitializableDevice)) {
            throw new CommandExecutionException
                (Command.ERROR_UNSUPPORTED_OPERATION);
        }
        StringBuffer sb = new StringBuffer();
        sb.append(device.getDeviceGroup().getName());
        if (device instanceof AddressableDevice) {
View Full Code Here

            List<String> args
                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            Device device = CommandUtil.findDevice(session, args, true);
            if (!device.getDeviceGroup().getSupportedDeviceTypes()
                    .contains(TerminatableDevice.class)) {
                    throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            if (!(device instanceof TerminatableDevice)) {
                return ERROR_NOT_SUPPORTED;
            }
            synchronized (device) {
View Full Code Here

            List<String> args
                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            Device device = CommandUtil.findDevice(session, args);
            if (!device.getDeviceGroup().getSupportedDeviceTypes()
                .contains(ResettableDevice.class)) {
                    throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            if (!(device instanceof ResettableDevice)) {
                return ERROR_NOT_SUPPORTED;
            }
            synchronized (device) {
View Full Code Here

                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            DeviceGroup deviceGroup
                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(SettableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
                long address = CommandUtil.consumeNumber(args);
                device = deviceGroup.getDevice(address);
                if (device == null) {
                    if (!deviceGroup.allowImplicitCreation()) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    device = deviceGroup.createDevice(address);
                    if (!(device instanceof InitializableDevice)
                        || !(device instanceof SettableDevice)) {
                        throw new CommandExecutionException
                            (Command.ERROR_UNSUPPORTED_DEVICE);
                    }
                    ((InitializableDevice)device).init
                        (session, deviceGroup,
                         ((InitializableDevice)device).getDescription());
View Full Code Here

                = new ArrayList<String>(Arrays.asList(arguments.split(" ")));
            DeviceGroup deviceGroup
                = CommandUtil.findDeviceGroup(session, args);
            if (!deviceGroup.getSupportedDeviceTypes()
                .contains(InitializableDevice.class)) {
                throw new CommandExecutionException(ERROR_FORBIDDEN);
            }
            Device device;
            if (deviceGroup instanceof SingleDeviceGroup) {
                device = ((SingleDeviceGroup)deviceGroup).getDevice();
            } else {
View Full Code Here

TOP

Related Classes of de.mnl.srcpd4cu.util.CommandExecutionException

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.