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

juliac.generated.SCAContentControllerImpl Maven / Gradle / Ivy

There is a newer version: 2.7
Show newest version
package juliac.generated;

import java.lang.annotation.Annotation;
import org.objectweb.fractal.julia.factory.ChainedInstantiationException;
import org.objectweb.fractal.api.Component;
import org.ow2.frascati.tinfi.control.content.scope.CompositeScopeManager;
import java.lang.reflect.Constructor;
import org.ow2.frascati.tinfi.control.content.ContentClassMetaData;
import org.ow2.frascati.tinfi.control.content.ContentInstantiationException;
import org.objectweb.fractal.julia.Controller;
import org.ow2.frascati.tinfi.control.content.scope.ConversationScopeManager;
import org.objectweb.fractal.julia.loader.Generated;
import java.util.HashMap;
import org.ow2.frascati.tinfi.control.content.IllegalContentClassMetaData;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.julia.InitializationContext;
import org.ow2.frascati.tinfi.control.content.InjectionPoint;
import org.ow2.frascati.tinfi.control.content.InjectionPointMap;
import org.objectweb.fractal.api.factory.InstantiationException;
import java.lang.reflect.InvocationTargetException;
import org.objectweb.fractal.api.control.LifeCycleController;
import java.util.Map;
import org.objectweb.fractal.api.control.NameController;
import org.osoa.sca.annotations.Property;
import org.ow2.frascati.tinfi.control.component.ReconfigurableComponentContext;
import org.osoa.sca.RequestContext;
import org.ow2.frascati.tinfi.control.content.scope.RequestScopeManager;
import org.ow2.frascati.tinfi.control.content.SCAContentController;
import org.ow2.frascati.tinfi.control.property.SCAPropertyController;
import org.ow2.frascati.tinfi.control.content.scope.ScopeManager;
import java.util.Set;
import org.ow2.frascati.tinfi.control.content.scope.StatelessScopeManager;
import org.ow2.frascati.tinfi.TinfiRuntimeException;

/** 
 * @see org.objectweb.fractal.julia.BasicControllerMixin
 * @see org.objectweb.fractal.julia.UseComponentMixin
 * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin
 * @see org.objectweb.fractal.julia.control.name.UseNameControllerMixin
 * @see org.ow2.frascati.tinfi.control.property.UseSCAPropertyControllerMixin
 * @see org.ow2.frascati.tinfi.control.component.UseComponentContextMixin
 * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin
 */
public class SCAContentControllerImpl implements Controller , Generated , SCAContentController {
    /** 
     * @see org.ow2.frascati.tinfi.control.property.UseSCAPropertyControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$1(final InitializationContext ic) throws InstantiationException {
        weaveableSCAPC = ((SCAPropertyController)(ic.interfaces.get(SCAPropertyController.NAME)));
        initFcController$2(ic);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.component.UseComponentContextMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$0(final InitializationContext ic) throws InstantiationException {
        weaveableCompCtx = ((ReconfigurableComponentContext)(ic.interfaces.get(ReconfigurableComponentContext.NAME)));
        initFcController$1(ic);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#weaveableC
     */
    public Component weaveableC;
    
    /** 
     * @see org.objectweb.fractal.julia.BasicControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$5(final InitializationContext ic) throws InstantiationException {
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.name.UseNameControllerMixin#weaveableOptNC
     */
    public NameController weaveableOptNC;
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin#weaveableOptLC
     */
    public LifeCycleController weaveableOptLC;
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#weaveableOptC
     */
    public Component weaveableOptC;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.property.UseSCAPropertyControllerMixin#weaveableSCAPC
     */
    @SuppressWarnings(value = "unused")
    private SCAPropertyController weaveableSCAPC;
    
    /** 
     * @see org.objectweb.fractal.julia.control.name.UseNameControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$2(final InitializationContext ic) throws InstantiationException {
        weaveableOptNC = ((NameController)(ic.getOptionalInterface("name-controller")));
        initFcController$3(ic);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$3(final InitializationContext ic) throws InstantiationException {
        weaveableOptLC = ((LifeCycleController)(ic.getOptionalInterface("lifecycle-controller")));
        initFcController$4(ic);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.component.UseComponentContextMixin#weaveableCompCtx
     */
    @SuppressWarnings(value = "unused")
    private ReconfigurableComponentContext weaveableCompCtx;
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$4(final InitializationContext ic) throws InstantiationException {
        weaveableC = ((Component)(ic.getInterface("component")));
        weaveableOptC = weaveableC;
        initFcController$5(ic);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#ccmd
     */
    private ContentClassMetaData ccmd;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#sm
     */
    private ScopeManager sm;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    public void initFcController(final InitializationContext ic) throws InstantiationException {
        initFcController$0(ic);
        Class  c = ((Class )(ic.content));
        try {
            innerSetFcContentClassName(c);
        } catch (IllegalContentClassMetaData e) {
            throw new ChainedInstantiationException(e , null , e.getMessage());
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#innerSetFcContentClassName(java.lang.Class)
     */
    private synchronized void innerSetFcContentClassName(Class  c) throws IllegalContentClassMetaData {
        ccmd = ContentClassMetaData.get(c);
        if (((ccmd.scope) == null) || (ccmd.scope.value().toUpperCase().equals("STATELESS"))) {
            sm = new StatelessScopeManager(weaveableC , weaveableSCAPC , weaveableCompCtx , weaveableOptNC , ccmd);
        } else if (ccmd.scope.value().toUpperCase().equals("REQUEST")) {
            sm = new RequestScopeManager(weaveableC , weaveableSCAPC , weaveableCompCtx , weaveableOptNC , ccmd);
        } else if (ccmd.scope.value().toUpperCase().equals("COMPOSITE")) {
            sm = new CompositeScopeManager(weaveableC , weaveableSCAPC , weaveableCompCtx , weaveableOptNC , ccmd);
        } else if (ccmd.scope.value().toUpperCase().equals("CONVERSATION")) {
            sm = new ConversationScopeManager(weaveableC , weaveableSCAPC , weaveableCompCtx , weaveableOptNC , ccmd);
        } else {
            String msg = "Unsupported scope: " + (ccmd.scope.value());
            throw new IllegalContentClassMetaData(msg);
        }
        props = new HashMap> ();
        InjectionPointMap  ipm = ccmd.props;
        Set  ipnames = ipm.keySet();
        for (String ipname : ipnames) {
            InjectionPoint  ip = ipm.get(ipname);
            Class  type = ip.getType();
            props.put(ipname ,type);
        }
        Constructor  ctr = ccmd.constructorAnnotatedElement;
        if (ctr != null) {
            Class [] ptypes = ctr.getParameterTypes();
            org.osoa.sca.annotations.Constructor annot = ctr.getAnnotation(org.osoa.sca.annotations.Constructor.class);
            String[] values = annot.value();
            if (((values.length) > 1) || ((values[0].length()) != 0)) {
                if ((values.length) != (ptypes.length)) {
                    String msg = ("Annotation @Constructor and " + (ctr.toString())) + " should declare the same number of parameters";
                    throw new IllegalContentClassMetaData(msg);
                } 
                for (int i = 0 ; i < (values.length) ; i++) {
                    String value = values[i];
                    Class  ptype = ptypes[i];
                    props.put(value ,ptype);
                }
            } 
            Annotation[][] psannots = ctr.getParameterAnnotations();
            for (int i = 0 ; i < (ptypes.length) ; i++) {
                Class  ptype = ptypes[i];
                Annotation[] pannots = psannots[i];
                for (Annotation pannot : pannots) {
                    if (pannot instanceof Property) {
                        Property prop = ((Property)(pannot));
                        String propname = prop.name();
                        props.put(propname ,ptype);
                    } 
                }
            }
        } 
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#props
     */
    private Map>  props = new HashMap> ();
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#setFcContentClass(java.lang.Class)
     */
    public void setFcContentClass(Class  c) throws IllegalLifeCycleException, ContentInstantiationException {
        String state = weaveableOptLC.getFcState();
        if (!(state.equals(LifeCycleController.STOPPED))) {
            String msg = "Component should be stopped";
            throw new IllegalLifeCycleException(msg);
        } 
        try {
            innerSetFcContentClassName(c);
        } catch (IllegalContentClassMetaData e) {
            throw new ContentInstantiationException(e);
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#releaseFcContent(java.lang.Object,boolean)
     */
    public void releaseFcContent(Object content, boolean isEndMethod) {
        sm.releaseFcContent(content ,isEndMethod);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#pushRequestContext(org.osoa.sca.RequestContext)
     */
    public void pushRequestContext(RequestContext rc) {
        sm.pushRequestContext(rc);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#popRequestContext()
     */
    public void popRequestContext() {
        sm.popRequestContext();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#peekRequestContext()
     */
    public RequestContext peekRequestContext() {
        return sm.peekRequestContext();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#getFcContent()
     */
    public Object getFcContent() throws ContentInstantiationException {
        return sm.getFcContent();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#eagerInit()
     */
    public void eagerInit() throws ContentInstantiationException {
        if ((ccmd.eagerinit) == null) {
            return ;
        } 
        if (!((sm) instanceof CompositeScopeManager)) {
            String msg = ("Eager initialization is meaningless in scopes other than COMPOSITE (scope is: " + (ccmd.scope.value())) + ")";
            throw new ContentInstantiationException(msg);
        } 
        sm.getFcContent();
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#eagerDestroy()
     */
    public void eagerDestroy() throws ContentInstantiationException {
        if ((ccmd.eagerDestroyMethod) == null) {
            return ;
        } 
        if (!((sm) instanceof CompositeScopeManager)) {
            String msg = ("Eager destruction is meaningless in scopes other than COMPOSITE (scope is: " + (ccmd.scope.value())) + ")";
            throw new ContentInstantiationException(msg);
        } 
        Object content = sm.getFcContent();
        try {
            ccmd.eagerDestroyMethod.invoke(content);
        } catch (IllegalAccessException e) {
            throw new ContentInstantiationException(e);
        } catch (InvocationTargetException e) {
            throw new ContentInstantiationException(e);
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#containsPropertyName(java.lang.String)
     */
    public boolean containsPropertyName(String name) {
        boolean b = props.containsKey(name);
        return b;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#getPropertyNames()
     */
    public String[] getPropertyNames() {
        Set  propnames = props.keySet();
        String[] names = propnames.toArray(new String[propnames.size()]);
        return names;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#getPropertyType(java.lang.String)
     */
    public Class  getPropertyType(String name) {
        Class  type = props.get(name);
        return type;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin#setPropertyValue(java.lang.String,java.lang.Object)
     */
    public void setPropertyValue(String name, Object value) {
        InjectionPoint  ip = ccmd.props.get(name);
        if (ip == null) {
            return ;
        } 
        Object[] contents = sm.getFcCurrentContents();
        for (Object content : contents) {
            try {
                ip.set(content ,value);
            } catch (IllegalAccessException e) {
                throw new TinfiRuntimeException(e);
            } catch (InvocationTargetException e) {
                throw new TinfiRuntimeException(e);
            }
        }
    }
    
    private void initFcController$6(InitializationContext ic) throws InstantiationException {
    }
    
    public String getFcGeneratorParameters() {
        return "(org.objectweb.fractal.juliac.spoon.MixinClassGenerator juliac.generated.SCAContentControllerImpl org.objectweb.fractal.julia.BasicControllerMixin org.objectweb.fractal.julia.UseComponentMixin org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin org.objectweb.fractal.julia.control.name.UseNameControllerMixin org.ow2.frascati.tinfi.control.property.UseSCAPropertyControllerMixin org.ow2.frascati.tinfi.control.component.UseComponentContextMixin org.ow2.frascati.tinfi.control.content.SCAContentControllerMixin)";
    }
    
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy