KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > conf > ProtocolData


1 // $Id: ProtocolData.java,v 1.6 2004/09/23 16:29:14 belaban Exp $
2

3 package org.jgroups.conf;
4
5 /**
6  * Data holder for protocol
7  * @author Filip Hanik (<a HREF="mailto:filip@filip.net">filip@filip.net)
8  * @version 1.0
9  */

10
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 public class ProtocolData {
15     private final HashMap JavaDoc mParameters=new HashMap JavaDoc();
16     private final String JavaDoc mProtocolName;
17     private final String JavaDoc mDescription;
18     private final String JavaDoc mClassName;
19     private boolean mIsOverRide=false;
20
21     public ProtocolData(String JavaDoc protocolName,
22                         String JavaDoc description,
23                         String JavaDoc className,
24                         ProtocolParameter[] params) {
25         mProtocolName=protocolName;
26         mDescription=description;
27         mClassName=className;
28         if(params != null) {
29             for(int i=0; i < params.length; i++) {
30                 mParameters.put(params[i].getName(), params[i]);
31             }
32         }
33     }
34
35     public ProtocolData(String JavaDoc overRideName,
36                         ProtocolParameter[] params) {
37         this(overRideName, null, null, params);
38         mIsOverRide=true;
39
40     }
41
42     public String JavaDoc getClassName() {
43         return mClassName;
44     }
45
46     public String JavaDoc getProtocolName() {
47         return mProtocolName;
48     }
49
50     public String JavaDoc getDescription() {
51         return mDescription;
52     }
53
54     public HashMap JavaDoc getParameters() {
55         return mParameters;
56     }
57
58     public boolean isOverride() {
59         return mIsOverRide;
60     }
61
62     public ProtocolParameter[] getParametersAsArray() {
63         ProtocolParameter[] result=new ProtocolParameter[mParameters.size()];
64         Iterator JavaDoc it=mParameters.keySet().iterator();
65         for(int i=0; i < result.length; i++) {
66             String JavaDoc key=(String JavaDoc)it.next();
67             result[i]=(ProtocolParameter)mParameters.get(key);
68         }
69         return result;
70     }
71
72
73     public void override(ProtocolParameter[] params) {
74         for(int i=0; i < params.length; i++)
75             mParameters.put(params[i].getName(), params[i]);
76     }
77
78     public String JavaDoc getProtocolString(boolean new_format) {
79         return new_format? getProtocolStringNewXml() : getProtocolString();
80     }
81
82     public String JavaDoc getProtocolString() {
83         StringBuffer JavaDoc buf=new StringBuffer JavaDoc(mClassName);
84         if(mParameters.size() > 0) {
85             buf.append('(');
86             Iterator JavaDoc i=mParameters.keySet().iterator();
87             while(i.hasNext()) {
88                 String JavaDoc key=(String JavaDoc)i.next();
89                 ProtocolParameter param=(ProtocolParameter)mParameters.get(key);
90                 buf.append(param.getParameterString());
91                 if(i.hasNext()) buf.append(';');
92             }//while
93
buf.append(')');
94         }
95         return buf.toString();
96     }
97
98     public String JavaDoc getProtocolStringNewXml() {
99         StringBuffer JavaDoc buf=new StringBuffer JavaDoc(mClassName + ' ');
100         if(mParameters.size() > 0) {
101             Iterator JavaDoc i=mParameters.keySet().iterator();
102             while(i.hasNext()) {
103                 String JavaDoc key=(String JavaDoc)i.next();
104                 ProtocolParameter param=(ProtocolParameter)mParameters.get(key);
105                 buf.append(param.getParameterStringXml());
106                 if(i.hasNext()) buf.append(' ');
107             }
108         }
109         return buf.toString();
110     }
111
112     public int hashCode() {
113         return mProtocolName.hashCode();
114     }
115
116     public boolean equals(Object JavaDoc another) {
117         if(another instanceof ProtocolData)
118             return getProtocolName().equals(((ProtocolData)another).getProtocolName());
119         else
120             return false;
121     }
122
123
124 }
125
Popular Tags