Search in sources :

Example 6 with Plugin

use of com.ramussoft.common.Plugin in project ramus by Vitaliy-Yakovchuk.

the class AbstractDatabase method createPluginFactory.

protected PluginFactory createPluginFactory(List<PluginProvider> list) {
    ArrayList<Plugin> plugins = new ArrayList<Plugin>();
    for (PluginProvider suit : list) {
        plugins.addAll(suit.getPlugins());
    }
    PluginFactory factory = new PluginFactory(plugins);
    return factory;
}
Also used : ArrayList(java.util.ArrayList) PluginProvider(com.ramussoft.common.PluginProvider) PluginFactory(com.ramussoft.common.PluginFactory) Plugin(com.ramussoft.common.Plugin)

Example 7 with Plugin

use of com.ramussoft.common.Plugin in project ramus by Vitaliy-Yakovchuk.

the class TcpLightClient method getEngine.

@SuppressWarnings("rawtypes")
@Override
protected Engine getEngine(PluginFactory factory, PersistentFactory persistentFactory) {
    tcpClientEngine = new TcpClientEngine((EngineInvocker) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EngineInvocker.class }, new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            return connection.invoke(method.getName(), args);
        }
    }), connection);
    List<Class> interfaces = new ArrayList<Class>();
    interfaces.add(Engine.class);
    interfaces.add(Journaled.class);
    interfaces.add(ILog.class);
    for (Plugin plugin : factory.getPlugins()) if (plugin.getFunctionalInterface() != null)
        interfaces.add(plugin.getFunctionalInterface());
    final Engine engine1 = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), tcpClientEngine);
    final Engine cachedEngine = createCachedEngine(engine1);
    final Hashtable<Method, Object> hashtable = new Hashtable<Method, Object>();
    for (Method m : Engine.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    for (Method m : Cached.class.getMethods()) {
        hashtable.put(m, cachedEngine);
    }
    interfaces.add(Cached.class);
    Engine engine = (Engine) Proxy.newProxyInstance(getClass().getClassLoader(), interfaces.toArray(new Class[interfaces.size()]), new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            Object o = hashtable.get(method);
            if (o == null)
                return tcpClientEngine.invoke(proxy, method, args);
            return method.invoke(o, args);
        }
    });
    tcpClientEngine.setEngine(engine);
    for (Plugin plugin : factory.getPlugins()) plugin.init(engine, rules);
    return engine;
}
Also used : EngineInvocker(com.ramussoft.net.common.tcp.EngineInvocker) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) InvocationHandler(java.lang.reflect.InvocationHandler) Engine(com.ramussoft.common.Engine) CachedEngine(com.ramussoft.common.cached.CachedEngine) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) LogPlugin(com.ramussoft.client.log.LogPlugin) Plugin(com.ramussoft.common.Plugin) UndoRedoPlugin(com.ramussoft.gui.common.UndoRedoPlugin) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 8 with Plugin

use of com.ramussoft.common.Plugin in project ramus by Vitaliy-Yakovchuk.

the class SuperEngineFactory method createTransactionalEngine.

@SuppressWarnings("unchecked")
public static Object createTransactionalEngine(Engine engine, Journaled journal) {
    String[] classes = engine.getAllImplementationClasseNames();
    Class[] clazzes = new Class[classes.length];
    for (int i = 0; i < classes.length; i++) {
        try {
            clazzes[i] = Class.forName(classes[i]);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    SuperInvoker invoker = null;
    if (engine instanceof AbstractJournaledEngine) {
        AbstractJournaledEngine abstractJournaledEngine = (AbstractJournaledEngine) engine;
        invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
    } else if (engine instanceof CachedEngine) {
        Object[] objects = new Object[classes.length];
        Engine engine2 = ((CachedEngine) engine).getSource();
        AbstractJournaledEngine abstractJournaledEngine = null;
        if (engine2 instanceof AbstractJournaledEngine) {
            abstractJournaledEngine = (AbstractJournaledEngine) engine2;
            invoker = abstractJournaledEngine.createSuperInvoker(classes, clazzes, journal);
        }
        for (int i = 0; i < objects.length; i++) {
            String className = classes[i];
            if (className.equals(Engine.class.getName())) {
                objects[i] = engine;
            } else if (className.equals(Journaled.class.getName())) {
                objects[i] = new UserTransactional(journal);
            } else {
                for (Plugin plugin : abstractJournaledEngine.pluginFactory.getPlugins()) {
                    Class class1 = plugin.getFunctionalInterface();
                    if (class1 != null)
                        if (class1.equals(clazzes[i])) {
                            objects[i] = plugin.createFunctionalInterfaceObject(engine, engine.getDeligate());
                        }
                }
            }
        }
        invoker = new SuperInvoker(classes, clazzes, objects);
    }
    return Proxy.newProxyInstance(SuperEngineFactory.class.getClassLoader(), clazzes, new Caller(invoker));
}
Also used : CachedEngine(com.ramussoft.common.cached.CachedEngine) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin)

Example 9 with Plugin

use of com.ramussoft.common.Plugin in project ramus by Vitaliy-Yakovchuk.

the class Navigator method createPluginFactory.

private PluginFactory createPluginFactory(List<PluginProvider> list) {
    ArrayList<Plugin> plugins = new ArrayList<Plugin>();
    for (PluginProvider suit : list) {
        plugins.addAll(suit.getPlugins());
    }
    PluginFactory factory = new PluginFactory(plugins);
    return factory;
}
Also used : ArrayList(java.util.ArrayList) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) ReportPluginProvider(com.ramussoft.report.ReportPluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) NDataPluginFactory(com.ramussoft.idef0.NDataPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) DataPlugin(com.ramussoft.pb.DataPlugin) Plugin(com.ramussoft.common.Plugin)

