001: /*
002: * JacORB - a free Java ORB
003: *
004: * Copyright (C) 1999-2004 Gerald Brose
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Library General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Library General Public License for more details.
015: *
016: * You should have received a copy of the GNU Library General Public
017: * License along with this library; if not, write to the Free
018: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
019: *
020: */
021: package org.jacorb.orb.portableInterceptor;
022:
023: import java.util.Iterator;
024: import java.util.List;
025: import java.util.Map;
026:
027: import org.jacorb.orb.MinorCodes;
028: import org.jacorb.orb.ORB;
029: import org.jacorb.orb.TaggedComponentList;
030: import org.jacorb.poa.POA;
031: import org.omg.CORBA.CompletionStatus;
032: import org.omg.CORBA.Policy;
033: import org.omg.ETF.Profile;
034: import org.omg.IOP.TaggedComponent;
035:
036: /**
037: * This class represents the type of info object
038: * that will be passed to the IORInterceptors. <br>
039: * See PI Spec p.7-64f
040: *
041: * @author Nicolas Noffke
042: * @version $Id: IORInfoImpl.java,v 1.14 2006/07/07 10:55:57 alphonse.bendt Exp $
043: */
044:
045: public class IORInfoImpl extends org.omg.CORBA.LocalObject implements
046: IORInfoExt {
047: /**
048: * Maps profile tags to component lists (Integer -> TaggedComponentList).
049: */
050: private final Map components;
051: private final Map policy_overrides;
052: private final ORB orb;
053: private final POA poa;
054: private final List _profiles;
055:
056: public IORInfoImpl(ORB orb, POA poa, Map components,
057: Map policy_overrides, List profiles) {
058: this .orb = orb;
059: this .poa = poa;
060: this .components = components;
061: this .policy_overrides = policy_overrides;
062: this ._profiles = profiles;
063: }
064:
065: /**
066: * Adds component to all profiles.
067: */
068: public void add_ior_component(TaggedComponent component) {
069: for (Iterator i = components.values().iterator(); i.hasNext();) {
070: TaggedComponentList list = (TaggedComponentList) i.next();
071: list.addComponent(component);
072: }
073: }
074:
075: /**
076: * Adds the component to the profile with the given tag.
077: */
078: public void add_ior_component_to_profile(TaggedComponent component,
079: int id) {
080: TaggedComponentList list = (TaggedComponentList) components
081: .get(new Integer(id));
082: if (list == null) {
083: throw new org.omg.CORBA.BAD_PARAM("unknown profile tag: "
084: + id, MinorCodes.NO_SUCH_PROFILE,
085: CompletionStatus.COMPLETED_MAYBE);
086: }
087:
088: list.addComponent(component);
089: }
090:
091: /**
092: * @return a policy of the given type, or null,
093: * if no policy of that type is present.
094: */
095: public Policy get_effective_policy(int type) {
096: if (!orb.hasPolicyFactoryForType(type)) {
097: throw new org.omg.CORBA.INV_POLICY(
098: "No PolicyFactory for type " + type
099: + " has been registered!",
100: MinorCodes.NO_SUCH_POLICY,
101: CompletionStatus.COMPLETED_MAYBE);
102: }
103:
104: Policy policy = null;
105: if (policy_overrides != null) {
106: policy = (Policy) policy_overrides.get(new Integer(type));
107: }
108: return (policy != null) ? policy : poa.getPolicy(type);
109: }
110:
111: /**
112: * This method adds a further profile to an IOR.
113: * By using this method it is possible to append e.g. further IIOP
114: * profiles. The added profile is marshalled after all profiles
115: * already existing in profile list.
116: * @param profile the profile to add
117: */
118: public void add_profile(Profile profile) {
119: if (_profiles != null) {
120: _profiles.add(profile);
121: }
122: }
123:
124: /**
125: * This method returns the number of profiles of the given type.
126: * The returned value can be used to iterate over the existing
127: * profiles of given type (get_profile()).
128: * @param tag profile tag, e.g. TAG_INTERNET_IOP.value
129: * @return number of profiles of given tag
130: */
131: public int get_number_of_profiles(int tag) {
132: int retVal = 0;
133: for (int i = 0; i < _profiles.size(); i++) {
134: Profile p = (Profile) _profiles.get(i);
135: if (p.tag() == tag) {
136: retVal++;
137: }
138: }
139: return retVal;
140: }
141:
142: /**
143: * Returns the profile with the given tag at the given position.
144: * Following rule must apply to parameter position:<p>
145: * <code> 0 <= position < get_number_of_profiles(tag) </code><p>
146: * @param tag tag of profile, e.g. TAG_INTERNET_IOP.value
147: * @param position position in IOR
148: * @return profile
149: * @exception ArrayIndexOutOfBoundsException if position is
150: * out of range
151: */
152: public org.omg.ETF.Profile get_profile(int tag, int position) {
153: int cnt = position;
154: Profile result = null;
155: for (int i = 0; i < _profiles.size(); i++) {
156: Profile profile = (Profile) _profiles.get(i);
157: if (profile.tag() == tag && cnt == 0) {
158: result = profile;
159: break;
160: }
161: cnt--;
162: }
163:
164: if (result == null) {
165: throw new ArrayIndexOutOfBoundsException(
166: "no profile with tag=" + tag + " at position"
167: + position);
168: }
169:
170: return result;
171: }
172:
173: /**
174: * Returns the first profile with the given tag (position == 0).
175: * If no profile with given tag exists, null is returned.
176: * @param tag tag of profile, e.g. TAG_INTERNET_IOP.value
177: * @return first profile or null if no profile with given
178: * tag exists
179: */
180: public org.omg.ETF.Profile get_profile(int tag) {
181: Profile result = null;
182: for (int i = 0; i < _profiles.size(); i++) {
183: Profile profile = (Profile) _profiles.get(i);
184: if (profile.tag() == tag) {
185: result = profile;
186: break;
187: }
188: }
189: return result;
190: }
191: }
|