001: package org.jgroups.conf;
002:
003: /**
004: * Data holder for protocol
005: * @author Filip Hanik (<a href="mailto:filip@filip.net">filip@filip.net)
006: * @version $Id: ProtocolData.java,v 1.7 2006/08/15 05:50:06 belaban Exp $
007: */
008:
009: import java.util.HashMap;
010: import java.util.Iterator;
011:
012: public class ProtocolData {
013: /** Map<String,ProtocolParameter> of property keys and values */
014: private final HashMap mParameters = new HashMap();
015: private final String mProtocolName;
016: private final String mDescription;
017: private final String mClassName;
018: private boolean mIsOverRide = false;
019:
020: public ProtocolData(String protocolName, String description,
021: String className, ProtocolParameter[] params) {
022: mProtocolName = protocolName;
023: mDescription = description;
024: mClassName = className;
025: if (params != null) {
026: for (int i = 0; i < params.length; i++) {
027: mParameters.put(params[i].getName(), params[i]);
028: }
029: }
030: }
031:
032: public ProtocolData(String overRideName, ProtocolParameter[] params) {
033: this (overRideName, null, null, params);
034: mIsOverRide = true;
035:
036: }
037:
038: public String getClassName() {
039: return mClassName;
040: }
041:
042: public String getProtocolName() {
043: return mProtocolName;
044: }
045:
046: public String getDescription() {
047: return mDescription;
048: }
049:
050: public HashMap getParameters() {
051: return mParameters;
052: }
053:
054: public boolean isOverride() {
055: return mIsOverRide;
056: }
057:
058: public ProtocolParameter[] getParametersAsArray() {
059: ProtocolParameter[] result = new ProtocolParameter[mParameters
060: .size()];
061: Iterator it = mParameters.keySet().iterator();
062: for (int i = 0; i < result.length; i++) {
063: String key = (String) it.next();
064: result[i] = (ProtocolParameter) mParameters.get(key);
065: }
066: return result;
067: }
068:
069: public void override(ProtocolParameter[] params) {
070: for (int i = 0; i < params.length; i++)
071: mParameters.put(params[i].getName(), params[i]);
072: }
073:
074: public String getProtocolString(boolean new_format) {
075: return new_format ? getProtocolStringNewXml()
076: : getProtocolString();
077: }
078:
079: public String getProtocolString() {
080: StringBuffer buf = new StringBuffer(mClassName);
081: if (mParameters.size() > 0) {
082: buf.append('(');
083: Iterator i = mParameters.keySet().iterator();
084: while (i.hasNext()) {
085: String key = (String) i.next();
086: ProtocolParameter param = (ProtocolParameter) mParameters
087: .get(key);
088: buf.append(param.getParameterString());
089: if (i.hasNext())
090: buf.append(';');
091: }//while
092: buf.append(')');
093: }
094: return buf.toString();
095: }
096:
097: public String getProtocolStringNewXml() {
098: StringBuffer buf = new StringBuffer(mClassName + ' ');
099: if (mParameters.size() > 0) {
100: Iterator i = mParameters.keySet().iterator();
101: while (i.hasNext()) {
102: String key = (String) i.next();
103: ProtocolParameter param = (ProtocolParameter) mParameters
104: .get(key);
105: buf.append(param.getParameterStringXml());
106: if (i.hasNext())
107: buf.append(' ');
108: }
109: }
110: return buf.toString();
111: }
112:
113: public int hashCode() {
114: return mProtocolName.hashCode();
115: }
116:
117: public boolean equals(Object another) {
118: if (another instanceof ProtocolData)
119: return getProtocolName().equals(
120: ((ProtocolData) another).getProtocolName());
121: else
122: return false;
123: }
124:
125: }
|