1 5 6 7 package com.hp.hpl.jena.rdql.test; 8 9 import java.util.* ; 10 import com.hp.hpl.jena.rdf.model.* ; 11 import com.hp.hpl.jena.vocabulary.RDF ; 12 import com.hp.hpl.jena.util.FileManager; 13 import com.hp.hpl.jena.vocabulary.TestManifest; 14 import junit.framework.* ; 15 import org.apache.commons.logging.*; 16 17 18 31 class TestManifestList 32 { 33 34 Model manifest = null ; 35 36 public TestManifestList(String filename) 37 { 38 manifest = FileManager.get().loadModel(filename) ; 39 } 40 41 public TestManifestList(Model m) 42 { 43 manifest = m ; 44 } 45 46 public Model getModel() { return manifest ; } 47 48 public TestIterator iterator() { return new TestIterator() ; } 49 50 55 56 public class TestIterator implements Iterator 57 { 58 List entries ; 61 Iterator iterator ; 62 63 64 TestIterator() 65 { 66 init() ; 67 } 68 69 73 public void init() 74 { 75 entries = new ArrayList(); 76 77 StmtIterator manifestStmts = 78 manifest.listStatements(null, RDF.type, TestManifest.Manifest); 79 80 for (; manifestStmts.hasNext();) 81 { 82 Statement manifestItemStmt = manifestStmts.nextStatement(); 83 Resource manifestRes = manifestItemStmt.getSubject(); 84 StmtIterator listIter = manifestRes.listProperties(TestManifest.entries); 85 for (; listIter.hasNext();) 86 { 87 Resource listItem = listIter.nextStatement().getResource(); 88 89 for (; !listItem.equals(RDF.nil);) 90 { 91 92 Resource entry = listItem.getRequiredProperty(RDF.first).getResource(); 93 TestItem item = new TestItem(entry) ; 94 95 entries.add(item); 96 listItem = listItem.getRequiredProperty(RDF.rest).getResource(); 98 } 99 } 100 listIter.close(); 101 } 102 manifestStmts.close(); 103 reset() ; 104 } 105 106 108 public void reset() { iterator = entries.iterator(); } 109 110 113 public boolean hasNext() 114 { 115 return iterator.hasNext(); 116 } 117 118 121 public Object next() 122 { 123 return iterator.next(); 124 } 125 126 public TestItem nextItem() 127 { 128 Object obj = iterator.next(); 129 if ( ! ( obj instanceof TestItem ) ) 130 { 131 LogFactory.getLog(TestManifestList.class) 132 .fatal("obj is "+obj.getClass().getName()) ; 133 return null ; 134 } 135 return (TestItem)obj ; 136 } 137 138 141 public void remove() 142 { 143 throw new UnsupportedOperationException (this.getClass().getName()); 144 } 145 } 146 147 149 150 public interface ActionProc 151 { 152 155 public void map1(TestItem testItem) ; 156 } 157 158 159 164 165 public void apply(ActionProc actionProc) 166 { 167 TestSuite suite = new TestSuite() ; 168 TestIterator iter = (TestIterator)iterator() ; 169 for ( ; iter.hasNext() ; ) 170 { 171 TestItem item = (TestItem)iter.next() ; 172 actionProc.map1(item) ; 173 } 174 } 175 } 176 177 178 204 205 | Popular Tags |