KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > embedded > KernelErrors


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.ejb3.embedded;
23
24 import java.util.HashSet JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.Set JavaDoc;
27 import org.jboss.dependency.spi.Controller;
28 import org.jboss.dependency.spi.ControllerContext;
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.kernel.Kernel;
33 import org.jboss.kernel.spi.dependency.KernelControllerContext;
34 import org.jboss.util.JBossStringBuilder;
35 import org.jboss.logging.Logger;
36
37 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 39972 $
42  */

43 public class KernelErrors
44 {
45    private static final Logger log = Logger.getLogger(KernelErrors.class);
46
47    public static boolean validate(Kernel kernel)
48    {
49       Controller controller = kernel.getController();
50       Set JavaDoc notInstalled = new HashSet JavaDoc(controller.getNotInstalled());
51       if (notInstalled.isEmpty()) return true;
52
53       for (Iterator JavaDoc i = notInstalled.iterator(); i.hasNext();)
54       {
55          KernelControllerContext context = (KernelControllerContext) i.next();
56          if (context.getState().equals(context.getRequiredState()))
57             i.remove();
58       }
59
60       if (notInstalled.isEmpty()) return true;
61
62       HashSet JavaDoc errors = new HashSet JavaDoc();
63       HashSet JavaDoc incomplete = new HashSet JavaDoc();
64       for (Iterator JavaDoc i = notInstalled.iterator(); i.hasNext();)
65       {
66          KernelControllerContext ctx = (KernelControllerContext) i.next();
67          if (ctx.getState().equals(ControllerState.ERROR))
68             errors.add(ctx);
69          else
70             incomplete.add(ctx);
71       }
72       if (errors.size() != 0)
73       {
74          log.error("*** DEPLOYMENTS IN ERROR:\n");
75          for (Iterator JavaDoc i = errors.iterator(); i.hasNext();)
76          {
77             KernelControllerContext ctx = (KernelControllerContext) i.next();
78             log.error("Failed deployment: " + ctx.getName(), ctx.getError());
79          }
80       }
81       if (incomplete.size() != 0)
82       {
83          JBossStringBuilder buffer = new JBossStringBuilder();
84          buffer.append("\n*** DEPLOYMENTS MISSING DEPENDENCIES:\n");
85          for (Iterator JavaDoc i = incomplete.iterator(); i.hasNext();)
86          {
87             KernelControllerContext ctx = (KernelControllerContext) i.next();
88             buffer.append(ctx.getName()).append(" depends on: \n");
89             DependencyInfo dependsInfo = ctx.getDependencyInfo();
90             Set JavaDoc depends = dependsInfo.getIDependOn(null);
91             for (Iterator JavaDoc j = depends.iterator(); j.hasNext();)
92             {
93                DependencyItem item = (DependencyItem) j.next();
94                buffer.append(" ").append(item.getIDependOn()).append("'{").append(item.getWhenRequired().getStateString());
95                buffer.append(':');
96                ControllerContext other = controller.getContext(item.getIDependOn(), null);
97                if (other == null)
98                   buffer.append("NOT FOUND");
99                else
100                   buffer.append(other.getState().getStateString());
101                buffer.append('}');
102                if (j.hasNext())
103                   buffer.append("\n");
104             }
105             buffer.append('\n');
106          }
107          log.error(buffer.toString());
108       }
109       if (errors.size() > 0 || incomplete.size() > 0)
110       {
111          return false;
112       }
113       return true;
114    }
115 }
116
Popular Tags