public static void main(final String[] args) throws Exception {
parseParams(args);
Exception repo_exc = null;
UserRepository src_repo = null;
UserAuthRepository src_auth = null;
try {
src_repo = RepositoryFactory.getUserRepository("util", src_class, src_uri,
null);
System.out.println(
"Loaded src_repo " + src_repo.getClass().getName()
+ " for parameters:"
+ "\n src_class=" + src_class
+ "\n src_uri=" + src_uri);
} catch (Exception e) {
repo_exc = e;
src_repo = null;
} // end of try-catch
// Unsuccessful UserRepository initialization
// Let's try with AuthRepository....
if (src_repo == null) {
try {
src_auth = RepositoryFactory.getAuthRepository("util", src_class, src_uri,
null);
System.out.println(
"Loaded src_auth " + src_auth.getClass().getName()
+ " for parameters:"
+ "\n src_class=" + src_class
+ "\n src_uri=" + src_uri);
} catch (Exception e) {
System.out.println("Incorrect source class name given (or connection URI).");
System.out.println("class: " + src_class);
System.out.println("uri: " + src_uri);
System.out.println("Can't initialize repository:");
repo_exc.printStackTrace();
e.printStackTrace();
System.exit(-1);
} // end of try-catch
} // end of if (src_repo == null)
if (simple_test) {
System.out.println("Simple test on repository:");
simpleTest(src_repo);
} // end of if (simple_test)
if (add_user_test) {
System.out.println("Simple test on repository:");
userAddTest(src_repo);
} // end of if (simple_test)
if (add) {
if (key_val && src_repo != null) {
System.out.println("Adding key=value: " + content);
parseNodeKeyValue(content);
System.out.println("Parsed parameters: user=" + user
+ ", node=" + subnode + ", key=" + key + ", value=" + value);
src_repo.setData(user, subnode, key, value);
} else {
System.out.println("Adding user: " + user);
if (src_repo != null) {
src_repo.addUser(user);
}
if (src_auth != null) {
int idx = user.indexOf(':');
String name = user;
String password = "";
if (idx >= 0) {
name = user.substring(0, idx);
password = user.substring(idx+1, user.length());
}
src_auth.addUser(name, password);
}
} // end of else
} // end of if (add)
if (del) {
if (key_val || node) {
if (key_val) {
System.out.println("Deleting data: " + content);
parseNodeKeyValue(content);
System.out.println("Parsed parameters: user=" + user
+ ", node=" + subnode + ", key=" + key + ", value=" + value);
src_repo.removeData(user, subnode, key);
} // end of if (key_val)
if (node) {
System.out.println("Deleting data node: " + content);
src_repo.removeSubnode(user, content);
} // end of if (node)
} else {
System.out.println("Deleting user: " + user);
if (src_repo != null) {
src_repo.removeUser(user);
}
if (src_auth != null) {
src_auth.removeUser(user);
}
} // end of else
} // end of if (del)
if (copy_repos) {
UserRepository dst_repo = null;
Exception dst_exc = null;
UserAuthRepository dst_auth = null;
try {
dst_repo = RepositoryFactory.getUserRepository("util", dst_class, dst_uri,
null);
System.out.println(
"Loaded dst_repo " + dst_repo.getClass().getName()
+ " for parameters:"
+ "\n src_class=" + dst_class
+ "\n src_uri=" + dst_uri);
copyRepositories(src_repo, dst_repo);
} catch (Exception e) {