All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.weld.tck.CreationalContextsImpl Maven / Gradle / Ivy

There is a newer version: 6.0.0.CR1
Show newest version
package org.jboss.weld.tck;

import jakarta.enterprise.context.spi.Contextual;

import org.jboss.cdi.tck.spi.CreationalContexts;
import org.jboss.weld.contexts.CreationalContextImpl;

public class CreationalContextsImpl implements CreationalContexts {
    @Override
    public  Inspectable create(Contextual contextual) {
        return new InspectableCreationalContext<>(contextual);
    }

    static class InspectableCreationalContext extends CreationalContextImpl implements Inspectable {
        private Object lastBeanPushed = null;
        private boolean pushCalled = false;
        private boolean releaseCalled = false;

        public InspectableCreationalContext(Contextual contextual) {
            super(contextual);
        }

        public void push(T incompleteInstance) {
            pushCalled = true;
            lastBeanPushed = incompleteInstance;
            super.push(incompleteInstance);
        }

        public Object getLastBeanPushed() {
            return lastBeanPushed;
        }

        public boolean isPushCalled() {
            return pushCalled;
        }

        public boolean isReleaseCalled() {
            return releaseCalled;
        }

        /**
         * We need to override this method because internally, Weld uses this enhanced method to release CCs so long
         * as the CC is instance of {@link org.jboss.weld.contexts.WeldCreationalContext} which will hold true for
         * this impl as well.
         */
        public void release(Contextual contextual, T instance) {
            releaseCalled = true;
            super.release(contextual, instance);
        }

        public void release() {
            releaseCalled = true;
            super.release();
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy