|
From: <pe...@us...> - 2003-09-22 19:24:13
|
Update of /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/source
In directory sc8-pr-cvs1:/tmp/cvs-serv4908/src/java/org/neuclear/source
Modified Files:
CachedSource.java HttpSource.java Source.java
Log Message:
More fixes throughout to problems caused by renaming.
Index: CachedSource.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/source/CachedSource.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** CachedSource.java 19 Sep 2003 14:41:44 -0000 1.1.1.1
--- CachedSource.java 22 Sep 2003 19:24:02 -0000 1.2
***************
*** 3,6 ****
--- 3,9 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:02 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:44 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 29,33 ****
import org.neuclear.id.NSTools;
import org.neuclear.id.NamedObject;
! import org.neuclear.utils.NeudistException;
import java.util.Map;
--- 32,36 ----
import org.neuclear.id.NSTools;
import org.neuclear.id.NamedObject;
! import org.neudist.utils.NeudistException;
import java.util.Map;
***************
*** 39,55 ****
public final class CachedSource extends Source {
public CachedSource(Source src) {
! this.src=src;
! cache=new LRUMap(CACHE_SIZE);
}
public NamedObject fetch(String endpoint, String name) throws NeudistException {
! name=NSTools.normalizeNameURI(name);
! NamedObject candidate=(NamedObject)cache.get(name);
! if (candidate!=null)
return candidate;
! candidate=src.fetch(endpoint, name);
! if (candidate!=null)
storeInCache(candidate);
return candidate;
--- 42,58 ----
public final class CachedSource extends Source {
public CachedSource(Source src) {
! this.src = src;
! cache = new LRUMap(CACHE_SIZE);
}
public NamedObject fetch(String endpoint, String name) throws NeudistException {
! name = NSTools.normalizeNameURI(name);
! NamedObject candidate = (NamedObject) cache.get(name);
! if (candidate != null)
return candidate;
! candidate = src.fetch(endpoint, name);
! if (candidate != null)
storeInCache(candidate);
return candidate;
***************
*** 57,62 ****
}
! private void storeInCache(NamedObject obj) throws NeudistException{
! cache.put(obj.getName(),obj);
}
--- 60,65 ----
}
! private void storeInCache(NamedObject obj) throws NeudistException {
! cache.put(obj.getName(), obj);
}
***************
*** 64,68 ****
private final Source src;
! public static final int CACHE_SIZE=10000;
--- 67,71 ----
private final Source src;
! public static final int CACHE_SIZE = 10000;
Index: HttpSource.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/source/HttpSource.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** HttpSource.java 19 Sep 2003 14:41:49 -0000 1.1.1.1
--- HttpSource.java 22 Sep 2003 19:24:02 -0000 1.2
***************
*** 7,11 ****
import org.neuclear.id.NamedObject;
import org.neuclear.id.NamedObjectFactory;
! import org.neuclear.utils.NeudistException;
import java.net.MalformedURLException;
--- 7,11 ----
import org.neuclear.id.NamedObject;
import org.neuclear.id.NamedObjectFactory;
! import org.neudist.utils.NeudistException;
import java.net.MalformedURLException;
***************
*** 19,22 ****
--- 19,25 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:02 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:49 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 42,56 ****
public class HttpSource extends Source {
public HttpSource() {
! reader=new SAXReader();
}
public NamedObject fetch(String endpoint, String name) throws NeudistException {
try {
! String urlstring = endpoint+NSTools.url2path(name);
! URL url=new URL(urlstring);
! Document doc=reader.read(url);
return NamedObjectFactory.createNamedObject(doc);
} catch (DocumentException e) {
! throw new NeudistException(name+ " not found");
} catch (MalformedURLException e) {
throw new NeudistException(e);
--- 45,59 ----
public class HttpSource extends Source {
public HttpSource() {
! reader = new SAXReader();
}
public NamedObject fetch(String endpoint, String name) throws NeudistException {
try {
! String urlstring = endpoint + NSTools.url2path(name);
! URL url = new URL(urlstring);
! Document doc = reader.read(url);
return NamedObjectFactory.createNamedObject(doc);
} catch (DocumentException e) {
! throw new NeudistException(name + " not found");
} catch (MalformedURLException e) {
throw new NeudistException(e);
***************
*** 58,66 ****
}
! public static void main(String args[]){
! Source source=new HttpSource();
try {
! NamedObject obj=source.fetch("http://repository.neuclear.org","/pelle");
! System.out.println("Got: "+obj.getName());
System.out.println(obj.getElement().asXML());
} catch (NeudistException e) {
--- 61,69 ----
}
! public static void main(String args[]) {
! Source source = new HttpSource();
try {
! NamedObject obj = source.fetch("http://repository.neuclear.org", "/pelle");
! System.out.println("Got: " + obj.getName());
System.out.println(obj.getElement().asXML());
} catch (NeudistException e) {
***************
*** 68,71 ****
--- 71,75 ----
}
}
+
private SAXReader reader;
}
Index: Source.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-id/src/java/org/neuclear/source/Source.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** Source.java 19 Sep 2003 14:41:49 -0000 1.1.1.1
--- Source.java 22 Sep 2003 19:24:02 -0000 1.2
***************
*** 2,7 ****
import org.neuclear.id.NamedObject;
! import org.neuclear.utils.NeudistException;
! import org.neuclear.utils.Utility;
/**
--- 2,7 ----
import org.neuclear.id.NamedObject;
! import org.neudist.utils.NeudistException;
! import org.neudist.utils.Utility;
/**
***************
*** 12,15 ****
--- 12,18 ----
* $Id$
* $Log$
+ * Revision 1.2 2003/09/22 19:24:02 pelle
+ * More fixes throughout to problems caused by renaming.
+ *
* Revision 1.1.1.1 2003/09/19 14:41:49 pelle
* First import into the neuclear project. This was originally under the SF neudist
***************
*** 42,64 ****
public static synchronized Source getInstance() {
! if (instance==null) {
! Source mainSource=null;
! String name=System.getProperty("org.neuclear.source");
! if (Utility.isEmpty(name)) {
! name=DEFAULT;
! }
try {
! mainSource=(Source)Class.forName(name).newInstance();
! } catch (Exception e) {
! e.printStackTrace(); //To change body of catch statement use Options | File Templates.
! try {
! mainSource=(Source)Class.forName(DEFAULT).newInstance();
! } catch (Exception e1) {
! e1.printStackTrace(); //To change body of catch statement use Options | File Templates.
! System.err.println("Real big problems");
! }
}
- instance=new CachedSource(mainSource);
}
return instance;
--- 45,67 ----
public static synchronized Source getInstance() {
! if (instance == null) {
! Source mainSource = null;
! String name = System.getProperty("org.neuclear.source");
! if (Utility.isEmpty(name)) {
! name = DEFAULT;
! }
! try {
! mainSource = (Source) Class.forName(name).newInstance();
! } catch (Exception e) {
! e.printStackTrace(); //To change body of catch statement use Options | File Templates.
try {
! mainSource = (Source) Class.forName(DEFAULT).newInstance();
! } catch (Exception e1) {
! e1.printStackTrace(); //To change body of catch statement use Options | File Templates.
! System.err.println("Real big problems");
}
}
+ instance = new CachedSource(mainSource);
+ }
return instance;
***************
*** 67,70 ****
private static Source instance;
! private final static String DEFAULT="org.neuclear.source.HttpSource";
}
--- 70,73 ----
private static Source instance;
! private final static String DEFAULT = "org.neuclear.source.HttpSource";
}
|