示例#1
0
 public Class getPropertyType(String property) {
   if (underlyingEventType.isProperty(property)) {
     return underlyingEventType.getPropertyType(property);
   } else if (underlyingMapType.isProperty(property)) {
     return underlyingMapType.getPropertyType(property);
   } else {
     return null;
   }
 }
示例#2
0
 public FragmentEventType getFragmentType(String property) {
   FragmentEventType fragment = underlyingEventType.getFragmentType(property);
   if (fragment != null) {
     return fragment;
   }
   return underlyingMapType.getFragmentType(property);
 }
示例#3
0
 public EventPropertyGetterIndexed getGetterIndexed(String indexedProperty) {
   final EventPropertyGetterIndexed undIndexed =
       underlyingEventType.getGetterIndexed(indexedProperty);
   if (undIndexed != null) {
     return new EventPropertyGetterIndexed() {
       public Object get(EventBean theEvent, int index) throws PropertyAccessException {
         if (!(theEvent instanceof DecoratingEventBean)) {
           throw new PropertyAccessException("Mismatched property getter to EventBean type");
         }
         DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
         EventBean wrappedEvent = wrapperEvent.getUnderlyingEvent();
         if (wrappedEvent == null) {
           return null;
         }
         return undIndexed.get(wrappedEvent, index);
       }
     };
   }
   final EventPropertyGetterIndexed decoIndexed =
       underlyingMapType.getGetterIndexed(indexedProperty);
   if (decoIndexed != null) {
     return new EventPropertyGetterIndexed() {
       public Object get(EventBean theEvent, int index) throws PropertyAccessException {
         if (!(theEvent instanceof DecoratingEventBean)) {
           throw new PropertyAccessException("Mismatched property getter to EventBean type");
         }
         DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
         Map map = wrapperEvent.getDecoratingProperties();
         return decoIndexed.get(
             eventAdapterService.adapterForTypedMap(map, underlyingMapType), index);
       }
     };
   }
   return null;
 }
示例#4
0
  private void initializeWriters() {
    List<EventPropertyDescriptor> writables = new ArrayList<EventPropertyDescriptor>();
    Map<String, Pair<EventPropertyDescriptor, EventPropertyWriter>> writerMap =
        new HashMap<String, Pair<EventPropertyDescriptor, EventPropertyWriter>>();
    writables.addAll(Arrays.asList(underlyingMapType.getWriteableProperties()));

    for (EventPropertyDescriptor writableMapProp : underlyingMapType.getWriteableProperties()) {
      final String propertyName = writableMapProp.getPropertyName();
      writables.add(writableMapProp);
      EventPropertyWriter writer =
          new EventPropertyWriter() {
            public void write(Object value, EventBean target) {
              DecoratingEventBean decorated = (DecoratingEventBean) target;
              decorated.getDecoratingProperties().put(propertyName, value);
            }
          };
      writerMap.put(
          propertyName,
          new Pair<EventPropertyDescriptor, EventPropertyWriter>(writableMapProp, writer));
    }

    if (underlyingEventType instanceof EventTypeSPI) {
      EventTypeSPI spi = (EventTypeSPI) underlyingEventType;
      for (EventPropertyDescriptor writableUndProp : spi.getWriteableProperties()) {
        final String propertyName = writableUndProp.getPropertyName();
        final EventPropertyWriter innerWriter = spi.getWriter(propertyName);
        if (innerWriter == null) {
          continue;
        }

        writables.add(writableUndProp);
        EventPropertyWriter writer =
            new EventPropertyWriter() {
              public void write(Object value, EventBean target) {
                DecoratingEventBean decorated = (DecoratingEventBean) target;
                innerWriter.write(value, decorated.getUnderlyingEvent());
              }
            };
        writerMap.put(
            propertyName,
            new Pair<EventPropertyDescriptor, EventPropertyWriter>(writableUndProp, writer));
      }
    }

    writers = writerMap;
    writableProperties = writables.toArray(new EventPropertyDescriptor[writables.size()]);
  }
示例#5
0
  private static PropertyDescriptorComposite getCompositeProperties(
      EventType underlyingEventType, MapEventType underlyingMapType) {
    List<String> propertyNames = new ArrayList<String>();
    propertyNames.addAll(Arrays.asList(underlyingEventType.getPropertyNames()));
    propertyNames.addAll(Arrays.asList(underlyingMapType.getPropertyNames()));
    String[] propertyNamesArr = propertyNames.toArray(new String[propertyNames.size()]);

    List<EventPropertyDescriptor> propertyDesc = new ArrayList<EventPropertyDescriptor>();
    HashMap<String, EventPropertyDescriptor> propertyDescriptorMap =
        new HashMap<String, EventPropertyDescriptor>();
    for (EventPropertyDescriptor eventProperty : underlyingEventType.getPropertyDescriptors()) {
      propertyDesc.add(eventProperty);
      propertyDescriptorMap.put(eventProperty.getPropertyName(), eventProperty);
    }
    for (EventPropertyDescriptor mapProperty : underlyingMapType.getPropertyDescriptors()) {
      propertyDesc.add(mapProperty);
      propertyDescriptorMap.put(mapProperty.getPropertyName(), mapProperty);
    }
    EventPropertyDescriptor[] propertyDescArr =
        propertyDesc.toArray(new EventPropertyDescriptor[propertyDesc.size()]);
    return new PropertyDescriptorComposite(
        propertyDescriptorMap, propertyNamesArr, propertyDescArr);
  }
