Commit 00ab6626 authored by Sunil Kumar's avatar Sunil Kumar
Browse files

Added Javadoc comments

parent 2a07cefb
......@@ -15,35 +15,42 @@
package com.novell.ldap.extensions;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
* Contains a collection of constants used by the Novell LDAP Backup
* and Restore extensions.
*/
public class BackupRestoreConstants {
/**
* A constant for eDirectory LDAP Based Backup/Restore OIDs.
* A constant for eDirectory LDAP Based Backup Request OID.
*/
public static final String NLDAP_LDAP_BACKUP_REQUEST
= "2.16.840.1.113719.1.27.100.96";
/**
* A constant for eDirectory LDAP Based Backup Response OID.
*/
public static final String NLDAP_LDAP_BACKUP_RESPONSE
= "2.16.840.1.113719.1.27.100.97";
/**
* A constant for eDirectory LDAP Based Restore Request OID.
*/
public static final String NLDAP_LDAP_RESTORE_REQUEST
= "2.16.840.1.113719.1.27.100.98";
/**
* A constant for eDirectory LDAP Based Restore Response OID.
*/
public static final String NLDAP_LDAP_RESTORE_RESPONSE
= "2.16.840.1.113719.1.27.100.99";
/**
*
* Default constructor
*/
public BackupRestoreConstants() {
super();
// TODO Auto-generated constructor stub
}
}
......@@ -27,11 +27,30 @@ import com.novell.ldap.resources.ExceptionMessages;
import com.novell.ldap.asn1.ASN1Integer;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
*
* This class provides an LDAP interface for object based backup
* of eDirectory objects. The backup API not only get the objects
* but all the DS level attributes associated with the objects.
*
* <p>The information available includes such items as modification timestamp,
* revision,data blob consisting of backup data of any eDirectory Object
* </p>
*
* <p>To get information about any eDirectory Object, you must
* create an instance of this class and then call the
* extendedOperation method with this object as the required
* LDAPExtendedOperation parameter.</p>
*
* <p>The getLDAPBackupRequest extension uses the following OID:<br>
* &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.96</p><br>
*
* <p>The requestValue has the following format:<br>
*
* requestValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp; objectDN&nbsp;&nbsp;&nbsp; LDAPDN<br>
* &nbsp;&nbsp;&nbsp;&nbsp; mts(modification timestamp) INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp; revision&nbsp;&nbsp;&nbsp; INTEGER</p>
*/
public class LDAPBackupRequest extends LDAPExtendedOperation {
static {
......@@ -51,25 +70,49 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
}
}
/**
*
* Constructs an extended operations object for getting data about any Object.
*
* @param objectDN The DN of the object to be backed up
* <br>
* @param stateInfo The state information of the object to backup.
* This parameter is a String which contains combination of modification
* timestamp and revision number of object being backed up. The format
* of both modification time stamp and revision should pertain to eDirectoty
* standard format of taking modification timestamp and revision.
* Separator being used between these two is a '+' character.<br>
*
*
* @exception LDAPException A general exception which includes an error
* message and an LDAP error code.
*/
public LDAPBackupRequest(String objectDN, String stateInfo)
throws LDAPException, LDAPLocalException {
throws LDAPException {
super(BackupRestoreConstants.NLDAP_LDAP_BACKUP_REQUEST, null);
int mts, revision; //mts = modifaction time stamp
int mts; // Modifaction time stamp of the Object
int revision; // Revision number of the Object
String mtsStr, revisionStr;
try {
if (objectDN == null)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
if (stateInfo == null) {
// If null reference is passed in stateInfo initialize both
// mts and revision
mts = 0;
revision = 0; //initialize these
revision = 0;
} else {
//Parse this. stateInfo is should contain mts+revision
// Parse the passed stateInfo to obtain mts and revision
stateInfo = stateInfo.trim();
int index = stateInfo.indexOf('+');
if(index == -1)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
mtsStr = stateInfo.substring(0, index);
revisionStr = stateInfo.substring(index + 1);
try {
......@@ -90,15 +133,17 @@ public class LDAPBackupRequest extends LDAPExtendedOperation {
ByteArrayOutputStream encodedData = new ByteArrayOutputStream();
LBEREncoder encoder = new LBEREncoder();
ASN1OctetString asn1_serverDN = new ASN1OctetString(objectDN);
// Encode data of objectDN, mts and revision
ASN1OctetString asn1_objectDN = new ASN1OctetString(objectDN);
ASN1Integer asn1_mts = new ASN1Integer(mts);
ASN1Integer asn1_revision = new ASN1Integer(revision);
asn1_serverDN.encode(encoder, encodedData);
asn1_objectDN.encode(encoder, encodedData);
asn1_mts.encode(encoder, encodedData);
asn1_revision.encode(encoder, encodedData);
// set the value of operation specific data
setValue(encodedData.toByteArray());
} catch (IOException ioe) {
......
......@@ -27,35 +27,49 @@ import com.novell.ldap.asn1.LBERDecoder;
import com.novell.ldap.rfc2251.RfcLDAPMessage;
/**
* @author Administrator
* This object represent the data returned from a LDAPBackupRequest.
*
* <p>An object in this class is generated from an ExtendedResponse object
* using the ExtendedResponseFactory class.</p>
*
* <p>The LDAPBackupResponse extension uses the following OID:<br>
* &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.97</p>
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class LDAPBackupResponse extends LDAPExtendedResponse {
private int bufferLength;
private String stateInfo;
private int bufferLength; //Represents the length of backup data
private String stateInfo; //Represent the state Information of data
/*
* The String representing the array of chunk sizes and data returned from server.
* Data from server is parsed as follows before sending to any Application::
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn);returnedBuffer
* where
* no_of_chunks => Represents the number of chunks of data returned from server
* sizeOf(chunkn) => Represents the size of data in chunkn
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*/
private String parsedString;
//parsedString = no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)..sizeOf(chunkn);returnedBuffer
public LDAPBackupResponse(RfcLDAPMessage rfcMessage) throws IOException {
//Call the super constructor
super(rfcMessage);
int modificationTime = 0;
int revision = 0;
String returnedBuffer = null;
int modificationTime = 0; // Modifaction time stamp of the Object
int revision = 0; // Revision number of the Object
String returnedBuffer = null; //Actual data of returned eDirectoty Object
int chunksSize = 0;
int[] chunks = null; //This will hold size of each chunks returned from server
int[] chunks = null; //Holds size of each chunks returned from server
//Verify if returned ID is not proper
if (getID() == null
|| !(getID()
.equals(BackupRestoreConstants.NLDAP_LDAP_BACKUP_RESPONSE)))
throw new IOException("LDAP Extended Operation not supported");
if (getResultCode() == LDAPException.SUCCESS) {
// parse the contents of the reply
// Get the contents of the reply
byte[] returnedValue = this.getValue();
if (returnedValue == null)
throw new IOException(
......@@ -75,16 +89,13 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
.decode(currentPtr);
if (asn1_bufferLength == null)
throw new IOException("Decoding error");
bufferLength = asn1_bufferLength.intValue();
System.out.println("sudhir buffer length =" + bufferLength);
// Parse modificationTime
ASN1Integer asn1_modificationTime = (ASN1Integer) decoder
.decode(currentPtr);
if (asn1_modificationTime == null)
throw new IOException("Decoding error");
modificationTime = asn1_modificationTime.intValue();
// Parse revision
......@@ -92,10 +103,9 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
.decode(currentPtr);
if (asn1_revision == null)
throw new IOException("Decoding error");
revision = asn1_revision.intValue();
//format stateInfo
//Format stateInfo to contain both modificationTime and revision
this.stateInfo = modificationTime + "+" + revision;
// Parse returnedBuffer
......@@ -103,30 +113,38 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
.decode(currentPtr);
if (asn1_returnedBuffer == null)
throw new IOException("Decoding error");
returnedBuffer = asn1_returnedBuffer.stringValue();
System.out.println("Ravi buffer =" + returnedBuffer);
System.out.println("sudhir buffer size =" + returnedBuffer.length());
//Chunks are encoded as shown below
//SEQUENCE{no_of_seq, SET{SEQUENCE1{size1}, SEQUENCE2{size2}....SEQUENCEn{sizen}} }
/*
* Parse chunks array
* Chunks returned from server is encoded as shown below::
* SEQUENCE{
* chunksSize INTEGER
* SET of [
* SEQUENCE of {eacChunksize INTEGER}]
* }
*/
ASN1Sequence asn1_chunksSeq = (ASN1Sequence) decoder
.decode(currentPtr);
if (asn1_chunksSeq == null)
throw new IOException("Decoding error");
//Get number of chunks returned from server
chunksSize = ((ASN1Integer)asn1_chunksSeq.get(0)).intValue();
//Construct chunks array
chunks = new int[chunksSize];
ASN1Set asn1_chunksSet = (ASN1Set)asn1_chunksSeq.get(1);
//Iterate through asn1_chunksSet and put each size into chunks array
for (int index = 0; index < chunksSize; index++) {
ASN1Sequence asn1_eachSeq = (ASN1Sequence)asn1_chunksSet.get(index);
chunks[index] = ((ASN1Integer)asn1_eachSeq.get(0)).intValue();
}
//Construct a temporary StringBuffer and append chunksSize, each size
//element in chunks array and actual data of eDirectoty Object
StringBuffer tempBuffer = new StringBuffer();
tempBuffer.append(chunksSize);
tempBuffer.append(";");
......@@ -136,24 +154,52 @@ public class LDAPBackupResponse extends LDAPExtendedResponse {
}
tempBuffer.append(returnedBuffer);
//Assign tempBuffer to parsedString to be returned to Application
this.parsedString = tempBuffer.toString();
} else {
//Intialize all these if getResultCode() != LDAPException.SUCCESS
this.bufferLength = 0;
this.stateInfo = null;
this.parsedString = null;
}
}
/**
* Returns the data buffer length
*
* @return bufferLength as integer.
*/
public int getBufferLength() {
return bufferLength;
}
/**
* Returns the stateInfo of returned eDirectory Object.
* This is combination of MT (Modification Timestamp) and
* Revision value with char '+' as separator between two.<br>
* Client application if want to use both MT and Revision need to break
* this string to get both these data.
*
* @return stateInfo as String.
*/
public String getStatusInfo(){
return stateInfo;
}
/**
* Returns the data in String as::<br>
* no_of_chunks;sizeOf(chunk1);sizeOf(chunk2)sizeOf(chunkn);returnedBuffer<br>
* where<br>
* no_of_chunks => Represents the number of chunks of data returned from server<br>
* sizeOf(chunkn) => Represents the size of data in chunkn<br>
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*
* @return parsedString as String.
*/
public String getParsedString() {
return parsedString;
}
public String getStatusInfo(){
return stateInfo;
}
}
\ No newline at end of file
......@@ -28,19 +28,68 @@ import com.novell.ldap.asn1.LBEREncoder;
import com.novell.ldap.resources.ExceptionMessages;
/**
* @author Administrator
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
*
* This class provides an LDAP interface for object based
* restore of eDirectory objects.
*
* <p>The information need for restore includes such items as object DN,
* data buffer length, string containing the chunks sizes and data blob
* consisting of atual backup data returned from server.
* </p>
*
* <p>To send this request to eDirectory, you must
* create an instance of this class and then call the
* extendedOperation method with this object as the required
* LDAPExtendedOperation parameter.</p><br>
*
* <p>The getLDAPRestoreRequest extension uses the following OID:<br>
* &nbsp;&nbsp;&nbsp;2.16.840.1.113719.1.27.100.98</p><br>
*
* <p>The requestValue has the following format:<br>
*
* <p>requestValue ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dataChunkSizes ::=<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp; SEQUENCE {<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* noOfChunks INTEGER<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp; SET of [<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* SEQUENCE of {eacChunksize INTEGER}]<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* &nbsp;&nbsp;&nbsp;
* }<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; objectDN ::= OCTET STRING<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bufferLength ::= INTEGER<br>
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retunedBuffer::= OCTET STRING</p>
*/
public class LDAPRestoreRequest extends LDAPExtendedOperation {
/**
*
* Constructs an extended operations object which contains the ber encoded
* restore data.
*
* @param objectDN The object DN to restore
* <br><br>
* @param bufferLength The length of backed up data
* <br><br>
* @param buffer The data buffer containing chunks sizes and data blob
* <br><br>
* @exception LDAPException A general exception which includes an error
* message and an LDAP error code.
*/
public LDAPRestoreRequest(String objectDN, int bufferLength, String buffer)
throws LDAPException, LDAPLocalException {
throws LDAPException {
super(BackupRestoreConstants.NLDAP_LDAP_RESTORE_REQUEST, null);
try {
//Verify the validity of arguments
if (objectDN == null || bufferLength == 0 || buffer == null)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
......@@ -48,7 +97,12 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
ByteArrayOutputStream encodedData = new ByteArrayOutputStream();
LBEREncoder encoder = new LBEREncoder();
//rervers parse the buffer
/*
* From the input argument buffer get::
* chunkSize => Represents the number of chunks of data returned from server
* sizeOf each chunk => int represents the size of each chunk
* returnedBuffer => Represents the actual data of returned eDirectoty Object
*/
int index;
int chunkSize;
int chunks[] = null;
......@@ -60,7 +114,7 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
"Invalid data buffer send in the request",
LDAPException.ENCODING_ERROR);
}
//Return exception if chunkSize == 0
if (chunkSize == 0)
throw new IllegalArgumentException(
ExceptionMessages.PARAM_ERROR);
......@@ -68,39 +122,39 @@ public class LDAPRestoreRequest extends LDAPExtendedOperation {
buffer = buffer.substring(index + 1);
int chunkIndex;
//Construct chunks array
chunks = new int[chunkSize];
//Iterate through each member in buffer, assign to chunks array elem
for (int i = 0; i < chunkSize; i++) {
chunkIndex = buffer.indexOf(';');
chunks[i] = Integer.parseInt(buffer.substring(0, chunkIndex));
buffer = buffer.substring(chunkIndex + 1);
}
ASN1OctetString asn1_serverDN = new ASN1OctetString(objectDN);
//Form the sequence to be passed to Server
//Form the chunks sequence to be passed to Server
ASN1Sequence asn1_chunksSeq = new ASN1Sequence();
asn1_chunksSeq.add(new ASN1Integer(chunkSize));
ASN1Set asn1_chunksSet = new ASN1Set();
for (int i = 0; i < chunkSize; i++) {
ASN1Integer tmpChunk = new ASN1Integer(chunks[i]);
ASN1Sequence tmpSeq = new ASN1Sequence();
tmpSeq.add(tmpChunk);
asn1_chunksSet.add(tmpSeq);
//asn1_chunksSet.add((new ASN1Sequence()).add(new
// ASN1Integer(chunks[i])));
}
asn1_chunksSeq.add(asn1_chunksSet);
ASN1Integer asn1_bufferLength = new ASN1Integer(bufferLength);
//Form objectDN, bufferLength, buffer ASN1 Objects
ASN1OctetString asn1_objectDN = new ASN1OctetString(objectDN);
ASN1Integer asn1_bufferLength = new ASN1Integer(bufferLength);
ASN1OctetString asn1_buffer = new ASN1OctetString(buffer);
//Encode data to send to server
asn1_chunksSeq.encode(encoder, encodedData);
asn1_serverDN.encode(encoder, encodedData);
asn1_objectDN.encode(encoder, encodedData);
asn1_bufferLength.encode(encoder, encodedData);
asn1_buffer.encode(encoder, encodedData);
// set the value of operation specific data
setValue(encodedData.toByteArray());
} catch (IOException ioe) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment