/** * Create the channel instance and sets its name. * * <p>If the channel class matches to constructor parameters of the default channel (ChannelImpl) * that constructor is used, else the empty constructor is invoked. * * @param channelClass Channel implementation class to instanciate. * @param name Name of the channel. * @return a new Channel instance. * @throws IllegalStateException if a channel with name already created or channelClass could not * be instancieated. */ protected Channel getNewChannel(Class<? extends Channel> channelClass, String name) throws IllegalStateException { try { channelRegister.getChannel(name); throw new IllegalStateException("Channel with name " + name + " has already been created."); } catch (NoSuchChannelException nsce) { try { if (ChannelImpl.class.isAssignableFrom(channelClass)) { Constructor<? extends Channel> cons = channelClass.getConstructor( String.class, ChannelRegister.class, EventRegister.class, EventMethodInvoker.class, BeanResolver.class); return cons.newInstance( name, channelRegister, eventRegister, eventMethodInvoker, beanResolver); } else { Channel channel = channelClass.newInstance(); channel.setName(name); return channel; } } catch (Exception e) { throw new IllegalStateException( "Could not find or instanciate channel class " + channelClass, e); } } }
/** * Create a channel initialized with the specified configuration. * * @param config the channel configuration * @param start initial state */ public Channel createChannel(ChannelConfig config, boolean start) { Channel channel = new Channel(config); channel.setName("channel: " + config.getName()); if (start) { channel.start(); } channels.add(channel); channelMap.put(config.getName().toLowerCase(), channel); return channel; }
/** * turns database cursor into object * * @param cursor cursor to database entry which should be returned into an object * @return object containing the database data */ public static Channel cursorToChannel(Cursor cursor) { Channel channel = new Channel(); channel.set_id(cursor.getLong(0)); channel.setName(cursor.getString(1)); channel.setAddress(cursor.getString(2)); channel.setParent_device(cursor.getLong(3)); channel.setDevice_index(cursor.getLong(4)); channel.setFunction_id(cursor.getLong(5)); channel.setRoom_id(cursor.getLong(6)); return channel; }
public void renameChannel(Channel channel, String newName) throws Exception { synchronized (channelStatus) { luceneUpdater.renameChannel(channel.getName(), newName); new File(configFilesDir, channel.getName() + ".config").delete(); ChannelStatus cStatus = channelStatus.remove(channel.getName()); if (cStatus != null) { channel.setName(newName); cStatus.channel(channel); channelStatus.put(newName, cStatus); saveChannel(channel); } } }
private List<Channel> loadChannels() throws Exception { File files[] = configFilesDir.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".config"); } }); ArrayList<Channel> result = new ArrayList<>(); for (File file : files) { FileInputStream in = new FileInputStream(file); try { Channel channel = loadChannel(in); String name = file.getName(); name = name.substring(0, name.length() - ".config".length()); channel.setName(name); result.add(channel); } finally { IOUtils.closeQuietly(in); } } return result; }
private List<Channel> getChannels(SQLiteDatabase database) { Cursor cursor = database.query( "Channel", new String[] {"id", "name", "orderIndex"}, null, null, null, null, "orderIndex"); cursor.moveToFirst(); List<Channel> list = new ArrayList<Channel>(); while (!cursor.isAfterLast()) { Channel ch = new Channel(); ch.setId(cursor.getLong(cursor.getColumnIndex("id"))); ch.setName(cursor.getString(cursor.getColumnIndex("name"))); ch.setOrder(cursor.getInt(cursor.getColumnIndex("orderIndex"))); list.add(ch); cursor.moveToNext(); } cursor.close(); return list; }