Monday, December 28, 2009

List Servers Indicated in Connection documents if Names.nsf

* Method to return a list of server names present in the connection documents in names.nsf
* @param session- The Notes Session belonging to a particular user
* @return String Array
* @author karthikeyan_a
* @created 11-May-2009
* @see ArrayList removeDuplicates(ArrayList arrayList) ---->

public String[] getServerNames(Session session){
//initializing return type
String[] serverNames=null;
try {
//declaring variables and objects necessary for further manipulations
ArrayList serverNameList=new ArrayList();

Database addBook=null;
View connectionView=null;
ViewEntryCollection connectionEntries=null;
ViewEntry connectionEntry=null;
Document connectionDocument=null;

String connectionServerName=null;

int entryCount=0;
int serverNameCount=0;

//getting the handle for the names and address book in the local server
addBook=session.getDatabase("", "names.nsf");

//if the handle is not set then return the same
if (addBook==null) {
System.out.println("Names.nsf is not found");
return null;

// if the address book is not open before then open it again
if (!addBook.isOpen()) {;

//get the handle of the view which has the list of various connection documents in names.nsf

//if the handle for the same is not set then return null
if (connectionView==null) {
System.out.println("Connections view is not found in names.nsf");
return null;

//get the handle of the collection of all entries present in the view

//if there are no entries found then return null
if (connectionEntries.getCount()==0) {
System.out.println("There are no connection documents found in names.nsf");
return null;
System.out.println("There are "+connectionEntries.getCount()+" connection documents found in names.nsf");

//set the handle for the first entry in the collection

//loop through the entries in the collection and get the destination server's name
for (entryCount=0;entryCount<connectionEntries.getCount();entryCount++) { //start of entry collection for loop

//if the concerned entry is a document then proceed else skip
if (connectionEntry.isDocument()) {

//get the handle of the document associated with the current entry

//get the name of the server the connection document is associated with

//put that in the list of server names found so far

//proceed to the next entry in the collection
} //end of entry collection for loop

//remove any duplicate entries present in the server list

//convert the array list into a string array
serverNames=new String[serverNameList.size()];
for (serverNameCount=0;serverNameCount<serverNameList.size();serverNameCount++) {

} catch (NotesException e) {
// TODO Auto-generated catch block

//return the resultant string array
return serverNames;

No comments:

Post a Comment