Sample Code File: SkeletonDriverShim.java


// Sample code file: SkeletonDriverShim.java
// Warning: This code has been marked up for HTML

/*************************************************************************

Copyright 1999-2002 Novell, Inc. All Rights Reserved.

With respect to this file, Novell hereby grants to Developer a
royalty-free, non-exclusive license to include this sample code
and derivative binaries in its product. Novell grants to Developer
worldwide distribution rights to market, distribute or sell this
sample code file and derivative binaries as a component of
Developer's product(s). Novell shall have no obligations to
Developer or Developer's customers with respect to this code.

DISCLAIMER:

Novell disclaims and excludes any and all express, implied, and
statutory warranties, including, without limitation, warranties
of good title, warranties against infringement, and the implied
warranties of merchantability and fitness for a particular purpose.
Novell does not warrant that the software will satisfy customer's
requirements or that the licensed works are without defect or error
or that the operation of the software will be uninterrupted.
Novell makes no warranties respecting any technical services or
support tools provided under the agreement, and disclaims all other
warranties, including the implied warranties of merchantability and
fitness for a particular purpose.

***************************************************************************/
package com.novell.nds.dirxml.driver.skeleton;

import com.novell.nds.dirxml.driver.*;
import com.novell.xml.dom.*;
import org.w3c.dom.*;

/**
 * A basic skeleton for implementing a <code>DriverShim</code>.
 *
 * <code>com.novell.nds.dirxml.driver.DriverShim</code> defines a top-level
 * interface for starting and stopping an application shim.
 *
 * A <code>DriverShim</code> must implement a constructor which takes no
 * parameters in order for the driver infrastructure to instantiate an instance
 * of it.
 *
 * Note that the skeleton driver makes no use of .ini files or any information  
 * outside of that
 * supplied through the initialization data supplied to the shim
 * <code>init()</code> methods.
 * In general it is inappropriate for a driver to store configuration
 * information outside of NDS
 * where it cannot be remotely configured using ConsoleOne or other remote
 * configuration utility.
 *
 * In addition it is unwise to have static mutable class data, since that
 * prevents multiple instances
 * of the driver from functioning independently.
 *
 * @version 2.0 28Jun2000
 */
