public static FastMessage convert(Group group, FastMessage groupMsg, ConversionContext context) { setNameAndId(group, groupMsg); if (group.getTypeReference() != null && !FastConstants.ANY_TYPE.equals(group.getTypeReference())) { GroupValue typeRef = new GroupValue( (Group) SessionControlProtocol_1_1.TYPE_REF.getField( new QName("TypeRef", SessionControlProtocol_1_1.NAMESPACE))); setName(typeRef, group.getTypeReference()); groupMsg.setFieldValue("TypeRef", typeRef); } SequenceValue instructions = new SequenceValue( SessionControlProtocol_1_1.TEMPLATE_DEFINITION.getSequence("Instructions")); int i = group instanceof MessageTemplate ? 1 : 0; Field[] fields = group.getFieldDefinitions(); for (; i < fields.length; i++) { Field field = fields[i]; FieldInstructionConverter converter = context.getConverter(field); if (converter == null) throw new IllegalStateException("No converter found for type " + field.getClass()); FieldValue value = converter.convert(field, context); instructions.add(new FieldValue[] {value}); } groupMsg.setFieldValue("Instructions", instructions); return groupMsg; }
public static Field[] parseFieldInstructions( GroupValue groupDef, TemplateRegistry registry, ConversionContext context) { SequenceValue instructions = groupDef.getSequence("Instructions"); Field[] fields = new Field[instructions.getLength()]; for (int i = 0; i < fields.length; i++) { GroupValue fieldDef = instructions.get(i).getGroup(0); FieldInstructionConverter converter = context.getConverter(fieldDef.getGroup()); if (converter == null) throw new IllegalStateException( "Encountered unknown group " + fieldDef.getGroup() + "while processing field instructions " + groupDef.getGroup()); fields[i] = converter.convert(fieldDef, registry, context); } return fields; }