001: package org.jacorb.orb.standardInterceptors;
002:
003: /*
004: * JacORB - a free Java ORB
005: *
006: * Copyright (C) 1999-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:
024: import org.apache.avalon.framework.configuration.Configurable;
025: import org.apache.avalon.framework.configuration.Configuration;
026: import org.apache.avalon.framework.configuration.ConfigurationException;
027: import org.jacorb.orb.CDROutputStream;
028: import org.jacorb.orb.ORB;
029: import org.jacorb.orb.giop.CodeSet;
030: import org.omg.PortableInterceptor.IORInfo;
031: import org.omg.PortableInterceptor.IORInterceptor;
032:
033: /**
034: * This interceptor creates a codeset TaggedComponent.
035: *
036: * @author Nicolas Noffke
037: * @version $Id: CodeSetInfoInterceptor.java,v 1.25 2006/07/26 11:05:21 nick.cross Exp $
038: */
039:
040: public class CodeSetInfoInterceptor extends org.omg.CORBA.LocalObject
041: implements IORInterceptor, Configurable {
042: private final org.omg.IOP.TaggedComponent tagc;
043:
044: public CodeSetInfoInterceptor(ORB orb) {
045: super ();
046:
047: try {
048: configure(orb.getConfiguration());
049: } catch (ConfigurationException ex) {
050: ex.printStackTrace();
051: // will have to do with defaults
052: }
053:
054: // create the info
055: org.omg.CONV_FRAME.CodeSetComponentInfo cs_info = new org.omg.CONV_FRAME.CodeSetComponentInfo();
056:
057: // fill the info
058: cs_info.ForCharData = new org.omg.CONV_FRAME.CodeSetComponent(
059: CodeSet.getTCSDefault(), new int[] { CodeSet
060: .getConversionDefault() });
061:
062: cs_info.ForWcharData = new org.omg.CONV_FRAME.CodeSetComponent(
063: CodeSet.getTCSWDefault(), new int[] { CodeSet.UTF8 });
064:
065: // encapsulate it into TaggedComponent
066: final CDROutputStream out = new CDROutputStream(orb);
067: try {
068: out.beginEncapsulatedArray();
069: org.omg.CONV_FRAME.CodeSetComponentInfoHelper.write(out,
070: cs_info);
071:
072: tagc = new org.omg.IOP.TaggedComponent(
073: org.omg.IOP.TAG_CODE_SETS.value, out
074: .getBufferCopy());
075: } finally {
076: out.close();
077: }
078: }
079:
080: public void configure(Configuration config)
081: throws ConfigurationException {
082: CodeSet.configure((org.jacorb.config.Configuration) config);
083: }
084:
085: public String name() {
086: return "CodeSetInfoComponentCreator";
087: }
088:
089: public void destroy() {
090: // nothing to do
091: }
092:
093: /**
094: * Creates default IOR codeset component.
095: */
096:
097: public void establish_components(IORInfo info, int[] tags) {
098: if (tags == null) {
099: info.add_ior_component_to_profile(tagc,
100: org.omg.IOP.TAG_MULTIPLE_COMPONENTS.value);
101: info.add_ior_component_to_profile(tagc,
102: org.omg.IOP.TAG_INTERNET_IOP.value);
103: } else {
104: for (int i = 0; i < tags.length; i++) {
105: info.add_ior_component_to_profile(tagc, tags[i]);
106: }
107: }
108: }
109:
110: public void establish_components(IORInfo info) {
111: info.add_ior_component_to_profile(tagc,
112: org.omg.IOP.TAG_MULTIPLE_COMPONENTS.value);
113: info.add_ior_component_to_profile(tagc,
114: org.omg.IOP.TAG_INTERNET_IOP.value);
115: }
116: }
|