1
2
3
4
5
6
7 package org.astrogrid.tableserver.metadata;
8
9 import java.io.IOException;
10 import org.astrogrid.dataservice.metadata.MetadataException;
11 import org.astrogrid.dataservice.metadata.VoResourcePlugin;
12 import org.astrogrid.dataservice.metadata.VoTypes;
13 import org.astrogrid.dataservice.metadata.v0_10.VoResourceSupport;
14 import org.astrogrid.io.xml.XmlPrinter;
15 import org.astrogrid.tableserver.metadata.ColumnInfo;
16 import org.astrogrid.tableserver.metadata.TableInfo;
17 import org.astrogrid.tableserver.metadata.TableMetaDocInterpreter;
18 import org.astrogrid.ucd.UcdVersions;
19 import org.astrogrid.ucd.UcdException;
20
21 /***
22 * Generates VoResource elements for tabular sky services.
23 */
24
25 public class TabularDbResources extends VoResourceSupport implements VoResourcePlugin {
26
27
28 /*** Generates a voResource element about the database.
29 * */
30 public String getVoResource() throws IOException {
31
32 String ucdVersion = UcdVersions.getUcdVersion();
33
34 TableMetaDocInterpreter reader = new TableMetaDocInterpreter();
35 StringBuffer tabularDb = new StringBuffer(
36 makeVoResourceElement(
37 "tdb:TabularDB",
38
39 "xmlns:vod='http://www.ivoa.net/xml/VODataService/v0.5' " +
40 "xmlns:tdb ='urn:astrogrid:schema:vo-resource-types:TabularDB:v0.3' ",
41
42 "http://www.ivoa.net/xml/VODataService/v0.5 http://www.ivoa.net/xml/VODataService/v0.5" + " " +
43 "urn:astrogrid:schema:vo-resource-types:TabularDB:v0.3 http://software.astrogrid.org/schema/vo-resource-types/TabularDB/v0.3/TabularDB.xsd"
44 ) +
45 makeCore("TDB") +
46 "<tdb:db>\n"
47 );
48
49 String[] catalogNames = reader.getCatalogs();
50 if (catalogNames.length == 0) {
51 throw new MetadataException("Server error: no catalog or table metadata are defined for this DSA/catalog installation; please check your metadoc file and/or configuration!");
52 }
53
54
55 String catalog = catalogNames[0];
56 if (catalog == null) {
57 throw new MetadataException("Server error: no catalog or table metadata are defined for this DSA/catalog installation; please check your metadoc file and/or configuration!");
58 }
59 tabularDb.append(
60 "<tdb:name>"+catalog+"</tdb:name>\n"+
61 "<tdb:description/>\n"
62 );
63
64 TableInfo[] tables = reader.getTables(catalog);
65 for (int t = 0; t < tables.length; t++) {
66 tabularDb.append(
67 "<tdb:table xmlns='http://www.ivoa.net/xml/VODataService/v0.5' >\n"+ //default namnespace for table descriptions
68 "<name>"+tables[t].getName()+"</name>\n"+
69 "<description>"+XmlPrinter.transformSpecials(tables[t].getDescription())+"</description>\n"
70 );
71
72 ColumnInfo[] columns = reader.getColumns(catalog, tables[t].getName());
73
74 for (int c = 0; c < columns.length; c++) {
75 tabularDb.append(
76 "<column>\n"+
77 "<name>"+columns[c].getName()+"</name>\n"+
78 "<description>"+XmlPrinter.transformSpecials(columns[c].getDescription())+"</description>\n"
79 );
80
81
82
83
84
85 tabularDb.append(
86 VoTypes.getVoTypeXml(columns[c].getJavaType())
87 );
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 if ((columns[c].getUnits() != null) && (columns[c].getUnits().toString().trim().length()>0)) {
104 tabularDb.append(
105 "<unit>"+columns[c].getUnits()+"</unit>\n"
106 );
107 }
108 String columnUcd = columns[c].getUcd(ucdVersion);
109 if ((columnUcd != null) && (columnUcd.trim().length()>0)) {
110 tabularDb.append(
111 "<ucd>"+columnUcd.trim()+"</ucd>\n"
112 );
113 }
114 tabularDb.append(
115 "</column>\n"
116 );
117 }
118
119 tabularDb.append(
120 "</tdb:table>\n");
121
122 }
123
124 tabularDb.append(
125 "</tdb:db>\n"+
126 "</"+VORESOURCE_ELEMENT+">\n");
127
128 return tabularDb.toString();
129 }
130
131 }
132
133