Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'core/org.eclipse.emf.teneo.eclipse/src')
-rw-r--r--core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/Messages.java35
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseException.java42
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseUtil.java80
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StorePlugin.java91
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/GenerateMappingAction.java138
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/RunGenerateJob.java234
-rw-r--r--core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/messages.properties25
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreExportXML.java201
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreImportXML.java136
-rwxr-xr-xcore/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreOpenResource.java140
10 files changed, 1122 insertions, 0 deletions
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/Messages.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/Messages.java
new file mode 100644
index 000000000..ecf2ad4c2
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/Messages.java
@@ -0,0 +1,35 @@
+/**
+ * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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:
+ * Victor Roldan Betancort - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.emf.teneo.eclipse;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author Victor Roldan Betancort
+ */
+public class Messages {
+ private static final String BUNDLE_NAME = "org.eclipse.emf.teneo.eclipse.messages"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseException.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseException.java
new file mode 100755
index 000000000..0230409d0
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseException.java
@@ -0,0 +1,42 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * StoreEclipseException.java,v 1.2 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse;
+
+import org.eclipse.emf.teneo.TeneoException;
+
+/**
+ * Is used to throw runtime plugin exception. This class offers automatic logging to commons
+ * logging. Note that this class extends RuntimeException, so no forced throws and catch statements.
+ * Although there are very differing views on this topic but it is our experience that to many
+ * checked exceptions only distract the programmer and have no added value.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+
+public class StoreEclipseException extends TeneoException {
+ /**
+ * Serializable id
+ */
+ private static final long serialVersionUID = 7433341056815136427L;
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public StoreEclipseException(String msg, Throwable cause) {
+ super(msg, cause);
+ }
+
+ /**
+ * The constructor, logs the exception also
+ */
+ public StoreEclipseException(String msg) {
+ super(msg);
+ }
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseUtil.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseUtil.java
new file mode 100755
index 000000000..7bdcec9f4
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StoreEclipseUtil.java
@@ -0,0 +1,80 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * StoreEclipseUtil.java,v 1.2 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.teneo.Constants;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ * Convenience util, for example reads the property file and returns the property file.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.4 $
+ */
+public class StoreEclipseUtil {
+ /** Utility method to handle an error */
+ public static void handleError(Throwable t, Log log) {
+ t.printStackTrace(System.err);
+ log.error(t);
+ MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
+ "Error Occured", t.getMessage());
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public static Properties readPropFile(IStructuredSelection selection) {
+ final IFile propFile = (IFile) selection.getFirstElement();
+ final String filePath = propFile.getFullPath().toOSString();
+ try {
+ final InputStream is = propFile.getContents();
+ final Properties props = new Properties();
+ props.load(is);
+ is.close();
+
+ // check some props
+ checkProperty(Constants.PROP_NAME, props);
+ checkProperty(Constants.PROP_EDITOR_EXTENSTION, Constants.PROP_EDITOR_ID, props);
+ return props;
+ } catch (IOException e) {
+ throw new StoreEclipseException("Exception when reading properties from: " + filePath,
+ e);
+ } catch (CoreException e) {
+ throw new StoreEclipseException("Exception when reading properties from: " + filePath,
+ e);
+ }
+ }
+
+ /** Checks if the passed value is null, if not then an exception is thrown */
+ private static void checkProperty(String propName, Properties props) {
+ if (props.getProperty(propName) == null) {
+ throw new StoreEclipseException("The ehb file does not contain the property: "
+ + propName);
+ }
+ }
+
+ /** Checks if the passed value is null, if not then an exception is thrown */
+ private static void checkProperty(String propName1, String propName2, Properties props) {
+ if (props.getProperty(propName1) == null && props.getProperty(propName2) == null) {
+ throw new StoreEclipseException("The ehb file must contain one of these properties: "
+ + propName1 + "," + propName2);
+ }
+ }
+} \ No newline at end of file
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StorePlugin.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StorePlugin.java
new file mode 100755
index 000000000..11cb96f71
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/StorePlugin.java
@@ -0,0 +1,91 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * 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:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: StorePlugin.java,v 1.4 2008/02/28 07:07:29 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class which is used for all plugins of elver.
+ */
+public class StorePlugin extends AbstractUIPlugin {
+
+ // The shared instance.
+ private static StorePlugin plugin;
+
+ /**
+ * The constructor.
+ */
+ public StorePlugin() {
+ plugin = this;
+ }
+
+ /**
+ * This method is called upon plug-in activation
+ */
+ @Override
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+// See bugzilla 207170
+//
+// Properties props = new Properties();
+// try
+// {
+// props.load(StorePlugin.class.getResourceAsStream("log4j.properties"));
+// }
+// catch (IOException e)
+// {
+// throw new StoreEclipseException("Exception when reading log4j props", e);
+// }
+//
+// // place the log file in the allowed location
+// final File file = getStateLocation().makeAbsolute().toFile();
+// props.setProperty("log4j.appender.A1.File", file.getAbsolutePath() +
+// File.separator + props.getProperty("log4j.appender.A1.File"));
+//
+// PropertyConfigurator.configure(props);
+ }
+
+ /**
+ * This method is called when the plug-in is stopped
+ */
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ }
+
+ /**
+ * Returns the shared instance.
+ */
+ public static StorePlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given plug-in relative path.
+ *
+ * @param path
+ * the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return AbstractUIPlugin.imageDescriptorFromPlugin("org.eclipse.emf.teneo.hibernate.eclipse", path);
+ }
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/GenerateMappingAction.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/GenerateMappingAction.java
new file mode 100755
index 000000000..a935d09e8
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/GenerateMappingAction.java
@@ -0,0 +1,138 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * GenerateMappingAction.java,v 1.3 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse.genxml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.emf.teneo.eclipse.Messages;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseUtil;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Is superclass for different generate descriptor file subclasses.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.7 $
+ */
+
+public abstract class GenerateMappingAction implements IObjectActionDelegate {
+ /** The logger for this class */
+ private static Log log = LogFactory.getLog(GenerateMappingAction.class);
+
+ /** The list of selected ecore files */
+ private ArrayList<IFile> ecoreFiles = new ArrayList<IFile>();
+
+ /**
+ * Constructor for Action1.
+ */
+ public GenerateMappingAction() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /** Should be implemented by subclasses */
+ public abstract void run(IAction action);
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action, final String targetFileName,
+ String resultTitle1, final HashMap<String, String> options,
+ final String mainClass) {
+ final StringBuffer result = new StringBuffer();
+
+ for (int i = 0; i < ecoreFiles.size(); i++) {
+ result.append((ecoreFiles.get(i)).getLocation().toOSString());
+ }
+
+ if (ecoreFiles.size() == 0) {
+ Shell shell = new Shell();
+ MessageDialog.openInformation(shell, Messages
+ .getString("teneo.create.or.mapping"), Messages
+ .getString("teneo.select.ecore.file"));
+ return;
+ }
+
+ log.debug("Generating or descriptor file based on ecores in: "
+ + result.toString());
+
+ try {
+ final IContainer container = (ecoreFiles.get(0)).getParent();
+
+ // get the location of the ecores
+ final String[] ecoreLocations = new String[ecoreFiles.size()];
+ ArrayList<IJavaProject> jprojects = new ArrayList<IJavaProject>();
+ ArrayList<IProject> projects = new ArrayList<IProject>();
+ for (int i = 0; i < ecoreFiles.size(); i++) {
+ final IFile ecoreFile = ecoreFiles.get(i);
+ ecoreLocations[i] = ecoreFile.getLocation().toOSString();
+
+ IProject project = ecoreFile.getProject();
+ if (project != null && !projects.contains(project)) {
+ projects.add(project);
+ jprojects.add(JavaCore.create(project));
+ }
+ }
+
+ RunGenerateJob rgj = new RunGenerateJob(jprojects, ecoreLocations,
+ targetFileName, mainClass, options);
+ rgj.schedule();
+
+ Shell shell = new Shell();
+ MessageDialog.openInformation(shell, resultTitle1, Messages
+ .getString("teneo.file.created")
+ + container.getName());
+
+ // is refresh a dangerous action, eclipse crashes?
+ container.refreshLocal(IResource.DEPTH_INFINITE, null);
+ } catch (Throwable t) {
+ StoreEclipseUtil.handleError(t, log);
+ }
+ }
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (!(selection instanceof IStructuredSelection))
+ return;
+
+ final IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+ final Iterator<?> it = structuredSelection.iterator();
+ ecoreFiles = new ArrayList<IFile>();
+ while (it.hasNext()) {
+ final Object obj = it.next();
+ if (obj instanceof IFile) {
+ ecoreFiles.add((IFile) obj);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/RunGenerateJob.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/RunGenerateJob.java
new file mode 100755
index 000000000..751926363
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/genxml/RunGenerateJob.java
@@ -0,0 +1,234 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * RunGenerateJob.java,v 1.4 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse.genxml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.ILaunchConfigurationType;
+import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
+import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
+import org.eclipse.jdt.launching.JavaRuntime;
+
+/**
+ * Generate a mapping file in a separate java program to use the classpath of
+ * the selected projects.
+ */
+public class RunGenerateJob extends WorkspaceJob implements
+ IJavaLaunchConfigurationConstants {
+
+ /** Standard name of the generation action */
+ private static final String CONFIGURATION_NAME = "Teneo OR-Mapping Generation";
+
+ /** The list of java projects */
+ private final ArrayList<IJavaProject> jProjects; // IJavaProject
+
+ /** Array of absolute paths to ecore files which are to be parsed */
+ private final String[] ecores;
+
+ /** The location to put the result */
+ private final String targetFileName;
+
+ /** The name of the main class */
+ private final String mainClass;
+
+ /** The options */
+ private final HashMap<String, String> options;
+
+ /**
+ * The constructor.
+ */
+ public RunGenerateJob(ArrayList<IJavaProject> jProjects, String[] ecores,
+ String targetFileName, String mainClass,
+ HashMap<String, String> options) {
+ super("Generate Mapping File");
+ this.jProjects = jProjects;
+ this.ecores = ecores;
+ this.targetFileName = targetFileName;
+ this.mainClass = mainClass;
+ this.options = options;
+ }
+
+ /**
+ * Launches a separate java process using the classpaths of the passed
+ * projects
+ */
+
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor)
+ throws CoreException {
+ // first delete the old generation of the same name
+ ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
+ ILaunchConfigurationType type = manager
+ .getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
+ ILaunchConfiguration[] configurations = manager
+ .getLaunchConfigurations(type);
+ for (ILaunchConfiguration element : configurations) {
+ if (element.getName().compareTo(CONFIGURATION_NAME) == 0) {
+ element.delete();
+ }
+ }
+
+ // create a new launch configuration
+ ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null,
+ CONFIGURATION_NAME);
+
+ final List<String> classPath = determineClassPath();
+ workingCopy.setAttribute(ATTR_DEFAULT_CLASSPATH, false);
+ workingCopy.setAttribute(ATTR_CLASSPATH, classPath);
+ workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, mainClass);
+ workingCopy.setAttribute(ATTR_PROJECT_NAME, (jProjects.get(0))
+ .getProject().getName());
+ // workingCopy.setAttribute(ATTR_WORKING_DIRECTORY, workingDir);
+ workingCopy.setAttribute(ATTR_PROGRAM_ARGUMENTS, getProgramArguments());
+ workingCopy.doSave();
+ workingCopy.launch(ILaunchManager.RUN_MODE, null);
+ return Status.OK_STATUS;
+ }
+
+ /** Collect the classpath as a list of strings */
+ private ArrayList<String> determineClassPath() throws CoreException {
+ ArrayList<String> result = new ArrayList<String>();
+
+ for (int i = 0; i < jProjects.size(); i++) {
+ final IJavaProject jProject = jProjects.get(i);
+ final IRuntimeClasspathEntry outputEntry = JavaRuntime
+ .newDefaultProjectClasspathEntry(jProject);
+ result.add(outputEntry.getMemento());
+ }
+
+ IPath systemLibsPath = new Path(JavaRuntime.JRE_CONTAINER);
+ IRuntimeClasspathEntry systemLibsEntry = JavaRuntime
+ .newRuntimeContainerClasspathEntry(systemLibsPath,
+ IRuntimeClasspathEntry.STANDARD_CLASSES);
+ result.add(systemLibsEntry.getMemento());
+
+ return result;
+ }
+
+ /** Determine the classnames of the interfaces */
+ private String getEPackageNames() {
+ try {
+ final ArrayList<String> result = new ArrayList<String>();
+ for (int i = 0; i < jProjects.size(); i++) {
+ final IJavaProject ijp = jProjects.get(i);
+ for (int j = 0; j < ijp.getPackageFragmentRoots().length; j++) {
+ IPackageFragmentRoot ipf = ijp.getPackageFragmentRoots()[j];
+ if (ipf.getClass().getName()
+ .endsWith("JarPackageFragmentRoot")) {
+ continue;
+ }
+ if (!ipf.exists()) {
+ continue;
+ }
+ for (int c = 0; c < ipf.getChildren().length; c++) {
+ walk(ipf.getChildren()[c], "", result);
+ }
+ }
+ }
+
+ StringBuffer resultStr = new StringBuffer();
+ for (int i = 0; i < result.size(); i++) {
+ final String epackage = result.get(i);
+ if (i > 0) {
+ resultStr.append(",");
+ }
+ resultStr.append(epackage);
+ }
+ return resultStr.toString();
+ } catch (Exception e) {
+ throw new StoreEclipseException(
+ "Exception while looking for epackages in projects "
+ + e.getMessage(), e);
+ }
+
+ }
+
+ /** Walk the java element structure looking for EPackage sources */
+ private void walk(IJavaElement ije, String pName, ArrayList<String> result)
+ throws Exception {
+ if (ije.getClass().getName().endsWith("JarPackageFragmentRoot")) {
+ return;
+ }
+ if (!(ije instanceof IPackageFragment)) {
+ return;
+ }
+
+ final IPackageFragment pf = (IPackageFragment) ije;
+ final String packageName = pName + (pName.length() > 0 ? "." : "")
+ + pf.getElementName();
+ for (int c = 0; c < pf.getChildren().length; c++) {
+ final IJavaElement child = pf.getChildren()[c];
+ if (child instanceof IPackageFragment) {
+ walk(child, packageName, result);
+ } else if (child instanceof ICompilationUnit) {
+ // a source, check if it implements an EPackage
+ // TODO make this more robust for other packages which are also
+ // EPackages
+ final ICompilationUnit icu = (ICompilationUnit) child;
+ final String[] types = icu.getTypes()[0]
+ .getSuperInterfaceNames();
+ for (String element : types) {
+ if (element.compareTo("EPackage") == 0) {
+ result.add(packageName + "."
+ + icu.getTypes()[0].getElementName());
+ return;
+ }
+ }
+ if (icu.getTypes()[0].getSuperclassName() != null
+ && icu.getTypes()[0].getSuperclassName().equals(
+ "EPackageImpl")) {
+ result.add(packageName + "."
+ + icu.getTypes()[0].getElementName());
+ return;
+ }
+ }
+ }
+ }
+
+ /** Returns the program arguments as a string */
+ private String getProgramArguments() {
+ StringBuffer args = new StringBuffer();
+ append(args, targetFileName);
+ for (String key : options.keySet()) {
+ append(args, "+" + key + "," + options.get(key));
+ }
+
+ for (String element : ecores) {
+ append(args, element);
+ }
+
+ append(args, "-" + getEPackageNames());
+
+ return args.toString();
+ }
+
+ /** Appends a program argument taking into account " and space */
+ private void append(StringBuffer buffer, String value) {
+ buffer.append("\"" + value + "\" ");
+ }
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/messages.properties b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/messages.properties
new file mode 100644
index 000000000..85376292f
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/messages.properties
@@ -0,0 +1,25 @@
+# ==============================================================================
+# Copyright (c) 2004 - 2009 Martin Taal and others.
+# 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:
+# Martin Taal
+# ==============================================================================
+
+# ==============================================================================
+# This properties file contains all strings subject to be shown in the UI.
+# ==============================================================================
+
+teneo.create.or.mapping = Create EMF OR Mapping File
+teneo.select.ecore.file = Please select a ecore file.
+teneo.file.created = The mapping file has been created here:
+teneo.export.xml = Export the contents of the datastore to XML
+teneo.export.xmi = Export the contents of the datastore to XMI
+teneo.select.parent = Select a parent location and enter a file name
+teneo.import.xml = Select one or more XML resources to import from.
+teneo.import.xmi = Select one or more XMI resources to import from.
+teneo.import = Import
+teneo.generate.orm.file = Generate ORM mapping file \ No newline at end of file
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreExportXML.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreExportXML.java
new file mode 100755
index 000000000..818c81f96
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreExportXML.java
@@ -0,0 +1,201 @@
+/**
+ * <copyright>
+ *
+ * Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
+ * 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:
+ * Martin Taal
+ * </copyright>
+ *
+ * $Id: StoreExportXML.java,v 1.5 2009/05/06 18:40:54 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse.resourcehandler;
+
+import java.io.ByteArrayInputStream;
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourceAttributes;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.teneo.eclipse.Messages;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseUtil;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ContainerGenerator;
+import org.eclipse.ui.dialogs.SaveAsDialog;
+
+/**
+ * Generic action class for exporting xml from a resource file.
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.5 $
+ */
+
+public abstract class StoreExportXML implements IObjectActionDelegate {
+ /** The logger for this class */
+ private static Log log = LogFactory.getLog(StoreExportXML.class);
+
+ /** The selected ehb file */
+ private IStructuredSelection selection = null;
+
+ /**
+ * Constructor for Action1.
+ */
+ public StoreExportXML() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ try {
+ final SaveAsDialog saDialog = new ExportSaveAsDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getShell());
+ saDialog.open();
+ final IPath path = saDialog.getResult();
+
+ if (path == null) {
+ return; // nothing selected
+ }
+
+ // create the path
+ final IPath containerPath = path.removeLastSegments(1);
+ final ContainerGenerator cg = new ContainerGenerator(containerPath);
+ IWorkspaceRunnable operation = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+ cg.generateContainer(null);
+ }
+ };
+ ResourcesPlugin.getWorkspace().run(operation, null);
+
+ // get the file
+ final IFile destFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ final Properties props = StoreEclipseUtil.readPropFile(selection);
+
+ final WorkspaceJob wj = new LocalJob(destFile, props);
+ wj.schedule();
+ } catch (CoreException c) {
+ StoreEclipseUtil.handleError(c, log);
+ }
+ }
+
+ /** Does the real export */
+ protected abstract byte[] doExport(Properties props);
+
+ /** Can be overridden */
+ protected boolean isXMLExport() {
+ return true;
+ }
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selected) {
+ if (!(selected instanceof IStructuredSelection)) {
+ return;
+ }
+
+ final IStructuredSelection structSelection = (IStructuredSelection) selected;
+ selection = structSelection;
+ }
+
+ /** Extends Save As dialog to add some specific export titles */
+ private class ExportSaveAsDialog extends SaveAsDialog {
+ /**
+ * Creates a new Save As dialog for no specific file.
+ *
+ * @param parentShell
+ * the parent shell
+ */
+ public ExportSaveAsDialog(Shell parentShell) {
+ super(parentShell);
+ }
+
+ /*
+ * (non-Javadoc) Method declared in Window.
+ */
+ @Override
+ protected Control createContents(Composite parent) {
+ Control contents = super.createContents(parent);
+ if (isXMLExport()) {
+ setTitle(Messages.getString("teneo.export.xml"));
+ } else {
+ setTitle(Messages.getString("teneo.export.xmi"));
+ }
+ setMessage(Messages.getString("teneo.select.parent"));
+ return contents;
+ }
+ }
+
+ private class LocalJob extends WorkspaceJob {
+
+ private IFile file;
+ private Properties props;
+
+ LocalJob(IFile file, Properties props) {
+ super("Import");
+ this.file = file;
+ this.props = props;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+
+ final byte[] content = doExport(props);
+
+ IWorkspaceRunnable createOperation = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor) throws CoreException {
+
+ // delete the file if it is present
+ // first set some attrs to make it possible to delete
+ final ResourceAttributes attrs = new ResourceAttributes();
+ attrs.setArchive(false);
+ attrs.setReadOnly(false);
+ if (file.exists()) {
+ file.setResourceAttributes(attrs);
+ file.delete(true, null);
+ }
+ file.create(new ByteArrayInputStream(content), true, null);
+ }
+ };
+
+ ResourcesPlugin.getWorkspace().run(createOperation, null);
+ return Status.OK_STATUS;
+ }
+ }
+
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreImportXML.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreImportXML.java
new file mode 100755
index 000000000..3413f0571
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreImportXML.java
@@ -0,0 +1,136 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * StoreImportXML.java,v 1.2 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse.resourcehandler;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.WorkspaceJob;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.teneo.eclipse.Messages;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseUtil;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.dialogs.ResourceSelectionDialog;
+
+/**
+ * Performs the import xml action
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+
+public abstract class StoreImportXML implements IObjectActionDelegate {
+ /** The logger for this class */
+ private static Log log = LogFactory.getLog(StoreImportXML.class);
+
+ /** The selected ehb file */
+ private IStructuredSelection selection = null;
+
+ /**
+ * Constructor for Action1.
+ */
+ public StoreImportXML() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /** Can be overridden */
+ protected boolean isXMLImport() {
+ return true;
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ try {
+ final String title;
+ if (isXMLImport()) {
+ title = Messages.getString("teneo.import.xml");
+ } else {
+ title = Messages.getString("teneo.import.xmi");
+ }
+
+ final ResourceSelectionDialog dialog = new ResourceSelectionDialog(PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getShell(), ResourcesPlugin.getWorkspace().getRoot(), title);
+ dialog.open();
+ final Object[] fileObjs = dialog.getResult();
+
+ if (fileObjs == null) {
+ return; // nothing selected
+ }
+
+ IFile[] files = new IFile[fileObjs.length];
+ for (int i = 0; i < fileObjs.length; i++) {
+ files[i] = (IFile) fileObjs[i];
+ }
+
+ final Properties props = StoreEclipseUtil.readPropFile(selection);
+ final WorkspaceJob wj = new LocalJob(files, props);
+ wj.schedule();
+ } catch (Exception c) {
+ StoreEclipseUtil.handleError(c, log);
+ }
+ }
+
+ /** Imports the files into the store */
+ protected abstract void doImport(IFile[] files, Properties props);
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selected) {
+ if (!(selected instanceof IStructuredSelection)) {
+ return;
+ }
+
+ final IStructuredSelection structSelection = (IStructuredSelection) selected;
+ selection = structSelection;
+ }
+
+ private class LocalJob extends WorkspaceJob {
+
+ private IFile[] files;
+ private Properties props;
+
+ LocalJob(IFile[] files, Properties props) {
+ super(Messages.getString("teneo.import"));
+ this.files = files;
+ this.props = props;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.core.resources.WorkspaceJob#runInWorkspace(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
+ doImport(files, props);
+ return Status.OK_STATUS;
+ }
+ }
+}
diff --git a/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreOpenResource.java b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreOpenResource.java
new file mode 100755
index 000000000..22a1bc6cf
--- /dev/null
+++ b/core/org.eclipse.emf.teneo.eclipse/src/org/eclipse/emf/teneo/eclipse/resourcehandler/StoreOpenResource.java
@@ -0,0 +1,140 @@
+/**
+ * <copyright> Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others 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: Martin Taal </copyright> $Id:
+ * StoreOpenResource.java,v 1.2 2007/02/01 12:35:18 mtaal Exp $
+ */
+
+package org.eclipse.emf.teneo.eclipse.resourcehandler;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.emf.teneo.Constants;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseException;
+import org.eclipse.emf.teneo.eclipse.StoreEclipseUtil;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IActionDelegate;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IFileEditorMapping;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+
+/**
+ * Performs the open resource action based on the information in the property file
+ *
+ * @author <a href="mailto:mtaal@elver.org">Martin Taal</a>
+ * @version $Revision: 1.6 $
+ */
+public abstract class StoreOpenResource implements IObjectActionDelegate {
+ /** The logger for this class */
+ private static Log log = LogFactory.getLog(StoreOpenResource.class);
+
+ /** The selected ehb file */
+ protected IStructuredSelection selection = null;
+
+ /**
+ * Constructor for Action1.
+ */
+ public StoreOpenResource() {
+ super();
+ }
+
+ /**
+ * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
+ */
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ }
+
+ /**
+ * @see IActionDelegate#run(IAction)
+ */
+ public void run(IAction action) {
+ final IFile propFile = (IFile) selection.getFirstElement();
+ try {
+ final Properties props = StoreEclipseUtil.readPropFile(selection);
+ openDataStore(props);
+
+ // now use the editor props to find the correct editor
+ final String editorextension = doTrim(props.getProperty(Constants.PROP_EDITOR_EXTENSTION));
+ final String editorid = doTrim(props.getProperty(Constants.PROP_EDITOR_ID));
+
+ final String foundEditorID = getEditorID(editorid, editorextension);
+
+ // and open it
+ final IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ final IWorkbenchPage page = workbenchWindow.getActivePage();
+ page.openEditor(new FileEditorInput(propFile), foundEditorID);
+ } catch (Exception e) {
+ e.printStackTrace(System.err);
+ log.error(e);
+ MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Error Occured", e
+ .getMessage());
+ }
+ }
+
+ /** Ensure that the data store is opened */
+ protected abstract void openDataStore(Properties props);
+
+ /** Convenience method */
+ private String doTrim(String totrim) {
+ if (totrim == null) {
+ return null;
+ }
+ return totrim.trim();
+ }
+
+ /** Returns the editor id on the basis of the editor id or the extension */
+ private String getEditorID(String propID, String propExtension) {
+ if (propID != null) {
+ return propID;
+ }
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+
+ IEditorDescriptor editorDesc = workbench.getEditorRegistry().getDefaultEditor(propExtension);
+ if (editorDesc == null) {
+ IFileEditorMapping[] mappings = workbench.getEditorRegistry().getFileEditorMappings();
+ for (IFileEditorMapping map : mappings) {
+ // System.err.println(map.getExtension() + "-->" + map.getEditors()[0].getId());
+ if (map.getExtension().compareTo(propExtension.toLowerCase()) == 0) {
+ editorDesc = map.getEditors()[0];
+ break;
+ }
+ }
+ }
+
+ if (editorDesc == null) {
+ throw new StoreEclipseException("No editor can be found for extension: " + propExtension);
+ }
+ return editorDesc.getId();
+ }
+
+ /** Creates a dummy file which is used to 'fool' the editor to open a specific rdb resource */
+ public IFile getModelFile(IFile ehbFile, String extension) {
+ return ResourcesPlugin.getWorkspace().getRoot().getFile(ehbFile.getFullPath().append("hibernate." + extension));
+ }
+
+ /**
+ * @see IActionDelegate#selectionChanged(IAction, ISelection)
+ */
+ public void selectionChanged(IAction action, ISelection selected) {
+ if (!(selected instanceof IStructuredSelection)) {
+ return;
+ }
+
+ final IStructuredSelection structSelection = (IStructuredSelection) selected;
+ selection = structSelection;
+ }
+} \ No newline at end of file

Back to the top