1 3 package org.jgroups.conf; 4 5 10 11 import java.util.HashMap ; 12 import java.util.Iterator ; 13 14 public class ProtocolData { 15 private final HashMap mParameters=new HashMap (); 16 private final String mProtocolName; 17 private final String mDescription; 18 private final String mClassName; 19 private boolean mIsOverRide=false; 20 21 public ProtocolData(String protocolName, 22 String description, 23 String 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 overRideName, 36 ProtocolParameter[] params) { 37 this(overRideName, null, null, params); 38 mIsOverRide=true; 39 40 } 41 42 public String getClassName() { 43 return mClassName; 44 } 45 46 public String getProtocolName() { 47 return mProtocolName; 48 } 49 50 public String getDescription() { 51 return mDescription; 52 } 53 54 public HashMap 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 it=mParameters.keySet().iterator(); 65 for(int i=0; i < result.length; i++) { 66 String key=(String )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 getProtocolString(boolean new_format) { 79 return new_format? getProtocolStringNewXml() : getProtocolString(); 80 } 81 82 public String getProtocolString() { 83 StringBuffer buf=new StringBuffer (mClassName); 84 if(mParameters.size() > 0) { 85 buf.append('('); 86 Iterator i=mParameters.keySet().iterator(); 87 while(i.hasNext()) { 88 String key=(String )i.next(); 89 ProtocolParameter param=(ProtocolParameter)mParameters.get(key); 90 buf.append(param.getParameterString()); 91 if(i.hasNext()) buf.append(';'); 92 } buf.append(')'); 94 } 95 return buf.toString(); 96 } 97 98 public String getProtocolStringNewXml() { 99 StringBuffer buf=new StringBuffer (mClassName + ' '); 100 if(mParameters.size() > 0) { 101 Iterator i=mParameters.keySet().iterator(); 102 while(i.hasNext()) { 103 String key=(String )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 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 |