Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA For these XMLTable steps, use the dom 4 j API which is dependency managed by Maven. 1 Serialize all types using corresponding XML equivalents

JAVA For these XMLTable steps, use the dom4j API which is dependency managed by Maven.
1 Serialize all types using corresponding XML equivalents or analogs.
2 Deserialize all types with minimal custom parsing.
3 Use XML elements, attributes, and text content efficiently and conventionally.
B' The following private fields:
1 A static constant path for the base directories, which are db sub tables relative to the project directory.
2 A path for the file, which is the table file structure in XML format.
3 A reference for the document, which is the document model representing the contents of the file.
4 No fields for the degree, size, fingerprint, or any other fields (unlike in previous modules).
C' A 2-ary constructor which takes a name parameter (string) and a columns parameter (list of strings).
1 Create the base directories, if needed.
2 Initialize the path field by resolving the given name plus the .xml extension relative to the base directories.
3 If the file doesnt exist at the path field, create it.
4 Use the document helper to create a new document, then set the document field to the result.
5 Add a new table element under the document as the root element.
6 Add a new columns element under the table element. Add the given columns as suitable column elements under it.
7 Add a new rows element under the table element.
8 Call the flush method to update the file.
D' A 1-ary constructor which takes a name parameter (string) only.
1 Initialize the path field by resolving the given name plus the .xml extension relative to the base directories.
2 If the file doesnt exist at the path field, throw an illegal argument exception.
3 Use a reader to read the document from the file, and initialize the document field to it.
4 When catching a document exception for an invalid XML file, throw an illegal state exception.
E' A public clear method.
1 Clear all row elements under the rows element.
2 Call the flush method to update the file.
F' A private flush method.
1 Use a writer to write the document to the file.
2 Configure the file output to be pretty-printed.
G' Public methods for the following statistics and predicates:
1 The name method which returns the name of the file, excluding the base directories and the .xml extension.
2 The columns method which returns appropriately from the column elements under the columns element.
3 The degree method which returns the size of the list of columns which is returned by the columns method.
4 The size method which returns the number of row elements under the rows element.
5 The hashCode method which returns the sum of the hash codes from the row elements under the rows element.
6 The equals method which returns true if the parameter is any table with the same fingerprint (as in previous modules).
7 Dont implement capacity or loadFactor, because this is a FileTable, not a DataTable.
page 3/3
H' A public iterator method which returns an iterator of rows.
1 Create an empty list of rows.
2 For each row element under the rows element, create a new row from that element, and add it to the list.
3 Call iterator on that list and return the corresponding iterator.
4 Dont implement a new iterator using an anonymous class (unlike in previous modules).
I' A public toString method.
1 Return an unsorted view of the table by calling toTabularView.
4TH QUARTER: XML PUT, GET, REMOVE
J' For these XMLTable steps, use the dom4j API which is dependency managed by Maven (as in step A').
K' A public put method which takes a key parameter (string), then a list of fields parameter (list of objects).
1 If the degree of the given row doesnt match the result of calling the degree method, throw an illegal argument exception.
2 Linear search the row elements under the rows element to find a row with the given key.
3 On a hit, remove the old row element at the key under the rows element, put the new row element as suitable at the key
under the rows element, call flush, and return the old list of fields.
4 On a miss, put the new row element at the key under the rows element, call flush, and return null.
L' A public get method which takes a key parameter.
1 Linear search the row elements under the rows element to find a row with the given key.
2 On a hit, return the old list of fields of the row element at the key under the rows element.
3 On a miss, return null.
M' A public remove method which takes a key parameter.
1 Linear search the row elements under the rows element to find a row with the given key.
2 On a hit, remove the old row element at the key under the rows element, call flush, and return the old list of fields.
3 On a miss, return null. Attach console screenshots for tabular views of two or more nontrivial tables, displayed using your Sandbox class.
At least one new table must be created in JSON format using the 2-ary constructor.
At least one existing table must be created in JSON format using the 1-ary constructor.
At least one new table must be created in XML format usin

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions