KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > joseki > rdfserver


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
10 import org.joseki.server.* ;
11 import org.joseki.Joseki ;
12
13 /** Command line application to run an RDF Server
14  *
15  * @author Andy Seaborne
16  * @version $Id: rdfserver.java,v 1.9 2004/04/30 14:13:14 andy_seaborne Exp $
17  */

18
19
20 public class rdfserver
21 {
22     public static String JavaDoc defaultConfigFile = RDFServer.defaultConfigFile ;
23     
24     public static boolean VERBOSE = false ;
25     public static boolean DEBUG = false ;
26
27     public static final int defaultPort = 2020 ;
28     public static int port = defaultPort ;
29     
30     public static final String JavaDoc PortArg = "port" ;
31
32     public static void main (String JavaDoc args[])
33     {
34         // Ensure there are logging configurations
35
//if (System.getProperty("java.util.logging.config.file") == null)
36
// System.setProperty("java.util.logging.config.file", "etc/logging.properties");
37

38         if ( System.getProperty("log4j.configuration") == null )
39             System.setProperty("log4j.configuration", "file:etc/log4j.properties") ;
40         
41         port = Integer.parseInt(System.getProperty("jena.rdfserver.port", defaultPort+"")) ;
42         
43         String JavaDoc usageMessage = rdfserver.class.getName()+
44                                 " [--verbose] [--port N] "+
45                                 "dataSourceConfigFile" ;
46                                 
47         
48         CommandLine cmd = new CommandLine() ;
49         cmd.setUsage(usageMessage) ;
50         
51         ArgDecl verboseDecl = new ArgDecl(false, "-v", "--verbose") ;
52         cmd.add(verboseDecl) ;
53         cmd.add("--debug", false) ;
54         cmd.add("--help", false) ;
55         cmd.add(PortArg, true) ;
56
57         // Addition argument, after the flags, is a query
58
cmd.process(args) ;
59         
60         if ( cmd.contains("help") )
61         {
62             System.out.println(usageMessage) ;
63             System.exit(0) ;
64         }
65
66         if ( cmd.contains(PortArg) )
67             port = Integer.parseInt(cmd.getArg(PortArg).getValue()) ;
68
69         if ( cmd.contains("--debug") )
70         {
71             DEBUG = true ;
72             Joseki.serverDebug = true ;
73             Joseki.serverContentType = "application/n3" ;
74         }
75         
76         if ( cmd.contains(verboseDecl) )
77             VERBOSE = true ;
78         
79         if ( cmd.items().size() > 1 )
80         {
81             System.err.println("Must specify exactly one configuration file (or use default : "+defaultConfigFile+")") ;
82             System.err.println(usageMessage) ;
83             System.exit(1) ;
84         }
85         
86         String JavaDoc configFile = null ;
87
88         if ( cmd.items().size() > 0 )
89             configFile = (String JavaDoc)cmd.items().get(0) ;
90         else
91             configFile = defaultConfigFile ;
92
93         try {
94             RDFServer server = new RDFServer(configFile, port) ;
95             server.start() ;
96         } catch (ConfigurationErrorException confEx)
97         {
98             // Flush console logging
99
System.out.flush() ;
100             System.err.println();
101             System.err.println("Failed to load the configuration file - see log") ;
102             // Errors have already come out on the logging
103
//System.err.println(confEx.getMessage()) ;
104
//if ( confEx.getCause() != null )
105
// System.err.print(" : "+confEx.getCause()) ;
106
System.err.println();
107             System.exit(99) ;
108         }
109         // Server threads running elsewhere.
110
}
111 }
112
113 /*
114  * (c) Copyright 2003, 2004 Hewlett-Packard Development Company, LP
115  * All rights reserved.
116  *
117  * Redistribution and use in source and binary forms, with or without
118  * modification, are permitted provided that the following conditions
119  * are met:
120  * 1. Redistributions of source code must retain the above copyright
121  * notice, this list of conditions and the following disclaimer.
122  * 2. Redistributions in binary form must reproduce the above copyright
123  * notice, this list of conditions and the following disclaimer in the
124  * documentation and/or other materials provided with the distribution.
125  * 3. The name of the author may not be used to endorse or promote products
126  * derived from this software without specific prior written permission.
127  *
128  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
129  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
130  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
131  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
132  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
133  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
134  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
135  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
136  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
137  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
138  */

139
Popular Tags