cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject [DAISY] Updated: Creating a Reader
Date Thu, 25 Aug 2005 19:44:22 GMT
A document has been updated:

Document ID: 681
Branch: main
Language: default
Name: Creating a Reader (unchanged)
Document Type: Document (unchanged)
Updated on: 8/25/05 7:44:05 PM
Updated by: Berin Loritsch

A new version has been created, state: publish

This part has been updated.
Mime type: text/xml (unchanged)
File name:  (unchanged)
Size: 9063 bytes (previous version: 5976 bytes)
Content diff:
(125 equal lines skipped)
    <p>Now we are going to override the <tt>service()</tt> method and implement
--- <tt>dispose()</tt> method to get and cleanup after ourselves.</p>
+++ <tt>dispose()</tt> method to get and cleanup after ourselves.  First lets
+++ with getting the DataSourceComponent.  Because Cocoon is configured to deal with
+++ multiple databases, you will need to use a ServiceSelector to choose the
+++ DataSourceComponent corresponding to your desired database.</p>
+++ <pre>    @Override
+++     public void service(ServiceManager services) throws ServiceException
+++     {
+++         super.service(services);
+++         dbselector = (ServiceSelector) manager.lookup(DataSourceComponent.ROLE + "Selector");
+++         datasource = (DataSourceComponent);
+++     }
+++ </pre>
+++ <p class="note">The <tt>@Override</tt> annotation above is used by the
+++ compiler to ensure that you are overriding a parent class's method.  It only
+++ works in Java 5.  If you are developing against an earlier version of Java
+++ remove that line so that you can compile the class.  That goes for every time
+++ you see it.</p>
+++ <p>We ensured that we called the superclass's <tt>service()</tt> method
so that
+++ we didn't upset the expectations of anyone wanting to extend our class.  Keeping
+++ the user's expectations in mind always helps to produce a good product--and in
+++ this case the user is a developer.  Next, we retrieved the selector for the
+++ DataSourceComponent and stored it in the class field we created earlier.  Then
+++ we did the same for the actual DataSouceComponent itself.  Now we have access to
+++ the component when we need it.  We didn't get an actual connection yet because
+++ the connections are pooled.  If we held onto a connection for the life of the
+++ component then we would run out and the application would come to a screaching
+++ halt waiting for a connection to become available.</p>
+++ <p>Since we are still dealing with managing the component itself, let's do the
+++ cleanup code next.  The Avalon framework uses the <tt>Disposable.dispose()</tt>
+++ callback method to let the component know when it is safe to release all the
+++ components it is using and perform other cleanup.</p>
+++ <pre>    public void dispose()
+++     {
+++         dbselector.release(datasource);
+++         manager.release(dbselector);
+++         datasource = null;
+++         manager = null;
+++     }
+++ </pre>
+++ <p>While setting the fields to <tt>null</tt> might not be necessary
with modern
+++ day garbage collectors, it still doesn't hurt.  By releasing those components we
+++ ensure that Cocoon can shut down nicely and safely when it is time.</p>
+++ <h3>Make sure PDFs Work</h3>
+++ <p>Since we expect to have PDF documents in our database alongside pictures and
+++ other types of documents, we need to make sure they display properly.  Since the
+++ bug in the IE Acrobat Reader plugin wasn't fixed until version 7 we need to make
+++ sure the content length is returned.  There is some overhead with this as Cocoon
+++ has to cache the results to get the content length, but because we are going to
+++ cache it anyway there is little difference on when it gets sent to the cache. 
+++ This is how we do it:</p>
+++ <pre>    @Override
+++     public boolean shouldSetContentLength()
+++     {
+++         return true;
+++     }
+++ </pre>
+++ <h3>Setting up for the Read (Cache directives, finding the resource, etc.)</h3>

no changes

no changes

Custom Fields
no changes

no changes

View raw message