chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dcaru...@apache.org
Subject svn commit: r936943 [3/4] - in /incubator/chemistry/opencmis/trunk/chemistry-opencmis-test: chemistry-opencmis-test-browser/src/main/java/org/apache/chemistry/opencmis/browser/ chemistry-opencmis-test-fit/src/test/java/org/apache/chemistry/opencmis/fit...
Date Thu, 22 Apr 2010 16:34:54 GMT
Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/Commander.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/Commander.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/Commander.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/Commander.java Thu Apr 22 16:34:53 2010
@@ -39,114 +39,114 @@ import org.apache.chemistry.opencmis.com
  */
 public class Commander {
 
-	private final static Map<String, Command> COMMAND_MAP = new LinkedHashMap<String, Command>();
-	static {
-		addCommand(new InfosCommand());
-		addCommand(new ListCommand());
-		addCommand(new DeleteCommand());
-	}
-
-	private PrintWriter fPW;
-
-	/**
-	 * Constructor.
-	 */
-	public Commander(String[] args) {
-		fPW = new PrintWriter(System.out);
-
-		if (args.length < 2) {
-			printUsage(fPW);
-			return;
-		}
-
-		try {
-			// get the command object
-			Command command = COMMAND_MAP.get(args[1].toLowerCase());
-			if (command == null) {
-				printUsage(fPW);
-				return;
-			}
-
-			// get provider object
-			CmisBinding binding = createBinding(args[0]);
-
-			// prepare args
-			String[] commandArgs = new String[args.length - 2];
-			System.arraycopy(args, 2, commandArgs, 0, commandArgs.length);
-
-			// execute
-			command.execute(binding, commandArgs, fPW);
-		} catch (Exception e) {
-			fPW.println("Exception:");
-
-			if (e instanceof CmisBaseException) {
-				fPW.println(e);
-			} else {
-				e.printStackTrace(fPW);
-			}
-		} finally {
-			fPW.flush();
-		}
-	}
-
-	/**
-	 * Prints usage.
-	 */
-	private void printUsage(PrintWriter output) {
-		output.println("CMIS Commander\n");
-		output.println("Usage: Commander <config file> <command>\n");
-		output.println("Available commands:");
-		for (Command command : COMMAND_MAP.values()) {
-			output.println("  " + command.getUsage());
-		}
-
-		output.flush();
-	}
-
-	/**
-	 * Creates the provider object
-	 */
-	private CmisBinding createBinding(String configFile) throws Exception {
-		Properties properties = new Properties();
-		properties.load(new FileInputStream(configFile));
-
-		Map<String, String> sessionParameters = new HashMap<String, String>();
-
-		for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
-			String key = (String) e.nextElement();
-			String value = properties.getProperty(key);
-			sessionParameters.put(key, value);
-		}
-
-		CmisBindingFactory factory = CmisBindingFactory.newInstance();
-
-		CmisBinding result = null;
-		if (sessionParameters.containsKey(SessionParameter.ATOMPUB_URL)) {
-			result = factory.createCmisAtomPubBinding(sessionParameters);
-		} else if (sessionParameters.containsKey(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE)) {
-			result = factory.createCmisWebServicesBinding(sessionParameters);
-		} else {
-			throw new IllegalArgumentException("Cannot find CMIS binding information in config file!");
-		}
-
-		return result;
-	}
-
-	/**
-	 * Adds a command
-	 */
-	private final static void addCommand(Command command) {
-		if ((command == null) || (command.getCommandName() == null)) {
-			return;
-		}
-
-		COMMAND_MAP.put(command.getCommandName().toLowerCase(), command);
-	}
-
-	/**
-	 * Main.
-	 */
-	public static void main(String[] args) {
-		new Commander(args);
-	}
+    private final static Map<String, Command> COMMAND_MAP = new LinkedHashMap<String, Command>();
+    static {
+        addCommand(new InfosCommand());
+        addCommand(new ListCommand());
+        addCommand(new DeleteCommand());
+    }
+
+    private PrintWriter fPW;
+
+    /**
+     * Constructor.
+     */
+    public Commander(String[] args) {
+        fPW = new PrintWriter(System.out);
+
+        if (args.length < 2) {
+            printUsage(fPW);
+            return;
+        }
+
+        try {
+            // get the command object
+            Command command = COMMAND_MAP.get(args[1].toLowerCase());
+            if (command == null) {
+                printUsage(fPW);
+                return;
+            }
+
+            // get provider object
+            CmisBinding binding = createBinding(args[0]);
+
+            // prepare args
+            String[] commandArgs = new String[args.length - 2];
+            System.arraycopy(args, 2, commandArgs, 0, commandArgs.length);
+
+            // execute
+            command.execute(binding, commandArgs, fPW);
+        } catch (Exception e) {
+            fPW.println("Exception:");
+
+            if (e instanceof CmisBaseException) {
+                fPW.println(e);
+            } else {
+                e.printStackTrace(fPW);
+            }
+        } finally {
+            fPW.flush();
+        }
+    }
+
+    /**
+     * Prints usage.
+     */
+    private void printUsage(PrintWriter output) {
+        output.println("CMIS Commander\n");
+        output.println("Usage: Commander <config file> <command>\n");
+        output.println("Available commands:");
+        for (Command command : COMMAND_MAP.values()) {
+            output.println("  " + command.getUsage());
+        }
+
+        output.flush();
+    }
+
+    /**
+     * Creates the provider object
+     */
+    private CmisBinding createBinding(String configFile) throws Exception {
+        Properties properties = new Properties();
+        properties.load(new FileInputStream(configFile));
+
+        Map<String, String> sessionParameters = new HashMap<String, String>();
+
+        for (Enumeration<?> e = properties.propertyNames(); e.hasMoreElements();) {
+            String key = (String) e.nextElement();
+            String value = properties.getProperty(key);
+            sessionParameters.put(key, value);
+        }
+
+        CmisBindingFactory factory = CmisBindingFactory.newInstance();
+
+        CmisBinding result = null;
+        if (sessionParameters.containsKey(SessionParameter.ATOMPUB_URL)) {
+            result = factory.createCmisAtomPubBinding(sessionParameters);
+        } else if (sessionParameters.containsKey(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE)) {
+            result = factory.createCmisWebServicesBinding(sessionParameters);
+        } else {
+            throw new IllegalArgumentException("Cannot find CMIS binding information in config file!");
+        }
+
+        return result;
+    }
+
+    /**
+     * Adds a command
+     */
+    private final static void addCommand(Command command) {
+        if ((command == null) || (command.getCommandName() == null)) {
+            return;
+        }
+
+        COMMAND_MAP.put(command.getCommandName().toLowerCase(), command);
+    }
+
+    /**
+     * Main.
+     */
+    public static void main(String[] args) {
+        new Commander(args);
+    }
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/DeleteCommand.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/DeleteCommand.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/DeleteCommand.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/DeleteCommand.java Thu Apr 22 16:34:53 2010
@@ -24,39 +24,39 @@ import org.apache.chemistry.opencmis.com
 
 public class DeleteCommand implements Command {
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getCommandName()
-	 */
-	public String getCommandName() {
-		return "delete";
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getUsage()
-	 */
-	public String getUsage() {
-		return "DELETE <repository id> <object id> [all versions: true/false]";
-	}
-
-	public void execute(CmisBinding binding, String[] args, PrintWriter output) {
-		if (args.length < 2) {
-			output.println(getUsage());
-			return;
-		}
-
-		String repositoryId = args[0];
-		String objectId = args[1];
-		Boolean allVersions = (args.length > 2 ? Boolean.valueOf(args[2]) : null);
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getCommandName()
+     */
+    public String getCommandName() {
+        return "delete";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getUsage()
+     */
+    public String getUsage() {
+        return "DELETE <repository id> <object id> [all versions: true/false]";
+    }
+
+    public void execute(CmisBinding binding, String[] args, PrintWriter output) {
+        if (args.length < 2) {
+            output.println(getUsage());
+            return;
+        }
+
+        String repositoryId = args[0];
+        String objectId = args[1];
+        Boolean allVersions = (args.length > 2 ? Boolean.valueOf(args[2]) : null);
 
-		output.println("Deleting " + objectId + " ...");
-		output.flush();
+        output.println("Deleting " + objectId + " ...");
+        output.flush();
 
-		binding.getObjectService().deleteObject(repositoryId, objectId, allVersions, null);
+        binding.getObjectService().deleteObject(repositoryId, objectId, allVersions, null);
 
-		output.println("done.");
-	}
+        output.println("done.");
+    }
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/InfosCommand.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/InfosCommand.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/InfosCommand.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/InfosCommand.java Thu Apr 22 16:34:53 2010
@@ -26,40 +26,40 @@ import org.apache.chemistry.opencmis.com
 
 public class InfosCommand implements Command {
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getCommandName()
-	 */
-	public String getCommandName() {
-		return "infos";
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getUsage()
-	 */
-	public String getUsage() {
-		return "INFOS";
-	}
-
-	public void execute(CmisBinding binding, String[] args, PrintWriter output) {
-		List<RepositoryInfo> repositoryInfos = binding.getRepositoryService().getRepositoryInfos(null);
-
-		for (RepositoryInfo repositoryInfo : repositoryInfos) {
-			printRepositoryInfo(repositoryInfo, output);
-		}
-	}
-
-	private void printRepositoryInfo(RepositoryInfo repositoryInfo, PrintWriter output) {
-		output.println("Id:           " + repositoryInfo.getId());
-		output.println("Name:         " + repositoryInfo.getProductName());
-		output.println("Description:  " + repositoryInfo.getDescription());
-		output.println("Vendor:       " + repositoryInfo.getVendorName());
-		output.println("Product:      " + repositoryInfo.getProductName() + " " + repositoryInfo.getProductVersion());
-		output.println("Root Folder:  " + repositoryInfo.getRootFolderId());
-		output.println("Capabilities: " + repositoryInfo.getCapabilities());
-		output.println("------------------------------------------------------");
-	}
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getCommandName()
+     */
+    public String getCommandName() {
+        return "infos";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getUsage()
+     */
+    public String getUsage() {
+        return "INFOS";
+    }
+
+    public void execute(CmisBinding binding, String[] args, PrintWriter output) {
+        List<RepositoryInfo> repositoryInfos = binding.getRepositoryService().getRepositoryInfos(null);
+
+        for (RepositoryInfo repositoryInfo : repositoryInfos) {
+            printRepositoryInfo(repositoryInfo, output);
+        }
+    }
+
+    private void printRepositoryInfo(RepositoryInfo repositoryInfo, PrintWriter output) {
+        output.println("Id:           " + repositoryInfo.getId());
+        output.println("Name:         " + repositoryInfo.getProductName());
+        output.println("Description:  " + repositoryInfo.getDescription());
+        output.println("Vendor:       " + repositoryInfo.getVendorName());
+        output.println("Product:      " + repositoryInfo.getProductName() + " " + repositoryInfo.getProductVersion());
+        output.println("Root Folder:  " + repositoryInfo.getRootFolderId());
+        output.println("Capabilities: " + repositoryInfo.getCapabilities());
+        output.println("------------------------------------------------------");
+    }
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/ListCommand.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/ListCommand.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/ListCommand.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tools/src/main/java/org/apache/chemistry/opencmis/commander/ListCommand.java Thu Apr 22 16:34:53 2010
@@ -28,57 +28,57 @@ import org.apache.chemistry.opencmis.com
 
 public class ListCommand implements Command {
 
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getCommandName()
-	 */
-	public String getCommandName() {
-		return "list";
-	}
-
-	/*
-	 * (non-Javadoc)
-	 * 
-	 * @see org.apache.opencmis.commander.Command#getUsage()
-	 */
-	public String getUsage() {
-		return "LIST <repository id> <folder id>";
-	}
-
-	public void execute(CmisBinding binding, String[] args, PrintWriter output) {
-		if (args.length < 2) {
-			output.println(getUsage());
-			return;
-		}
-
-		String repositoryId = args[0];
-		String folderId = args[1];
-
-		ObjectInFolderList list = binding.getNavigationService().getChildren(repositoryId, folderId, null, null, null,
-				null, null, null, null, null, null);
-
-		for (ObjectInFolderData object : list.getObjects()) {
-			output.println(getPropertyValue(object, PropertyIds.OBJECT_ID) + "\t"
-					+ getPropertyValue(object, PropertyIds.NAME) + "\t"
-					+ getPropertyValue(object, PropertyIds.OBJECT_TYPE_ID));
-		}
-	}
-
-	/**
-	 * Returns a property value as string.
-	 */
-	private String getPropertyValue(ObjectInFolderData object, String name) {
-		if ((object == null) || (object.getObject() == null) || (object.getObject().getProperties() == null)
-				|| (object.getObject().getProperties().getProperties() == null)) {
-			return "?";
-		}
-
-		PropertyData<?> property = object.getObject().getProperties().getProperties().get(name);
-		if ((property == null) || (property.getFirstValue() == null)) {
-			return "<not set>";
-		}
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getCommandName()
+     */
+    public String getCommandName() {
+        return "list";
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.opencmis.commander.Command#getUsage()
+     */
+    public String getUsage() {
+        return "LIST <repository id> <folder id>";
+    }
+
+    public void execute(CmisBinding binding, String[] args, PrintWriter output) {
+        if (args.length < 2) {
+            output.println(getUsage());
+            return;
+        }
+
+        String repositoryId = args[0];
+        String folderId = args[1];
+
+        ObjectInFolderList list = binding.getNavigationService().getChildren(repositoryId, folderId, null, null, null,
+                null, null, null, null, null, null);
+
+        for (ObjectInFolderData object : list.getObjects()) {
+            output.println(getPropertyValue(object, PropertyIds.OBJECT_ID) + "\t"
+                    + getPropertyValue(object, PropertyIds.NAME) + "\t"
+                    + getPropertyValue(object, PropertyIds.OBJECT_TYPE_ID));
+        }
+    }
+
+    /**
+     * Returns a property value as string.
+     */
+    private String getPropertyValue(ObjectInFolderData object, String name) {
+        if ((object == null) || (object.getObject() == null) || (object.getObject().getProperties() == null)
+                || (object.getObject().getProperties().getProperties() == null)) {
+            return "?";
+        }
+
+        PropertyData<?> property = object.getObject().getProperties().getProperties().get(name);
+        if ((property == null) || (property.getFirstValue() == null)) {
+            return "<not set>";
+        }
 
-		return property.getFirstValue().toString();
-	}
+        return property.getFirstValue().toString();
+    }
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/MultiThreadedObjectGenerator.java Thu Apr 22 16:34:53 2010
@@ -27,204 +27,204 @@ import org.apache.chemistry.opencmis.com
 
 public class MultiThreadedObjectGenerator {
 
-	static public enum Action {
-		CreateDocument, CreateTree, CreateFolders
-	};
-
-	static class ObjectGeneratorRunner implements Runnable {
-		private Action fAction;
-		ObjectGenerator fObjGen;
-		private String fRootFolderId;
-		private int fFoldersPerFolders;
-		private int fDepth;
-		private int fCount;
-
-		public ObjectGeneratorRunner(ObjectGenerator objGen, Action action) {
-			fObjGen = objGen;
-			fAction = action;
-		}
-
-		public void run() {
-			if (fAction == Action.CreateDocument) {
-				doCreateDocument();
-			} else if (fAction == Action.CreateTree) {
-				doCreateTree();
-			} else if (fAction == Action.CreateFolders) {
-				doCreateFolder();
-			}
-		}
-
-		public String[] doCreateDocument() {
-			String ids[] = fObjGen.createDocuments(fRootFolderId, fCount);
-			return ids;
-		}
-
-		public void doCreateTree() {
-			fObjGen.createFolderHierachy(fDepth, fFoldersPerFolders, fRootFolderId);
-		}
-
-		public String[] doCreateFolder() {
-			return fObjGen.createFolders(fRootFolderId, fCount);
-		}
-
-		public ObjectGenerator getObjectGenerator() {
-			return fObjGen;
-		}
-
-	} // ObjectCreatorRunner
-
-	static private ObjectGenerator createObjectGenerator(CmisBinding binding, String repoId, int docsPerFolder,
-			int foldersPerFolders, int depth, String documentType, String folderType, int contentSizeInKB,
-			String rootFolderId, boolean doCleanup) {
-
-		BindingsObjectFactory objectFactory = binding.getObjectFactory();
-		NavigationService navSvc = binding.getNavigationService();
-		ObjectService objSvc = binding.getObjectService();
-
-		ObjectGenerator gen = new ObjectGenerator(objectFactory, navSvc, objSvc, repoId);
-		gen.setUseUuidsForNames(true);
-		gen.setNumberOfDocumentsToCreatePerFolder(docsPerFolder);
-		// Set the type id for all created documents:
-		gen.setDocumentTypeId(documentType);
-		// Set the type id for all created folders:
-		gen.setFolderTypeId(folderType);
-		// Set contentSize
-		gen.setContentSizeInKB(contentSizeInKB);
-		gen.setCleanUpAfterCreate(doCleanup);
-
-		return gen;
-	}
-
-	static private String getRootFolderId(CmisBinding binding, String repositoryId, String rootFolderId) {
-		RepositoryService repSvc = binding.getRepositoryService();
-
-		RepositoryInfo rep = repSvc.getRepositoryInfo(repositoryId, null);
-		if (null == rootFolderId || rootFolderId.length() == 0)
-			rootFolderId = rep.getRootFolderId();
-
-		return rootFolderId;
-	}
-
-	public static ObjectGeneratorRunner prepareForCreateTree(CmisBinding binding, String repoId, int docsPerFolder,
-			int foldersPerFolders, int depth, String documentType, String folderType, int contentSizeInKB,
-			String rootFolderId, boolean doCleanup) {
-
-		ObjectGenerator objGen = createObjectGenerator(binding, repoId, docsPerFolder, foldersPerFolders, depth,
-				documentType, folderType, contentSizeInKB, rootFolderId, doCleanup);
-
-		ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateTree);
-		gen.fFoldersPerFolders = foldersPerFolders;
-		gen.fDepth = depth;
-		gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
-		return gen;
-	}
-
-	public static ObjectGeneratorRunner[] prepareForCreateTreeMT(CmisBinding provider, String repoId,
-			int docsPerFolder, int foldersPerFolders, int depth, String documentType, String folderType,
-			int contentSizeInKB, String[] rootFolderIds, boolean doCleanup) {
-
-		ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[rootFolderIds.length];
-		for (int i = 0; i < rootFolderIds.length; i++) {
-			ObjectGenerator objGen = createObjectGenerator(provider, repoId, docsPerFolder, foldersPerFolders, depth,
-					documentType, folderType, contentSizeInKB, rootFolderIds[i], doCleanup);
-
-			ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateTree);
-			gen.fFoldersPerFolders = foldersPerFolders;
-			gen.fDepth = depth;
-			gen.fRootFolderId = rootFolderIds[i];
-			runners[i] = gen;
-		}
-		return runners;
-	}
-
-	public static ObjectGeneratorRunner prepareForCreateDocument(CmisBinding provider, String repoId,
-			String documentType, int contentSizeInKB, String rootFolderId, int noDocuments, boolean doCleanup) {
-
-		ObjectGenerator objGen = createObjectGenerator(provider, repoId, 0, 0, 0, documentType, null, contentSizeInKB,
-				rootFolderId, doCleanup);
-
-		ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateDocument);
-		gen.fRootFolderId = getRootFolderId(provider, repoId, rootFolderId);
-		gen.fCount = noDocuments;
-		return gen;
-	}
-
-	public static ObjectGeneratorRunner[] prepareForCreateDocumentMT(int threadCount, CmisBinding binding,
-			String repoId, String documentType, int contentSizeInKB, String rootFolderId, int noDocuments,
-			boolean doCleanup) {
-
-		ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[threadCount];
-		for (int i = 0; i < threadCount; i++) {
-			ObjectGenerator objGen = createObjectGenerator(binding, repoId, 0, 0, 0, documentType, null,
-					contentSizeInKB, rootFolderId, doCleanup);
-
-			ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateDocument);
-			gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
-			gen.fCount = noDocuments;
-			runners[i] = gen;
-		}
-		return runners;
-	}
-
-	public static ObjectGeneratorRunner prepareForCreateFolder(CmisBinding provider, String repoId, String folderType,
-			String rootFolderId, int noFolders, boolean doCleanup) {
-
-		ObjectGenerator objGen = createObjectGenerator(provider, repoId, 0, 0, 0, null, folderType, 0, rootFolderId,
-				doCleanup);
-
-		ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateFolders);
-		gen.fRootFolderId = getRootFolderId(provider, repoId, rootFolderId);
-		gen.fCount = noFolders;
-		return gen;
-	}
-
-	public static ObjectGeneratorRunner[] prepareForCreateFolderMT(int threadCount, CmisBinding binding, String repoId,
-			String folderType, String rootFolderId, int noFolders, boolean doCleanup) {
-
-		ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[threadCount];
-		for (int i = 0; i < threadCount; i++) {
-			ObjectGenerator objGen = createObjectGenerator(binding, repoId, 0, 0, 0, null, folderType, 0, rootFolderId,
-					doCleanup);
-
-			ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateFolders);
-			gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
-			gen.fCount = noFolders;
-			runners[i] = gen;
-		}
-		return runners;
-	}
-
-	public static void runMultiThreaded(ObjectGeneratorRunner[] runner) {
-		int threadCount = runner.length;
-		Thread threads[] = new Thread[threadCount];
-		for (int i = 0; i < threadCount; i++) {
-			Thread thread = new Thread(runner[i], "ObjectGeneratorThread-" + i);
-			threads[i] = thread;
-			thread.start();
-		}
-
-		try {
-			for (Thread thread : threads) {
-				thread.join();
-			}
-			// Print all timings to System.out
-			System.out.println();
-			System.out.println("Result:");
-			TimeLogger[] loggersCreateDoc = new TimeLogger[threadCount];
-			TimeLogger[] loggersCreateFolder = new TimeLogger[threadCount];
-			TimeLogger[] loggersDelete = new TimeLogger[threadCount];
-			for (int i = 0; i < threadCount; i++) {
-				loggersCreateDoc[i] = runner[i].fObjGen.getCreateDocumentTimeLogger();
-				loggersCreateFolder[i] = runner[i].fObjGen.getCreateFolderTimeLogger();
-				loggersDelete[i] = runner[i].fObjGen.getDeleteTimeLogger();
-			}
-			TimeLogger.printTimes(loggersCreateDoc);
-			TimeLogger.printTimes(loggersCreateFolder);
-			TimeLogger.printTimes(loggersDelete);
-
-		} catch (InterruptedException e) {
-			System.out.println("Failed to wait for termination of threads: " + e);
-		}
-	}
+    static public enum Action {
+        CreateDocument, CreateTree, CreateFolders
+    };
+
+    static class ObjectGeneratorRunner implements Runnable {
+        private Action fAction;
+        ObjectGenerator fObjGen;
+        private String fRootFolderId;
+        private int fFoldersPerFolders;
+        private int fDepth;
+        private int fCount;
+
+        public ObjectGeneratorRunner(ObjectGenerator objGen, Action action) {
+            fObjGen = objGen;
+            fAction = action;
+        }
+
+        public void run() {
+            if (fAction == Action.CreateDocument) {
+                doCreateDocument();
+            } else if (fAction == Action.CreateTree) {
+                doCreateTree();
+            } else if (fAction == Action.CreateFolders) {
+                doCreateFolder();
+            }
+        }
+
+        public String[] doCreateDocument() {
+            String ids[] = fObjGen.createDocuments(fRootFolderId, fCount);
+            return ids;
+        }
+
+        public void doCreateTree() {
+            fObjGen.createFolderHierachy(fDepth, fFoldersPerFolders, fRootFolderId);
+        }
+
+        public String[] doCreateFolder() {
+            return fObjGen.createFolders(fRootFolderId, fCount);
+        }
+
+        public ObjectGenerator getObjectGenerator() {
+            return fObjGen;
+        }
+
+    } // ObjectCreatorRunner
+
+    static private ObjectGenerator createObjectGenerator(CmisBinding binding, String repoId, int docsPerFolder,
+            int foldersPerFolders, int depth, String documentType, String folderType, int contentSizeInKB,
+            String rootFolderId, boolean doCleanup) {
+
+        BindingsObjectFactory objectFactory = binding.getObjectFactory();
+        NavigationService navSvc = binding.getNavigationService();
+        ObjectService objSvc = binding.getObjectService();
+
+        ObjectGenerator gen = new ObjectGenerator(objectFactory, navSvc, objSvc, repoId);
+        gen.setUseUuidsForNames(true);
+        gen.setNumberOfDocumentsToCreatePerFolder(docsPerFolder);
+        // Set the type id for all created documents:
+        gen.setDocumentTypeId(documentType);
+        // Set the type id for all created folders:
+        gen.setFolderTypeId(folderType);
+        // Set contentSize
+        gen.setContentSizeInKB(contentSizeInKB);
+        gen.setCleanUpAfterCreate(doCleanup);
+
+        return gen;
+    }
+
+    static private String getRootFolderId(CmisBinding binding, String repositoryId, String rootFolderId) {
+        RepositoryService repSvc = binding.getRepositoryService();
+
+        RepositoryInfo rep = repSvc.getRepositoryInfo(repositoryId, null);
+        if (null == rootFolderId || rootFolderId.length() == 0)
+            rootFolderId = rep.getRootFolderId();
+
+        return rootFolderId;
+    }
+
+    public static ObjectGeneratorRunner prepareForCreateTree(CmisBinding binding, String repoId, int docsPerFolder,
+            int foldersPerFolders, int depth, String documentType, String folderType, int contentSizeInKB,
+            String rootFolderId, boolean doCleanup) {
+
+        ObjectGenerator objGen = createObjectGenerator(binding, repoId, docsPerFolder, foldersPerFolders, depth,
+                documentType, folderType, contentSizeInKB, rootFolderId, doCleanup);
+
+        ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateTree);
+        gen.fFoldersPerFolders = foldersPerFolders;
+        gen.fDepth = depth;
+        gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
+        return gen;
+    }
+
+    public static ObjectGeneratorRunner[] prepareForCreateTreeMT(CmisBinding provider, String repoId,
+            int docsPerFolder, int foldersPerFolders, int depth, String documentType, String folderType,
+            int contentSizeInKB, String[] rootFolderIds, boolean doCleanup) {
+
+        ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[rootFolderIds.length];
+        for (int i = 0; i < rootFolderIds.length; i++) {
+            ObjectGenerator objGen = createObjectGenerator(provider, repoId, docsPerFolder, foldersPerFolders, depth,
+                    documentType, folderType, contentSizeInKB, rootFolderIds[i], doCleanup);
+
+            ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateTree);
+            gen.fFoldersPerFolders = foldersPerFolders;
+            gen.fDepth = depth;
+            gen.fRootFolderId = rootFolderIds[i];
+            runners[i] = gen;
+        }
+        return runners;
+    }
+
+    public static ObjectGeneratorRunner prepareForCreateDocument(CmisBinding provider, String repoId,
+            String documentType, int contentSizeInKB, String rootFolderId, int noDocuments, boolean doCleanup) {
+
+        ObjectGenerator objGen = createObjectGenerator(provider, repoId, 0, 0, 0, documentType, null, contentSizeInKB,
+                rootFolderId, doCleanup);
+
+        ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateDocument);
+        gen.fRootFolderId = getRootFolderId(provider, repoId, rootFolderId);
+        gen.fCount = noDocuments;
+        return gen;
+    }
+
+    public static ObjectGeneratorRunner[] prepareForCreateDocumentMT(int threadCount, CmisBinding binding,
+            String repoId, String documentType, int contentSizeInKB, String rootFolderId, int noDocuments,
+            boolean doCleanup) {
+
+        ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[threadCount];
+        for (int i = 0; i < threadCount; i++) {
+            ObjectGenerator objGen = createObjectGenerator(binding, repoId, 0, 0, 0, documentType, null,
+                    contentSizeInKB, rootFolderId, doCleanup);
+
+            ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateDocument);
+            gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
+            gen.fCount = noDocuments;
+            runners[i] = gen;
+        }
+        return runners;
+    }
+
+    public static ObjectGeneratorRunner prepareForCreateFolder(CmisBinding provider, String repoId, String folderType,
+            String rootFolderId, int noFolders, boolean doCleanup) {
+
+        ObjectGenerator objGen = createObjectGenerator(provider, repoId, 0, 0, 0, null, folderType, 0, rootFolderId,
+                doCleanup);
+
+        ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateFolders);
+        gen.fRootFolderId = getRootFolderId(provider, repoId, rootFolderId);
+        gen.fCount = noFolders;
+        return gen;
+    }
+
+    public static ObjectGeneratorRunner[] prepareForCreateFolderMT(int threadCount, CmisBinding binding, String repoId,
+            String folderType, String rootFolderId, int noFolders, boolean doCleanup) {
+
+        ObjectGeneratorRunner[] runners = new ObjectGeneratorRunner[threadCount];
+        for (int i = 0; i < threadCount; i++) {
+            ObjectGenerator objGen = createObjectGenerator(binding, repoId, 0, 0, 0, null, folderType, 0, rootFolderId,
+                    doCleanup);
+
+            ObjectGeneratorRunner gen = new ObjectGeneratorRunner(objGen, Action.CreateFolders);
+            gen.fRootFolderId = getRootFolderId(binding, repoId, rootFolderId);
+            gen.fCount = noFolders;
+            runners[i] = gen;
+        }
+        return runners;
+    }
+
+    public static void runMultiThreaded(ObjectGeneratorRunner[] runner) {
+        int threadCount = runner.length;
+        Thread threads[] = new Thread[threadCount];
+        for (int i = 0; i < threadCount; i++) {
+            Thread thread = new Thread(runner[i], "ObjectGeneratorThread-" + i);
+            threads[i] = thread;
+            thread.start();
+        }
+
+        try {
+            for (Thread thread : threads) {
+                thread.join();
+            }
+            // Print all timings to System.out
+            System.out.println();
+            System.out.println("Result:");
+            TimeLogger[] loggersCreateDoc = new TimeLogger[threadCount];
+            TimeLogger[] loggersCreateFolder = new TimeLogger[threadCount];
+            TimeLogger[] loggersDelete = new TimeLogger[threadCount];
+            for (int i = 0; i < threadCount; i++) {
+                loggersCreateDoc[i] = runner[i].fObjGen.getCreateDocumentTimeLogger();
+                loggersCreateFolder[i] = runner[i].fObjGen.getCreateFolderTimeLogger();
+                loggersDelete[i] = runner[i].fObjGen.getDeleteTimeLogger();
+            }
+            TimeLogger.printTimes(loggersCreateDoc);
+            TimeLogger.printTimes(loggersCreateFolder);
+            TimeLogger.printTimes(loggersDelete);
+
+        } catch (InterruptedException e) {
+            System.out.println("Failed to wait for termination of threads: " + e);
+        }
+    }
 
 }

