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

org.jboss.weld.injection.WeldInjectionPoint Maven / Gradle / Ivy

There is a newer version: 6.0.0.Beta4
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2008, Red Hat, Inc., and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.weld.injection;

import org.jboss.weld.Container;
import org.jboss.weld.bootstrap.api.Service;
import org.jboss.weld.introspector.WeldAnnotated;
import org.jboss.weld.introspector.WeldClass;
import org.jboss.weld.manager.api.WeldManager;
import org.jboss.weld.resources.ClassTransformer;
import org.jboss.weld.serialization.spi.ContextualStore;

import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.InjectionPoint;
import java.io.Serializable;

public interface WeldInjectionPoint extends InjectionPoint, WeldAnnotated {

    abstract static class WeldInjectionPointSerializationProxy implements Serializable {

        private static final long serialVersionUID = -5488095196637387378L;

        private final String declaringBeanId;
        private final Class declaringClass;
        private final WeldManager beanManager;

        public WeldInjectionPointSerializationProxy(WeldInjectionPoint injectionPoint, WeldManager beanManager) {
            this.beanManager = beanManager;
            this.declaringBeanId =
                    injectionPoint.getBean() == null ? null : getService(ContextualStore.class).putIfAbsent(injectionPoint.getBean());
            this.declaringClass = injectionPoint.getDeclaringType().getJavaClass();
        }

        protected Bean getDeclaringBean() {
            return declaringBeanId == null ? null : getService(ContextualStore.class)., T>getContextual(declaringBeanId);
        }

        protected WeldClass getDeclaringWeldClass() {
            return getService(ClassTransformer.class).loadClass(declaringClass);
        }

        protected String getDeclaringBeanId() {
            return declaringBeanId;
        }

        protected WeldManager getBeanManager() {
            return beanManager;
        }

        protected  E getService(Class serviceClass) {
            return beanManager.getServices().get(serviceClass);
        }

    }

    WeldClass getDeclaringType();

    /**
     * Injects an instance
     *
     * @param declaringInstance The instance to inject into
     * @param value             The value to inject
     */
    void inject(Object declaringInstance, Object value);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy