Author: kono
Date: 2009-03-09 16:59:49 -0700 (Mon, 09 Mar 2009)
New Revision: 16189
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/CyFileFilterImpl.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/AbstractNetworkReader.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderFactoryImpl.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderManagerImpl.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/gml/GMLReader.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/sif/InteractionsReader.java
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/xgmml/XGMMLReader.java
Log:
Now read() method returns actual read object.
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/CyFileFilterImpl.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/CyFileFilterImpl.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/internal/CyFileFilterImpl.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -37,6 +37,7 @@
package org.cytoscape.io.internal;
import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.URI;
@@ -128,6 +129,19 @@
return false;
}
+ /**
+ * Must be overridden by subclasses.
+ */
+ public boolean accept(InputStream stream, DataCategory category) throws
IOException {
+
+ // Check data category
+ if(category != this.category)
+ return false;
+
+ return true;
+
+ }
+
public Set<String> getExtensions() {
return extensions;
}
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/AbstractNetworkReader.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/AbstractNetworkReader.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/AbstractNetworkReader.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -3,7 +3,6 @@
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.cytoscape.io.read.CyReader;
import org.cytoscape.layout.CyLayouts;
@@ -13,43 +12,34 @@
abstract public class AbstractNetworkReader implements CyReader {
protected static final String NODE_NAME_ATTR_LABEL = "name";
-
+
protected InputStream inputStream;
protected CyNetworkFactory cyNetworkFactory;
protected GraphViewFactory graphViewFactory;
-
+
protected CyLayouts layouts;
-
+
protected Map<Class<?>, Object> readObjects;
public AbstractNetworkReader() {
this.readObjects = new HashMap<Class<?>, Object>();
}
-
+
public void setCyNetworkFactory(CyNetworkFactory cyNetworkFactory) {
this.cyNetworkFactory = cyNetworkFactory;
}
-
+
public void setGraphViewFactory(GraphViewFactory graphViewFactory) {
this.graphViewFactory = graphViewFactory;
}
-
+
public void setLayouts(CyLayouts layouts) {
this.layouts = layouts;
}
- public <T> T getReadData(Class<T> type) {
- return type.cast(readObjects.get(type));
- }
-
public void setInputStream(InputStream is) {
if (is == null)
throw new NullPointerException("Input stream is null");
inputStream = is;
}
-
- public Set<Class<?>> getSupportedDataTypes() {
- return readObjects.keySet();
- }
-
}
\ No newline at end of file
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderFactoryImpl.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderFactoryImpl.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderFactoryImpl.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -1,6 +1,7 @@
package org.cytoscape.io.read.internal;
import java.io.IOException;
+import java.io.InputStream;
import java.net.Proxy;
import java.net.URI;
import java.net.URLConnection;
@@ -13,7 +14,7 @@
private CyFileFilter filter;
private CyReader reader;
-
+
// This should be an OSGi service.
private Proxy proxy;
@@ -28,7 +29,7 @@
throw new IllegalArgumentException("CyFileFilter cannot
be null.");
}
}
-
+
public void setProxy(Proxy proxy) {
this.proxy = proxy;
}
@@ -43,15 +44,19 @@
*/
public CyReader getReader(URI uri) throws IOException {
final URLConnection urlConn;
-
+
// Proxy available
- if(proxy != null) {
+ if (proxy != null) {
urlConn = uri.toURL().openConnection(proxy);
} else {
urlConn = uri.toURL().openConnection();
}
-
- reader.setInputStream(urlConn.getInputStream());
+
+ return getReader(urlConn.getInputStream());
+ }
+
+ public CyReader getReader(InputStream stream) throws IOException {
+ reader.setInputStream(stream);
return reader;
}
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderManagerImpl.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderManagerImpl.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/CyReaderManagerImpl.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -34,8 +34,8 @@
*/
package org.cytoscape.io.read.internal;
-import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import java.util.HashSet;
import java.util.Map;
@@ -92,7 +92,17 @@
*/
public CyReader getReader(URI fileLocation, DataCategory category)
throws IllegalArgumentException {
+ return getReader(fileLocation, null, category);
+ }
+ public CyReader getReader(InputStream stream, DataCategory category)
+ throws IllegalArgumentException {
+ return getReader(null, stream, category);
+ }
+
+ private CyReader getReader(URI uri, InputStream stream,
+ DataCategory category) {
+
CyFileFilter cff;
CyReader reader = null;
@@ -100,8 +110,13 @@
cff = factory.getCyFileFilter();
try {
- if (cff.accept(fileLocation, category))
- reader =
factory.getReader(fileLocation);
+ if (uri != null) {
+ if (cff.accept(uri, category))
+ reader = factory.getReader(uri);
+ } else {
+ if (cff.accept(stream, category))
+ reader =
factory.getReader(stream);
+ }
} catch (IOException e) {
e.printStackTrace();
throw new IllegalArgumentException(
@@ -114,12 +129,7 @@
}
return reader;
- }
- public CyReader getReader(String fileLocation, DataCategory category)
- throws IllegalArgumentException {
- final File file = new File(fileLocation);
- return getReader(file.toURI(), category);
}
}
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/gml/GMLReader.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/gml/GMLReader.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/gml/GMLReader.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -50,7 +50,7 @@
import java.util.Set;
import java.util.Vector;
-import org.cytoscape.io.read.CyReader;
+import org.cytoscape.io.read.internal.AbstractNetworkReader;
import org.cytoscape.io.read.internal.VisualStyleBuilder;
import org.cytoscape.layout.CyLayoutAlgorithm;
import org.cytoscape.layout.LayoutAdapter;
@@ -74,7 +74,7 @@
* generated when you call this class. The new style saves all visual features
* (like node shape) and will not be lost even after other style selected.
*/
-public class GMLReader implements CyReader {
+public class GMLReader extends AbstractNetworkReader {
/**
* The following are all taken to be reserved keywords for gml (note
that
* not all of them are actually keywords according to the spec)
@@ -251,7 +251,7 @@
/**
* DOCUMENT ME!
*/
- public void read() throws IOException {
+ public Map<Class<?>, Object> read() throws IOException {
try {
keyVals = (new GMLParser(inputStream)).parseList();
} catch (Exception io) {
@@ -274,6 +274,8 @@
extract();
releaseStructures();
+
+ return readObjects;
}
/**
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/sif/InteractionsReader.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/sif/InteractionsReader.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/sif/InteractionsReader.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -38,10 +38,10 @@
package org.cytoscape.io.read.internal.sif;
import java.io.IOException;
-import java.util.ArrayList;
import java.util.HashMap;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.cytoscape.io.internal.util.ReadUtils;
import org.cytoscape.io.read.internal.AbstractNetworkReader;
@@ -55,55 +55,58 @@
* provides the graph and attributes objects constructed from the file.
*/
public class InteractionsReader extends AbstractNetworkReader {
-
+
private static final String DEF_DELIMITER = " ";
private static final String LINE_SEP =
System.getProperty("line.separator");
-
+
private static final String INTERACTION = "interaction";
-
+
private ReadUtils readUtil;
- private List<Interaction> interactions;
+ private Set<Interaction> interactions;
+
public InteractionsReader(ReadUtils readUtil) {
super();
- this.interactions = new ArrayList<Interaction>();
+ this.interactions = new HashSet<Interaction>();
this.readUtil = readUtil;
}
- public void read() throws IOException {
+ public Map<Class<?>, Object> read() throws IOException {
refresh();
-
+
String delimiter = DEF_DELIMITER;
-
+
final String rawText = readUtil.getInputString(inputStream);
-
+
if (rawText.indexOf("\t") >= 0)
delimiter = "\t";
final String[] lines = rawText.split(LINE_SEP);
final int size = lines.length;
- for (int i=0; i < size; i++) {
+ for (int i = 0; i < size; i++) {
if (lines[i].length() <= 0)
continue;
interactions.add(new Interaction(lines[i], delimiter));
}
-
- if(inputStream != null) {
+
+ if (inputStream != null) {
inputStream.close();
inputStream = null;
}
createNetwork();
+
+ return readObjects;
}
private void refresh() {
readObjects.clear();
interactions.clear();
- interactions = new ArrayList<Interaction>();
+ interactions = new HashSet<Interaction>();
readObjects = new HashMap<Class<?>, Object>();
}
-
+
private void createNetwork() {
final CyNetwork network = cyNetworkFactory.getInstance();
@@ -124,12 +127,13 @@
nodeMap.put(nodeName, node);
}
- // Now loop over the interactions again, this time creating
edges between
+ // Now loop over the interactions again, this time creating
edges
+ // between
// all sources and each of their respective targets.
String srcName;
String interactionType;
CyEdge edge;
-
+
for (Interaction interaction : interactions) {
srcName = interaction.getSource();
@@ -143,13 +147,13 @@
edge.attrs().set(INTERACTION, interactionType);
}
}
-
+
readObjects.put(CyNetwork.class, network);
-
- final GraphView view = graphViewFactory.createGraphView(
network );
+
+ final GraphView view =
graphViewFactory.createGraphView(network);
layouts.getDefaultLayout().doLayout(view);
readObjects.put(GraphView.class, view);
-
+
nodeMap.clear();
nodeMap = null;
}
Modified:
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/xgmml/XGMMLReader.java
===================================================================
---
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/xgmml/XGMMLReader.java
2009-03-09 23:58:39 UTC (rev 16188)
+++
core3/io-impl/trunk/src/main/java/org/cytoscape/io/read/internal/xgmml/XGMMLReader.java
2009-03-09 23:59:49 UTC (rev 16189)
@@ -129,7 +129,7 @@
* @throws IOException
* DOCUMENT ME!
*/
- public void read() throws IOException {
+ public Map<Class<?>, Object> read() throws IOException {
try {
this.readXGMML();
@@ -139,6 +139,8 @@
} catch (SAXException e) {
throw new IOException("Could not parse XGMML file: ");
}
+
+ return readObjects;
}
/**
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---