Search in sources :

Example 6 with DfLanguageDependency

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);
}
Also used : DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) DfLanguagePropertyPackageResolver(org.dbflute.logic.generate.language.pkgstyle.DfLanguagePropertyPackageResolver)

Example 7 with DfLanguageDependency

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());
            }
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) BufferedReader(java.io.BufferedReader) OutputStreamWriter(java.io.OutputStreamWriter) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) DfDocumentProperties(org.dbflute.properties.DfDocumentProperties) Map(java.util.Map)

Example 8 with DfLanguageDependency

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);
        }
    }
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfLanguageGrammar(org.dbflute.logic.generate.language.grammar.DfLanguageGrammar) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) DfLanguagePropertyPackageResolver(org.dbflute.logic.generate.language.pkgstyle.DfLanguagePropertyPackageResolver)

Example 9 with DfLanguageDependency

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;
}
Also used : DfLanguageDependencyPhp(org.dbflute.logic.generate.language.DfLanguageDependencyPhp) DfLanguageDependencyScala(org.dbflute.logic.generate.language.DfLanguageDependencyScala) DfLanguageDependencyCSharp(org.dbflute.logic.generate.language.DfLanguageDependencyCSharp) DfLanguageDependencyJava(org.dbflute.logic.generate.language.DfLanguageDependencyJava) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency)

Example 10 with DfLanguageDependency

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);
    }
}
Also used : DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency)

Aggregations

DfLanguageDependency (org.dbflute.logic.generate.language.DfLanguageDependency)26 DfLanguagePropertyPackageResolver (org.dbflute.logic.generate.language.pkgstyle.DfLanguagePropertyPackageResolver)7 Column (org.apache.torque.engine.database.model.Column)4 Map (java.util.Map)3 DfLanguageGrammar (org.dbflute.logic.generate.language.grammar.DfLanguageGrammar)3 DfLanguageImplStyle (org.dbflute.logic.generate.language.implstyle.DfLanguageImplStyle)3 DfLanguageClassPackage (org.dbflute.logic.generate.language.pkgstyle.DfLanguageClassPackage)3 DfBasicProperties (org.dbflute.properties.DfBasicProperties)3 FileNotFoundException (java.io.FileNotFoundException)2 DfLittleAdjustmentProperties (org.dbflute.properties.DfLittleAdjustmentProperties)2 BufferedReader (java.io.BufferedReader)1 BufferedWriter (java.io.BufferedWriter)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1