Example 10 with Plugin

use of com.ramussoft.common.Plugin in project ramus by Vitaliy-Yakovchuk.

the class EngineFactory method createJournaledEngine.

public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
    try {
        JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
        suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        suits.add(new IDEF0PluginProvider());
        Properties ps = getPropeties();
        if (ps != null) {
            String suitNames = ps.getProperty("AdditionalSuits");
            if (suitNames != null)
                PluginFactory.loadAdditionalSuits(suitNames, suits);
            canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
        }
        suits.addAll(getAdditionalSuits());
        createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
        factory = createPluginFactory(suits);
        String prefix = "ramus_";
        impl = new ServerIEngineImpl(0, template, prefix, factory);
        accessor = impl.getAccessor();
        persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
        persistentFactory.rebuild();
        checkIfGroupsExists();
        Engine result;
        Journaled journaled;
        if (cachedData == null) {
            JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
            result = journaledEngine2;
            journaled = journaledEngine2.getJournal();
        } else {
            JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

                @Override
                protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
                }
            };
            journaled = engine.getJournal();
            CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
            for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
            result = cachedEngine;
        }
        EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
        log = new Log(result, journaled) {

            protected Event createEvent(String type, UpdateEventCallback callback) {
                String user = "admin";
                if (impl.getServerAccessRules() != null)
                    user = impl.getServerAccessRules().getUser().getLogin();
                long id = impl.nextValue("qualifiers_log_seq");
                return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
            }
        };
        log.addExtension(engineLogExtension);
        log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
        return result;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : PersistentFactory(com.ramussoft.core.persistent.PersistentFactory) UniversalPersistentFactory(com.ramussoft.core.persistent.UniversalPersistentFactory) EngineLogExtension(com.ramussoft.common.logger.EngineLogExtension) Log(com.ramussoft.common.logger.Log) ILog(com.ramussoft.common.logger.ILog) PersistentsPluginProvider(com.ramussoft.core.persistent.PersistentsPluginProvider) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) PluginProvider(com.ramussoft.common.PluginProvider) Properties(java.util.Properties) IDEF0PluginProvider(com.ramussoft.idef0.IDEF0PluginProvider) Timestamp(java.sql.Timestamp) SQLException(java.sql.SQLException) UpdateEventCallback(com.ramussoft.common.logger.UpdateEventCallback) Journaled(com.ramussoft.common.journal.Journaled) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) Event(com.ramussoft.common.logger.Event) PluginFactory(com.ramussoft.common.PluginFactory) Engine(com.ramussoft.common.Engine) IEngine(com.ramussoft.common.IEngine) JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) Plugin(com.ramussoft.common.Plugin) PersistentsPlugin(com.ramussoft.core.persistent.PersistentsPlugin) AbstractPlugin(com.ramussoft.common.AbstractPlugin)

Aggregations

Plugin (com.ramussoft.common.Plugin)12 PluginFactory (com.ramussoft.common.PluginFactory)8 PluginProvider (com.ramussoft.common.PluginProvider)7 ArrayList (java.util.ArrayList)7 Engine (com.ramussoft.common.Engine)5 CachedEngine (com.ramussoft.common.cached.CachedEngine)5 StandardAttributesPlugin (com.ramussoft.core.attribute.standard.StandardAttributesPlugin)4 IEngine (com.ramussoft.common.IEngine)3 JournaledEngine (com.ramussoft.common.journal.JournaledEngine)3 GUIPlugin (com.ramussoft.gui.common.GUIPlugin)3 IDEF0PluginProvider (com.ramussoft.idef0.IDEF0PluginProvider)3 AbstractPlugin (com.ramussoft.common.AbstractPlugin)2 AccessRules (com.ramussoft.common.AccessRules)2 AttributePlugin (com.ramussoft.common.attribute.AttributePlugin)2 SimpleAttributePluginSuit (com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit)2 PersistentsPlugin (com.ramussoft.core.persistent.PersistentsPlugin)2 PersistentsPluginProvider (com.ramussoft.core.persistent.PersistentsPluginProvider)2 JDBCTemplate (com.ramussoft.jdbc.JDBCTemplate)2 EngineInvocker (com.ramussoft.net.common.tcp.EngineInvocker)2 InvocationHandler (java.lang.reflect.InvocationHandler)2