Package com.apama.event.parser

Represents the definition of an Apama event type, for which values are specified as Event objects. Each EventType consists of an event type name, and zero or more Field objects. An event that contains an 'any' field must be registered to exactly one EventParser object, along with all types that may be contained within the 'any' value. Example: EVENT_PARSER.registerType(FieldTypes.sequence(FieldTypes.INTEGER));

Example usage:


static final Field<String> FIELD_MY_STRING = FieldTypes.STRING.newField("myString");
static final Field<List<Double>> FIELD_MY_SEQ = FieldTypes.sequence(FieldTypes.FLOAT).newField("mySeq");
static final Field<Map<String,Long>> FIELD_MY_DICT = FieldTypes.dictionary(FieldTypes.STRING, FieldTypes.INTEGER).newField("myDict");
static final Field<AnyFieldValue> FIELD_ANY = new AnyFieldType().newField("anyField");

static final EventType EVENT_NESTED = new EventType("sample.NestedEvent", FIELD_MY_STRING);
static final Field<Event> FIELD_NESTED = EVENT_NESTED.newField("myNested");

static final EventType EVENT_MY_EVENT = new EventType("sample.MyEvent", FIELD_MY_STRING, FIELD_MY_SEQ, FIELD_MY_DICT, FIELD_NESTED, FIELD_ANY);
static final EventParser EVENT_PARSER = new EventParser(EVENT_MY_EVENT);

public void demonstrateParsingAndGettingFieldValues()
{
	Event e = EVENT_PARSER.parse("sample.MyEvent(\"Hello\",[1.5,2.3],{\"myDictKey\":123},sample.NestedEvent(\"Nested Hello\"), any(integer,4321))");
	String myString = e.getField(FIELD_MY_STRING);
	List<Double> mySeq = e.getField(FIELD_MY_SEQ);
	Map<String,Long> myDict = e.getField(FIELD_MY_DICT);
	String myString2 = e.getField(FIELD_NESTED).getField(FIELD_MY_STRING);
	Object anyField = e.getField(FIELD_ANY);
	System.out.println("Field values: "+myString+", "+mySeq+", "+myDict+", "+myString2 + ", "+ anyField);
}

public void demonstrateSettingFieldValues()
{
	Event e = new Event(EVENT_MY_EVENT)
		.setField(FIELD_MY_STRING, "Hello")
		.setField(FIELD_MY_SEQ, Arrays.asList(1.5, 2.3D))
		.setField(FIELD_MY_DICT, Collections.singletonMap("myDictKey", 123L))
		.setField(FIELD_NESTED, 
				new Event(EVENT_NESTED)
				.setField(FIELD_MY_STRING, "Nested Hello"))
		.setField(FIELD_ANY,new AnyFieldValue(FieldTypes.STRING, "ANY_AS_STRING"));
	String eventString = e.getText();
	System.out.println(eventString);
}