KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > accounting > tariffpriceconfig > TariffPriceConfig


1 /*
2  * Created on Feb 26, 2005
3  */

4 package com.nightlabs.ipanema.accounting.tariffpriceconfig;
5
6 import java.util.Collection JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.Map JavaDoc;
9
10 import com.nightlabs.ipanema.accounting.CustomerGroup;
11 import com.nightlabs.ipanema.accounting.Price;
12 import com.nightlabs.ipanema.accounting.PriceConfig;
13 import com.nightlabs.ipanema.accounting.Tariff;
14 import com.nightlabs.ipanema.trade.OfferItem;
15
16 /**
17  * This implementation of <tt>PriceConfig</tt> manages cells
18  * that are dependent on <tt>CustomerGroup</tt> and <tt>Tariff</tt>.
19  * Each of these parameters must be imported using one of the methods
20  * <tt>addCustomerGroup(..)</tt> or <tt>addTariff</tt>.
21  *
22  * @author Marco Schulze - marco at nightlabs dot de
23  *
24  * @jdo.persistence-capable
25  * identity-type = "application"
26  * persistence-capable-superclass = "com.nightlabs.ipanema.accounting.PriceConfig"
27  * detachable = "true"
28  *
29  * @jdo.inheritance strategy = "new-table"
30  */

31 public abstract class TariffPriceConfig extends PriceConfig
32 {
33     /**
34      * key: String customerGroupPK<br/>
35      * value: CustomerGroup customerGroup
36      *
37      * @jdo.field
38      * persistence-modifier="persistent"
39      * collection-type="map"
40      * key-type="java.lang.String"
41      * value-type="CustomerGroup"
42      *
43      * @jdo.join
44      */

45     private Map JavaDoc customerGroups = new HashMap JavaDoc();
46
47     /**
48      * key: String tariffPK<br/>
49      * value: Tariff tariff
50      *
51      * @jdo.field
52      * persistence-modifier="persistent"
53      * collection-type="map"
54      * key-type="java.lang.String"
55      * value-type="Tariff"
56      *
57      * @jdo.join
58      */

59     private Map JavaDoc tariffs = new HashMap JavaDoc();
60
61     protected TariffPriceConfig()
62     {
63     }
64     /**
65      * @param organisationID
66      * @param priceConfigID
67      */

68     public TariffPriceConfig(String JavaDoc organisationID, long priceConfigID)
69     {
70         super(organisationID, priceConfigID);
71     }
72
73     /**
74      * @see com.nightlabs.ipanema.accounting.PriceConfig#getPrice(com.nightlabs.ipanema.trade.OfferItem)
75      */

76     public Price getPrice(OfferItem offerItem)
77     {
78         return null;
79     }
80
81     /**
82      * @see com.nightlabs.ipanema.accounting.PriceConfig#isDependentOnOffer()
83      */

84     public boolean isDependentOnOffer()
85     {
86         return false;
87     }
88     
89     
90     /**
91      * @return Returns the customerGroups.
92      */

93     public Collection JavaDoc getCustomerGroups()
94     {
95         return customerGroups.values();
96     }
97     public void addCustomerGroup(CustomerGroup customerGroup)
98     {
99         customerGroups.put(customerGroup.getPrimaryKey(), customerGroup);
100     }
101     public CustomerGroup getCustomerGroup(String JavaDoc organisationID, String JavaDoc customerGroupID, boolean throwExceptionIfNotExistent)
102     {
103         CustomerGroup customerGroup = (CustomerGroup) customerGroups.get(CustomerGroup.getPrimaryKey(organisationID, customerGroupID));
104         if (customerGroup == null && throwExceptionIfNotExistent)
105             throw new IllegalArgumentException JavaDoc("No CustomerGroup registered with organisationID=\""+organisationID+"\" customerGroupID=\""+customerGroupID+"\"!");
106         return customerGroup;
107     }
108     public boolean containsCustomerGroup(CustomerGroup customerGroup)
109     {
110         return customerGroups.containsKey(customerGroup.getPrimaryKey());
111     }
112     public CustomerGroup removeCustomerGroup(String JavaDoc organisationID, String JavaDoc customerGroupID)
113     {
114         return (CustomerGroup) customerGroups.remove(
115                 CustomerGroup.getPrimaryKey(organisationID, customerGroupID));
116     }
117     
118     /**
119      * @return Returns the tariffs.
120      */

121     public Collection JavaDoc getTariffs()
122     {
123         return tariffs.values();
124     }
125     public void addTariff(Tariff tariff)
126     {
127         tariffs.put(tariff.getPrimaryKey(), tariff);
128     }
129     public Tariff getTariff(String JavaDoc organisationID, long tariffID, boolean throwExceptionIfNotExistent)
130     {
131         Tariff tariff = (Tariff) tariffs.get(Tariff.getPrimaryKey(organisationID, tariffID));
132         if (tariff == null && throwExceptionIfNotExistent)
133             throw new IllegalArgumentException JavaDoc("There is no Tariff registered with organisationID=\""+organisationID+"\" tariffID=\""+tariffID+"\"!");
134
135         return tariff;
136     }
137     public boolean containsTariff(Tariff tariff)
138     {
139         return tariffs.containsKey(tariff.getPrimaryKey());
140     }
141     public Tariff removeTariff(String JavaDoc organisationID, long tariffID)
142     {
143         return (Tariff) tariffs.remove(Tariff.getPrimaryKey(organisationID, tariffID));
144     }
145 }
146
Popular Tags