KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > portableInterceptor > IORInfoImpl


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21 package org.jacorb.orb.portableInterceptor;
22
23 import org.omg.PortableInterceptor.*;
24 import org.omg.IOP.*;
25 import org.omg.CORBA.*;
26 import org.omg.ETF.Profile;
27
28 import org.jacorb.orb.ORB;
29 import org.jacorb.orb.MinorCodes;
30 import org.jacorb.orb.TaggedComponentList;
31 import org.jacorb.poa.POA;
32
33 import java.util.*;
34
35 /**
36  * This class represents the type of info object
37  * that will be passed to the IORInterceptors. <br>
38  * See PI Spec p.7-64f
39  *
40  * @author Nicolas Noffke
41  * @version $Id: IORInfoImpl.java,v 1.13 2004/05/06 12:40:00 nicolas Exp $
42  */

43
44 public class IORInfoImpl extends org.omg.CORBA.LocalObject JavaDoc
45                          implements IORInfoExt
46 {
47     /**
48      * Maps profile tags to component lists (Integer -> TaggedComponentList).
49      */

50     private Map components = null;
51     
52     private Map policy_overrides = null;
53   
54     private ORB orb = null;
55     private POA poa = null;
56     private List _profiles = null;
57   
58     public IORInfoImpl (ORB orb, POA poa,
59                         Map components, Map policy_overrides,
60                         List profiles)
61     {
62         this.orb = orb;
63         this.poa = poa;
64         this.components = components;
65         this.policy_overrides = policy_overrides;
66         this._profiles = profiles;
67     }
68
69     /**
70      * Adds component to all profiles.
71      */

72     public void add_ior_component (TaggedComponent component)
73     {
74         for (Iterator i = components.values().iterator(); i.hasNext();)
75         {
76             TaggedComponentList l = (TaggedComponentList)i.next();
77             l.addComponent (component);
78         }
79     }
80
81     /**
82      * Adds the component to the profile with the given tag.
83      */

84     public void add_ior_component_to_profile(TaggedComponent component, int id)
85     {
86         TaggedComponentList l =
87             (TaggedComponentList)components.get (new Integer JavaDoc (id));
88         if (l == null)
89         {
90             throw new org.omg.CORBA.BAD_PARAM JavaDoc
91             (
92                 "unknown profile tag: " + id,
93                 MinorCodes.NO_SUCH_PROFILE,
94                 CompletionStatus.COMPLETED_MAYBE
95             );
96         }
97         else
98         {
99             l.addComponent (component);
100         }
101     }
102
103     /**
104      * @return a policy of the given type, or null,
105      * if no policy of that type is present.
106      */

107     public Policy get_effective_policy(int type)
108     {
109         if (!orb.hasPolicyFactoryForType(type))
110         {
111             throw new org.omg.CORBA.INV_POLICY JavaDoc
112             (
113                 "No PolicyFactory for type " + type +
114                 " has been registered!",
115                 MinorCodes.NO_SUCH_POLICY,
116                 CompletionStatus.COMPLETED_MAYBE
117             );
118         }
119         else
120         {
121             Policy policy = null;
122             if (policy_overrides != null)
123             {
124                policy = (Policy)policy_overrides.get (new Integer JavaDoc(type));
125             }
126             return (policy != null) ? policy : poa.getPolicy(type);
127         }
128     }
129
130     /**
131      * This method adds a further profile to an IOR.
132      * By using this method it is possible to append e.g. further IIOP
133      * profiles. The added profile is marshalled after all profiles
134      * already existing in profile list.
135      * @param profile the profile to add
136      */

137     public void add_profile(Profile profile)
138     {
139        if( _profiles != null )
140        {
141           _profiles.add(profile);
142        }
143
144     }
145
146     /**
147      * This method returns the number of profiles of the given type.
148      * The returned value can be used to iterate over the existing
149      * profiles of given type (get_profile()).
150      * @param tag profile tag, e.g. TAG_INTERNET_IOP.value
151      * @return number of profiles of given tag
152      */

153     public int get_number_of_profiles(int tag)
154     {
155        int retVal = 0;
156        for (int i=0; i < _profiles.size(); i++)
157        {
158            Profile p = (Profile) _profiles.get(i);
159            if ( p.tag() == tag )
160               retVal++;
161        }
162        return retVal;
163     }
164
165     /**
166      * Returns the profile with the given tag at the given position.
167      * Following rule must apply to parameter position:<p>
168      * <code> 0 <= position < get_number_of_profiles(tag) </code><p>
169      * @param tag tag of profile, e.g. TAG_INTERNET_IOP.value
170      * @param position position in IOR
171      * @return profile
172      * @exception ArrayIndexOutOfBoundsException if position is
173      * out of range
174      */

175     public org.omg.ETF.Profile get_profile(int tag, int position)
176     {
177        int cnt = position;
178        Profile retVal = null;
179        for (int i=0; i < _profiles.size(); i++)
180        {
181            Profile p = (Profile) _profiles.get(i);
182            if ( p.tag() == tag && cnt == 0)
183            {
184               retVal = p;
185               break;
186            }
187            else
188            {
189               cnt--;
190            }
191        }
192        if( retVal == null )
193          throw new ArrayIndexOutOfBoundsException JavaDoc("no profile with tag=" + tag + " at position" + position);
194
195        return retVal;
196     }
197
198     /**
199      * Returns the first profile with the given tag (position == 0).
200      * If no profile with given tag exists, null is returned.
201      * @param tag tag of profile, e.g. TAG_INTERNET_IOP.value
202      * @return first profile or null if no profile with given
203      * tag exists
204      */

205     public org.omg.ETF.Profile get_profile(int tag)
206     {
207        Profile retVal = null;
208        for (int i=0; i < _profiles.size(); i++)
209        {
210            Profile p = (Profile) _profiles.get(i);
211            if ( p.tag() == tag )
212            {
213               retVal = p;
214               break;
215            }
216        }
217        return retVal;
218
219     }
220
221 }
222
223
224
225
226
227
228
Popular Tags