KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Created on 30.10.2004
3  */

4 package com.nightlabs.ipanema.accounting;
5
6 import java.io.Serializable JavaDoc;
7
8 import javax.jdo.JDOObjectNotFoundException;
9 import javax.jdo.PersistenceManager;
10
11 import com.nightlabs.ipanema.accounting.id.PriceFragmentTypeID;
12 import com.nightlabs.ipanema.organisation.Organisation;
13
14 /**
15  * A PriceFragmentType defines a part out of which a <tt>Price</tt> may consist.
16  * Normally, these are taxes. Examples are: vat-de-16, vat-de-7 or vat-ch-6_5
17  * <br/><br/>
18  * Not all <tt>Price</tt> s contain <tt>PriceFragment</tt> s for all <tt>PriceFragmentType</tt> s.
19  * <tt>PriceFragmentType</tt> s are defined globally, but that does not mean that
20  * every organisation knows all of them.
21  *
22  * @author Marco Schulze - marco at nightlabs dot de
23  *
24  * @jdo.persistence-capable
25  * identity-type = "application"
26  * objectid-class = "com.nightlabs.ipanema.accounting.id.PriceFragmentTypeID"
27  * detachable = "true"
28  *
29  * @jdo.inheritance strategy = "new-table"
30  */

31 public class PriceFragmentType
32     implements Serializable JavaDoc
33 {
34     /**
35      * @jdo.field primary-key="true"
36      * @jdo.column length="100"
37      */

38     private String JavaDoc organisationID;
39
40     /**
41      * @jdo.field primary-key="true"
42      * @jdo.column length="100"
43      */

44     private String JavaDoc priceFragmentTypeID;
45
46     protected PriceFragmentType() { }
47
48     public PriceFragmentType(String JavaDoc organisationID, String JavaDoc priceFragmentTypeID)
49     {
50         this.organisationID = organisationID;
51         this.priceFragmentTypeID = priceFragmentTypeID;
52     }
53     /**
54      * @return Returns the organisationID.
55      */

56     public String JavaDoc getOrganisationID()
57     {
58         return organisationID;
59     }
60     /**
61      * @return Returns the priceFragmentTypeID.
62      */

63     public String JavaDoc getPriceFragmentTypeID()
64     {
65         return priceFragmentTypeID;
66     }
67     public String JavaDoc getPrimaryKey()
68     {
69         return organisationID + '/' + priceFragmentTypeID;
70     }
71     public static String JavaDoc getPrimaryKey(String JavaDoc organisationID, String JavaDoc priceFragmentTypeID)
72     {
73         return organisationID + '/' + priceFragmentTypeID;
74     }
75
76     /**
77      * This predefined priceFragmentType exists to allow a unified API for accesses
78      * to the priceFragments and the <tt>Price.amount</tt>. This is necessary e.g. in
79      * formulas.
80      *
81      * @see Price#getAmount(String)
82      * @see Price#setAmount(String, long)
83      */

84     public static final String JavaDoc TOTAL_PRICEFRAGMENTTYPEID = "_Total_";
85
86     /**
87      * @return Returns the special predefined <tt>PriceFragmentType</tt> that represents the total price.
88      * The total price is no real price fragment, but can be managed by this <tt>PriceFragmentType</tt>
89      * to make formulas easier.
90      */

91     public static PriceFragmentType getTotalPriceFragmentType(PersistenceManager pm)
92     {
93         pm.getExtent(PriceFragmentType.class);
94         PriceFragmentType priceFragmentType;
95         try {
96             priceFragmentType = (PriceFragmentType) pm.getObjectById(PriceFragmentTypeID.create(
97                     Organisation.ROOT_ORGANISATIONID, PriceFragmentType.TOTAL_PRICEFRAGMENTTYPEID));
98         } catch (JDOObjectNotFoundException x) {
99             priceFragmentType = new PriceFragmentType(Organisation.ROOT_ORGANISATIONID, PriceFragmentType.TOTAL_PRICEFRAGMENTTYPEID);
100             pm.makePersistent(priceFragmentType);
101         }
102         return priceFragmentType;
103     }
104 }
105
Popular Tags