示例#6
0
  public EventBeanWriter getWriter(String[] properties) {
    if (writableProperties == null) {
      initializeWriters();
    }

    boolean isOnlyMap = true;
    for (int i = 0; i < properties.length; i++) {
      if (!writers.containsKey(properties[i])) {
        return null;
      }
      if (underlyingMapType.getWritableProperty(properties[i]) == null) {
        isOnlyMap = false;
      }
    }

    boolean isOnlyUnderlying = true;
    if (!isOnlyMap) {
      EventTypeSPI spi = (EventTypeSPI) underlyingEventType;
      for (int i = 0; i < properties.length; i++) {
        if (spi.getWritableProperty(properties[i]) == null) {
          isOnlyUnderlying = false;
        }
      }
    }

    if (isOnlyMap) {
      return new WrapperEventBeanMapWriter(properties);
    }
    if (isOnlyUnderlying) {
      EventTypeSPI spi = (EventTypeSPI) underlyingEventType;
      EventBeanWriter undWriter = spi.getWriter(properties);
      if (undWriter == null) {
        return undWriter;
      }
      return new WrapperEventBeanUndWriter(undWriter);
    }

    EventPropertyWriter writerArr[] = new EventPropertyWriter[properties.length];
    for (int i = 0; i < properties.length; i++) {
      writerArr[i] = writers.get(properties[i]).getSecond();
    }
    return new WrapperEventBeanPropertyWriter(writerArr);
  }
示例#7
0
  public EventBeanCopyMethod getCopyMethod(String[] properties) {
    if (writableProperties == null) {
      initializeWriters();
    }

    boolean isOnlyMap = true;
    for (int i = 0; i < properties.length; i++) {
      if (underlyingMapType.getWritableProperty(properties[i]) == null) {
        isOnlyMap = false;
      }
    }

    boolean isOnlyUnderlying = true;
    if (!isOnlyMap) {
      if (!(underlyingEventType instanceof EventTypeSPI)) {
        return null;
      }
      EventTypeSPI spi = (EventTypeSPI) underlyingEventType;
      for (int i = 0; i < properties.length; i++) {
        if (spi.getWritableProperty(properties[i]) == null) {
          isOnlyUnderlying = false;
        }
      }
    }

    if (isOnlyMap) {
      return new WrapperEventBeanMapCopyMethod(this, eventAdapterService);
    }

    EventBeanCopyMethod undCopyMethod =
        ((EventTypeSPI) underlyingEventType).getCopyMethod(properties);
    if (undCopyMethod == null) {
      return null;
    }
    if (isOnlyUnderlying) {
      return new WrapperEventBeanUndCopyMethod(this, eventAdapterService, undCopyMethod);
    } else {
      return new WrapperEventBeanCopyMethod(this, eventAdapterService, undCopyMethod);
    }
  }
示例#8
0
 public boolean isProperty(String property) {
   return underlyingEventType.isProperty(property) || underlyingMapType.isProperty(property);
 }
示例#9
0
  public EventPropertyGetter getGetter(final String property) {
    EventPropertyGetter cachedGetter = propertyGetterCache.get(property);
    if (cachedGetter != null) {
      return cachedGetter;
    }

    if (underlyingMapType.isProperty(property) && (property.indexOf('?') == -1)) {
      final EventPropertyGetter mapGetter = underlyingMapType.getGetter(property);
      EventPropertyGetter getter =
          new EventPropertyGetter() {
            public Object get(EventBean theEvent) {
              if (!(theEvent instanceof DecoratingEventBean)) {
                throw new PropertyAccessException("Mismatched property getter to EventBean type");
              }
              DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
              Map map = wrapperEvent.getDecoratingProperties();
              return mapGetter.get(eventAdapterService.adapterForTypedMap(map, underlyingMapType));
            }

            public boolean isExistsProperty(EventBean eventBean) {
              return true; // Property exists as the property is not dynamic (unchecked)
            }

            public Object getFragment(EventBean theEvent) {
              if (!(theEvent instanceof DecoratingEventBean)) {
                throw new PropertyAccessException("Mismatched property getter to EventBean type");
              }
              DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
              Map map = wrapperEvent.getDecoratingProperties();
              return mapGetter.getFragment(
                  eventAdapterService.adapterForTypedMap(map, underlyingMapType));
            }
          };
      propertyGetterCache.put(property, getter);
      return getter;
    } else if (underlyingEventType.isProperty(property)) {
      EventPropertyGetter getter =
          new EventPropertyGetter() {
            public Object get(EventBean theEvent) {
              if (!(theEvent instanceof DecoratingEventBean)) {
                throw new PropertyAccessException("Mismatched property getter to EventBean type");
              }
              DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
              EventBean wrappedEvent = wrapperEvent.getUnderlyingEvent();
              if (wrappedEvent == null) {
                return null;
              }

              EventPropertyGetter underlyingGetter = underlyingEventType.getGetter(property);
              return underlyingGetter.get(wrappedEvent);
            }

            public boolean isExistsProperty(EventBean eventBean) {
              return true; // Property exists as the property is not dynamic (unchecked)
            }

            public Object getFragment(EventBean theEvent) {
              if (!(theEvent instanceof DecoratingEventBean)) {
                throw new PropertyAccessException("Mismatched property getter to EventBean type");
              }
              DecoratingEventBean wrapperEvent = (DecoratingEventBean) theEvent;
              EventBean wrappedEvent = wrapperEvent.getUnderlyingEvent();
              if (wrappedEvent == null) {
                return null;
              }

              EventPropertyGetter underlyingGetter = underlyingEventType.getGetter(property);
              return underlyingGetter.getFragment(wrappedEvent);
            }
          };
      propertyGetterCache.put(property, getter);
      return getter;
    } else {
      return null;
    }
  }