1 5 6 7 package com.hp.hpl.jena.rdql.test; 8 9 import com.hp.hpl.jena.rdf.model.* ; 10 11 import com.hp.hpl.jena.vocabulary.* ; 12 import com.hp.hpl.jena.rdql.QueryPrintUtils; 13 14 15 22 class TestItem 23 { 24 Resource testResource = null ; 25 26 Resource actionResource ; 27 String name ; 28 public String getName() { return name ; } 29 30 String resultFile ; 31 public String getResultFile() { return resultFile ; } 32 33 String comment ; 34 public String getComment() { return comment ; } 35 36 String dataFile ; 37 public String getDataFile() { return dataFile ; } 38 39 String queryFile ; 40 public String getQueryFile() { return queryFile ; } 41 42 Resource queryForm ; 43 public Resource getQueryForm() { return queryForm ; } 44 45 Resource resultForm ; 46 public Resource getResultForm() { return resultForm ; } 47 48 TestItem(Resource r) 49 { 50 testResource = r ; 51 if ( ! r.hasProperty(TestManifest.action) ) 52 throw new QueryTestException("TestItem with no action") ; 53 if ( ! r.hasProperty(TestManifest.name) ) 54 throw new QueryTestException("TestItem with no name") ; 55 56 name = _getName() ; 57 resultFile = _getResultFile() ; 58 comment = _getComment() ; 59 dataFile = _getDataFile() ; 60 queryFile = _getQueryFile() ; 61 queryForm = _getQueryForm() ; 62 resultForm = _getResultForm() ; 63 } 64 65 TestItem(String _name, 66 String _queryFile, 67 String _dataFile, 68 String _resultFile) 69 { 70 name = _name ; 71 queryFile = _queryFile ; 72 dataFile = _dataFile ; 73 resultFile = _resultFile ; 74 comment = "" ; 75 queryForm = null ; 76 resultForm = null ; 77 } 78 79 80 public Resource getResource() { return testResource ; } 81 82 85 String _getName() 86 { 87 Statement s = testResource.getProperty(TestManifest.name) ; 88 if ( s == null ) 89 return "<<unset>>" ; 90 return s.getString() ; 91 } 92 93 Resource _getAction() 94 { 95 if ( actionResource == null ) 96 actionResource = testResource.getProperty(TestManifest.action).getResource() ; 97 return actionResource ; 98 } 99 100 String _getResultFile() 101 { 102 return getLiteralOrURI(testResource, TestManifest.result) ; 103 } 104 105 String _getComment() 106 { 107 Statement s = testResource.getProperty(RDFS.comment) ; 108 if ( s == null ) 109 return null ; 110 return s.getString() ; 111 } 112 113 116 119 120 String _getDataFile() 121 { 122 if ( _getAction().isAnon() ) 123 return getLiteralOrURI(_getAction(), TestQuery.data) ; 124 return null ; 125 } 126 127 131 132 String _getQueryFile() 133 { 134 Resource r = _getAction() ; 135 if ( r.hasProperty(TestQuery.query)) 136 return getLiteralOrURI(_getAction(), TestQuery.query) ; 137 138 140 if ( _getAction().isAnon() ) 141 return "[]" ; 142 return _getAction().getURI() ; 143 } 144 145 Resource _getQueryForm() 146 { 147 return null ; 149 } 150 151 Resource _getResultForm() 152 { 153 return null ; 155 } 156 157 160 public String toString() 161 { 162 StringBuffer sbuff = new StringBuffer () ; 163 String name = getName() ; 164 String comment = getComment() ; 165 166 String actionStr = QueryPrintUtils.stringForRDFNode(_getAction()) ; 167 168 sbuff.append("Name: "+name) ; 169 170 if ( getComment() != null ) 171 sbuff.append(" Comment: "+getComment()) ; 172 return sbuff.toString() ; 173 } 174 175 178 private String getLiteralOrURI(Resource r, Property p) 179 { 180 if ( r == null ) 181 return null ; 182 183 if ( ! r.hasProperty(p) ) 184 return null ; 185 186 RDFNode n = r.getProperty(p).getObject() ; 187 if ( n instanceof Literal ) 188 return ((Literal)n).getString() ; 189 190 if ( n instanceof Resource ) 191 { 192 Resource r2 = (Resource)n ; 193 if ( ! r2.isAnon() ) 194 return r2.getURI() ; 195 } 196 197 throw new QueryTestException("Manifest problem: "+ 198 QueryPrintUtils.stringForRDFNode(n)+" => "+ 199 QueryPrintUtils.stringForRDFNode(p) 200 ) ; 201 } 202 } 203 204 205 231 232 | Popular Tags |