use of ca.uhn.hl7v2.model.Type in project camel by apache.
the class HL7MLLPEncoder method encode.
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
if (message == null) {
throw new IllegalArgumentException("Message to be encoded is null");
} else if (message instanceof Exception) {
// we cannot handle exceptions
throw (Exception) message;
}
byte[] body;
if (message instanceof Message) {
body = ((Message) message).encode().getBytes(config.getCharset());
} else if (message instanceof String) {
body = ((String) message).getBytes(config.getCharset());
} else if (message instanceof byte[]) {
body = (byte[]) message;
} else {
throw new IllegalArgumentException("The message to encode is not a supported type: " + message.getClass().getCanonicalName());
}
// put the data into the byte buffer
IoBuffer buf = IoBuffer.allocate(body.length + 3).setAutoExpand(true);
buf.put((byte) config.getStartByte());
buf.put(body);
buf.put((byte) config.getEndByte1());
buf.put((byte) config.getEndByte2());
// flip the buffer so we can use it to write to the out stream
buf.flip();
LOG.debug("Encoded HL7 from {} to byte stream", message.getClass().getCanonicalName());
out.write(buf);
}
use of ca.uhn.hl7v2.model.Type in project tdi-studio-se by Talend.
the class TypeModel method generatePrimitive.
private void generatePrimitive() {
if (type != null) {
List<PrimitiveModel> pms = new ArrayList<PrimitiveModel>();
int numComp = Terser.numComponents(this.type);
for (int k = 1; k <= numComp; k++) {
int numSubComp = Terser.numSubComponents(this.type, k);
for (int m = 1; m <= numSubComp; m++) {
Primitive p = getPrimitive(this.type, k, m);
PrimitiveModel pm = new PrimitiveModel(this, p, k, m);
pms.add(pm);
}
}
primitives = pms.toArray(new PrimitiveModel[0]);
} else {
PrimitiveModel pm = new PrimitiveModel(this, null, 1, 1);
primitives = new PrimitiveModel[] { pm };
}
}
use of ca.uhn.hl7v2.model.Type in project tdi-studio-se by Talend.
the class PrimitiveModel method generateDisplayName.
@Override
protected void generateDisplayName() {
//$NON-NLS-1$
String parentName = "";
if (parent instanceof TypeModel) {
TypeModel tm = (TypeModel) parent;
Type type = tm.getType();
String parentDisplayName = tm.getDisplayName();
parentName = parentDisplayName;
if (type != null) {
String extensionName = type.getName();
// int extensionIndex = parentDisplayName.indexOf(extensionName);
// changed for bug TDI-19467
int extensionIndex = parentDisplayName.lastIndexOf(extensionName);
parentName = parentDisplayName.substring(0, extensionIndex - 1);
}
}
String typeDispaly = primitive == null ? "" : TalendTextUtils.LBRACKET + this.primitive.getName() + TalendTextUtils.RBRACKET;
//$NON-NLS-1$ //$NON-NLS-2$
this.displayName = parentName + "-" + this.componentindex + "-" + this.subcomponentindex + typeDispaly;
}
Aggregations