Beispiel #1
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);
  }
Beispiel #2
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;
  }
Beispiel #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;
  }
Beispiel #4
0
 public boolean isDynamic() {
   for (Property property : properties) {
     if (property.isDynamic()) {
       return true;
     }
   }
   return false;
 }
Beispiel #5
0
 public String[] toPropertyArray() {
   List<String> propertyNames = new ArrayList<String>();
   for (Property property : properties) {
     String[] nested = property.toPropertyArray();
     propertyNames.addAll(Arrays.asList(nested));
   }
   return propertyNames.toArray(new String[propertyNames.size()]);
 }
Beispiel #6
0
 public void toPropertyEPL(StringWriter writer) {
   String delimiter = "";
   for (Property property : properties) {
     writer.append(delimiter);
     property.toPropertyEPL(writer);
     delimiter = ".";
   }
 }
Beispiel #7
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);
  }
Beispiel #8
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));
  }
Beispiel #9
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());
  }
Beispiel #10
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);
    }
  }