1 package org.apache.ojb.broker.metadata; 2 3 17 18 import java.io.Serializable ; 19 import java.util.*; 20 21 26 class DescriptorBase implements AttributeContainer, Serializable 27 { 28 static final long serialVersionUID = 713914612744155925L; 29 30 private Map attributeMap = null; 31 32 35 public DescriptorBase() 36 { 37 } 38 39 42 public void addAttribute(String attributeName, String attributeValue) 43 { 44 if (attributeName == null) 46 { 47 return; 48 } 49 if (attributeMap == null) 51 { 52 attributeMap = new HashMap(); 53 } 54 attributeMap.put(attributeName, attributeValue); 56 } 57 58 61 public String getAttribute(String attributeName, String defaultValue) 62 { 63 String result = defaultValue; 64 if (attributeMap != null) 65 { 66 result = (String ) attributeMap.get(attributeName); 67 if (result == null) 68 { 69 result = defaultValue; 70 } 71 } 72 return result; 73 } 74 75 78 public String getAttribute(String attributeName) 79 { 80 return this.getAttribute(attributeName, null); 81 } 82 83 89 public Map getAttributes() 90 { 91 return Collections.unmodifiableMap(attributeMap); 92 } 93 94 99 public String [] getAttributeNames() 100 { 101 Set keys = (attributeMap == null ? new HashSet() : attributeMap.keySet()); 102 String [] result = new String [keys.size()]; 103 104 keys.toArray(result); 105 return result; 106 } 107 108 public String toString() 109 { 110 StringBuffer buf = new StringBuffer (); 111 buf.append("custom attributes ["); 112 buf.append(attributeMap); 113 buf.append("]"); 114 return buf.toString(); 115 } 116 } 117 | Popular Tags |