KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > util > FixIOR


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-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.util;
22
23 import org.apache.avalon.framework.logger.Logger;
24
25 import org.jacorb.orb.giop.CodeSet;
26 import org.jacorb.orb.ParsedIOR;
27 import org.jacorb.orb.*;
28
29 import org.omg.IOP.*;
30 import org.omg.GIOP.*;
31 import org.omg.IIOP.*;
32 import org.omg.SSLIOP.*;
33 import org.omg.CSIIOP.*;
34 import org.omg.CONV_FRAME.*;
35
36 import java.io.*;
37
38 /**
39  * Utility class to patch host and port information into an IOR.
40  *
41  * @author Steve Osselton
42  */

43
44 public class FixIOR
45 {
46     public static void main (String JavaDoc args[])
47         throws Exception JavaDoc
48     {
49         org.omg.CORBA.ORB JavaDoc orb;
50         String JavaDoc iorString;
51         String JavaDoc iorFile;
52         String JavaDoc host;
53         BufferedReader br;
54         BufferedWriter bw;
55         CDRInputStream is;
56         CDROutputStream os;
57         ParsedIOR pior;
58         IOR ior;
59         TaggedProfile[] profiles;
60         ProfileBody_1_0 body10;
61         ProfileBody_1_1 body11;
62         short port;
63         int iport;
64
65
66         if (args.length != 3)
67         {
68             System.err.println ("Usage: fixior host port ior_file");
69             System.exit( 1 );
70         }
71         host = args[0];
72
73         // Read in IOR from file
74

75         iorFile = args[2];
76         br = new BufferedReader (new FileReader (iorFile));
77         iorString = br.readLine ();
78         br.close ();
79
80         if (! iorString.startsWith ("IOR:"))
81         {
82             System.err.println ("IOR must be in the standard IOR URL format");
83             System.exit (1);
84         }
85
86         iport = Integer.parseInt (args[1]);
87         if (iport > 32767)
88         {
89            iport = iport - 65536;
90         }
91         port = (short) iport;
92
93         orb = org.omg.CORBA.ORB.init (args, null);
94
95         Logger logger =
96             ((org.jacorb.orb.ORB)orb).getConfiguration().getNamedLogger("jacorb.fixior");
97
98         // Parse IOR
99

100         pior = new ParsedIOR(iorString, orb, logger);
101         ior = pior.getIOR ();
102
103         // Iterate through IIOP profiles setting host and port
104

105         profiles = ior.profiles;
106         for (int i = 0; i < profiles.length; i++)
107         {
108             if (profiles[i].tag == TAG_INTERNET_IOP.value)
109             {
110                 is = new CDRInputStream (orb, profiles[i].profile_data);
111                 is.openEncapsulatedArray ();
112                 body10 = ProfileBody_1_0Helper.read (is);
113                 is.close ();
114
115                 os = new CDROutputStream ();
116                 os.beginEncapsulatedArray ();
117
118                 if (body10.iiop_version.minor > 0)
119                 {
120                     is = new CDRInputStream (orb, profiles[i].profile_data);
121                     is.openEncapsulatedArray ();
122                     body11 = ProfileBody_1_1Helper.read (is);
123                     is.close ();
124
125                     body11.host = host;
126                     body11.port = port;
127
128                     ProfileBody_1_1Helper.write (os, body11);
129                 }
130                 else
131                 {
132                     body10.host = host;
133                     body10.port = port;
134
135                     ProfileBody_1_0Helper.write (os, body10);
136                 }
137                 profiles[i].profile_data = os.getBufferCopy ();
138             }
139         }
140
141         pior = new ParsedIOR (ior, (org.jacorb.orb.ORB)orb, logger);
142
143         // Write out new IOR to file
144

145         bw = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (iorFile)));
146         bw.write (pior.getIORString ());
147         bw.close ();
148     }
149
150     private FixIOR ()
151     {
152     }
153 }
154
Popular Tags