Modified: incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java?rev=936943&r1=936942&r2=936943&view=diff
==============================================================================
--- incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java (original)
+++ incubator/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-util/src/main/java/org/apache/chemistry/opencmis/util/repository/ObjGenApp.java Thu Apr 22 16:34:53 2010
@@ -40,457 +40,457 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
 
 public class ObjGenApp {
-	public static final String DEFAULT_USER = "";
-	public static final String DEFAULT_PWD = "";
-	public static final String PROP_ATOMPUB_URL = "opencmis.test.atompub.url";
-	public static final String PROP_URL = "url";
-	public static final String PROP_WS_URL = "opencmis.test.webservices.url";
-	public static final String DEFAULT_ATOMPUB_URL = "http://localhost:8080/opencmis/atom";
-	public static final String DEFAULT_WS_URL = "http://localhost:8080/cmis/services/";
-
-	private final static String CMD = "Command";
-	private final static String REPOSITORY_ID = "RepositoryId";
-	private final static String FILLER_DOCUMENT_TYPE_ID = "DocumentTypeId";
-	private final static String FILLER_FOLDER_TYPE_ID = "FolderTypeId";
-	private final static String FILLER_DOCS_PER_FOLDER = "DocsPerFolder";
-	private final static String FILLER_FOLDERS_PER_FOLDER = "FoldersPerFolder";
-	private final static String FILLER_DEPTH = "Depth";
-	private final static String FILLER_CONTENT_SIZE = "ContentSizeInKB";
-	private final static String COUNT = "Count";
-	private final static String BINDING = "Binding";
-	private final static String CLEANUP = "Cleanup";
-	private final static String ROOTFOLDER = "RootFolder";
-	private final static String THREADS = "Threads";
-
-	private final static String BINDING_ATOM = "AtomPub";
-	private final static String BINDING_WS = "WebService";
-
-	private CmisBinding binding;
-	private boolean fUsingAtom;
-	private String fUrlStr;
-
-	OptionSpec<String> fCmd;
-	OptionSpec<Integer> fDepth;
-	OptionSpec<Integer> fContentSize;
-	OptionSpec<Integer> fFolderPerFolder;
-	OptionSpec<Integer> fDocsPerFolder;
-	OptionSpec<String> fFolderType;
-	OptionSpec<String> fDocType;
-	OptionSpec<String> fRepoId;
-	OptionSpec<Integer> fCount;
-	OptionSpec<String> fBinding;
-	OptionSpec<Boolean> fCleanup;
-	OptionSpec<String> fRootFolder;
-	OptionSpec<Integer> fThreads;
-
-	public static void main(String[] args) {
-
-		ObjGenApp app = new ObjGenApp();
-		try {
-			app.processCmdLine(args);
-		} catch (CmisBaseException ce) {
-			System.out.println("Error: Could not process command. " + ce);
-			System.out.println("Extended error: " + ce.getErrorContent());
-			ce.printStackTrace();
-		} catch (Exception e) {
-			System.out.println("Could not fill repository " + e);
-			e.printStackTrace();
-		}
-	}
-
-	private void processCmdLine(String[] args) {
-
-		OptionParser parser = new OptionParser();
-		fCmd = parser.accepts(CMD).withRequiredArg().describedAs("Command to perform (see below)");
-		fRepoId = parser.accepts(REPOSITORY_ID).withOptionalArg().describedAs("Repository used");
-		fDocType = parser.accepts(FILLER_DOCUMENT_TYPE_ID).withOptionalArg().defaultsTo(
-				BaseTypeId.CMIS_DOCUMENT.value()).describedAs("Document type created");
-		fFolderType = parser.accepts(FILLER_FOLDER_TYPE_ID).withOptionalArg()
-				.defaultsTo(BaseTypeId.CMIS_FOLDER.value()).describedAs("Folder type created");
-		fDocsPerFolder = parser.accepts(FILLER_DOCS_PER_FOLDER).withOptionalArg().ofType(Integer.class).describedAs(
-				"Documents on each level").defaultsTo(1);
-		fFolderPerFolder = parser.accepts(FILLER_FOLDERS_PER_FOLDER).withOptionalArg().ofType(Integer.class)
-				.describedAs(" Folders on each level").defaultsTo(0);
-		fDepth = parser.accepts(FILLER_DEPTH).withOptionalArg().ofType(Integer.class).describedAs("Levels of folders")
-				.defaultsTo(1);
-		fContentSize = parser.accepts(FILLER_CONTENT_SIZE).withOptionalArg().ofType(Integer.class).describedAs(
-				"Content size of each doc").defaultsTo(0);
-		fCount = parser.accepts(COUNT).withOptionalArg().ofType(Integer.class).defaultsTo(1).describedAs(
-				"Repeat a command n times (partially implemented)");
-		fBinding = parser.accepts(BINDING).withOptionalArg().ofType(String.class).defaultsTo(BINDING_ATOM).describedAs(
-				"Protocol Binding: " + BINDING_ATOM + " or " + BINDING_WS);
-		fCleanup = parser.accepts(CLEANUP).withOptionalArg().ofType(Boolean.class).defaultsTo(false).describedAs(
-				"Clean all created objects at the end");
-		fRootFolder = parser.accepts(ROOTFOLDER).withOptionalArg().ofType(String.class).describedAs(
-				"folder id used as root to create objects (default repository root folder)");
-		fThreads = parser.accepts(THREADS).withOptionalArg().ofType(Integer.class).defaultsTo(1).describedAs(
-				"Number of threads to start in parallel");
-
-		OptionSet options = parser.parse(args);
-
-		if (options.valueOf(fCmd) == null || options.has("?"))
-			usage(parser);
-
-		if (options.valueOf(fBinding).equals(BINDING_WS)) {
-			fUsingAtom = false;
-		} else if (options.valueOf(fBinding).equals(BINDING_ATOM)) {
-			fUsingAtom = true;
-		} else {
-			System.out.println("Unknown option <Binding>: " + options.valueOf(fBinding) + " allowed values: "
-					+ BINDING_WS + " or " + BINDING_ATOM);
-			return;
-		}
-
-		if (options.valueOf(fCmd).equals("FillRepository")) {
-			fillRepository(options);
-		} else if (options.valueOf(fCmd).equals("CreateDocument")) {
-			createSingleDocument(options);
-		} else if (options.valueOf(fCmd).equals("CreateFolder")) {
-			createFolders(options);
-		} else if (options.valueOf(fCmd).equals("RepositoryInfo")) {
-			repositoryInfo(options);
-		} else if (options.valueOf(fCmd).equals("GetUrl")) {
-			getUrl(getConfiguredUrl());
-		} else {
-			System.out.println("Unknown cmd: " + options.valueOf(fCmd));
-			usage(parser);
-		}
-	}
-
-	// private void preInitExpensiveTasks() {
-	// // JAXB initialization is very expensive, count this separate:
-	// TimeLogger logger = new TimeLogger("Initialization");
-	// logger.start();
-	// try {
-	// JaxBHelper.createMarshaller();
-	// }
-	// catch (JAXBException e) {
-	// System.out.print("Failuer in JAXB init: " + e);
-	// e.printStackTrace();
-	// } // dummy call just to get initialized
-	// logger.stop();
-	// logger.printTimes();
-	// }
-
-	private void usage(OptionParser parser) {
-		try {
-			System.out.println();
-			System.out.println("ObjGenApp is a command line tool for testing a CMIS repository.");
-			System.out.println("Usage:");
-			parser.printHelpOn(System.out);
-			System.out.println();
-			System.out.println("Command is one of [CreateDocument, CreateFolder, FillRepository, RepositoryInfo]");
-			System.out.println("JVM system properties: " + PROP_ATOMPUB_URL + ", " + PROP_WS_URL);
-			System.out.println();
-			System.out.println("Example: ");
-			System.out
-					.println("java -D"
-							+ PROP_ATOMPUB_URL
-							+ "=http://localhost:8080/opencmis/atom -cp ... "
-							+ "org.apache.chemistry.opencmis.util.repository.ObjGenApp --Binding=AtomPub --Command=CreateDocument "
-							+ "--RepositoryId=A1 --ContentSizeInKB=25");
-			return;
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	private void fillRepository(String repoId, int docsPerFolder, int foldersPerFolders, int depth,
-			String documentType, String folderType, int contentSizeInKB, String rootFolderId, boolean doCleanup) {
-
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator.prepareForCreateTree(
-				getBinding(), repoId, docsPerFolder, foldersPerFolders, depth, documentType, folderType,
-				contentSizeInKB, rootFolderId, doCleanup);
-		ObjectGenerator gen = runner.getObjectGenerator();
-		runner.doCreateTree();
-
-		System.out.println();
-		System.out.println("Result:");
-		System.out.println("Filling repository succeeded.");
-		System.out.println("Folder used as root for creation (null=rootFolderId): " + rootFolderId);
-		System.out.println("Number of documents created: " + gen.getDocumentsInTotal());
-		System.out.println("Number of folders created: " + gen.getFoldersInTotal());
-		gen.printTimings();
-	}
-
-	private void fillRepositoryMT(int noThreads, String repoId, int docsPerFolder, int foldersPerFolders, int depth,
-			String documentType, String folderType, int contentSizeInKB, String rootFolderId, boolean doCleanup) {
-
-		// Step 1: create a root folder for each thread
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
-				.prepareForCreateFolder(getBinding(), repoId, folderType, rootFolderId, noThreads, doCleanup);
-		String[] folderIds = runner.doCreateFolder();
-
-		// Step 2: fill each root folder with an object tree
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
-				.prepareForCreateTreeMT(getBinding(), repoId, docsPerFolder, foldersPerFolders, depth, documentType,
-						folderType, contentSizeInKB, folderIds, doCleanup);
-
-		MultiThreadedObjectGenerator.runMultiThreaded(runners);
-		System.out.println("Filling repository succeeded.");
-	}
-
-	private void printParameters(OptionSet options) {
-		if (fUsingAtom)
-			System.out.println("Using AtomPub, connecting to  " + getAtomPubUrl());
-		else
-			System.out.println("Using WebService, connecting to  " + getWsUrl());
-
-		System.out.println("Repository id is: " + options.valueOf(fRepoId));
-		System.out.println("Content size: " + options.valueOf(fContentSize));
-		System.out.println("Document Type: " + options.valueOf(fDocType));
-		System.out.println("Folder id used as root: " + options.valueOf(fRootFolder));
-		System.out.println("Delete all objects after creation: " + options.valueOf(fCleanup));
-		System.out.println("Number of actions to perform: " + options.valueOf(fCount));
-		System.out.println("Number of threads to start: " + options.valueOf(fThreads));
-	}
-
-	private void createSingleDocument(OptionSet options) {
-		System.out.println();
-		System.out.println("Creating document with parameters:");
-		printParameters(options);
-		int noThreads = options.valueOf(fThreads);
-		if (noThreads <= 1)
-			createSingleDocument(options.valueOf(fRepoId), options.valueOf(fDocType), options.valueOf(fContentSize),
-					options.valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
-		else
-			createSingleDocumentMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocType), options
-					.valueOf(fContentSize), options.valueOf(fRootFolder), options.valueOf(fCount), options
-					.valueOf(fCleanup));
-	}
-
-	private void fillRepository(OptionSet options) {
-		System.out.println();
-		printParameters(options);
-		System.out.println("Creating object tree with folowing parameters: ");
-		System.out.println("Documents per folder: " + options.valueOf(fDocsPerFolder));
-		System.out.println("Folder per folder: " + options.valueOf(fFolderPerFolder));
-		System.out.println("Depth: " + options.valueOf(fDepth));
-		System.out.println("Folder Type: " + options.valueOf(fFolderType));
-
-		int noThreads = options.valueOf(fThreads);
-		if (noThreads <= 1)
-			fillRepository(options.valueOf(fRepoId), options.valueOf(fDocsPerFolder),
-					options.valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
-							.valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
-							.valueOf(fCleanup));
-		else
-			fillRepositoryMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocsPerFolder), options
-					.valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
-					.valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
-					.valueOf(fCleanup));
-
-	}
-
-	private void createFolders(OptionSet options) {
-		System.out.println();
-		System.out.println("Creating folder with parameters:");
-		printParameters(options);
-		System.out.println("Folder Type: " + options.valueOf(fFolderType));
-		int noThreads = options.valueOf(fThreads);
-		if (noThreads <= 1)
-			createFolders(options.valueOf(fRepoId), options.valueOf(fFolderType), options.valueOf(fRootFolder), options
-					.valueOf(fCount), options.valueOf(fCleanup));
-		else
-			createFoldersMT(noThreads, options.valueOf(fRepoId), options.valueOf(fFolderType), options
-					.valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
-	}
-
-	private void createSingleDocument(String repoId, String documentType, int contentSizeInKB, String rootFolderId,
-			int docCount, boolean doCleanup) {
-
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
-				.prepareForCreateDocument(getBinding(), repoId, documentType, contentSizeInKB, rootFolderId, docCount,
-						doCleanup);
-		ObjectGenerator gen = runner.getObjectGenerator();
-		String[] ids = runner.doCreateDocument();
-		System.out.println();
-		System.out.println("Result:");
-		System.out.println("Document creation succeeded.");
-		System.out.println("Folder used as root for creation: " + rootFolderId);
-		System.out.println("Ids of created documents: ");
-		if (null == ids)
-			System.out.println("<none>");
-		else
-			for (int i = 0; i < ids.length; i++)
-				System.out.println(ids[i]);
-		gen.printTimings();
-		gen.resetCounters();
-	}
-
-	private void createSingleDocumentMT(int noThreads, String repoId, String documentType, int contentSizeInKB,
-			String rootFolderId, int docCount, boolean doCleanup) {
-
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
-				.prepareForCreateDocumentMT(noThreads, getBinding(), repoId, documentType, contentSizeInKB,
-						rootFolderId, docCount, doCleanup);
-
-		MultiThreadedObjectGenerator.runMultiThreaded(runners);
-		System.out.println("Document creation succeeded. All threads terminated.");
-	}
-
-	private void createFolders(String repoId, String folderType, String rootFolderId, int noFolders, boolean doCleanup) {
-
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
-				.prepareForCreateFolder(getBinding(), repoId, folderType, rootFolderId, noFolders, doCleanup);
-		ObjectGenerator gen = runner.getObjectGenerator();
-		String[] ids = runner.doCreateFolder();
-		System.out.println();
-		System.out.println("Result:");
-		System.out.println("Folder creation succeeded.");
-		System.out.println("Ids of created folders: ");
-		if (null == ids)
-			System.out.println("<none>");
-		else
-			for (int i = 0; i < ids.length; i++)
-				System.out.println(ids[i]);
-		gen.printTimings();
-		gen.resetCounters();
-	}
-
-	private void createFoldersMT(int noThreads, String repoId, String folderType, String rootFolderId, int noFolders,
-			boolean doCleanup) {
-
-		MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
-				.prepareForCreateFolderMT(noThreads, getBinding(), repoId, folderType, rootFolderId, noFolders,
-						doCleanup);
-		MultiThreadedObjectGenerator.runMultiThreaded(runners);
-		System.out.println("Folder creation succeeded.");
-	}
-
-	private void callRepoInfo(String repositoryId, int count) {
-		RepositoryService repSvc = getBinding().getRepositoryService();
-		TimeLogger timeLogger = new TimeLogger("RepoInfoTest");
-		RepositoryInfo repoInfo = null;
-		for (int i = 0; i < count; i++) {
-			binding.clearRepositoryCache(repositoryId);
-			timeLogger.start();
-			repoInfo = repSvc.getRepositoryInfo(repositoryId, null);
-			timeLogger.stop();
-		}
-		System.out.println("Root Folder id is: " + (repoInfo == null ? "<unknown>" : repoInfo.getRootFolderId()));
-		timeLogger.printTimes();
-	}
-
-	private void repositoryInfo(OptionSet options) {
-		callRepoInfo(options.valueOf(fRepoId), options.valueOf(fCount));
-	}
-
-	private CmisBinding getBinding() {
-		if (binding == null) {
-			if (fUsingAtom)
-				binding = createAtomBinding(getAtomPubUrl(), DEFAULT_USER, DEFAULT_PWD);
-			else
-				binding = createWsBinding(getWsUrl(), DEFAULT_USER, DEFAULT_PWD);
-		}
-		return binding;
-	}
-
-	private static void filLoginParams(Map<String, String> parameters, String user, String password) {
-		if (user != null && user.length() > 0)
-			parameters.put(SessionParameter.USER, user);
-		if (user != null && user.length() > 0)
-			parameters.put(SessionParameter.PASSWORD, password);
-	}
-
-	private static CmisBinding createAtomBinding(String url, String user, String password) {
-
-		// gather parameters
-		Map<String, String> parameters = new HashMap<String, String>();
-		filLoginParams(parameters, user, password);
-
-		// get factory and create binding
-		CmisBindingFactory factory = CmisBindingFactory.newInstance();
-		parameters.put(SessionParameter.ATOMPUB_URL, url);
-		CmisBinding binding = factory.createCmisAtomPubBinding(parameters);
-		return binding;
-	}
-
-	private static CmisBinding createWsBinding(String url, String username, String password) {
-		boolean isPrefix = true;
-		String urlLower = url.toLowerCase();
-
-		if (urlLower.endsWith("?wsdl")) {
-			isPrefix = false;
-		} else if (urlLower.endsWith(".wsdl")) {
-			isPrefix = false;
-		} else if (urlLower.endsWith(".xml")) {
-			isPrefix = false;
-		}
-
-		return createBinding(url, isPrefix, username, password);
-	}
-
-	public static CmisBinding createBinding(String url, boolean isPrefix, String username, String password) {
-		// gather parameters
-		Map<String, String> parameters = new HashMap<String, String>();
-		parameters.put(SessionParameter.USER, username);
-		parameters.put(SessionParameter.PASSWORD, password);
-
-		if (!isPrefix) {
-			parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url);
-			parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url);
-		} else {
-			parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url + "RepositoryService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url + "NavigationService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url + "ObjectService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url + "VersioningService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url + "DiscoveryService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url + "RelationshipService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url + "MultiFilingService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url + "PolicyService?wsdl");
-			parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url + "ACLService?wsdl");
-		}
-
-		// get factory and create provider
-		CmisBindingFactory factory = CmisBindingFactory.newInstance();
-		CmisBinding binding = factory.createCmisWebServicesBinding(parameters);
-
-		return binding;
-	}
-
-	private String getAtomPubUrl() {
-		return System.getProperty(PROP_ATOMPUB_URL, DEFAULT_ATOMPUB_URL);
-	}
-
-	private String getWsUrl() {
-		return System.getProperty(PROP_WS_URL, DEFAULT_WS_URL);
-	}
-
-	private String getConfiguredUrl() {
-		return System.getProperty(PROP_URL, fUrlStr);
-	}
-
-	private void getUrl(String urlStr) {
-		URL url;
-		InputStream is;
-		InputStreamReader isr;
-		BufferedReader r;
-		String str;
-
-		try {
-			System.out.println("Reading URL: " + urlStr);
-			url = new URL(urlStr);
-			is = url.openStream();
-			isr = new InputStreamReader(is);
-			r = new BufferedReader(isr);
-			do {
-				str = r.readLine();
-				if (str != null)
-					System.out.println(str);
-			} while (str != null);
-		} catch (MalformedURLException e) {
-			System.out.println("Must enter a valid URL" + e);
-		} catch (IOException e) {
-			System.out.println("Can not connect" + e);
-		}
-	}
+    public static final String DEFAULT_USER = "";
+    public static final String DEFAULT_PWD = "";
+    public static final String PROP_ATOMPUB_URL = "opencmis.test.atompub.url";
+    public static final String PROP_URL = "url";
+    public static final String PROP_WS_URL = "opencmis.test.webservices.url";
+    public static final String DEFAULT_ATOMPUB_URL = "http://localhost:8080/opencmis/atom";
+    public static final String DEFAULT_WS_URL = "http://localhost:8080/cmis/services/";
+
+    private final static String CMD = "Command";
+    private final static String REPOSITORY_ID = "RepositoryId";
+    private final static String FILLER_DOCUMENT_TYPE_ID = "DocumentTypeId";
+    private final static String FILLER_FOLDER_TYPE_ID = "FolderTypeId";
+    private final static String FILLER_DOCS_PER_FOLDER = "DocsPerFolder";
+    private final static String FILLER_FOLDERS_PER_FOLDER = "FoldersPerFolder";
+    private final static String FILLER_DEPTH = "Depth";
+    private final static String FILLER_CONTENT_SIZE = "ContentSizeInKB";
+    private final static String COUNT = "Count";
+    private final static String BINDING = "Binding";
+    private final static String CLEANUP = "Cleanup";
+    private final static String ROOTFOLDER = "RootFolder";
+    private final static String THREADS = "Threads";
+
+    private final static String BINDING_ATOM = "AtomPub";
+    private final static String BINDING_WS = "WebService";
+
+    private CmisBinding binding;
+    private boolean fUsingAtom;
+    private String fUrlStr;
+
+    OptionSpec<String> fCmd;
+    OptionSpec<Integer> fDepth;
+    OptionSpec<Integer> fContentSize;
+    OptionSpec<Integer> fFolderPerFolder;
+    OptionSpec<Integer> fDocsPerFolder;
+    OptionSpec<String> fFolderType;
+    OptionSpec<String> fDocType;
+    OptionSpec<String> fRepoId;
+    OptionSpec<Integer> fCount;
+    OptionSpec<String> fBinding;
+    OptionSpec<Boolean> fCleanup;
+    OptionSpec<String> fRootFolder;
+    OptionSpec<Integer> fThreads;
+
+    public static void main(String[] args) {
+
+        ObjGenApp app = new ObjGenApp();
+        try {
+            app.processCmdLine(args);
+        } catch (CmisBaseException ce) {
+            System.out.println("Error: Could not process command. " + ce);
+            System.out.println("Extended error: " + ce.getErrorContent());
+            ce.printStackTrace();
+        } catch (Exception e) {
+            System.out.println("Could not fill repository " + e);
+            e.printStackTrace();
+        }
+    }
+
+    private void processCmdLine(String[] args) {
+
+        OptionParser parser = new OptionParser();
+        fCmd = parser.accepts(CMD).withRequiredArg().describedAs("Command to perform (see below)");
+        fRepoId = parser.accepts(REPOSITORY_ID).withOptionalArg().describedAs("Repository used");
+        fDocType = parser.accepts(FILLER_DOCUMENT_TYPE_ID).withOptionalArg().defaultsTo(
+                BaseTypeId.CMIS_DOCUMENT.value()).describedAs("Document type created");
+        fFolderType = parser.accepts(FILLER_FOLDER_TYPE_ID).withOptionalArg()
+                .defaultsTo(BaseTypeId.CMIS_FOLDER.value()).describedAs("Folder type created");
+        fDocsPerFolder = parser.accepts(FILLER_DOCS_PER_FOLDER).withOptionalArg().ofType(Integer.class).describedAs(
+                "Documents on each level").defaultsTo(1);
+        fFolderPerFolder = parser.accepts(FILLER_FOLDERS_PER_FOLDER).withOptionalArg().ofType(Integer.class)
+                .describedAs(" Folders on each level").defaultsTo(0);
+        fDepth = parser.accepts(FILLER_DEPTH).withOptionalArg().ofType(Integer.class).describedAs("Levels of folders")
+                .defaultsTo(1);
+        fContentSize = parser.accepts(FILLER_CONTENT_SIZE).withOptionalArg().ofType(Integer.class).describedAs(
+                "Content size of each doc").defaultsTo(0);
+        fCount = parser.accepts(COUNT).withOptionalArg().ofType(Integer.class).defaultsTo(1).describedAs(
+                "Repeat a command n times (partially implemented)");
+        fBinding = parser.accepts(BINDING).withOptionalArg().ofType(String.class).defaultsTo(BINDING_ATOM).describedAs(
+                "Protocol Binding: " + BINDING_ATOM + " or " + BINDING_WS);
+        fCleanup = parser.accepts(CLEANUP).withOptionalArg().ofType(Boolean.class).defaultsTo(false).describedAs(
+                "Clean all created objects at the end");
+        fRootFolder = parser.accepts(ROOTFOLDER).withOptionalArg().ofType(String.class).describedAs(
+                "folder id used as root to create objects (default repository root folder)");
+        fThreads = parser.accepts(THREADS).withOptionalArg().ofType(Integer.class).defaultsTo(1).describedAs(
+                "Number of threads to start in parallel");
+
+        OptionSet options = parser.parse(args);
+
+        if (options.valueOf(fCmd) == null || options.has("?"))
+            usage(parser);
+
+        if (options.valueOf(fBinding).equals(BINDING_WS)) {
+            fUsingAtom = false;
+        } else if (options.valueOf(fBinding).equals(BINDING_ATOM)) {
+            fUsingAtom = true;
+        } else {
+            System.out.println("Unknown option <Binding>: " + options.valueOf(fBinding) + " allowed values: "
+                    + BINDING_WS + " or " + BINDING_ATOM);
+            return;
+        }
+
+        if (options.valueOf(fCmd).equals("FillRepository")) {
+            fillRepository(options);
+        } else if (options.valueOf(fCmd).equals("CreateDocument")) {
+            createSingleDocument(options);
+        } else if (options.valueOf(fCmd).equals("CreateFolder")) {
+            createFolders(options);
+        } else if (options.valueOf(fCmd).equals("RepositoryInfo")) {
+            repositoryInfo(options);
+        } else if (options.valueOf(fCmd).equals("GetUrl")) {
+            getUrl(getConfiguredUrl());
+        } else {
+            System.out.println("Unknown cmd: " + options.valueOf(fCmd));
+            usage(parser);
+        }
+    }
+
+    // private void preInitExpensiveTasks() {
+    // // JAXB initialization is very expensive, count this separate:
+    // TimeLogger logger = new TimeLogger("Initialization");
+    // logger.start();
+    // try {
+    // JaxBHelper.createMarshaller();
+    // }
+    // catch (JAXBException e) {
+    // System.out.print("Failuer in JAXB init: " + e);
+    // e.printStackTrace();
+    // } // dummy call just to get initialized
+    // logger.stop();
+    // logger.printTimes();
+    // }
+
+    private void usage(OptionParser parser) {
+        try {
+            System.out.println();
+            System.out.println("ObjGenApp is a command line tool for testing a CMIS repository.");
+            System.out.println("Usage:");
+            parser.printHelpOn(System.out);
+            System.out.println();
+            System.out.println("Command is one of [CreateDocument, CreateFolder, FillRepository, RepositoryInfo]");
+            System.out.println("JVM system properties: " + PROP_ATOMPUB_URL + ", " + PROP_WS_URL);
+            System.out.println();
+            System.out.println("Example: ");
+            System.out
+                    .println("java -D"
+                            + PROP_ATOMPUB_URL
+                            + "=http://localhost:8080/opencmis/atom -cp ... "
+                            + "org.apache.chemistry.opencmis.util.repository.ObjGenApp --Binding=AtomPub --Command=CreateDocument "
+                            + "--RepositoryId=A1 --ContentSizeInKB=25");
+            return;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    private void fillRepository(String repoId, int docsPerFolder, int foldersPerFolders, int depth,
+            String documentType, String folderType, int contentSizeInKB, String rootFolderId, boolean doCleanup) {
+
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator.prepareForCreateTree(
+                getBinding(), repoId, docsPerFolder, foldersPerFolders, depth, documentType, folderType,
+                contentSizeInKB, rootFolderId, doCleanup);
+        ObjectGenerator gen = runner.getObjectGenerator();
+        runner.doCreateTree();
+
+        System.out.println();
+        System.out.println("Result:");
+        System.out.println("Filling repository succeeded.");
+        System.out.println("Folder used as root for creation (null=rootFolderId): " + rootFolderId);
+        System.out.println("Number of documents created: " + gen.getDocumentsInTotal());
+        System.out.println("Number of folders created: " + gen.getFoldersInTotal());
+        gen.printTimings();
+    }
+
+    private void fillRepositoryMT(int noThreads, String repoId, int docsPerFolder, int foldersPerFolders, int depth,
+            String documentType, String folderType, int contentSizeInKB, String rootFolderId, boolean doCleanup) {
+
+        // Step 1: create a root folder for each thread
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
+                .prepareForCreateFolder(getBinding(), repoId, folderType, rootFolderId, noThreads, doCleanup);
+        String[] folderIds = runner.doCreateFolder();
+
+        // Step 2: fill each root folder with an object tree
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
+                .prepareForCreateTreeMT(getBinding(), repoId, docsPerFolder, foldersPerFolders, depth, documentType,
+                        folderType, contentSizeInKB, folderIds, doCleanup);
+
+        MultiThreadedObjectGenerator.runMultiThreaded(runners);
+        System.out.println("Filling repository succeeded.");
+    }
+
+    private void printParameters(OptionSet options) {
+        if (fUsingAtom)
+            System.out.println("Using AtomPub, connecting to  " + getAtomPubUrl());
+        else
+            System.out.println("Using WebService, connecting to  " + getWsUrl());
+
+        System.out.println("Repository id is: " + options.valueOf(fRepoId));
+        System.out.println("Content size: " + options.valueOf(fContentSize));
+        System.out.println("Document Type: " + options.valueOf(fDocType));
+        System.out.println("Folder id used as root: " + options.valueOf(fRootFolder));
+        System.out.println("Delete all objects after creation: " + options.valueOf(fCleanup));
+        System.out.println("Number of actions to perform: " + options.valueOf(fCount));
+        System.out.println("Number of threads to start: " + options.valueOf(fThreads));
+    }
+
+    private void createSingleDocument(OptionSet options) {
+        System.out.println();
+        System.out.println("Creating document with parameters:");
+        printParameters(options);
+        int noThreads = options.valueOf(fThreads);
+        if (noThreads <= 1)
+            createSingleDocument(options.valueOf(fRepoId), options.valueOf(fDocType), options.valueOf(fContentSize),
+                    options.valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
+        else
+            createSingleDocumentMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocType), options
+                    .valueOf(fContentSize), options.valueOf(fRootFolder), options.valueOf(fCount), options
+                    .valueOf(fCleanup));
+    }
+
+    private void fillRepository(OptionSet options) {
+        System.out.println();
+        printParameters(options);
+        System.out.println("Creating object tree with folowing parameters: ");
+        System.out.println("Documents per folder: " + options.valueOf(fDocsPerFolder));
+        System.out.println("Folder per folder: " + options.valueOf(fFolderPerFolder));
+        System.out.println("Depth: " + options.valueOf(fDepth));
+        System.out.println("Folder Type: " + options.valueOf(fFolderType));
+
+        int noThreads = options.valueOf(fThreads);
+        if (noThreads <= 1)
+            fillRepository(options.valueOf(fRepoId), options.valueOf(fDocsPerFolder),
+                    options.valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
+                            .valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
+                            .valueOf(fCleanup));
+        else
+            fillRepositoryMT(noThreads, options.valueOf(fRepoId), options.valueOf(fDocsPerFolder), options
+                    .valueOf(fFolderPerFolder), options.valueOf(fDepth), options.valueOf(fDocType), options
+                    .valueOf(fFolderType), options.valueOf(fContentSize), options.valueOf(fRootFolder), options
+                    .valueOf(fCleanup));
+
+    }
+
+    private void createFolders(OptionSet options) {
+        System.out.println();
+        System.out.println("Creating folder with parameters:");
+        printParameters(options);
+        System.out.println("Folder Type: " + options.valueOf(fFolderType));
+        int noThreads = options.valueOf(fThreads);
+        if (noThreads <= 1)
+            createFolders(options.valueOf(fRepoId), options.valueOf(fFolderType), options.valueOf(fRootFolder), options
+                    .valueOf(fCount), options.valueOf(fCleanup));
+        else
+            createFoldersMT(noThreads, options.valueOf(fRepoId), options.valueOf(fFolderType), options
+                    .valueOf(fRootFolder), options.valueOf(fCount), options.valueOf(fCleanup));
+    }
+
+    private void createSingleDocument(String repoId, String documentType, int contentSizeInKB, String rootFolderId,
+            int docCount, boolean doCleanup) {
+
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
+                .prepareForCreateDocument(getBinding(), repoId, documentType, contentSizeInKB, rootFolderId, docCount,
+                        doCleanup);
+        ObjectGenerator gen = runner.getObjectGenerator();
+        String[] ids = runner.doCreateDocument();
+        System.out.println();
+        System.out.println("Result:");
+        System.out.println("Document creation succeeded.");
+        System.out.println("Folder used as root for creation: " + rootFolderId);
+        System.out.println("Ids of created documents: ");
+        if (null == ids)
+            System.out.println("<none>");
+        else
+            for (int i = 0; i < ids.length; i++)
+                System.out.println(ids[i]);
+        gen.printTimings();
+        gen.resetCounters();
+    }
+
+    private void createSingleDocumentMT(int noThreads, String repoId, String documentType, int contentSizeInKB,
+            String rootFolderId, int docCount, boolean doCleanup) {
+
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
+                .prepareForCreateDocumentMT(noThreads, getBinding(), repoId, documentType, contentSizeInKB,
+                        rootFolderId, docCount, doCleanup);
+
+        MultiThreadedObjectGenerator.runMultiThreaded(runners);
+        System.out.println("Document creation succeeded. All threads terminated.");
+    }
+
+    private void createFolders(String repoId, String folderType, String rootFolderId, int noFolders, boolean doCleanup) {
+
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner runner = MultiThreadedObjectGenerator
+                .prepareForCreateFolder(getBinding(), repoId, folderType, rootFolderId, noFolders, doCleanup);
+        ObjectGenerator gen = runner.getObjectGenerator();
+        String[] ids = runner.doCreateFolder();
+        System.out.println();
+        System.out.println("Result:");
+        System.out.println("Folder creation succeeded.");
+        System.out.println("Ids of created folders: ");
+        if (null == ids)
+            System.out.println("<none>");
+        else
+            for (int i = 0; i < ids.length; i++)
+                System.out.println(ids[i]);
+        gen.printTimings();
+        gen.resetCounters();
+    }
+
+    private void createFoldersMT(int noThreads, String repoId, String folderType, String rootFolderId, int noFolders,
+            boolean doCleanup) {
+
+        MultiThreadedObjectGenerator.ObjectGeneratorRunner[] runners = MultiThreadedObjectGenerator
+                .prepareForCreateFolderMT(noThreads, getBinding(), repoId, folderType, rootFolderId, noFolders,
+                        doCleanup);
+        MultiThreadedObjectGenerator.runMultiThreaded(runners);
+        System.out.println("Folder creation succeeded.");
+    }
+
+    private void callRepoInfo(String repositoryId, int count) {
+        RepositoryService repSvc = getBinding().getRepositoryService();
+        TimeLogger timeLogger = new TimeLogger("RepoInfoTest");
+        RepositoryInfo repoInfo = null;
+        for (int i = 0; i < count; i++) {
+            binding.clearRepositoryCache(repositoryId);
+            timeLogger.start();
+            repoInfo = repSvc.getRepositoryInfo(repositoryId, null);
+            timeLogger.stop();
+        }
+        System.out.println("Root Folder id is: " + (repoInfo == null ? "<unknown>" : repoInfo.getRootFolderId()));
+        timeLogger.printTimes();
+    }
+
+    private void repositoryInfo(OptionSet options) {
+        callRepoInfo(options.valueOf(fRepoId), options.valueOf(fCount));
+    }
+
+    private CmisBinding getBinding() {
+        if (binding == null) {
+            if (fUsingAtom)
+                binding = createAtomBinding(getAtomPubUrl(), DEFAULT_USER, DEFAULT_PWD);
+            else
+                binding = createWsBinding(getWsUrl(), DEFAULT_USER, DEFAULT_PWD);
+        }
+        return binding;
+    }
+
+    private static void filLoginParams(Map<String, String> parameters, String user, String password) {
+        if (user != null && user.length() > 0)
+            parameters.put(SessionParameter.USER, user);
+        if (user != null && user.length() > 0)
+            parameters.put(SessionParameter.PASSWORD, password);
+    }
+
+    private static CmisBinding createAtomBinding(String url, String user, String password) {
+
+        // gather parameters
+        Map<String, String> parameters = new HashMap<String, String>();
+        filLoginParams(parameters, user, password);
+
+        // get factory and create binding
+        CmisBindingFactory factory = CmisBindingFactory.newInstance();
+        parameters.put(SessionParameter.ATOMPUB_URL, url);
+        CmisBinding binding = factory.createCmisAtomPubBinding(parameters);
+        return binding;
+    }
+
+    private static CmisBinding createWsBinding(String url, String username, String password) {
+        boolean isPrefix = true;
+        String urlLower = url.toLowerCase();
+
+        if (urlLower.endsWith("?wsdl")) {
+            isPrefix = false;
+        } else if (urlLower.endsWith(".wsdl")) {
+            isPrefix = false;
+        } else if (urlLower.endsWith(".xml")) {
+            isPrefix = false;
+        }
+
+        return createBinding(url, isPrefix, username, password);
+    }
+
+    public static CmisBinding createBinding(String url, boolean isPrefix, String username, String password) {
+        // gather parameters
+        Map<String, String> parameters = new HashMap<String, String>();
+        parameters.put(SessionParameter.USER, username);
+        parameters.put(SessionParameter.PASSWORD, password);
+
+        if (!isPrefix) {
+            parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url);
+            parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url);
+        } else {
+            parameters.put(SessionParameter.WEBSERVICES_REPOSITORY_SERVICE, url + "RepositoryService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_NAVIGATION_SERVICE, url + "NavigationService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_OBJECT_SERVICE, url + "ObjectService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_VERSIONING_SERVICE, url + "VersioningService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_DISCOVERY_SERVICE, url + "DiscoveryService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_RELATIONSHIP_SERVICE, url + "RelationshipService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_MULTIFILING_SERVICE, url + "MultiFilingService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_POLICY_SERVICE, url + "PolicyService?wsdl");
+            parameters.put(SessionParameter.WEBSERVICES_ACL_SERVICE, url + "ACLService?wsdl");
+        }
+
+        // get factory and create provider
+        CmisBindingFactory factory = CmisBindingFactory.newInstance();
+        CmisBinding binding = factory.createCmisWebServicesBinding(parameters);
+
+        return binding;
+    }
+
+    private String getAtomPubUrl() {
+        return System.getProperty(PROP_ATOMPUB_URL, DEFAULT_ATOMPUB_URL);
+    }
+
+    private String getWsUrl() {
+        return System.getProperty(PROP_WS_URL, DEFAULT_WS_URL);
+    }
+
+    private String getConfiguredUrl() {
+        return System.getProperty(PROP_URL, fUrlStr);
+    }
+
+    private void getUrl(String urlStr) {
+        URL url;
+        InputStream is;
+        InputStreamReader isr;
+        BufferedReader r;
+        String str;
+
+        try {
+            System.out.println("Reading URL: " + urlStr);
+            url = new URL(urlStr);
+            is = url.openStream();
+            isr = new InputStreamReader(is);
+            r = new BufferedReader(isr);
+            do {
+                str = r.readLine();
+                if (str != null)
+                    System.out.println(str);
+            } while (str != null);
+        } catch (MalformedURLException e) {
+            System.out.println("Must enter a valid URL" + e);
+        } catch (IOException e) {
+            System.out.println("Can not connect" + e);
+        }
+    }
 
 }



Mime
View raw message