KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > accounting > Tariff


1 /*
2  * Created on 14.11.2004
3  */

4 package com.nightlabs.ipanema.accounting;
5
6 import java.io.Serializable JavaDoc;
7
8 import javax.jdo.JDOHelper;
9 import javax.jdo.PersistenceManager;
10 import javax.jdo.StoreCallback;
11
12 import com.nightlabs.i18n.Localizable;
13 import com.nightlabs.jdo.LocalizedDetachable;
14
15 /**
16  * TODO Shall I really put this class into IpanemaTrade? Or is it Ticketing specific?
17  * Does it help me here or does it make things complicated?
18  * To have it here makes sense, if I define directly in CustomerGroup which Tariffs
19  * they're allowed to sell. Or should I better use our Authority based ACL to manage
20  * Tariffs? Or should a CustomerGroup automatically create an Authority? That seems to
21  * make sense. We wanted to make Authorities markable "internal" and then use them for
22  * such purposes...
23  *
24  * @author Marco Schulze - marco at nightlabs dot de
25  *
26  * @jdo.persistence-capable
27  * identity-type = "application"
28  * objectid-class = "com.nightlabs.ipanema.accounting.id.TariffID"
29  * detachable = "true"
30  *
31  * @jdo.inheritance strategy = "new-table"
32  */

33 public class Tariff
34     implements Serializable JavaDoc, StoreCallback, Localizable, LocalizedDetachable
35 {
36     /**
37      * @jdo.field primary-key="true"
38      * @jdo.column length="100"
39      */

40     private String JavaDoc organisationID;
41
42     /**
43      * @jdo.field primary-key="true"
44      */

45     private long tariffID = -1;
46
47     /**
48      * @jdo.field persistence-modifier="persistent"
49      */

50     private String JavaDoc primaryKey;
51
52     /**
53      * @jdo.field persistence-modifier="persistent"
54      */

55     private TariffName name;
56
57     public Tariff() { }
58
59     public Tariff(String JavaDoc organisationID)
60     {
61         this.organisationID = organisationID;
62 // this.tariffID = tariffID;
63
this.primaryKey = getPrimaryKey(organisationID, tariffID);
64         this.name = new TariffName(this);
65     }
66
67     public static String JavaDoc getPrimaryKey(String JavaDoc organisationID, long tariffID)
68     {
69         return organisationID + '/' + Long.toHexString(tariffID);
70     }
71
72     /**
73      * @return Returns the organisationID.
74      */

75     public String JavaDoc getOrganisationID()
76     {
77         return organisationID;
78     }
79     /**
80      * @return Returns the tariffID.
81      */

82     public long getTariffID()
83     {
84 // if (tariffID == null)
85
// return -1;
86
return tariffID;
87     }
88     /**
89      * @param tariffID The tariffID to set.
90      */

91     public void setTariffID(long tariffID)
92     {
93         this.tariffID = tariffID;
94         this.primaryKey = getPrimaryKey(getOrganisationID(), tariffID);
95     }
96 // public static String getPrimaryKey(String organisationID, String tariffID)
97
// {
98
// return organisationID + '/' + tariffID;
99
// }
100
/**
101      * @return Returns the primaryKey.
102      */

103     public String JavaDoc getPrimaryKey()
104     {
105         return primaryKey;
106     }
107     
108     /**
109      * @see javax.jdo.StoreCallback#jdoPreStore()
110      */

111     public void jdoPreStore()
112     {
113         if (tariffID < 0) {
114             PersistenceManager pm = JDOHelper.getPersistenceManager(this);
115             this.setTariffID(
116                     TariffRegistry.getTariffRegistry(pm).createTariffID());
117         }
118     }
119
120     /**
121      * @return Returns the name.
122      */

123     public TariffName getName()
124     {
125         return name;
126     }
127
128     /**
129      * @see com.nightlabs.i18n.Localizable#localize(java.lang.String)
130      */

131     public void localize(String JavaDoc languageID)
132     {
133         name.localize(languageID);
134     }
135
136     /**
137      * @see com.nightlabs.jdo.LocalizedDetachable#detachCopyLocalized(java.lang.String, javax.jdo.PersistenceManager)
138      */

139     public LocalizedDetachable detachCopyLocalized(String JavaDoc languageID, PersistenceManager pm)
140     {
141         Tariff tariff = (Tariff) pm.detachCopy(this);
142         tariff.name.localize(languageID, this.name);
143         return tariff;
144     }
145 }
146
Popular Tags