KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jacorb.trading.impl;
2
3 import org.omg.CORBA.*;
4 import org.omg.CosTrading.LinkPackage.*;
5 import org.omg.CosTrading.*;
6 import java.util.*;
7
8 /**
9  * This class implements the Link-interface from CosTrading.
10  * It is mainly for administrating the links of the trader
11  *
12  * @author Nicolas Noffke
13  */

14
15 public class LinkImpl
16     extends org.omg.CosTrading.LinkPOA
17     implements LinkOperations
18 {
19
20     private TraderComp m_traderComp;
21     private SupportAttrib m_support;
22     private LinkAttrib m_link;
23
24     private Hashtable m_current_links; // all LinkInfo-Instances are stored here
25
private boolean m_links_changed = true; // indicates, if links have been added, removed or modidfied
26

27
28     /**
29      * The constructor of LinkImpl.
30      *
31      * @param trader_comp The TraderComp-object of this trader
32      * @param support The SupportAttrib-object of this trader
33      * @param link The LinkAttrib-object of this trader
34      */

35     public LinkImpl (TraderComp trader_comp, SupportAttrib support, LinkAttrib link){
36     m_traderComp = trader_comp;
37     m_support = support;
38     m_link = link;
39     m_current_links = new Hashtable();
40     }
41
42     // operations inherited from CosTrading::TraderComponents
43

44     /**
45      * Returns the Lookup-Interface of this trader.<br>
46      * Inherited from CosTrading::TraderComponents
47      * @return The Lookup-Interface
48      */

49     public Lookup lookup_if()
50     {
51     return m_traderComp.getLookupInterface();
52     }
53     
54     /**
55      * Returns the Register-Interface of this trader.<br>
56      * Inherited from CosTrading::TraderComponents
57      * @return The Register-Interface
58      */

59     public Register register_if()
60     {
61     return m_traderComp.getRegisterInterface();
62     }
63     
64     /**
65      * Returns the Link-Interface of this trader.<br>
66      * Inherited from CosTrading::TraderComponents
67      * @return The Link-Interface
68      */

69     public Link link_if()
70     {
71     return m_traderComp.getLinkInterface();
72     }
73     
74     /**
75      * Returns the Proxy-Interface of this trader.<br>
76      * Inherited from CosTrading::TraderComponents
77      * @return The Proxy-Interface
78      */

79     public Proxy proxy_if()
80     {
81     return m_traderComp.getProxyInterface();
82     }
83     
84     /**
85      * Returns the Admin-Interface of this trader.<br>
86      * Inherited from CosTrading::TraderComponents
87      * @return The Admin-Interface
88      */

89     public Admin admin_if()
90     {
91     return m_traderComp.getAdminInterface();
92     }
93     
94     // operations inherited from CosTrading::SupportAttributes
95

96     /**
97      * Does this trader support modifiable properties.<br>
98      * Inherited from CosTrading::SupportAttributes
99      * @return True, if it supports them
100      */

101     public boolean supports_modifiable_properties()
102     {
103     return m_support.getModifiableProperties();
104     }
105     
106
107     /**
108      * Does this trader support dynamic properties.<br>
109      * Inherited from CosTrading::SupportAttributes
110      * @return True, if it supports them
111      */

112     public boolean supports_dynamic_properties()
113     {
114     return m_support.getDynamicProperties();
115     }
116     
117     
118    /**
119      * Does this trader support proxy offers.<br>
120      * Inherited from CosTrading::SupportAttributes
121      * @return True, if it supports them
122      */

123     public boolean supports_proxy_offers()
124     {
125     return m_support.getProxyOffers();
126     }
127     
128     
129    /**
130      * Returns the TypeRepository.<br>
131      * Inherited from CosTrading::SupportAttributes
132      * @return The TypeRepository
133      */

134     public org.omg.CORBA.Object JavaDoc type_repos()
135     {
136     return m_support.getTypeRepos();
137     }
138     
139
140     // operations inherited from CosTrading::LinkAttributes
141
/**
142      * Get the max_link_follow_policy of this trader.<br>
143      * Inherited from CosTrading::LinkAttributes
144      * @return The max_link_follow_policy
145      */

146     public FollowOption max_link_follow_policy()
147     {
148     return m_link.getMaxLinkFollowPolicy();
149     }
150
151     // operations inherited from CosTrading::LinkOperations
152
/**
153      * Adds a link to the specified Trader.<br>
154      * Inherited from CosTrading::LinkOperations
155      *
156      * @param name The name for this new link
157      * @param target The Lookup-Interface of the Trader to link to
158      * @param default_follow_rule The default_follow_rule
159      * @param limiting_follow_rule The limiting_follow_rule
160      * @exception org.omg.CosTrading.LinkPackage.IllegalLinkName Link name not allowed
161      * @exception org.omg.CosTrading.LinkPackage.DuplicateLinkName Link name already in usage
162      * @exception org.omg.CosTrading.InvalidLookupRef Lookup-reference is not ok
163      * @exception org.omg.CosTrading.LinkPackage.DefaultFollowTooPermissive default_follow_rule more permissive
164      * than limiting_follow_rule
165      * @exception org.omg.CosTrading.LinkPackage.LimitingFollowTooPermissive limiting_follow_rule more permissive
166      * than traders max_link_follow_policy
167      */

168     public void add_link(String JavaDoc name,
169              Lookup target,
170              FollowOption default_follow_rule,
171              FollowOption limiting_follow_rule)
172     throws IllegalLinkName,
173     DuplicateLinkName,
174     InvalidLookupRef,
175     DefaultFollowTooPermissive,
176     LimitingFollowTooPermissive {
177
178     // check parameters
179

180     // since there is no specification for a correct link name,
181
// we do just a simple check
182
// is name legal?
183
if (name == null || name.length() == 0)
184         throw new IllegalLinkName(name);
185
186     // duplicate name?
187
if (m_current_links.containsKey(name))
188         throw new DuplicateLinkName(name);
189
190     //invalid lookup refence?
191
Register _reg = null;
192     try {
193         org.omg.CORBA.Object JavaDoc _obj = target.register_if();
194         _reg = RegisterHelper.narrow(_obj);
195     }
196         catch (Exception JavaDoc e){
197         // if we get an exception here, we assume that the lookup reference is
198
// invalid. It might as well be an network error, but since we cannot
199
// confirm the lookup reference, we don't accept it.
200
throw new InvalidLookupRef(target);
201     }
202
203     // default_follow_rule too permissive?
204
if (default_follow_rule.value() > limiting_follow_rule.value())
205         throw new DefaultFollowTooPermissive(default_follow_rule, limiting_follow_rule);
206
207     // limiting_follow_rule too permissive?
208
if (limiting_follow_rule.value() > max_link_follow_policy().value())
209         throw new LimitingFollowTooPermissive(default_follow_rule, limiting_follow_rule);
210     
211     // everything o.k., so we create the new link
212
LinkInfo _info = new LinkInfo(target, _reg, default_follow_rule, limiting_follow_rule);
213     m_current_links.put(name, _info);
214
215     //set flag
216
m_links_changed = true;
217     }
218     
219     /**
220      * Get the LinkInfo-Object of a specific link.
221      * @param name The name of the link
222      * @return The LinkInfo-Object of this link
223      * @exception org.omg.CosTrading.LinkPackage.IllegalLinkName Link name not allowed
224      * @exception org.omg.CosTrading.LinkPackage.UnknownLinkName No link with that name
225      */

226     public LinkInfo describe_link(String JavaDoc name) throws IllegalLinkName, UnknownLinkName {
227     // is name legal?
228
if (name == null || name.length() == 0)
229         throw new IllegalLinkName(name);
230
231     // get LinkInfo
232
LinkInfo _result = (LinkInfo) m_current_links.get(name);
233
234     //check for UnknownLinkName (the key has no associated object)
235
if (_result == null)
236         throw new UnknownLinkName(name);
237
238     return _result;
239     }
240     
241     /**
242      * Lists all link-names.
243      * @return An array with all link names
244      */

245     public String JavaDoc[] list_links() {
246     String JavaDoc[] _links_array = new String JavaDoc[m_current_links.size()];
247     Enumeration _links = m_current_links.keys();
248     int _i = 0;
249
250     while (_links.hasMoreElements())
251         _links_array[_i++] = (String JavaDoc) _links.nextElement();
252
253     return _links_array;
254     }
255     
256     /**
257      * Modify an existing link.
258      * @param name The name of the link to modify
259      * @param default_follow_rule The new default_follow_rule for this link
260      * @param limiting_follow_rule The new limiting_follow_rule for this link
261      * @exception org.omg.CosTrading.LinkPackage.IllegalLinkName Link name not allowed
262      * @exception org.omg.CosTrading.LinkPackage.UnknownLinkName No link for that name exists
263      * @exception org.omg.CosTrading.LinkPackage.DefaultFollowTooPermissive default_follow_rule more permissive
264      * than limiting_follow_rule
265      * @exception org.omg.CosTrading.LinkPackage.LimitingFollowTooPermissive limiting_follow_rule more permissive
266      * than traders max_link_follow_policy
267      */

268     public void modify_link(String JavaDoc name,
269                 FollowOption default_follow_rule,
270                 FollowOption limiting_follow_rule)
271     throws IllegalLinkName, UnknownLinkName,
272     DefaultFollowTooPermissive, LimitingFollowTooPermissive {
273     // check parameters
274

275     // since there is no specification for a correct link name,
276
// we do just a simple check
277
// is name legal?
278
if (name == null || name.length() == 0)
279         throw new IllegalLinkName(name);
280
281     // is name known?
282
if (! m_current_links.containsKey(name))
283         throw new UnknownLinkName(name);
284
285     // default_follow_rule too permissive?
286
if (default_follow_rule.value() > limiting_follow_rule.value())
287         throw new DefaultFollowTooPermissive(default_follow_rule, limiting_follow_rule);
288
289     // limiting_follow_rule too permissive?
290
if (limiting_follow_rule.value() > max_link_follow_policy().value())
291         throw new LimitingFollowTooPermissive(default_follow_rule, limiting_follow_rule);
292     
293     // everything o.k., so we can fetch and modify the link
294
LinkInfo _link = (LinkInfo) m_current_links.get(name);
295     _link.def_pass_on_follow_rule = default_follow_rule;
296     _link.limiting_follow_rule = limiting_follow_rule;
297
298     //set flag
299
m_links_changed = true;
300     }
301     
302     /**
303      * Remove a specific link.
304      * @param name The name of the link to remove
305      * @exception org.omg.CosTrading.LinkPackage.IllegalLinkName Link name not allowed
306      * @exception org.omg.CosTrading.LinkPackage.UnknownLinkName No link for that name exists
307      */

308     public void remove_link(String JavaDoc name) throws IllegalLinkName, UnknownLinkName {
309     // check parameters
310

311     // since there is no specification for a correct link name,
312
// we do just a simple check
313
// is name legal?
314
if (name == null || name.length() == 0)
315         throw new IllegalLinkName(name);
316
317     // is name known?
318
if (! m_current_links.containsKey(name))
319         throw new UnknownLinkName(name);
320
321     // o.k. to remove
322
m_current_links.remove(name);
323     
324     //set flag
325
m_links_changed = true;
326     }
327
328     /**
329      * Check, if any links have been added, removed or modified.<br>
330      * *NOT* inherited from anywhere.
331      * @return True, if anything changed
332      */

333     public boolean linksChanged(){
334     return m_links_changed;
335     }
336
337     /**
338      * Get the links of this trader.<br>
339      * *NOT* inherited from anywhere.
340      * @return All LinkInfo-objects of this trader
341      */

342     public LinkInfo[] getLinks(){
343     LinkInfo[] _links_array = new LinkInfo[m_current_links.size()];
344     Enumeration _links = m_current_links.elements();
345     int _i = 0;
346
347     while (_links.hasMoreElements())
348         _links_array[_i++] = (LinkInfo) _links.nextElement();
349
350     //reset flag
351
m_links_changed = false;
352
353     return _links_array;
354     }
355     
356 } // LinkImpl
357

358
359
360
Popular Tags