]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.application/src/org/simantics/application/db/HeadlessDatabaseApplication.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.application / src / org / simantics / application / db / HeadlessDatabaseApplication.java
index 2f13280ff86fd44d04075d659522bdd4c2cdae74..355476e62512356643a6204fc5eabd9294bc9af3 100644 (file)
@@ -1,99 +1,99 @@
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.application.db;\r
-\r
-import org.eclipse.equinox.app.IApplication;\r
-import org.eclipse.equinox.app.IApplicationContext;\r
-import org.simantics.application.arguments.SimanticsArguments;\r
-import org.simantics.application.template.TemplateDatabaseApplication;\r
-import org.simantics.db.Session;\r
-\r
-/**\r
- * A headless (non-ui) application base class for one-shot connection to and\r
- * usage of a Simantics database.\r
- * \r
- * <p>\r
- * The simplest way to use this application class is to override the\r
- * {@link #afterConnect(DatabaseHandle)} method to do your own stuff with the\r
- * database in question. Use {@link #getSession()} to get a hold of the database\r
- * session.\r
- * </p>\r
- * \r
- * <p>\r
- * The application expects at least the {@link SimanticsArguments#SERVER} and\r
- * supports the {@link SimanticsArguments#CHECKOUT}.\r
- * </p>\r
- * \r
- * @see TemplateDatabaseApplication for a usage example\r
- */\r
-public abstract class HeadlessDatabaseApplication implements IApplication {\r
-\r
-    private DatabaseHandle database;\r
-\r
-    @Override\r
-    public Object start(IApplicationContext context) throws Exception {\r
-        try {\r
-            beforeConnect(context);\r
-            connectToServer(context);\r
-            afterConnect();\r
-            \r
-            return IApplication.EXIT_OK;\r
-        } finally {\r
-            if (database != null) {\r
-                try {\r
-                    database.dispose();\r
-                } catch (Throwable t) {\r
-                    t.printStackTrace();\r
-                }\r
-            }\r
-        }\r
-    }\r
-\r
-    @Override\r
-    public void stop() {\r
-        // TODO: force the application to stop\r
-    }\r
-\r
-    protected IDatabaseHandle connectToServer(IApplicationContext context) throws Exception {\r
-        String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);\r
-        database = new DatabaseHandle(args, deleteLocalCopyAtExit());\r
-        return database;\r
-    }\r
-\r
-    protected Session getSession() {\r
-        if (database == null)\r
-            throw new IllegalStateException("null database session");\r
-        return database.getSession();\r
-    }\r
-\r
-    /**\r
-     * Override this method to perform actions <em>before</em> the application\r
-     * attempts to connect to the database specified by the command line\r
-     * arguments.\r
-     * \r
-     * @param context the application startup context\r
-     */\r
-    protected void beforeConnect(IApplicationContext context) {\r
-    }\r
-\r
-    /**\r
-     * Override this method to perform actions <em>after</em> the application\r
-     * has connected to the database specified by the command line arguments.\r
-     */\r
-    protected void afterConnect() {\r
-    }\r
-\r
-    protected boolean deleteLocalCopyAtExit() {\r
-        return false;\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.application.db;
+
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+import org.simantics.application.arguments.SimanticsArguments;
+import org.simantics.application.template.TemplateDatabaseApplication;
+import org.simantics.db.Session;
+
+/**
+ * A headless (non-ui) application base class for one-shot connection to and
+ * usage of a Simantics database.
+ * 
+ * <p>
+ * The simplest way to use this application class is to override the
+ * {@link #afterConnect(DatabaseHandle)} method to do your own stuff with the
+ * database in question. Use {@link #getSession()} to get a hold of the database
+ * session.
+ * </p>
+ * 
+ * <p>
+ * The application expects at least the {@link SimanticsArguments#SERVER} and
+ * supports the {@link SimanticsArguments#CHECKOUT}.
+ * </p>
+ * 
+ * @see TemplateDatabaseApplication for a usage example
+ */
+public abstract class HeadlessDatabaseApplication implements IApplication {
+
+    private DatabaseHandle database;
+
+    @Override
+    public Object start(IApplicationContext context) throws Exception {
+        try {
+            beforeConnect(context);
+            connectToServer(context);
+            afterConnect();
+            
+            return IApplication.EXIT_OK;
+        } finally {
+            if (database != null) {
+                try {
+                    database.dispose();
+                } catch (Throwable t) {
+                    t.printStackTrace();
+                }
+            }
+        }
+    }
+
+    @Override
+    public void stop() {
+        // TODO: force the application to stop
+    }
+
+    protected IDatabaseHandle connectToServer(IApplicationContext context) throws Exception {
+        String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
+        database = new DatabaseHandle(args, deleteLocalCopyAtExit());
+        return database;
+    }
+
+    protected Session getSession() {
+        if (database == null)
+            throw new IllegalStateException("null database session");
+        return database.getSession();
+    }
+
+    /**
+     * Override this method to perform actions <em>before</em> the application
+     * attempts to connect to the database specified by the command line
+     * arguments.
+     * 
+     * @param context the application startup context
+     */
+    protected void beforeConnect(IApplicationContext context) {
+    }
+
+    /**
+     * Override this method to perform actions <em>after</em> the application
+     * has connected to the database specified by the command line arguments.
+     */
+    protected void afterConnect() {
+    }
+
+    protected boolean deleteLocalCopyAtExit() {
+        return false;
+    }
+
+}