CVS: xdoclet/modules/jdo/src/xdoclet/modules/jdo JdoObjectIdGeneratorTagsHandler.java, 1.7, 1.8

Marco Schulze <[email protected]> Tue, 24 Jul 2007 10:45:10 -0700
Newsgroups gmane.comp.java.xdoclet.devel
Message-ID <[email protected]>
Update of /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv2572/modules/jdo/src/xdoclet/modules/jdo

Modified Files:
	JdoObjectIdGeneratorTagsHandler.java 
Log Message:
Modification by Marc Klinger: implemented creation of serialVersionUID in generated ObjectID classes

Index: JdoObjectIdGeneratorTagsHandler.java
===================================================================
RCS file: /cvsroot/xdoclet/xdoclet/modules/jdo/src/xdoclet/modules/jdo/JdoObjectIdGeneratorTagsHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -r1.7 -r1.8
*** JdoObjectIdGeneratorTagsHandler.java	20 Oct 2006 03:50:55 -0000	1.7
--- JdoObjectIdGeneratorTagsHandler.java	24 Jul 2007 17:45:07 -0000	1.8
***************
*** 8,11 ****
--- 8,12 ----
  import java.io.File;
  import java.io.FileReader;
+ import java.io.Serializable;
  import java.util.ArrayList;
  import java.util.Collections;
***************
*** 307,310 ****
--- 308,361 ----
  
      /**
+      * @param attributes
+      * @return                      Returns <tt>null</tt> or the serial version uid expression.
+      * @exception XDocletException
+      */
+     public String serialVersionUID(Properties attributes) throws XDocletException
+     {
+         XDoc classDoc = getCurrentClass().getDoc();
+         String serialVerisionUID = classDoc.getTagAttributeValue("jdo.create-objectid-class", "serial-version-uid");
+ 
+         if (serialVerisionUID == null)
+             serialVerisionUID = "auto";
+ 
+         String number;
+ 
+         if ("none".equals(serialVerisionUID))
+             return null;
+         else if ("default".equals(serialVerisionUID))
+             number = "1L";
+         else if ("auto".equals(serialVerisionUID)) {
+             StringBuffer sb = new StringBuffer();
+             List fields = getCurrentClass().getFields();
+ 
+             for (Iterator iter = fields.iterator(); iter.hasNext(); ) {
+                 XField field = (XField) iter.next();
+ 
+                 if (!field.isStatic() && !field.isTransient()) {
+                     sb.append(field.getModifiers());
+                     sb.append(' ');
+                     sb.append(field.getType());
+                     sb.append(' ');
+                     sb.append(field.getName());
+                     sb.append('?');
+                 }
+             }
+             System.out.println("serial version suid String: " + sb.toString());
+ 
+             int splitIdx = sb.length() / 2;
+             int hash1 = sb.substring(0, splitIdx).hashCode();
+             int hash2 = sb.substring(splitIdx).hashCode();
+             long hash = (long) hash1 | (((long) hash2) << 32);
+ 
+             System.out.println("serial version uid: " + hash);
+             number = String.valueOf(hash) + "L";
+         }
+         else
+             number = serialVerisionUID;
+         return "private static final long serialVersionUID = " + number + ";";
+     }
+ 
+     /**
       * Additional code can be pasted into the objectid-class.
       *


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/