use of jmri.Block in project JMRI by JMRI.
the class OPathTest method testSetBlockToNull.
@Test
public void testSetBlockToNull() {
Block b1 = new Block("IB1");
OPath op = new OPath(b1, "name");
op.setBlock(null);
Assert.assertEquals("block", null, op.getBlock());
}
use of jmri.Block in project JMRI by JMRI.
the class OPathTest method testSetBlockNonNull.
@Test
public void testSetBlockNonNull() {
Block b1 = new Block("IB1");
Block b2 = new Block("IB2");
OPath op = new OPath(b1, "name");
op.setBlock(b2);
Assert.assertEquals("block", b2, op.getBlock());
}
use of jmri.Block in project JMRI by JMRI.
the class OPathTest method testCtor.
@Test
public void testCtor() {
Block b = new Block("IB1");
OPath op = new OPath(b, "name");
Assert.assertEquals("name", "name", op.getName());
Assert.assertEquals("block", b, op.getBlock());
}
use of jmri.Block in project JMRI by JMRI.
the class JsonBlockHttpService method doGet.
@Override
public JsonNode doGet(String type, String name, Locale locale) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, BLOCK);
ObjectNode data = root.putObject(DATA);
Block block = InstanceManager.getDefault(BlockManager.class).getBlock(name);
if (block == null) {
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", BLOCK, name));
}
data.put(NAME, block.getSystemName());
data.put(USERNAME, block.getUserName());
data.put(COMMENT, block.getComment());
if (block.getValue() == null) {
data.putNull(VALUE);
} else {
data.put(VALUE, block.getValue().toString());
}
return root;
}
use of jmri.Block in project JMRI by JMRI.
the class JsonBlockSocketService method onMessage.
@Override
public void onMessage(String type, JsonNode data, Locale locale) throws IOException, JmriException, JsonException {
this.locale = locale;
String name = data.path(NAME).asText();
if (data.path(METHOD).asText().equals(PUT)) {
this.connection.sendMessage(this.service.doPut(type, name, data, locale));
} else {
this.connection.sendMessage(this.service.doPost(type, name, data, locale));
}
if (!this.blocks.containsKey(name)) {
Block block = InstanceManager.getDefault(BlockManager.class).getBlock(name);
if (block != null) {
BlockListener listener = new BlockListener(block);
block.addPropertyChangeListener(listener);
this.blocks.put(name, listener);
}
}
}
Aggregations