Search in sources :

Example 1 with KieComponentFactory

use of org.drools.core.reteoo.KieComponentFactory in project drools by kiegroup.

the class AbstractTraitFactory method buildProxyClass.

protected Class<T> buildProxyClass(String key, K core, Class<?> trait) {
    Class coreKlass = core.getClass();
    // get the trait classDef
    ClassDefinition tdef = getTraitRegistry().getTrait(trait.getName());
    ClassDefinition cdef = getTraitRegistry().getTraitable(coreKlass.getName());
    if (tdef == null) {
        if (trait.getAnnotation(Trait.class) != null) {
            try {
                if (Thing.class.isAssignableFrom(trait)) {
                    tdef = buildClassDefinition(trait, null);
                } else {
                    throw new RuntimeException("Unable to create definition for class " + trait + " : trait interfaces should extend " + Thing.class.getName() + " or be DECLARED as traits explicitly");
                }
            } catch (IOException e) {
                throw new RuntimeException("Unable to create definition for class " + trait + " : " + e.getMessage());
            }
            getTraitRegistry().addTrait(tdef);
        } else {
            throw new RuntimeException("Unable to find Trait definition for class " + trait.getName() + ". It should have been DECLARED as a trait");
        }
    }
    if (cdef == null) {
        if (core.getClass().getAnnotation(Traitable.class) != null) {
            try {
                cdef = buildClassDefinition(core.getClass(), core.getClass());
            } catch (IOException e) {
                throw new RuntimeException("Unable to create definition for class " + coreKlass.getName() + " : " + e.getMessage());
            }
            getTraitRegistry().addTraitable(cdef);
        } else {
            throw new RuntimeException("Unable to find Core class definition for class " + coreKlass.getName() + ". It should have been DECLARED as a trait");
        }
    }
    String proxyName = getProxyName(tdef, cdef);
    String wrapperName = getPropertyWrapperName(tdef, cdef);
    KieComponentFactory rcf = getComponentFactory();
    TraitPropertyWrapperClassBuilder propWrapperBuilder = (TraitPropertyWrapperClassBuilder) rcf.getClassBuilderFactory().getPropertyWrapperBuilder();
    propWrapperBuilder.init(tdef, getTraitRegistry());
    try {
        byte[] propWrapper = propWrapperBuilder.buildClass(cdef, getRootClassLoader());
        registerAndLoadTypeDefinition(wrapperName, propWrapper);
    } catch (Exception e) {
        e.printStackTrace();
    }
    TraitProxyClassBuilder proxyBuilder = (TraitProxyClassBuilder) rcf.getClassBuilderFactory().getTraitProxyBuilder();
    proxyBuilder.init(tdef, rcf.getBaseTraitProxyClass(), getTraitRegistry());
    try {
        byte[] proxy = proxyBuilder.buildClass(cdef, getRootClassLoader());
        registerAndLoadTypeDefinition(proxyName, proxy);
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        BitSet mask = getTraitRegistry().getFieldMask(trait.getName(), cdef.getDefinedClass().getName());
        Class<T> wrapperClass = (Class<T>) getRootClassLoader().loadClass(wrapperName);
        Class<T> proxyClass = (Class<T>) getRootClassLoader().loadClass(proxyName);
        return proxyClass;
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}
Also used : BitSet(java.util.BitSet) IOException(java.io.IOException) ClassDefinition(org.drools.core.factmodel.ClassDefinition) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) KieComponentFactory(org.drools.core.reteoo.KieComponentFactory)

Example 2 with KieComponentFactory

use of org.drools.core.reteoo.KieComponentFactory in project drools by kiegroup.

the class TraitFactory method setMode.

public static void setMode(VirtualPropertyMode newMode, KieBase kBase) {
    KieComponentFactory rcf = ((InternalKnowledgeBase) kBase).getConfiguration().getComponentFactory();
    setMode(newMode, rcf);
}
Also used : KieComponentFactory(org.drools.core.reteoo.KieComponentFactory)

Example 3 with KieComponentFactory

use of org.drools.core.reteoo.KieComponentFactory in project drools by kiegroup.

the class RuleBaseConfiguration method init.

