Project

General

Profile

« Previous | Next » 

Revision e6d7b501

Added by Andreas Müller almost 7 years ago

ref #6368 remove TaxonNameBase subclasses

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/strategy/parser/NonViralNameParserImpl.java
27 27
import eu.etaxonomy.cdm.model.common.CdmBase;
28 28
import eu.etaxonomy.cdm.model.common.IParsable;
29 29
import eu.etaxonomy.cdm.model.common.TimePeriod;
30
import eu.etaxonomy.cdm.model.name.BotanicalName;
31
import eu.etaxonomy.cdm.model.name.CultivarPlantName;
32 30
import eu.etaxonomy.cdm.model.name.HybridRelationship;
33 31
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
32
import eu.etaxonomy.cdm.model.name.IBotanicalName;
33
import eu.etaxonomy.cdm.model.name.ICultivarPlantName;
34 34
import eu.etaxonomy.cdm.model.name.INonViralName;
35 35
import eu.etaxonomy.cdm.model.name.IZoologicalName;
36 36
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
37 37
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
38 38
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
39
import eu.etaxonomy.cdm.model.name.NonViralName;
40 39
import eu.etaxonomy.cdm.model.name.Rank;
41 40
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
42 41
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
43
import eu.etaxonomy.cdm.model.name.ZoologicalName;
44 42
import eu.etaxonomy.cdm.model.reference.IBook;
45 43
import eu.etaxonomy.cdm.model.reference.IBookSection;
46 44
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
......
138 136
	}
139 137

  
140 138
	@Override
141
    public NonViralName parseReferencedName(String fullReferenceString) {
139
    public TaxonNameBase parseReferencedName(String fullReferenceString) {
142 140
		return parseReferencedName(fullReferenceString, null, null);
143 141
	}
144 142

  
145 143
	@Override
146
    public NonViralName parseReferencedName(String fullReferenceString, NomenclaturalCode nomCode, Rank rank) {
144
    public TaxonNameBase parseReferencedName(String fullReferenceString, NomenclaturalCode nomCode, Rank rank) {
147 145
		if (fullReferenceString == null){
148 146
			return null;
149 147
		}else{
150
			INonViralName result = getNonViralNameInstance(fullReferenceString, nomCode, rank);
148
		    INonViralName result = getNonViralNameInstance(fullReferenceString, nomCode, rank);
151 149
			parseReferencedName(result, fullReferenceString, rank, MAKE_EMPTY);
152
			return (NonViralName)result;
150
			return TaxonNameBase.castAndDeproxy(result);
153 151
		}
154 152
	}
155 153

  
......
177 175
	 */
178 176
	private String getCodeSpecificFullNameRegEx(INonViralName nameToBeFilledOrig){
179 177
	    INonViralName nameToBeFilled = CdmBase.deproxy(nameToBeFilledOrig);
180
		if (nameToBeFilled instanceof ZoologicalName){
178
		if (nameToBeFilled.isZoological()){
181 179
			return anyZooFullName;
182
		}else if (nameToBeFilled instanceof BotanicalName) {
180
		}else if (nameToBeFilled.isBotanical()) {
183 181
			return anyBotanicFullName;
184
		}else if (nameToBeFilled instanceof NonViralName) {
182
		}else if (nameToBeFilled.isNonViral()) {
185 183
			return anyBotanicFullName;  //TODO ?
186 184
		}else{
187 185
			logger.warn("nameToBeFilled class not supported ("+nameToBeFilled.getClass()+")");
......
197 195
	private String getCodeSpecificSimpleNameRegEx(INonViralName nameToBeFilled){
198 196
		nameToBeFilled = CdmBase.deproxy(nameToBeFilled);
199 197

  
200
		if (nameToBeFilled instanceof ZoologicalName){
198
		if (nameToBeFilled.isZoological()){
201 199
			return anyZooName;
202
		}else if (nameToBeFilled instanceof NonViralName){
200
		}else if (nameToBeFilled.isBotanical()) {
201
		    return anyBotanicName;
202
		}else if (nameToBeFilled.isNonViral()){
203 203
			return anyZooName;  //TODO ?
204
		}else if (nameToBeFilled instanceof BotanicalName) {
205
			return anyBotanicName;
206 204
		}else{
207 205
			logger.warn("nameToBeFilled class not supported ("+nameToBeFilled.getClass()+")");
208 206
			return null;
......
329 327
	    nameToBeFilled.setProblemEnds(oldProblemEnds);
330 328

  
331 329
		//zoological new combinations should not have a nom. reference to be parsed
332
	    if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
333
			IZoologicalName zooName = CdmBase.deproxy(nameToBeFilled, ZoologicalName.class);
330
	    if (nameToBeFilled.isZoological()){
331
			IZoologicalName zooName = (IZoologicalName)CdmBase.deproxy(nameToBeFilled);
334 332
			//is name new combination?
335 333
			if (zooName.getBasionymAuthorship() != null || zooName.getOriginalPublicationYear() != null){
336 334
				ParserProblem parserProblem = ParserProblem.NewCombinationHasPublication;
......
460 458
			strReference = strReference.substring(0, strReference.length() - yearPart.length());
461 459
			yearPart = yearPart.replaceFirst(pStart + yearSeperator, "").trim();
462 460
		}else{
463
			if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
464
				IZoologicalName zooName = CdmBase.deproxy(nameToBeFilled, ZoologicalName.class);
461
			if (nameToBeFilled.isZoological()){
462
				IZoologicalName zooName = (IZoologicalName)CdmBase.deproxy(nameToBeFilled);
465 463
				yearPart = String.valueOf(zooName.getPublicationYear());
466 464
				//continue
467 465
			}else{
......
1141 1139
	 */
1142 1140
	@Override
1143 1141
	public void parseAuthors(INonViralName nonViralNameOrig, String authorString) throws StringNotParsableException{
1144
	    INonViralName nonViralName = nonViralNameOrig;
1142
	    INonViralName nonViralName = CdmBase.deproxy(nonViralNameOrig);
1145 1143
	    TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
1146 1144
		Integer[] years = new Integer[4];
1147
		Class<? extends INonViralName> clazz = nonViralName.getClass();
1148
		fullAuthors(authorString, authors, years, clazz);
1145
		NomenclaturalCode code = nonViralName.getNameType();
1146
		fullAuthors(authorString, authors, years, code);
1149 1147
		nonViralName.setCombinationAuthorship(authors[0]);
1150 1148
		nonViralName.setExCombinationAuthorship(authors[1]);
1151 1149
		nonViralName.setBasionymAuthorship(authors[2]);
1152 1150
		nonViralName.setExBasionymAuthorship(authors[3]);
1153
		if (nonViralName instanceof ZoologicalName){
1154
			IZoologicalName zooName = CdmBase.deproxy(nonViralName, ZoologicalName.class);
1151
		if (nonViralName.isZoological()){
1152
			IZoologicalName zooName = (IZoologicalName)nonViralName;
1155 1153
			zooName.setPublicationYear(years[0]);
1156 1154
			zooName.setOriginalPublicationYear(years[2]);
1157 1155
		}
......
1166 1164
	    TeamOrPersonBase<?>[] authors = new TeamOrPersonBase[4];
1167 1165
		Integer[] years = new Integer[4];
1168 1166
		try {
1169
			Class<? extends INonViralName> clazz = nameToBeFilled.getClass();
1170
			fullAuthors(authorString, authors, years, clazz);
1167
			NomenclaturalCode code = nameToBeFilled.getNameType();
1168
			fullAuthors(authorString, authors, years, code);
1171 1169
		} catch (StringNotParsableException e) {
1172 1170
			nameToBeFilled.addParsingProblem(ParserProblem.UnparsableAuthorPart);
1173 1171
			nameToBeFilled.setTitleCache(fullNameString, true);
1174 1172
			// FIXME Quick fix, otherwise search would not deliver results for unparsable names
1175 1173
			nameToBeFilled.setNameCache(fullNameString, true);
1176 1174
			// END
1177
			logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");;
1175
			logger.info("no applicable parsing rule could be found for \"" + fullNameString + "\"");
1178 1176
		}
1179 1177
		nameToBeFilled.setCombinationAuthorship(authors[0]);
1180 1178
		nameToBeFilled.setExCombinationAuthorship(authors[1]);
1181 1179
		nameToBeFilled.setBasionymAuthorship(authors[2]);
1182 1180
		nameToBeFilled.setExBasionymAuthorship(authors[3]);
1183
		if (nameToBeFilled instanceof ZoologicalName){
1184
			IZoologicalName zooName = (ZoologicalName)nameToBeFilled;
1181
		if (nameToBeFilled.isZoological()){
1182
			IZoologicalName zooName = (IZoologicalName)nameToBeFilled;
1185 1183
			zooName.setPublicationYear(years[0]);
1186 1184
			zooName.setOriginalPublicationYear(years[2]);
1187 1185
		}
......
1194 1192
	 */
1195 1193
	private Rank guessUninomialRank(INonViralName nameToBeFilled, String uninomial) {
1196 1194
		Rank result = Rank.GENUS();
1197
		if (nameToBeFilled.isInstanceOf(BotanicalName.class)){
1195
		if (nameToBeFilled.isBotanical()){
1198 1196
			if (false){
1199 1197
				//
1200 1198
			}else if (uninomial.endsWith("phyta") || uninomial.endsWith("mycota") ){  //plants, fungi
......
1222 1220
			}else if (uninomial.endsWith("ota")){
1223 1221
				result = Rank.KINGDOM();  //TODO
1224 1222
			}
1225
		}else if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
1223
		}else if (nameToBeFilled.isZoological()){
1226 1224
			if (false){
1227 1225
				//
1228 1226
			}else if (uninomial.endsWith("oideae")){
......
1251 1249
	 * ExTeam[1], BasionymTeam[2], ExBasionymTeam[3]
1252 1250
	 */
1253 1251
	protected void fullAuthors (String fullAuthorStringOrig, TeamOrPersonBase<?>[] authors,
1254
	        Integer[] years, Class<? extends INonViralName> clazz)
1252
	        Integer[] years, NomenclaturalCode code)
1255 1253
			throws StringNotParsableException{
1256
		if (fullAuthorStringOrig == null || clazz == null){
1254
		if (fullAuthorStringOrig == null || code == null){
1257 1255
			return;
1258 1256
		}
1259 1257
		String fullAuthorString = fullAuthorStringOrig.trim();
1260 1258

  
1261 1259
		//Botanic
1262
		if ( BotanicalName.class.isAssignableFrom(clazz) ){
1260
		if ( code.isBotanical() ){
1263 1261
			if (! fullBotanicAuthorStringPattern.matcher(fullAuthorString).matches() ){
1264 1262
				throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
1265 1263
			}
1266 1264
		}
1267 1265
		//Zoo
1268
		else if ( ZoologicalName.class.isAssignableFrom(clazz) ){
1266
		else if ( code.isZoological() ){
1269 1267
			if (! fullZooAuthorStringPattern.matcher(fullAuthorString).matches() ){
1270 1268
				throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
1271 1269
			}
1272 1270
		}else {
1273 1271
			//TODO
1274
			logger.warn ("Full author String parsable only for defined BotanicalNames or ZoologicalNames but this is " + clazz.getSimpleName());
1272
			logger.warn ("Full author String parsable only for defined BotanicalNames or ZoologicalNames but this is " + code.getMessage());
1275 1273
			throw new StringNotParsableException("fullAuthorString (" +fullAuthorString+") not parsable: ");
1276 1274
		}
1277 1275
		fullAuthorsChecked(fullAuthorString, authors, years);
......
1407 1405

  
1408 1406
//	// Parsing of the given full name that has been identified as a cultivar already somwhere else.
1409 1407
//	// The ... cv. ... syntax is not covered here as it is not according the rules for naming cultivars.
1410
	public BotanicalName parseCultivar(String fullName)	throws StringNotParsableException{
1411
		CultivarPlantName result = null;
1408
	public IBotanicalName parseCultivar(String fullName) throws StringNotParsableException{
1409
		ICultivarPlantName result = null;
1412 1410
		    String[] words = oWsPattern.split(fullName);
1413 1411

  
1414 1412
		    /* ---------------------------------------------------------------------------------
......
1423 1421
					String cultivarPart = cultivarMatcher.group(0).replace("'","").trim();
1424 1422
					//OLD: String cultivarPart = cultivarRE.getParen(0).replace("'","").trim();
1425 1423

  
1426
					result = (CultivarPlantName)parseFullName(namePart);
1424
					result = (ICultivarPlantName)parseFullName(namePart);
1427 1425
					result.setCultivarName(cultivarPart);
1428 1426
				}
1429 1427
			}else if (fullName.indexOf(" cv.") != 0){
......
1449 1447
		        	//OLD: String namePart = fullName.substring(0, groupRE.getParenStart(0) - 0);
1450 1448

  
1451 1449
		        	String cultivarPart = words[words.length -1];
1452
		        	result = (CultivarPlantName)parseFullName(namePart);
1450
		        	result = (ICultivarPlantName)parseFullName(namePart);
1453 1451
		        	if (result != null){
1454 1452
		        		result.setCultivarName(cultivarPart);
1455 1453

  
......
1468 1466
	}
1469 1467

  
1470 1468

  
1471
	private void makeEmpty(INonViralName nameToBeFilled){
1469
	private void makeEmpty(INonViralName name){
1470
	    TaxonNameBase<?,?> nameToBeFilled = TaxonNameBase.castAndDeproxy(name);
1472 1471
		nameToBeFilled.setRank(null);
1473 1472
		nameToBeFilled.setTitleCache(null, false);
1474 1473
		nameToBeFilled.setFullTitleCache(null, false);
......
1502 1501
		nameToBeFilled.setBinomHybrid(false);
1503 1502
		nameToBeFilled.setTrinomHybrid(false);
1504 1503

  
1505
		if (nameToBeFilled.isInstanceOf(BotanicalName.class)){
1506
			BotanicalName botanicalName = (BotanicalName)nameToBeFilled;
1507
			botanicalName.setAnamorphic(false);
1508
		}
1504
		nameToBeFilled.setAnamorphic(false);
1509 1505

  
1510
		if (nameToBeFilled.isInstanceOf(ZoologicalName.class)){
1511
			IZoologicalName zoologicalName = (ZoologicalName)nameToBeFilled;
1512
			zoologicalName.setBreed(null);
1513
			zoologicalName.setOriginalPublicationYear(null);
1514
		}
1506
		nameToBeFilled.setBreed(null);
1507
		nameToBeFilled.setOriginalPublicationYear(null);
1515 1508

  
1516 1509
		//nom status handled in nom status parser, otherwise we loose additional information like reference etc.
1517 1510
		//hybrid relationships handled in hybrid formula and at end of fullNameParser
1518 1511
	}
1519

  
1520

  
1521

  
1522 1512
}

Also available in: Unified diff