|
From: <mwl...@us...> - 2007-08-09 19:13:35
|
Revision: 465
http://cishell.svn.sourceforge.net/cishell/?rev=465&view=rev
Author: mwlinnem
Date: 2007-08-09 12:13:21 -0700 (Thu, 09 Aug 2007)
Log Message:
-----------
Added a bunch of extra functionality used in the main part of the Converter Tester.
Modified Paths:
--------------
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterGraph.java
trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java
Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterGraph.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterGraph.java 2007-08-06 20:37:40 UTC (rev 464)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterGraph.java 2007-08-09 19:13:21 UTC (rev 465)
@@ -10,6 +10,7 @@
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
public class ConverterGraph {
@@ -18,10 +19,12 @@
Map fileExtensionTestConverters;
Map fileExtensionCompareConverters;
ServiceReference[] converters;
+ BundleContext bContext;
private static final String testOutData = "prefuse.data.Graph";
- public ConverterGraph(ServiceReference[] converters){
+ public ConverterGraph(ServiceReference[] converters, BundleContext bContext){
this.converters = converters;
+ this.bContext = bContext;
inDataToAlgorithm = new HashMap();//<String, ArrayList<ServiceReference>>();
fileExtensionTestConverters = new ConcurrentHashMap();//<String, ArrayList<ConverterPath>>();
fileExtensionCompareConverters = new ConcurrentHashMap();//<String, ConverterPath>();
@@ -55,7 +58,7 @@
if(s.startsWith("file-ext")){
- ConverterPath test = new ConverterPath();
+ ConverterPath test = new ConverterPath(this.bContext);
test.setInData(s);
@@ -75,7 +78,7 @@
return path;
}
while(!refs.isEmpty()){
- ConverterPath p = new ConverterPath(path);
+ ConverterPath p = new ConverterPath(path, this.bContext);
p.addAlgorithm((ServiceReference)refs.get(0));
refs.remove(0);
createPaths((ArrayList)this.inDataToAlgorithm.get(p.getOutData()), p, p.getOutData());
@@ -100,14 +103,14 @@
if(this.fileExtensionCompareConverters.get(key) == null){
- this.fileExtensionCompareConverters.put(key, new ConverterPath(cp));
+ this.fileExtensionCompareConverters.put(key, new ConverterPath(cp, this.bContext));
}
else {
ConverterPath tempPath = (ConverterPath)this.fileExtensionCompareConverters.get(key);
int pathSize = tempPath.getPath().size();
if(pathSize > cp.getPath().size()){
- this.fileExtensionCompareConverters.put(key, new ConverterPath(cp));
+ this.fileExtensionCompareConverters.put(key, new ConverterPath(cp, this.bContext));
}
}
}
Modified: trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java
===================================================================
--- trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java 2007-08-06 20:37:40 UTC (rev 464)
+++ trunk/testing/org.cishell.testing.convertertester.core.new/src/org/cishell/testing/convertertester/core/converter/graph/ConverterPath.java 2007-08-09 19:13:21 UTC (rev 465)
@@ -3,18 +3,28 @@
import java.util.ArrayList;
import java.util.List;
+import org.cishell.framework.algorithm.AlgorithmFactory;
+import org.cishell.framework.algorithm.AlgorithmProperty;
+import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-public class ConverterPath {
- String in_data;
- String out_data = null;
- ArrayList path;
+public class ConverterPath implements AlgorithmProperty {
+ private String in_data;
+ private String out_data = null;
+ private ArrayList path;
+ private BundleContext bContext;
- public ConverterPath(){
+ boolean algPathCached = false;
+ ArrayList algPath;
+
+ public ConverterPath(BundleContext bContext){
+ this.bContext = bContext;
path = new ArrayList();
}
- public ConverterPath(ConverterPath p){
+ public ConverterPath(ConverterPath p, BundleContext bContext) {
+ this.bContext = bContext;
+
in_data = p.getInData();
out_data = p.getOutData();
@@ -23,14 +33,17 @@
}
public void setInData(String s){
+
this.in_data = s;
}
public void setOutData(String s){
+
this.out_data = s;
}
public boolean addAlgorithm(ServiceReference sr){
+
boolean val = true;
if(path.contains(sr)){
@@ -39,28 +52,53 @@
return false;
}
+
path.add(sr);
+ invalidateAlgPath();
this.setOutData(sr.getProperty("out_data").toString());
return val;
}
public String getInData(){
+
return this.in_data;
}
public String getOutData(){
+
return this.out_data;
}
public List getPath(){
+
return this.path;
}
+ public ServiceReference getRef(int index) {
+
+ return (ServiceReference) this.path.get(index);
+ }
+
+ public AlgorithmFactory getAlg(int index) {
+
+ if (! algPathCached) cacheAlgPath();
+ return (AlgorithmFactory) this.algPath.get(index);
+ }
+
public ServiceReference[] getPathAsArray(){
+
return (ServiceReference[])this.path.toArray(new ServiceReference[0]);
}
+ public AlgorithmFactory[] getPathAsAlgorithms(){
+
+ if (! algPathCached) cacheAlgPath();
+
+ return (AlgorithmFactory[]) this.algPath.toArray(new AlgorithmFactory[0]);
+ }
+
public String toString(){
+
String val = this.in_data +" -->\n";
for(int i = 0; i < this.path.size(); i++){
@@ -70,5 +108,70 @@
val += "--> " + this.out_data + "\n";
return val;
}
+
+ public boolean isLossy() {
+ String lossiness = LOSSLESS;
+ for (int i = 0; i < this.path.size(); i++) {
+ ServiceReference sr = (ServiceReference) this.path.get(i);
+
+ if (LOSSY.equals(sr.getProperty(CONVERSION))) {
+ lossiness = LOSSY;
+ }
+ }
+
+ boolean result = lossiness.equals(LOSSY);
+ return result;
+ }
+
+ public boolean preservesIDs() {
+
+ //TODO: Determine this somehow.
+ return false;
+ }
+
+
+ public ConverterPath appendNonMutating(ConverterPath otherPath) {
+
+ List thisConvPath = this.path;
+ List otherConvPath = otherPath.getPath();
+
+ List thisConvPathCopy = new ArrayList(thisConvPath);
+ thisConvPathCopy.addAll(otherConvPath);
+ ConverterPath combinedPath = new ConverterPath(this.bContext);
+
+ List combinedConvPath = thisConvPathCopy;
+ for (int ii = 0; ii < combinedConvPath.size(); ii++) {
+ ServiceReference sr = (ServiceReference) combinedConvPath.get(ii);
+
+ combinedPath.addAlgorithm(sr);
+ }
+
+ return combinedPath;
+ }
+
+ public int size() {
+
+ return this.path.size();
+ }
+
+
+ private void cacheAlgPath() {
+ this.algPath = new ArrayList();
+
+ for (int i = 0; i < this.path.size(); i++){
+ ServiceReference sr = (ServiceReference)this.path.get(i);
+
+ AlgorithmFactory alg = (AlgorithmFactory) this.bContext.getService(sr);
+ this.algPath.add(alg);
+ }
+
+ this.algPathCached = true;
+ }
+
+ private void invalidateAlgPath() {
+
+ this.algPathCached = false;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|