Search in sources :

Example 6 with Type

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);
}
Also used : Message(ca.uhn.hl7v2.model.Message) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 7 with Type

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 };
    }
}
Also used : Primitive(ca.uhn.hl7v2.model.Primitive) GenericPrimitive(ca.uhn.hl7v2.model.GenericPrimitive) ArrayList(java.util.ArrayList)

Example 8 with Type

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;
}
Also used : Type(ca.uhn.hl7v2.model.Type)

Aggregations

Type (ca.uhn.hl7v2.model.Type)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)2 GenericPrimitive (ca.uhn.hl7v2.model.GenericPrimitive)2 Primitive (ca.uhn.hl7v2.model.Primitive)2 ArrayList (java.util.ArrayList)2 Composite (ca.uhn.hl7v2.model.Composite)1 DataTypeException (ca.uhn.hl7v2.model.DataTypeException)1 GenericComposite (ca.uhn.hl7v2.model.GenericComposite)1 Group (ca.uhn.hl7v2.model.Group)1 Message (ca.uhn.hl7v2.model.Message)1 Structure (ca.uhn.hl7v2.model.Structure)1 Varies (ca.uhn.hl7v2.model.Varies)1 QRY_A19 (ca.uhn.hl7v2.model.v24.message.QRY_A19)1 QRD (ca.uhn.hl7v2.model.v24.segment.QRD)1 PipeParser (ca.uhn.hl7v2.parser.PipeParser)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 HL7DataFormat (org.apache.camel.component.hl7.HL7DataFormat)1