001: package org.jacorb.orb.portableInterceptor;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1997-2004 Gerald Brose.
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Library General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Library General Public License for more details.
017: *
018: * You should have received a copy of the GNU Library General Public
019: * License along with this library; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: */
022:
023: import org.omg.PortableInterceptor.*;
024: import org.omg.PortableInterceptor.ORBInitInfoPackage.*;
025: import org.omg.CORBA.INTERNAL;
026: import org.omg.CORBA.Object;
027: import org.omg.IOP.CodecFactory;
028:
029: import java.util.*;
030:
031: import org.apache.avalon.framework.logger.Logger;
032: import org.jacorb.orb.ORB;
033:
034: /**
035: * This class represents the type of info object
036: * that will be passed to the ORBInitializers. <br>
037: * See PI Spec p. 9-70ff
038: *
039: * @author Nicolas Noffke
040: * @version $Id: ORBInitInfoImpl.java,v 1.16 2006/07/07 10:55:57 alphonse.bendt Exp $
041: */
042:
043: public class ORBInitInfoImpl extends org.omg.CORBA.LocalObject
044: implements ORBInitInfo {
045: private int slot_count = 0;
046: private final ORB orb;
047: private final Logger logger;
048:
049: private final Map named_server_interceptors;
050: private final List anonymous_server_interceptors;
051:
052: private final Map named_client_interceptors;
053: private final List anonymous_client_interceptors;
054:
055: private final Map named_ior_interceptors;
056: private final List anonymous_ior_interceptors;
057:
058: private final Map policy_factories;
059:
060: private boolean valid = true;
061:
062: public ORBInitInfoImpl(ORB orb) {
063: this .orb = orb;
064:
065: logger = orb.getConfiguration().getNamedLogger("jacorb.orb");
066:
067: named_server_interceptors = new HashMap();
068: named_client_interceptors = new HashMap();
069:
070: anonymous_server_interceptors = new ArrayList();
071: anonymous_client_interceptors = new ArrayList();
072:
073: named_ior_interceptors = new HashMap();
074: anonymous_ior_interceptors = new ArrayList();
075:
076: policy_factories = new HashMap();
077: }
078:
079: /**
080: * This method is for interceptors that need access to the ORB.
081: * Be careful with that since there is a reason, why there is no
082: * other way to get access to the ORB.
083: */
084: public ORB getORB() {
085: return orb;
086: }
087:
088: public void setInvalid() {
089: valid = false;
090: }
091:
092: /**
093: * Copies the elements of a Map into
094: * a List.
095: */
096:
097: private List merge(List target, Map source) {
098: List result = new ArrayList(target);
099: result.addAll(source.values());
100: return result;
101: }
102:
103: public List getClientInterceptors() {
104: return merge(anonymous_client_interceptors,
105: named_client_interceptors);
106: }
107:
108: public List getServerInterceptors() {
109: return merge(anonymous_server_interceptors,
110: named_server_interceptors);
111: }
112:
113: public List getIORInterceptors() {
114: return merge(anonymous_ior_interceptors, named_ior_interceptors);
115: }
116:
117: public Map getPolicyFactories() {
118: return policy_factories;
119: }
120:
121: public int getSlotCount() {
122: return slot_count;
123: }
124:
125: // implementation of org.omg.PortableInterceptor.ORBInitInfoOperations interface
126: public void add_client_request_interceptor(
127: ClientRequestInterceptor interceptor) throws DuplicateName {
128: checkIsValid();
129:
130: checkInterceptorName(interceptor);
131:
132: if (interceptor.name().length() == 0) {
133: anonymous_client_interceptors.add(interceptor);
134: } else {
135: if (named_client_interceptors.containsKey(interceptor
136: .name())) {
137: throw new DuplicateName(interceptor.name());
138: }
139:
140: named_client_interceptors.put(interceptor.name(),
141: interceptor);
142: }
143: }
144:
145: private void checkIsValid() {
146: if (!valid) {
147: throw new org.omg.CORBA.OBJECT_NOT_EXIST(
148: "This ORBInitIfo is not valid anymore!");
149: }
150: }
151:
152: private void checkInterceptorName(Interceptor interceptor)
153: throws DuplicateName {
154: if (interceptor.name() == null) {
155: throw new DuplicateName("the name is null");
156: }
157: }
158:
159: public void add_ior_interceptor(IORInterceptor interceptor)
160: throws DuplicateName {
161: checkInterceptorName(interceptor);
162:
163: if (interceptor.name().length() == 0) {
164: anonymous_ior_interceptors.add(interceptor);
165: } else {
166: if (named_ior_interceptors.containsKey(interceptor.name())) {
167: throw new DuplicateName(interceptor.name());
168: }
169:
170: named_ior_interceptors.put(interceptor.name(), interceptor);
171: }
172: }
173:
174: public void add_server_request_interceptor(
175: ServerRequestInterceptor interceptor) throws DuplicateName {
176: checkIsValid();
177:
178: checkInterceptorName(interceptor);
179:
180: if (interceptor.name().length() == 0) {
181: anonymous_server_interceptors.add(interceptor);
182: } else {
183: if (named_server_interceptors.containsKey(interceptor
184: .name())) {
185: throw new DuplicateName(interceptor.name());
186: }
187:
188: named_server_interceptors.put(interceptor.name(),
189: interceptor);
190: }
191: }
192:
193: public int allocate_slot_id() {
194: checkIsValid();
195:
196: return slot_count++;
197: }
198:
199: public String[] arguments() {
200: checkIsValid();
201:
202: return orb._args;
203: }
204:
205: public CodecFactory codec_factory() {
206: checkIsValid();
207:
208: try {
209: return (CodecFactory) orb
210: .resolve_initial_references("CodecFactory");
211: } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
212: logger.fatalError("unexpected error", e);
213: throw new INTERNAL(e.toString());
214: }
215: }
216:
217: public String orb_id() {
218: checkIsValid();
219:
220: return ORB.orb_id;
221: }
222:
223: public void register_initial_reference(String id, Object obj)
224: throws InvalidName {
225: checkIsValid();
226:
227: try {
228: orb.register_initial_reference(id, obj);
229: } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
230: throw new InvalidName();
231: }
232: }
233:
234: public void register_policy_factory(int type,
235: PolicyFactory policy_factory) {
236: checkIsValid();
237:
238: if (policy_factory == null) {
239: throw new org.omg.CORBA.BAD_PARAM(
240: "Actual parameter policy_factory is null!");
241: }
242:
243: final Integer key = new Integer(type);
244: if (policy_factories.containsKey(key)) {
245: throw new org.omg.CORBA.BAD_INV_ORDER(
246: "A PolicyFactory for type " + type
247: + " has already been registered!", 12,
248: org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
249: }
250:
251: policy_factories.put(key, policy_factory);
252: }
253:
254: public org.omg.CORBA.Object resolve_initial_references(String id)
255: throws InvalidName {
256: checkIsValid();
257:
258: try {
259: return orb.resolve_initial_references(id);
260: } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
261: throw new InvalidName();
262: }
263: }
264: }
|