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

juliac.generated.SCAPrimitiveIntentControllerImpl Maven / Gradle / Ivy

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

import java.lang.reflect.AnnotatedElement;
import org.ow2.frascati.tinfi.reflect.AnnotatedElementFilter;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import org.objectweb.fractal.julia.control.lifecycle.ChainedIllegalLifeCycleException;
import org.objectweb.fractal.juliac.runtime.ClassLoaderFcItf;
import org.objectweb.fractal.juliac.runtime.ClassLoaderItf;
import java.util.Collection;
import org.objectweb.fractal.api.Component;
import org.objectweb.fractal.julia.ComponentInterface;
import org.objectweb.fractal.julia.Controller;
import org.ow2.frascati.tinfi.reflect.Filter;
import org.objectweb.fractal.julia.loader.Generated;
import java.util.HashMap;
import org.objectweb.fractal.api.control.IllegalLifeCycleException;
import org.objectweb.fractal.julia.InitializationContext;
import org.objectweb.fractal.api.factory.InstantiationException;
import org.ow2.frascati.tinfi.control.intent.IntentHandler;
import org.objectweb.fractal.api.Interface;
import org.ow2.frascati.tinfi.control.intent.InterfaceFilter;
import org.ow2.frascati.tinfi.control.intent.InterfaceMethodFilter;
import org.objectweb.fractal.api.type.InterfaceType;
import org.objectweb.fractal.juliac.runtime.Juliac;
import org.objectweb.fractal.api.control.LifeCycleController;
import java.util.List;
import java.util.Map;
import java.lang.reflect.Method;
import org.objectweb.fractal.api.NoSuchInterfaceException;
import org.ow2.frascati.tinfi.control.intent.SCABasicIntentController;
import org.ow2.frascati.tinfi.control.intent.SCAIntentController;
import org.ow2.frascati.tinfi.TinfiComponentInterceptor;
import org.ow2.frascati.tinfi.TinfiRuntimeException;
import org.objectweb.fractal.api.Type;

/** 
 * @see org.objectweb.fractal.julia.BasicControllerMixin
 * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin
 * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin
 * @see org.objectweb.fractal.julia.UseComponentMixin
 * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin
 * @see org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin
 */
