Exemplo n.º 1
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()]);
  }
Exemplo n.º 2
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);
  }
Exemplo n.º 3
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);
    }
  }
Exemplo n.º 4
0
  public boolean equalsCompareType(EventType otherEventType) {
    if (this == otherEventType) {
      return true;
    }

    if (!(otherEventType instanceof WrapperEventType)) {
      return false;
    }

    WrapperEventType other = (WrapperEventType) otherEventType;
    if (!other.underlyingMapType.equalsCompareType(this.underlyingMapType)) {
      return false;
    }

    if (!(other.underlyingEventType instanceof EventTypeSPI)
        || (!(this.underlyingEventType instanceof EventTypeSPI))) {
      return other.underlyingEventType.equals(this.underlyingEventType);
    }

    EventTypeSPI otherUnderlying = (EventTypeSPI) other.underlyingEventType;
    EventTypeSPI thisUnderlying = (EventTypeSPI) this.underlyingEventType;
    return otherUnderlying.equalsCompareType(thisUnderlying);
  }