Author: batosai
Date: 2008-08-13 15:00:52 +0000 (Wed, 13 Aug 2008)
New Revision: 21813
Modified:
trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
trunk/apps/WoT/src/plugins/WoT/Trust.java
trunk/apps/WoT/src/plugins/WoT/Trustlist.java
trunk/apps/WoT/src/plugins/WoT/WoT.java
trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
Log:
Refactor. Made Trust throw when given an invalid value.
Modified: trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java 2008-08-13
14:57:53 UTC (rev 21812)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityInserter.java 2008-08-13
15:00:52 UTC (rev 21813)
@@ -16,6 +16,8 @@
import javax.xml.transform.TransformerException;
import com.db4o.ObjectContainer;
+import com.db4o.ext.DatabaseClosedException;
+import com.db4o.ext.Db4oIOException;
import freenet.client.ClientMetadata;
import freenet.client.FetchException;
@@ -46,7 +48,7 @@
this.client = client;
}
- public void insert(OwnIdentity identity) throws
TransformerConfigurationException, FileNotFoundException,
ParserConfigurationException, TransformerException, IOException,
InsertException {
+ public void insert(OwnIdentity identity) throws
TransformerConfigurationException, FileNotFoundException,
ParserConfigurationException, TransformerException, IOException,
InsertException, Db4oIOException, DatabaseClosedException,
InvalidParameterException {
this.identity = identity;
Modified: trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java 2008-08-13 14:57:53 UTC
(rev 21812)
+++ trunk/apps/WoT/src/plugins/WoT/OwnIdentity.java 2008-08-13 15:00:52 UTC
(rev 21813)
@@ -32,6 +32,8 @@
import org.w3c.dom.Element;
import com.db4o.ObjectContainer;
+import com.db4o.ext.DatabaseClosedException;
+import com.db4o.ext.Db4oIOException;
import freenet.keys.FreenetURI;
@@ -64,8 +66,11 @@
* @throws TransformerException
* @throws FileNotFoundException
* @throws IOException
+ * @throws InvalidParameterException
+ * @throws DatabaseClosedException
+ * @throws Db4oIOException
*/
- public File exportToXML(ObjectContainer db, File dir ) throws
ParserConfigurationException, TransformerConfigurationException,
TransformerException, FileNotFoundException, IOException {
+ public File exportToXML(ObjectContainer db, File dir ) throws
ParserConfigurationException, TransformerConfigurationException,
TransformerException, FileNotFoundException, IOException, Db4oIOException,
DatabaseClosedException, InvalidParameterException {
// Create the output file
File outputFile = new File(dir, getNickName());
Modified: trunk/apps/WoT/src/plugins/WoT/Trust.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Trust.java 2008-08-13 14:57:53 UTC (rev
21812)
+++ trunk/apps/WoT/src/plugins/WoT/Trust.java 2008-08-13 15:00:52 UTC (rev
21813)
@@ -32,17 +32,16 @@
* @param truster Identity that gives the trust
* @param trustee Identity that receives the trust
* @param value Numeric value of the trust [-100;+100]
+ * @throws InvalidParameterException
*/
- public Trust(Identity truster, Identity trustee, int value) {
+ public Trust(Identity truster, Identity trustee, int value) throws
InvalidParameterException {
this.truster = truster;
this.trustee = trustee;
setValue(value);
}
- public Trust(Identity truster, Identity trustee, int value, String
comment) {
- this.truster = truster;
- this.trustee = trustee;
- setValue(value);
+ public Trust(Identity truster, Identity trustee, int value, String
comment) throws InvalidParameterException {
+ this(truster, trustee, value);
this.comment = comment;
}
@@ -101,11 +100,11 @@
/**
* @param value Numeric value of the trust [-100;+100]
+ * @throws InvalidParameterException if value isn't in the range
*/
- public void setValue(int value) {
- if(value >= -100 && value <= 100) {
- this.value = value;
- }
+ public void setValue(int value) throws InvalidParameterException {
+ if(value >= -100 && value <= 100) this.value = value;
+ else throw new InvalidParameterException("Invalid trust value
("+value+")");
}
/**
Modified: trunk/apps/WoT/src/plugins/WoT/Trustlist.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/Trustlist.java 2008-08-13 14:57:53 UTC
(rev 21812)
+++ trunk/apps/WoT/src/plugins/WoT/Trustlist.java 2008-08-13 15:00:52 UTC
(rev 21813)
@@ -10,6 +10,8 @@
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import com.db4o.ext.DatabaseClosedException;
+import com.db4o.ext.Db4oIOException;
/**
* TrustList of an Identity
@@ -25,8 +27,11 @@
*
* @param db Connection to db4o
* @param truster Identity that owns that trustList
+ * @throws InvalidParameterException
+ * @throws DatabaseClosedException
+ * @throws Db4oIOException
*/
- public Trustlist(ObjectContainer db, OwnIdentity truster) {
+ public Trustlist(ObjectContainer db, OwnIdentity truster) throws
Db4oIOException, DatabaseClosedException, InvalidParameterException {
list = db.queryByExample(new Trust(truster,null,0));
}
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-13 14:57:53 UTC (rev
21812)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-08-13 15:00:52 UTC (rev
21813)
@@ -6,12 +6,11 @@
package plugins.WoT;
import java.net.MalformedURLException;
-import java.util.HashSet;
-import java.util.Set;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
-import com.db4o.query.Constraint;
+import com.db4o.ext.DatabaseClosedException;
+import com.db4o.ext.Db4oIOException;
import com.db4o.query.Query;
import freenet.keys.FreenetURI;
@@ -48,8 +47,11 @@
/**
* Handles the creation of a new trust relationship, or the update of
an existing one.
* @param newTrust A Trust object reflecting the trust relationship.
+ * @throws InvalidParameterException
+ * @throws DatabaseClosedException
+ * @throws Db4oIOException
*/
- public void setTrust(Trust newTrust) {
+ public void setTrust(Trust newTrust) throws Db4oIOException,
DatabaseClosedException, InvalidParameterException {
boolean changedTrustValue = false;
boolean changedComment = false;
@@ -84,8 +86,11 @@
* Computes an id's score in a particular trust tree.
* @param treeOwner The owner of the trust tree
* @param identity The identity you want to update the score
+ * @throws InvalidParameterException
+ * @throws DatabaseClosedException
+ * @throws Db4oIOException
*/
- private void updateScore(OwnIdentity treeOwner, Identity identity) {
+ private void updateScore(OwnIdentity treeOwner, Identity identity)
throws Db4oIOException, DatabaseClosedException, InvalidParameterException {
Score score;
Modified: trunk/apps/WoT/src/plugins/WoT/WoTplugin.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 14:57:53 UTC
(rev 21812)
+++ trunk/apps/WoT/src/plugins/WoT/WoTplugin.java 2008-08-13 15:00:52 UTC
(rev 21813)
@@ -10,7 +10,6 @@
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Date;
-import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
@@ -19,6 +18,8 @@
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
+import com.db4o.ext.DatabaseClosedException;
+import com.db4o.ext.Db4oIOException;
import freenet.client.FetchException;
import freenet.client.HighLevelSimpleClient;
@@ -89,15 +90,20 @@
public String handleHTTPGet(HTTPRequest request) throws
PluginHTTPException {
String page = request.getPath().substring(SELF_URI.length());
- if(page.equals("/ownidentities")) {
- return makeOwnIdentitiesPage();
+
+ try {
+ if(page.equals("/ownidentities")) {
+ return makeOwnIdentitiesPage();
+ }
+ if(page.equals("/knownidentities")) {
+ return makeKnownIdentitiesPage();
+ }
+ else {
+ return makeHomePage();
+ }
+ } catch (Exception e) {
+ return e.getMessage();
}
- if(page.equals("/knownidentities")) {
- return makeKnownIdentitiesPage();
- }
- else {
- return makeHomePage();
- }
}
private String makeHomePage() {
@@ -162,11 +168,11 @@
return pageNode.generate();
}
- private String makeKnownIdentitiesPage() {
+ private String makeKnownIdentitiesPage() throws Db4oIOException,
DatabaseClosedException, InvalidParameterException {
return makeKnownIdentitiesPage("");
}
- private String makeKnownIdentitiesPage(String owner) {
+ private String makeKnownIdentitiesPage(String owner) throws
Db4oIOException, DatabaseClosedException, InvalidParameterException {
Identity treeOwner = null;
@@ -363,7 +369,7 @@
setTrust((OwnIdentity)trusterId, trusteeId,
Integer.parseInt(value), comment);
}
- private void setTrust(OwnIdentity truster, Identity trustee, int value,
String comment) throws TransformerConfigurationException,
FileNotFoundException, ParserConfigurationException, TransformerException,
IOException, InsertException {
+ private void setTrust(OwnIdentity truster, Identity trustee, int value,
String comment) throws TransformerConfigurationException,
FileNotFoundException, ParserConfigurationException, TransformerException,
IOException, InsertException, Db4oIOException, DatabaseClosedException,
InvalidParameterException {
wot.setTrust(new Trust(truster, trustee, value, comment));