KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > iiop > rmi > ExceptionAnalysis


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.iiop.rmi;
23
24 /**
25  * Exception analysis.
26  *
27  * Routines here are conforming to the "Java(TM) Language to IDL Mapping
28  * Specification", version 1.1 (01-06-07).
29  *
30  * @author <a HREF="mailto:osh@sparre.dk">Ole Husgaard</a>
31  * @version $Revision: 42315 $
32  */

33 public class ExceptionAnalysis
34    extends ValueAnalysis
35 {
36    // Constants -----------------------------------------------------
37

38    // Attributes ----------------------------------------------------
39

40    // Static --------------------------------------------------------
41

42    private static final org.jboss.logging.Logger logger =
43                org.jboss.logging.Logger.getLogger(ExceptionAnalysis.class);
44
45    private static WorkCacheManager cache
46                                = new WorkCacheManager(ExceptionAnalysis.class);
47  
48    public static ExceptionAnalysis getExceptionAnalysis(Class JavaDoc cls)
49       throws RMIIIOPViolationException
50    {
51       return (ExceptionAnalysis)cache.getAnalysis(cls);
52    }
53
54    // Constructors --------------------------------------------------
55

56    protected ExceptionAnalysis(Class JavaDoc cls)
57    {
58       super(cls);
59       logger.debug("ExceptionAnalysis(\""+cls.getName()+"\") entered.");
60    }
61  
62    protected void doAnalyze()
63       throws RMIIIOPViolationException
64    {
65       super.doAnalyze();
66
67       if (!Exception JavaDoc.class.isAssignableFrom(cls) ||
68           RuntimeException JavaDoc.class.isAssignableFrom(cls))
69          throw new RMIIIOPViolationException(
70                              "Exception type " + cls.getName() +
71                              " must be a checked exception class.", "1.2.6");
72
73       // calculate exceptionRepositoryId
74
StringBuffer JavaDoc b = new StringBuffer JavaDoc("IDL:");
75       String JavaDoc pkgName = cls.getPackage().getName();
76
77       while (!"".equals(pkgName)) {
78          int idx = pkgName.indexOf('.');
79          String JavaDoc n = (idx == -1) ? pkgName : pkgName.substring(0, idx);
80          b.append(Util.javaToIDLName(n)).append('/');
81          pkgName = (idx == -1) ? "" : pkgName.substring(idx+1);
82       }
83
84       String JavaDoc base = cls.getName();
85       base = base.substring(base.lastIndexOf('.')+1);
86       if (base.endsWith("Exception"))
87          base = base.substring(0, base.length()-9);
88       base = Util.javaToIDLName(base + "Ex");
89
90       b.append(base).append(":1.0");
91       exceptionRepositoryId = b.toString();
92    }
93
94    // Public --------------------------------------------------------
95

96    /**
97     * Return the repository ID for the mapping of this analysis
98     * to an exception.
99     */

100    public String JavaDoc getExceptionRepositoryId()
101    {
102       return exceptionRepositoryId;
103    }
104
105    // Protected -----------------------------------------------------
106

107    // Private -------------------------------------------------------
108

109    private String JavaDoc exceptionRepositoryId;
110
111    // Inner classes ------------------------------------------------
112

113 }
114
115
Popular Tags