private ConversionDefEntry conversionDefFromList(final List<String> list)
throws ConversionException {
final int listSize = list.size();
if (listSize < 3) {
throw new ConversionException("too less elements " + listSize);
}
final String[] elts = new String[listSize];
list.toArray(elts);
final int oldIdentifier = computeIdentifier(elts[0]);
try {
fieldDefParser.parse(elts[1]);
} catch (ConversionException exception) {
throw new ConversionException(
"bad original class/field definition \"" + elts[1],
exception);
}
final String originalClassName = fieldDefParser.getClassName();
if (originalClassName == null) {
throw new ConversionException(
"bad original class/field definition \"" + elts[1]);
}
final ClassInfo originalClass = classForName(originalClassName);
final String originalFieldName = fieldDefParser.getFieldName();
final int originalFieldIndex = fieldDefParser.getFieldIndex();
final String originalFieldClassName = normalizeClassName(fieldDefParser
.getFieldClassName());
final String originalFieldDeclaringClassName = fieldDefParser
.getFieldDeclaringClassName();
final Boolean originalStaticField = fieldDefParser.getStaticField();
final Boolean originalTransientField = fieldDefParser
.getTransientField();
final ConversionDefEntry conversionDefEntry;
if ("*".equals(originalFieldName)) {
/*
* list of class's fields
*/
final int toIdentifier = computeIdentifier(elts[2]);
conversionDefEntry = new ConversionDefEntry(originalClass,
oldIdentifier, toIdentifier);
for (int fieldDefIndex = 3; fieldDefIndex < elts.length; fieldDefIndex++) {
try {
fieldDefParser.parse(elts[fieldDefIndex]);
} catch (ConversionException exception) {
throw new ConversionException("bad field definition \""
+ elts[fieldDefIndex] + "\"", exception);
}
if (fieldDefParser.getClassName() != null) {
throw new ConversionException("bad field definition \""
+ elts[fieldDefIndex] + "\"");
}
final String fieldClassName = normalizeClassName(fieldDefParser
.getFieldClassName());
final Boolean staticField = fieldDefParser.getStaticField();
final Boolean transientField = fieldDefParser
.getTransientField();
final String declaringClassName = fieldDefParser
.getFieldDeclaringClassName();
final String fieldName = fieldDefParser.getFieldName();
final int fieldIndex = fieldDefParser.getFieldIndex();
if (fieldIndex != -1) {
throw new ConversionException(
"bad field definition, must not have field index declaration \""
+ elts[fieldDefIndex]);
}
final ClassInfo fieldClass = classForName(fieldClassName);
final ClassInfo declaringClass = classForName(declaringClassName);
FieldInfo fieldInfo;
try {
// FIXMELUC ______known field
fieldInfo = new FieldInfo(declaringClass, fieldName,// NOPMD
fieldClass, staticField, transientField);
} catch (ClassInfoException exception) {
throw new ConversionException("bad field definition \""
+ elts[fieldDefIndex], exception);
}
conversionDefEntry.addToFieldList(fieldInfo);
}
} else {
/*
* replacement definition
*/
if (listSize < 3 || listSize > 5) {// NOPMD
throw new ConversionException("3 thru 5 elements expected for "
+ listSize + " get");
} else {
final int toIdentifier = computeIdentifier(elts[2]);
if (listSize == 3) {
conversionDefEntry = new ConversionDefEntry(originalClass,
oldIdentifier, ClassInfo.NULL, toIdentifier,
ClassInfo.NULL, ClassInfo.NULL);
} else {
final ClassInfo converterClass;
final ClassInfo staticConverterClass;
if (listSize == 5) {
final String[] converterClassDef = elts[4].split(":");
if (converterClassDef.length == 1) {
converterClass = classForName(converterClassDef[0]);
staticConverterClass = ClassInfo.NULL;
} else if (converterClassDef.length == 2
&& "static".equals(converterClassDef[0])) {
staticConverterClass = classForName(converterClassDef[1]);
converterClass = ClassInfo.NULL;
} else {
throw new ConversionException(
"bad conversion class declaration \""
+ elts[4] + "\"");
}
} else {
converterClass = ClassInfo.NULL;
staticConverterClass = ClassInfo.NULL;
}
try {
fieldDefParser.parse(elts[3]);
} catch (ConversionException exception) {
throw new ConversionException(
"bad replacemet class/field definition \""
+ elts[3] + "\"", exception);
}
final String replacementClassName = fieldDefParser
.getClassName();
if (replacementClassName == null) {
throw new ConversionException(
"bad replacement class/field definition \""
+ elts[3] + "\"");
}
final String replacementFieldName = fieldDefParser
.getFieldName();
final int replacementFieldIndex = fieldDefParser
.getFieldIndex();
final String replacementFieldClassName = normalizeClassName(fieldDefParser
.getFieldClassName());
final String replacementFieldDeclaringClassName = fieldDefParser
.getFieldDeclaringClassName();
final Boolean replacementStaticField = fieldDefParser
.getStaticField();
final Boolean replacementTransientField = fieldDefParser
.getTransientField();
final ClassInfo replacementFieldDeclaringClass;
final ClassInfo replacementClass = classForName(replacementClassName);
if (replacementFieldDeclaringClassName == null) {
replacementFieldDeclaringClass = replacementClass;
} else {
replacementFieldDeclaringClass = classForName(replacementFieldDeclaringClassName);
}
if (originalFieldName == null) {
conversionDefEntry = new ConversionDefEntry(
originalClass, oldIdentifier, replacementClass,
toIdentifier, converterClass,
staticConverterClass);
} else {
final ClassInfo originalFieldDeclaringClass;
if (originalFieldDeclaringClassName == null) {
originalFieldDeclaringClass = originalClass;
} else {
originalFieldDeclaringClass = classForName(originalFieldDeclaringClassName);
}
final ClassInfo originalFieldType;
if (originalFieldClassName == null) {
originalFieldType = ClassInfo.NULL;
} else {
originalFieldType = classForName(originalFieldClassName);
}
final FieldInfo originalFieldInfo;
try {
originalFieldInfo = new FieldInfo(
originalFieldDeclaringClass,
originalFieldName, originalFieldType,
originalStaticField, originalTransientField);
} catch (ClassInfoException exception) {
throw new ConversionException(
"bad replacement class \"" + elts[1] + "\"",
exception);
}
try {
final FieldInfo replacementFieldInfo;
if (replacementFieldName == null) {
replacementFieldInfo = null;
} else {
final ClassInfo replacementFieldType;
if (replacementFieldClassName == null) {
throw new ConversionException(
"bad replacement class/field type must be defined \""
+ elts[3] + "\"");
} else {
replacementFieldType = classForName(replacementFieldClassName);
}
replacementFieldInfo = new FieldInfo(
replacementFieldDeclaringClass,
replacementFieldName,
replacementFieldType,
replacementStaticField,
replacementTransientField);
}
conversionDefEntry = new ConversionDefEntry(
originalClass, oldIdentifier,
replacementClass, toIdentifier,
originalFieldInfo, originalFieldIndex,
replacementFieldInfo, replacementFieldIndex);
} catch (ClassInfoException exception) {
throw new ConversionException(
"bad replacement class \"" + elts[3] + "\"",
exception);
}
}
}