use of com.ramussoft.idef0.IDEF0PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class BaseExporter method export.
/**
* @param args
* @throws IOException
*/
public void export(final File file) throws IOException {
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
ps.add(new IDEF0PluginProvider());
return ps;
}
@Override
protected File getFile() {
return null;
}
@Override
public Connection createConnection() throws SQLException {
return EngineFactory.createNewConnection();
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
@Override
protected FileIEngineImpl createFileIEngine(PluginFactory factory) throws ClassNotFoundException, ZipException, IOException {
return new FileIEngineImpl(0, template, factory, null);
}
};
Engine s = database.getEngine(null);
FileIEngineImpl impl = (FileIEngineImpl) s.getDeligate();
EngineFactory factory = new EngineFactory();
IEngine d = factory.getEngine();
ZipOutputStream out = impl.saveToFileNotCloseFile(file);
for (String streamName : d.getStreamNames()) {
byte[] bs = d.getStream(streamName);
if (bs == null) {
} else {
if (streamName.startsWith("/"))
streamName = streamName.substring(1);
out.putNextEntry(new ZipEntry(streamName));
out.write(bs);
}
}
out.close();
try {
factory.getTemplate().getConnection().close();
impl.getConnection().close();
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.ramussoft.idef0.IDEF0PluginProvider 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);
}
}
use of com.ramussoft.idef0.IDEF0PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class BaseImporter method main.
/**
* @param args
*/
public static void main(final String[] args) {
if (args.length == 0) {
System.err.println("Enter input file as parameter");
return;
}
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
ps.add(new IDEF0PluginProvider());
return ps;
}
@Override
protected File getFile() {
return new File(args[0]);
}
@Override
public Connection createConnection() throws SQLException {
return EngineFactory.createNewConnection();
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
};
EngineFactory factory = new EngineFactory();
Engine s = database.getEngine(null);
IEngine d = factory.getEngine();
for (String streamName : s.getStreamNames()) {
byte[] bs = s.getStream(streamName);
if (bs == null) {
System.err.println("WARNING: stream " + streamName + " not found in the source");
} else
d.setStream(streamName, bs);
}
try {
((FileIEngineImpl) (database.getEngine(null).getDeligate())).close();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations