KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > spi > persistence > support > ejb > ejbc > JDOCodeGeneratorHelper


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * JDOCodeGeneratorHelper.java
26  *
27  * Created on Aug 28, 2001
28  */

29
30 package com.sun.jdo.spi.persistence.support.ejb.ejbc;
31
32 import java.util.ResourceBundle JavaDoc;
33
34 import com.sun.ejb.codegen.GeneratorException;
35
36 import com.sun.enterprise.deployment.Application;
37 import com.sun.enterprise.deployment.EjbBundleDescriptor;
38
39 import com.sun.jdo.spi.persistence.utility.I18NHelper;
40
41 /*
42  * This is the helper class for JDO code generation
43  *
44  */

45 public class JDOCodeGeneratorHelper {
46
47     /**
48      * I18N message handler
49      */

50     private final static ResourceBundle JavaDoc messages = I18NHelper.loadBundle(
51         JDOCodeGeneratorHelper.class);
52
53     /** Calculate module name from a bundle.
54      * @return module name.
55      */

56     public static String JavaDoc getModuleName(EjbBundleDescriptor bundle) {
57         String JavaDoc moduleName = null;
58         Application application = bundle.getApplication();
59         if (application.isVirtual()) {
60             // Stand-alone module is deployed.
61
moduleName = application.getRegistrationName();
62
63         } else {
64             // Module is deployed as a part of an Application.
65
String JavaDoc jarName = bundle.getModuleDescriptor().getArchiveUri();
66             int l = jarName.length();
67
68             // Remove ".jar" from the bundle's jar name.
69
moduleName = jarName.substring(0, l - 4);
70
71         }
72
73         return moduleName;
74     }
75
76     /**
77      * Create GeneratorException for this message key.
78      * @param key the message key in the bundle.
79      * @param bundle the ejb bundle.
80      * @return GeneratorException.
81      */

82     public static GeneratorException createGeneratorException(
83             String JavaDoc key, EjbBundleDescriptor bundle) {
84         return new GeneratorException(I18NHelper.getMessage(
85             messages, key,
86             bundle.getApplication().getRegistrationName(),
87             getModuleName(bundle)));
88     }
89
90     /**
91      * Create GeneratorException for this message key.
92      * @param key the message key in the bundle.
93      * @param bundle the ejb bundle.
94      * @param e the Exception to use for the message.
95      * @return GeneratorException.
96      */

97     public static GeneratorException createGeneratorException(
98             String JavaDoc key, EjbBundleDescriptor bundle, Exception JavaDoc e) {
99
100         return new GeneratorException(I18NHelper.getMessage(
101             messages, key,
102             bundle.getApplication().getRegistrationName(),
103             getModuleName(bundle),
104             e.getMessage()));
105     }
106
107     /**
108      * Create GeneratorException for this message key and bean name.
109      * @param key the message key in the bundle.
110      * @param bundle the ejb bundle.
111      * @return GeneratorException.
112      */

113     public static GeneratorException createGeneratorException(
114             String JavaDoc key, String JavaDoc beanName, EjbBundleDescriptor bundle) {
115
116         return new GeneratorException(I18NHelper.getMessage(
117             messages, key, beanName,
118             bundle.getApplication().getRegistrationName(),
119             getModuleName(bundle)));
120     }
121
122     /**
123      * Create GeneratorException for this message key and bean name.
124      * @param key the message key in the bundle.
125      * @param beanName the CMP bean name that caused the exception.
126      * @param bundle the ejb bundle.
127      * @param e the Exception to use for the message.
128      * @return GeneratorException.
129      */

130     public static GeneratorException createGeneratorException(
131             String JavaDoc key, String JavaDoc beanName, EjbBundleDescriptor bundle,
132             Exception JavaDoc e) {
133
134         return createGeneratorException(key, beanName, bundle, e.getMessage());
135     }
136
137     /**
138      * Create GeneratorException for this message key, bean name,
139      * and a StringBuffer with validation exceptions.
140      * @param key the message key in the bundle.
141      * @param beanName the CMP bean name that caused the exception.
142      * @param bundle the ejb bundle.
143      * @param e the Exception to use for the message.
144      * @param buf the StringBuffer with validation exceptions.
145      * @return GeneratorException.
146      */

147     public static GeneratorException createGeneratorException(
148             String JavaDoc key, String JavaDoc beanName, EjbBundleDescriptor bundle,
149             Exception JavaDoc e, StringBuffer JavaDoc buf) {
150
151         String JavaDoc msg = (buf == null) ?
152                 e.getMessage() :
153                 buf.append(e.getMessage()).append('\n').toString();
154         return createGeneratorException(key, beanName, bundle, msg);
155     }
156
157     /**
158      * Create GeneratorException for this message key and bean name.
159      * @param key the message key in the bundle.
160      * @param beanName the CMP bean name that caused the exception.
161      * @param bundle the ejb bundle.
162      * @param msg the message text to append.
163      * @return GeneratorException.
164      */

165     public static GeneratorException createGeneratorException(
166             String JavaDoc key, String JavaDoc beanName, EjbBundleDescriptor bundle,
167             String JavaDoc msg) {
168
169         return new GeneratorException(I18NHelper.getMessage(
170             messages, key,
171             new Object JavaDoc[] {
172                 beanName,
173                 bundle.getApplication().getRegistrationName(),
174                 getModuleName(bundle),
175                 msg}
176             ));
177     }
178 }
179
Popular Tags