001: package com.avaje.util.codegen;
002:
003: import java.io.PrintStream;
004: import java.util.Map;
005:
006: import com.avaje.ebean.server.deploy.generatedproperty.GeneratedPropertySettings;
007: import com.avaje.ebean.server.naming.NamingConvention;
008: import com.avaje.ebean.server.plugin.Plugin;
009: import com.avaje.ebean.server.plugin.PluginProperties;
010: import com.avaje.lib.sql.DictionaryInfo;
011: import com.avaje.lib.util.StringHelper;
012:
013: public class GenerateConfiguration {
014:
015: NamingConvention namingConvention;
016:
017: TableNaming tableNaming;
018:
019: DictionaryInfo dictionaryInfo;
020:
021: GeneratedPropertySettings generatedPropertySettings;
022:
023: ReservedWords reservedWords;
024:
025: boolean writeMode = true;
026:
027: boolean withAnnotations = true;
028:
029: TableType tableType;
030:
031: PrintStream printStream;
032:
033: Plugin plugin;
034: PluginProperties properties;
035:
036: public GenerateConfiguration(Plugin plugin) {
037: this .plugin = plugin;
038: this .properties = plugin.getProperties();
039:
040: String mode = getProperty("codegen.mode", "generate");
041: if (!mode.equalsIgnoreCase("generate")) {
042: writeMode = false;
043: }
044:
045: printStream = System.out;
046:
047: tableType = new TableType(plugin);
048: generatedPropertySettings = new GeneratedPropertySettings(
049: properties);
050:
051: dictionaryInfo = plugin.getDbConfig().getDictionaryInfo();
052: namingConvention = plugin.getDbConfig().getNamingConvention();
053:
054: reservedWords = new ReservedWords();
055: tableNaming = new TableNaming(plugin);
056:
057: initReservedWords(plugin);
058: }
059:
060: public boolean isWriteMode() {
061: return writeMode;
062: }
063:
064: public void print(String msg) {
065: printStream.print(msg);
066: int blanks = 30 - msg.length();
067: for (int j = 0; j < blanks; j++) {
068: printStream.print(" ");
069: }
070: }
071:
072: public void println(String msg) {
073: printStream.println(msg);
074: }
075:
076: private void initReservedWords(Plugin plugin) {
077:
078: String resWords = properties.getProperty(
079: "codegen.reservedwords", null);
080: if (resWords != null) {
081: Map wordMapping = StringHelper.delimitedToMap(resWords,
082: ",", "=");
083: reservedWords(wordMapping);
084: }
085: }
086:
087: public String getProperty(String key, String defaultValue) {
088: return properties.getProperty(key, defaultValue);
089: }
090:
091: // public int getPropertyInt(String key, int defaultValue){
092: // return plugin.getPropertyInt(key, defaultValue);
093: // }
094: //
095: // public boolean getPropertyBoolean(String key, boolean defaultValue){
096: // return plugin.getPropertyBoolean(key, defaultValue);
097: // }
098:
099: /**
100: * Merge wordMapping into the reserved words mapping.
101: */
102: public void reservedWords(Map wordMapping) {
103: if (wordMapping != null) {
104: reservedWords.merge(wordMapping);
105: }
106: }
107:
108: public boolean isWithAnnotations() {
109: return withAnnotations;
110: }
111:
112: public void setWithAnnotations(boolean withAnnotations) {
113: this .withAnnotations = withAnnotations;
114: }
115:
116: public DictionaryInfo getDictionaryInfo() {
117: return dictionaryInfo;
118: }
119:
120: public NamingConvention getNamingConvention() {
121: return namingConvention;
122: }
123:
124: public TableNaming getTableNaming() {
125: return tableNaming;
126: }
127:
128: public void setTableNaming(TableNaming tableNameConverter) {
129: this .tableNaming = tableNameConverter;
130: }
131:
132: public GeneratedPropertySettings getGeneratedPropertySettings() {
133: return generatedPropertySettings;
134: }
135:
136: public ReservedWords getReservedWords() {
137: return reservedWords;
138: }
139:
140: public TableType getTableType() {
141: return tableType;
142: }
143:
144: }
|