When adding new files, would it be possible to use
apache headers instead of some misleading copyright
assignments ?

On 8/1/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Author: mszefler
Date: Tue Aug  1 11:52:47 2006
New Revision: 427676

URL: http://svn.apache.org/viewvc?rev=427676&view=rev
Log:
ODE-16 Replaced missing tools.

Added:
    incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/
    incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/AliasElement.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceElement.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceFileSet.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrOperation.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrTask.java
    incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAdd.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAlias.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrDrop.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrGet.java

    
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrList.java

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/AliasElement.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/AliasElement.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/AliasElement.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/AliasElement.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,86 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.ant;
+
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.tools.ant.Project;
+
+
+/**
+ * Sub-element of [EMAIL PROTECTED] org.apache.ode.tools.rr.ant.RrTask} for
+ * setting up URI <em>aliases</em>. An alias is analogous
+ * to a "soft link": it makes a resource already in the repository
+ * accessible via an alternate URI.
+ *
+ * <p>
+ * For example, the following:
+ * <pre>
+ * &lt;rr ... &gt;
+ *    &lt;resource uri="uri:bar" file="bar.xml" /&gt;
+ *    &lt;alias fromuri="uri:foo" touri="uri:bar" /&gt;
+ * &lt;/rr &gt;
+ * </pre>
+ * creates a resource repository where the XML resource "bar.xml" is
accessible both
+ * via the "uri:foo" and "uri:bar" URIs.
+ */
+public class AliasElement implements RrOperation {
+
+  private String _fromUri;
+  private String _toUri;
+
+  /**
+   * Set the alias URI.
+   * @param from alias URI
+   */
+  public void setFromUri(String from) {
+    _fromUri = from;
+  }
+
+  /**
+   * Get the alias URI.
+   * @return alias URI
+   */
+  public String getFromUri() {
+    return _fromUri;
+  }
+
+  /**
+   * Set the <em>aliased</em> URI
+   * @param to <em>aliased</em> URI
+   */
+  public void setToUri(String to) {
+    _toUri = to;
+  }
+
+  /**
+   * Get the <em>aliased</em> URI.
+   * @return the <em>aliased</em> URI
+   */
+  public String getToUri() {
+    return _toUri;
+  }
+
+  public void execute(RrTask executingTask, ResourceRepositoryBuilder
rrb)
+    throws URISyntaxException, IOException {
+    String from = _fromUri;
+    String to = _toUri;
+
+    if (from == null || to == null) {
+      from = ((from == null) ? "<<null>>" : from);
+      to = ((to == null) ? "<<null>>" : to);
+      executingTask.log("Unable to alias " + from + " to " + to + ";
skipping.", Project.MSG_WARN);
+      return;
+    }
+
+    rrb.addAlias(new URI(from), new URI(to));
+    executingTask.log("Aliased " + from + " to " + to,
Project.MSG_VERBOSE);
+  }
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceElement.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceElement.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceElement.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceElement.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,113 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.ant;
+
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+
+
+/**
+ * Sub-element of the [EMAIL PROTECTED] org.apache.ode.tools.rr.ant.RrTask} 
used to
add
+ * individual resources to the repository. This object maintains two
pieces
+ * of information: the logical name of the resource (it's URI within the
+ * resource repository) and the physical location of the resource (either
+ * a [EMAIL PROTECTED] File} or URL).
+ */
+public class ResourceElement implements RrOperation {
+
+       /** Location of the resource (file) */
+       private File _file;
+
+       /** Location of the resource (URL) */
+  private String _location;
+
+  /** Optional URI. */
+  private String _uri;
+
+
+  /**
+   * The physical location (URL) of the resource. This location must be
+   * accessible through the standard Java [EMAIL PROTECTED] java.net.URL} 
mechanism.
+   * @param url resource location (URL string)
+   */
+  public void setLocation(String url) {
+    _location = url;
+  }
+
+  /**
+   * Get the physical location of the resource.
+   * @return resource location (URL string)
+   */
+  public String getLocation() {
+    return _location;
+  }
+
+  /**
+   * Set the logical name of the resource. The logical name, will be the
"primary key"
+   * of the resource in the repository; it must be in URI form.
+   * @param uri logical name of the resource (URI string)
+   */
+  public void setUri(String uri) {
+       _uri = uri;
+  }
+
+  /**
+   * Get the logical name of the resource.
+   * @return logical name of the resource (URI string)
+   */
+  public String getUri() {
+       return _uri;
+  }
+
+  /**
+   * Get the file containing the resource (as a file).
+   * @return file containing the resource
+   */
+  public File getFile() {
+       return _file;
+  }
+
+  /**
+   * Set the physical location of the resource to be a local file. This
may
+   * be used as an alternative to [EMAIL PROTECTED] #setLocation(String)}.
+   * @param file
+   */
+  public void setFile(File file) {
+       _file = file;
+  }
+
+  public void execute(RrTask executingTask, ResourceRepositoryBuilder
rrb)
+    throws URISyntaxException, IOException {
+    URL url;
+    URI uri;
+
+    if (_location != null) {
+      url = new URL(_location);
+      uri = url.toURI();
+    } else if (_file != null) {
+      url = _file.toURI().toURL();
+      uri = _file.toURI();
+    } else {
+      throw new BuildException("Must specify a resource URL or file!");
+    }
+
+    if (_uri != null) {
+      uri = new URI(_uri);
+    }
+
+    rrb.addURI(uri, url);
+    executingTask.log("Added " + url + " as " + uri, Project.MSG_VERBOSE
);
+  }
+
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceFileSet.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceFileSet.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceFileSet.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/ResourceFileSet.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,152 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.ant;
+
+import org.apache.ode.utils.fs.TempFileManager;
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+import org.apache.ode.utils.xml.capture.XmlDependencyScanner;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+
+/**
+ * Extension of ANT <code>fileset</code> that is used with [EMAIL PROTECTED] 
RrTask}
to
+ * specify a collection of resources that is to be included in the
repository.
+ *
+ * <p>
+ * In addition to the standard features of [EMAIL PROTECTED] FileSet} this 
class
provides
+ * a destination URI and a recursive flag. The destination URI (if
specified)
+ * makes the resources found through the fileset appear relative to an
arbitrary
+ * base URI in the resource repository. For example:
+ * <pre>
+ * &lt;rr ... &gt;
+ *    &lt;rrfileset desturi="http://www.foo.com/bar/"; dir="."
includes="*.xml" /&gt;
+ * &lt;/rr &gt;
+ * </pre>
+ * would have the effect of making a file "baz.wsdl" in the local
directory appear
+ * in the resource repository under URI "http://www.foo.com/bar/baz.wsdl
".
+ * </p>
+ *
+ * <p>
+ * In addition to URI mapping, this class provides a recursion
capability. When
+ * the <code>recursive="yes"</code> attribute is given, each resource in
the fileset
+ * will be scanned for imports and each import will also be included in
the resource
+ * repository. The scanning mechanism is aware of XML Schema, WSDL, and
BPEL
+ * <code>import</code> (and <code>include</code>) statements.
+ * </p>
+ *
+ */
+public class ResourceFileSet extends FileSet implements RrOperation {
+  /** Recursive (deep) resource imports. */
+  private boolean _recursive;
+
+  /** Alias (Destination) URI. */
+  private String _destUri;
+
+
+  /**
+   * Get the destination URI root.
+   * @return destination URI root
+   */
+  public String getDestUri() {
+    return _destUri;
+  }
+
+  /**
+   * Set the destination URI root.
+   * @param desturi destination URI root
+   */
+  public void setDestUri(String desturi) {
+    _destUri = desturi;
+  }
+
+  /**
+   * Is the <code>recursive</code> flag set?
+   * @return state of the <code>recursive</code> flag.
+   */
+  public boolean isRecursive() {
+    return _recursive;
+  }
+
+  /**
+   * Set the <code>recursive</code> flag.
+   * @param recursive recursive flag.
+   */
+  public void setRecursive(boolean recursive) {
+    _recursive = recursive;
+  }
+
+  public void execute(RrTask executingTask, ResourceRepositoryBuilder
rrb) throws BuildException {
+
+    URI destRoot = null;
+    if (_destUri != null)
+      try {
+        destRoot = new URI(_destUri);
+      } catch (URISyntaxException e) {
+        TempFileManager.cleanup();
+        log("Malformed destination URI: " + _destUri, Project.MSG_ERR);
+        throw new BuildException("Malformed destination URI: "  +
_destUri);
+      }
+
+    String[] files = this.getDirectoryScanner(this.getProject
()).getIncludedFiles();
+    File dir = this.getDir(this.getProject());
+
+    URI srcRoot = dir.toURI();
+    List<URI> todo = new LinkedList<URI>();
+    XmlDependencyScanner scanner = new XmlDependencyScanner();
+    for (int i=0; i < files.length; ++i) {
+      File f = new File(dir,files[i]);
+      if (this.isRecursive()) {
+        scanner.process(f.toURI());
+        if (scanner.isError()) {
+          throw new BuildException("Error scanning " + f.toURI() + ";
resources could not be loaded: " + scanner.getErrors().keySet());
+        }
+      } else {
+        todo.add(f.toURI());
+      }
+    }
+
+    if (this.isRecursive()) {
+      todo.addAll(scanner.getURIs());
+    }
+
+    for (Iterator<URI> i = todo.iterator();i.hasNext(); ) {
+      URI src = i.next();
+      URI relative = srcRoot.relativize(src);
+      URI dest = destRoot == null ? src : destRoot.resolve(relative);
+      URL fu;
+      try {
+        fu = src.toURL();
+      } catch (MalformedURLException mue) {
+        log("Unrecognized URI: " + src,Project.MSG_ERR);
+        if (executingTask.getFailOnError()) {
+          throw new BuildException("Unrecognized URI: " + src);
+        }
+        continue;
+      }
+      try {
+        rrb.addURI(dest,fu);
+        log("Added " + src + " as " + dest,Project.MSG_VERBOSE);
+      } catch (Exception zre) {
+        log("Error writing resource " + dest + " to repository.",
Project.MSG_ERR);
+        if (executingTask.getFailOnError()) {
+          throw new BuildException(zre);
+        }
+      }
+    }
+  }
+
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrOperation.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrOperation.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrOperation.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrOperation.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,22 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.ant;
+
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+
+/**
+ * Simple common interface for RR operations.
+ */
+public interface RrOperation {
+
+  public void execute(RrTask executingTask, ResourceRepositoryBuilder
rrb)
+    throws URISyntaxException, IOException;
+
+}
+

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrTask.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrTask.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrTask.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/ant/RrTask.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,118 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.ant;
+
+import org.apache.ode.utils.fs.TempFileManager;
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+
+/**
+ * ANT Task for constructing PXE resource repositories.
+ * <p>
+ * Usage:
+ * <pre>
+ *    &lt;rr failOnError="yes/no" rrdir="destination.rr"&gt;
+ *        &lt;rrfileset ... /&gt;*
+ *        &lt;resource ... /&gt;*
+ *        &lt;alias ... /&gt;*
+ *    &lt;/rr&gt;
+ * </pre>
+ *
+ * Each resource repository may contain sub-elements corresponding to:
collections
+ * of resource repositories (<code>rrfileset</codde>s), individual
resources
+ * (<code>resource</code>s), or resource aliases (<code>alias</code>es).
+ * @see AliasElement
+ * @see ResourceElement
+ * @see ResourceFileSet
+ * </p>
+ */
+public class RrTask extends Task {
+
+  private List<RrOperation> _operations = new ArrayList<RrOperation>();
+  private boolean _failOnError = true;
+  private File _rr;
+
+  /**
+   * Returns the fail-on-error flag.
+   * @return true or false
+   */
+  public boolean getFailOnError() {
+    return _failOnError;
+  }
+
+  /**
+   * Set the fail-on-error flag.
+   * @param b value of the fail-on-error flag
+   */
+  public void setFailOnError(boolean b) {
+    _failOnError = b;
+  }
+
+  /**
+   * Set the destination <em>directory</em> (resource repositories are
+   * directories, not files).
+   * @param f
+   */
+  public void setRrDir(File f) {
+    _rr = f;
+  }
+
+  public void addRrFileSet(ResourceFileSet fs) {
+    _operations.add(fs);
+  }
+
+  public void addConfiguredResource(ResourceElement ue) {
+    _operations.add(ue);
+  }
+
+  public void addConfiguredAlias(AliasElement uae) {
+    _operations.add(uae);
+  }
+
+  public void execute() throws BuildException {
+    ResourceRepositoryBuilder wcr;
+    _rr.mkdirs();
+
+    try {
+      wcr = new ResourceRepositoryBuilder(_rr);
+    } catch (IOException ioex) {
+      TempFileManager.cleanup();
+      log("I/O Error",Project.MSG_ERR);
+      if (_failOnError) {
+        throw new BuildException(ioex);
+      }
+      log("Aborting RR modification operation.",Project.MSG_INFO);
+      return;
+    }
+
+    Iterator<RrOperation> it = _operations.iterator();
+    while (it.hasNext()) {
+      RrOperation o = it.next();
+      try {
+        o.execute(this, wcr);
+      } catch (Exception e) {
+        log("Error processing " + o, Project.MSG_ERR);
+        if (_failOnError) {
+          throw new BuildException(e);
+        }
+        break;
+      }
+    }
+
+    TempFileManager.cleanup();
+  }
+
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAdd.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAdd.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAdd.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAdd.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,171 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.cline;
+
+import org.apache.ode.utils.cli.*;
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+import org.apache.ode.utils.xml.capture.XmlDependencyScanner;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * Command-line tool for adding resoruces to resource repository.
+ * @see [EMAIL PROTECTED] com.fs.utils.rr.ResourceRepository}
+ * @see [EMAIL PROTECTED] com.fs.utils.rr.URLResourceRepository}
+ * @see [EMAIL PROTECTED] ResourceRepositoryBuilder}
+ */
+public class RrAdd extends BaseCommandlineTool {
+
+  private static final Flag ARG_RECURSE = new Flag("r","add recursively",
true);
+  private static final FlagWithArgument ARG_BASEDIR = new
FlagWithArgument("src","src-uri", "source URI (for resolving realtive URIs)
", true);
+  private static final FlagWithArgument ARG_ALIAS = new
FlagWithArgument("dest", "dest-uri", "destination URI", true);
+  private static final Argument ARG_RRDIR = new Argument("rr-dir",
"destination resource repository directory" ,false);
+  private static final MultiArgument ARG_SRC = new
MultiArgument("resource", "resource URI(s)", false);
+  private static final Fragments CLINE = new Fragments(new
CommandlineFragment[] {
+      LOGGING, ARG_RECURSE, ARG_BASEDIR, ARG_ALIAS,  ARG_RRDIR, ARG_SRC
+  });
+
+  private static final String SYNOPSIS = "add resources to a resource
repository.";
+
+  public static void main(String[] args) {
+       setClazz(RrAdd.class);
+    if (args.length == 0 || HELP.matches(args)) {
+      ConsoleFormatter.printSynopsis(getProgramName(),SYNOPSIS, new
Fragments[] {
+        CLINE, HELP
+      });
+      System.exit(0);
+    } else if (!CLINE.matches(args)) {
+      consoleErr("INVALID COMMANDLINE: Try \"" + getProgramName() + "
-h\" for help.");
+      System.exit(-1);
+    }
+    registerTempFileManager();
+    initLogging();
+    boolean quiet = QUIET_F.isSet();
+    ResourceRepositoryBuilder rr = null;
+    File rrdir = new File(ARG_RRDIR.getValue());
+    rrdir.mkdirs();
+    try {
+      rr = new ResourceRepositoryBuilder(rrdir);
+    } catch (FileNotFoundException fnf) {
+      consoleErr("Resource repository not found.");
+      System.exit(-2);
+    } catch (IOException e) {
+      consoleErr("Error reading resource repository.");
+      System.exit(-2);
+    }
+
+    URI srcRoot,destRoot;
+    try {
+      srcRoot = ARG_BASEDIR.getValue() == null ? new File("./").toURI() :
new URI(ARG_BASEDIR.getValue());
+    } catch (URISyntaxException e) {
+      consoleErr("Malformed source URI: " + ARG_BASEDIR.getValue());
+      System.exit(-2);
+      return;
+    }
+
+    if (!srcRoot.isAbsolute()) {
+      consoleErr("Source URI must be absolute: " + srcRoot);
+      System.exit(-2);
+      return;
+    }
+
+    try {
+      destRoot = ARG_ALIAS.getValue() == null ? null :  new
URI(ARG_ALIAS.getValue());
+    } catch (URISyntaxException e) {
+      consoleErr("Malformed destination URI: " + ARG_ALIAS.getValue());
+      System.exit(-2);
+      return;
+    }
+
+    URI original[] = new URI[ARG_SRC.getValues().length];
+    URI source[] = new URI[original.length];
+    URI dest[] = new URI[original.length];
+    URL urls[] = new URL[original.length];
+    if (destRoot != null && srcRoot == null) {
+      consoleErr("A source URI must be specified when a destination URI
is given.");
+      System.exit(-2);
+      return;
+    }
+
+    for (int i = 0; i < original.length; ++i) {
+      try {
+        original[i] = new URI(ARG_SRC.getValues()[i]);
+      } catch (URISyntaxException use) {
+        consoleErr("Malformed resource URI: " + ARG_SRC.getValues()[i]);
+        System.exit(-2);
+        return;
+      }
+
+      URI relative = srcRoot.relativize(original[i]);
+      source[i] = srcRoot.resolve(original[i]);
+      dest[i] = destRoot == null ? source[i] : destRoot.resolve
(relative);
+
+
+      try {
+        urls[i] = source[i].toURL();
+      } catch (MalformedURLException e) {
+        consoleErr("Unrecognized URI: " + source[i]);
+        System.exit(-2);
+        return;
+      }
+    }
+
+
+    for (int i = 0; i < source.length; ++i) {
+      if (ARG_RECURSE.isSet()) {
+        addRecursive(rr,srcRoot,destRoot, source[i]);
+      } else {
+
+        if (!quiet && rr.containsResource(dest[i]))
+          consoleErr("Overwriting existing resource for " + dest[i]);
+        try {
+          rr.addURI(dest[i],urls[i]);
+        } catch (IOException zre) {
+          consoleErr("Error writing " + dest[i]
+                  + " to the repository.");
+          System.exit(-6);
+        }
+      }
+    }
+
+    System.exit(0);
+  }
+
+
+  private static void addRecursive(ResourceRepositoryBuilder rr, URI
base, URI alias, URI target) {
+    XmlDependencyScanner scanner = new XmlDependencyScanner();
+    scanner.process(target);
+    if (scanner.isError()) {
+      Map.Entry<URI, Exception> e = scanner.getErrors
().entrySet().iterator().next();
+      consoleErr("Error scanning " + e.getKey() + " : "  + e.getValue());
+      System.exit(-3);
+      return;
+    }
+
+    for (Iterator<URI> i = scanner.getURIs().iterator();i.hasNext(); ) {
+      URI uri = i.next();
+      URI relative = base.relativize(uri);
+      URI aliased = alias == null ? uri : alias.resolve(relative);
+      try {
+        rr.addURI(aliased,uri.toURL());
+      } catch (IOException ioex) {
+        consoleErr("Error reading/writing resource " + target);
+        System.exit(-2);
+        return;
+      }
+    }
+
+  }
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAlias.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAlias.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAlias.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrAlias.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,100 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.cline;
+
+import org.apache.ode.utils.cli.*;
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+/**
+ * Command-line tool for adding aliases to a resource repository.
+ */
+public class RrAlias extends BaseCommandlineTool {
+
+  private static final Argument ARG_RRDIR = new LastArgument("rr-dir",
+      "destination resource repository",false);
+  private static final Argument EXISTING_A = new Argument("resource",
+      "URI of an existing repository resource",false);
+  private static final Argument NEW_A = new Argument("alias",
+      "new alias URI",false);
+
+  private static final Fragments CLINE = new Fragments(new
CommandlineFragment[] {
+    LOGGING, ARG_RRDIR, EXISTING_A, NEW_A
+  });
+
+  private static final String SYNOPSIS = "add an alias from an existing
URI to a new URI.";
+
+  public static void main(String[] args) {
+    registerTempFileManager();
+
+    if (args.length == 0 || HELP.matches(args)) {
+      ConsoleFormatter.printSynopsis(getProgramName(),SYNOPSIS, new
Fragments[] {
+        CLINE, HELP
+      });
+      System.exit(0);
+    } else if (!CLINE.matches(args)) {
+      consoleErr("INVALID COMMANDLINE: Try \"" + getProgramName() + "
-h\" for help.");
+      System.exit(-1);
+    }
+
+
+    initLogging();
+
+    URI resource;
+    URI alias;
+    try {
+      resource = new URI(EXISTING_A.getValue());
+    } catch (URISyntaxException e) {
+      consoleErr("Malformed URI " + EXISTING_A.getValue());
+      System.exit(-2);
+      return;
+    }
+
+    try {
+      alias = new URI(NEW_A.getValue());
+    } catch (URISyntaxException e) {
+      consoleErr("Malformed URI " + EXISTING_A.getValue());
+      System.exit(-2);
+      return;
+    }
+
+    ResourceRepositoryBuilder rr = null;
+    File rrdir = new File(ARG_RRDIR.getValue());
+    rrdir.mkdirs();
+    try {
+      rr = new ResourceRepositoryBuilder(rrdir);
+    } catch (FileNotFoundException fnf) {
+      consoleErr("Resource repository not found.");
+      System.exit(-2);
+    } catch (IOException e) {
+      consoleErr("Error reading resource repository.");
+      System.exit(-2);
+    }
+
+    if (!rr.containsResource(resource)) {
+      consoleErr("The resource " + resource + " is not in the
repository.");
+      System.exit(-3);
+    }
+
+    if (rr.containsResource(alias) && !QUIET_F.isSet()) {
+      consoleErr("The resource " + NEW_A.getValue() +
+          " is already bound in the repository and will be overwritten");
+    }
+
+    try {
+      rr.addAlias(alias, resource);
+    } catch (IOException ex) {
+      consoleErr("The resource " + resource + " is not in the
repository.");
+    }
+    System.exit(0);
+  }
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrDrop.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrDrop.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrDrop.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrDrop.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,89 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.cline;
+
+import org.apache.ode.utils.cli.*;
+import org.apache.ode.utils.rr.ResourceRepositoryBuilder;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+/**
+ * Command line tool for removing resources from a resource repository.
+ */
+public class RrDrop extends BaseCommandlineTool {
+
+  private static final Argument ZIPRR_LA = new Argument("rr-dir",
+      "resource repository directory",false);
+
+  private static final MultiArgument RESOURCES_MA = new
MultiArgument("uri",
+      "URI(s) of resource(s) to remove",false);
+
+  private static final Fragments CLINE = new Fragments(new
CommandlineFragment[] {
+      LOGGING, ZIPRR_LA, RESOURCES_MA
+  });
+
+  private static final String SYNOPSIS =
+    "remove one or more URI references from a resource repository.  ";
+
+  public static void main(String[] args) {
+    registerTempFileManager();
+    if (args.length == 0 || HELP.matches(args)) {
+      ConsoleFormatter.printSynopsis(getProgramName(),SYNOPSIS,new
Fragments[] {
+        CLINE, HELP
+      });
+      System.exit(-1);
+    }
+
+    initLogging();
+
+    URI[] uris = new URI[RESOURCES_MA.getValues().length];
+    for (int i = 0; i < uris.length; ++i)
+       try {
+               uris[i] = new URI(RESOURCES_MA.getValues()[i]);
+       } catch (URISyntaxException use) {
+        consoleErr("Malformed URI " + RESOURCES_MA.getValues()[i]);
+               System.exit(-2);
+       }
+
+    boolean quiet = QUIET_F.isSet();
+    File rrdir = new File(ZIPRR_LA.getValue());
+    if (!rrdir.exists()) {
+      consoleErr("The resource repository " + rrdir + " does not
exist.");
+      System.exit(-3);
+    }
+
+    ResourceRepositoryBuilder rr;
+    try {
+      rr = new ResourceRepositoryBuilder(rrdir);
+    } catch (IOException zre) {
+      consoleErr("Error reading resource repository " + rrdir);
+      System.exit(-2);
+      return;
+    }
+
+    for (int i=0; i<uris.length; ++i) {
+      if (!rr.containsResource(uris[i])) {
+        if (!quiet) {
+          consoleErr(uris[i] + " is not in the repository.");
+        }
+      } else {
+       try {
+          rr.removeURI(uris[i]);
+       } catch (IOException ioex) {
+          consoleErr("Error removing URI " + uris[i] + " from resource
repository.");
+          System.exit(-2);
+          return;
+
+       }
+      }
+    }
+    System.exit(0);
+  }
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrGet.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrGet.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrGet.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrGet.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,89 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.cline;
+
+import org.apache.ode.utils.StreamUtils;
+import org.apache.ode.utils.cli.*;
+import org.apache.ode.utils.rr.ResourceRepository;
+import org.apache.ode.utils.rr.ResourceRepositoryException;
+import org.apache.ode.utils.rr.URLResourceRepository;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+
+/**
+ * Command-line tool for getting (displaying) resources in a resource
+ * repository.
+ */
+public class RrGet extends BaseCommandlineTool {
+
+  private static final Argument ARG_RRDIR = new Argument("rr-dir",
+      "resource repository directory"
+      ,false);
+  private static final Argument ARG_RESURI = new Argument("uri",
+      "URI to retrieve",false);
+
+  private static final Fragments CLINE = new Fragments(new
CommandlineFragment[] {
+    LOGGING, ARG_RRDIR, ARG_RESURI
+  });
+
+  private static final String SYNOPSIS = "retrieve a resource from a
resource repository to standard out";
+
+  public static void main(String[] args) {
+       setClazz(RrGet.class);
+    if (args.length == 0 || HELP.matches(args)) {
+      ConsoleFormatter.printSynopsis(getProgramName(),SYNOPSIS, new
Fragments[] {
+        CLINE, HELP
+      });
+      System.exit(0);
+    } else if (!CLINE.matches(args)) {
+      consoleErr("INVALID COMMANDLINE: Try \"" + getProgramName() + "
-h\" for help.");
+      System.exit(-1);
+    }
+    registerTempFileManager();
+    initLogging();
+    boolean quiet = QUIET_F.isSet();
+
+    URI uri;
+               try {
+                       uri = new URI(ARG_RESURI.getValue());
+               } catch (URISyntaxException ex) {
+                       consoleErr("Malformed URI " +
ARG_RESURI.getValue());
+                       System.exit(-2);
+                       throw new IllegalStateException();
+               }
+
+    ResourceRepository rr;
+    try {
+       rr = new URLResourceRepository(new
File(ARG_RRDIR.getValue()).toURI());
+    } catch (ResourceRepositoryException zre) {
+      consoleErr(zre.getMessage());
+      System.exit(-2);
+      throw new IllegalStateException();
+    }
+
+    if (rr.containsResource(uri)) {
+      try {
+        InputStream is = rr.resourceAsStream(uri);
+        StreamUtils.copy(System.out,is);
+        rr.close();
+      } catch (IOException ioe) {
+        consoleErr("IO Error reading resource: " + ioe.getMessage());
+        System.exit(-4);
+      }
+    } else {
+      if(!quiet) {
+        consoleErr(ARG_RESURI.getValue() + " is not present in the
repository.");
+        System.exit(-3);
+      }
+    }
+    System.exit(0);
+  }
+}

Added:
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrList.java
URL:
http://svn.apache.org/viewvc/incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrList.java?rev=427676&view=auto

==============================================================================
---
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrList.java
(added)
+++
incubator/ode/trunk/tools/src/main/java/org/apache/ode/tools/rr/cline/RrList.java
Tue Aug  1 11:52:47 2006
@@ -0,0 +1,66 @@
+/*
+ * File:      $RCSfile$
+ * Copyright: (C) 1999-2005 FiveSight Technologies Inc.
+ *
+ */
+package org.apache.ode.tools.rr.cline;
+
+import org.apache.ode.utils.cli.*;
+import org.apache.ode.utils.rr.ResourceRepositoryException;
+import org.apache.ode.utils.rr.URLResourceRepository;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * Command-line utility for listing resources in a resource repository
+ * directory.
+ */
+public class RrList extends BaseCommandlineTool {
+
+  private static final Argument ARG_RR = new Argument(
+      "rr-dir","resource repository directory",false);
+
+  private static final Fragments CLINE = new Fragments(new
CommandlineFragment[] {
+     LOGGING, ARG_RR
+  });
+
+  private static final String SYNOPSIS = "enumerate the contents of a
ZIPRR.";
+
+  public static void main(String[] args) {
+    registerTempFileManager();
+    if (args.length == 0 || HELP.matches(args)) {
+      ConsoleFormatter.printSynopsis(getProgramName(),SYNOPSIS,new
Fragments[] {
+        CLINE, HELP
+      });
+      System.exit(0);
+    } else if (!CLINE.matches(args)) {
+      consoleErr("INVALID COMMANDLINE: Try \"" + getProgramName() + "
-h\" for help.");
+      System.exit(-1);
+    }
+
+    String rrf = ARG_RR.getValue();
+    initLogging();
+    URLResourceRepository rr;
+    try {
+        rr = new URLResourceRepository(new File(rrf).toURI());
+    } catch (ResourceRepositoryException zre) {
+      consoleErr(zre.getMessage());
+      System.exit(-2);
+      throw new IllegalStateException();
+    }
+    Map<URI, String> resources = rr.getTableOfContents();
+    System.out.println( resources.size()+ " resource" + 
(resources.size()==1?"":"s")
+
+               " in " + rr.getBaseURL());
+    for (Iterator<Map.Entry<URI,String>> i = 
resources.entrySet().iterator();i.hasNext();)
{
+       Map.Entry<URI,String> me = i.next();
+       System.out.print("  " + me.getKey() + " --> ");
+       System.out.println(me.getValue());
+    }
+    System.exit(0);
+  }
+
+}





--
Cheers,
Guillaume Nodet

Reply via email to