KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > joseki > options


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

5
6 package joseki;
7
8 import jena.cmdline.*;
9 import com.hp.hpl.jena.joseki.* ;
10 import com.hp.hpl.jena.rdf.model.* ;
11
12 /** Command line application to issue queries against a remote model.
13  *
14  * @author Andy Seaborne
15  * @version $Id: options.java,v 1.2 2004/04/30 14:13:14 andy_seaborne Exp $
16  */

17
18
19 public class options
20 {
21     public static final String JavaDoc defaultURL = "http://localhost:2020/rdfserver/rdf" ;
22     
23     public static boolean VERBOSE = false ;
24     public static boolean DEBUG = false ;
25     
26     // This is very similar to rdffetch and sort of like all Joseki command line apps
27
// can we create a common framework for argument handling?
28

29     public static void main (String JavaDoc args[])
30     {
31         try {
32             String JavaDoc usageMessage = options.class.getName()+
33                                     " [--verbose] [--format fmt] "+
34                                     "--model modelURL";
35
36             CommandLine cmd = new CommandLine() ;
37             cmd.setUsage(usageMessage) ;
38
39             ArgDecl verboseDecl = new ArgDecl(false, "-v", "--verbose") ;
40             ArgDecl modelDecl = new ArgDecl(true, "model", "url") ;
41             
42             cmd.add(verboseDecl) ;
43             cmd.add(modelDecl) ;
44             
45             cmd.add("--format", true) ;
46             cmd.add("--debug", false) ;
47
48             // No addition arguments after the flags
49
cmd.process(args) ;
50
51             if ( cmd.contains("--debug") )
52                 DEBUG = true ;
53
54             if ( cmd.contains("--help") )
55             {
56                 System.err.println(usageMessage) ;
57                 System.exit(0) ;
58             }
59
60             if ( cmd.contains(verboseDecl) )
61                 VERBOSE = true ;
62             
63                 
64             if ( ! cmd.contains(modelDecl) )
65             {
66                 System.err.println(usageMessage) ;
67                 System.err.println("Required argument: --model") ;
68                 System.exit(8) ;
69             }
70
71             String JavaDoc format = "N3" ;
72             String JavaDoc modelStr = cmd.getArg(modelDecl).getValue() ;
73             
74             if ( cmd.contains("format") )
75                 format = cmd.getArg("format").getValue() ;
76             
77             HttpOptions optionRequest = new HttpOptions(modelStr) ;
78             Model obj = optionRequest.exec() ;
79             
80             obj.write(System.out, format) ;
81             
82         }
83         catch (Exception JavaDoc e)
84         {
85             e.printStackTrace(System.err) ;
86             System.exit(9) ;
87         }
88     }
89 }
90
91 /*
92  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
93  * All rights reserved.
94  *
95  * Redistribution and use in source and binary forms, with or without
96  * modification, are permitted provided that the following conditions
97  * are met:
98  * 1. Redistributions of source code must retain the above copyright
99  * notice, this list of conditions and the following disclaimer.
100  * 2. Redistributions in binary form must reproduce the above copyright
101  * notice, this list of conditions and the following disclaimer in the
102  * documentation and/or other materials provided with the distribution.
103  * 3. The name of the author may not be used to endorse or promote products
104  * derived from this software without specific prior written permission.
105  *
106  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
107  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
108  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
109  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
110  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
111  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
112  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
113  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
114  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
115  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
116  */

117
Popular Tags