Handle null object in StoreUtil.getCdmEntity
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / store / StoreUtil.java
index 600a2b38157991d7115f8cebfa17cacee801e9be..69e94c1ecacb6cde2818964db44d46c101e0441e 100644 (file)
@@ -21,6 +21,7 @@ import org.eclipse.ui.IEditorPart;
 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 
 /**
@@ -46,21 +47,26 @@ public class StoreUtil extends AbstractUtility {
 
        /**
         * If the object given is already a {@link CdmBase} then it is returned.<br>
-        * If it is a facade then it is asked for its "responsible" CdmBase entity.<br>
+        * If it is a kind of "container" for CDM objects then it is asked for its "responsible" CdmBase entity.<br>
         * Otherwise an exception is thrown.
         * @param object the object to test for CdmBase
         * @return a CdmBase object
-        * @throws IllegalArgumentException if the tested object is neither a CdmBase nor a facade
+        * @throws IllegalArgumentException if the tested object is neither a CdmBase nor a CDM "container"
         */
        public static CdmBase getCdmEntity(Object object){
         // TODO temporary solution for ticket #4091????
-        if(object instanceof DerivedUnitFacade){
+        if (object == null){
+               return null;   //not sure if an object should ever be null at this point, but this needs to be handled in calling methods
+        }else if(object instanceof DerivedUnitFacade){
             return ((DerivedUnitFacade)object).baseUnit();
         }
+        else if(object instanceof FeatureNodeContainer){
+            return ((FeatureNodeContainer) object).getFeatureNode();
+        }
         else if(object instanceof CdmBase){
             return (CdmBase) object;
         }
-        throw new IllegalArgumentException("Object " + object.toString() + " is neither a CdmBase nor an EntityFacade");
+        throw new IllegalArgumentException("Object " + object.toString() + " is neither a CdmBase nor a CDM \"container\"");
        }
 
        /**