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());
}
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());
}
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);
}
Aggregations