KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > pos > container > PosContainer


1 /*
2  * $Id: PosContainer.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2004 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.pos.container;
26
27 import java.util.Locale JavaDoc;
28
29 import org.ofbiz.base.container.ContainerConfig;
30 import org.ofbiz.base.container.ContainerException;
31 import org.ofbiz.base.util.UtilMisc;
32 import org.ofbiz.base.util.UtilValidate;
33 import org.ofbiz.guiapp.xui.XuiContainer;
34 import org.ofbiz.guiapp.xui.XuiSession;
35 import org.ofbiz.entity.GenericEntityException;
36 import org.ofbiz.entity.GenericValue;
37 import org.ofbiz.product.store.ProductStoreWorker;
38
39 /**
40  *
41  * @author <a HREF="mailto:jaz@ofbiz.org">Andy Zeneski</a>
42  * @version $Rev: 5462 $
43  * @since 3.1
44  */

45 public class PosContainer extends XuiContainer {
46
47     public String JavaDoc getContainerConfigName() {
48         return "pos-container";
49     }
50
51     public void configure(ContainerConfig.Container cc) throws ContainerException {
52         XuiSession session = XuiContainer.getSession();
53         GenericValue productStore = null;
54         GenericValue facility = null;
55
56         // get the facility id
57
String JavaDoc facilityId = ContainerConfig.getPropertyValue(cc, "facility-id", null);
58         if (UtilValidate.isEmpty(facilityId)) {
59             throw new ContainerException("No facility-id value set in pos-container!");
60         } else {
61             try {
62                 facility = session.getDelegator().findByPrimaryKey("Facility", UtilMisc.toMap("facilityId", facilityId));
63             } catch (GenericEntityException e) {
64                 throw new ContainerException("Invalid facilityId : " + facilityId);
65             }
66         }
67
68         // verify the facility exists
69
if (facility == null) {
70             throw new ContainerException("Invalid facility; facility ID not found [" + facilityId + "]");
71         }
72         session.setAttribute("facilityId", facilityId);
73         session.setAttribute("facility", facility);
74
75         // get the product store id
76
String JavaDoc productStoreId = facility.getString("productStoreId");
77         if (UtilValidate.isEmpty(productStoreId)) {
78             throw new ContainerException("No productStoreId set on facility [" + facilityId + "]!");
79         } else {
80             productStore = ProductStoreWorker.getProductStore(productStoreId, session.getDelegator());
81             if (productStore == null) {
82                 throw new ContainerException("Invalid productStoreId : " + productStoreId);
83             }
84         }
85         session.setAttribute("productStoreId", productStoreId);
86         session.setAttribute("productStore", productStore);
87
88         // get the store locale
89
String JavaDoc localeStr = ContainerConfig.getPropertyValue(cc, "locale", null);
90         if (UtilValidate.isEmpty(localeStr)) {
91             localeStr = productStore.getString("defaultLocaleString");
92         }
93         if (UtilValidate.isEmpty(localeStr)) {
94             throw new ContainerException("Invalid Locale for POS!");
95         }
96         Locale JavaDoc locale = UtilMisc.parseLocale(localeStr);
97         session.setAttribute("locale", locale);
98
99         // get the store currency
100
String JavaDoc currencyStr = ContainerConfig.getPropertyValue(cc, "currency", null);
101         if (UtilValidate.isEmpty(currencyStr)) {
102             currencyStr = productStore.getString("defaultCurrencyUomId");
103         }
104         if (UtilValidate.isEmpty(currencyStr)) {
105             throw new ContainerException("Invalid Currency for POS!");
106         }
107         session.setAttribute("currency", currencyStr);
108     }
109 }
110
Popular Tags