KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > deployers > spi > IncompleteDeploymentException


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.deployers.spi;
23
24 import java.util.Collection JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Map JavaDoc;
27 import java.util.Set JavaDoc;
28
29 /**
30  * IncompleteDeploymentException.
31  *
32  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
33  * @version $Revision: 1.1 $
34  */

35 public class IncompleteDeploymentException extends DeploymentException
36 {
37    /** The serialVersionUID */
38    private static final long serialVersionUID = 1433292979582684692L;
39
40    /** Incomplete deployments */
41    private IncompleteDeployments incompleteDeployments;
42
43    /**
44     * For serialization
45     */

46    public IncompleteDeploymentException()
47    {
48    }
49    
50    /**
51     * Create a new IncompleteDeploymentException.
52     *
53     * @param incompleteDeployments the incomplete deployments
54     * @throws IllegalArgumentException for null incompleteDeployments
55     */

56    public IncompleteDeploymentException(IncompleteDeployments incompleteDeployments)
57    {
58       if (incompleteDeployments == null)
59          throw new IllegalArgumentException JavaDoc("Null incompleteDeployments");
60       this.incompleteDeployments = incompleteDeployments;
61    }
62
63    /**
64     * Get the incompleteDeployments.
65     *
66     * @return the incompleteDeployments.
67     */

68    public IncompleteDeployments getIncompleteDeployments()
69    {
70       return incompleteDeployments;
71    }
72
73    // TODO Some of the calculations done in this method should be done upfront in IncompleteDeployments instead!
74
@Override JavaDoc
75    public String JavaDoc getMessage()
76    {
77       StringBuilder JavaDoc buffer = new StringBuilder JavaDoc();
78       buffer.append("Summary of incomplete deployments (SEE PREVIOUS ERRORS FOR DETAILS):\n");
79
80       // Display all the missing deployers
81
Collection JavaDoc<String JavaDoc> deploymentsMissingDeployers = incompleteDeployments.getDeploymentsMissingDeployer();
82       if (deploymentsMissingDeployers.isEmpty() == false)
83       {
84          buffer.append("\n*** DEPLOYMENTS MISSING DEPLOYERS: Name\n\n");
85          for (String JavaDoc name : deploymentsMissingDeployers)
86             buffer.append(name).append('\n');
87       }
88
89       // Display all the incomplete deployments
90
Map JavaDoc<String JavaDoc, Throwable JavaDoc> deploymentsInError = incompleteDeployments.getDeploymentsInError();
91       if (deploymentsInError.isEmpty() == false)
92       {
93          buffer.append("\n*** DEPLOYMENTS IN ERROR: Name -> Error\n\n");
94          for (Map.Entry JavaDoc<String JavaDoc, Throwable JavaDoc> entry : deploymentsInError.entrySet())
95             buffer.append(entry.getKey()).append(" -> ").append(entry.getValue().toString()).append("\n\n");
96       }
97
98       // Popluate the potential root causes
99
Map JavaDoc<String JavaDoc, String JavaDoc> rootCauses = new HashMap JavaDoc<String JavaDoc, String JavaDoc>();
100
101       // Missing dependencies are root causes
102
Map JavaDoc<String JavaDoc, Set JavaDoc<MissingDependency>> contextsMissingDependencies = incompleteDeployments.getContextsMissingDependencies();
103       if (contextsMissingDependencies.isEmpty() == false)
104       {
105          for (Map.Entry JavaDoc<String JavaDoc, Set JavaDoc<MissingDependency>> entry : contextsMissingDependencies.entrySet())
106          {
107             for (MissingDependency dependency : entry.getValue())
108                rootCauses.put(dependency.getDependency(), dependency.getActualState());
109          }
110       }
111
112       // Errors are root causes
113
Map JavaDoc<String JavaDoc, Throwable JavaDoc> contextsInError = incompleteDeployments.getContextsInError();
114       if (contextsInError.isEmpty() == false)
115       {
116          for (Map.Entry JavaDoc<String JavaDoc, Throwable JavaDoc> entry : contextsInError.entrySet())
117          {
118             Throwable JavaDoc t = entry.getValue();
119             if (t == null)
120                rootCauses.put(entry.getKey(), "** UNKNOWN ERROR **");
121             else
122                rootCauses.put(entry.getKey(), t.toString());
123          }
124       }
125
126       // Display all the missing dependencies
127
if (contextsMissingDependencies.isEmpty() == false)
128       {
129          buffer.append("\n*** CONTEXTS MISSING DEPENDENCIES: Name -> Dependency{Required State:Actual State}\n\n");
130          for (Map.Entry JavaDoc<String JavaDoc, Set JavaDoc<MissingDependency>> entry : contextsMissingDependencies.entrySet())
131          {
132             String JavaDoc name = entry.getKey();
133             buffer.append(name).append("\n");
134             for (MissingDependency dependency : entry.getValue())
135             {
136                buffer.append(" -> ").append(dependency.getDependency());
137                buffer.append('{').append(dependency.getRequiredState());
138                buffer.append(':').append(dependency.getActualState()).append("}");
139                buffer.append("\n");
140             }
141             buffer.append('\n');
142             
143             // It is not a root cause if it has missing dependencies
144
rootCauses.remove(name);
145          }
146       }
147       if (rootCauses.isEmpty() == false)
148       {
149          buffer.append("\n*** CONTEXTS IN ERROR: Name -> Error\n\n");
150          for (Map.Entry JavaDoc<String JavaDoc, String JavaDoc> entry : rootCauses.entrySet())
151             buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\n\n");
152       }
153       return buffer.toString();
154    }
155 }
156
Popular Tags