public class SkeletonDriverShim extends CommonImpl implements DriverShim
{
/**
 * Object implementing
 * <code>com.novell.nds.dirxml.driver.SubscriptionShim</code>, which is
 * supplied to DirXML via the <code>getSubscriptionShim()</code> method.
 */
SkeletonSubscriptionShim subscriptionShim = null;
 /**
* Object implementing
* <code>com.novell.nds.dirxml.driver.PublicationShim</code>, which is
* supplied to DirXML via the <code>getPublicationShim()</code> method.
*/
SkeletonPublicationShim publicationShim = null;
/**
* Contains driver options from the init params passed to <code>init()</code>
*/
ShimParams params = null;
/**
 * Instance of inner class AuthenticationParams that is initialized by
 * DriverShim.init()
 * and DriverShim.getSchema() so that all derived classes may share
 * the auth params
 * if necessary. Note that the actual strings may be null if no
 * auth info was entered
 * in ConsoleOne.
 */
AuthenticationParams authParams = null;

/**
 * A Java driver shim must have a constructor which takes no parameters.
 * DirXML
 * uses this to construct the driver object.
 */
public SkeletonDriverShim()
{
//set up the Trace object in CommonImpl with the name of this object
super("SkeletonDriverShim");
}

/**
 * <code>init</code> will be called after a driver is created to allow the
 * driver to perform any necessary initialization before starting to process
 * events and commands. Typically it will perform any setup that is
 * common to both the subscriber and publisher channels.
 *
 * @param initParameters XML document that contains the shim initialization
 * parameters
 * @return XML document containing status/messages from the init operation
 */
public XmlDocument init(XmlDocument initParameters )
{
try
{
tracer.trace("init");
//create an output document for returning status to DirXML
Element output = createOutputDocument();
//setup the shared authentication information
authParams = getAuthenticationParams(initParameters.getDocument());
//if we don't have any authentication parameters, report a warning. This
//is intended to serve as an example of how to report a warning or an
//error. A real driver may or may not need to information in the
//authentication parameters.
if (authParams.authenticationId == null &&
authParams.authenticationContext == null &&
authParams.applicationPassword == null)
{
//a real driver would probably want to report a fatal error
//if required parameters are not supplied
addStatusElement(output,STATUS_WARNING,"No authentication
information",null);
}
//get any non-authentication options from the init document
params = getShimParams
(initParameters.getDocument(),"driver",DRIVER_PARAMS);
//create the objects that do the real work
subscriptionShim = new SkeletonSubscriptionShim(authParams);
publicationShim = new SkeletonPublicationShim(authParams);
//if we didn't already add a status element, add a success
if (output.getElementsByTagName("status").item(0) == null)
{
addStatusElement(output,STATUS_SUCCESS,null,null);
}
//return the status document
return new XmlDocument(output.getOwnerDocument());
} catch (Throwable t)
{
//something bad happened...
return createStatusDocument(STATUS_FATAL,t.getMessage());
}
}

/**
 * <code>shutdownShim</code> indicates to the DriverShim that
 * the driver is being terminated.
 *
 * @param initParameters XML document that may contain description of reason
 * for shutdown @return XML document containing status/messages from shutdown
 * operation
 */
public XmlDocument shutdown(XmlDocument reason)
{
tracer.trace("shutdown");
//create an output document so the subscriber can write its state info
Element output = createOutputDocument();
subscriptionShim.setState(output);
// shutdown whatever needs shutting down
// which will always include telling the publication shim to return control
// back to the caller
publicationShim.stop();
//add a successful status
addStatusElement(output,STATUS_SUCCESS,null,null);
//return the status and state to DirXML
return new XmlDocument(output.getOwnerDocument());
}

/**
 * <code>getSubscriptionShim</code> gets an implementation of SubscriptionShim
 * that can be used to process commands on behalf of DirXML.
 *
 * @return an instance of SubscriptionShim that can be used to process
 * commands on behalf of the DirXML.
 */
public SubscriptionShim getSubscriptionShim()
{
tracer.trace("getSubscriptionShim");
return subscriptionShim;
}

/**
* <code>getPublicationShim</code> gets an implementation of PublicationShim
* that can be invoked by NDS.
*
* @return an instance of PublicationShim that can be invoked by DirXML.
*/
public PublicationShim getPublicationShim()
{
tracer.trace("getPublicationShim");
return publicationShim;
}

/**
* <code>getSchema</code> returns a representation of the application
* schema data encoded in XML.
* <p>
* This will be called only when the driver is not running. In other words, if
* this method is
* called init()/shutdown() will not be called for the current instance of the
* DriverShim.
*
* @param initParameters XML document containing the driver shim initialization
* parameters as
* well as the subscription shim and publication shim initialization parameters.
* @return XML document containing the application schema data, or an
* error status return.
*/
public XmlDocument getSchema(XmlDocument initParameters)
{
//setup the shared authentication informationS
authParams = getAuthenticationParams(initParameters.getDocument());
//a driver that supports a real application would do whatever is necessary
//to create an XDS schema description document and return it.
//For example, it might
//create an instance of the Subscriber object and query the application
//schema.
//If the application has an invariant schema, the driver might just have an
//embedded XML document
//describing the schema in XDS terms. This embedded document could then be
//returned to DirXML
//wrapped by an XmlDocument object.
//
//However, since we are just a skeleton...
//
//Create a return document that says we can't do it. Note that this will
//cause DirXML to display a warning in DSTrace that it is unable to read the
//application schema
return createStatusDocument(STATUS_ERROR,"Skeleton driver doesn't support
the getSchema operation");
}

/**
 * Table of parameters that this driver shim wants to get from the
 * &lt;driver-options> element
 * of the init-params.
 * <p>
 * This is illustrative, of course, an actual driver would want parameters
 * specific to its
 * functionality.
 */
private static final ShimParamDesc[] DRIVER_PARAMS =
{
new ShimParamDesc("option-1",ShimParamDesc.STRING_TYPE,false),
new ShimParamDesc("option-2",ShimParamDesc.INT_TYPE,false),
};

}

DirXML SubscriberShim

The SubscriberShim executes all of the XDS commands on the subscriber channel. When a directory event occurs, the DirXML engine converts the data to XDS and sends it to the subscription shim of the DirXML driver for the conversion of eDirectory data to the proper format for the external application and for sending the converted data to the external data source.

Interface Methods include:

  • init- returns instance of the subscriber for the engine to call

  • execute- called by the engine when it receives a command from eDirectory



Download Sample Code - 16.4MB
Previous blank Table of Contents blank Next