public class SCAPrimitiveIntentControllerImpl implements Controller , Generated , SCABasicIntentController , SCAIntentController {
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler)
     */
    public void addFcIntentHandler(IntentHandler handler) throws IllegalLifeCycleException {
        checkFcStopped();
        addFcIntentHandler$0(handler);
    }
    
    /** 
     * @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$2(final InitializationContext ic) throws InstantiationException {
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin#weaveableOptLC
     */
    public LifeCycleController weaveableOptLC;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler)
     */
    private void addFcIntentHandler$0(IntentHandler handler) {
        Map>  interceptors = getFcInterceptors();
        Collection>  tcis = interceptors.values();
        for (TinfiComponentInterceptor  tci : tcis) {
            tci.addIntentHandler(handler);
        }
    }
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#weaveableOptC
     */
    public Component weaveableOptC;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.Class,java.lang.String)
     */
    public  void addFcIntentHandler(IntentHandler handler, Class  annotcl, String value) throws IllegalLifeCycleException {
        checkFcStopped();
        addFcIntentHandler$0(handler ,annotcl ,value);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    public void initFcController(final InitializationContext ic) throws InstantiationException {
        weaveableOptLC = ((LifeCycleController)(ic.getOptionalInterface("lifecycle-controller")));
        initFcController$0(ic);
    }
    
    /** 
     * @see org.objectweb.fractal.julia.UseComponentMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$0(final InitializationContext ic) throws InstantiationException {
        weaveableC = ((Component)(ic.getInterface("component")));
        weaveableOptC = weaveableC;
        initFcController$1(ic);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin#removeFcHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler)
     */
    public void removeFcHandler(IntentHandler handler) throws IllegalLifeCycleException {
        checkFcStopped();
        removeFcHandler$0(handler);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#initFcController(org.objectweb.fractal.julia.InitializationContext)
     */
    private void initFcController$1(final InitializationContext ic) throws InstantiationException {
        cl = ((Class )(ic.content));
        initFcController$2(ic);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,org.ow2.frascati.tinfi.control.intent.InterfaceFilter)
     */
    public void addFcIntentHandler(IntentHandler handler, InterfaceFilter filter) {
        Object[] itfs = weaveableOptC.getFcInterfaces();
        for (Object o : itfs) {
            Interface itf = ((Interface)(o));
            boolean accept = filter.accept(itf);
            if (!accept) {
                continue;
            } 
            Object i = ((ComponentInterface)(itf)).getFcItfImpl();
            if (!(i instanceof TinfiComponentInterceptor )) {
                String name = itf.getFcItfName();
                String msg = (("Interface " + name) + " was expected to delegate to an object implementing") + " TinfiComponentInterceptor";
                throw new TinfiRuntimeException(msg);
            } 
            TinfiComponentInterceptor  tci = ((TinfiComponentInterceptor )(i));
            tci.addIntentHandler(handler);
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin#checkFcStopped()
     */
    private void checkFcStopped() throws IllegalLifeCycleException {
        if ((weaveableOptLC) != null) {
            String state = weaveableOptLC.getFcState();
            if (!(LifeCycleController.STOPPED.equals(state))) {
                throw new ChainedIllegalLifeCycleException(null , weaveableOptC , "The component is not stopped");
            } 
        } 
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#cl
     */
    private Class  cl;
    
    private void initFcController$3(InitializationContext ic) throws InstantiationException {
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.Class,java.lang.String)
     */
    private  void addFcIntentHandler$0(IntentHandler handler, Class  annotcl, String value) {
        List  methods = getFcMatchingMethods(annotcl ,value);
        for (Method method : methods) {
            TinfiComponentInterceptor  tci = getFcInterceptor(method);
            Method m = getFcItfMethod(method);
            try {
                tci.addIntentHandler(handler ,m);
            } catch (NoSuchMethodException e) {
                throw new TinfiRuntimeException(e);
            }
        }
    }
    
    private void addFcIntentHandler$1(IntentHandler handler) {
    }
    
    private  void addFcIntentHandler$1(IntentHandler handler, Class  annotcl, String value) {
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,org.ow2.frascati.tinfi.control.intent.InterfaceMethodFilter)
     */
    public void addFcIntentHandler(IntentHandler handler, InterfaceMethodFilter filter) {
        Object[] itfs = weaveableOptC.getFcInterfaces();
        for (Object o : itfs) {
            Interface itf = ((Interface)(o));
            Object i = ((ComponentInterface)(itf)).getFcItfImpl();
            if (!(i instanceof TinfiComponentInterceptor )) {
                String name = itf.getFcItfName();
                String msg = (("Interface " + name) + " was expected to delegate to an object implementing") + " TinfiComponentInterceptor";
                throw new TinfiRuntimeException(msg);
            } 
            TinfiComponentInterceptor  tci = ((TinfiComponentInterceptor )(i));
            Method[] methods = tci.getMethods();
            for (Method method : methods) {
                boolean accept = filter.accept(itf ,method);
                if (accept) {
                    try {
                        tci.addIntentHandler(handler ,method);
                    } catch (NoSuchMethodException nsme) {
                        throw new TinfiRuntimeException(nsme);
                    }
                } 
            }
        }
    }
    
    private void removeFcHandler$0(IntentHandler handler) {
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#getFcMatchingMethods(java.lang.Class,java.lang.String)
     */
    private  List  getFcMatchingMethods(Class  annotcl, String value) {
        List  ret = new ArrayList ();
        Method[] methods = org.ow2.frascati.tinfi.reflect.Util.getAllMethods(cl);
        Filter  filter = new AnnotatedElementFilter(annotcl);
        Method[] ms = org.ow2.frascati.tinfi.reflect.Filters.filter(methods ,filter);
        for (Method method : ms) {
            T annot = method.getAnnotation(annotcl);
            if (annot != null) {
                Class  cl = annot.getClass();
                try {
                    Method mvalue = cl.getMethod("value");
                    String[] values = null;
                    try {
                        values = ((String[])(mvalue.invoke(annot)));
                    } catch (Exception e) {
                        throw new TinfiRuntimeException(e);
                    }
                    for (String v : values) {
                        if (v.equals(value)) {
                            ret.add(method);
                        } 
                    }
                } catch (NoSuchMethodException e) {
                }
            } 
        }
        return ret;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.String)
     */
    public void addFcIntentHandler(IntentHandler handler, String name) throws NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        tci.addIntentHandler(handler);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#addFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.String,java.lang.reflect.Method)
     */
    public void addFcIntentHandler(IntentHandler handler, String name, Method method) throws NoSuchMethodException, NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        tci.addIntentHandler(handler ,method);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#getFcInterceptor(java.lang.reflect.Method)
     */
    private TinfiComponentInterceptor  getFcInterceptor(Method method) {
        if ((mtcis) == null) {
            initFcMaps();
        } 
        if (!(mtcis.containsKey(method))) {
            String msg = "No interceptor for component method: " + (method.toString());
            throw new TinfiRuntimeException(msg);
        } 
        TinfiComponentInterceptor  tci = mtcis.get(method);
        return tci;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#listFcIntentHandler(java.lang.String)
     */
    public List  listFcIntentHandler(String name) throws NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        List  handlers = tci.listIntentHandler();
        return handlers;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#getFcItfMethod(java.lang.reflect.Method)
     */
    private Method getFcItfMethod(Method method) {
        if ((mms) == null) {
            initFcMaps();
        } 
        if (!(mms.containsKey(method))) {
            String msg = "No interface method for component method: " + (method.toString());
            throw new TinfiRuntimeException(msg);
        } 
        Method m = mms.get(method);
        return m;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#mtcis
     */
    private Map>  mtcis;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#mms
     */
    private Map  mms;
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#listFcIntentHandler(java.lang.String,java.lang.reflect.Method)
     */
    public List  listFcIntentHandler(String name, Method method) throws NoSuchMethodException, NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        List  handlers = tci.listIntentHandler(method);
        return handlers;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#initFcMaps()
     */
    private void initFcMaps() {
        mtcis = new HashMap> ();
        mms = new HashMap ();
        Method[] methods = cl.getMethods();
        Object[] itfs = weaveableOptC.getFcInterfaces();
        for (Object o : itfs) {
            Interface itf = ((Interface)(o));
            String name = itf.getFcItfName();
            if ((name.endsWith("-controller")) || (name.equals("component"))) {
                continue;
            } 
            Object i = ((ComponentInterface)(itf)).getFcItfImpl();
            TinfiComponentInterceptor  tci = ((TinfiComponentInterceptor )(i));
            InterfaceType it = ((InterfaceType)(itf.getFcItfType()));
            String signature = it.getFcItfSignature();
            Class  business = SCAPrimitiveIntentControllerImpl.loadFcClass(signature);
            Method[] ms = business.getMethods();
            for (Method method : methods) {
                for (Method m : ms) {
                    if (SCAPrimitiveIntentControllerImpl.areSame(m ,method)) {
                        mtcis.put(method ,tci);
                        mms.put(method ,m);
                    } 
                }
            }
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#removeFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler)
     */
    public void removeFcIntentHandler(IntentHandler handler) {
        Map>  interceptors = getFcInterceptors();
        Collection>  tcis = interceptors.values();
        for (TinfiComponentInterceptor  tci : tcis) {
            tci.removeIntentHandler(handler);
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#removeFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.String)
     */
    public void removeFcIntentHandler(IntentHandler handler, String name) throws NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        tci.removeIntentHandler(handler);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#loadFcClass(java.lang.String)
     */
    private static Class  loadFcClass(String name) {
        Component boot = new Juliac().newFcInstance();
        ClassLoaderItf loader = null;
        try {
            loader = ((ClassLoaderItf)(boot.getFcInterface(ClassLoaderFcItf.NAME)));
        } catch (NoSuchInterfaceException nsie) {
            throw new RuntimeException(nsie);
        }
        try {
            Class  cl = loader.loadClass(name);
            return cl;
        } catch (ClassNotFoundException cnfe) {
            throw new TinfiRuntimeException(cnfe);
        }
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#removeFcIntentHandler(org.ow2.frascati.tinfi.control.intent.IntentHandler,java.lang.String,java.lang.reflect.Method)
     */
    public void removeFcIntentHandler(IntentHandler handler, String name, Method method) throws NoSuchMethodException, NoSuchInterfaceException {
        Map>  interceptors = getFcInterceptors();
        if (!(interceptors.containsKey(name))) {
            throw new NoSuchInterfaceException(name);
        } 
        TinfiComponentInterceptor  tci = interceptors.get(name);
        tci.removeIntentHandler(handler ,method);
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin#areSame(java.lang.reflect.Method,java.lang.reflect.Method)
     */
    private static boolean areSame(Method m1, Method m2) {
        String name1 = m1.getName();
        String name2 = m2.getName();
        if (!(name1.equals(name2))) {
            return false;
        } 
        Class [] ptypes1 = m1.getParameterTypes();
        Class [] ptypes2 = m2.getParameterTypes();
        if ((ptypes1.length) != (ptypes2.length)) {
            return false;
        } 
        for (int i = 0 ; i < (ptypes1.length) ; i++) {
            Class  ptype1 = ptypes1[i];
            Class  ptype2 = ptypes2[i];
            if (!(ptype1.equals(ptype2))) {
                return false;
            } 
        }
        return true;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#getFcInterceptors()
     */
    private Map>  getFcInterceptors() {
        if ((interceptors) != null) {
            return interceptors;
        } 
        interceptors = new HashMap> ();
        Object[] itfs = weaveableOptC.getFcInterfaces();
        for (Object o : itfs) {
            Interface itf = ((Interface)(o));
            String name = itf.getFcItfName();
            if ((name.endsWith("-controller")) || (name.equals("component"))) {
                continue;
            } 
            Object i = ((ComponentInterface)(itf)).getFcItfImpl();
            if (!(i instanceof TinfiComponentInterceptor )) {
                String msg = (("Interface " + name) + " was expected to delegate to an object implementing") + " TinfiComponentInterceptor";
                throw new TinfiRuntimeException(msg);
            } 
            TinfiComponentInterceptor  tci = ((TinfiComponentInterceptor )(i));
            interceptors.put(name ,tci);
        }
        return interceptors;
    }
    
    /** 
     * @see org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin#interceptors
     */
    private Map>  interceptors;
    
    public String getFcGeneratorParameters() {
        return "(org.objectweb.fractal.juliac.spoon.MixinClassGenerator juliac.generated.SCAPrimitiveIntentControllerImpl org.objectweb.fractal.julia.BasicControllerMixin org.ow2.frascati.tinfi.control.intent.SCAIntentControllerMixin org.ow2.frascati.tinfi.control.intent.SCABasicIntentControllerMixin org.objectweb.fractal.julia.UseComponentMixin org.objectweb.fractal.julia.control.lifecycle.UseLifeCycleControllerMixin org.ow2.frascati.tinfi.control.intent.LifeCycleIntentMixin)";
    }
    
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy