Exemplo n.º 1
0
  public GenericPropertyDesc getPropertyTypeGeneric(
      BeanEventType eventType, EventAdapterService eventAdapterService) {
    GenericPropertyDesc result = null;

    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      result = property.getPropertyTypeGeneric(eventType, eventAdapterService);

      if (result == null) {
        // property not found, return null
        return null;
      }

      if (it.hasNext()) {
        // Map cannot be used to further nest as the type cannot be determined
        if (result.getType() == Map.class) {
          return null;
        }

        if (result.getType().isArray()) {
          return null;
        }

        eventType =
            eventAdapterService
                .getBeanEventTypeFactory()
                .createBeanType(result.getType().getName(), result.getType(), false, false, false);
      }
    }

    return result;
  }
Exemplo n.º 2
0
  public SchemaItem getPropertyTypeSchema(
      SchemaElementComplex parentComplexProperty, EventAdapterService eventAdapterService) {
    Property lastProperty = null;
    SchemaElementComplex complexElement = parentComplexProperty;

    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      lastProperty = property;

      if (it.hasNext()) {
        SchemaItem childSchemaItem =
            property.getPropertyTypeSchema(complexElement, eventAdapterService);
        if (childSchemaItem == null) {
          // if the property is not valid, return null
          return null;
        }

        if ((childSchemaItem instanceof SchemaItemAttribute)
            || (childSchemaItem instanceof SchemaElementSimple)) {
          return null;
        }

        complexElement = (SchemaElementComplex) childSchemaItem;
      }
    }

    return lastProperty.getPropertyTypeSchema(complexElement, eventAdapterService);
  }
Exemplo n.º 3
0
  public Class getPropertyType(BeanEventType eventType, EventAdapterService eventAdapterService) {
    Class result = null;

    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      result = property.getPropertyType(eventType, eventAdapterService);

      if (result == null) {
        // property not found, return null
        return null;
      }

      if (it.hasNext()) {
        // Map cannot be used to further nest as the type cannot be determined
        if (result == Map.class) {
          return null;
        }

        if (result.isArray()
            || result.isPrimitive()
            || JavaClassHelper.isJavaBuiltinDataType(result)) {
          return null;
        }

        eventType =
            eventAdapterService
                .getBeanEventTypeFactory()
                .createBeanType(result.getName(), result, false, false, false);
      }
    }

    return result;
  }
Exemplo n.º 4
0
  public EventPropertyGetter getGetterDOM() {
    List<EventPropertyGetter> getters = new LinkedList<EventPropertyGetter>();

    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      EventPropertyGetter getter = property.getGetterDOM();
      if (getter == null) {
        return null;
      }

      getters.add(getter);
    }

    return new DOMNestedPropertyGetter(getters, null);
  }
Exemplo n.º 5
0
  public EventPropertyGetter getGetterDOM(
      SchemaElementComplex parentComplexProperty,
      EventAdapterService eventAdapterService,
      BaseXMLEventType eventType,
      String propertyExpression) {
    List<EventPropertyGetter> getters = new LinkedList<EventPropertyGetter>();

    SchemaElementComplex complexElement = parentComplexProperty;

    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      EventPropertyGetter getter =
          property.getGetterDOM(complexElement, eventAdapterService, eventType, propertyExpression);
      if (getter == null) {
        return null;
      }

      if (it.hasNext()) {
        SchemaItem childSchemaItem =
            property.getPropertyTypeSchema(complexElement, eventAdapterService);
        if (childSchemaItem == null) {
          // if the property is not valid, return null
          return null;
        }

        if ((childSchemaItem instanceof SchemaItemAttribute)
            || (childSchemaItem instanceof SchemaElementSimple)) {
          return null;
        }

        complexElement = (SchemaElementComplex) childSchemaItem;

        if (complexElement.isArray()) {
          if ((property instanceof SimpleProperty) || (property instanceof DynamicSimpleProperty)) {
            return null;
          }
        }
      }

      getters.add(getter);
    }

    return new DOMNestedPropertyGetter(
        getters, new FragmentFactoryDOMGetter(eventAdapterService, eventType, propertyExpression));
  }
Exemplo n.º 6
0
  public EventPropertyGetter getGetter(
      BeanEventType eventType, EventAdapterService eventAdapterService) {
    List<EventPropertyGetter> getters = new LinkedList<EventPropertyGetter>();

    Property lastProperty = null;
    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      Property property = it.next();
      lastProperty = property;
      EventPropertyGetter getter = property.getGetter(eventType, eventAdapterService);
      if (getter == null) {
        return null;
      }

      if (it.hasNext()) {
        Class clazz = property.getPropertyType(eventType, eventAdapterService);
        if (clazz == null) {
          // if the property is not valid, return null
          return null;
        }
        // Map cannot be used to further nest as the type cannot be determined
        if (clazz == Map.class) {
          return null;
        }
        if (clazz.isArray()) {
          return null;
        }
        eventType =
            eventAdapterService
                .getBeanEventTypeFactory()
                .createBeanType(clazz.getName(), clazz, false, false, false);
      }
      getters.add(getter);
    }

    GenericPropertyDesc finalPropertyType =
        lastProperty.getPropertyTypeGeneric(eventType, eventAdapterService);
    return new NestedPropertyGetter(
        getters, eventAdapterService, finalPropertyType.getType(), finalPropertyType.getGeneric());
  }
Exemplo n.º 7
0
  public MapEventPropertyGetter getGetterMap(
      Map optionalMapPropTypes, EventAdapterService eventAdapterService) {
    List<EventPropertyGetter> getters = new LinkedList<EventPropertyGetter>();
    Map currentDictionary = optionalMapPropTypes;

    int count = 0;
    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      count++;
      Property property = it.next();

      // manufacture a getter for getting the item out of the map
      EventPropertyGetter getter = property.getGetterMap(currentDictionary, eventAdapterService);
      if (getter == null) {
        return null;
      }
      getters.add(getter);

      PropertyBase theBase = (PropertyBase) property;
      String propertyName = theBase.getPropertyNameAtomic();

      // For the next property if there is one, check how to property type is defined
      if (!it.hasNext()) {
        continue;
      }

      if (currentDictionary != null) {
        // check the type that this property will return
        Object propertyReturnType = currentDictionary.get(propertyName);

        if (propertyReturnType == null) {
          currentDictionary = null;
        }
        if (propertyReturnType != null) {
          if (propertyReturnType instanceof Map) {
            currentDictionary = (Map) propertyReturnType;
          } else if (propertyReturnType == Map.class) {
            currentDictionary = null;
          } else if (propertyReturnType instanceof String) {
            String nestedName = propertyReturnType.toString();
            boolean isArray = EventTypeUtility.isPropertyArray(nestedName);
            if (isArray) {
              nestedName = EventTypeUtility.getPropertyRemoveArray(nestedName);
            }

            EventType innerType = eventAdapterService.getExistsTypeByName(nestedName);
            if (innerType == null) {
              return null;
            }

            String remainingProps = toPropertyEPL(properties, count);
            EventPropertyGetter getterInner = innerType.getGetter(remainingProps);
            if (getterInner == null) {
              return null;
            }

            getters.add(getterInner);
            break; // the single Pojo getter handles the rest
          } else if (propertyReturnType instanceof EventType) {
            EventType innerType = (EventType) propertyReturnType;
            String remainingProps = toPropertyEPL(properties, count);
            EventPropertyGetter getterInner = innerType.getGetter(remainingProps);
            if (getterInner == null) {
              return null;
            }

            getters.add(getterInner);
            break; // the single Pojo getter handles the rest
          } else {
            // treat the return type of the map property as a POJO
            Class pojoClass = (Class) propertyReturnType;
            if (!pojoClass.isArray()) {
              BeanEventType beanType =
                  eventAdapterService
                      .getBeanEventTypeFactory()
                      .createBeanType(pojoClass.getName(), pojoClass, false, false, false);
              String remainingProps = toPropertyEPL(properties, count);
              EventPropertyGetter getterInner = beanType.getGetter(remainingProps);
              if (getterInner == null) {
                return null;
              }
              getters.add(getterInner);
              break; // the single Pojo getter handles the rest
            } else {
              Class componentType = pojoClass.getComponentType();
              BeanEventType beanType =
                  eventAdapterService
                      .getBeanEventTypeFactory()
                      .createBeanType(componentType.getName(), componentType, false, false, false);
              String remainingProps = toPropertyEPL(properties, count);
              EventPropertyGetter getterInner = beanType.getGetter(remainingProps);
              if (getterInner == null) {
                return null;
              }
              getters.add(getterInner);
              break; // the single Pojo getter handles the rest
            }
          }
        }
      }
    }

    boolean hasNonmapGetters = false;
    for (int i = 0; i < getters.size(); i++) {
      if (!(getters.get(i) instanceof MapEventPropertyGetter)) {
        hasNonmapGetters = true;
      }
    }
    if (!hasNonmapGetters) {
      return new MapNestedPropertyGetterMapOnly(getters, eventAdapterService);
    } else {
      return new MapNestedPropertyGetterMixedType(getters, eventAdapterService);
    }
  }
