All LDAP Classes
Internal LDAP Classes

com.novell.ldap.util
Class DOMWriter

java.lang.Object
  extended by com.novell.ldap.util.DOMWriter
All Implemented Interfaces:
LDAPWriter

public class DOMWriter
extends java.lang.Object
implements LDAPWriter

Writes LDAPMessages into a DOM structure as DSML batch requests and batch responses.

See Also:
DOMReader, DSMLWriter, LDAPMessage

Field Summary
private  org.w3c.dom.Document doc
           
private static int NEW_BATCH
           
private static int REQUEST_BATCH
           
private static int RESPONSE_BATCH
           
private  org.w3c.dom.Element root
           
private static int SEARCH_RESPONSE
           
private  org.w3c.dom.Element searchNode
           
private  int state
           
 
Constructor Summary
DOMWriter()
          Initializes the DOMWriter.
 
Method Summary
private  java.lang.String byte2String(byte[] value)
           
private  void checkState(LDAPEntry entry)
          Tests the current state with a new message that is either a response or request.
private  void checkState(LDAPMessage message)
          Tests the current state with a new message that is either a response or request.
(package private) static java.lang.String findRequestID(LDAPMessage message)
           
 void finish()
          Writes any remaining data to the output destination.
 org.w3c.dom.Element getRootElement()
          Retrieves the batchRequest or batchResponse element populated with this writer.
 java.lang.String getVersion()
          Retrieves the version of DSML being written, currently only 2.0 is supported.
 boolean isRequest()
          Used to identify if the root node is a batchRequest or not.
 org.w3c.dom.Element message2Element(LDAPMessage message)
          Utility method to convert an LDAPMessage to a DSML DOM element.
private  org.w3c.dom.Element myWriteEntry(LDAPEntry entry, LDAPControl[] controls)
           
private  void writeAttribute(org.w3c.dom.Element attribute, LDAPAttribute attr)
           
 void writeComments(java.lang.String comments)
          This method is not implemented and is silently ignored.
private  void writeControls(org.w3c.dom.Element e, LDAPControl[] controls)
           
 void writeEntry(LDAPEntry entry)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeEntry(LDAPEntry entry, LDAPControl[] controls, java.lang.String requestID)
          Write an LDAP record into LDIF file as LDAPContent data.
 void writeError(java.lang.Exception e)
          Any Exception can be written in DSML with this method, via the tag.
private  void writeFilter(org.w3c.dom.Element e, java.util.Iterator itr)
           
private  void writeMatching(org.w3c.dom.Element newElement, java.util.Iterator itr)
          Common code for =, >=, <=, and ~=.
 void writeMessage(LDAPMessage message)
          Writes the LDAPMessage into the DOMStructure.
private  void writeResult(org.w3c.dom.Element e, LDAPResponse response)
          Writes the specified LDAPResponse into the specified element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doc

private org.w3c.dom.Document doc

root

private org.w3c.dom.Element root

state

private int state

NEW_BATCH

private static final int NEW_BATCH
See Also:
Constant Field Values

REQUEST_BATCH

private static final int REQUEST_BATCH
See Also:
Constant Field Values

RESPONSE_BATCH

private static final int RESPONSE_BATCH
See Also:
Constant Field Values

SEARCH_RESPONSE

private static final int SEARCH_RESPONSE
See Also:
Constant Field Values

searchNode

private org.w3c.dom.Element searchNode
Constructor Detail

DOMWriter

public DOMWriter()
          throws javax.xml.parsers.ParserConfigurationException
Initializes the DOMWriter.

Throws:
javax.xml.parsers.ParserConfigurationException - Occurs if a parser could not be found or is misconfigured.
Method Detail

getVersion

public java.lang.String getVersion()
Retrieves the version of DSML being written, currently only 2.0 is supported.

Specified by:
getVersion in interface LDAPWriter
Returns:
Version of DSML being used.

isRequest

public boolean isRequest()
Used to identify if the root node is a batchRequest or not.

Specified by:
isRequest in interface LDAPWriter
Returns:
true if the root node of the DOM is a batchRequest and false otherwise.

writeComments

public void writeComments(java.lang.String comments)
                   throws java.io.IOException
This method is not implemented and is silently ignored.

Specified by:
writeComments in interface LDAPWriter
Parameters:
comments - The comments to write
Throws:
java.io.IOException

writeMessage

public void writeMessage(LDAPMessage message)
                  throws LDAPLocalException,
                         java.io.IOException
Writes the LDAPMessage into the DOMStructure.

