|
Oracle Fusion Middleware interMedia Domains Java API Reference for Oracle ADF Business Components 11g Release 1 (11.1.1.7.0) E10656-08 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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:
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:
setContentSource(OrdContentSource source);
OrdDomainIOInterface
defines three methods, which the user chooses for a specific content source:
loadDataFromFile(String filename);
loadDataFromByteArray(byte[] byteArray);
loadDataFromInputStream(InputStream inpStream);
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:
BLOB
locator for the domain object.
BLOB
in the
database.
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() {} }
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 |
---|
java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
int getContentLength() throws java.io.IOException
java.io.IOException
java.lang.String getMimeType()
null
.
void release()
|
Oracle Fusion Middleware interMedia Domains Java API Reference for Oracle ADF Business Components 11g Release 1 (11.1.1.7.0) E10656-08 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |