001/*license*\ 002 Codelet: Copyright (C) 2014, Jeff Epstein (aliteralmind __DASH__ github __AT__ yahoo __DOT__ com) 003 004 This software is dual-licensed under the: 005 - Lesser General Public License (LGPL) version 3.0 or, at your option, any later version; 006 - Apache Software License (ASL) version 2.0. 007 008 Either license may be applied at your discretion. More information may be found at 009 - http://en.wikipedia.org/wiki/Multi-licensing. 010 011 The text of both licenses is available in the root directory of this project, under the names "LICENSE_lgpl-3.0.txt" and "LICENSE_asl-2.0.txt". The latest copies may be downloaded at: 012 - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt 013 - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt 014\*license*/ 015package com.github.aliteralmind.codelet; 016 import com.github.aliteralmind.codelet.type.ConsoleOutTemplate; 017 import com.github.aliteralmind.codelet.type.FileTextTemplate; 018 import com.github.aliteralmind.codelet.type.OnlyOneBodyGapTemplateBase; 019 import com.github.aliteralmind.codelet.type.SourceAndOutTemplate; 020 import com.github.aliteralmind.codelet.type.SourceCodeTemplate; 021 import com.github.xbn.io.TextAppenter; 022 import com.github.xbn.lang.CrashIfObject; 023 import com.github.xbn.lang.Empty; 024 import com.github.xbn.regexutil.IgnoreCase; 025 import com.github.aliteralmind.templatefeather.FeatherTemplate; 026 import com.github.xbn.text.CharUtil; 027 import com.github.xbn.util.GetBooleanFromString; 028 import com.github.xbn.util.PropertiesUtil; 029 import com.github.xbn.lang.reflect.ReflectRtxUtil; 030 import com.github.xbn.util.tuple.TwoTuple; 031 import java.util.Iterator; 032 import java.util.Properties; 033 import static com.github.aliteralmind.codelet.CodeletBaseConfig.*; 034 import static com.github.xbn.lang.XbnConstants.*; 035/** 036 <p>Loads and manages default templates and user-extra gaps. Loading is executed by {@link com.github.aliteralmind.codelet.CodeletBootstrap}.</p> 037 038 * @since 0.1.0 039 * @author Copyright (C) 2014, Jeff Epstein ({@code aliteralmind __DASH__ github __AT__ yahoo __DOT__ com}), dual-licensed under the LGPL (version 3.0 or later) or the ASL (version 2.0). See source code for details. <a href="http://codelet.aliteralmind.com">{@code http://codelet.aliteralmind.com}</a>, <a href="https://github.com/aliteralmind/codelet">{@code https://github.com/aliteralmind/codelet}</a> 040 **/ 041public enum CodeletTemplateConfig { 042 INSTANCE; 043 private static boolean wasLoaded ; 044 private static SourceCodeTemplate defaultCodeletTmpl ; 045 private static ConsoleOutTemplate defaultConsoleOutTmpl ; 046 private static SourceAndOutTemplate defaultSrcAndOutTmpl ; 047 private static FileTextTemplate defaultFileTextletTmpl; 048 private static UserExtraGapGetter xtraGapGetter ; 049 /** 050 <p>Load configuration and return theh instance. Call only once.</p> 051 052 * @return #INSTANCE 053 * @exception IllegalStateException If 054 <br/> <code>{@link com.github.aliteralmind.codelet.CodeletBaseConfig CodeletBaseConfig}.{@link com.github.aliteralmind.codelet.CodeletBaseConfig#wasLoaded() wasLoaded}</code> 055 <br/>is {@code false}, or {@link #wasLoaded() wasLoaded}{@code ()} is {@code true}. 056 * @exception ClassNotFoundException If 057 <br/> <code>{@link com.github.aliteralmind.codelet.CodeletBaseConfig CodeletBaseConfig}.{@link com.github.aliteralmind.codelet.CodeletBaseConfig#getUserExtraGapsClassName() getUserExtraGapsClassName}()</code> 058 <br/>is non-empty, but does not represent an existing class. 059 * @exception ClassCastException If the class exists, but is not a {@link com.github.aliteralmind.codelet.UserExtraGapGetter}. 060 * @see com.github.xbn.util.PropertiesUtil 061 */ 062 public static final CodeletTemplateConfig loadConfigGetInstance() throws ClassNotFoundException { 063 if(!CodeletBaseConfig.wasLoaded()) { 064 throw new IllegalStateException("wasLoaded() is false."); 065 } 066 if(wasLoaded()) { 067 throw new IllegalStateException("wasLoaded() is true."); 068 } 069 070 boolean doDebug = isDebugOn(null, "zzconfiguration.progress"); 071 072 if(doDebug) { 073 debugln(" Loading template config"); 074 } 075 076 if(getUserExtraGapsClassName().length() == 0) { 077 xtraGapGetter = null; 078 if(doDebug) { 079 debugln(" No user-extra gap getter."); 080 } 081 082 } else { 083 xtraGapGetter = ReflectRtxUtil.<UserExtraGapGetter>getNewInstanceFromNoParamCnstr( 084 getUserExtraGapsClassName(), UserExtraGapGetter.class, 085 getDebugApblIfOn(null, "zzconfiguration.progress")); 086 } 087 088 defaultCodeletTmpl = SourceCodeTemplate.newFromPathAndUserExtraGaps( 089 getDefaultSourceCodeTemplatePath(), 090 DEFAULT_SRC_CODE_TMPL_PATH, xtraGapGetter); 091 092 defaultConsoleOutTmpl = ConsoleOutTemplate.newFromPathAndUserExtraGaps( 093 getDefaultConsoleOutTemplatePath(), 094 DEFAULT_DOT_OUT_TMPL_PATH, xtraGapGetter); 095 096 defaultSrcAndOutTmpl = SourceAndOutTemplate.newFromPathAndUserExtraGaps( 097 getDefaultSourceAndOutTemplatePath(), 098 DEFAULT_AND_OUT_TMPL_PATH, xtraGapGetter); 099 100 defaultFileTextletTmpl = FileTextTemplate.newFromPathAndUserExtraGaps( 101 getDefaultFileTextTemplatePath(), 102 DEFAULT_FILE_TEXT_TMPL_PATH, xtraGapGetter); 103 104 if(doDebug) { 105 debugln(" (Done--ready to load TemplateOverrides)"); 106 } 107 108 wasLoaded = true; 109 110 return INSTANCE; 111 } 112 /** 113 <p>Was configuration loaded?.</p> 114 115 * @return {@code true} If all values loaded successfully. 116 * @see #loadConfigGetInstance() 117 */ 118 public static final boolean wasLoaded() { 119 return wasLoaded; 120 } 121 /** 122 <p>The path to the default template used for (source-code) {@code {@.codelet}} taglets.</p> 123 124 * @see com.github.aliteralmind.codelet.CodeletBaseConfig#DEFAULT_SRC_CODE_TMPL_PATH 125 */ 126 public static final SourceCodeTemplate getDefaultSourceCodeTemplate() { 127 return defaultCodeletTmpl; 128 } 129 /** 130 <p>The path to the default template used for {@code {@.codelet.out}} taglets.</p> 131 132 * @see com.github.aliteralmind.codelet.CodeletBaseConfig#DEFAULT_DOT_OUT_TMPL_PATH 133 */ 134 public static final ConsoleOutTemplate getDefaultConsoleOutTemplate() { 135 return defaultConsoleOutTmpl; 136 } 137 /** 138 <p>The path to the default template used for {@code {@.codelet.and.out}} taglets.</p> 139 140 * @see com.github.aliteralmind.codelet.CodeletBaseConfig#DEFAULT_AND_OUT_TMPL_PATH 141 */ 142 public static final SourceAndOutTemplate getDefaultSourceAndOutTemplate() { 143 return defaultSrcAndOutTmpl; 144 } 145 /** 146 <p>The path to the default template used for {@code {@.file.textlet}} taglets.</p> 147 148 * @see com.github.aliteralmind.codelet.CodeletBaseConfig#DEFAULT_FILE_TEXT_TMPL_PATH 149 */ 150 public static final FileTextTemplate getDefaultFileTextTemplate() { 151 return defaultFileTextletTmpl; 152 } 153 /** 154 <p>The class that defines extra gaps that can be placed in Codelet templates.</p> 155 156 * @see com.github.aliteralmind.codelet.CodeletBaseConfig#USER_EXTRA_GAPS_CLASS_NAME 157 */ 158 public static final UserExtraGapGetter getUserExtraGapsClass() { 159 return xtraGapGetter; 160 } 161}