01: package com.sun.portal.util;
02:
03: import java.net.MalformedURLException;
04: import java.net.URL;
05:
06: /*
07: * Implementation of HostAvalibilityEvent
08: *
09: * @date 25-07-2002
10: * @ author Rajesh T
11: */
12:
13: public final class HostAvailabilityEventImpl implements
14: HostAvailabilityEvent {
15:
16: private String host = null;
17:
18: private int EVENT_TYPE = HostAvailabilityEvent.HOST_UNAVAILABLE;
19:
20: private int HOST_TYPE = HostAvailabilityEvent.IS_HOST;
21:
22: /*
23: * @ returns the event type either a host has gone down or up
24: */
25:
26: public int getEventType() {
27: return EVENT_TYPE;
28: }
29:
30: /*
31: * validates whether the specified host is a valid url.
32: */
33:
34: public void setHost(String hst) {
35: URL url = null;
36: try {
37: url = new URL(hst);
38: } catch (MalformedURLException me) {
39: throw new IllegalArgumentException("Invalid host");
40: }
41: StringBuffer portalHost = new StringBuffer();
42: portalHost.append(url.getProtocol()).append("://").append(
43: url.getHost()).append(":").append(url.getPort());
44: host = portalHost.toString().toLowerCase();
45: }
46:
47: /*
48: * @ returns host
49: */
50:
51: public String getHost() {
52: return host;
53: }
54:
55: public void setHostStatus(int eventType) {
56: if ((eventType != HostAvailabilityEvent.HOST_UNAVAILABLE)
57: && (eventType != HostAvailabilityEvent.HOST_AVAILABLE))
58: throw new IllegalArgumentException(
59: "Invalid Host Availability Event type..");
60: EVENT_TYPE = eventType;
61: }
62:
63: public void setHostType(int hostType) {
64: if (hostType != HostAvailabilityEvent.IS_HOST
65: && hostType != HostAvailabilityEvent.PS_HOST
66: && hostType != HostAvailabilityEvent.RP_HOST
67: && hostType != HostAvailabilityEvent.NP_HOST) {
68: throw new IllegalArgumentException("Invalid Host type..");
69: }
70: HOST_TYPE = hostType;
71: }
72:
73: public int getHostType() {
74: return HOST_TYPE;
75: }
76:
77: public int getHostStatus() {
78: return EVENT_TYPE;
79: }
80: }
|