You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by le...@apache.org on 2011/06/28 00:58:16 UTC

svn commit: r1140358 - in /ofbiz/trunk/applications/product/src/org/ofbiz/product/config: ProductConfigItemContentWrapper.java ProductConfigWrapper.java

Author: lektran
Date: Mon Jun 27 22:58:16 2011
New Revision: 1140358

URL: http://svn.apache.org/viewvc?rev=1140358&view=rev
Log:
Make references to Delegator and LocalDispatcher transient and provide methods to retrieve the objects when missing in ProductCofigWrapper and ProductConfigItemContentWrapper.  Prevents non-serializable exceptions from being thrown when attempting to serialize a ShoppingCart object.  Thanks to Arun Patidar for the patch.

Modified:
    ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java
    ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java?rev=1140358&r1=1140357&r2=1140358&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigItemContentWrapper.java Mon Jun 27 22:58:16 2011
@@ -50,7 +50,8 @@ public class ProductConfigItemContentWra
 
     public static final String module = ProductConfigItemContentWrapper.class.getName();
 
-    protected LocalDispatcher dispatcher;
+    protected transient LocalDispatcher dispatcher;
+    protected String dispatcherName;
     protected GenericValue productConfigItem;
     protected Locale locale;
     protected String mimeTypeId;

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java?rev=1140358&r1=1140357&r2=1140358&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/product/config/ProductConfigWrapper.java Mon Jun 27 22:58:16 2011
@@ -35,9 +35,11 @@ import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.entity.Delegator;
+import org.ofbiz.entity.DelegatorFactory;
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.service.GenericDispatcher;
 import org.ofbiz.service.LocalDispatcher;
 
 
@@ -49,12 +51,14 @@ public class ProductConfigWrapper implem
 
     public static final String module = ProductConfigWrapper.class.getName();
 
-    protected LocalDispatcher dispatcher;
+    protected transient LocalDispatcher dispatcher;
+    protected String dispatcherName;
     protected String productStoreId;
     protected String catalogId;
     protected String webSiteId;
     protected String currencyUomId;
-    protected Delegator delegator;
+    protected transient Delegator delegator;
+    protected String delegatorName = null;
     protected GenericValue product = null; // the aggregated product
     protected GenericValue autoUserLogin = null;
     protected BigDecimal listPrice = BigDecimal.ZERO;
@@ -77,12 +81,14 @@ public class ProductConfigWrapper implem
         basePrice = pcw.basePrice;
         defaultPrice = pcw.defaultPrice;
         questions = FastList.newInstance();
-        dispatcher = pcw.dispatcher;
+        delegator = pcw.getDelegator();
+        delegatorName = delegator.getDelegatorName();
+        dispatcher = pcw.getDispatcher();
+        dispatcherName = dispatcher.getName();
         productStoreId = pcw.productStoreId;
         catalogId = pcw.catalogId;
         webSiteId = pcw.webSiteId;
         currencyUomId = pcw.currencyUomId;
-        delegator = pcw.delegator;
         autoUserLogin = pcw.autoUserLogin;
         for (ConfigItem ci: pcw.questions) {
             questions.add(new ConfigItem(ci));
@@ -95,11 +101,13 @@ public class ProductConfigWrapper implem
             throw new ProductConfigWrapperException("Product " + productId + " is not an AGGREGATED product.");
         }
         this.dispatcher = dispatcher;
+        this.dispatcherName = dispatcher.getName();
         this.productStoreId = productStoreId;
         this.catalogId = catalogId;
         this.webSiteId = webSiteId;
         this.currencyUomId = currencyUomId;
         this.delegator = delegator;
+        this.delegatorName = delegator.getDelegatorName();
         this.autoUserLogin = autoUserLogin;
 
         // get the list Price, the base Price
@@ -202,6 +210,20 @@ public class ProductConfigWrapper implem
         return configId;
     }
 
+    public Delegator getDelegator() {
+        if (delegator == null) {
+            delegator = DelegatorFactory.getDelegator(delegatorName);
+        }
+        return delegator;
+    }
+
+    public LocalDispatcher getDispatcher() {
+        if (dispatcher == null) {
+            dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, this.getDelegator());
+        }
+        return dispatcher;
+    }
+
     @Override
     public boolean equals(Object obj) {
         if (!(obj instanceof ProductConfigWrapper)) {
@@ -607,7 +629,7 @@ public class ProductConfigWrapper implem
 
                 // Get the component's price
                 Map<String, Object> fieldMap = UtilMisc.toMap("product", oneComponentProduct, "prodCatalogId", pcw.catalogId, "webSiteId", pcw.webSiteId, "currencyUomId", pcw.currencyUomId, "productPricePurposeId", "COMPONENT_PRICE", "autoUserLogin", pcw.autoUserLogin, "productStoreId",productStoreId);
-                Map<String, Object> priceMap = dispatcher.runSync("calculateProductPrice", fieldMap);
+                Map<String, Object> priceMap = pcw.getDispatcher().runSync("calculateProductPrice", fieldMap);
                 BigDecimal componentListPrice = (BigDecimal) priceMap.get("listPrice");
                 BigDecimal componentPrice = (BigDecimal) priceMap.get("price");
                 Boolean validPriceFound = (Boolean)priceMap.get("validPriceFound");
@@ -627,7 +649,7 @@ public class ProductConfigWrapper implem
                     }
                 } else {
                     fieldMap.put("productPricePurposeId", "PURCHASE");
-                    Map<String, Object> purchasePriceResultMap = dispatcher.runSync("calculateProductPrice", fieldMap);
+                    Map<String, Object> purchasePriceResultMap = pcw.getDispatcher().runSync("calculateProductPrice", fieldMap);
                     BigDecimal purchaseListPrice = (BigDecimal) purchasePriceResultMap.get("listPrice");
                     BigDecimal purchasePrice = (BigDecimal) purchasePriceResultMap.get("price");
                     if (purchaseListPrice != null) {