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();
}
}
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;
}
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;
}
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;
}
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;
}
}
Aggregations