1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
5 <title>Adding new IOR Parsers to TAO
</title>
8 <body text=
"#000000" link=
"#0000ff" vlink=
"#cc0000" bgcolor=
"#ffffff">
14 <h4>What is an IOR Parser?
</h4>
16 <P>TAO supports several IOR formats, including
17 <CODE>IOR:
</CODE>,
<CODE>corbaloc:
</CODE>,
18 <CODE>corbaname:
</CODE> and
<CODE>file:
</CODE>.
19 However, some applications may benefit from other formats, for
20 example,
<CODE>http:
</CODE> could allow applications to download
21 an object reference from a web server.
23 <P>Adding new IOR formats to the ORB is a simple task, the ORB
25 <A HREF=
"http://www.cs.wustl.edu/~schmidt/DSEJ-94.ps.gz">
28 to dynamically load new
<EM>IOR Parsers
</EM>.
29 The implementation of
<CODE>string_to_object()
</CODE> queries
30 each available IOR Parser to convert an string into an object
32 Application developers can implement their own parsers and
33 dynamically (or statically) add them to the ORB, without any
34 need to recompile TAO.
37 <H4>Why aren't the IOR parsers in TAO enough?
</H4>
39 <P>TAO provides a basic set of IOR parsers,
40 but it would be detrimental to TAO's footprint to implement a
41 huge collection of IOR parsers into the ORB.
42 Moreover, the DOC group does not have the ability to create all
43 possible IOR parsers: many applications will use proprietary
44 databases to configure the ORB.
47 <H4>Why should I use an IOR parser?
</H4>
49 <P>Using an IOR parser is more convenient than, say,
50 setting up the ad-hoc configuration code in
52 It also allows for easier integration with other TAO components,
53 such as the
<CODE>-ORBInitRef
</CODE> options.
59 <H1>Implementation
</H2>
62 <H1>How do you Implement an IOR Parser?
</H1>
64 <P>Implementing an IOR parser is easy,
65 you must implement a class derived from
66 <CODE>TAO_IOR_Parser
</CODE>.
67 As an example we will develop an HTTP IOR parser,
68 the class declaration will probably look like this:
70 class HTTP_Parser : public TAO_IOR_Parser
73 virtual bool match_prefix (const char *ior_string) const;
74 virtual CORBA::Object_ptr parse_string (const char *ior,
77 ACE_THROW_SPEC ((CORBA::SystemException));
80 For maximal portability this class uses the alternative mapping
81 for exception handling, if you are not familiar with the
82 alternative mapping you can safely ignore the
83 <CODE>CORBA::Environment
</CODE> argument.
84 Please read the exception handling
85 <A HREF=
"exceptions.html">
92 <LI><B>match_prefix
</B> This method must recognize all the IOR
93 prefixes that this parser supports. Normally this is a single
94 prefix, a typical implementation will look like this:
97 HTTP_Parser::match_prefix (const char *ior_string) const
99 static char http_prefix[] =
"http:";
100 int cmp = ACE_OS::strncmp (ior_string, http_prefix, sizeof(http_prefix));
105 <LI><B>parse_string
</B> This method implements the real string
106 parsing, you can safely assume that the string has been
107 validated by the
<CODE>match_prefix()
</CODE> method.
108 Typically, this method will obtain the IOR string, in our
109 example by downloading the document from the web server,
110 and then uses
<CODE>string_to_object()
</CODE> to return the
114 HTTP_Parser::parse_string (const char *ior,
117 // Parse IOR as if it was an http:-URL
118 ACE_URL_Addr *url_addr =
119 ACE_URL_Addr::create_addr (ior);
121 ACE_HTTP_Addr *http_addr =
122 ACE_dynamic_cast(ACE_HTTP_Addr*,url_addr);
124 // Connect to the remote host and download the web page, store the
126 char *document_contents = ...;
128 return orb-
>string_to_object (document_contents);
134 <H4>How do you add an IOR Parser to the ORB?
</H4>
136 <P>As we mentioned above, TAO uses the ACE Service Configurator
137 framework to find (dynamically or statically) the IOR parsers.
138 You may want to read the
139 <A HREF=
"../../docs/tutorials/022/page01.html">
142 on this subject, but the process is mostly mechanic, and
145 <P>First you must declare, in the header file, a factory method
146 and a description of the service,
147 this is easily accomplished via the following ACE macros:
149 ACE_FACTORY_DECLARE (Export_Prefix, HTTP_Parser)
150 ACE_STATIC_SVC_DELCARE_EXPORT (Export_Prefix, HTTP_Parser)
152 If you are only going to use Unix-like compilers and linkers,
153 then you can simply use
<CODE>TAO
</CODE> in place of
154 <CODE>Export_Prefix
</CODE>.
155 However, under Microsoft Windows variants, this string must be
156 the prefix of the DLL export/import macros used by your library.
157 If you are going to statically link your IOR Parser into the
158 application you will also need to add
159 <CODE>ACE_STATIC_SVC_REQUIRE
</CODE>, as follows:
161 ACE_FACTORY_DECLARE (Export_Prefix, HTTP_Parser)
162 ACE_STATIC_SVC_DELCARE_EXPORT (Export_Prefix, HTTP_Parser)
163 ACE_STATIC_SVC_REQUIRE (HTTP_Parser)
167 <P>Next you must implement the services defined above, using some
168 other group of helper macros, in your source file you should
171 ACE_STATIC_SVC_DEFINE (HTTP_Parser,
172 ACE_TEXT (
"HTTP_Parser"),
174 &ACE_SVC_NAME (HTTP_Parser),
175 ACE_Service_Type::DELETE_THIS |
176 ACE_Service_Type::DELETE_OBJ,
178 ACE_FACTORY_DEFINE (Export_Prefix, HTTP_Parser)
180 The second argument to
<CODE>ACE_STATIC_SVC_DEFINE
</CODE> is
181 the name of the service in ACE's Service Configurator.
182 It is customary, but not required, to use the name of the class.
185 <P>Finally you can dynamically add your IOR parser to the ORB
186 using the
<CODE>-ORBIORParser
</CODE> option in the
189 <A HREF=
"Options.html">
190 Options for TAO Components
192 for details about ORB and Resource Factory options),
196 static Resource_Factory
"-ORBIORPaser HTTP_Parser"
198 would add our new parser to the ORB.
205 <H4>Are there any complete examples?
</H4>
207 <P>Yes, the IOR parsers in the ORB can serve as complete examples,
209 <CODE>FILE_Parser.h
</CODE>,
210 <CODE>CORBALOC_Parser.h
</CODE>,
211 <CODE>CORBANAME_Parser.h
</CODE>,
212 or
<CODE>DLL_Parser.h
</CODE>.
213 Unfortunately there are no examples that show how to dynamically
214 add a new IOR parser into the ORB.
218 <address><a href=
"mailto:coryan@uci.edu">Carlos O'Ryan
</a></address>