Skip navigation links

Oracle Fusion Middleware interMedia Domains Java API Reference for Oracle ADF Business Components
11g Release 1 (11.1.1)

E10656-03


oracle.ord.im
Interface OrdContentSource

All Known Implementing Classes:
OrdByteArraySource, OrdFileSource, OrdHttpUploadFileSource

public interface OrdContentSource

Specifies a multimedia content source to use when it is desirable to defer content loading until the application either posts or commits the data. OrdContentSource supports "deferred loading" because it permits the user to handle content loading in two steps:

  1. Associate the content source with the interMedia domain object.
  2. Load the content from the content source to the interMedia SQL object in the database.

Deferred loading is provided to simplify writing code using interMedia under some circumstances, such as inserting a new row with an interMedia object.

Deferred loading is in contrast to "immediate loading." Immediate loading occurs when the user makes an explicit method call to load the content, rather then waiting to load the content in the post or commit operation. For reasons explained below, immediate loading serves the user best when the application updates an existing record. Whereas, deferred loading is preferrable when inserting a new record in a table.

To support deferred loading OrdDomainIOInterface defines a single method the user can call for various content sources:

To support immediate loading OrdDomainIOInterface defines three methods, which the user chooses for a specific content source:

The reason immediate loading is not desired for inserting a new record has to do with the fact that a BLOB locator in the database has to be initialized before any content can be written into it. Immediate loading requires that the domain object already contains an initialized BLOB locator. Deferred loading does not have this requirement because the BC4J framework does the BLOB initialization for the domain object. So, in the case of deferred loading, in the next postChanges() after setContentSource(), the BC4J framework performs these actions:

  1. Initializes the BLOB locator for the domain object.
  2. Loads the content into the initialized BLOB in the database.
  3. Calls the domain object's setProperties() method.

Deferred loading is commonly used to insert a new record into a table because it allows the user to write cleaner code. The following sample code shows how to insert a new record that contains an OrdImageDomain object using deferred loading.

       Row row = viewObject.createRow();
       row.setAttribute("Id", 1);
       OrdImageDomain imgDomain = new OrdImageDomain();
       imgDomain.setContentSource(new OrdFileSource("flower.jpg"));
       row.setAttribute("Image", imgDomain);
       viewObject.insertRow(row);
       appModule.getTransaction().commit();
 

To accomplish the same thing using immediate loading is more complex because the user has to explicitly perform the actions performed by BC4J during deferred loading. Inserting a new record in a table using immediate loading would look like this:

       Row row = viewObject.createRow();
       row.setAttribute("Id", 1);
       OrdImageDomain imgDomain = new OrdImageDomain();
       row.setAttribute("Image", imgDomain);
       viewObject.insertRow(row);
       // initialize the BLOB locator
       appModule.getTransaction().postChanges();
       // load content to the interMedia object in the database
       imgDomain.loadDataFromFile("flower.jpg");
       // set properties on the interMedia object
       imgDomain.setProperties();
       appModule.getTransaction().commit();
 

Fortunately, when updating an existing record, the code for immediate loading looks cleaner because the BLOB locator already exists in the domain object. In that case, immediate loading serves the user best.

Oracle interMedia provides three predefined OrdContentSource implementations, which are convenient when loading content from a file, a byte array, or a OrdHttpUploadFile object:

Users can also write their own implementation of OrdContentSource to allow loading from alternative content sources. For example, users may want to implement an URL content source class.

       package user;
       
       import oracle.ord.im.OrdContentSource;
       import java.net.URL;
       import java.io.InputStream;
       import java.io.IOException;
       
       public class URLSource implements OrdContentSource
       {
         private URL m_url = null;
         private String m_mimeType = null;
       
         public URLSource(URL url)
         {
           m_url = url;
         }
       
         public void setURL(URL url)
         {
           m_url = url;
         }
       
         public URL getURL()
         {
           return m_url;
         }
       
         public InputStream getInputStream() throws IOException
         {
           return m_url.openStream();
         }
       
         public int getContentLength() throws IOException
         {
           return -1;
         }
 
         public void setMimeType(String mimeType)
         {
           m_mimeType = mimeType;
         }
       
         public String getMimeType()
         {
           return m_mimeType;
         }
        
         public void release()
         {}
       }
 
Since:
JDev5.0
Version:
JDev5.0
See Also:
OrdDomainIOInterface.setContentSource(oracle.ord.im.OrdContentSource), OrdDomainIOInterface.getContentSource()

Method Summary
 int getContentLength()
          Gets the length of the content.
 java.io.InputStream getInputStream()
          Returns an InputStream object.
 java.lang.String getMimeType()
          Gets the MIME type information of the content.
 void release()
          Releases the resources used by the content source.

 

Method Detail

getInputStream

java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns an InputStream object. User's code is responsible for closing the InputStream when finished.
Throws:
java.io.IOException

getContentLength

int getContentLength()
                     throws java.io.IOException
Gets the length of the content. If the length is unknown, it returns -1.
Throws:
java.io.IOException

getMimeType

java.lang.String getMimeType()
Gets the MIME type information of the content. If the MIME type is unknown, it returns null.

release

void release()
Releases the resources used by the content source.

Skip navigation links

Oracle Fusion Middleware interMedia Domains Java API Reference for Oracle ADF Business Components
11g Release 1 (11.1.1)

E10656-03


Copyright © 1997, 2009, Oracle. All rights reserved.