Search in sources :

Example 1 with AccessorKey

use of org.drools.core.base.AccessorKey in project drools by kiegroup.

the class ClassFieldAccessorStore method getAccessor.

public ClassFieldAccessor getAccessor(final String className, final String fieldName) {
    AccessorKey key = new AccessorKey(className, fieldName, AccessorKey.AccessorType.FieldAccessor);
    FieldLookupEntry entry = (FieldLookupEntry) this.lookup.computeIfAbsent(key, k -> new FieldLookupEntry(new ClassFieldReader(className, fieldName), new ClassFieldWriter(className, fieldName)));
    ClassFieldAccessor accessor = new ClassFieldAccessor((ClassFieldReader) entry.getClassFieldReader(), entry.getClassFieldWriter());
    if (this.eagerWire) {
        wire(entry.getClassFieldReader());
        wire(entry.getClassFieldWriter());
    }
    return accessor;
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) TypeDeclaration(org.drools.core.rule.TypeDeclaration) ObjectType(org.drools.core.spi.ObjectType) ObjectOutput(java.io.ObjectOutput) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) AccessorType(org.drools.core.base.AccessorKey.AccessorType) AccessorKey(org.drools.core.base.AccessorKey) Map(java.util.Map) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) FactField(org.kie.api.definition.type.FactField) Externalizable(java.io.Externalizable) Collection(java.util.Collection) WriteAccessor(org.drools.core.spi.WriteAccessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseClassFieldWriter(org.drools.core.base.BaseClassFieldWriter) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) ClassWireable(org.drools.core.spi.ClassWireable) IOException(java.io.IOException) Field(java.lang.reflect.Field) UncheckedIOException(java.io.UncheckedIOException) CoreComponentsBuilder(org.drools.core.base.CoreComponentsBuilder) AcceptsReadAccessor(org.drools.core.spi.AcceptsReadAccessor) Entry(java.util.Map.Entry) ObjectInput(java.io.ObjectInput) BaseClassFieldReader(org.drools.core.base.BaseClassFieldReader) ReadAccessorSupplier(org.drools.core.base.ReadAccessorSupplier) Collections(java.util.Collections) ClassFieldInspector(org.drools.core.base.ClassFieldInspector) BaseClassFieldWriter(org.drools.core.base.BaseClassFieldWriter) BaseClassFieldReader(org.drools.core.base.BaseClassFieldReader) AccessorKey(org.drools.core.base.AccessorKey)

Example 2 with AccessorKey

use of org.drools.core.base.AccessorKey in project drools by kiegroup.

the class ClassFieldAccessorStore method getReader.

public synchronized ClassFieldReader getReader(final String className, String fieldName, final AcceptsReadAccessor target, final AccessorKey.AccessorType accessorType) {
    AccessorKey key = new AccessorKey(className, fieldName, accessorType);
    FieldLookupEntry entry = (FieldLookupEntry) this.lookup.get(key);
    boolean exists = entry != null;
    if (!exists) {
        entry = new FieldLookupEntry(new ClassFieldReader(className, fieldName));
    }
    if (this.eagerWire) {
        wire(entry.getClassFieldReader());
        ClassFieldReader reader = (ClassFieldReader) entry.getClassFieldReader();
        if (!reader.hasReadAccessor()) {
            return null;
        }
    }
    if (target != null) {
        target.setReadAccessor(entry.getClassFieldReader());
    }
    if (!exists) {
        // we delay the key writing as we only want to do it if the wiring was successful
        this.lookup.put(key, entry);
    }
    return (ClassFieldReader) entry.getClassFieldReader();
}
Also used : BaseClassFieldReader(org.drools.core.base.BaseClassFieldReader) AccessorKey(org.drools.core.base.AccessorKey)

Example 3 with AccessorKey

use of org.drools.core.base.AccessorKey in project drools by kiegroup.

the class ClassFieldAccessorStore method getMVELReader.

