1 22 package org.jboss.deployers.spi; 23 24 import java.util.Collection ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 import java.util.Set ; 31 32 import org.jboss.dependency.spi.Controller; 33 import org.jboss.dependency.spi.ControllerContext; 34 import org.jboss.dependency.spi.ControllerState; 35 import org.jboss.dependency.spi.DependencyInfo; 36 import org.jboss.dependency.spi.DependencyItem; 37 import org.jboss.deployers.spi.deployment.MainDeployer; 38 import org.jboss.deployers.spi.structure.DeploymentContext; 39 40 46 public class IncompleteDeploymentsBuilder 47 { 48 54 private static Throwable getCause(Throwable original) 55 { 56 if (original == null) 57 return null; 58 Throwable result = original; 59 Throwable cause = result.getCause(); 60 while (cause != null) 61 { 62 result = cause; 63 cause = cause.getCause(); 64 } 65 return result; 66 } 67 68 75 public static IncompleteDeployments build(MainDeployer main, Controller controller) 76 { 77 Map <String , Throwable > deploymentsInError = null; 78 Collection <String > deploymentsMissingDeployer = null; 79 Map <String , Throwable > contextsInError = null; 80 Map <String , Set <MissingDependency>> contextsMissingDependencies = null; 81 82 if (main != null) 83 { 84 Collection <DeploymentContext> errors = main.getErrors(); 85 if (errors != null && errors.isEmpty() == false) 86 { 87 deploymentsInError = new HashMap <String , Throwable >(); 88 for (DeploymentContext context : errors) 89 deploymentsInError.put(context.getName(), getCause(context.getProblem())); 90 } 91 92 93 Collection <DeploymentContext> missingDeployer = main.getMissingDeployer(); 94 if (missingDeployer != null && missingDeployer.isEmpty() == false) 95 { 96 deploymentsMissingDeployer = new HashSet <String >(); 97 for (DeploymentContext context : missingDeployer) 98 deploymentsMissingDeployer.add(context.getName()); 99 } 100 } 101 102 if (controller != null) 103 { 104 List <ControllerState> states = controller.getStates(); 105 106 Set <ControllerContext> notInstalled = controller.getNotInstalled(); 107 if (notInstalled.isEmpty() == false) 108 { 109 for (Iterator <ControllerContext> i = notInstalled.iterator(); i.hasNext();) 110 { 111 ControllerContext context = i.next(); 112 if (context.getState().equals(context.getRequiredState())) 113 i.remove(); 114 } 115 if (notInstalled.isEmpty() == false) 116 { 117 contextsInError = new HashMap <String , Throwable >(); 118 contextsMissingDependencies = new HashMap <String , Set <MissingDependency>>(); 119 for (ControllerContext context : notInstalled) 120 { 121 if (context.getState().equals(ControllerState.ERROR)) 122 contextsInError.put(context.getName().toString(), getCause(context.getError())); 123 else 124 { 125 String name = context.getName().toString(); 126 Set <MissingDependency> dependencies = new HashSet <MissingDependency>(); 127 DependencyInfo dependsInfo = context.getDependencyInfo(); 128 for (DependencyItem item : dependsInfo.getIDependOn(null)) 129 { 130 if (item.isResolved() == false) 131 { 132 String dependency; 133 ControllerState actualState = null; 134 String actualStateString; 135 Object iDependOn = item.getIDependOn(); 136 if (iDependOn == null) 137 { 138 dependency = "<UNKNOWN>"; 139 actualStateString = "** UNRESOLVED " + item + " **"; 141 } 142 else 143 { 144 dependency = iDependOn.toString(); 145 ControllerContext other = controller.getContext(item.getIDependOn(), null); 146 if (other == null) 147 actualStateString = "** NOT FOUND **"; 148 else 149 { 150 actualState = other.getState(); 151 actualStateString = actualState.getStateString(); 152 } 153 } 154 ControllerState requiredState = item.getWhenRequired(); 155 String requiredStateString = requiredState.getStateString(); 156 int required = states.indexOf(requiredState); 157 int actual = actualState == null ? -1 : states.indexOf(actualState); 158 if (required > actual) 159 { 160 MissingDependency missing = new MissingDependency(name, dependency, requiredStateString, actualStateString); 161 dependencies.add(missing); 162 } 163 } 164 } 165 contextsMissingDependencies.put(name, dependencies); 166 } 167 } 168 } 169 } 170 } 171 172 return new IncompleteDeployments(deploymentsInError, deploymentsMissingDeployer, contextsInError, contextsMissingDependencies); 173 } 174 } 175 | Popular Tags |