.
authorp.ciardelli <p.ciardelli@localhost>
Thu, 1 Oct 2009 15:27:37 +0000 (15:27 +0000)
committerp.ciardelli <p.ciardelli@localhost>
Thu, 1 Oct 2009 15:27:37 +0000 (15:27 +0000)
.gitattributes
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/ParseHandler.java [deleted file]

index 06dc713b83b0acbe906d0b24eb52ae8635b1dd44..0d80dca8e1d4d291f9257101a5b50ec74b6c6978 100644 (file)
@@ -794,7 +794,6 @@ taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/MisappliedName
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameSelectComposite.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameViewer.java -text
-taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/ParseHandler.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/RulerWithIcon.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/SynonymComposite.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/TaxonNameEditor.java -text
diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/ParseHandler.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/ParseHandler.java
deleted file mode 100644 (file)
index db21c45..0000000
+++ /dev/null
@@ -1,288 +0,0 @@
-/**
- * 
- */
-package eu.etaxonomy.taxeditor.editor.name;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
-import eu.etaxonomy.cdm.model.name.NonViralName;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.reference.ReferenceBase;
-import eu.etaxonomy.cdm.strategy.match.DefaultMatchStrategy;
-import eu.etaxonomy.cdm.strategy.match.IMatchStrategy;
-import eu.etaxonomy.cdm.strategy.match.MatchException;
-import eu.etaxonomy.cdm.strategy.match.MatchMode;
-import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
-import eu.etaxonomy.taxeditor.parser.ParserUtil;
-import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
-import eu.etaxonomy.taxeditor.store.CdmStore;
-
-/**
- * @author n.hoffmann
- *
- */
-public class ParseHandler{
-       private static final Logger logger = Logger.getLogger(ParseHandler.class);
-
-       private TaxonNameBase taxonNameBase;
-       
-       private List<ReferenceBase> duplicateReferences;
-
-       private List<TaxonNameBase> duplicateNames;
-
-       private List<TeamOrPersonBase> duplicateCombinationAuthorTeams;
-       private List<TeamOrPersonBase> duplicateExCombinationAuthorTeams;
-       private List<TeamOrPersonBase> duplicateBasionymAuthorTeams;
-       private List<TeamOrPersonBase> duplicateExBasionymAuthorTeams;
-
-       private NonViralNameParserImpl nonViralNameParser;
-
-       private NonViralName name;
-
-       private Control textWidget;
-       
-       private ParseHandler(Control textWidget, TaxonNameBase name){
-                               
-               nonViralNameParser = NonViralNameParserImpl.NewInstance();
-               
-               if(textWidget != null){
-                       this.textWidget = textWidget;
-                       checkControlHasText();
-               }else{
-                       throw new IllegalArgumentException("text widget must not be null");
-               }
-               
-               if(name == null){
-                       this.name = nonViralNameParser.getNonViralNameInstance("", PreferencesUtil.getPreferredNomenclaturalCode());
-               }else{
-                       this.name = (NonViralName) HibernateProxyHelper.deproxy(name);
-               }
-       }
-       
-       public static ParseHandler NewInstance(Control textWidget, TaxonNameBase name){
-               return new ParseHandler(textWidget, name);
-               
-       }
-       
-       private void checkControlHasText(){
-               Class clazz = textWidget.getClass();
-               
-               try {
-                       clazz.getDeclaredMethod("getText", null);
-               } catch (SecurityException e) {
-               } catch (NoSuchMethodException e) {     
-                       throw new IllegalArgumentException("Given composite does not have a getText method");
-               }
-       }
-       
-       /**
-        * 
-        * @param unparsedNameString
-        * @param rank
-        * @return
-        */
-       public NonViralName parse(){
-               
-               
-               String unparsedNameString = "";
-               try {
-                       Method getText;
-                       getText = textWidget.getClass().getDeclaredMethod("getText", null);
-                       unparsedNameString = (String) getText.invoke(textWidget, null);
-               } catch (Exception e) {
-                       // we should never get here
-                       logger.error("Error trying to invoke getText method");
-               }
-               
-               
-               nonViralNameParser.parseReferencedName(name, unparsedNameString,
-                               name.getRank(), true);
-
-               if (name.hasProblem()) {
-                       name.setFullTitleCache(unparsedNameString);
-               }
-               
-               return name;
-       }
-       
-       /**
-        * 
-        * @param unparsedNameString
-        * @param rank
-        * @return
-        */
-       public NonViralName parseAndResolveDuplicates(){
-               
-               parse();
-               
-               findMatches(name);
-               
-               resolveDuplicates(name);
-               
-               return name;
-       }
-               
-       
-       
-       
-       /**
-        * @param parsedName
-        */
-       private void resolveDuplicates(NonViralName name) {
-               resolveDuplicateNames(name);
-               
-               resolveAllDuplicateAuthors(name);
-                               
-               resolveDuplicateReferences(name);
-               
-       }
-       
-       /**
-        * @param composite
-        */
-       private void resolveDuplicateNames(NonViralName name) {
-                               
-               if (duplicateNames.size() == 1){
-                       name = (NonViralName) duplicateNames.iterator().next();
-               }else if(duplicateNames.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name = (NonViralName) duplicateNames.iterator().next();
-               }
-       }
-
-       /**
-        * @param composite
-        */
-       private void resolveDuplicateReferences(NonViralName name) {
-               if(duplicateReferences.size() == 1){
-                       // exactly one match. We assume that the user wants this reference
-                       name.setNomenclaturalReference(duplicateReferences.iterator().next());
-               }else if(duplicateReferences.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name.setNomenclaturalReference(duplicateReferences.iterator().next());
-               }
-       }
-
-
-
-       /**
-        * @param composite
-        */
-       private void resolveAllDuplicateAuthors(NonViralName name) {
-               
-               if(duplicateCombinationAuthorTeams.size() == 1){
-                       name.setCombinationAuthorTeam(duplicateCombinationAuthorTeams.iterator().next());
-               }else if(duplicateCombinationAuthorTeams.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name.setCombinationAuthorTeam(duplicateCombinationAuthorTeams.iterator().next());
-               }
-               
-               if(duplicateExCombinationAuthorTeams.size() == 1){
-                       name.setExCombinationAuthorTeam(duplicateExCombinationAuthorTeams.iterator().next());
-               }else if(duplicateExCombinationAuthorTeams.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name.setExCombinationAuthorTeam(duplicateExCombinationAuthorTeams.iterator().next());
-               }
-               
-               if(duplicateBasionymAuthorTeams.size() == 1){
-                       name.setBasionymAuthorTeam(duplicateBasionymAuthorTeams.iterator().next());
-               }else if(duplicateBasionymAuthorTeams.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name.setBasionymAuthorTeam(duplicateBasionymAuthorTeams.iterator().next());
-               }
-               
-               if(duplicateExBasionymAuthorTeams.size() == 1){
-                       name.setExBasionymAuthorTeam(duplicateExBasionymAuthorTeams.iterator().next());
-               }else if(duplicateExBasionymAuthorTeams.size() > 1){
-                       // FIXME TODO resolve multiple duplications. Use first match for a start
-                       name.setExBasionymAuthorTeam(duplicateExBasionymAuthorTeams.iterator().next());
-               }
-       }
-       
-
-       private void findMatches(NonViralName name){
-               
-               duplicateNames = findMatchingLatinNames(name);
-               
-               duplicateCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getCombinationAuthorTeam());
-               duplicateExCombinationAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExCombinationAuthorTeam());
-               duplicateBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getBasionymAuthorTeam());
-               duplicateExBasionymAuthorTeams = findMatchingAuthors((TeamOrPersonBase) name.getExBasionymAuthorTeam());
-               
-               duplicateReferences = findMatchingNomenclaturalReference(name.getNomenclaturalReference());
-       }
-       
-       /**
-        * @param name
-        */
-       private List<ReferenceBase> findMatchingNomenclaturalReference(ReferenceBase referenceBase) {
-               if(referenceBase == null) return new ArrayList<ReferenceBase>();
-               try{
-                       return CdmStore.getCommonService().findMatching(referenceBase, null);
-               }catch (MatchException e) {
-                       logger.error("Error finding matching references", e);
-               }
-               return null;
-       }
-
-       /**
-        * @param name
-        */
-       private List<TeamOrPersonBase> findMatchingAuthors(TeamOrPersonBase authorTeam) {
-
-               if(authorTeam == null){
-                       return new ArrayList<TeamOrPersonBase>();
-               }
-               
-               try{
-                       return CdmStore.getCommonService().findMatching(authorTeam, null);
-               }catch (MatchException e) {
-                       logger.error("Error finding matching authors", e);
-               }
-               return null;
-       }
-
-       /**
-        * @param name
-        */
-       private List<TaxonNameBase> findMatchingLatinNames(TaxonNameBase taxonNameBase) {
-
-               try {
-                       IMatchStrategy strategy = DefaultMatchStrategy.NewInstance(NonViralName.class);
-                       strategy.setMatchMode("nomenclaturalReference", MatchMode.IGNORE);
-                       strategy.setMatchMode("combinationAuthorTeam", MatchMode.IGNORE);
-                       strategy.setMatchMode("exCombinationAuthorTeam", MatchMode.IGNORE);
-                       strategy.setMatchMode("basionymAuthorTeam", MatchMode.IGNORE);
-                       strategy.setMatchMode("exBasionymAuthorTeam", MatchMode.IGNORE);
-                       
-                       return CdmStore.getCommonService().findMatching(taxonNameBase, strategy);
-                       
-               } catch (MatchException e) {
-                       logger.error("Error finding matching names", e);
-               }
-               return null;
-       }
-
-       /**
-        * @return the textWidget
-        */
-       public Control getTextWidget() {
-               return textWidget;
-       }
-
-       /**
-        * @param textWidget the textWidget to set
-        */
-       public void setTextWidget(Control textWidget) {
-               this.textWidget = textWidget;
-               checkControlHasText();
-       }
-}