KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > trading > impl > ProxyImpl


1
2 // Copyright (C) 1998-1999
3
// Object Oriented Concepts, Inc.
4

5 // **********************************************************************
6
//
7
// Copyright (c) 1997
8
// Mark Spruiell (mark@intellisoft.com)
9
//
10
// See the COPYING file for more information
11
//
12
// **********************************************************************
13

14 package org.jacorb.trading.impl;
15
16 import java.util.*;
17 import org.omg.CORBA.*;
18 import org.omg.CosTrading.*;
19 import org.omg.CosTrading.ProxyPackage.*;
20 import org.omg.CosTradingRepos.*;
21 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.*;
22 import org.jacorb.trading.db.OfferDatabase;
23 import org.jacorb.trading.util.*;
24
25
26 /**
27  * Implementation of CosTrading::Proxy
28  */

29 public class ProxyImpl extends ProxyPOA // GB: instead of _ProxyBaseImpl
30
{
31   private TraderComp m_traderComp;
32   private SupportAttrib m_support;
33   private OfferDatabase m_db;
34   private ServiceTypeRepository m_repos;
35
36
37   private ProxyImpl()
38   {
39   }
40
41
42   public ProxyImpl(
43     TraderComp traderComp,
44     SupportAttrib supportAttrib,
45     OfferDatabase db)
46   {
47     m_traderComp = traderComp;
48     m_support = supportAttrib;
49     m_db = db;
50     org.omg.CORBA.Object JavaDoc obj = supportAttrib.getTypeRepos();
51     m_repos = ServiceTypeRepositoryHelper.narrow(obj);
52   }
53
54
55     // operations inherited from CosTrading::TraderComponents
56

57   public Lookup lookup_if()
58   {
59     return m_traderComp.getLookupInterface();
60   }
61
62
63   public Register register_if()
64   {
65     return m_traderComp.getRegisterInterface();
66   }
67
68
69   public Link link_if()
70   {
71     return m_traderComp.getLinkInterface();
72   }
73
74
75   public Proxy proxy_if()
76   {
77     return m_traderComp.getProxyInterface();
78   }
79
80
81   public Admin admin_if()
82   {
83     return m_traderComp.getAdminInterface();
84   }
85
86
87     // operations inherited from CosTrading::SupportAttributes
88

89   public boolean supports_modifiable_properties()
90   {
91     return m_support.getModifiableProperties();
92   }
93
94
95   public boolean supports_dynamic_properties()
96   {
97     return m_support.getDynamicProperties();
98   }
99
100
101   public boolean supports_proxy_offers()
102   {
103     return m_support.getProxyOffers();
104   }
105
106
107   public org.omg.CORBA.Object JavaDoc type_repos()
108   {
109     return m_support.getTypeRepos();
110   }
111
112
113     // operations inherited from CosTrading::Proxy
114

115   public String JavaDoc export_proxy(
116     Lookup target,
117     String JavaDoc type,
118     Property[] properties,
119     boolean if_match_all,
120     String JavaDoc recipe,
121     org.omg.CosTrading.Policy[] policies_to_pass_on)
122     throws IllegalServiceType,
123            UnknownServiceType,
124            InvalidLookupRef,
125            IllegalPropertyName,
126            PropertyTypeMismatch,
127            ReadonlyDynamicProperty,
128            MissingMandatoryProperty,
129            IllegalRecipe,
130            DuplicatePropertyName,
131            DuplicatePolicyName
132   {
133     String JavaDoc result = null;
134
135     if (target == null)
136       throw new InvalidLookupRef(target);
137
138       // retrieve complete information about the service type from the
139
// repository - may throw IllegalServiceType, UnknownServiceType
140
TypeStruct ts = m_repos.fully_describe_type(type);
141
142       // do not allow exporting for a masked service type
143
if (ts.masked)
144       throw new UnknownServiceType(type);
145
146       // validate the exported properties - may throw
147
// IllegalPropertyName, PropertyTypeMismatch,
148
// MissingMandatoryProperty, DuplicatePropertyName
149
OfferUtil.validateProperties(m_db, properties, type, ts);
150
151       // validate the recipe
152
if (! Recipe.validate(recipe, properties))
153       throw new IllegalRecipe(recipe);
154
155       // check for duplicate policies
156
Hashtable policyTable = new Hashtable();
157     for (int i = 0; i < policies_to_pass_on.length; i++) {
158       if (policyTable.containsKey(policies_to_pass_on[i].name))
159         throw new DuplicatePolicyName(policies_to_pass_on[i].name);
160       else
161         policyTable.put(policies_to_pass_on[i].name, policies_to_pass_on[i]);
162     }
163
164       // save the offer in the database
165

166     m_db.begin(OfferDatabase.WRITE);
167
168     try {
169       result = m_db.createProxy(target, type, properties, if_match_all,
170         recipe, policies_to_pass_on);
171     }
172     finally {
173       m_db.end();
174     }
175
176     return result;
177   }
178
179
180   public void withdraw_proxy(String JavaDoc id)
181     throws IllegalOfferId,
182            UnknownOfferId,
183            NotProxyOfferId
184   {
185     if (! m_db.validateOfferId(id))
186       throw new IllegalOfferId(id);
187
188     m_db.begin(OfferDatabase.WRITE);
189
190     try {
191       if (! m_db.exists(id))
192         throw new UnknownOfferId(id);
193
194       if (! m_db.isProxy(id))
195         throw new NotProxyOfferId(id);
196
197       m_db.removeProxy(id);
198     }
199     finally {
200       m_db.end();
201     }
202   }
203
204
205   public ProxyInfo describe_proxy(String JavaDoc id)
206     throws IllegalOfferId,
207            UnknownOfferId,
208            NotProxyOfferId
209   {
210     ProxyInfo result;
211
212     if (! m_db.validateOfferId(id))
213       throw new IllegalOfferId(id);
214
215     m_db.begin(OfferDatabase.READ);
216
217     try {
218       if (! m_db.exists(id))
219         throw new UnknownOfferId(id);
220
221       if (! m_db.isProxy(id))
222         throw new NotProxyOfferId(id);
223
224       result = m_db.describeProxy(id);
225     }
226     finally {
227       m_db.end();
228     }
229
230     return result;
231   }
232 }
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
Popular Tags