public InternalReadAccessor getMVELReader(final String pkgName, final String className, final String expr, final boolean typesafe, Class<?> returnType) {
    AccessorKey key = new AccessorKey(pkgName + className, expr, AccessorKey.AccessorType.FieldAccessor);
    FieldLookupEntry entry = (FieldLookupEntry) this.lookup.computeIfAbsent(key, k -> new FieldLookupEntry(getReadAcessor(className, expr, typesafe, returnType)));
    return entry.getClassFieldReader();
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) TypeDeclaration(org.drools.core.rule.TypeDeclaration) ObjectType(org.drools.core.spi.ObjectType) ObjectOutput(java.io.ObjectOutput) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) AccessorType(org.drools.core.base.AccessorKey.AccessorType) AccessorKey(org.drools.core.base.AccessorKey) Map(java.util.Map) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) FactField(org.kie.api.definition.type.FactField) Externalizable(java.io.Externalizable) Collection(java.util.Collection) WriteAccessor(org.drools.core.spi.WriteAccessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseClassFieldWriter(org.drools.core.base.BaseClassFieldWriter) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) ClassWireable(org.drools.core.spi.ClassWireable) IOException(java.io.IOException) Field(java.lang.reflect.Field) UncheckedIOException(java.io.UncheckedIOException) CoreComponentsBuilder(org.drools.core.base.CoreComponentsBuilder) AcceptsReadAccessor(org.drools.core.spi.AcceptsReadAccessor) Entry(java.util.Map.Entry) ObjectInput(java.io.ObjectInput) BaseClassFieldReader(org.drools.core.base.BaseClassFieldReader) ReadAccessorSupplier(org.drools.core.base.ReadAccessorSupplier) Collections(java.util.Collections) ClassFieldInspector(org.drools.core.base.ClassFieldInspector) AccessorKey(org.drools.core.base.AccessorKey)

Example 4 with AccessorKey

use of org.drools.core.base.AccessorKey in project drools by kiegroup.

the class ClassFieldAccessorStore method wireObjectType.

public ObjectType wireObjectType(ObjectType objectType, AcceptsClassObjectType target) {
    if (!(objectType instanceof ClassObjectType)) {
        return objectType;
    }
    AccessorKey key = new AccessorKey(objectType.getClassName(), objectType.isEvent() ? "$$DROOLS__isEvent__" : null, AccessorKey.AccessorType.ClassObjectType);
    ClassObjectTypeLookupEntry entry = (ClassObjectTypeLookupEntry) this.lookup.computeIfAbsent(key, k -> new ClassObjectTypeLookupEntry(cache.getClassObjectType((ClassObjectType) objectType, false)));
    if (target != null) {
        target.setClassObjectType(entry.getClassObjectType());
    }
    return entry.getClassObjectType();
}
Also used : ClassObjectType(org.drools.core.base.ClassObjectType) TypeDeclaration(org.drools.core.rule.TypeDeclaration) ObjectType(org.drools.core.spi.ObjectType) ObjectOutput(java.io.ObjectOutput) ClassFieldAccessorCache(org.drools.core.base.ClassFieldAccessorCache) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) AccessorType(org.drools.core.base.AccessorKey.AccessorType) AccessorKey(org.drools.core.base.AccessorKey) Map(java.util.Map) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) FactField(org.kie.api.definition.type.FactField) Externalizable(java.io.Externalizable) Collection(java.util.Collection) WriteAccessor(org.drools.core.spi.WriteAccessor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) BaseClassFieldWriter(org.drools.core.base.BaseClassFieldWriter) KnowledgeBuilderResult(org.kie.internal.builder.KnowledgeBuilderResult) ClassWireable(org.drools.core.spi.ClassWireable) IOException(java.io.IOException) Field(java.lang.reflect.Field) UncheckedIOException(java.io.UncheckedIOException) CoreComponentsBuilder(org.drools.core.base.CoreComponentsBuilder) AcceptsReadAccessor(org.drools.core.spi.AcceptsReadAccessor) Entry(java.util.Map.Entry) ObjectInput(java.io.ObjectInput) BaseClassFieldReader(org.drools.core.base.BaseClassFieldReader) ReadAccessorSupplier(org.drools.core.base.ReadAccessorSupplier) Collections(java.util.Collections) ClassFieldInspector(org.drools.core.base.ClassFieldInspector) ClassObjectType(org.drools.core.base.ClassObjectType) AcceptsClassObjectType(org.drools.core.spi.AcceptsClassObjectType) AccessorKey(org.drools.core.base.AccessorKey)

Aggregations

AccessorKey (org.drools.core.base.AccessorKey)4 BaseClassFieldReader (org.drools.core.base.BaseClassFieldReader)4 Externalizable (java.io.Externalizable)3 IOException (java.io.IOException)3 ObjectInput (java.io.ObjectInput)3 ObjectOutput (java.io.ObjectOutput)3 UncheckedIOException (java.io.UncheckedIOException)3 Field (java.lang.reflect.Field)3 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Map (java.util.Map)3 Entry (java.util.Map.Entry)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 AccessorType (org.drools.core.base.AccessorKey.AccessorType)3 BaseClassFieldWriter (org.drools.core.base.BaseClassFieldWriter)3 ClassFieldAccessorCache (org.drools.core.base.ClassFieldAccessorCache)3 ClassFieldInspector (org.drools.core.base.ClassFieldInspector)3 ClassObjectType (org.drools.core.base.ClassObjectType)3 CoreComponentsBuilder (org.drools.core.base.CoreComponentsBuilder)3 ReadAccessorSupplier (org.drools.core.base.ReadAccessorSupplier)3