Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store
In directory sc8-pr-cvs1:/tmp/cvs-serv5310/src/java/org/neuclear/store
Modified Files:
EncryptedFileStore.java FileStore.java Store.java
Added Files:
StorageException.java
Log Message:
Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
- For most cases the main exception to worry about now is InvalidNamedObjectException.
- Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
runtime exception.
- Source and Store patterns each now have their own exceptions that generalizes the various physical
exceptions that can happen in that area.
--- NEW FILE: StorageException.java ---
package org.neuclear.store;
import org.neuclear.commons.NeuClearException;
/**
* Created by IntelliJ IDEA.
* User: pelleb
* Date: Dec 19, 2003
* Time: 11:11:50 AM
* To change this template use Options | File Templates.
*/
public class StorageException extends NeuClearException {
public StorageException(Store store,final Throwable cause) {
super("NeuClear Storage Exception in:\n"+store.getClass().getName()+"\n"+cause.getLocalizedMessage(),cause);
this.store=store;
}
public StorageException(Store store,final String message) {
super("NeuClear Storage Exception in:\n"+store.getClass().getName()+"\n"+message);
this.store=store;
}
public StorageException(Store store,final String message, final Throwable cause) {
super("NeuClear Storage Exception in:\n"+store.getClass().getName()+"\n"+message,cause);
this.store=store;
}
public Store getStore() {
return store;
}
private final Store store;
}
Index: EncryptedFileStore.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/EncryptedFileStore.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** EncryptedFileStore.java 10 Dec 2003 23:58:52 -0000 1.17
--- EncryptedFileStore.java 19 Dec 2003 18:03:35 -0000 1.18
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.18 2003/12/19 18:03:35 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.17 2003/12/10 23:58:52 pelle
* Did some cleaning up in the builders
***************
*** 201,204 ****
--- 209,213 ----
import org.neuclear.id.NSTools;
import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.id.InvalidNamedObjectException;
import javax.crypto.Cipher;
***************
*** 217,221 ****
}
! protected final OutputStream getOutputStream(final SignedNamedObject obj) throws NeuClearException, FileNotFoundException {
final String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
--- 226,230 ----
}
! protected final OutputStream getOutputStream(final SignedNamedObject obj) throws InvalidNamedObjectException, StorageException {
final String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
***************
*** 225,247 ****
return new CipherOutputStream(new FileOutputStream(outputFile), CryptoTools.makePBECipher(Cipher.ENCRYPT_MODE, obj.getName().toCharArray()));
} catch (Exception e) {
! throw new CryptoException(e);
}
}
! protected final InputStream getInputStream(final String name) throws FileNotFoundException, NeuClearException {
final String inputFilename = base + getFileName(name);
System.out.println("Loading from: " + inputFilename);
final File fin = new File(inputFilename);
if (!fin.exists())
! throw new NeuClearException("NeuClear: " + name + " doesnt exist");
try {
return new CipherInputStream(new FileInputStream(fin), CryptoTools.makePBECipher(Cipher.DECRYPT_MODE, name.toCharArray()));
} catch (Exception e) {
! throw new CryptoException(e);
}
}
! protected final String getFileName(final String name) throws NeuClearException {
final String deURLizedName = NSTools.normalizeNameURI(name);
final byte[] hash = CryptoTools.formatAsBase36(CryptoTools.digest256(deURLizedName.getBytes())).getBytes();
--- 234,256 ----
return new CipherOutputStream(new FileOutputStream(outputFile), CryptoTools.makePBECipher(Cipher.ENCRYPT_MODE, obj.getName().toCharArray()));
} catch (Exception e) {
! throw new StorageException(this,e);
}
}
! protected final InputStream getInputStream(final String name) throws InvalidNamedObjectException, StorageException {
final String inputFilename = base + getFileName(name);
System.out.println("Loading from: " + inputFilename);
final File fin = new File(inputFilename);
if (!fin.exists())
! throw new InvalidNamedObjectException(name);
try {
return new CipherInputStream(new FileInputStream(fin), CryptoTools.makePBECipher(Cipher.DECRYPT_MODE, name.toCharArray()));
} catch (Exception e) {
! throw new StorageException(this,e);
}
}
! protected final String getFileName(final String name) throws InvalidNamedObjectException {
final String deURLizedName = NSTools.normalizeNameURI(name);
final byte[] hash = CryptoTools.formatAsBase36(CryptoTools.digest256(deURLizedName.getBytes())).getBytes();
Index: FileStore.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/FileStore.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** FileStore.java 11 Dec 2003 23:57:29 -0000 1.18
--- FileStore.java 19 Dec 2003 18:03:35 -0000 1.19
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.19 2003/12/19 18:03:35 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.18 2003/12/11 23:57:29 pelle
* Trying to test the ReceiverServlet with cactus. Still no luck. Need to return a ElementProxy of some sort.
***************
*** 192,195 ****
--- 200,205 ----
import org.neuclear.id.NSTools;
import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.id.InvalidNamedObjectException;
+ import org.neuclear.id.NameResolutionException;
import org.neuclear.id.verifier.VerifyingReader;
import org.neuclear.xml.XMLException;
***************
*** 207,223 ****
}
! protected final void rawStore(final SignedNamedObject obj) throws IOException, NeuClearException, XMLException {
final OutputStream out = getOutputStream(obj);
! out.write(obj.getEncoded().getBytes("UTF-8"));
! out.close();
}
! protected OutputStream getOutputStream(final SignedNamedObject obj) throws NeuClearException, FileNotFoundException {
final String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
final File outputFile = new File(outputFilename);
outputFile.getParentFile().mkdirs();
! final OutputStream out = new FileOutputStream(outputFile);
! return out;
}
--- 217,241 ----
}
! protected final void rawStore(final SignedNamedObject obj) throws StorageException, InvalidNamedObjectException {
final OutputStream out = getOutputStream(obj);
! try {
! out.write(obj.getEncoded().getBytes("UTF-8"));
! out.close();
! } catch (IOException e) {
! throw new StorageException(this,e);
! }
}
! protected OutputStream getOutputStream(final SignedNamedObject obj) throws StorageException, InvalidNamedObjectException {
final String outputFilename = base + getFileName(obj);
System.out.println("Outputting to: " + outputFilename);
final File outputFile = new File(outputFilename);
outputFile.getParentFile().mkdirs();
! try {
! final OutputStream out = new FileOutputStream(outputFile);
! return out;
! } catch (FileNotFoundException e) {
! throw new StorageException(this,e);
! }
}
***************
*** 226,257 ****
// }
! final SignedNamedObject fetch(final String name) throws NeuClearException {
!
! try {
! return VerifyingReader.getInstance().read(getInputStream(name));
! } catch (FileNotFoundException e) {
! e.printStackTrace();
! } catch (XMLException e) {
! e.printStackTrace();
! }
! return null;
}
! protected InputStream getInputStream(final String name) throws FileNotFoundException, NeuClearException {
final String inputFilename = base + getFileName(name);
System.out.println("Loading from: " + inputFilename);
final File fin = new File(inputFilename);
if (!fin.exists())
! throw new NeuClearException("NeuClear: " + name + " doesnt exist");
! return new FileInputStream(fin);
}
! protected String getFileName(final String name) throws NeuClearException {
return NSTools.name2path(name) + "/root.id";
}
! protected final String getFileName(final SignedNamedObject obj) throws NeuClearException {
return getFileName(obj.getName());
// if (! (obj instanceof Identity))
--- 244,271 ----
// }
! final SignedNamedObject fetch(final String name) throws StorageException, InvalidNamedObjectException, NameResolutionException {
! return VerifyingReader.getInstance().read(getInputStream(name));
}
! protected InputStream getInputStream(final String name) throws InvalidNamedObjectException, StorageException {
final String inputFilename = base + getFileName(name);
System.out.println("Loading from: " + inputFilename);
final File fin = new File(inputFilename);
if (!fin.exists())
! throw new InvalidNamedObjectException(name);
! try {
! return new FileInputStream(fin);
! } catch (FileNotFoundException e) {
! throw new StorageException(this,e);
! }
}
! protected String getFileName(final String name) throws InvalidNamedObjectException {
return NSTools.name2path(name) + "/root.id";
}
! protected final String getFileName(final SignedNamedObject obj) throws InvalidNamedObjectException {
return getFileName(obj.getName());
// if (! (obj instanceof Identity))
Index: Store.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/store/Store.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** Store.java 10 Dec 2003 23:58:52 -0000 1.16
--- Store.java 19 Dec 2003 18:03:35 -0000 1.17
***************
*** 2,5 ****
--- 2,13 ----
* $Id$
* $Log$
+ * Revision 1.17 2003/12/19 18:03:35 pelle
+ * Revamped a lot of exception handling throughout the framework, it has been simplified in most places:
+ * - For most cases the main exception to worry about now is InvalidNamedObjectException.
+ * - Most lowerlevel exception that cant be handled meaningful are now wrapped in the LowLevelException, a
+ * runtime exception.
+ * - Source and Store patterns each now have their own exceptions that generalizes the various physical
+ * exceptions that can happen in that area.
+ *
* Revision 1.16 2003/12/10 23:58:52 pelle
* Did some cleaning up in the builders
***************
*** 188,191 ****
--- 196,201 ----
import org.neuclear.commons.NeuClearException;
import org.neuclear.id.SignedNamedObject;
+ import org.neuclear.id.InvalidNamedObjectException;
+ import org.neuclear.id.NameResolutionException;
import org.neuclear.receiver.Receiver;
import org.neuclear.xml.XMLException;
***************
*** 202,212 ****
*/
public final org.neuclear.xml.ElementProxy receive(final SignedNamedObject obj) throws NeuClearException {
! try {
! rawStore(obj);
! } catch (IOException e) {
! throw new NeuClearException(e);
! } catch (XMLException e) {
! throw new NeuClearException(e);
! }
return null;
}
--- 212,216 ----
*/
public final org.neuclear.xml.ElementProxy receive(final SignedNamedObject obj) throws NeuClearException {
! rawStore(obj);
return null;
}
***************
*** 215,223 ****
* Override this for each specific Store type
*/
! protected void rawStore(final SignedNamedObject obj) throws IOException, NeuClearException, XMLException {
;
}
! abstract SignedNamedObject fetch(String name) throws NeuClearException;
}
--- 219,227 ----
* Override this for each specific Store type
*/
! protected void rawStore(final SignedNamedObject obj) throws StorageException, InvalidNamedObjectException {
;
}
! abstract SignedNamedObject fetch(String name) throws StorageException, InvalidNamedObjectException, NameResolutionException;
}
|