|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rakeshv.xml.addressbook.AddressBook
public class AddressBook
Address book implementation. This class presents a java view of the specified address book xml file. This class also contains methods for creating new address book entries, and for deleted existing entries. This class should ideally be cached in the servlet containers servlet context for maximum performance, since it can take quite a long time to build the JDOM tree if the address book is large.
You can use the createAddressBook( String ) method to
create a new AddressBook specified by the fully
qualified file name specified in the method call.
Copyright 2003 Rakesh Vidyadharan
| Field Summary | |
|---|---|
private org.jdom.Document |
document
A reference to the address book XML document. |
private java.lang.String |
fileName
The fully qualified name of the address book XML file. |
private java.util.Map |
groups
The map of Group records. |
private org.jdom.Element |
groupsElement
A reference to the element that contains all the group entries ( groups). |
(package private) org.jdom.Namespace |
namespace
The namespace for the root element. |
private java.util.Map |
persons
The map of Person records. |
private org.jdom.Element |
personsElement
A reference to the element that contains all the person entries ( persons). |
| Constructor Summary | |
|---|---|
protected |
AddressBook()
Default constructor. |
|
AddressBook(java.lang.String fileName)
Just invoke AddressBook( String, String ) with a value of
null for the preferred SAX Parser to use. |
|
AddressBook(java.lang.String fileName,
java.lang.String saxParser)
Load the specified address book XML file using the specified SAX Parser. |
| Method Summary | |
|---|---|
private void |
addAddress(java.util.List list,
org.jdom.Element component)
Add the Address objects in the specified list to the
specified element. |
void |
addGroup(Group group)
Add the specified Group to the address book. |
private void |
addGroupToTree(Group group)
Add the specified Group object under the groupsElement node in the JDOM tree. |
void |
addPerson(Person person)
Add the specified Person java bean to the address book. |
private void |
addPersonToTree(Person person)
Add the specified Person object to the JDOM tree as a
person element. |
static AddressBook |
createAddressBook(java.lang.String file)
Just invokes createAddressBook( String, String ) with a
null value for the default SAX Parser. |
static AddressBook |
createAddressBook(java.lang.String file,
java.lang.String saxParser)
Create a new address book using the fully qualified file name specified, and using the specified SAX Parser to load the XML file that has been created. |
boolean |
deleteGroup(java.lang.String nickname)
Delete the Group identified by the Group.nickname
specified from the address book. |
boolean |
deleteGroups(java.lang.String[] nicknames)
Delete the Group's identified by the Group.nickname's specified from the address book. |
boolean |
deletePerson(java.lang.String nickname)
Remove the Person identified by the specified Person.nickname. |
boolean |
deletePersons(java.lang.String[] nicknames)
Remove the Person's identified by the specified Person.nicknames. |
java.util.Map |
getGroups()
Return the value/reference of the groups. |
java.util.Map |
getPersons()
Return the value/reference of the persons. |
private void |
loadAddressBook(java.lang.String saxParser)
Load the address book XML file ( fileName) using JDOM,
and populate the class fields persons and groups. |
void |
modifyAssociatedGroup(Person person)
Find the associated Group in the groups Map
(if any), and change the Member.mail to the
Person.mail of the Person object passed in. |
void |
modifyGroup(Group group)
Modify the specified Group in the address book. |
void |
modifyPerson(Person person)
Save the specified Person java bean that has been modified
to the underlying JDOM tree. |
private void |
populateAddresses(Person person,
org.jdom.Element personElement)
Populate the Person.addresses list, if address data is
available for the specified person element in the
address book. |
private Group |
populateGroup(org.jdom.Element group)
Walk through the child elements of the specified group
element, and create a Group object out of the contents. |
private void |
populateGroups()
Walk through the JDOM tree, and populate the groups list
of Group objects. |
private Person |
populatePerson(org.jdom.Element element)
Walk through the child elements of the specified person
element, and create a corresponding Person bean. |
private void |
populatePersons()
Walk through the JDOM tree, and populate the persons
Map of Person objects. |
void |
saveAddressBook()
Write the JDOM tree back to the address book file. |
void |
setFileName(java.lang.String fileName)
Set the value of fileName. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private java.lang.String fileName
private java.util.Map persons
map of Person records. This corresponds
to all the person elements under the
persons element in the address book. The map is
populated using the Person.nickname as the
key.
private java.util.Map groups
map of Group records. This corresponds
to all the group elements under the
groups element in the address book. The map is
populated using the Group.nickname as the key.
private org.jdom.Document document
org.jdom.Namespace namespace
namespace for the root element.
private org.jdom.Element personsElement
persons).
private org.jdom.Element groupsElement
groups).
| Constructor Detail |
|---|
protected AddressBook()
public AddressBook(java.lang.String fileName)
throws AddressException
AddressBook( String, String ) with a value of
null for the preferred SAX Parser to use.
fileName - - The fully qualified name of the address
book XML file.
AddressException - - If any JDOM/IOExceptions are encountered
while processing the address book XML file.
public AddressBook(java.lang.String fileName,
java.lang.String saxParser)
throws AddressException
fileName - - The fully qualified name of the address
book XML file.saxParser - - The full class name of the preferred
SAX Parser to use.
AddressException - - If any JDOM/IOExceptions are encountered
while processing the address book XML file.loadAddressBook( String )| Method Detail |
|---|
private void loadAddressBook(java.lang.String saxParser)
throws AddressException
fileName) using JDOM,
and populate the class fields persons and groups.
saxParser - - The full class name of the SAX Parser
to use. If this is null the default JAXP SAX
Parser will be used.
AddressException - - If any JDOM/IOExceptions are encountered
while processing the address book XML file.populatePersons(),
populateGroups()private void populatePersons()
persons
Map of Person objects. Fetches all the
children of the personsElement root
Element in the address book XML file.
populatePerson( Element )private Person populatePerson(org.jdom.Element element)
person
element, and create a corresponding Person bean.
element - - The current person element.
private void populateAddresses(Person person,
org.jdom.Element personElement)
Person.addresses list, if address data is
available for the specified person element in the
address book.
person - - The java bean to which the address list
is to be added.personElement - - The person element
in which to look for address information.private void populateGroups()
groups list
of Group objects. Fetches all the children
under the groupsElement root Element in the
address book XML file.
populateGroup( Element )private Group populateGroup(org.jdom.Element group)
group
element, and create a Group object out of the contents.
group - - The specific group element
to process.
public void addPerson(Person person)
throws AddressException
Person java bean to the address book.
This method checks to make sure that an entry with the same
Person.nickname does not exist in the persons
Map. The specified Person object is added
both to the persons Map, as well as to the
JDOM tree.
Note:This method does not write the modified JDOM tree
back to the address book file. To save your modifications, please
use the saveAddressBook() method.
person - - The java bean with all the information
pertaining to a person entry in the address book.
AddressException - - If the specified Person has an
identical Person.nickname as an existing entry in the
persons Map.addPersonToTree( Person )public void modifyPerson(Person person)
Person java bean that has been modified
to the underlying JDOM tree. The easiest way to do this is to
remove the existing person element, and add the
modified Person bean as a new child element of the
persons element using addPersonToTree(
Person ).
Note:This method does not write the modified JDOM tree
back to the address book file. To save your modifications, please
use the saveAddressBook() method.
person - - The java bean with all the information
pertaining to a person entry in the address book.private void addPersonToTree(Person person)
Person object to the JDOM tree as a
person element.
Note:This method does not write the modified JDOM tree
back to the address book file. To save your modifications, please
use the saveAddressBook() method.
person - - The java bean with all the information
pertaining to a person entry in the address book.public boolean deletePersons(java.lang.String[] nicknames)
Person's identified by the specified Person.nicknames. This method removes the Person's from
the persons Map as well as the appropriate
element from the underlying JDOM tree. This method
just iterates through the array, and invokes deletePerson( String ) to delete each Person specified.
nicknames - - The nickname of the person that is to
be removed.
true if the nickname exists
in the persons Map, and false
otherwise. A return value of false indicates that
not all the specified persons could be deleted, as not all of
them were valid.public boolean deletePerson(java.lang.String nickname)
Person identified by the specified Person.nickname. This method removes the Person from
the persons Map as well as the appropriate
element from the underlying JDOM tree.
nickname - - The nickname of the person that is to
be removed.
true if the nickname exists
in the persons Map, and false
otherwise.
private void addAddress(java.util.List list,
org.jdom.Element component)
Address objects in the specified list to the
specified element.
list - - The list containing the addresses for the
person.component - - The element to which the addresses
are to be added.
public void addGroup(Group group)
throws AddressException
Group to the address book. This method
checks to make sure that a Group with the Group.nickname does not exist in the groups
Map. This method adds the specified Group
to the groups Map as well as the JDOM tree.
Note:This method does not save the modification to the
JDOM tree to the address book xml file. Please use the saveAddressBook() method, if you wish to save your changes.
group - - The new group that is to be added to the
address book.
AddressException - - If the specified Group has an
identical Group.nickname as an existing entry in the
groups Map.public void modifyGroup(Group group)
Group in the address book. This
method modifies the specified Group in the groups
Map as well as the under-lying element in the JDOM
tree.
Note:This method does not save the modification to the
JDOM tree to the address book xml file. Please use the saveAddressBook() method, if you wish to save your changes.
group - - The new group that is to be added to the
address book.addGroupToTree( Group )private void addGroupToTree(Group group)
Group object under the groupsElement node in the JDOM tree.
group - - The group bean that is to be added.public void modifyAssociatedGroup(Person person)
Group in the groups Map
(if any), and change the Member.mail to the
Person.mail of the Person object passed in. If an
associated Group is found, also modify the underlying
JDOM tree.
Note:This method does not save the modification to the
JDOM tree to the address book xml file. Please use the saveAddressBook() method, if you wish to save your changes.
public boolean deleteGroups(java.lang.String[] nicknames)
Group's identified by the Group.nickname's specified from the address book. This method
deletes the specified Group's from the groups
Map as well as the under-lying elements in the JDOM
tree. This method simply iterates through the entries in the
array, and invokes deleteGroup( String ) to delete the
individual entry.
Note:This method does not save the modification to the
JDOM tree to the address book xml file. Please use the saveAddressBook() method, if you wish to save your changes.
nicknames - - The groups that are to be deleted.
true if the specified
nicknames exists in the groups Map. If not
it returns false. A return value of
false indicates that some/all of the groups
specified could not be deleted, as they are not valid groups.public boolean deleteGroup(java.lang.String nickname)
Group identified by the Group.nickname
specified from the address book. This method deletes the
specified Group from the groups
Map as well as the under-lying element in the JDOM
tree.
Note:This method does not save the modification to the
JDOM tree to the address book xml file. Please use the saveAddressBook() method, if you wish to save your changes.
nickname - - The group that is to be deleted.
true if the specified
nickname exists in the groups Map. If not
it returns false.
public void saveAddressBook()
throws AddressException
AddressException - - If any exceptions are encountered while
serialising the JDOM tree to the address book file.
public static AddressBook createAddressBook(java.lang.String file)
throws AddressException
createAddressBook( String, String ) with a
null value for the default SAX Parser.
file - - The fully qualified name of the file ie. the
full path and name of file to use as the address book.
AddressException - - If any exceptions are encountered while
creating or writing to the specified file.
public static AddressBook createAddressBook(java.lang.String file,
java.lang.String saxParser)
throws AddressException
file - - The fully qualified name of the file ie. the
full path and name of file to use as the address book.saxParser - - The full class name of the preferred
SAX Parser. If this is null the default JAXP
SAX Parser will be used.
AddressException - - If any exceptions are encountered while
creating or writing to the specified file.public final java.util.Map getPersons()
persons.
public final java.util.Map getGroups()
groups.
public final void setFileName(java.lang.String fileName)
fileName.
fileName - - The value to set.
|
Rakesh API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||