1 22 package org.jboss.dependency.plugins; 23 24 import java.util.HashSet ; 25 import java.util.Iterator ; 26 import java.util.Set ; 27 28 import org.jboss.dependency.spi.Controller; 29 import org.jboss.dependency.spi.ControllerState; 30 import org.jboss.dependency.spi.DependencyInfo; 31 import org.jboss.dependency.spi.DependencyItem; 32 import org.jboss.util.JBossObject; 33 import org.jboss.util.JBossStringBuilder; 34 import org.jboss.util.collection.CollectionsFactory; 35 36 42 public class AbstractDependencyInfo extends JBossObject implements DependencyInfo 43 { 44 45 private Set <DependencyItem> iDependOn = CollectionsFactory.createCopyOnWriteSet(); 46 47 48 private Set <DependencyItem> dependsOnMe = CollectionsFactory.createCopyOnWriteSet(); 49 50 51 private Set <DependencyItem> unresolved = CollectionsFactory.createCopyOnWriteSet(); 52 53 56 public AbstractDependencyInfo() 57 { 58 } 59 60 public Set <DependencyItem> getIDependOn(Class type) 61 { 62 if (type == null || iDependOn.isEmpty()) 63 return iDependOn; 64 else 65 { 66 HashSet <DependencyItem> set = new HashSet <DependencyItem>(); 67 for (Iterator i = iDependOn.iterator(); i.hasNext();) 68 { 69 DependencyItem item = (DependencyItem) i.next(); 70 if (type.isInstance(item)) 71 set.add(item); 72 } 73 return set; 74 } 75 } 76 77 public void addIDependOn(DependencyItem dependency) 78 { 79 iDependOn.add(dependency); 80 unresolved.add(dependency); 81 flushJBossObjectCache(); 82 } 83 84 public void removeIDependOn(DependencyItem dependency) 85 { 86 iDependOn.remove(dependency); 87 unresolved.remove(dependency); 88 flushJBossObjectCache(); 89 } 90 91 public Set <DependencyItem> getDependsOnMe(Class type) 92 { 93 if (type == null || dependsOnMe.isEmpty()) 94 return dependsOnMe; 95 else 96 { 97 HashSet <DependencyItem> set = new HashSet <DependencyItem>(); 98 for (Iterator i = dependsOnMe.iterator(); i.hasNext();) 99 { 100 DependencyItem item = (DependencyItem) i.next(); 101 if (type.isInstance(item)) 102 set.add(item); 103 } 104 return set; 105 } 106 } 107 108 public void addDependsOnMe(DependencyItem dependency) 109 { 110 dependsOnMe.add(dependency); 111 flushJBossObjectCache(); 112 } 113 114 public void removeDependsOnMe(DependencyItem dependency) 115 { 116 dependsOnMe.add(dependency); 117 flushJBossObjectCache(); 118 } 119 120 public boolean resolveDependencies(Controller controller, ControllerState state) 121 { 122 boolean resolved = true; 123 if (unresolved.isEmpty() == false) 124 { 125 for (Iterator i = unresolved.iterator(); i.hasNext();) 126 { 127 DependencyItem item = (DependencyItem) i.next(); 128 if (state.equals(item.getWhenRequired()) && item.resolve(controller) == false) 129 { 130 resolved = false; 131 break; 132 } 133 } 134 } 135 return resolved; 136 } 137 138 public Set <DependencyItem> getUnresolvedDependencies() 139 { 140 return unresolved; 141 } 142 143 public void toString(JBossStringBuilder buffer) 144 { 145 buffer.append("idependOn=").append(iDependOn); 146 if (unresolved.isEmpty() == false) 147 buffer.append(" unresolved=").append(unresolved); 148 } 149 } 150 | Popular Tags |