KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > internal > ejb > cmp3 > metadata > MetadataLogger


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
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
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 in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2006, Oracle. All rights reserved.
22
package oracle.toplink.essentials.internal.ejb.cmp3.metadata;
23
24 import java.util.HashMap JavaDoc;
25
26 import oracle.toplink.essentials.logging.SessionLog;
27 import oracle.toplink.essentials.internal.sessions.AbstractSession;
28
29 import oracle.toplink.essentials.internal.ejb.cmp3.metadata.accessors.MetadataAccessor;
30
31 /**
32  * Logger class for the metadata processors. It defines the common log messages
33  * used by the metadata processors.
34  *
35  * @author Guy Pelletier
36  * @since TopLink EJB 3.0 Reference Implementation
37  */

38 public class MetadataLogger {
39     public static final String JavaDoc ALIAS = "metadata_default_alias";
40     public static final String JavaDoc MAP_KEY_ATTRIBUTE_NAME = "metadata_default_map_key_attribute_name";
41     public static final String JavaDoc IGNORE_BASIC_FETCH_LAZY = "annotation_warning_ignore_basic_fetch_lazy";
42     public static final String JavaDoc IGNORE_GET_METHOD = "annotation_warning_ignore_get_method";
43     public static final String JavaDoc IGNORE_SECONDARY_TABLE = "annotation_warning_ignore_secondary_table";
44     
45     public static final String JavaDoc TABLE_NAME = "metadata_default_table_name";
46     public static final String JavaDoc TABLE_SCHEMA = "metadata_default_table_schema";
47     public static final String JavaDoc TABLE_CATALOG = "metadata_default_table_catalog";
48     
49     public static final String JavaDoc JOIN_TABLE_NAME = "metadata_default_join_table_name";
50     public static final String JavaDoc JOIN_TABLE_SCHEMA = "metadata_default_join_table_schema";
51     public static final String JavaDoc JOIN_TABLE_CATALOG = "metadata_default_join_table_catalog";
52     
53     public static final String JavaDoc COLUMN = "metadata_default_column";
54     public static final String JavaDoc PK_COLUMN = "metadata_default_pk_column";
55     public static final String JavaDoc FK_COLUMN = "metadata_default_fk_column";
56     public static final String JavaDoc SOURCE_PK_COLUMN = "metadata_default_source_pk_column";
57     public static final String JavaDoc SOURCE_FK_COLUMN = "metadata_default_source_fk_column";
58     public static final String JavaDoc TARGET_PK_COLUMN = "metadata_default_target_pk_column";
59     public static final String JavaDoc TARGET_FK_COLUMN = "metadata_default_target_fk_column";
60     public static final String JavaDoc DISCRIMINATOR_COLUMN = "metadata_default_discriminator_column";
61     public static final String JavaDoc INHERITANCE_PK_COLUMN = "metadata_default_inheritance_pk_column";
62     public static final String JavaDoc INHERITANCE_FK_COLUMN = "metadata_default_inheritance_fk_column";
63     public static final String JavaDoc SECONDARY_TABLE_PK_COLUMN = "metadata_default_secondary_table_pk_column";
64     public static final String JavaDoc SECONDARY_TABLE_FK_COLUMN = "metadata_default_secondary_table_fk_column";
65     
66     public static final String JavaDoc ONE_TO_ONE_MAPPING = "metadata_default_one_to_one_mapping";
67     public static final String JavaDoc ONE_TO_MANY_MAPPING = "metadata_default_one_to_many_mapping";
68     public static final String JavaDoc ONE_TO_ONE_MAPPING_REFERENCE_CLASS = "metadata_default_one_to_one_reference_class";
69     public static final String JavaDoc ONE_TO_MANY_MAPPING_REFERENCE_CLASS = "metadata_default_one_to_many_reference_class";
70     public static final String JavaDoc MANY_TO_ONE_MAPPING_REFERENCE_CLASS = "metadata_default_many_to_one_reference_class";
71     public static final String JavaDoc MANY_TO_MANY_MAPPING_REFERENCE_CLASS = "metadata_default_many_to_many_reference_class";
72     
73     // Shared context strings that are defined by the subclasses.
74
public static String JavaDoc IGNORE_TABLE;
75     public static String JavaDoc IGNORE_QUERY;
76     public static String JavaDoc IGNORE_MAPPING;
77     public static String JavaDoc IGNORE_ID_CLASS;
78     public static String JavaDoc IGNORE_PRIMARY_KEY;
79     public static String JavaDoc IGNORE_EMBEDDED_ID;
80     public static String JavaDoc IGNORE_INHERITANCE;
81     public static String JavaDoc IGNORE_VERSION_LOCKING;
82     
83     protected AbstractSession session;
84     protected HashMap JavaDoc ctxStrings;
85
86     public MetadataLogger(AbstractSession session) {
87         this.session = session;
88         ctxStrings = new HashMap JavaDoc();
89         initSharedContextStrings();
90         populateContextStrings();
91     }
92     
93     /**
94      * INTERNAL:
95      * Return the logging context string for the given context.
96      */

97     protected String JavaDoc getLoggingContextString(String JavaDoc context) {
98         return (String JavaDoc) ctxStrings.get(context);
99     }
100     
101     /**
102      * INTERNAL:
103      * Init the shared context strings.
104      */

105     protected void initSharedContextStrings() {
106         IGNORE_TABLE = "annotation_warning_ignore_table";
107         IGNORE_QUERY = "annotation_warning_ignore_query";
108         IGNORE_MAPPING = "annotation_warning_ignore_mapping";
109         IGNORE_ID_CLASS = "annotation_warning_ignore_id_class";
110         IGNORE_PRIMARY_KEY = "annotation_warning_ignore_primary_key";
111         IGNORE_EMBEDDED_ID = "annotation_warning_ignore_embedded_id";
112         IGNORE_INHERITANCE = "annotation_warning_ignore_inheritance";
113         IGNORE_VERSION_LOCKING = "annotation_warning_ignore_version_locking";
114     }
115     
116     /**
117      * INTERNAL:
118      * Logging utility method.
119      */

120     public void log(int level, String JavaDoc ctx, Object JavaDoc[] params) {
121         session.log(level, SessionLog.EJB_ANNOTATION, getLoggingContextString(ctx), params);
122     }
123     
124     /**
125      * INTERNAL:
126      * Logging utility method.
127      */

128     public void logConfigMessage(String JavaDoc ctx, MetadataAccessor accessor, Object JavaDoc param) {
129         log(SessionLog.CONFIG, ctx, new Object JavaDoc[] { accessor.getAnnotatedElement(), param });
130     }
131     
132     /**
133      * INTERNAL:
134      * Logging utility method.
135      */

136     public void logConfigMessage(String JavaDoc ctx, MetadataDescriptor md, Object JavaDoc param) {
137         log(SessionLog.CONFIG, ctx, new Object JavaDoc[] { md.getJavaClass(), param });
138     }
139     
140     /**
141      * INTERNAL:
142      * Logging utility method.
143      */

144     public void logConfigMessage(String JavaDoc ctx, Object JavaDoc object) {
145         log(SessionLog.CONFIG, ctx, new Object JavaDoc[] { object });
146     }
147     
148     /**
149      * INTERNAL:
150      * Logging utility method.
151      */

152     public void logConfigMessage(String JavaDoc ctx, Object JavaDoc param1, Object JavaDoc param2) {
153         log(SessionLog.CONFIG, ctx, new Object JavaDoc[] { param1, param2 });
154     }
155     
156     /**
157      * INTERNAL:
158      * Logging utility method.
159      */

160     public void logWarningMessage(String JavaDoc ctx, MetadataAccessor accessor) {
161         log(SessionLog.WARNING, ctx, new Object JavaDoc[] { accessor.getJavaClass(), accessor.getAttributeName() });
162     }
163     
164     /**
165      * INTERNAL:
166      * Logging utility method.
167      */

168     public void logWarningMessage(String JavaDoc ctx, Object JavaDoc param) {
169         log(SessionLog.WARNING, ctx, new Object JavaDoc[] { param });
170     }
171     
172     /**
173      * INTERNAL:
174      * Logging utility method.
175      */

176     public void logWarningMessage(String JavaDoc ctx, Object JavaDoc param1, Object JavaDoc param2) {
177         log(SessionLog.WARNING, ctx, new Object JavaDoc[] { param1, param2 });
178     }
179     
180     /**
181      * INTERNAL:
182      * Logging utility method.
183      */

184     public void logWarningMessage(String JavaDoc ctx, Object JavaDoc param1, Object JavaDoc param2, Object JavaDoc param3) {
185         log(SessionLog.WARNING, ctx, new Object JavaDoc[] {param1, param2, param3});
186     }
187     
188     /**
189      * INTERNAL:
190      * Method will populate the common logging strings. Subclasses can add
191      * to this by implementing this method. Just be sure to call this method
192      * from the subclass to get the common strings.
193      */

194     protected void populateContextStrings() {
195         ctxStrings.put(ALIAS, ALIAS);
196         ctxStrings.put(MAP_KEY_ATTRIBUTE_NAME, MAP_KEY_ATTRIBUTE_NAME);
197         
198         ctxStrings.put(TABLE_NAME, TABLE_NAME);
199         ctxStrings.put(TABLE_SCHEMA, TABLE_SCHEMA);
200         ctxStrings.put(TABLE_CATALOG, TABLE_CATALOG);
201         
202         ctxStrings.put(JOIN_TABLE_NAME, JOIN_TABLE_NAME);
203         ctxStrings.put(JOIN_TABLE_SCHEMA, JOIN_TABLE_SCHEMA);
204         ctxStrings.put(JOIN_TABLE_CATALOG, JOIN_TABLE_CATALOG);
205     
206         ctxStrings.put(COLUMN, COLUMN);
207         ctxStrings.put(PK_COLUMN, PK_COLUMN);
208         ctxStrings.put(FK_COLUMN, FK_COLUMN);
209         ctxStrings.put(SOURCE_PK_COLUMN, SOURCE_PK_COLUMN);
210         ctxStrings.put(SOURCE_FK_COLUMN, SOURCE_FK_COLUMN);
211         ctxStrings.put(TARGET_PK_COLUMN, TARGET_PK_COLUMN);
212         ctxStrings.put(TARGET_FK_COLUMN, TARGET_FK_COLUMN);
213         ctxStrings.put(DISCRIMINATOR_COLUMN, DISCRIMINATOR_COLUMN);
214         ctxStrings.put(INHERITANCE_PK_COLUMN, INHERITANCE_PK_COLUMN);
215         ctxStrings.put(INHERITANCE_FK_COLUMN, INHERITANCE_FK_COLUMN);
216         ctxStrings.put(SECONDARY_TABLE_PK_COLUMN, SECONDARY_TABLE_PK_COLUMN);
217         ctxStrings.put(SECONDARY_TABLE_FK_COLUMN, SECONDARY_TABLE_FK_COLUMN);
218         
219         ctxStrings.put(ONE_TO_ONE_MAPPING, ONE_TO_ONE_MAPPING);
220         ctxStrings.put(ONE_TO_MANY_MAPPING, ONE_TO_MANY_MAPPING);
221         ctxStrings.put(ONE_TO_ONE_MAPPING_REFERENCE_CLASS, ONE_TO_ONE_MAPPING_REFERENCE_CLASS);
222         ctxStrings.put(ONE_TO_MANY_MAPPING_REFERENCE_CLASS, ONE_TO_MANY_MAPPING_REFERENCE_CLASS);
223         ctxStrings.put(MANY_TO_ONE_MAPPING_REFERENCE_CLASS, MANY_TO_ONE_MAPPING_REFERENCE_CLASS);
224         ctxStrings.put(MANY_TO_MANY_MAPPING_REFERENCE_CLASS, MANY_TO_MANY_MAPPING_REFERENCE_CLASS);
225         
226         ctxStrings.put(IGNORE_GET_METHOD, IGNORE_GET_METHOD);
227         ctxStrings.put(IGNORE_SECONDARY_TABLE, IGNORE_SECONDARY_TABLE);
228         
229         ctxStrings.put(IGNORE_TABLE, IGNORE_TABLE);
230         ctxStrings.put(IGNORE_QUERY, IGNORE_QUERY);
231         ctxStrings.put(IGNORE_MAPPING, IGNORE_MAPPING);
232         ctxStrings.put(IGNORE_ID_CLASS, IGNORE_ID_CLASS);
233         ctxStrings.put(IGNORE_PRIMARY_KEY, IGNORE_PRIMARY_KEY);
234         ctxStrings.put(IGNORE_EMBEDDED_ID, IGNORE_EMBEDDED_ID);
235         ctxStrings.put(IGNORE_INHERITANCE, IGNORE_INHERITANCE);
236         ctxStrings.put(IGNORE_VERSION_LOCKING, IGNORE_VERSION_LOCKING);
237         ctxStrings.put(IGNORE_BASIC_FETCH_LAZY, IGNORE_BASIC_FETCH_LAZY);
238         
239     }
240     
241     /**
242      * INTERNAL:
243      * Set the session to log to.
244      */

245     public void setSession(AbstractSession session) {
246         this.session = session;
247     }
248 }
249
Popular Tags