use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.
the class WriteBufferXmlBased method pushContext.
@Override
public void pushContext(String logicalName, WithWriterArgs... writerArgs) {
try {
indent();
depth++;
StartElement startElement = xmlEventFactory.createStartElement("", "", logicalName);
xmlEventWriter.add(startElement);
if (isToBeRenderedAsList(writerArgs)) {
Attribute isListAttribute = xmlEventFactory.createAttribute(rwIsListKey, "true");
xmlEventWriter.add(isListAttribute);
}
newLine();
} catch (XMLStreamException e) {
throw new PlcRuntimeException(e);
}
stack.push(logicalName);
}
use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.
the class PlcList method serialize.
@Override
public void serialize(WriteBuffer writeBuffer) throws SerializationException {
writeBuffer.pushContext("PlcList");
for (PlcValue listItem : listItems) {
if (!(listItem instanceof Serializable)) {
throw new PlcRuntimeException("Error serializing. List item doesn't implement XmlSerializable");
}
((Serializable) listItem).serialize(writeBuffer);
}
writeBuffer.popContext("PlcList");
}
use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.
the class ReadBufferJsonBased method readInt.
@Override
public int readInt(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
logicalName = sanitizeLogicalName(logicalName);
move(bitLength);
Map element = getElement(logicalName);
validateAttr(logicalName, element, rwIntKey, bitLength);
Integer value = (Integer) element.get(logicalName);
if (value == null) {
throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
}
return value;
}
use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.
the class ReadBufferJsonBased method getElement.
private Map getElement(String logicalName) {
logicalName = sanitizeLogicalName(logicalName);
Object peek = stack.peek();
Map element;
if (peek instanceof List) {
List elementList = (List) stack.pop();
element = (Map) elementList.get(0);
if (elementList.size() < 2) {
stack.push(Collections.emptyList());
} else {
elementList.remove(0);
stack.push(elementList);
}
return element;
} else if (peek instanceof Map) {
return (Map) peek;
} else {
throw new PlcRuntimeException(String.format("Invalid state at %s with %s", logicalName, peek));
}
}
use of org.apache.plc4x.java.api.exceptions.PlcRuntimeException in project plc4x by apache.
the class ReadBufferJsonBased method readShort.
@Override
public short readShort(String logicalName, int bitLength, WithReaderArgs... readerArgs) throws ParseException {
logicalName = sanitizeLogicalName(logicalName);
move(bitLength);
Map element = getElement(logicalName);
validateAttr(logicalName, element, rwIntKey, bitLength);
Integer value = (Integer) element.get(logicalName);
if (value == null) {
throw new PlcRuntimeException(String.format(REQUIRED_ELEMENT_NOT_FOUND, logicalName, stack.peek()));
}
return value.shortValue();
}
Aggregations