use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.
the class DfPmbMetaData method getPropertyOptionClassificationFixedElementValueExp.
public String getPropertyOptionClassificationFixedElementValueExp(String propertyName) {
if (!isPropertyOptionClassificationFixedElement(propertyName)) {
// no way
return null;
}
final String classificationName = getPropertyOptionSpecifiedClassificationName(propertyName);
if (isPropertyTypeList(propertyName)) {
final List<String> elementList = DfCollectionUtil.newArrayList();
if (isPropertyOptionClassificationFixedElementList(propertyName)) {
final List<String> fixedElementList = getPropertyOptionClassificationFixedElementList(propertyName);
for (String fixedElement : fixedElementList) {
final String valueExp = buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
elementList.add(valueExp);
}
} else {
// property is list but specified one
final String fixedElement = getPropertyOptionClassificationFixedElement(propertyName);
final String valueExp = buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
elementList.add(valueExp);
}
final DfLanguageGrammar grammar = getLanguageGrammar();
return grammar.buildOneLinerListNewBackStage(elementList);
} else {
if (isPropertyOptionClassificationFixedElementList(propertyName)) {
final ExceptionMessageBuilder br = new ExceptionMessageBuilder();
br.addNotice("Not list property but classification fixed element list.");
br.addItem("ParameterBean");
br.addElement(getClassName());
br.addItem("Property");
br.addElement(getPropertyType(propertyName) + " " + propertyName);
br.addItem("Classification");
br.addElement(classificationName);
final List<String> fixedElementList = getPropertyOptionClassificationFixedElementList(propertyName);
br.addItem("Element List");
br.addElement(fixedElementList);
final String msg = br.buildExceptionMessage();
throw new IllegalStateException(msg);
}
final String fixedElement = getPropertyOptionClassificationFixedElement(propertyName);
return buildPropertyOptionClassificationElementValueExp(propertyName, classificationName, fixedElement);
}
}
use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar in project dbflute-core by dbflute.
the class DfParameterAutoDetectAssist method doDerivePropertyTypeFromTestValue.
protected String doDerivePropertyTypeFromTestValue(String testValue) {
// test point
if (testValue == null) {
String msg = "The argument 'testValue' should be not null.";
throw new IllegalArgumentException(msg);
}
final DfLanguageGrammar grammar = getLanguageGrammar();
final String plainTypeName;
if (Srl.startsWithIgnoreCase(testValue, "date '", "date'")) {
plainTypeName = "Date";
} else if (Srl.startsWithIgnoreCase(testValue, "timestamp '", "timestamp'")) {
plainTypeName = "Timestamp";
} else if (Srl.startsWithIgnoreCase(testValue, "time '", "time'")) {
plainTypeName = "Time";
} else {
if (Srl.isQuotedSingle(testValue)) {
final String unquoted = Srl.unquoteSingle(testValue);
Timestamp timestamp = null;
Time time = null;
try {
timestamp = DfTypeUtil.toTimestamp(unquoted);
} catch (ParseTimestampException ignored) {
try {
time = DfTypeUtil.toTime(unquoted);
} catch (ParseTimeException andIgnored) {
}
}
if (timestamp != null) {
final String timeParts = DfTypeUtil.toString(timestamp, "HH:mm:ss.SSS");
if (timeParts.equals("00:00:00.000")) {
plainTypeName = "Date";
} else {
plainTypeName = "Timestamp";
}
} else if (time != null) {
plainTypeName = "Time";
} else {
plainTypeName = "String";
}
} else if (Srl.isQuotedAnything(testValue, "(", ")")) {
final String unquoted = Srl.unquoteAnything(testValue, "(", ")");
final List<String> elementList = Srl.splitListTrimmed(unquoted, ",");
if (elementList.size() > 0) {
final String firstElement = elementList.get(0);
// InScope for Date is unsupported at this analyzing
if (Srl.isQuotedSingle(firstElement)) {
plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
} else {
final String elementType = doDeriveNonQuotedLiteralTypeFromTestValue(firstElement);
plainTypeName = "List" + grammar.buildGenericOneClassHint(elementType);
}
} else {
plainTypeName = "List" + grammar.buildGenericOneClassHint("String");
}
} else {
plainTypeName = doDeriveNonQuotedLiteralTypeFromTestValue(testValue);
}
}
return plainTypeName;
}
use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar 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.grammar.DfLanguageGrammar in project dbflute-core by dbflute.
the class DfPmbMetaData method getPropertyTypeOfListElement.
public String getPropertyTypeOfListElement(String propertyName) {
if (!isPropertyTypeList(propertyName)) {
return null;
}
final String propertyType = getPropertyType(propertyName);
final DfLanguageGrammar grammar = getLanguageGrammar();
return grammar.extractGenericClassElement("List", propertyType);
}
use of org.dbflute.logic.generate.language.grammar.DfLanguageGrammar 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)) {
if (isPropertyOptionClassificationFixedElement(propertyName)) {
// :cls(Maihama.Sea) or :cls(Maihama.Sea, Land)
// e.g. /*pmb.maihamaList:cls(Maihama.Sea)*/ or /*pmb.maihamaList:cls(Maihama.Sea, Land)*/
// no adjustment because fixed element list needs List<String> as framework-internal property
} else {
// list property by public setter, wants to be e.g. List<CDef.Maihama>
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);
}
}
}
Aggregations