Exemplo n.º 8
0
  public Class getPropertyTypeMap(
      Map optionalMapPropTypes, EventAdapterService eventAdapterService) {
    Map currentDictionary = optionalMapPropTypes;

    int count = 0;
    for (Iterator<Property> it = properties.iterator(); it.hasNext(); ) {
      count++;
      Property property = it.next();
      PropertyBase theBase = (PropertyBase) property;
      String propertyName = theBase.getPropertyNameAtomic();

      Object nestedType = null;
      if (currentDictionary != null) {
        nestedType = currentDictionary.get(propertyName);
      }

      if (nestedType == null) {
        if (property instanceof DynamicProperty) {
          return Object.class;
        } else {
          return null;
        }
      }

      if (!it.hasNext()) {
        if (nestedType instanceof Class) {
          return (Class) nestedType;
        }
        if (nestedType instanceof Map) {
          return Map.class;
        }
      }

      if (nestedType == Map.class) {
        return Object.class;
      }

      if (nestedType instanceof Class) {
        Class pojoClass = (Class) nestedType;
        if (!pojoClass.isArray()) {
          BeanEventType beanType =
              eventAdapterService
                  .getBeanEventTypeFactory()
                  .createBeanType(pojoClass.getName(), pojoClass, false, false, false);
          String remainingProps = toPropertyEPL(properties, count);
          return beanType.getPropertyType(remainingProps);
        } else if (property instanceof IndexedProperty) {
          Class componentType = pojoClass.getComponentType();
          BeanEventType beanType =
              eventAdapterService
                  .getBeanEventTypeFactory()
                  .createBeanType(componentType.getName(), componentType, false, false, false);
          String remainingProps = toPropertyEPL(properties, count);
          return beanType.getPropertyType(remainingProps);
        }
      }

      if (nestedType instanceof String) // property type is the name of a map event type
      {
        String nestedName = nestedType.toString();
        boolean isArray = EventTypeUtility.isPropertyArray(nestedName);
        if (isArray) {
          nestedName = EventTypeUtility.getPropertyRemoveArray(nestedName);
        }

        EventType innerType = eventAdapterService.getExistsTypeByName(nestedName);
        if (innerType == null) {
          return null;
        }

        String remainingProps = toPropertyEPL(properties, count);
        return innerType.getPropertyType(remainingProps);
      } else if (nestedType instanceof EventType) // property type is the name of a map event type
      {
        EventType innerType = (EventType) nestedType;
        String remainingProps = toPropertyEPL(properties, count);
        return innerType.getPropertyType(remainingProps);
      } else {
        if (!(nestedType instanceof Map)) {
          String message =
              "Nestable map type configuration encountered an unexpected value type of '"
                  + nestedType.getClass()
                  + " for property '"
                  + propertyName
                  + "', expected Class, Map.class or Map<String, Object> as value type";
          throw new PropertyAccessException(message);
        }
      }

      currentDictionary = (Map) nestedType;
    }
    throw new IllegalStateException("Unexpected end of nested property");
  }