1 23 package com.sun.enterprise.repository; 24 25 import java.util.*; 26 import java.io.Serializable ; 27 28 33 public abstract class J2EEResourceBase implements J2EEResource, Serializable { 34 35 String name_; 36 Map properties_; 37 boolean enabled_; 39 String description_; 40 42 public J2EEResourceBase(String name) { 43 name_ = name; 44 properties_ = new HashMap(); 45 } 46 47 public String getName() { 48 return name_; 49 } 50 51 public void setEnabled(boolean value) { 53 enabled_ = value; 54 } 55 56 public boolean isEnabled() { 57 return enabled_; 58 } 59 60 public void setDescription(String value) { 61 description_ = value; 62 } 63 64 public String getDescription() { 65 return description_; 66 } 67 69 public abstract int getType(); 70 71 public Set getProperties() { 72 Set shallowCopy = new HashSet(); 73 Collection collection = properties_.values(); 74 for(Iterator iter = collection.iterator(); iter.hasNext();) { 75 ResourceProperty next = (ResourceProperty) iter.next(); 76 shallowCopy.add(next); 77 } 78 return shallowCopy; 79 } 80 81 public void addProperty(ResourceProperty property) { 82 properties_.put(property.getName(), property); 83 } 84 85 public boolean removeProperty(ResourceProperty property) { 86 Object removedObj = properties_.remove(property.getName()); 87 return (removedObj != null); 88 } 89 90 public ResourceProperty getProperty(String propertyName) { 91 return (ResourceProperty) properties_.get(propertyName); 92 } 93 94 public J2EEResource makeClone(String name) { 95 J2EEResource clone = doClone(name); 96 Set entrySet = properties_.entrySet(); 97 for(Iterator iter = entrySet.iterator(); iter.hasNext();) { 98 Map.Entry next = (Map.Entry) iter.next(); 99 ResourceProperty nextProp = (ResourceProperty) next.getValue(); 100 ResourceProperty propClone = 101 new ResourcePropertyImpl((String ) next.getKey()); 102 propClone.setValue(next.getValue()); 103 104 clone.addProperty(propClone); 105 } 106 clone.setEnabled(isEnabled()); 108 clone.setDescription(getDescription()); 109 return clone; 111 } 112 113 protected String getPropsString() { 114 StringBuffer propsBuffer = new StringBuffer (); 115 Set props = getProperties(); 116 if( !props.isEmpty() ) { 117 for(Iterator iter = props.iterator(); iter.hasNext(); ) { 118 if( propsBuffer.length() == 0 ) { 119 propsBuffer.append("[ "); 120 } else { 121 propsBuffer.append(" , "); 122 } 123 ResourceProperty next = (ResourceProperty) iter.next(); 124 propsBuffer.append(next.getName() + "=" + next.getValue()); 125 } 126 propsBuffer.append(" ]"); 127 } 128 return propsBuffer.toString(); 129 } 130 131 protected abstract J2EEResource doClone(String name); 132 } 133 | Popular Tags |