Specified by:
writeMessage in interface LDAPWriter
Parameters:
message - LDAPMessage to write
Throws:
LDAPLocalException - Occurs when a message is written out of sequence, i.e. a response is written into a batchRequest.
java.io.IOException - if an I/O error occurs.

writeEntry

public void writeEntry(LDAPEntry entry)
                throws LDAPLocalException
Write an LDAP record into LDIF file as LDAPContent data. An LDAPEntry is written as a DSML SearchResultEntry record.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
Throws:
LDAPLocalException - if data and content are mixed.
LDAPLocalException - if an I/O error occurs.
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls)
                throws LDAPLocalException
Write an LDAP record into LDIF file as LDAPContent data. An LDAPEntry is written as a DSML SearchResultEntry record.

You are not allowed to mix request data and content data

Specified by:
writeEntry in interface LDAPWriter
Parameters:
entry - LDAPEntry object
controls - Controls that were returned with this entry
Throws:
LDAPLocalException - if data and content are mixed.
See Also:
LDAPEntry

writeEntry

public void writeEntry(LDAPEntry entry,
                       LDAPControl[] controls,
                       java.lang.String requestID)
                throws LDAPLocalException
Write an LDAP record into LDIF file as LDAPContent data. An LDAPEntry is written as a DSML SearchResultEntry record.

You are not allowed to mix request data and content data

Parameters:
entry - object
controls - Controls that were returned with this entry
requestID - the String that associates this response with the request
Throws:
LDAPLocalException - if data and content are mixed.
See Also:
LDAPEntry

myWriteEntry

private org.w3c.dom.Element myWriteEntry(LDAPEntry entry,
                                         LDAPControl[] controls)

writeAttribute

private void writeAttribute(org.w3c.dom.Element attribute,
                            LDAPAttribute attr)

message2Element

public org.w3c.dom.Element message2Element(LDAPMessage message)
Utility method to convert an LDAPMessage to a DSML DOM element.

Parameters:
message - An LDAPMessage to be converted to a DSML DOM element.
Returns:
element A DOM element representing either a response or a request in DSML.

writeMatching

private void writeMatching(org.w3c.dom.Element newElement,
                           java.util.Iterator itr)
Common code for =, >=, <=, and ~=.


writeFilter

private void writeFilter(org.w3c.dom.Element e,
                         java.util.Iterator itr)
Parameters:
e - element to add a DSML search filter component (filter or a AND, OR or NOT )
itr -

byte2String

private java.lang.String byte2String(byte[] value)

writeResult

private void writeResult(org.w3c.dom.Element e,
                         LDAPResponse response)
Writes the specified LDAPResponse into the specified element.

Possible information written to the element is a Result code with a description, a server response, and a matched DN. Controls and referrals should also be written - and will be in the future.

Parameters:
e - Element to insert response info into.
response - Response message to write.

writeControls

private void writeControls(org.w3c.dom.Element e,
                           LDAPControl[] controls)

writeError

public void writeError(java.lang.Exception e)
                throws java.io.IOException
Any Exception can be written in DSML with this method, via the tag. In general LDAPExceptions should be written to the errorResponse tag and other exception in a SOAP Fault.

Specified by:
writeError in interface LDAPWriter
Parameters:
e - LDAPException to be written in DSML.
Throws:
java.io.IOException

checkState

private void checkState(LDAPMessage message)
                 throws LDAPLocalException
Tests the current state with a new message that is either a response or request.

If the state is NEW_BATCH, check_state will create the appropriate batch element and set it as root. If the state is SEARCH_RESPONSE then the new message is verified to be a search result, search response or search reference.

Parameters:
message - Message to be written
Throws:
LDAPLocalException

checkState

private void checkState(LDAPEntry entry)
                 throws LDAPLocalException
Tests the current state with a new message that is either a response or request.

If the state is NEW_BATCH, check_state will create the appropriate batch element and set it as root. If the state is SEARCH_RESPONSE then the new message is verified to be a search result, search response or search reference.

Parameters:
entry - Message to be written
Throws:
LDAPLocalException

findRequestID

static java.lang.String findRequestID(LDAPMessage message)

getRootElement

public org.w3c.dom.Element getRootElement()
Retrieves the batchRequest or batchResponse element populated with this writer.

Returns:
A batchRequest or batchResponse element.

finish

public void finish()
            throws java.io.IOException
Description copied from interface: LDAPWriter
Writes any remaining data to the output destination.

Specified by:
finish in interface LDAPWriter
Throws:
java.io.IOException

All LDAP Classes
Internal LDAP Classes

Copyright ? 2002 Novell, Inc. All Rights Reserved.
Novell, Inc.
1800 South Novell Place
Provo, Ut 84606
Phone: (801) 861-5000