Cédric Bosdonnat - IDLhttps://bosdonnat.fr/2007-11-25T20:36:00+01:00A geek's perspectiveUNO services constructors2007-11-25T20:36:00+01:002007-11-25T20:36:00+01:00Cédric Bosdonnattag:bosdonnat.fr,2007-11-25:/uno-services-constructors.html<p>I have already read about the new-style UNO services
constructors, but I had never used them. Last week I discovered the
power hidden in this tiny UNO improvement. Let's consider the following
service specification:</p>
<div class="highlight"><pre><span></span><code>module org { module openoffice { module test {
service Customer <span class="o">:</span> XCustomer {
Customer( [in] <span class="nb">string</span> customerId );
};
}; }; };
</code></pre></div>
<p>To implement such …</p><p>I have already read about the new-style UNO services
constructors, but I had never used them. Last week I discovered the
power hidden in this tiny UNO improvement. Let's consider the following
service specification:</p>
<div class="highlight"><pre><span></span><code>module org { module openoffice { module test {
service Customer <span class="o">:</span> XCustomer {
Customer( [in] <span class="nb">string</span> customerId );
};
}; }; };
</code></pre></div>
<p>To implement such a service we will need to add the
<code>com::sun::star::lang::XInitialization</code> interface to the service
inherited interfaces. The service interface could look like this:</p>
<div class="highlight"><pre><span></span><code>module org { module openoffice { module test {
interface XCustomer <span class="o">:</span> com<span class="o">::</span>sun<span class="o">::</span>star<span class="o">::</span>lang<span class="o">::</span>XInitialization {
[attribute, readonly] <span class="nb">string</span> Id;
};
}; }; };
</code></pre></div>
<p>Then the UNO constructor of the service will be implemented in the
<code>initialize()</code> method specified by the <code>XInitialization</code> interface. Then
the implementation could be like the following in Java:</p>
<div class="highlight"><pre><span></span><code><span class="kd">public</span> <span class="kt">void</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">Object</span><span class="o">[]</span> <span class="n">pArgs</span><span class="p">)</span> <span class="kd">throws</span> <span class="n">com</span><span class="p">.</span><span class="na">sun</span><span class="p">.</span><span class="na">star</span><span class="p">.</span><span class="na">uno</span><span class="p">.</span><span class="na">Exception</span> <span class="p">{</span>
<span class="n">String</span> <span class="n">id</span> <span class="o">=</span> <span class="n">args</span><span class="o">[</span><span class="mi">0</span><span class="o">]</span><span class="p">;</span>
<span class="c1">// Do the initialization from the Customer's database (for example)</span>
<span class="p">}</span>
</code></pre></div>
<p>Then to use the service constructor, it's easy in Java:</p>
<div class="highlight"><pre><span></span><code><span class="n">Customer</span> <span class="n">johnDoe</span> <span class="o">=</span> <span class="n">Customer</span><span class="p">.</span><span class="na">Customer</span><span class="p">(</span><span class="s">"johndoe"</span><span class="p">);</span>
</code></pre></div>
<p>To use the constructor in Basic it's slightly more complicated because
you will need to create the service with arguments. It should look like
this:</p>
<div class="highlight"><pre><span></span><code><span class="err">oServiceManager = getProcessServiceManager()</span>
<span class="err">oCustomer = oServiceManager.createInstanceWithArguments("org.openoffice.test.Customer", "johndoe")</span>
</code></pre></div>
<p>This could seem trivial for any common object-oriented language
programmer like Java, C++, but for UNO it's a big step. I hope this
could help someone to better know UNO. </p>Uno IDL syntax highlighting in PHP2006-08-20T11:20:00+02:002006-08-20T11:20:00+02:00Cédric Bosdonnattag:bosdonnat.fr,2006-08-20:/uno-idl-syntax-highlighting-in-php.html<p>Uno IDL is the component specification language of OpenOffice.org. Here
is a solution to show some highlighted Uno IDL code. It uses <a href="http://qbnz.com/highlighter/">GeSHi</a>
and you need to add a language file describing how to parse and colorize
you Uno IDL code. As this language file doesn't exist I created …</p><p>Uno IDL is the component specification language of OpenOffice.org. Here
is a solution to show some highlighted Uno IDL code. It uses <a href="http://qbnz.com/highlighter/">GeSHi</a>
and you need to add a language file describing how to parse and colorize
you Uno IDL code. As this language file doesn't exist I created one.</p>
<p><a href="https://bosdonnat.fr/data/OpenOffice.org/idl.phps">Download the GeSHi language file now</a></p>