Search in sources :

Example 1 with Plugin

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

the class EngineConnection method init.

public void init(String[] args) throws Exception {
    try {
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        java.sql.Connection jdbcConnection = null;
        Properties ps = EngineFactory.getPropeties();
        if (ps != null) {
            try {
                Class.forName(ps.getProperty("driver"));
                jdbcConnection = DriverManager.getConnection(ps.getProperty("url"), ps.getProperty("user"), ps.getProperty("password"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (jdbcConnection == null)
            jdbcConnection = DriverManager.getConnection("jdbc:postgresql://127.0.0.1/ramus_public", "postgres", "postgres");
        template = new JDBCTemplate(jdbcConnection);
        userFactory = new UserFactoryImpl(template);
        JDBCTemplate template = new JDBCTemplate(jdbcConnection);
        String password = template.queryForObjects("SELECT \"password\" FROM users WHERE \"login\"=?", new RowMapper() {

            @Override
            public Object mapRow(ResultSet rs, int index) throws SQLException {
                return rs.getString(1);
            }
        }, new Object[] { "admin" }, true).toString().trim();
        connection = new TcpClientConnection("127.0.0.1", Metadata.TCP_PORT) {

            @Override
            protected void objectReaded(Object object) {
                if (tcpClientEngine != null)
                    tcpClientEngine.call((EvenstHolder) object);
            }
        };
        connection.start();
        connection.invoke("login", new Object[] { "admin", password });
        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);
        List<PluginProvider> suits = new ArrayList<PluginProvider>();
        suits.add(new SimpleAttributePluginSuit());
        initAdditionalPluginSuits(suits);
        PluginFactory factory = createPluginFactory(suits);
        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);
        // new CachedEngine(engine1);
        final Engine cachedEngine = 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);
        rules = (AccessRules) createDeligate(AccessRules.class);
        this.engine = engine;
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) EngineInvocker(com.ramussoft.net.common.tcp.EngineInvocker) ArrayList(java.util.ArrayList) Properties(java.util.Properties) TcpClientEngine(com.ramussoft.client.TcpClientEngine) UserFactoryImpl(com.ramussoft.server.UserFactoryImpl) JDBCTemplate(com.ramussoft.jdbc.JDBCTemplate) ResultSet(java.sql.ResultSet) PluginFactory(com.ramussoft.common.PluginFactory) TcpClientEngine(com.ramussoft.client.TcpClientEngine) Engine(com.ramussoft.common.Engine) RowMapper(com.ramussoft.jdbc.RowMapper) Hashtable(java.util.Hashtable) Method(java.lang.reflect.Method) PluginProvider(com.ramussoft.common.PluginProvider) InvocationHandler(java.lang.reflect.InvocationHandler) SQLException(java.sql.SQLException) SimpleAttributePluginSuit(com.ramussoft.core.attribute.simple.SimpleAttributePluginSuit) TcpClientConnection(com.ramussoft.client.TcpClientConnection) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) Plugin(com.ramussoft.common.Plugin)

Example 2 with Plugin

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

the class EngineConnection 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) PluginProvider(com.ramussoft.common.PluginProvider) PluginFactory(com.ramussoft.common.PluginFactory) StandardAttributesPlugin(com.ramussoft.core.attribute.standard.StandardAttributesPlugin) Plugin(com.ramussoft.common.Plugin)

Example 3 with Plugin

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

the class Client 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) PluginProvider(com.ramussoft.common.PluginProvider) AbstractGUIPluginFactory(com.ramussoft.gui.common.AbstractGUIPluginFactory) SimleGUIPluginFactory(com.ramussoft.gui.core.simple.SimleGUIPluginFactory) GUIPluginFactory(com.ramussoft.gui.core.GUIPluginFactory) PluginFactory(com.ramussoft.common.PluginFactory) Plugin(com.ramussoft.common.Plugin) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 4 with Plugin

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

the class AboutDialog method createPluginListComponent.

private Component createPluginListComponent() {
    JScrollPane pane = new JScrollPane();
    Object[][] data = new Object[plugins.size()][];
    for (int i = 0; i < plugins.size(); i++) {
        Plugin plugin = plugins.get(i);
        String name = plugin.getName();
        if (plugin instanceof AttributePlugin)
            name = "Attribute." + name + "." + ((AttributePlugin) plugin).getTypeName();
        data[i] = new Object[] { name };
    }
    Arrays.sort(data, new Comparator<Object[]>() {

        @SuppressWarnings("unchecked")
        @Override
        public int compare(Object[] o1, Object[] o2) {
            return ((Comparable<String>) o1[0]).compareTo((String) o2[0]);
        }
    });
    DefaultTableModel model = new DefaultTableModel(data, new Object[] { GlobalResourcesManager.getString("Plugin.Name") }) {

        /**
         */
        private static final long serialVersionUID = -1986847073145962545L;

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    pane.setViewportView(new JTable(model));
    return pane;
}
Also used : JScrollPane(javax.swing.JScrollPane) AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) DefaultTableModel(javax.swing.table.DefaultTableModel) JTable(javax.swing.JTable) Plugin(com.ramussoft.common.Plugin) AttributePlugin(com.ramussoft.common.attribute.AttributePlugin) GUIPlugin(com.ramussoft.gui.common.GUIPlugin)

Example 5 with Plugin

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

the class MemoryDatabase method createJournaledEngine.

private JournaledEngine createJournaledEngine(PluginFactory factory, PersistentFactory persistentFactory) throws ClassNotFoundException {
    if (cached) {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {

            @Override
            protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
            }
        };
        CachedEngine cachedEngine = new CachedEngine(journaledEngine2);
        for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
        this.engine = cachedEngine;
        return journaledEngine2;
    } else {
        JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
        this.engine = journaledEngine2;
        return journaledEngine2;
    }
}
Also used : JournaledEngine(com.ramussoft.common.journal.JournaledEngine) CachedEngine(com.ramussoft.common.cached.CachedEngine) AccessRules(com.ramussoft.common.AccessRules) PluginFactory(com.ramussoft.common.PluginFactory) Plugin(com.ramussoft.common.Plugin)

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