KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > SelectionPersonStructField


1 /*
2  * Created on Nov 21, 2004
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.person;
7
8 import java.util.Collection JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11
12 import com.nightlabs.ipanema.base.DuplicateKeyException;
13
14 /**
15  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
16  */

17 /**
18  * @jdo.persistence-capable
19  * identity-type = "application"
20  * persistence-capable-superclass="com.nightlabs.ipanema.person.AbstractPersonStructField"
21  * detachable = "true"
22  *
23  * @jdo.inheritance strategy = "new-table"
24  */

25 public class SelectionPersonStructField extends AbstractPersonStructField {
26
27     /**
28      * @jdo.field
29      * persistence-modifier="persistent"
30      * collection-type="map"
31      * key-type="java.lang.String"
32      * value-type="com.nightlabs.ipanema.person.PersonStructFieldValue"
33      * mapped-by="personStructField"
34      * dependent="true"
35      *
36      * @jdo.map-vendor-extension vendor-name="jpox" key="key-field" value="personStructFieldValueID"
37      */

38     protected Map JavaDoc personStructFieldValues = new HashMap JavaDoc();
39     
40     public Collection JavaDoc getPersonStructFieldValues() {
41         return personStructFieldValues.values();
42     }
43     
44     /**
45      * Returns the {@link PersonStructFieldValue} with the given personStructFieldValueID.
46      * If no entry is found for this id a {@link PersonStructFieldValueNotFoundException}
47      * is thrown.
48      * @param personStructFieldValueID
49      * @return
50      * @throws PersonStructFieldValueNotFoundException
51      */

52     public PersonStructFieldValue getPersonStructFieldValue(String JavaDoc personStructFieldValueID)
53     throws PersonStructFieldValueNotFoundException
54     {
55       PersonStructFieldValue psfv = (PersonStructFieldValue)personStructFieldValues.get(personStructFieldValueID);
56       if (psfv == null) {
57         throw new PersonStructFieldValueNotFoundException("No PersonStructFieldValue with ID \""+personStructFieldValueID+"\" existent in PersonStructField \""+getPersonStructFieldID()+"\" in PersonStructBlock \""+getPersonStructBlockID()+"\"!");
58       }
59         return psfv;
60     }
61     
62     /**
63      * Creates a new {@link PersonStructFieldValue} registers it in
64      * the Map and returns it.
65      * @param personStructFieldValueID
66      * @return
67      */

68     public PersonStructFieldValue newPersonStructFieldValue(String JavaDoc personStructFieldValueID) {
69         PersonStructFieldValue psfv = new PersonStructFieldValue(this, personStructFieldValueID);
70       personStructFieldValues.put(personStructFieldValueID, psfv);
71       return psfv;
72     }
73
74     /**
75      * Adds an instance of {@link SelectionPersonDataField}
76      * @see com.nightlabs.ipanema.person.AbstractPersonStructField#getRepresentationDataClass()
77      */

78     public AbstractPersonDataField addNewDataFieldInstance(PersonDataBlock dataBlock) {
79         SelectionPersonDataField newInstance = new SelectionPersonDataField(dataBlock,this);
80         try {
81             dataBlock.addPersonDataField(newInstance);
82         } catch (DuplicateKeyException e) {
83             throw new RuntimeException JavaDoc("Caught DuplicateKeyException when adding new instance of SelectionPersonDataField ("+newInstance.getPersonStructBlockOrganisationID()+", "+newInstance.getPersonStructBlockID()+") to dataBlock ("+dataBlock.getPersonStructBlockOrganisationID()+", "+dataBlock.getOrganisationID());
84         }
85         return newInstance;
86     }
87
88 }
89
Popular Tags