Blog: Tech Talk

agsdix-fas fa-home

Blog: Home

agsdix-fas fa-pen-fancy

Blog: CEO's Corner

agsdix-fas fa-code

Blog: Tech Talk

Blog: Product Releases

Blog: Conversion

arrow left circle icon Blog: Tech Talk

Implementing Interfaces and Declaring Classes at Runtime

by | Apr 24, 2012

One of the fundamental benefits of an object-oriented language such as Java is the ability to design applications around Interfaces. Interaction with a class is done only through the known set of methods in the interface. Calling functions do not need to know the implementation, just the method signature. Interfaces are often used within a software application or framework to allow for flexibility and re-use, but the use of Interfaces can be even more powerful when you allow the implementations to be defined at runtime. FlexSnap:SI‚Äôs ‚ÄúContent Handler API‚ÄĚ is an example of such a case.

Snowbound Software’s FlexSnap:SI Applet and Servlet based product comes straight out of the box with functionality to view images stored in a folder on your server. However, often times these images sit on another server, or in a content repository. FlexSnap:SI allows you to customize the retrieval of documents via a Java Interface named FlexSnapSIContentHandler .

The Content Handler class is defined in the applications web.xml as follows:









The FlexSnap code will instantiate your class as follows:

String contentClassName = config .getInitParameter( PARAM_CONTENT_CLASS ); 

Class contentClass = Class.forName( contentClassName ); 

FlexSnapSIContentHandlerInterface gContentRetriever = (FlexSnapSIContentHandlerInterface) contentClass 

.getConstructors()[0].newInstance( new Object[] {}); 

As long as your class implements the following set of methods, you are all set to go.

Method Summary
voiddeleteAnnotation (String clientInstanceId, String documentKey, String annotationKey)Called when the client has requested to delete the specified annotation layer.
byte[]getAnnotationContent (String clientInstanceId, String documentKey, String annotationKey)Returns the content for the specified annotation key in the form of a byte array
StringgetAnnotationNames (String clientInstanceId, String documentKey)Returns an array of annotation object names for the specified clientInstance and documentKey array.
byte[]getBookmarkContent (String clientInstanceId, String documentKey)Returns the bookmark xml content for the specified documentKey in the form of a byte array.
byte[]getDocumentContent (String clientInstanceId, String documentKey)Returns the content for the specified content key in the form of a byte array.
booleanhasAnnotations (String clientInstanceId, String documentKey)Returns true if there is annotation content associated with the specified document.
voidinit (ServletConfig config)Performs any necessary configuration tasks 
ContentHandlerResultpublishDocument(HttpServletRequest request, String clientInstanceId, String documentKey, byte[] data, int status)This method is used when the File>Publish menu choise is invoked.
ContentHandlerResultsaveAnnotationContent(HttpServletRequest request, String clientInstanceId,String documentKey, String annotationKey, byte[] data)This method gets called when updated annotation data for the specified annotation file is ready to be saved. 
ContentHandlerResultsaveBookmarkContent(HttpServletRequest request, String clientInstanceId,String documentKey, byte[] data)This method is called when bookmark data is saved. 
ContentHandlerResultsaveDocumentComponents(HttpServletRequest request, String clientInstanceId,String documentKey, byte[] data, com.snowbound.snapserv.servlet.AnnotationLayer[] annotations, byte[] bookmark)This method saves the document as well as the annotations and bookmarks associated with the document. 
ContentHandlerResultsaveDocumentContent(HttpServletRequest request, String clientInstanceId,String documentKey, byte[] data)This method is called when document data is saved. 
ContentHandlerResultsendCocumentContent(HttpServletRequest request, String clientInstanceId,String documentKey, byte[] data)This method is called when document data is sent.