wlu: created
diff --git a/org.eclipse.epf.toolbox/.classpath b/org.eclipse.epf.toolbox/.classpath
new file mode 100644
index 0000000..751c8f2
--- /dev/null
+++ b/org.eclipse.epf.toolbox/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.epf.toolbox/.options b/org.eclipse.epf.toolbox/.options
new file mode 100644
index 0000000..4f97999
--- /dev/null
+++ b/org.eclipse.epf.toolbox/.options
@@ -0,0 +1,2 @@
+# Turn on debug trace for the toolbox plug-in
+org.eclipse.epf.toolbox/debug=true
diff --git a/org.eclipse.epf.toolbox/.project b/org.eclipse.epf.toolbox/.project
new file mode 100644
index 0000000..348db45
--- /dev/null
+++ b/org.eclipse.epf.toolbox/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.epf.toolbox</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.epf.toolbox/META-INF/MANIFEST.MF b/org.eclipse.epf.toolbox/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..5c848ed
--- /dev/null
+++ b/org.eclipse.epf.toolbox/META-INF/MANIFEST.MF
@@ -0,0 +1,25 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.epf.toolbox;singleton:=true
+Bundle-Version: 7.2.0.qualifier
+Bundle-Activator: org.eclipse.epf.toolbox.ToolboxPlugin
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.epf.common,
+ org.eclipse.epf.uma,
+ org.eclipse.epf.library,
+ org.eclipse.epf.migration.diagram,
+ org.eclipse.epf.diagram.core,
+ org.eclipse.gmf.runtime.notation,
+ org.eclipse.epf.import,
+ org.eclipse.epf.authoring.ui,
+ org.eclipse.epf.library.xmi,
+ org.eclipse.epf.export,
+ org.eclipse.epf.export.xml,
+ org.eclipse.epf.import.xml,
+ org.eclipse.epf.common.ui
+Eclipse-LazyStart: true
+Import-Package: org.eclipse.epf.library.util
diff --git a/org.eclipse.epf.toolbox/build.properties b/org.eclipse.epf.toolbox/build.properties
new file mode 100644
index 0000000..c88359b
--- /dev/null
+++ b/org.eclipse.epf.toolbox/build.properties
@@ -0,0 +1,7 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/,\
+ plugin.properties
diff --git a/org.eclipse.epf.toolbox/icons/sample.gif b/org.eclipse.epf.toolbox/icons/sample.gif
new file mode 100644
index 0000000..34fb3c9
--- /dev/null
+++ b/org.eclipse.epf.toolbox/icons/sample.gif
Binary files differ
diff --git a/org.eclipse.epf.toolbox/plugin.xml b/org.eclipse.epf.toolbox/plugin.xml
new file mode 100644
index 0000000..53d4022
--- /dev/null
+++ b/org.eclipse.epf.toolbox/plugin.xml
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+
+
+ <extension
+ point="org.eclipse.epf.common.commandLineRunners">
+ <commandLineRunner
+ class="org.eclipse.epf.toolbox.batch.EpfBatchRunner"
+ runnerId="epfBatchRunner">
+ </commandLineRunner>
+ </extension>
+
+
+</plugin>
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/ToolboxPlugin.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/ToolboxPlugin.java
new file mode 100644
index 0000000..dc5154a
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/ToolboxPlugin.java
@@ -0,0 +1,54 @@
+package org.eclipse.epf.toolbox;
+
+import java.util.Date;
+
+import org.eclipse.epf.common.ui.AbstractPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class ToolboxPlugin extends AbstractPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = ToolboxPlugin.class.getName();
+
+ // The shared plug-in instance.
+ private static ToolboxPlugin plugin;
+
+ // The date and time when this plug-in was started.
+ private Date startTime;
+
+ /**
+ * Default constructor.
+ */
+ public ToolboxPlugin() {
+ super();
+ plugin = this;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ startTime = new Date();
+ }
+
+ public void stop(BundleContext context) throws Exception {
+ super.stop(context);
+ plugin = null;
+ }
+
+ /**
+ * Returns the shared plug-in instance.
+ */
+ public static ToolboxPlugin getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns the date and time when this plug-in was started.
+ */
+ public Date getStartTime() {
+ return startTime;
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/C.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/C.java
new file mode 100644
index 0000000..195a69b
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/C.java
@@ -0,0 +1,41 @@
+package org.eclipse.epf.toolbox.batch;
+
+public class C {
+
+ public static String OpenLibrary = "OpenLibrary";
+ public static String ExportPlugins = "ExportPlugins";
+ public static String ImportPlugins = "ImportPlugins";
+ public static String ExportConfiguration = "ExportConfiguration";
+ public static String ImportConfiguration = "ImportConfiguration";
+ public static String ExportXml = "ExportXml";
+ public static String ImportXml = "ImportXml";
+ public static String SelectedPlugin = "SelectedPlugin";
+ public static String ReportMethodElement = "ReportMethodElement";
+
+ public static String End = "End";
+
+ //Attribute tags
+ public static String RootPath = "rootPath";
+ public static String TraceFilePath = "traceFilePath";
+ public static String ReportFilePath = "reportFilePath";
+ public static String Trace = "trace";
+
+ public static String Disable = "disable";
+
+ public static String Id = "id";
+ public static String Path = "path";
+ public static String ExportFolderPath = "exportFolderPath";
+ public static String ImportFolderPath = "importFolderPath";
+ public static String XmlExportFilePath = "xmlExportFilePath";
+ public static String XmlImportFilePath = "xmlImportFilePath";
+ public static String SelectedConfigName = "selectedConfigName";
+ public static String ExportAll = "exportAll";
+ public static String ImportAll = "importAll";
+ public static String Name = "name";
+ public static String ElementType = "elementType";
+ public static String Recursive = "recursive";
+
+ public static String Verbose = "verbose";
+
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchCommandMgr.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchCommandMgr.java
new file mode 100644
index 0000000..503fc8f
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchCommandMgr.java
@@ -0,0 +1,238 @@
+package org.eclipse.epf.toolbox.batch;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.epf.common.utils.XMLUtil;
+import org.eclipse.epf.library.xmi.XMILibraryUtil;
+import org.eclipse.epf.toolbox.ToolboxPlugin;
+import org.eclipse.epf.toolbox.batch.commands.EbcExportConfiguration;
+import org.eclipse.epf.toolbox.batch.commands.EbcExportPlugins;
+import org.eclipse.epf.toolbox.batch.commands.EbcExportXml;
+import org.eclipse.epf.toolbox.batch.commands.EbcImportConfiguration;
+import org.eclipse.epf.toolbox.batch.commands.EbcImportPlugins;
+import org.eclipse.epf.toolbox.batch.commands.EbcImportXml;
+import org.eclipse.epf.toolbox.batch.commands.EbcOpenLibrary;
+import org.eclipse.epf.toolbox.batch.commands.EbcReportMethodElement;
+import org.eclipse.epf.toolbox.batch.commands.EpfBatchCommand;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Weiping Lu
+ */
+public class EbcBatchCommandMgr {
+
+ private boolean trace = false;
+ private PrintStream tracePS;
+ private String rootPath;
+ private File ebcInputFile;
+ private EbcLibraryService service = EbcLibraryService.getInstance();
+ private MethodLibrary currentBaseLib;
+
+ private EbcReportMgr reportMgr;
+
+ private List<EpfBatchCommand> epfBatchCommandList = new ArrayList<EpfBatchCommand>();
+
+ private static Map<String, EpfBatchCommand> ebcClassMap = new HashMap<String, EpfBatchCommand>();
+ private static Map<Class, String> ebcTagNameMap = new HashMap<Class, String>();
+
+ static {
+ addToEbcClassMap(C.OpenLibrary, EbcOpenLibrary.class);
+ addToEbcClassMap(C.ExportPlugins, EbcExportPlugins.class);
+ addToEbcClassMap(C.ImportPlugins, EbcImportPlugins.class);
+ addToEbcClassMap(C.ExportConfiguration, EbcExportConfiguration.class);
+ addToEbcClassMap(C.ImportConfiguration, EbcImportConfiguration.class);
+ addToEbcClassMap(C.ExportXml, EbcExportXml.class);
+ addToEbcClassMap(C.ImportXml, EbcImportXml.class);
+ addToEbcClassMap(C.ReportMethodElement, EbcReportMethodElement.class);
+
+ }
+
+ private static void addToEbcClassMap(String elementName, Class cls) {
+ Object instance = null;
+ try {
+ instance = cls.newInstance();
+ } catch (Exception e){
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ }
+ if (instance instanceof EpfBatchCommand) {
+ ebcClassMap.put(elementName, (EpfBatchCommand) instance);
+ ebcTagNameMap.put(cls, elementName);
+ }
+ }
+
+ public EbcBatchCommandMgr(File inputFile) {
+ ebcInputFile = inputFile;
+ reportMgr = new EbcReportMgr(this);
+ }
+
+ public String getTagName(EpfBatchCommand epfInstance) {
+ return ebcTagNameMap.get(epfInstance.getClass());
+ }
+
+ public EbcExeReplies execute() {
+ ToolboxPlugin.getDefault().getLogger().logInfo("Begin executing: " + ebcInputFile); //$NON-NLS-1$
+
+ EbcExeReplies result = null;
+ boolean loaded = false;
+ Exception loadException = null;
+ try {
+ loaded = loadEbcInputFile();
+ } catch (Exception e) {
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ }
+
+ if (loaded) {
+ result = executeCommands();
+ } else {
+ }
+
+ getReportMgr().saveDocument();
+
+ ToolboxPlugin.getDefault().getLogger().logInfo("End executing: " + ebcInputFile); //$NON-NLS-1$
+ return result;
+ }
+
+ private boolean loadEbcInputFile() throws Exception {
+ Document document = XMLUtil.loadXml(ebcInputFile);
+ Element root = document.getDocumentElement();
+
+ trace = root.getAttribute(C.Trace).equalsIgnoreCase("true");
+ rootPath = root.getAttribute(C.RootPath);
+
+ String reportFilePath = root.getAttribute(C.ReportFilePath);
+ if (reportFilePath.length() > 0) {
+ getReportMgr().setReportFile(new File(rootPath + File.separator + reportFilePath));
+ }
+
+ if (trace) {
+ String traceFilePath = root.getAttribute(C.TraceFilePath);
+ File traceFile = new File(rootPath, traceFilePath);
+ try {
+ tracePS = new PrintStream(new FileOutputStream(traceFile));
+ } catch (Exception e){
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ trace = false;
+ }
+ }
+
+ trace("Begin parsing: " + ebcInputFile);
+
+ epfBatchCommandList.clear();
+ NodeList nodes = root.getChildNodes();
+ int sz = nodes == null ? 0 : nodes.getLength();
+ for (int i = 0; i < sz; i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element) {
+ Element element = (Element) node;
+
+ if (element.getTagName().equalsIgnoreCase(C.End)) {
+ break;
+ }
+ addCommand((Element) node);
+ }
+ }
+
+ trace("End parsing: " + ebcInputFile + "\n");
+ return true;
+ }
+
+ public EbcExeReplies executeCommands() {
+ EbcExeReplies result = new EbcExeReplies();
+ for (int i = 0; i < epfBatchCommandList.size(); i++) {
+ EpfBatchCommand command = (EpfBatchCommand) epfBatchCommandList.get(i);
+ EbcExeReply reply = null;
+ try {
+ reply = command.execute();
+ } catch (Exception e) {
+ e.printStackTrace();
+ reply = new EbcExeReply();
+ }
+ if (reply != null) {
+ result.add(reply);
+ }
+ }
+
+ return result;
+ }
+
+ public void trace(String line) {
+ if (tracePS != null) {
+ tracePS.println(line);
+ }
+ }
+
+ private void addCommand(Element element) {
+ if (! element.getAttribute(C.Disable).equals("true")) {
+ EpfBatchCommand command = newEpfBatchCommand(element.getTagName());
+ if (command != null) {
+ command.parse(element);
+ epfBatchCommandList.add(command);
+ }
+ }
+ }
+
+ private EpfBatchCommand newEpfBatchCommand(String comandName) {
+ EpfBatchCommand cm = ebcClassMap.get(comandName);
+ return cm == null ? null : newEpfBatchCommand(cm.getClass());
+ }
+
+ public EpfBatchCommand newEpfBatchCommand(Class cls) {
+ EpfBatchCommand ret = null;
+ try {
+ ret = (EpfBatchCommand) cls.newInstance();
+ ret.setMgr(this);
+ } catch (Exception e) {
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ }
+ return ret;
+ }
+
+ public MethodLibrary loadBaseLib(String path) {
+ if (currentBaseLib != null) {
+ service.closeLibrary(currentBaseLib);
+ }
+ String libPath = rootPath + File.separator + path;
+ try {
+ currentBaseLib = XMILibraryUtil.openMethodLibrary(libPath);
+ } catch (Exception e) {
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ currentBaseLib = null;
+ }
+ return currentBaseLib;
+ }
+
+ public boolean isTrace() {
+ return trace;
+ }
+
+ public MethodLibrary getCurrentBaseLib() {
+ return currentBaseLib;
+ }
+
+ public String getRootPath() {
+ return rootPath;
+ }
+
+ public EbcReportMgr getReportMgr() {
+ return reportMgr;
+ }
+
+ public EbcLibraryService getService() {
+ return service;
+ }
+
+ public void setCurrentBaseLib(MethodLibrary currentBaseLib) {
+ this.currentBaseLib = currentBaseLib;
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchRunner.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchRunner.java
new file mode 100644
index 0000000..f6b974a
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcBatchRunner.java
@@ -0,0 +1,47 @@
+package org.eclipse.epf.toolbox.batch;
+
+import java.io.File;
+
+import org.eclipse.epf.common.utils.CommandLineRunner;
+import org.eclipse.epf.toolbox.ToolboxPlugin;
+
+public class EbcBatchRunner extends CommandLineRunner {
+
+ public boolean execute(String[] args) {
+
+ if (true || localDebug) {
+ System.out.println("LD> EpfBatchRunner.execute, args: "); //$NON-NLS-1$
+ for (int i = 0; i < args.length; i++) {
+ System.out.println("LD> args[" + i + "]: " + args[i]); //$NON-NLS-1$//$NON-NLS-2$
+ }
+ }
+
+ File inputFile = null;
+ for (int i = 0; i < args.length; i++) {
+ if (args[i].equalsIgnoreCase("-epfBatch")) { //$NON-NLS-1$
+ if (i + 1 < args.length) {
+ String path = args[i + 1];
+ inputFile = new File(path);
+ if (!inputFile.exists()) {
+ String msg = "Cannot fine the file: " + path; //$NON-NLS-1$
+ ToolboxPlugin.getDefault().getLogger().logError(msg);
+ return false;
+ }
+ break;
+ }
+ }
+ }
+
+ if (inputFile == null) {
+ String msg = "Input file is missing"; //$NON-NLS-1$
+ ToolboxPlugin.getDefault().getLogger().logError(msg);
+ return false;
+ }
+
+ EbcBatchCommandMgr rbcMgr = new EbcBatchCommandMgr(inputFile);
+ EbcExeReplies replies = rbcMgr.execute();
+
+ return true;
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReplies.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReplies.java
new file mode 100644
index 0000000..2e906b8
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReplies.java
@@ -0,0 +1,18 @@
+package org.eclipse.epf.toolbox.batch;
+
+
+public class EbcExeReplies {
+
+ public int size() {
+ return 0;
+ }
+
+ public EbcExeReply item(int i) {
+ return null;
+ }
+
+ public void add(EbcExeReply reply) {
+
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReply.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReply.java
new file mode 100644
index 0000000..21e5219
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcExeReply.java
@@ -0,0 +1,30 @@
+package org.eclipse.epf.toolbox.batch;
+
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.epf.toolbox.ToolboxPlugin;
+
+
+public class EbcExeReply {
+
+ private static final String pluginId = " ";
+
+ private MultiStatus mstatus = new MultiStatus(pluginId, 0, null, null);
+
+ public EbcExeReply() {
+ }
+
+ public boolean isOk() {
+ return mstatus.isOK();
+ }
+
+ public String toString() {
+ return mstatus.toString();
+ }
+
+ public void addStatus(int severity, String message, Throwable exception) {
+ Status status = new Status(severity, pluginId, 0, message, exception);
+ mstatus.add(status);
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcLibraryService.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcLibraryService.java
new file mode 100644
index 0000000..405b549
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcLibraryService.java
@@ -0,0 +1,114 @@
+package org.eclipse.epf.toolbox.batch;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.epf.common.utils.FileUtil;
+import org.eclipse.epf.library.project.MethodLibraryProject;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.library.util.LibraryUtil;
+import org.eclipse.epf.uma.MethodElement;
+import org.eclipse.epf.uma.MethodLibrary;
+
+/**
+ * Utility class
+ *
+ * @author Weiping Lu
+ *
+ */
+public class EbcLibraryService {
+
+ private static EbcLibraryService instance = new EbcLibraryService();
+
+ private EbcLibraryService() {
+ }
+
+ public static EbcLibraryService getInstance() {
+ return instance;
+ }
+
+ public MethodLibrary createLibrary(String path, String libName) {
+ try {
+ Map params = new HashMap();
+ params.put("library.path", path); //$NON-NLS-1$
+ MethodLibrary lib = org.eclipse.epf.library.LibraryService.getInstance()
+ .createMethodLibrary(libName, "xmi", params); //$NON-NLS-1$ //$NON-NLS-2$
+ org.eclipse.epf.library.LibraryService.getInstance().setCurrentMethodLibrary(lib);
+ return lib;
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * close the temp library and delete the library resource files
+ *
+ */
+ public void closeLibrary(MethodLibrary lib) {
+ if (lib == null) {
+ return;
+ }
+ try {
+ if (lib != org.eclipse.epf.library.LibraryService.getInstance().getCurrentMethodLibrary()) {
+ throw new UnsupportedOperationException();
+ }
+
+ File libFolder = new File(lib.eResource().getURI().toFileString()).getParentFile();
+
+ org.eclipse.epf.library.LibraryService.getInstance()
+ .closeCurrentMethodLibrary();
+
+ MethodLibraryProject.closeProject(libFolder.getAbsolutePath(), null);
+
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ public MethodLibrary loadLibrary(final String path) {
+ final MethodLibrary[] lib = new MethodLibrary[1];
+ lib[0] = null;
+
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ try {
+ MethodLibraryProject.openProject(path, new NullProgressMonitor());
+ lib[0] = LibraryUtil.loadLibrary(path + File.separator + "library.xmi");
+ MethodLibraryProject.closeProject(path, new NullProgressMonitor());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+ return lib[0];
+ }
+
+ public void deleteFolder(File folder) {
+ if (folder == null) {
+ return;
+ }
+ FileUtil.deleteAllFiles(folder.getAbsolutePath());
+ folder.delete();
+ }
+
+ public MethodElement getElement(List elements, String name) {
+ int sz = elements == null ? 0 : elements.size();
+ if (sz == 0) {
+ return null;
+ }
+ for (int i=0; i<sz; i++) {
+ Object obj = elements.get(i);
+ MethodElement elem = obj instanceof MethodElement ? (MethodElement) obj : null;
+ if (elem != null && elem.getName().equals(name)) {
+ return elem;
+ }
+ }
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcReportMgr.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcReportMgr.java
new file mode 100644
index 0000000..1dd17a8
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/EbcReportMgr.java
@@ -0,0 +1,140 @@
+package org.eclipse.epf.toolbox.batch;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.epf.common.utils.XMLUtil;
+import org.eclipse.epf.library.util.LibraryUtil;
+import org.eclipse.epf.toolbox.ToolboxPlugin;
+import org.eclipse.epf.uma.MethodElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+public class EbcReportMgr {
+
+ private EbcBatchCommandMgr ebcMgr;
+ private File reportFile;
+ private Document reportDocument;
+ private Set<Object> repoptObjectSet;
+ private static String umaPackagePath = "org.eclipse.epf.uma.impl";
+ private Element rootElement;
+
+ public EbcReportMgr(EbcBatchCommandMgr ebcMgr) {
+ this.ebcMgr = ebcMgr;
+ getReportDocument();
+ }
+
+ public void setReportFile(File reportFile) {
+ this.reportFile = reportFile;
+ }
+
+ public void saveDocument() {
+ try {
+ XMLUtil.saveDocument(getReportDocument(), reportFile.getAbsolutePath());
+ } catch (Exception e){
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ }
+ }
+
+ public Document getReportDocument() {
+ if (reportDocument == null) {
+ try {
+ reportDocument = XMLUtil.createDocument();
+ rootElement = reportDocument.createElement("Report");
+ reportDocument.appendChild(rootElement);
+ repoptObjectSet = new HashSet<Object>();
+ } catch (Exception e) {
+ ToolboxPlugin.getDefault().getLogger().logError(e);
+ }
+ }
+ return reportDocument;
+ }
+
+ public void report(Object obj) {
+ if (repoptObjectSet.contains(obj)) {
+ return;
+ }
+ report_(obj);
+ repoptObjectSet.add(obj);
+ }
+
+ private void report_(Object obj) {
+ Document doc = getReportDocument();
+
+ String tag = null;
+
+ String clsName = obj.getClass().getName();
+ if (clsName.startsWith(umaPackagePath)) {
+ tag = clsName.substring(25);
+ if (tag.endsWith("Impl")) {
+ int ix = tag.length() - 4;
+ tag = tag.substring(0, ix);
+ }
+ }
+
+ Resource res = null;
+ MethodElement me = null;
+ if (obj instanceof MethodElement) {
+ me = (MethodElement) obj;
+ res = me.eResource();
+ }
+
+ String path = res == null ? "?" : res.getURI().toFileString();
+
+ Element elem = doc.createElement(tag);
+ elem.setAttribute("path", path);
+
+ String textContent = obj.toString();
+ int ix = textContent.indexOf("(name:");
+ if (ix > 0) {
+ textContent = textContent.substring(ix);
+ }
+
+ elem.setTextContent(textContent);
+
+ if (me != null) {
+ List features = LibraryUtil.getStructuralFeatures(me);
+
+ if (features != null) {
+ for (int i = 0; i < features.size(); i++) {
+ EStructuralFeature feature = (EStructuralFeature) features
+ .get(i);
+ if (feature instanceof EReference) {
+ EReference ref = (EReference) feature;
+ if (!ref.isContainment()) {
+ Object value = me.eGet(ref);
+ if (value != null) {
+ if (value instanceof List) {
+ for (Object subValue: (List) value) {
+ addRefElem(doc, elem, ref, subValue);
+ }
+ } else {
+ addRefElem(doc, elem, ref, value);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ rootElement.appendChild(elem);
+ }
+
+ private void addRefElem(Document doc, Element elem, EReference ref, Object value) {
+ Element refElem = doc.createElement(ref
+ .getName());
+ elem.appendChild(refElem);
+ String str = value.toString();
+ if (value instanceof MethodElement) {
+ MethodElement me = (MethodElement) value;
+ str = me.getName() + ", " + me.getGuid();
+ }
+ refElem.setTextContent(str);
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportConfiguration.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportConfiguration.java
new file mode 100644
index 0000000..1bec031
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportConfiguration.java
@@ -0,0 +1,57 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.epf.export.services.ConfigurationExportData;
+import org.eclipse.epf.export.services.ConfigurationExportService;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodConfiguration;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Element;
+
+public class EbcExportConfiguration extends EpfBatchCommandImpl {
+
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.ExportFolderPath, element.getAttribute(C.ExportFolderPath));
+ setAttribute(C.SelectedConfigName, element.getAttribute(C.SelectedConfigName));
+ }
+
+ protected void executeBody(EbcExeReply reply) {
+ MethodLibrary currLib = getMgr().getCurrentBaseLib();
+ if (currLib == null) {
+ return;
+ }
+
+ String selectedConfigName = getAttribute(C.SelectedConfigName);
+ MethodConfiguration config = (MethodConfiguration) getMgr().getService().getElement
+ (currLib.getPredefinedConfigurations(), selectedConfigName);
+ if (config == null) {
+ return;
+ }
+
+ String path = getAttribute(C.ExportFolderPath);
+ String exportFolderPath = getMgr().getRootPath() + File.separator + path;
+ File exportFolder = new File(exportFolderPath);
+
+ final ConfigurationExportData data = new ConfigurationExportData();
+ data.llData.setLibName(currLib.getName());
+ data.llData.setParentFolder(exportFolder.getAbsolutePath());
+ data.exportOneConfig = true;
+ data.exportConfigSpecs = false;
+ data.selectedConfigs = new ArrayList();
+ data.selectedConfigs.add(config);
+
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ (new ConfigurationExportService(data)).run(new NullProgressMonitor());
+ }
+ });
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportPlugins.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportPlugins.java
new file mode 100644
index 0000000..9282c95
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportPlugins.java
@@ -0,0 +1,94 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.epf.export.services.PluginExportData;
+import org.eclipse.epf.export.services.PluginExportService;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.eclipse.epf.uma.MethodPlugin;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class EbcExportPlugins extends EpfBatchCommandImpl {
+
+ private List<MethodPlugin> selectedPlugins;
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.ExportAll, element.getAttribute(C.ExportAll));
+ setAttribute(C.ExportFolderPath, element.getAttribute(C.ExportFolderPath));
+ }
+
+ public void parseAtExecute() {
+ Element element = getElement();
+
+ MethodLibrary lib = getMgr().getCurrentBaseLib();
+ boolean exportAll = parseBoolean(C.ExportAll, false);
+ if (exportAll) {
+ selectedPlugins = new ArrayList<MethodPlugin>(lib.getMethodPlugins());
+ } else {
+ Map<String, MethodPlugin> nameMap = new HashMap<String, MethodPlugin>();
+ for (MethodPlugin plugin : (List<MethodPlugin>) lib.getMethodPlugins()) {
+ nameMap.put(plugin.getName(), plugin);
+ }
+
+ selectedPlugins = new ArrayList<MethodPlugin>();
+ NodeList nodes = element.getChildNodes();
+ int sz = nodes == null ? 0 : nodes.getLength();
+ if (sz > 0) {
+ for (int i=0; i<sz; i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element) {
+ Element cElement = (Element) node;
+ if (cElement.getTagName().equals(C.SelectedPlugin)) {
+ String name = cElement.getAttribute(C.Name);
+ MethodPlugin plugin = nameMap.get(name);
+ if (plugin != null) {
+ selectedPlugins.add(plugin);
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+ MethodPlugin plugin = (MethodPlugin) selectedPlugins.get(0);
+ File file = new File(plugin.eResource().getURI().toFileString());
+ file = file.getParentFile().getParentFile();
+
+ String path = getAttribute(C.ExportFolderPath);
+ String exportFolderPath = getMgr().getRootPath() + File.separator + path;
+ File exportFolder = new File(exportFolderPath);
+
+ final PluginExportData data = new PluginExportData();
+ data.llData.setLibName(file.getName());
+ data.llData.setParentFolder(exportFolder.getAbsolutePath());
+ data.setSelectedPlugins(selectedPlugins);
+ data.buildAssociatedConfigMap();
+
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ try {
+ (new PluginExportService(data)).run(new NullProgressMonitor());
+ } catch (Exception e) {
+ reply.addStatus(Status.ERROR, e.getMessage(), e);
+ }
+ }
+ });
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportXml.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportXml.java
new file mode 100644
index 0000000..2da7b65
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcExportXml.java
@@ -0,0 +1,61 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.epf.export.xml.services.ExportXMLData;
+import org.eclipse.epf.export.xml.services.ExportXMLService;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Element;
+
+public class EbcExportXml extends EpfBatchCommandImpl {
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.XmlExportFilePath, element.getAttribute(C.XmlExportFilePath));
+ }
+
+ public EbcExeReply execute() {
+ traceBeforeExcute();
+ final EbcExeReply reply = new EbcExeReply();
+
+ try {
+ executeBody(reply);
+ } catch (Exception e) {
+ reply.addStatus(Status.ERROR, e.getMessage(), e);
+ }
+
+ traceAfterExcute(reply);
+ return reply;
+ }
+
+
+
+ public void executeBody(EbcExeReply reply) {
+
+ String relPath = getAttribute(C.XmlExportFilePath);
+
+ MethodLibrary lib = getMgr().getCurrentBaseLib();
+ File file = new File(lib.eResource().getURI().toFileString());
+ file = file.getParentFile().getParentFile();
+
+ String absPath = getMgr().getRootPath() + File.separator + relPath;
+ File exportFile = new File(absPath);
+
+ final ExportXMLData data = new ExportXMLData();
+ data.setExportType(ExportXMLData.EXPORT_METHOD_LIBRARY);
+ data.setXMLFile(exportFile.getAbsolutePath());
+
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ (new ExportXMLService(data)).doExport(new NullProgressMonitor());
+ }
+ });
+
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportConfiguration.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportConfiguration.java
new file mode 100644
index 0000000..80c90c5
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportConfiguration.java
@@ -0,0 +1,94 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.epf.importing.services.ConfigurationImportData;
+import org.eclipse.epf.importing.services.ConfigurationImportService;
+import org.eclipse.epf.importing.services.ElementDiffTree;
+import org.eclipse.epf.library.edit.util.TngUtil;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodElement;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.eclipse.epf.uma.MethodPackage;
+import org.eclipse.epf.uma.ProcessComponent;
+import org.w3c.dom.Element;
+
+public class EbcImportConfiguration extends EpfBatchCommandImpl {
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.ImportFolderPath, element.getAttribute(C.ImportFolderPath));
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+ String relPath = getAttribute(C.ImportFolderPath);
+ String absPath = getMgr().getRootPath() + File.separator + relPath;
+ File file = new File(absPath);
+
+ ConfigurationImportData data = new ConfigurationImportData();
+ data.llData.setLibName(file.getName());
+ data.llData.setParentFolder(file.getAbsolutePath());
+
+ final ConfigurationImportService importService = new ConfigurationImportService(data);
+ importService.analyze(new NullProgressMonitor());
+
+ Object[] elements = getElements(importService.getDiffTree());
+ data.importList.clear();
+ for ( int i = 0; i < elements.length; i++ ) {
+ data.importList.add(elements[i]);
+ }
+
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ try {
+ importService.performImport(new NullProgressMonitor());
+ MethodLibrary lib = org.eclipse.epf.library.LibraryService.getInstance().getCurrentMethodLibrary();
+ getMgr().setCurrentBaseLib(lib);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ });
+ }
+
+ private boolean selectable(ElementDiffTree node) {
+ if (node instanceof ProcessComponent) {
+ return false;
+ }
+ if (node.isOldOnly()) {
+ return false;
+ }
+ MethodElement base = node.getBaseElement();
+ if ( (base instanceof MethodPackage)
+ && TngUtil.isRootCutomCategoryPackage((MethodPackage)base) ) {
+ return false;
+ }
+ return true;
+ }
+
+ private void selectNodes(ElementDiffTree node, ArrayList selectedNodes) {
+ if (! selectable(node)) {
+ return;
+ }
+ selectedNodes.add(node);
+ List cnodes = node.getChildren();
+ int sz = cnodes == null ? 0 : cnodes.size();
+ for (int i=0; i<sz; i++) {
+ ElementDiffTree cnode = (ElementDiffTree) cnodes.get(i);
+ selectNodes(cnode, selectedNodes);
+ }
+ }
+
+ private Object[] getElements(ElementDiffTree root) {
+ ArrayList selectedNodes = new ArrayList();
+ selectNodes(root, selectedNodes);
+ return selectedNodes.toArray();
+ }
+
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportPlugins.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportPlugins.java
new file mode 100644
index 0000000..fb4aa82
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportPlugins.java
@@ -0,0 +1,92 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.epf.importing.services.PluginImportData;
+import org.eclipse.epf.importing.services.PluginImportingService;
+import org.eclipse.epf.importing.services.PluginImportData.PluginInfo;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.jface.dialogs.ProgressMonitorDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class EbcImportPlugins extends EpfBatchCommandImpl {
+
+ private Set<String> selectedPlugins;
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.ImportAll, element.getAttribute(C.ImportAll));
+ setAttribute(C.ImportFolderPath, element
+ .getAttribute(C.ImportFolderPath));
+
+ boolean importAll = parseBoolean(C.ImportAll, false);
+
+ if (!importAll) {
+ selectedPlugins = new HashSet<String>();
+ NodeList nodes = element.getChildNodes();
+ int sz = nodes == null ? 0 : nodes.getLength();
+ for (int i = 0; i < sz; i++) {
+ Node node = nodes.item(i);
+ if (node instanceof Element) {
+ Element cElement = (Element) node;
+ if (cElement.getTagName().equals(C.SelectedPlugin)) {
+ String name = cElement.getAttribute(C.Name);
+ selectedPlugins.add(name);
+ }
+ }
+ }
+ }
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+
+ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
+ public void execute(IProgressMonitor monitor) {
+ try {
+ boolean importAll = parseBoolean(C.ImportAll, false);
+
+ String importLibPath = getAttribute(C.ImportFolderPath);
+ File importLibFolder = new File(importLibPath);
+
+ PluginImportData data = new PluginImportData();
+ data.llData.setLibName(importLibFolder.getName());
+ data.llData.setParentFolder(importLibFolder
+ .getAbsolutePath());
+ final PluginImportingService service = new PluginImportingService(
+ data);
+ service.validate(null);
+
+ List importPlugins = data.getPlugins();
+ for (int i = 0; i < importPlugins.size(); i++) {
+ PluginInfo info = (PluginInfo) importPlugins
+ .get(i);
+ info.selected = importAll || selectedPlugins.contains(info.name);
+ }
+ service.performImport(monitor);
+ } catch (Exception e) {
+ reply.addStatus(Status.ERROR, e.getMessage(), e);
+ } finally {
+ monitor.done();
+ }
+ }
+ };
+
+ try {
+ ProgressMonitorDialog pmDialog = new ProgressMonitorDialog(
+ Display.getCurrent().getActiveShell());
+ pmDialog.run(true, false, operation);
+ } catch (Exception e) {
+ reply.addStatus(Status.ERROR, e.getMessage(), e);
+ }
+ }
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportXml.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportXml.java
new file mode 100644
index 0000000..63d16e1
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcImportXml.java
@@ -0,0 +1,48 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.io.File;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.epf.importing.xml.services.ImportXMLService;
+import org.eclipse.epf.library.services.SafeUpdateController;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Element;
+
+public class EbcImportXml extends EpfBatchCommandImpl {
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.XmlImportFilePath, element.getAttribute(C.XmlImportFilePath));
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+
+ boolean merge = true;
+ String relPath = getAttribute(C.XmlImportFilePath);
+ String absPath = getMgr().getRootPath() + File.separator + relPath;
+
+ final File file = new File(absPath);
+
+ final boolean overwrite = ! merge;
+ SafeUpdateController.syncExec(new Runnable() {
+ public void run() {
+ try {
+ ImportXMLService importService = new ImportXMLService();
+ importService.setOverwrite(overwrite);
+ importService.loadXml(file.getAbsolutePath());
+ importService.doImport(new NullProgressMonitor());
+ MethodLibrary lib = org.eclipse.epf.library.LibraryService.getInstance().getCurrentMethodLibrary();
+ getMgr().setCurrentBaseLib(lib);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ });
+
+
+ }
+
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcOpenLibrary.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcOpenLibrary.java
new file mode 100644
index 0000000..ade482a
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcOpenLibrary.java
@@ -0,0 +1,45 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.eclipse.epf.library.edit.util.TngUtil;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.uma.MethodElement;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Element;
+
+public class EbcOpenLibrary extends EpfBatchCommandImpl {
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.Path, element.getAttribute(C.Path));
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+ String path = getAttribute(C.Path);
+ MethodLibrary lib = getMgr().loadBaseLib(path);
+
+ if (localDebug) {
+ Collection col = lib.eContents();
+ for (Object obj : col) {
+ System.out.println("LD> obj: " + obj);
+ }
+ }
+
+ if (false) {
+ for (Iterator it = lib.eAllContents(); it.hasNext();) {
+ Object obj = it.next();
+ if (obj instanceof MethodElement) {
+ MethodElement me = (MethodElement) obj;
+ String label = TngUtil.getLabelWithPath(me);
+ getMgr().trace("LD> " + me.getClass().getName().substring(25) + ": " + label);
+ }
+ }
+
+ }
+
+ }
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcReportMethodElement.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcReportMethodElement.java
new file mode 100644
index 0000000..64ebb52
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EbcReportMethodElement.java
@@ -0,0 +1,86 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.toolbox.batch.EbcReportMgr;
+import org.eclipse.epf.uma.MethodElement;
+import org.eclipse.epf.uma.MethodLibrary;
+import org.w3c.dom.Element;
+
+public class EbcReportMethodElement extends EpfBatchCommandImpl {
+
+ EbcReportMgr reportMgr;
+
+ public void parse(Element element) {
+ super.parse(element);
+ setAttribute(C.ElementType, element.getAttribute(C.ElementType));
+ setAttribute(C.Recursive, element.getAttribute(C.Recursive));
+ setAttribute(C.Name, element.getAttribute(C.Name));
+
+ reportMgr = getMgr().getReportMgr();
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+ boolean recursive = parseBoolean(C.Recursive, false);
+ for (MethodElement elem: getReportedElements()) {
+ report(elem, recursive);
+ }
+ }
+
+ private Collection<MethodElement> getReportedElements() {
+ MethodLibrary lib = getMgr().getCurrentBaseLib();
+ String elementType = getAttribute(C.ElementType);
+ String name = getAttribute(C.Name);
+
+ Set<MethodElement> reportedSet = new LinkedHashSet<MethodElement>();
+
+ if (elementType.equals("MethodLibrary")) {
+ reportedSet.add(lib);
+ } else {
+ boolean showAll = name.equals("*");
+
+ for (Iterator it = lib.eAllContents(); it.hasNext();) {
+ Object obj = it.next();
+ if (obj instanceof MethodElement) {
+ MethodElement me = (MethodElement) obj;
+ if (showAll || me.getName().equals(name)) {
+ if (me.getClass().getName().contains(elementType)) {
+ reportedSet.add(me);
+ }
+ }
+ }
+ }
+ }
+
+ return reportedSet;
+ }
+
+ private void reportContents(List contents) {
+ if (contents == null) {
+ return;
+ }
+ for (int i = 0; i < contents.size(); i++) {
+ report(contents.get(i), true);
+ }
+ }
+
+
+
+ private void report(Object obj, boolean recursive) {
+ reportMgr.report(obj);
+ if (recursive) {
+ if (obj instanceof EObject) {
+ reportContents(((EObject) obj).eContents());
+ }
+ }
+ }
+
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommand.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommand.java
new file mode 100644
index 0000000..c2a9cfb
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommand.java
@@ -0,0 +1,16 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.toolbox.batch.EbcBatchCommandMgr;
+import org.w3c.dom.Element;
+
+
+public interface EpfBatchCommand {
+
+ void setMgr(EbcBatchCommandMgr mgr);
+ void setAttribute(String attName, String attValue);
+ String getAttribute(String attName);
+ void parse(Element element);
+ EbcExeReply execute();
+
+}
diff --git a/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommandImpl.java b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommandImpl.java
new file mode 100644
index 0000000..4ef4e21
--- /dev/null
+++ b/org.eclipse.epf.toolbox/src/org/eclipse/epf/toolbox/batch/commands/EpfBatchCommandImpl.java
@@ -0,0 +1,119 @@
+package org.eclipse.epf.toolbox.batch.commands;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.Status;
+import org.eclipse.epf.toolbox.batch.C;
+import org.eclipse.epf.toolbox.batch.EbcExeReply;
+import org.eclipse.epf.toolbox.batch.EbcBatchCommandMgr;
+import org.w3c.dom.Element;
+
+public class EpfBatchCommandImpl implements EpfBatchCommand {
+
+ private boolean verbose = false;
+ private Element element;
+ protected static boolean localDebug = false;
+ private EbcBatchCommandMgr mgr;
+ private Map atttibuteMap = new LinkedHashMap();
+
+ public void setMgr(EbcBatchCommandMgr mgr) {
+ this.mgr = mgr;
+ }
+
+ protected Map getAttributeMap() {
+ return atttibuteMap;
+ }
+
+ public void setAttribute(String attName, String attValue) {
+ if (attValue != null && attValue.length() > 0) {
+ atttibuteMap.put(attName, attValue);
+ }
+ }
+
+ public String removeAttribute(String attName) {
+ return (String) atttibuteMap.remove(attName);
+ }
+
+ public String getAttribute(String attName) {
+ return (String) atttibuteMap.get(attName);
+ }
+
+ public void parse(Element element) {
+ this.element = element;
+ /*setAttribute(AT_Verbose, element.getAttribute(AT_Verbose));
+ verbose = parseBoolean(AT_Verbose, verbose);*/
+ }
+
+ public void parseAtExecute() {
+ }
+
+ protected boolean getVerbose() {
+ return verbose;
+ }
+
+ protected Element getElement() {
+ return element;
+ }
+
+ protected void parseChildren(Element element) {
+ }
+
+ protected EbcBatchCommandMgr getMgr() {
+ return mgr;
+ }
+
+ public EbcExeReply execute() {
+ traceBeforeExcute();
+ final EbcExeReply reply = new EbcExeReply();
+ parseAtExecute();
+
+ try {
+ executeBody(reply);
+ } catch (Exception e) {
+ reply.addStatus(Status.ERROR, e.getMessage(), e);
+ }
+
+ traceAfterExcute(reply);
+ return reply;
+ }
+
+ protected void executeBody(final EbcExeReply reply) {
+ }
+
+ public String tagName() {
+ return mgr == null ? null : mgr.getTagName(this);
+ }
+
+ protected boolean parseBoolean(String att, boolean defaultValue) {
+ String toCheckStr = defaultValue ? "false" : "true";
+ String str = getAttribute(att);
+ if (str != null && str.equalsIgnoreCase(toCheckStr)) {
+ return !defaultValue;
+ }
+ return defaultValue;
+ }
+
+ protected int parseInteger(String att, int defaultValue) {
+ if (att != null && att.length() > 0) {
+ return Integer.parseInt(att);
+ }
+ return defaultValue;
+ }
+
+ protected void traceBeforeExcute() {
+ if (getMgr().isTrace()) {
+ String id = getElement().getAttribute(C.Id);
+ getMgr().trace("Begin " + getMgr().getTagName(this) + ".execute, id: " + id);
+ }
+ }
+
+ protected void traceAfterExcute(EbcExeReply reply) {
+ if (getMgr().isTrace()) {
+ String id = getElement().getAttribute(C.Id);
+ getMgr().trace("End " + getMgr().getTagName(this) + ".execute, id: " + id + ", reply: " + reply);
+ getMgr().trace("");
+ }
+ }
+
+}