Search in sources :

Example 1 with DfRefClsElement

use of org.dbflute.properties.assistant.classification.refcls.DfRefClsElement in project dbflute-core by dbflute.

the class DfAppClsTableLoader method loadTable.

// ===================================================================================
// Load Table
// ==========
// ; resourceMap = map:{
// ; baseDir = ../src/main
// ; resourceType = APP_CLS
// ; resourceFile = ../../../dockside_appcls.properties
// }
// ; outputMap = map:{
// ; templateFile = LaAppCDef.vm
// ; outputDirectory = $$baseDir$$/java
// ; package = org.dbflute...
// ; className = unused
// }
// ; optionMap = map:{
// }
@Override
public DfFreeGenMetaData loadTable(String requestName, DfFreeGenResource resource, DfFreeGenMapProp mapProp) {
    final String resourceFile = resource.getResourceFile();
    final Map<String, Object> appClsMap = readAppClsMap(resourceFile);
    boolean hasRefCls = false;
    final DfClassificationProperties clsProp = getClassificationProperties();
    final DfClsElementLiteralArranger literalArranger = new DfClsElementLiteralArranger();
    final List<DfClassificationTop> topList = new ArrayList<DfClassificationTop>();
    for (Entry<String, Object> entry : appClsMap.entrySet()) {
        final String classificationName = entry.getKey();
        final DfClassificationTop classificationTop = new DfClassificationTop(classificationName);
        topList.add(classificationTop);
        DfRefClsElement refClsElement = null;
        @SuppressWarnings("unchecked") final List<Map<String, Object>> elementMapList = (List<Map<String, Object>>) entry.getValue();
        for (Map<String, Object> elementMap : elementMapList) {
            if (isElementMapTop(elementMap)) {
                // e.g. map:{ topComment=... ; codeType=String }
                classificationTop.acceptBasicItem(elementMap);
                classificationTop.putGroupingAll(clsProp.getElementMapGroupingMap(elementMap));
                classificationTop.putDeprecatedAll(clsProp.getElementMapDeprecatedMap(elementMap));
            } else {
                if (isElementMapRefCls(elementMap)) {
                    // e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
                    refClsElement = arrangeRefCls(resource, classificationName, classificationTop, refClsElement, elementMap);
                } else {
                    // e.g. map:{ code=FML ; name=OneMan ; alias=ShowBase ; comment=Formalized }
                    arrangeLiteral(resource, classificationName, classificationTop, refClsElement, elementMap, literalArranger);
                }
            }
        }
        if (refClsElement != null) {
            // should be after all literal evaluation
            inheritRefClsGroup(classificationTop, refClsElement);
            refClsElement.verifyRelationshipByRefTypeIfNeeds(classificationTop);
            hasRefCls = true;
        }
    }
    final Map<String, Object> optionMap = mapProp.getOptionMap();
    // basically exists
    final String clsTheme = (String) optionMap.getOrDefault("clsTheme", getDefaultClsTheme());
    setupOptionMap(optionMap, topList, hasRefCls, clsTheme);
    // @since 1.2.5
    stopRedundantCommentIfNeeds(requestName, resourceFile, topList, optionMap);
    // for next appcls's refCls @since 1.2.5
    registerRefClsReference(requestName, clsTheme, topList, optionMap);
    // #for_now can be flexible? (table name is unused?)
    return DfFreeGenMetaData.asOnlyOne(optionMap, clsTheme, Collections.emptyList());
}
Also used : ArrayList(java.util.ArrayList) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement) DfClsElementLiteralArranger(org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) DfClassificationProperties(org.dbflute.properties.DfClassificationProperties)

Example 2 with DfRefClsElement

use of org.dbflute.properties.assistant.classification.refcls.DfRefClsElement in project dbflute-core by dbflute.

the class DfRefClsLoadingHandler method prepareImportedReferredCDefFqcnList.