private void init(Properties properties) {
    this.componentFactory = new KieComponentFactory();
    this.immutable = false;
    this.chainedProperties = ChainedProperties.getChainedProperties(this.classLoader);
    if (properties != null) {
        this.chainedProperties.addProperties(properties);
    }
    setRemoveIdentities(Boolean.valueOf(this.chainedProperties.getProperty("drools.removeIdentities", "false")).booleanValue());
    setShareAlphaNodes(Boolean.valueOf(this.chainedProperties.getProperty(ShareAlphaNodesOption.PROPERTY_NAME, "true")).booleanValue());
    setShareBetaNodes(Boolean.valueOf(this.chainedProperties.getProperty(ShareBetaNodesOption.PROPERTY_NAME, "true")).booleanValue());
    setPermGenThreshold(Integer.parseInt(this.chainedProperties.getProperty(PermGenThresholdOption.PROPERTY_NAME, "" + PermGenThresholdOption.DEFAULT_VALUE)));
    setJittingThreshold(Integer.parseInt(this.chainedProperties.getProperty(ConstraintJittingThresholdOption.PROPERTY_NAME, "" + ConstraintJittingThresholdOption.DEFAULT_VALUE)));
    setAlphaNodeHashingThreshold(Integer.parseInt(this.chainedProperties.getProperty(AlphaThresholdOption.PROPERTY_NAME, "3")));
    setCompositeKeyDepth(Integer.parseInt(this.chainedProperties.getProperty(CompositeKeyDepthOption.PROPERTY_NAME, "3")));
    setIndexLeftBetaMemory(Boolean.valueOf(this.chainedProperties.getProperty(IndexLeftBetaMemoryOption.PROPERTY_NAME, "true")).booleanValue());
    setIndexRightBetaMemory(Boolean.valueOf(this.chainedProperties.getProperty(IndexRightBetaMemoryOption.PROPERTY_NAME, "true")).booleanValue());
    setIndexPrecedenceOption(IndexPrecedenceOption.determineIndexPrecedence(this.chainedProperties.getProperty(IndexPrecedenceOption.PROPERTY_NAME, "equality")));
    setAssertBehaviour(AssertBehaviour.determineAssertBehaviour(this.chainedProperties.getProperty(EqualityBehaviorOption.PROPERTY_NAME, "identity")));
    setConsequenceExceptionHandler(this.chainedProperties.getProperty(ConsequenceExceptionHandlerOption.PROPERTY_NAME, "org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler"));
    setRuleBaseUpdateHandler(this.chainedProperties.getProperty("drools.ruleBaseUpdateHandler", ""));
    setSequentialAgenda(SequentialAgenda.determineSequentialAgenda(this.chainedProperties.getProperty(SequentialAgendaOption.PROPERTY_NAME, "sequential")));
    setSequential(Boolean.valueOf(this.chainedProperties.getProperty(SequentialOption.PROPERTY_NAME, "false")).booleanValue());
    setConflictResolver(determineConflictResolver(this.chainedProperties.getProperty("drools.conflictResolver", "org.drools.core.conflict.DepthConflictResolver")));
    setAdvancedProcessRuleIntegration(Boolean.valueOf(this.chainedProperties.getProperty("drools.advancedProcessRuleIntegration", "false")).booleanValue());
    setMultithreadEvaluation(Boolean.valueOf(this.chainedProperties.getProperty(MultithreadEvaluationOption.PROPERTY_NAME, "false")).booleanValue());
    setMaxThreads(Integer.parseInt(this.chainedProperties.getProperty(MaxThreadsOption.PROPERTY_NAME, "3")));
    setEventProcessingMode(EventProcessingOption.determineEventProcessingMode(this.chainedProperties.getProperty(EventProcessingOption.PROPERTY_NAME, "cloud")));
    setMBeansEnabled(MBeansOption.isEnabled(this.chainedProperties.getProperty(MBeansOption.PROPERTY_NAME, "disabled")));
    setClassLoaderCacheEnabled(Boolean.valueOf(this.chainedProperties.getProperty(ClassLoaderCacheOption.PROPERTY_NAME, "true")));
    setSessionCacheOption(SessionCacheOption.determineOption(this.chainedProperties.getProperty(SessionCacheOption.PROPERTY_NAME, "none")));
    setDeclarativeAgendaEnabled(Boolean.valueOf(this.chainedProperties.getProperty(DeclarativeAgendaOption.PROPERTY_NAME, "false")));
}
Also used : KieComponentFactory(org.drools.core.reteoo.KieComponentFactory)

Aggregations

KieComponentFactory (org.drools.core.reteoo.KieComponentFactory)3 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 BitSet (java.util.BitSet)1 ClassDefinition (org.drools.core.factmodel.ClassDefinition)1