KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jena > dblist


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

5
6 package jena;
7
8 import com.hp.hpl.jena.db.* ;
9 import com.hp.hpl.jena.rdf.model.* ;
10 import com.hp.hpl.jena.util.iterator.*;
11
12  
13 /** List the models available in a database
14  * <p>
15  * Usage:<pre>
16  * jena.dblist [db spec]
17  * where [db spec] is:
18  * --spec file Contains an RDF description of the model
19  * --db JDBC_url --dbUser userId --dbPassword password --dbType
20  * </pre>
21  * Ignores any <code>--model modelName</code>.
22  * </p>
23  *
24  * @author Andy Seaborne
25  * @version $Id: dblist.java,v 1.5 2005/02/21 11:49:11 andy_seaborne Exp $
26  */

27  
28 public class dblist extends DBcmd
29 {
30     public static final String JavaDoc[] usage = new String JavaDoc[]
31                                                     {
32             "dblist [--spec spec] | [db_description] [--model name]" ,
33             " where db_description is" ,
34             " --db JDBC URL --dbType type" ,
35             " --dbUser user --dbPassword password"
36     } ;
37     
38     
39     
40     public static void main(String JavaDoc[] args)
41     {
42         dblist db = new dblist();
43         db.setUsage(usage) ;
44         db.init(args);
45         db.exec();
46     }
47
48     public dblist()
49     {
50         super("dblist", false) ;
51     }
52     
53     protected void exec0()
54     {
55         if ( getConnection().containsDefaultModel() )
56         {
57             System.out.println("Model: <<default model>>") ;
58             properties(null) ;
59         }
60         
61         ClosableIterator iter = getConnection().getAllModelNames() ;
62         try {
63             for ( ; iter.hasNext() ; )
64             {
65                 String JavaDoc name = (String JavaDoc)iter.next() ;
66                 System.out.println("Model: "+name) ;
67                 properties(name) ;
68             }
69         }
70         finally
71         {
72             iter.close() ;
73         }
74       
75     }
76     
77     protected boolean exec1(String JavaDoc arg) { return true ; }
78
79     private void properties(String JavaDoc name)
80     {
81         if ( true )
82             return ;
83         ModelRDB m = ModelRDB.open(getConnection(), name) ;
84         Model props = m.getModelProperties() ;
85         props.setNsPrefix("db", "http://jena.hpl.hp.com/2003/04/DB#") ;
86         props.write(System.out, "N3") ;
87         props.close() ;
88     }
89
90 }
91
92
93 /*
94  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
95  * All rights reserved.
96  *
97  * Redistribution and use in source and binary forms, with or without
98  * modification, are permitted provided that the following conditions
99  * are met:
100  * 1. Redistributions of source code must retain the above copyright
101  * notice, this list of conditions and the following disclaimer.
102  * 2. Redistributions in binary form must reproduce the above copyright
103  * notice, this list of conditions and the following disclaimer in the
104  * documentation and/or other materials provided with the distribution.
105  * 3. The name of the author may not be used to endorse or promote products
106  * derived from this software without specific prior written permission.
107  *
108  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
109  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
110  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
111  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
112  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
113  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
114  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
115  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
116  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
117  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118  */

119
Popular Tags