1 23 package com.sun.enterprise.repository; 24 25 import java.util.*; 26 27 32 public class J2EEResourceCollectionImpl implements J2EEResourceCollection { 33 34 private Map resourceSets_; 35 36 public J2EEResourceCollectionImpl() { 37 resourceSets_ = new HashMap(); 38 } 39 40 public Set getResourcesByType(int type) { 41 Map resourceSet = getResourcesInternal(type); 42 Collection collection = resourceSet.values(); 43 Set shallowCopy = new HashSet(); 44 for(Iterator iter = collection.iterator(); iter.hasNext();) { 45 J2EEResource next = (J2EEResource) iter.next(); 46 shallowCopy.add(next); 47 } 48 return shallowCopy; 49 } 50 51 public Set getAllResources() { 52 Set allResources = new HashSet(); 53 Collection resourcesByType = resourceSets_.values(); 54 for(Iterator iter = resourcesByType.iterator(); iter.hasNext(); ) { 55 HashMap next = (HashMap) iter.next(); 56 allResources.addAll(next.values()); 57 } 58 return allResources; 59 } 60 61 public void addResource(J2EEResource resource) { 62 Map resourceSet = getResourcesInternal(resource.getType()); 63 resourceSet.put(resource.getName(), resource); 64 } 65 66 public boolean removeResource(J2EEResource resource) { 67 Map resourceSet = getResourcesInternal(resource.getType()); 68 boolean removed = 69 (resourceSet.remove(resource.getName()) != null); 70 return removed; 71 } 72 73 public void removeAllResourcesByType(int type) { 74 resourceSets_.remove(new Integer (type)); 75 } 76 77 public J2EEResource getResourceByName(int type, String resourceName) { 78 Map resourceSet = getResourcesInternal(type); 79 return (J2EEResource) resourceSet.get(resourceName); 80 81 } 82 83 private Map getResourcesInternal(int type) { 84 Map resourceSet = (Map) resourceSets_.get(new Integer (type)); 85 if( resourceSet == null ) { 86 resourceSet = new HashMap(); 87 resourceSets_.put(new Integer (type), resourceSet); 88 } 89 return resourceSet; 90 } 91 92 } 93 | Popular Tags |