1 package com.mjh.switchrmi;
2
3 import com.mjh.util.UrlInfo;
4
5 import java.net.MalformedURLException;
6
7 import org.apache.log4j.Logger;
8
9 public class RmiUrlInfo extends UrlInfo
10 {
11 private static final Logger log =
12 Logger.getLogger(RmiUrlInfo.class.getName());
13 private String objectName;
14 private String protocolName;
15
16 public RmiUrlInfo(String url, String[] requiredParameters)
17 throws MalformedURLException
18 {
19 super(url, requiredParameters);
20 init();
21 }
22
23 public RmiUrlInfo(String url)
24 throws MalformedURLException
25 {
26 super(url);
27 init();
28 }
29
30 private void init() throws MalformedURLException
31 {
32 String path = getPath();
33
34 if ((path == null) || (path.length() < 3))
35 {
36 throw new MalformedURLException(
37 "Path must contain object name and protocol name");
38 }
39
40 int start = path.lastIndexOf('/');
41
42 while (path.charAt(start) == '/')
43 {
44 start++;
45 }
46
47 int end = path.indexOf('.');
48
49 if (end == -1)
50 {
51 throw new MalformedURLException(
52 "Path must contain object name and protocol name");
53 }
54
55 objectName = path.substring(start, end);
56 start = end + 1;
57 end = path.length();
58 protocolName = path.substring(start, end);
59
60 if (log.isDebugEnabled())
61 {
62 log.debug("url = " + getUrl());
63 log.debug("protocol = " + getProtocol());
64 log.debug("host = " + getHost());
65 log.debug("port = " + getPort());
66 log.debug("path = " + getPath());
67 log.debug("query = " + getQuery());
68 log.debug("objectName = " + objectName);
69 log.debug("protocolName = " + protocolName);
70 }
71 }
72
73 public String getObjectName()
74 {
75 return objectName;
76 }
77
78 public String getProtocolName()
79 {
80 return protocolName;
81 }
82
83 public String getTransportName()
84 {
85 return getProtocol();
86 }
87 }