KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdql > test > TestItem


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

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 /** Wrapper class for individual test items.
16  * Assumes it is a query test item, using both the manifest vocabulary and the
17  * test query vocabulary.
18  *
19  * @author Andy Seaborne
20  * @version $Id: TestItem.java,v 1.3 2005/02/21 12:16:09 andy_seaborne Exp $
21  */

22 class TestItem
23 {
24     Resource testResource = null ;
25     
26     Resource actionResource ;
27     String JavaDoc name ;
28     public String JavaDoc getName() { return name ; }
29     
30     String JavaDoc resultFile ;
31     public String JavaDoc getResultFile() { return resultFile ; }
32     
33     String JavaDoc comment ;
34     public String JavaDoc getComment() { return comment ; }
35     
36     String JavaDoc dataFile ;
37     public String JavaDoc getDataFile() { return dataFile ; }
38     
39     String JavaDoc queryFile ;
40     public String JavaDoc 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 JavaDoc _name,
66              String JavaDoc _queryFile,
67              String JavaDoc _dataFile,
68              String JavaDoc _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     // ----------------------------------------------------
83
// ---- Action properties
84

85     String JavaDoc _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 JavaDoc _getResultFile()
101     {
102         return getLiteralOrURI(testResource, TestManifest.result) ;
103     }
104
105     String JavaDoc _getComment()
106     {
107         Statement s = testResource.getProperty(RDFS.comment) ;
108         if ( s == null )
109             return null ;
110         return s.getString() ;
111     }
112     
113     // ----------------------------------------------------
114
// ---- Query specific properties
115

116     /** Get the data file: maybve unknown if part for the query (FROM)
117      * @return
118      */

119     
120     String JavaDoc _getDataFile()
121     {
122         if ( _getAction().isAnon() )
123             return getLiteralOrURI(_getAction(), TestQuery.data) ;
124         return null ;
125     }
126
127     /** Get the query file: either it is the action (data in query)
128      * or it is specified within the bNode as a query/data pair.
129      * @return
130      */

131     
132     String JavaDoc _getQueryFile()
133     {
134         Resource r = _getAction() ;
135         if ( r.hasProperty(TestQuery.query))
136             return getLiteralOrURI(_getAction(), TestQuery.query) ;
137         
138         // No query property - must be this action node
139

140         if ( _getAction().isAnon() )
141             return "[]" ;
142         return _getAction().getURI() ;
143     }
144         
145     Resource _getQueryForm()
146     {
147         //return _getAction().getProperty(TestQuery.queryForm).getResource() ;
148
return null ;
149     }
150     
151     Resource _getResultForm()
152     {
153         //return _getAction().getProperty(TestQuery.resultForm).getResource() ;
154
return null ;
155     }
156
157     // ----------------------------------------------------
158
// Misc
159

160     public String JavaDoc toString()
161     {
162         StringBuffer JavaDoc sbuff = new StringBuffer JavaDoc() ;
163         String JavaDoc name = getName() ;
164         String JavaDoc comment = getComment() ;
165                 
166         String JavaDoc 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     // ----------------------------------------------------
176
// Workers
177

178     private String JavaDoc 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 /*
206  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
207  * All rights reserved.
208  *
209  * Redistribution and use in source and binary forms, with or without
210  * modification, are permitted provided that the following conditions
211  * are met:
212  * 1. Redistributions of source code must retain the above copyright
213  * notice, this list of conditions and the following disclaimer.
214  * 2. Redistributions in binary form must reproduce the above copyright
215  * notice, this list of conditions and the following disclaimer in the
216  * documentation and/or other materials provided with the distribution.
217  * 3. The name of the author may not be used to endorse or promote products
218  * derived from this software without specific prior written permission.
219  *
220  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
221  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
222  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
223  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
224  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
225  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
226  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
227  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
228  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
229  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
230  */

231
232
Popular Tags