001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.adapter.ls.exec.ui;
034:
035: import org.libresource.so6.adapter.ls.tools.IndeterminateProgressView;
036: import org.libresource.so6.adapter.ls.tools.LsClassicPropertiesEditor;
037: import org.libresource.so6.core.client.AuthenticationException;
038: import org.libresource.so6.core.client.LocalException;
039: import org.libresource.so6.core.client.ServerException;
040: import org.libresource.so6.core.client.UnableToContactServerException;
041: import org.libresource.so6.core.exec.CreateGenericWsConnection;
042:
043: import java.io.IOException;
044:
045: import java.util.Hashtable;
046: import java.util.Properties;
047:
048: import javax.swing.JOptionPane;
049:
050: /**
051: * @author smack
052: */
053: public class CreateLibresourceReplica extends LsClassicPropertiesEditor {
054: private String basePath;
055: private String login;
056: private String password;
057: private String queueId;
058: private String wsName;
059:
060: public CreateLibresourceReplica(String queueId_, String basePath_,
061: String login_, String password_, String wsName_,
062: String clientName_, Properties clientProperties_)
063: throws IOException {
064: super ("Create Workspace");
065: addTextPropertie("wsName", "Workspace Name :", wsName_);
066: addPathPropertie("basePath", "Base Path :", basePath_);
067: addTextPropertie("synchronizerURI", "Synchronizer URI :",
068: queueId_);
069: addTextPropertie("login", "Login :", login_);
070: addPasswordPropertie("password", "Password :", password_);
071:
072: Hashtable props = editProperties();
073:
074: if (props != null) {
075: new IndeterminateProgressView("Workspace creation",
076: "Please wait during the local workspace creation...");
077:
078: basePath = (String) props.get("basePath");
079: wsName = (String) props.get("wsName");
080: queueId = (String) props.get("synchronizerURI");
081: login = (String) props.get("login");
082: password = (String) props.get("password");
083:
084: //
085: try {
086: new CreateGenericWsConnection(basePath, wsName,
087: clientName_, login, password, queueId,
088: clientProperties_).execute();
089: } catch (AuthenticationException e) {
090: e.printStackTrace();
091: JOptionPane
092: .showMessageDialog(null,
093: "<html><b>Invalide user name or password</b><br></html>");
094: System.exit(0);
095: } catch (ServerException e) {
096: e.printStackTrace();
097: JOptionPane.showMessageDialog(null,
098: "<html><b>Server error</b><br>"
099: + e.getMessage() + "</html>");
100: System.exit(0);
101: } catch (IOException e) {
102: e.printStackTrace();
103: JOptionPane.showMessageDialog(null,
104: "<html><b>Local error (IO error)</b><br>"
105: + e.getMessage() + "</html>");
106: System.exit(0);
107: } catch (UnableToContactServerException e) {
108: e.printStackTrace();
109: JOptionPane.showMessageDialog(null,
110: "<html><b>Unable to contact server</b><br>"
111: + e.getMessage() + "</html>");
112: System.exit(0);
113: } catch (LocalException e) {
114: e.printStackTrace();
115: JOptionPane.showMessageDialog(null,
116: "<html><b>Local error</b><br>" + e.getMessage()
117: + "</html>");
118: System.exit(0);
119: } catch (Exception e) {
120: e.printStackTrace();
121: JOptionPane.showMessageDialog(null,
122: "<html><b>Error</b><br>" + e.getMessage()
123: + "</html>");
124: System.exit(0);
125: }
126: } else {
127: System.exit(0);
128: }
129: }
130:
131: public static void main(String[] args) throws Exception {
132: if (args.length > 1) {
133: System.err
134: .println("The only parameter required is the client class name");
135: System.err
136: .println("To set default value please use System properties");
137: System.err
138: .println(" (1) createLibresourceReplica.basePath = workspace base path");
139: System.err
140: .println(" (2) createLibresourceReplica.wsName = name of the workspace");
141: System.err
142: .println(" (3) createLibresourceReplica.queueId = the synchronizer URI");
143: System.err
144: .println(" (4) createLibresourceReplica.login = user login");
145: System.err
146: .println(" (5) createLibresourceReplica.password = user password");
147: } else if (args.length == 1) {
148: String queueId = System.getProperties().getProperty(
149: "createLibresourceReplica.queueId", "");
150: String basePath = System.getProperties().getProperty(
151: "createLibresourceReplica.basePath", "");
152: String login = System.getProperties().getProperty(
153: "createLibresourceReplica.login", "");
154: String password = System.getProperties().getProperty(
155: "createLibresourceReplica.password", "");
156: String wsName = System.getProperties().getProperty(
157: "createLibresourceReplica.wsName", "");
158: String clientName = args[0];
159:
160: new CreateLibresourceReplica(queueId, basePath, login,
161: password, wsName, clientName, null);
162: JOptionPane
163: .showMessageDialog(
164: null,
165: "<html>Your replica has been created localy.<br>(Refresh your browser to see it...)</html>");
166: System.exit(0);
167: }
168: }
169: }
|