コード例 #1
0
  public ClassObjectType getClassObjectType(
      final ClassObjectType objectType,
      final boolean isEvent,
      final AcceptsClassObjectType target) {
    AccessorKey key =
        new AccessorKey(
            objectType.getClassName(),
            isEvent ? "$$DROOLS__isEvent__" : null,
            AccessorKey.AccessorType.ClassObjectType);

    ClassObjectTypeLookupEntry entry = (ClassObjectTypeLookupEntry) this.lookup.get(key);
    if (entry == null) {
      entry = new ClassObjectTypeLookupEntry(cache.getClassObjectType(objectType));
      this.lookup.put(key, entry);
    }

    if (target != null) {
      entry.addAccessorTarget(target);
      target.setClassObjectType(entry.getClassObjectType());
    }

    return entry.getClassObjectType();
  }
コード例 #2
0
  public void merge(ClassFieldAccessorStore other) {
    for (Entry<AccessorKey, BaseLookupEntry> entry : other.lookup.entrySet()) {

      switch (entry.getValue().getAccessorType()) {
        case FieldAccessor:
          {
            FieldLookupEntry lookupEntry = (FieldLookupEntry) this.lookup.get(entry.getKey());
            if (lookupEntry == null) {
              lookupEntry = (FieldLookupEntry) entry.getValue();
              this.lookup.put(entry.getKey(), lookupEntry);
              // wire up ClassFieldReaders
              if (lookupEntry.getClassFieldReader() != null) {
                wire(lookupEntry.getClassFieldReader());
              }

              if (lookupEntry.getClassFieldWriter() != null) {
                wire(lookupEntry.getClassFieldWriter());
              }
            } else {
              // iterate through new targets adding them and wiring them up
              // to the existing ClassFieldReader, no need to wire generated accessor
              // as we know it already exists
              for (Acceptor target : entry.getValue().getAccessorTargets()) {
                if (target instanceof AcceptsReadAccessor) {
                  ((AcceptsReadAccessor) target).setReadAccessor(lookupEntry.getClassFieldReader());
                } else if (target instanceof AcceptsWriteAccessor) {
                  ((AcceptsWriteAccessor) target)
                      .setWriteAccessor(lookupEntry.getClassFieldWriter());
                }
                lookupEntry.addAccessorTarget(target);
              }
              if (lookupEntry.getClassFieldReader() != null) {
                wire(((FieldLookupEntry) entry.getValue()).getClassFieldReader());
              }
              if (lookupEntry.getClassFieldWriter() != null) {
                wire(((FieldLookupEntry) entry.getValue()).getClassFieldWriter());
              }
            }
            break;
          }

        case ClassObjectType:
          {
            ClassObjectTypeLookupEntry lookupEntry =
                (ClassObjectTypeLookupEntry) this.lookup.get(entry.getKey());
            if (lookupEntry == null) {
              // Create new entry with correct ClassObjectType and targets
              lookupEntry =
                  new ClassObjectTypeLookupEntry(
                      cache.getClassObjectType(
                          ((ClassObjectTypeLookupEntry) entry.getValue()).getClassObjectType()));

              this.lookup.put(entry.getKey(), lookupEntry);
            }

            for (Acceptor target : entry.getValue().getAccessorTargets()) {
              ((AcceptsClassObjectType) target)
                  .setClassObjectType(lookupEntry.getClassObjectType());
              lookupEntry.addAccessorTarget(target);
            }
          }

          //                case ObjectAccessor : {
          //                    ObjectExtractorLookupEntry lookupEntry = (
          // ObjectExtractorLookupEntry ) this.lookup.get( entry.getKey() );
          //                    if ( lookupEntry == null ) {
          //                        lookupEntry = ( ObjectExtractorLookupEntry )  entry.getValue();
          //                        this.lookup.put( entry.getKey(),
          //                                         lookupEntry );
          //                        wire( lookupEntry.getObjectExtractor() );
          //                    } else {
          //                        for ( Acceptor target : entry.getValue().getAccessorTargets() )
          // {
          //                            ((Declaration)target).setReadAccessor(
          // lookupEntry.getObjectExtractor() );
          //                            lookupEntry.addAccessorTarget( target );
          //                        }
          //                    }
          //                    break;
          //                }
          //                case GlobalAccessor : {
          //                    GlobalExtractorLookupEntry lookupEntry = (
          // GlobalExtractorLookupEntry ) this.lookup.get( entry.getKey() );
          //                    if ( lookupEntry == null ) {
          //                        lookupEntry = ( GlobalExtractorLookupEntry )  entry.getValue();
          //                        this.lookup.put( entry.getKey(),
          //                                         lookupEntry );
          //                        wire( lookupEntry.getGlobalExtractor() );
          //                    } else {
          //                        for ( Acceptor target : entry.getValue().getAccessorTargets() )
          // {
          //                            ((Declaration)target).setReadAccessor(
          // lookupEntry.getGlobalExtractor() );
          //                            lookupEntry.addAccessorTarget( target );
          //                        }
          //                    }
          //                    break;
          //                }
      }
    }
  }