// ===================================================================================
// Referred CDef
// =============
public List<String> prepareImportedReferredCDefFqcnList(List<DfClassificationTop> topList, Map<String, Object> optionMap) {
    // null allowed, as best effort way
    final String currentCDefPackage = extractCDefPackage(optionMap);
    final Map<String, String> refThemeCDefFqcnMap = new LinkedHashMap<String, String>();
    for (DfClassificationTop top : topList) {
        final List<DfRefClsElement> refClsElementList = top.getRefClsElementList();
        for (DfRefClsElement refClsElement : refClsElementList) {
            final String refClsTheme = refClsElement.getRefClsTheme();
            final String existingImportExp = refThemeCDefFqcnMap.get(refClsTheme);
            if (existingImportExp != null) {
                break;
            }
            final String referredCDefPackage = refClsElement.getReferredCDefPackage();
            if (currentCDefPackage != null && currentCDefPackage.equals(referredCDefPackage)) {
                // same-package import statement is unneeded (to avoid Eclipse warning) e.g. namedcls to namedcls
                continue;
            }
            final String referredCDefClassName = refClsElement.getReferredCDefClassName();
            final String refThemeCDefFqcn = referredCDefPackage + "." + referredCDefClassName;
            refThemeCDefFqcnMap.put(refClsTheme, refThemeCDefFqcn);
        }
    }
    return new ArrayList<>(refThemeCDefFqcnMap.values());
}
Also used : DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) ArrayList(java.util.ArrayList) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with DfRefClsElement

use of org.dbflute.properties.assistant.classification.refcls.DfRefClsElement in project dbflute-core by dbflute.

the class DfRefClsLoadingHandler method createRefClsElement.

public DfRefClsElement createRefClsElement(String classificationName, Map<String, Object> elementMap, DfFreeGenResource resource) {
    // e.g. map:{ refCls=maihamadb@MemberStatus ; refType=included }
    final String refAttr = (String) elementMap.get(DfRefClsElement.KEY_REFCLS);
    // of e.g. DB or "appcls" or namedcls's name
    final String refClsTheme;
    // classification name
    final String refClsName;
    final String refGroupName;
    if (refAttr.contains("@")) {
        // #hope other schema's reference
        refClsTheme = Srl.substringFirstFront(refAttr, "@");
        final String rearName = Srl.substringFirstRear(refAttr, "@");
        if (rearName.contains(".")) {
            refClsName = Srl.substringFirstFront(rearName, ".");
            refGroupName = Srl.substringFirstRear(rearName, ".");
        } else {
            refClsName = rearName;
            refGroupName = null;
        }
    } else {
        // current DB as default
        refClsTheme = getBasicProperties().getProjectName();
        if (refAttr.contains(".")) {
            refClsName = Srl.substringFirstFront(refAttr, ".");
            refGroupName = Srl.substringFirstRear(refAttr, ".");
        } else {
            refClsName = refAttr;
            refGroupName = null;
        }
    }
    final String refType = extractRefType(classificationName, elementMap);
    final DfClassificationTop referredClsTop = findReferredClsTop(classificationName, refAttr, refClsTheme, refClsName, resource);
    final DfRefClsReferredCDef referredCDef = findReferredCDef(classificationName, refAttr, refClsTheme, refClsName, resource);
    final DfClassificationGroup referredGroup = findReferredGroup(classificationName, refAttr, refClsTheme, refClsName, refGroupName, referredClsTop, resource);
    final String resourceFile = resource.getResourceFile();
    return new DfRefClsElement(refClsTheme, refClsName, refGroupName, refType, referredClsTop, referredCDef, referredGroup, resourceFile);
}
Also used : DfClassificationGroup(org.dbflute.properties.assistant.classification.DfClassificationGroup) DfClassificationTop(org.dbflute.properties.assistant.classification.DfClassificationTop) DfRefClsReferredCDef(org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef) DfRefClsElement(org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)

Aggregations

DfClassificationTop (org.dbflute.properties.assistant.classification.DfClassificationTop)3 DfRefClsElement (org.dbflute.properties.assistant.classification.refcls.DfRefClsElement)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 DfClassificationProperties (org.dbflute.properties.DfClassificationProperties)1 DfClassificationGroup (org.dbflute.properties.assistant.classification.DfClassificationGroup)1 DfClsElementLiteralArranger (org.dbflute.properties.assistant.classification.element.proploading.DfClsElementLiteralArranger)1 DfRefClsReferredCDef (org.dbflute.properties.assistant.classification.refcls.DfRefClsReferredCDef)1