KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > demo1 > FormImpl


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): Alex Andrushchak.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.demo1;
28
29 /**
30  * This is the client application to access Form.
31  *
32  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
33  *
34  * @version 0.1
35  */

36 public class FormImpl
37      extends FormPOA
38 {
39     // ==================================================================
40
//
41
// Internal state.
42
//
43
// ==================================================================
44

45     /** The basic session */
46     org.omg.CosPersistentState.Session _session;
47
48     /** The Person storage home */
49     SH_Person _person_home;
50
51     /** The Address storage home */
52     SH_Address _address_home;
53
54     // ==================================================================
55
//
56
// Constructor.
57
//
58
// ==================================================================
59

60     /**
61      * Default Constructor.
62      *
63      * @param session - The PSS session associated to this Form.
64      */

65     public FormImpl(org.omg.CosPersistentState.Session session)
66     {
67         _session = session;
68         try
69         {
70             _person_home = (SH_Person)
71                                 _session.find_storage_home("PSDL:openccm.objectweb.org/pss/demo1/SH_Person:1.0");
72         }catch(org.omg.CosPersistentState.NotFound e){
73             e.printStackTrace();
74         }
75         try
76         {
77             _address_home = (SH_Address)
78                                 _session.find_storage_home("PSDL:openccm.objectweb.org/pss/demo1/SH_Address:1.0");
79         }catch(org.omg.CosPersistentState.NotFound e){
80             e.printStackTrace();
81         }
82     }
83
84     // ==================================================================
85
//
86
// Internal methods.
87
//
88
// ==================================================================
89

90     // ==================================================================
91
//
92
// Public methods.
93
//
94
// ==================================================================
95

96     /**
97      * Operation createPerson
98      */

99     public void
100     createPerson( String JavaDoc first_name,
101                   String JavaDoc last_name,
102                   int age,
103                   String JavaDoc address_line1,
104                   String JavaDoc address_line2,
105                   String JavaDoc address_city,
106                   String JavaDoc address_zip)
107     {
108         Address a = null;
109         Person p = null;
110
111         try{
112             a = _address_home._create( address_line1, address_line2, address_city, address_zip );
113
114             p = _person_home.my_create( first_name, last_name );
115         }catch( Exception JavaDoc e ){
116             e.printStackTrace();
117         }
118
119         try{
120             org.omg.CosPersistentState.CatalogBase cat = null;
121
122             // Get the session
123
cat = p.get_storage_home().get_catalog();
124
125             // Update the storage type
126
p.age(age);
127             p.adress( a.get_pid() );
128             cat.flush();
129         }catch(Exception JavaDoc e){
130             e.printStackTrace();
131         }
132     }
133
134     /**
135      * Operation removePerson
136      */

137     public void removePerson( java.lang.String JavaDoc first_name,
138                               java.lang.String JavaDoc last_name )
139     {
140         Person p = null;
141         Address adr = null;
142
143         try
144         {
145             p = _person_home.find_by_mykey( first_name, last_name );
146             adr = p.adress();
147
148             if ( adr != null )
149             {
150                 adr.destroy_object();
151             }
152             p.destroy_object();
153         }
154         catch ( org.omg.CosPersistentState.NotFound ex )
155         {
156             System.out.println( "This person was not found..." );
157         }
158         catch( Exception JavaDoc e )
159         {
160             e.printStackTrace();
161         }
162     }
163
164     /**
165      * Operation showPerson
166      */

167     public String JavaDoc showPerson( java.lang.String JavaDoc first_name,
168                               java.lang.String JavaDoc last_name )
169     {
170         try
171         {
172             Person p = _person_home.find_by_mykey( first_name, last_name );
173
174             return p.print();
175         }
176         catch ( org.omg.CosPersistentState.NotFound ex )
177         {
178             return "This person was not found...\n";
179         }
180         catch( Exception JavaDoc e )
181         {
182             e.printStackTrace();
183         }
184         return null;
185     }
186 }
187
Popular Tags