1 22 package org.jboss.beans.metadata.plugins; 23 24 import java.util.Iterator ; 25 26 import org.jboss.beans.metadata.spi.DemandMetaData; 27 import org.jboss.beans.metadata.spi.MetaDataVisitor; 28 import org.jboss.beans.metadata.spi.MetaDataVisitorNode; 29 import org.jboss.dependency.plugins.AbstractDependencyItem; 30 import org.jboss.dependency.spi.Controller; 31 import org.jboss.dependency.spi.ControllerContext; 32 import org.jboss.dependency.spi.ControllerState; 33 import org.jboss.dependency.spi.DependencyItem; 34 import org.jboss.kernel.spi.dependency.KernelControllerContext; 35 import org.jboss.util.JBossObject; 36 import org.jboss.util.JBossStringBuilder; 37 38 44 public class AbstractDemandMetaData extends JBossObject implements DemandMetaData 45 { 46 47 protected Object demand; 48 49 50 protected ControllerState whenRequired = ControllerState.DESCRIBED; 51 52 53 protected AbstractDependencyItem dependencyItem; 54 55 58 public AbstractDemandMetaData() 59 { 60 } 61 62 67 public AbstractDemandMetaData(Object demand) 68 { 69 this.demand = demand; 70 } 71 72 77 public void setWhenRequired(ControllerState whenRequired) 78 { 79 this.whenRequired = whenRequired; 80 flushJBossObjectCache(); 81 } 82 83 88 public void setDemand(Object demand) 89 { 90 this.demand = demand; 91 flushJBossObjectCache(); 92 } 93 94 public Object getDemand() 95 { 96 return demand; 97 } 98 99 public ControllerState getWhenRequired() 100 { 101 return whenRequired; 102 } 103 104 public void initialVisit(MetaDataVisitor visitor) 105 { 106 KernelControllerContext context = visitor.getControllerContext(); 107 DependencyItem item = new DemandDependencyItem(context.getName()); 108 visitor.addDependency(item); 109 visitor.initialVisit(this); 110 } 111 112 public void describeVisit(MetaDataVisitor vistor) 113 { 114 vistor.describeVisit(this); 115 } 116 117 public Iterator <? extends MetaDataVisitorNode> getChildren() 118 { 119 return null; 120 } 121 122 public void toString(JBossStringBuilder buffer) 123 { 124 buffer.append("demand=").append(demand); 125 if (whenRequired != null) 126 buffer.append(" whenRequired").append(whenRequired.getStateString()); 127 } 128 129 public void toShortString(JBossStringBuilder buffer) 130 { 131 buffer.append(demand); 132 } 133 134 137 public class DemandDependencyItem extends AbstractDependencyItem 138 { 139 144 public DemandDependencyItem(Object name) 145 { 146 super(name, null, whenRequired, null); 147 } 148 149 public boolean resolve(Controller controller) 150 { 151 ControllerContext context = controller.getInstalledContext(demand); 152 if (context != null) 153 { 154 setIDependOn(context.getName()); 155 addDependsOnMe(controller, context); 156 setResolved(true); 157 } 158 else 159 { 160 setResolved(false); 161 } 162 return isResolved(); 163 } 164 165 public void unresolved() 166 { 167 setIDependOn(null); 168 setResolved(false); 169 } 170 171 public void toString(JBossStringBuilder buffer) 172 { 173 super.toString(buffer); 174 buffer.append(" demand=").append(demand); 175 } 176 177 public void toShortString(JBossStringBuilder buffer) 178 { 179 buffer.append(getName()).append(" demands ").append(demand); 180 } 181 } 182 } 183 | Popular Tags |