public void TestArrayOp() { EventBean[] testEvent = MakeEventArray(new[] { "a1", "a2", "a3" }); EPAssertionUtil.AssertEqualsAnyOrder(new Object[] { testEvent[0] }, EventBeanUtility.AddToArray(new EventBean[0], testEvent[0])); EPAssertionUtil.AssertEqualsAnyOrder(new Object[] { testEvent[0], testEvent[1] }, EventBeanUtility.AddToArray(new[] { testEvent[0] }, testEvent[1])); EPAssertionUtil.AssertEqualsAnyOrder(new Object[] { testEvent[0], testEvent[1], testEvent[2] }, EventBeanUtility.AddToArray(new[] { testEvent[0], testEvent[1] }, testEvent[2])); }
public void TestMultiKey() { // try 2 properties EventPropertyGetter[] getters = MakeGetters(); EventBean theEvent = SupportEventBeanFactory.CreateObject(new SupportBean("a", 10)); MultiKeyUntyped multikey = EventBeanUtility.GetMultiKey(theEvent, getters); Assert.AreEqual(2, multikey.Keys.Length); Assert.AreEqual("a", multikey.Keys[0]); Assert.AreEqual(10, multikey.Keys[1]); // try no properties multikey = EventBeanUtility.GetMultiKey(theEvent, new EventPropertyGetter[0]); Assert.AreEqual(0, multikey.Keys.Length); }
public void TestGetPropertyArray() { // try 2 properties EventPropertyGetter[] getters = MakeGetters(); EventBean theEvent = SupportEventBeanFactory.CreateObject(new SupportBean("a", 10)); Object[] properties = EventBeanUtility.GetPropertyArray(theEvent, getters); Assert.AreEqual(2, properties.Length); Assert.AreEqual("a", properties[0]); Assert.AreEqual(10, properties[1]); // try no properties properties = EventBeanUtility.GetPropertyArray(theEvent, new EventPropertyGetter[0]); Assert.AreEqual(0, properties.Length); }
public FragmentEventType GetFragmentType(String propertyName) { var item = _propertyItems.Get(propertyName); if (item != null) // may contain null values { return(item.FragmentEventType); } // see if this is a nested property var index = ASTUtil.UnescapedIndexOfDot(propertyName); if (index == -1) { // dynamic simple property if (propertyName.EndsWith("?")) { return(null); } // parse, can be an indexed property var property = PropertyParser.ParseAndWalk(propertyName); if (property is IndexedProperty) { var indexedProp = (IndexedProperty)property; var type = NestableTypes.Get(indexedProp.PropertyNameAtomic); if (type == null) { return(null); } else if (type is EventType[]) { var eventType = ((EventType[])type)[0]; return(new FragmentEventType(eventType, false, false)); } else if (type is String) { var propTypeName = type.ToString(); var isArray = EventTypeUtility.IsPropertyArray(propTypeName); if (!isArray) { return(null); } propTypeName = EventTypeUtility.GetPropertyRemoveArray(propTypeName); EventType innerType = EventAdapterService.GetEventTypeByName(propTypeName); if (!(innerType is BaseNestableEventType)) { return(null); } return(new FragmentEventType(innerType, false, false)); // false since an index is present } if (!(type is Type)) { return(null); } if (!((Type)type).IsArray) { return(null); } // its an array return(EventBeanUtility.CreateNativeFragmentType(((Type)type).GetElementType(), null, EventAdapterService)); } else if (property is MappedProperty) { // No type information available for the inner event return(null); } else { return(null); } } // Map event types allow 2 types of properties inside: // - a property that is a object is interrogated via bean property getters and BeanEventType // - a property that is a Map itself is interrogated via map property getters // The property getters therefore act on // Take apart the nested property into a map key and a nested value class property name var propertyMap = ASTUtil.UnescapeDot(propertyName.Substring(0, index)); var propertyNested = propertyName.Substring(index + 1); // If the property is dynamic, it cannot be a fragment if (propertyMap.EndsWith("?")) { return(null); } var nestedType = NestableTypes.Get(propertyMap); if (nestedType == null) { // parse, can be an indexed property var property = PropertyParser.ParseAndWalk(propertyMap); if (property is IndexedProperty) { var indexedProp = (IndexedProperty)property; var type = NestableTypes.Get(indexedProp.PropertyNameAtomic); if (type == null) { return(null); } // handle map-in-map case if (type is String) { var propTypeName = type.ToString(); var isArray = EventTypeUtility.IsPropertyArray(propTypeName); if (isArray) { propTypeName = EventTypeUtility.GetPropertyRemoveArray(propTypeName); } EventType innerType = EventAdapterService.GetEventTypeByName(propTypeName); if (!(innerType is BaseNestableEventType)) { return(null); } return(innerType.GetFragmentType(propertyNested)); } // handle eventtype[] in map else if (type is EventType[]) { var innerType = ((EventType[])type)[0]; return(innerType.GetFragmentType(propertyNested)); } // handle array class in map case else { if (!(type is Type)) { return(null); } if (!((Type)type).IsArray) { return(null); } var fragmentParent = EventBeanUtility.CreateNativeFragmentType( (Type)type, null, EventAdapterService); if (fragmentParent == null) { return(null); } return(fragmentParent.FragmentType.GetFragmentType(propertyNested)); } } else if (property is MappedProperty) { // No type information available for the property's map value return(null); } else { return(null); } } // If there is a map value in the map, return the Object value if this is a dynamic property if (ReferenceEquals(nestedType, typeof(IDictionary <string, object>))) { return(null); } else if (nestedType is IDictionary <string, object> ) { return(null); } else if (nestedType is Type) { var simpleClass = (Type)nestedType; if (!TypeHelper.IsFragmentableType(simpleClass)) { return(null); } EventType nestedEventType = EventAdapterService.BeanEventTypeFactory.CreateBeanTypeDefaultName(simpleClass); return(nestedEventType.GetFragmentType(propertyNested)); } else if (nestedType is EventType) { var innerType = (EventType)nestedType; return(innerType.GetFragmentType(propertyNested)); } else if (nestedType is EventType[]) { var innerType = (EventType[])nestedType; return(innerType[0].GetFragmentType(propertyNested)); } else if (nestedType is String) { var nestedName = nestedType.ToString(); var isArray = EventTypeUtility.IsPropertyArray(nestedName); if (isArray) { nestedName = EventTypeUtility.GetPropertyRemoveArray(nestedName); } var innerType = EventAdapterService.GetEventTypeByName(nestedName); if (!(innerType is BaseNestableEventType)) { return(null); } return(innerType.GetFragmentType(propertyNested)); } else { var message = "Nestable map type configuration encountered an unexpected value type of '" + nestedType.GetType() + " for property '" + propertyName + "', expected Class, typeof(Map) or IDictionary<String, Object> as value type"; throw new PropertyAccessException(message); } }