KickJava   Java API By Example, From Geeks To Geeks.

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


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
26 /*
27  * CMPROTemplateFormatter.java
28  *
29  * Created on March 03, 2004
30  */

31
32 package com.sun.jdo.spi.persistence.support.ejb.ejbc;
33
34 import java.io.*;
35
36 import java.text.MessageFormat JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Properties JavaDoc;
39 import java.util.StringTokenizer JavaDoc;
40
41 /*
42  * This is the helper class for JDO specific generation of
43  * a read-only concrete bean implementation.
44  * This class does not extend CMPTemplateFormatter but only references
45  * its variables when necessary. This allows to reuse CMPTemplateFormatter's
46  * properties but the corresponding templates and formatters must be accessed
47  * directly.
48  *
49  * @author Marina Vatkina
50  */

51 public class CMPROTemplateFormatter {
52
53     private final static String JavaDoc templateFile =
54         "com/sun/jdo/spi/persistence/support/ejb/ejbc/CMPROTemplates.properties"; // NOI18N
55

56     // Strings for CMP code generation:
57
public final static String JavaDoc updateNotAllowed_ = "updateNotAllowed"; // NOI18N
58
public final static String JavaDoc accessNotAllowed_ = "accessNotAllowed"; // NOI18N
59
public final static String JavaDoc loadNonDFG_ = "loadNonDFG"; // NOI18N
60

61     // Code generator templates.
62
public static Properties JavaDoc helpers = null;
63
64     // variables
65
public static MessageFormat JavaDoc privatetransientvformatter = null; // privateTransientVariables
66

67     // methods
68
public static MessageFormat JavaDoc giformatter = null; // jdoGetInstance
69
public static MessageFormat JavaDoc jdolookuppmfformatter = null; // jdoLookupPersistenceManagerFactory
70
public static MessageFormat JavaDoc ejb__refreshformatter = null; // ejb__refresh
71
public static MessageFormat JavaDoc loadNonDFGformatter = null; // loadNonDFG
72

73     // standard templates for the corresponding keys, so that a template "xxxTemplate"
74
// corresponds to a "xxx" key.
75
public static String JavaDoc privateStaticVariablesTemplate = null;
76     public static String JavaDoc signatureTemplate = null;
77     public static String JavaDoc updateNotAllowedTemplate = null;
78     public static String JavaDoc accessNotAllowedTemplate = null;
79     public static String JavaDoc jdoCleanAllRefsTemplate = null;
80
81     // standard method bodies for the corresponding keys, so that a method body with
82
// a name "xxxBody" corresponds to a "xxx" key.
83
public static String JavaDoc[] jdoGetPersistenceManagerBody = null;
84     public static String JavaDoc[] jdoReleasePersistenceManagerBody = null;
85
86     /**
87      * Constructs a new <code>CMPROTemplateFormatter</code> instance.
88      */

89     CMPROTemplateFormatter() {
90     }
91
92     /**
93      * Initializes templates for code generation.
94      */

95     static synchronized void initHelpers() throws IOException {
96         if (helpers == null) {
97             helpers = new Properties JavaDoc();
98             CMPTemplateFormatter.loadProperties(helpers, templateFile);
99
100             initFormatters();
101             initTemplates();
102         }
103     }
104
105     /**
106      * Initializes MessageFormats for code generation.
107      */

108     private static void initFormatters() {
109         // variables
110
privatetransientvformatter = new MessageFormat JavaDoc(helpers.getProperty(
111                 CMPTemplateFormatter.privateTransientVariables_));
112
113         // methods
114
giformatter = new MessageFormat JavaDoc(helpers.getProperty(
115                 CMPTemplateFormatter.getInstance_));
116         jdolookuppmfformatter = new MessageFormat JavaDoc(helpers.getProperty(
117                 CMPTemplateFormatter.jdoLookupPersistenceManagerFactory_));
118         ejb__refreshformatter = new MessageFormat JavaDoc(helpers.getProperty(
119                 CMPTemplateFormatter.ejb__refresh_));
120         loadNonDFGformatter = new MessageFormat JavaDoc(helpers.getProperty(loadNonDFG_));
121     }
122
123     /**
124      * Initializes standard templates for code generation.
125      */

126     private static void initTemplates() {
127         privateStaticVariablesTemplate = helpers.getProperty(
128                 CMPTemplateFormatter.privateStaticVariables_);
129         signatureTemplate = helpers.getProperty(CMPTemplateFormatter.signature_);
130         updateNotAllowedTemplate = helpers.getProperty(updateNotAllowed_);
131         accessNotAllowedTemplate = helpers.getProperty(accessNotAllowed_);
132         jdoCleanAllRefsTemplate = helpers.getProperty(CMPTemplateFormatter.jdoCleanAllRefs_);
133
134         jdoGetPersistenceManagerBody = CMPTemplateFormatter.getBodyAsStrings(
135                 helpers.getProperty(CMPTemplateFormatter.jdoGetPersistenceManager_));
136         jdoReleasePersistenceManagerBody = CMPTemplateFormatter.getBodyAsStrings(
137                 helpers.getProperty(CMPTemplateFormatter.jdoReleasePersistenceManager_));
138     }
139 }
140
Popular Tags