1 22 package org.jboss.dependency.plugins; 23 24 import org.jboss.dependency.spi.Controller; 25 import org.jboss.dependency.spi.ControllerContext; 26 import org.jboss.dependency.spi.ControllerMode; 27 import org.jboss.dependency.spi.ControllerState; 28 import org.jboss.dependency.spi.DependencyInfo; 29 import org.jboss.dependency.spi.DependencyItem; 30 import org.jboss.logging.Logger; 31 import org.jboss.util.JBossObject; 32 import org.jboss.util.JBossStringBuilder; 33 34 40 public class AbstractDependencyItem extends JBossObject implements DependencyItem 41 { 42 43 private static final Logger log = Logger.getLogger(AbstractDependencyItem.class); 44 45 46 private Object iDependOn; 47 48 49 private Object name; 50 51 52 private ControllerState whenRequired = ControllerState.DESCRIBED; 53 54 55 private ControllerState dependentState; 56 57 58 private boolean resolved; 59 60 63 public AbstractDependencyItem() 64 { 65 } 66 67 75 public AbstractDependencyItem(Object name, Object iDependOn, ControllerState whenRequired, ControllerState dependentState) 76 { 77 this.name = name; 78 this.iDependOn = iDependOn; 79 this.whenRequired = whenRequired; 80 this.dependentState = dependentState; 81 } 82 83 public Object getName() 84 { 85 return name; 86 } 87 88 public Object getIDependOn() 89 { 90 return iDependOn; 91 } 92 93 public ControllerState getWhenRequired() 94 { 95 return whenRequired; 96 } 97 98 public ControllerState getDependentState() 99 { 100 return dependentState; 101 } 102 103 public boolean isResolved() 104 { 105 return resolved; 106 } 107 108 public boolean resolve(Controller controller) 109 { 110 boolean previous = resolved; 111 ControllerContext context; 112 113 if (dependentState == null) 114 context = controller.getInstalledContext(iDependOn); 115 else 116 { 117 context = controller.getContext(iDependOn, dependentState); 118 if (context == null) 119 { 120 if (dependentState == ControllerState.INSTALLED) 121 context = controller.getInstalledContext(iDependOn); 122 } 123 } 124 125 if (context == null) 126 { 127 resolved = false; 128 ControllerContext unresolvedContext = controller.getContext(iDependOn, null); 129 if (unresolvedContext != null && ControllerMode.ON_DEMAND.equals(unresolvedContext.getMode())) 130 { 131 try 132 { 133 controller.enableOnDemand(unresolvedContext); 134 } 135 catch (Throwable ignored) 136 { 137 if (log.isTraceEnabled()) 138 log.trace("Unexpected error", ignored); 139 } 140 } 141 } 142 else 143 { 144 addDependsOnMe(controller, context); 145 resolved = true; 146 } 147 148 if (previous != resolved) 149 { 150 flushJBossObjectCache(); 151 if (log.isTraceEnabled()) 152 { 153 if (resolved) 154 log.trace("Resolved " + this); 155 else 156 log.trace("Unresolved " + this); 157 } 158 } 159 return resolved; 160 } 161 162 public void unresolved(Controller controller) 163 { 164 if (resolved) 165 { 166 resolved = false; 167 flushJBossObjectCache(); 168 log.trace("Forced unresolved " + this); 169 } 170 } 171 172 public void toString(JBossStringBuilder buffer) 173 { 174 buffer.append("name=").append(name); 175 buffer.append(" dependsOn=").append(iDependOn); 176 if (whenRequired != null) 177 buffer.append(" whenRequired=").append(whenRequired.getStateString()); 178 if (dependentState != null) 179 buffer.append(" dependentState=").append(dependentState.getStateString()); 180 buffer.append(" resolved=").append(resolved); 181 } 182 183 public void toShortString(JBossStringBuilder buffer) 184 { 185 buffer.append(name).append(" dependsOn ").append(iDependOn); 186 } 187 188 194 protected void addDependsOnMe(Controller controller, ControllerContext context) 195 { 196 DependencyInfo info = context.getDependencyInfo(); 197 if (info != null) 198 info.addDependsOnMe(this); 199 } 200 201 206 protected void setIDependOn(Object iDependOn) 207 { 208 this.iDependOn = iDependOn; 209 flushJBossObjectCache(); 210 } 211 212 217 protected void setResolved(boolean resolved) 218 { 219 this.resolved = resolved; 220 flushJBossObjectCache(); 221 } 222 } 223 | Popular Tags |