001: package com.sun.portal.admin.console.sra.proxylet;
002:
003: import java.io.Serializable;
004: import java.util.StringTokenizer;
005:
006: /**
007: * author: Noble Paul
008: * Date: Jul 15, 2005, 5:43:54 PM
009: */
010: public class Rule implements Serializable {
011:
012: private String _id = null;
013:
014: private static int INT = 0;
015:
016: private String protocol = "", domain = "", hostPort = "";
017:
018: private boolean selected;
019:
020: public Rule() {
021: _id = "_" + INT++;
022: }
023:
024: public Rule(String domain, String hostPort, String protocol,
025: boolean selected) {
026: _id = "_" + INT++;
027: this .domain = domain;
028: this .hostPort = hostPort;
029: this .protocol = protocol;
030: this .selected = selected;
031: }
032:
033: public String getId() {
034: return _id;
035: }
036:
037: public void setId(String id) {
038: _id = id;
039: }
040:
041: public String getDomain() {
042: return domain;
043: }
044:
045: public void setDomain(String domain) {
046: this .domain = domain;
047: }
048:
049: public String getHostPort() {
050: return hostPort;
051: }
052:
053: public void setHostPort(String hostPort) {
054: this .hostPort = hostPort;
055: }
056:
057: public String getProtocol() {
058: return protocol;
059: }
060:
061: public void setProtocol(String protocol) {
062: this .protocol = protocol;
063: }
064:
065: public boolean getSelected() {
066: return selected;
067: }
068:
069: public void setSelected(boolean selected) {
070: this .selected = selected;
071: }
072:
073: public String toString() {
074: return encode(this );
075:
076: }
077:
078: public static final String encode(Rule rule) {
079: return rule.protocol + ":" + rule.domain + ":" + rule.hostPort;
080: }
081:
082: public static final Rule decode(String s) {
083: StringTokenizer st = new StringTokenizer(s, ":", false);
084: String s1 = null, s2 = null, s3 = null, s4 = null;
085: if (st.hasMoreTokens())
086: s1 = st.nextToken();
087: if (st.hasMoreTokens())
088: s2 = st.nextToken();
089: if (st.hasMoreTokens())
090: s3 = st.nextToken();
091: if (st.hasMoreTokens())
092: s4 = st.nextToken();
093:
094: Rule r = new Rule();
095: if (s4 != null) {
096: r.hostPort = s3 + ":" + s4;
097: r.domain = s2;
098: r.protocol = s1;
099: } else {
100: r.hostPort = s2 + ":" + s3;
101: r.domain = s1;
102: }
103:
104: return r;
105: }
106:
107: public boolean isEmpty() {
108: return "".equals(hostPort) && "".equals(domain);
109: }
110: }
|