use of org.dbflute.logic.generate.language.DfLanguageDependency in project dbflute-core by dbflute.
the class DfParameterBeanResolver method resolvePackageNameExceptUtil.
protected String resolvePackageNameExceptUtil(String typeName) {
final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
final DfLanguagePropertyPackageResolver resolver = lang.getLanguagePropertyPackageResolver();
return resolver.resolvePackageNameExceptUtil(typeName);
}
use of org.dbflute.logic.generate.language.DfLanguageDependency in project dbflute-core by dbflute.
the class DfBqpBehaviorFile method writeBehaviorQueryPath.
// ===================================================================================
// Write
// =====
/**
* @param resourceElementMap The map of resource element. (NotNull)
*/
protected void writeBehaviorQueryPath(Map<String, Map<String, String>> resourceElementMap) {
final String encoding = getBasicProperties().getSourceFileEncoding();
final String lineSep = getBasicProperties().getSourceCodeLineSeparator();
final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
final DfLanguageGrammar grammar = lang.getLanguageGrammar();
final String behaviorQueryPathBeginMark = getBasicProperties().getBehaviorQueryPathBeginMark();
final String behaviorQueryPathEndMark = getBasicProperties().getBehaviorQueryPathEndMark();
final DfDocumentProperties docprop = getDocumentProperties();
final StringBuilder sb = new StringBuilder();
String lineString = null;
BufferedReader br = null;
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(_bsbhvFile), encoding));
boolean targetArea = false;
boolean done = false;
while (true) {
lineString = br.readLine();
if (lineString == null) {
if (targetArea) {
String msg = "The end mark of behavior query path was not found: bsbhvFile=" + _bsbhvFile;
throw new IllegalStateException(msg);
}
break;
}
if (targetArea) {
if (lineString.contains(behaviorQueryPathEndMark)) {
targetArea = false;
} else {
continue;
}
}
sb.append(lineString).append(lineSep);
if (!done && lineString.contains(behaviorQueryPathBeginMark)) {
targetArea = true;
final String adjustedIndent = grammar.adjustClassElementIndent(" ");
for (Entry<String, Map<String, String>> entry : resourceElementMap.entrySet()) {
final String behaviorQueryPath = entry.getKey();
final Map<String, String> behaviorQueryElementMap = entry.getValue();
final StringBuilder defSb = new StringBuilder();
final String keyTitle = DfBehaviorQueryPathSetupper.KEY_TITLE;
final String title = behaviorQueryElementMap.get(keyTitle);
if (title != null && title.trim().length() > 0) {
final String comment = buildJavaDocComment(grammar, docprop, title, adjustedIndent);
defSb.append(comment).append(lineSep);
}
defSb.append(adjustedIndent);
defSb.append(grammar.getPublicStaticFinal());
final String keySubDirectoryPath = DfBehaviorQueryPathSetupper.KEY_SUB_DIRECTORY_PATH;
final String subDirectoryPath = behaviorQueryElementMap.get(keySubDirectoryPath);
final String pathJavaNativeType = "String";
defSb.append(" ");
if (Srl.is_NotNull_and_NotTrimmedEmpty(subDirectoryPath)) {
final String subDirectoryName = Srl.replace(subDirectoryPath, "/", "_");
final String subDirectoryValue = Srl.replace(subDirectoryPath, "/", ":");
String variable = "PATH_" + subDirectoryName + "_" + behaviorQueryPath;
defSb.append(grammar.buildVariableSimpleDefinition(pathJavaNativeType, variable));
defSb.append(" = \"");
defSb.append(subDirectoryValue).append(":").append(behaviorQueryPath);
defSb.append("\";");
} else {
String variable = "PATH_" + behaviorQueryPath;
defSb.append(grammar.buildVariableSimpleDefinition(pathJavaNativeType, variable));
defSb.append(" = \"").append(behaviorQueryPath).append("\";");
}
defSb.append(lineSep);
sb.append(defSb);
}
done = true;
}
}
if (!done) {
_log.warn("*The mark of behavior query path was not found: " + _bsbhvFile);
}
} catch (IOException e) {
String msg = "BufferedReader.readLine() threw the exception: current line=" + lineString;
throw new IllegalStateException(msg, e);
} finally {
if (br != null) {
try {
br.close();
} catch (IOException ignored) {
_log.warn(ignored.getMessage());
}
}
}
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(_bsbhvFile), encoding));
bw.write(sb.toString());
bw.flush();
} catch (UnsupportedEncodingException e) {
String msg = "The encoding is unsupported: encoding=" + encoding;
throw new IllegalStateException(msg, e);
} catch (FileNotFoundException e) {
String msg = "The file of base behavior was not found: bsbhvFile=" + _bsbhvFile;
throw new IllegalStateException(msg, e);
} catch (IOException e) {
String msg = "BufferedWriter.write() threw the exception: bsbhvFile=" + _bsbhvFile;
throw new IllegalStateException(msg, e);
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException ignored) {
_log.warn(ignored.getMessage());
}
}
}
}
use of org.dbflute.logic.generate.language.DfLanguageDependency in project dbflute-core by dbflute.
the class DfPmbMetaData method adjustPropertyMetaFinally.
// ===================================================================================
// Adjustment
// ==========
public void adjustPropertyMetaFinally(AppData schemaData) {
// basically this adjusts property types for auto-detected properties
// it should be called after initialization
// (not called by procedure)
final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
final DfLanguagePropertyPackageResolver packageResolver = lang.getLanguagePropertyPackageResolver();
final Set<String> autoDetectedPropertyNameSet = getAutoDetectedPropertyNameSet();
if (autoDetectedPropertyNameSet == null || autoDetectedPropertyNameSet.isEmpty()) {
return;
}
final Map<String, String> propertyNameTypeMap = getPropertyNameTypeMap();
for (String propertyName : autoDetectedPropertyNameSet) {
// loop for auto-detected properties
final String beforeType = propertyNameTypeMap.get(propertyName);
String afterType = null;
if (isPropertyTypeList(propertyName) && isPropertyOptionClassification(propertyName, schemaData)) {
// list and classification option
final String classificationName = getPropertyOptionClassificationName(propertyName, schemaData);
final String plainType = "$$CDef$$." + classificationName;
// ParameterBean has the "import" clause of language-embedded utility
afterType = packageResolver.resolvePackageNameExceptUtil(plainType);
} else if (!beforeType.contains("CDef")) {
final Column refColumn = getPropertyOptionReferenceColumn(propertyName, schemaData);
if (refColumn != null) {
// not CDef and reference
afterType = refColumn.getJavaNative();
final String utilPrefix = "java.util.";
if (Srl.startsWith(afterType, utilPrefix) && Srl.count(afterType, ".") == 2) {
// ParameterBean has the "import" clause of language-embedded utility
afterType = Srl.substringFirstRear(afterType, utilPrefix);
}
}
}
if (afterType != null) {
final String finalType;
if (isPropertyTypeList(propertyName)) {
final DfLanguageGrammar grammar = getLanguageGrammar();
final String beginMark = grammar.getGenericBeginMark();
final String endMark = grammar.getGenericEndMark();
final String prefix = Srl.substringFirstFront(beforeType, "List" + beginMark);
final String suffix = Srl.substringLastRear(beforeType, endMark);
finalType = prefix + "List" + beginMark + afterType + endMark + suffix;
} else {
finalType = afterType;
}
// override
propertyNameTypeMap.put(propertyName, finalType);
}
}
}
use of org.dbflute.logic.generate.language.DfLanguageDependency in project dbflute-core by dbflute.
the class DfBasicProperties method getLanguageDependency.
public DfLanguageDependency getLanguageDependency() {
if (_languageDependency != null) {
return _languageDependency;
}
final DfLanguageDependency lang;
if (isTargetLanguageJava()) {
lang = new DfLanguageDependencyJava();
} else if (isTargetLanguageCSharp()) {
lang = new DfLanguageDependencyCSharp();
} else if (isTargetLanguagePhp()) {
lang = new DfLanguageDependencyPhp();
} else if (isTargetLanguageScala()) {
lang = new DfLanguageDependencyScala();
} else {
String msg = "The language is unsupported: " + getTargetLanguage();
throw new IllegalStateException(msg);
}
_languageDependency = lang;
return _languageDependency;
}
use of org.dbflute.logic.generate.language.DfLanguageDependency in project dbflute-core by dbflute.
the class DfBasicProperties method checkDirectoryPackage.
public void checkDirectoryPackage() {
final String flatDirectoryPackage = getFlatDirectoryPackage();
final String omitDirectoryPackage = getOmitDirectoryPackage();
if (flatDirectoryPackage == null && omitDirectoryPackage == null) {
return;
}
final DfLanguageDependency languageDependencyInfo = getBasicProperties().getLanguageDependency();
if (!languageDependencyInfo.isFlatOrOmitDirectorySupported()) {
String msg = "The language does not support flatDirectoryPackage or omitDirectoryPackage:";
msg = msg + " language=" + getBasicProperties().getTargetLanguage();
throw new IllegalStateException(msg);
}
}
Aggregations