clazz) throws ClassCastException {
+ return HibernateProxyHelper.deproxy(object, clazz);
+ }
+
+ public boolean isInstanceOf(Class extends CdmBase> clazz) throws ClassCastException {
+ return HibernateProxyHelper.isInstanceOf(this, clazz);
+ }
// ************* Object overrides *************************/
- /**
- * Is true if UUID is the same for the passed Object and this one.
- * @see java.lang.Object#equals(java.lang.Object)
- * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
- * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
- * for more information about equals and hashcode.
- */
- @Override
- public boolean equals(Object obj) {
- if (obj == this){
- return true;
- }
- if (obj == null){
- return false;
- }
- if (!CdmBase.class.isAssignableFrom(obj.getClass())){
- return false;
- }
- ICdmBase cdmObj = (ICdmBase)obj;
- boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
- boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
- if (! uuidEqual || !createdEqual){
- return false;
- }
- return true;
- }
+ /**
+ * Is true if UUID is the same for the passed Object and this one.
+ * @see java.lang.Object#equals(java.lang.Object)
+ * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
+ * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
+ * for more information about equals and hashcode.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this){
+ return true;
+ }
+ if (obj == null){
+ return false;
+ }
+ if (!CdmBase.class.isAssignableFrom(obj.getClass())){
+ return false;
+ }
+ ICdmBase cdmObj = (ICdmBase)obj;
+ boolean uuidEqual = cdmObj.getUuid().equals(this.getUuid());
+ boolean createdEqual = cdmObj.getCreated().equals(this.getCreated());
+ if (! uuidEqual || !createdEqual){
+ return false;
+ }
+ return true;
+ }
+
+
+ /** Overrides {@link java.lang.Object#hashCode()}
+ * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
+ * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
+ * for more information about equals and hashcode.
+ */
+ @Override
+ public int hashCode() {
+ int hashCode = 7;
+ if(this.getUuid() != null) {
+ //this unfortunately leads to errors when loading maps via hibernate
+ //as hibernate computes hash values for CdmBase objects used as key at
+ // a time when the uuid is not yet loaded from the database. Therefore
+ //the hash values later change and give wrong results when retrieving
+ //data from the map (map.get(key) returns null, though there is an entry
+ //for key in the map.
+ //see further comments in #2114
+ int result = 29 * hashCode + this.getUuid().hashCode();
+// int shresult = 29 * hashCode + Integer.valueOf(this.getId()).hashCode();
+ return result;
+ } else {
+ return 29 * hashCode;
+ }
+ }
+
+ /**
+ * Overrides {@link java.lang.Object#toString()}.
+ * This returns an String that identifies the object well without being necessarily unique. Internally the method is delegating the
+ * call to {link {@link #instanceToString()}.
+ * Specification: This method should never call other object' methods so it can be well used for debugging
+ * without problems like lazy loading, unreal states etc.
+ *
+ * Note: If overriding this method's javadoc always copy or link the above requirement.
+ * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
+ *
+ * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
+ * @see java.lang.Object#toString()
+ */
+ @Override
+ public String toString() {
+ return instanceToString();
+ }
+
+ /**
+ * This returns an String that identifies the cdm instacne well without being necessarily unique.
+ * The string representation combines the class name the {@link #id} and {@link #uuid}.
+ *
+ * For example: Taxon#13<b5938a98-c1de-4dda-b040-d5cc5bfb3bc0>
+ * @return
+ */
+ public String instanceToString() {
+ return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
+ }
+// **************** invoke methods **************************/
- /** Overrides {@link java.lang.Object#hashCode()}
- * See {@link http://www.hibernate.org/109.html hibernate109}, {@link http://www.geocities.com/technofundo/tech/java/equalhash.html geocities}
- * or {@link http://www.ibm.com/developerworks/java/library/j-jtp05273.html ibm}
- * for more information about equals and hashcode.
- */
+ protected void invokeSetMethod(Method method, Object object){
+ try {
+ method.invoke(object, this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ //TODO handle exceptioin;
+ }
+ }
+
+ protected void invokeSetMethodWithNull(Method method, Object object){
+ try {
+ Object[] nul = new Object[]{null};
+ method.invoke(object, nul);
+ } catch (Exception e) {
+ e.printStackTrace();
+ //TODO handle exceptioin;
+ }
+ }
+
+ @Transient
@Override
- public int hashCode() {
- int hashCode = 7;
- if(this.getUuid() != null) {
- //this unfortunately leads to errors when loading maps via hibernate
- //as hibernate computes hash values for CdmBase objects used as key at
- // a time when the uuid is not yet loaded from the database. Therefore
- //the hash values later change and give wrong results when retrieving
- //data from the map (map.get(key) returns null, though there is an entry
- //for key in the map.
- //see further comments in #2114
- int result = 29 * hashCode + this.getUuid().hashCode();
-// int shresult = 29 * hashCode + Integer.valueOf(this.getId()).hashCode();
- return result;
- } else {
- return 29 * hashCode;
- }
+ public String getUserFriendlyTypeName(){
+ return getClass().getSimpleName();
}
- /**
- * Overrides {@link java.lang.Object#toString()}.
- * This returns an String that identifies the object well without beeing necessarily unique.
- * Specification: This method should never call other object' methods so it can be well used for debugging
- * without problems like lazy loading, unreal states etc.
- * Note: If overriding this method's javadoc always copy or link the above requirement.
- * If not overwritten by a subclass method returns the class, id and uuid as a string for any CDM object.
- * For example: Taxon#13
- * @see java.lang.Object#toString()
- */
+ @Transient
@Override
- public String toString() {
- return this.getClass().getSimpleName()+"#"+this.getId()+"<"+this.getUuid()+">";
- }
-
-// **************** invoke methods **************************/
-
- protected void invokeSetMethod(Method method, Object object){
- try {
- method.invoke(object, this);
- } catch (Exception e) {
- e.printStackTrace();
- //TODO handle exceptioin;
- }
+ public String getUserFriendlyDescription(){
+ return toString();
}
- protected void invokeSetMethodWithNull(Method method, Object object){
- try {
- Object[] nul = new Object[]{null};
- method.invoke(object, nul);
- } catch (Exception e) {
- e.printStackTrace();
- //TODO handle exceptioin;
- }
+ @Override
+ public String getUserFriendlyFieldName(String field){
+ return field;
}
//********************** CLONE *****************************************/
- protected void clone(CdmBase clone){
- clone.setCreatedBy(createdBy);
- clone.setId(id);
- clone.propertyChangeSupport=new PropertyChangeSupport(clone);
- //Constructor Attributes
- //clone.setCreated(created);
- //clone.setUuid(getUuid());
-
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#clone()
- */
- @Override
- public Object clone() throws CloneNotSupportedException{
- CdmBase result = (CdmBase)super.clone();
- result.propertyChangeSupport=new PropertyChangeSupport(result);
-
- //TODO ?
- result.setId(0);
- result.setUuid(UUID.randomUUID());
- result.setCreated(new DateTime());
- result.setCreatedBy(null);
-
- //no changes to: -
- return result;
- }
+// protected void clone(CdmBase clone){
+// clone.setCreatedBy(createdBy);
+// clone.setId(id);
+// clone.propertyChangeSupport=new PropertyChangeSupport(clone);
+// //Constructor Attributes
+// //clone.setCreated(created);
+// //clone.setUuid(getUuid());
+//
+// }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException{
+ CdmBase result = (CdmBase)super.clone();
+ result.propertyChangeSupport=new PropertyChangeSupport(result);
+
+ //TODO ?
+ result.setId(0);
+ result.setUuid(UUID.randomUUID());
+ result.setCreated(new DateTime());
+ result.setCreatedBy(null);
+
+ //no changes to: -
+ return result;
+ }
}