You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ad...@apache.org on 2008/11/07 17:54:55 UTC

svn commit: r712195 - in /ofbiz/trunk: applications/product/src/org/ofbiz/product/product/ framework/base/src/org/ofbiz/base/util/ framework/base/src/org/ofbiz/base/util/cache/ framework/webapp/src/org/ofbiz/webapp/event/

Author: adrianc
Date: Fri Nov  7 08:54:41 2008
New Revision: 712195

URL: http://svn.apache.org/viewvc?rev=712195&view=rev
Log:
Code cleanups in the base component - deprecated unused/unnecessary classes.

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/OutputStreamByteCount.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringOutputStream.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilName.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilParse.java
    ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLine.java
    ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductEvents.java Fri Nov  7 08:54:41 2008
@@ -36,7 +36,6 @@
 import org.ofbiz.base.util.UtilDateTime;
 import org.ofbiz.base.util.UtilHttp;
 import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilParse;
 import org.ofbiz.base.util.UtilProperties;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.GenericDelegator;
@@ -434,10 +433,10 @@
                     product.set("lastModifiedDate", nowTimestamp);
                     product.setString("lastModifiedByUserLogin", userLogin.getString("userLoginId"));
                     try {
-                        product.set("productHeight", UtilParse.parseDoubleForEntity(request.getParameter("productHeight")));
-                        product.set("productWidth", UtilParse.parseDoubleForEntity(request.getParameter("productWidth")));
-                        product.set("productDepth", UtilParse.parseDoubleForEntity(request.getParameter("productDepth")));
-                        product.set("weight", UtilParse.parseDoubleForEntity(request.getParameter("weight")));
+                        product.set("productHeight", parseDoubleForEntity(request.getParameter("productHeight")));
+                        product.set("productWidth", parseDoubleForEntity(request.getParameter("productWidth")));
+                        product.set("productDepth", parseDoubleForEntity(request.getParameter("productDepth")));
+                        product.set("weight", parseDoubleForEntity(request.getParameter("weight")));
     
                         // default unit settings for shipping parameters
                         product.set("heightUomId", "LEN_in");
@@ -445,10 +444,10 @@
                         product.set("depthUomId", "LEN_in");
                         product.set("weightUomId", "WT_oz");
     
-                        Double floz = UtilParse.parseDoubleForEntity(request.getParameter("~floz"));
-                        Double ml = UtilParse.parseDoubleForEntity(request.getParameter("~ml"));
-                        Double ntwt = UtilParse.parseDoubleForEntity(request.getParameter("~ntwt"));
-                        Double grams = UtilParse.parseDoubleForEntity(request.getParameter("~grams"));
+                        Double floz = parseDoubleForEntity(request.getParameter("~floz"));
+                        Double ml = parseDoubleForEntity(request.getParameter("~ml"));
+                        Double ntwt = parseDoubleForEntity(request.getParameter("~ntwt"));
+                        Double grams = parseDoubleForEntity(request.getParameter("~grams"));
     
                         List currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE")), true);
                         setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
@@ -471,14 +470,14 @@
                     do {
                         GenericValue product = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", productId));
                         try {
-                            product.set("productHeight", UtilParse.parseDoubleForEntity(request.getParameter("productHeight" + attribIdx)));
-                            product.set("productWidth", UtilParse.parseDoubleForEntity(request.getParameter("productWidth" + attribIdx)));
-                            product.set("productDepth", UtilParse.parseDoubleForEntity(request.getParameter("productDepth" + attribIdx)));
-                            product.set("weight", UtilParse.parseDoubleForEntity(request.getParameter("weight" + attribIdx)));
-                            Double floz = UtilParse.parseDoubleForEntity(request.getParameter("~floz" + attribIdx));
-                            Double ml = UtilParse.parseDoubleForEntity(request.getParameter("~ml" + attribIdx));
-                            Double ntwt = UtilParse.parseDoubleForEntity(request.getParameter("~ntwt" + attribIdx));
-                            Double grams = UtilParse.parseDoubleForEntity(request.getParameter("~grams" + attribIdx));
+                            product.set("productHeight", parseDoubleForEntity(request.getParameter("productHeight" + attribIdx)));
+                            product.set("productWidth", parseDoubleForEntity(request.getParameter("productWidth" + attribIdx)));
+                            product.set("productDepth", parseDoubleForEntity(request.getParameter("productDepth" + attribIdx)));
+                            product.set("weight", parseDoubleForEntity(request.getParameter("weight" + attribIdx)));
+                            Double floz = parseDoubleForEntity(request.getParameter("~floz" + attribIdx));
+                            Double ml = parseDoubleForEntity(request.getParameter("~ml" + attribIdx));
+                            Double ntwt = parseDoubleForEntity(request.getParameter("~ntwt" + attribIdx));
+                            Double grams = parseDoubleForEntity(request.getParameter("~grams" + attribIdx));
     
                                 List currentProductFeatureAndAppls = EntityUtil.filterByDate(delegator.findByAnd("ProductFeatureAndAppl", UtilMisc.toMap("productId", productId, "productFeatureApplTypeId", "STANDARD_FEATURE")), true);
                                 setOrCreateProdFeature(delegator, productId, currentProductFeatureAndAppls, "VLIQ_ozUS", "AMOUNT", floz);
@@ -1049,4 +1048,22 @@
         }
         return "success";
     }
+
+    /**
+     * Return nulls for empty strings, as the entity engine can deal with nulls. This will provide blanks
+     * in fields where doubles display. Blank meaning null, vs. 0 which means 0
+     * @param doubleString
+     * @return a Double for the parsed value
+     */
+    public static Double parseDoubleForEntity(String doubleString) throws NumberFormatException {
+        if (doubleString == null) {
+            return null;
+        }
+        doubleString = doubleString.trim();
+        doubleString = doubleString.replaceAll(",", "");
+        if (doubleString.length() < 1) {
+            return null;
+        }
+        return Double.valueOf(doubleString);
+    }
 }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/OutputStreamByteCount.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/OutputStreamByteCount.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/OutputStreamByteCount.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/OutputStreamByteCount.java Fri Nov  7 08:54:41 2008
@@ -22,10 +22,12 @@
 import java.io.OutputStream;
 
 
+/** @deprecated */
 public class OutputStreamByteCount extends OutputStream {
 
     protected long byteCount = 0;
 
+    /** @deprecated */
     public OutputStreamByteCount() {
         super();
     }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringOutputStream.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringOutputStream.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringOutputStream.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/StringOutputStream.java Fri Nov  7 08:54:41 2008
@@ -22,9 +22,7 @@
 import java.io.OutputStream;
 import java.io.IOException;
 
-/**
- * StringOutputStream
- */
+/** @deprecated */
 public class StringOutputStream extends OutputStream {
 
     protected StringBuffer buffer = new StringBuffer();

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilName.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilName.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilName.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilName.java Fri Nov  7 08:54:41 2008
@@ -20,14 +20,10 @@
 
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-/**
- * UtilName
- *
- */
+/** @deprecated */
 public class UtilName {
 
     public static final String module = UtilName.class.getName();
@@ -44,6 +40,7 @@
     protected String name[] = null;
     protected String raw = null;
 
+    /** @deprecated */
     public UtilName(String name, boolean initial) {
         this.middleIsInitial = initial;
         this.raw = name;
@@ -61,6 +58,7 @@
         this.name = goodElements.toArray(new String[goodElements.size()]);
     }
 
+    /** @deprecated */
     public UtilName(String name) {
         this(name, false);
     }

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilObject.java Fri Nov  7 08:54:41 2008
@@ -92,40 +92,21 @@
     }
 
     /** Returns the size of a serializable object. Non-serializable objects
-     * will return zero.<p>It is important to note
+     * will throw an <code>IOException</code>.<p>It is important to note
      * that the returned value is length of the byte stream after the object has
      * been serialized. The returned value does not represent the amount of memory
      * the object uses. There is no accurate way to determine the size of an
      * object in memory.</p>
      * @param obj
      * @return the number of bytes in the serialized object
+     * @throws IOException
      */
-    public static long getByteCount(Object obj) {
-        OutputStreamByteCount osbc = null;
-        ObjectOutputStream oos = null;
-        long objSize = 0;
-        try {
-            osbc = new OutputStreamByteCount();
-            oos = new ObjectOutputStream(osbc);
-            oos.writeObject(obj);
-            objSize = osbc.getByteCount();
-        } catch (IOException e) {
-            // Non-serializable objects will cause this exception, so
-            // logging verbose to cut down on console log size
-            Debug.logVerbose(e, module);
-        }
-        try {
-            if (oos != null) {
-                oos.flush();
-                oos.close();
-            }
-            if (osbc != null) {
-                osbc.close();
-            }
-        } catch (IOException e) {
-            Debug.logError(e, module);
-        }
-        return objSize;
+    public static long getByteCount(Object obj) throws IOException {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(bos);
+        oos.writeObject(obj);
+        oos.flush();
+        return (long) bos.size();
     }
 
     /** Deserialize a byte array back to an object */

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilParse.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilParse.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilParse.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilParse.java Fri Nov  7 08:54:41 2008
@@ -18,23 +18,10 @@
  *******************************************************************************/
 package org.ofbiz.base.util;
 
-/**
- * <p/>
- * <p>
- * Parses input to strip ignorable characters, deal with nulls, etc.
- * </p>
- * <br/>
- * <br/>
- * Created on Oct 2, 2004 by dustin
- */
+/** @deprecated */
 public class UtilParse {
 
-    /**
-     * return nulls for empty strings, as the entity engine can deal with nulls. This will provide blanks
-     * in fields where doubles display. Blank meaning null, vs. 0 which means 0
-     * @param doubleString
-     * @return a Double for the parsed value
-     */
+    /** @deprecated */
     public static Double parseDoubleForEntity(String doubleString) throws NumberFormatException {
         if (doubleString == null) {
             return null;

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLine.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLine.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLine.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/CacheLine.java Fri Nov  7 08:54:41 2008
@@ -43,7 +43,11 @@
     }
 
     public long getSizeInBytes() {
-        return UtilObject.getByteCount(this);
+        try {
+            return UtilObject.getByteCount(this);
+        } catch (Exception e) {
+            return 0;
+        }
     }
 
     public boolean hasExpired() {

Modified: ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java?rev=712195&r1=712194&r2=712195&view=diff
==============================================================================
--- ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java (original)
+++ ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/event/SOAPEventHandler.java Fri Nov  7 08:54:41 2008
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.webapp.event;
 
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.Writer;
 import java.io.OutputStream;
@@ -36,7 +37,6 @@
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.base.util.StringOutputStream;
 import org.ofbiz.service.GenericServiceException;
 import org.ofbiz.service.LocalDispatcher;
 import org.ofbiz.service.ModelService;
@@ -170,9 +170,7 @@
         // log the request message
         if (Debug.verboseOn()) {
             try {
-                StringOutputStream out = new StringOutputStream();
-                msg.writeTo(out);
-                Debug.logInfo("Request Message:\n" + out.toString() + "\n", module);
+                Debug.logInfo("Request Message:\n" + messageToString(msg) + "\n", module);
             } catch (Throwable t) {
             }
         }
@@ -271,9 +269,7 @@
         // log the response message
         if (Debug.verboseOn()) {
             try {
-                StringOutputStream out = new StringOutputStream();
-                msg.writeTo(out);
-                Debug.log("Response Message:\n" + out.toString() + "\n", module);
+                Debug.log("Response Message:\n" + messageToString(msg) + "\n", module);
             } catch (Throwable t) {
             }
         }
@@ -333,4 +329,10 @@
         uri.append(reqInfo);
         return uri.toString();
     }
+    
+    public static String messageToString(Message msg) throws SOAPException, IOException {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        msg.writeTo(out);
+        return out.toString();
+    }
 }