From: David ‘Bombe’ Roden Date: Thu, 15 May 2008 14:01:45 +0000 (+0000) Subject: make key generation throw exceptions in case of errors X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=7a6a3c1c08be242d176b141f261e25b16fee84aa;p=jSite2.git make key generation throw exceptions in case of errors git-svn-id: http://trooper/svn/projects/jSite/trunk@889 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/core/Core.java b/src/net/pterodactylus/jsite/core/Core.java index 2815e38..d2a5e10 100644 --- a/src/net/pterodactylus/jsite/core/Core.java +++ b/src/net/pterodactylus/jsite/core/Core.java @@ -116,11 +116,12 @@ public interface Core { * * @param projectName * The name of the project - * @return A newly created project, or null if key generation - * failed + * @return A newly created project * @throws IOException * if an I/O error occured communicating with the node + * @throws NoNodeException + * if no node is configured */ - public Project addProject(String projectName) throws IOException; + public Project createProject(String projectName) throws IOException, NoNodeException; } diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index eae7b3a..3e96b10 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -441,13 +441,10 @@ public class CoreImpl implements Core, NodeListener, RequestListener { /** * {@inheritDoc} */ - public Project addProject(String projectName) throws IOException { + public Project createProject(String projectName) throws IOException, NoNodeException { Project project = new Project(); project.setName(projectName); String[] keyPair = nodeManager.generateKeyPair(); - if (keyPair == null) { - return null; - } project.setPrivateKey(keyPair[0]); project.setPublicKey(keyPair[1]); return project; diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index f772dc2..b9404c7 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -429,17 +429,20 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * public key at index 1 * @throws IOException * if an I/O error occurs communicating with the node + * @throws NoNodeException + * if no node is configured */ - public String[] generateKeyPair() throws IOException { - if (!nodes.isEmpty()) { - Node node = nodes.get(0); - HighLevelClient highLevelClient = nodeClients.get(node); - try { - KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult(); - return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() }; - } catch (InterruptedException e) { - /* ignore. */ - } + public String[] generateKeyPair() throws IOException, NoNodeException { + if (nodes.isEmpty()) { + throw new NoNodeException("no node configured"); + } + Node node = nodes.get(0); + HighLevelClient highLevelClient = nodeClients.get(node); + try { + KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult(); + return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() }; + } catch (InterruptedException e) { + /* ignore. */ } return null; } diff --git a/src/net/pterodactylus/jsite/gui/SwingInterface.java b/src/net/pterodactylus/jsite/gui/SwingInterface.java index 0accb58..3652388 100644 --- a/src/net/pterodactylus/jsite/gui/SwingInterface.java +++ b/src/net/pterodactylus/jsite/gui/SwingInterface.java @@ -45,6 +45,7 @@ import javax.swing.UnsupportedLookAndFeelException; import net.pterodactylus.jsite.core.Core; import net.pterodactylus.jsite.core.CoreListener; +import net.pterodactylus.jsite.core.NoNodeException; import net.pterodactylus.jsite.core.Node; import net.pterodactylus.jsite.core.Project; import net.pterodactylus.jsite.core.Request; @@ -817,10 +818,14 @@ public class SwingInterface implements CoreListener, LoggingListener { */ private void addProject() { try { - Project project = core.addProject("New Project"); + Project project = core.createProject("New Project"); System.out.println("private: " + project.getPrivateKey() + ", public: " + project.getPublicKey()); mainWindow.addProject(project); + } catch (NoNodeException nne1) { + /* TODO - add i18n */ + JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); } catch (IOException e) { + /* TODO - add i18n */ JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE); } }