1 |
2737
|
jones
|
/**
|
2 |
|
|
* '$RCSfile$'
|
3 |
|
|
* Copyright: 2000-2005 Regents of the University of California and the
|
4 |
|
|
* National Center for Ecological Analysis and Synthesis
|
5 |
|
|
*
|
6 |
|
|
* '$Author$'
|
7 |
|
|
* '$Date$'
|
8 |
|
|
* '$Revision$'
|
9 |
|
|
*
|
10 |
|
|
* This program is free software; you can redistribute it and/or modify
|
11 |
|
|
* it under the terms of the GNU General Public License as published by
|
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
13 |
|
|
* (at your option) any later version.
|
14 |
|
|
*
|
15 |
|
|
* This program is distributed in the hope that it will be useful,
|
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
|
|
* GNU General Public License for more details.
|
19 |
|
|
*
|
20 |
|
|
* You should have received a copy of the GNU General Public License
|
21 |
|
|
* along with this program; if not, write to the Free Software
|
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
23 |
|
|
*/
|
24 |
|
|
|
25 |
|
|
package edu.ucsb.nceas.metacat.lsid;
|
26 |
|
|
|
27 |
|
|
import java.util.regex.Pattern;
|
28 |
|
|
import java.util.regex.Matcher;
|
29 |
|
|
|
30 |
|
|
import com.ibm.lsid.LSID;
|
31 |
|
|
import com.ibm.lsid.ExpiringResponse;
|
32 |
|
|
import com.ibm.lsid.wsdl.LSIDDataPort;
|
33 |
|
|
import com.ibm.lsid.wsdl.LSIDMetadataPort;
|
34 |
|
|
|
35 |
|
|
import com.ibm.lsid.wsdl.SOAPLocation;
|
36 |
|
|
import com.ibm.lsid.wsdl.HTTPLocation;
|
37 |
|
|
|
38 |
|
|
import com.ibm.lsid.server.LSIDServerException;
|
39 |
|
|
import com.ibm.lsid.server.LSIDServiceConfig;
|
40 |
|
|
|
41 |
|
|
import com.ibm.lsid.server.impl.SimpleAuthority;
|
42 |
|
|
|
43 |
|
|
public class LSIDAuthorityMain extends SimpleAuthority {
|
44 |
|
|
|
45 |
|
|
private LSIDDataLookup lookup = null;
|
46 |
|
|
|
47 |
|
|
public void initService(LSIDServiceConfig cf) throws LSIDServerException {
|
48 |
|
|
System.out.println("Starting LSIDAuthorityMain (Metacat).");
|
49 |
|
|
lookup = new LSIDDataLookup();
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
public ExpiringResponse getKnownURIs() throws LSIDServerException {
|
53 |
|
|
return null;
|
54 |
|
|
}
|
55 |
|
|
|
56 |
|
|
public LSIDMetadataPort[] getMetadataLocations(LSID lsid, String url) {
|
57 |
|
|
if (lookup == null)
|
58 |
|
|
return null;
|
59 |
|
|
|
60 |
|
|
int lsType;
|
61 |
|
|
try {
|
62 |
|
|
lsType = lookup.lsidType(lsid);
|
63 |
|
|
}
|
64 |
|
|
catch (LSIDServerException ex) {
|
65 |
|
|
ex.printStackTrace();
|
66 |
|
|
lsType = LSIDDataLookup.UNKNOWN;
|
67 |
|
|
}
|
68 |
|
|
if (lsType == LSIDDataLookup.UNKNOWN)
|
69 |
|
|
return null;
|
70 |
|
|
|
71 |
|
|
HostDescriptor hd = new HostDescriptor(url);
|
72 |
|
|
return new LSIDMetadataPort[] {
|
73 |
|
|
// thau added http metadata port here
|
74 |
|
|
new HTTPLocation(
|
75 |
|
|
hd.host, hd.port,
|
76 |
|
|
hd.pathPrefix + "/authority/metadata"
|
77 |
|
|
),
|
78 |
|
|
new SOAPLocation(
|
79 |
|
|
hd.baseURL + "metadata"
|
80 |
|
|
)
|
81 |
|
|
};
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
public LSIDDataPort[] getDataLocations(LSID lsid, String url) {
|
85 |
|
|
if (lookup == null)
|
86 |
|
|
return null;
|
87 |
|
|
|
88 |
|
|
int lsType;
|
89 |
|
|
try {
|
90 |
|
|
lsType = lookup.lsidType(lsid);
|
91 |
|
|
}
|
92 |
|
|
catch (LSIDServerException ex) {
|
93 |
|
|
ex.printStackTrace();
|
94 |
|
|
lsType = LSIDDataLookup.UNKNOWN;
|
95 |
|
|
}
|
96 |
|
|
if (lsType == LSIDDataLookup.UNKNOWN)
|
97 |
|
|
return null;
|
98 |
|
|
if (lsType == LSIDDataLookup.ABSTRACT)
|
99 |
|
|
return new LSIDDataPort[0];
|
100 |
|
|
|
101 |
|
|
HostDescriptor hd = new HostDescriptor(url);
|
102 |
|
|
return new LSIDDataPort[] {
|
103 |
|
|
new HTTPLocation(
|
104 |
|
|
hd.host, hd.port,
|
105 |
|
|
hd.pathPrefix + "/authority/data"
|
106 |
|
|
),
|
107 |
|
|
new SOAPLocation(
|
108 |
|
|
hd.baseURL + "data"
|
109 |
|
|
)
|
110 |
|
|
};
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
private static final Pattern HOST_PTN = Pattern.compile(
|
114 |
|
|
"https?://([^/:]+)(?::(\\d+))?(.*)/authority(.*)"
|
115 |
|
|
);
|
116 |
|
|
|
117 |
|
|
/* Q&D implementation */
|
118 |
|
|
private class HostDescriptor {
|
119 |
|
|
public String host;
|
120 |
|
|
public int port;
|
121 |
|
|
public String pathPrefix;
|
122 |
|
|
public String baseURL;
|
123 |
|
|
|
124 |
|
|
public HostDescriptor(String url) {
|
125 |
|
|
host = "localhost";
|
126 |
|
|
port = -1;
|
127 |
|
|
pathPrefix = "";
|
128 |
|
|
if (url != null || url.length() > 0) {
|
129 |
|
|
Matcher m = HOST_PTN.matcher(url);
|
130 |
|
|
if (m.lookingAt()) {
|
131 |
|
|
host = m.group(1);
|
132 |
|
|
if ((m.group(2) != null) && (m.group(2).length() > 0))
|
133 |
|
|
port = Integer.parseInt(m.group(2));
|
134 |
|
|
pathPrefix = m.group(3);
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
if (port > 0)
|
138 |
|
|
baseURL = "http://" + host + ":" + port +
|
139 |
|
|
pathPrefix + "/authority/";
|
140 |
|
|
else
|
141 |
|
|
baseURL = "http://" + host + pathPrefix + "/authority/";
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
}
|