× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Tables, Wrappers and MLs, oh my!
  • From: "Fred Kulack" <kulack@xxxxxxxxxx>
  • Date: Thu, 22 Mar 2001 13:49:18 -0600
  • Importance: Normal


On 03/22/2001 at 07:57:58 AM, "Stone, Brad V (TC)" <bvstone@taylorcorp.com>
wrote:
if I have the code...

Table myTable = new Table();
myTable.setFormatter(new XMLTableFormatter());
myTable.toML();

With the following construcion:
Table is a vector of Rows
Rows is a vector of Fields

1.  Where and how do I set the wrapper for the Field?
2.  Where and how do I set the wrapper for the Row?
3.  What if I wanted HTML.  I need to set HTML tags then for each Field and
Row (<td> and <tr>, but...see number 4
4.  Again, if it's HTML, a field could have a class assigned to it.  That's
specific to HTML.  Should it be included in the Field definition as an
attribute?
5.  What if a new ML type is added that is totally different.  now I have
the possibilities of NEW attributes being added specific to that 'ML.

With everything encupsulated as shown in the example above, There's no way
to set these attributes.  I'm not talking just one or two, I'm talking
infinte possiblities.

The Field it is possible because I can use the field column name for the
XML
tag as a default.  But I still have no way of passing any different data
into the field when each one is created because everything is so
encapsulated.
--- end of excerpt ---

Ah. Add another level of encapsulation.
This is the solution to all design questions. You simply encapsulate more,
and
if you find its difficult, you mix your encapsulation around a bit.
(Tongue in cheek ;-)

Create 'MLAttribute' Interface and XML/HTML implementations of it.
The XXXFormatter and the XXXMLAttribute work together to
get the final goel done.

Create abstraction so that Table, Row, Field use the generic Formatter
and MLAttribute objects.

The user code does set up the tiny piece of code that cares about WHICH
type of formatting is being done, all the rest is generic.


Table myTable = new Table();
numRows = myTable.getNumRows();
numFields = myTable.getNumFields();

GenericFormatter    fmt = null;
MLAttributes        tblAttr = null;
MLAttributes        rowAttr[] = new MLAttributes[numRows];
MLAttributes        fieldAttr[] = new MLAttributes[numFields];

if (isXML) {
   // First get very specific into the right type
   // of formatter.
   XMLTableFormatter  xmlFmt         = new XMLTableFormatter;
   XMLMLAttributes    xmlTblAttr     = new XMLMLAttributes();
   XMLMLAttributes    xmlRowAttr[]   = new XMLMLAttributes[numRows];
   XMLMLAttributes    xmlFieldAttr[] = new XMLMLAttributes[numFields];

   xmlTblAttr = new XMLMLAttributes();
   xmlTblAttr.setWrapper("Table");

   for (int rowN=0; i<numRows; ++i) {
     // In reality, use 1 of these if the attributes for each
     // row are the same.
     xmlRowAttr[rowN] = new XMLMLAttributes();
     xmlRowAttr[rowN].setWrapper("Data");
   }
   for (int fieldN=0; i<numFields; ++i) {
     xmlFieldAttr[fieldN] = new XMLMLAttributes()
     // Perhaps table is defined to use some appropriately
     // generic setXxxx method on the attributes object
     // for each time its called for a field.
     // i.e. the table would do MLAttribute.setName()
     // and an XMLMLAttribute might use that for the
     // setWrapper() method, while the HTMLMLAttribute()
     // might simply ignore it.
   }
   // Now go back to generic for the rest of the code
   fmt = xmlFmt;
   tblAttr = xmlTblAttr;
   // Yes, this array assigment is compatible due to
   // the relationship between the XMLMLAttributes and
   // the MLAttributes objects.
   rowAttr = xmlRowAttr;
   fieldAttr = xmlFieldAttr;
}
else if (isHTML) {
   // First get very specific into the right type
   // of formatter.
   HTMLTableFormatter  htmlFmt         = new HTMLTableFormatter;
   HTMLMLAttributes    htmlTblAttr     = new HTMLMLAttributes();
   HTMLMLAttributes    htmlRowAttr[]   = new HTMLMLAttributes[numRows];
   HTMLMLAttributes    htmlFieldAttr[] = new HTMLMLAttributes[numFields];

   htmlTblAttr = new HTMLMLAttributes();
   htmlTblAttr.setHTMLOpenTag("<td>");
   htmlTblAttr.setHTMLCloseTag("</td>");

   for (int rowN=0; i<numRows; ++i) {
     // In reality, use 1 of these if the attributes for each
     // row are the same.
     htmlRowAttr[rowN] = new HTMLMLAttributes();
     htmlRowAttr[rowN].setHtmlOpenTag("<tr>");
     htmlRowAttr[rowN].setHtmlCloseTag("</tr>");
   }
   for (int fieldN=0; i<numFields; ++i) {
     htmlFieldAttr[fieldN] = new HTMLMLAttributes()
     // Perhaps table is defined to use some appropriately
     // generic setXxxx method on the attributes object
     // for each time its called for a field.
     // i.e. the table would do MLAttribute.setName()
     // and an XMLMLAttribute might use that for the
     // setWrapper() method, while the HTMLMLAttribute()
     // might simply ignore it.
     htmlFieldAttr[fieldN].setClass(myTable.getFieldClass(fieldN));
   }
   // Now go back to generic for the rest of the code
   fmt = htmlFmt;
   tblAttr = htmlTblAttr;
   // Yes, this array assigment is compatible due to
   // the relationship between the HTMLMLAttributes and
   // the MLAttributes objects.
   rowAttr = htmlRowAttr;
   fieldAttr = htmlFieldAttr;
}


myTable.setFormatter(new XMLTableFormatter());
// In reality, might have a single set method
// if we desired to use one set of attributes
// for all rows.
for (int rowN=0; i<numRows; ++i) {
  myTable.setRowAttributes(rowN, rowAttr[rowN]);
}
for (int fieldN=0; i<numFields; ++i) {
  myTable.setFieldAttributes(fieldN, fieldAttr[fieldN])
}
myTable.toML();




"The stuff we call "software" is not like anything that human society
  is used to thinking about. Software is something like a machine, and
  something like mathematics, and something like language, and
  something like thought, and art, and information...
  but software is not in fact any of those other things."
Bruce Sterling - The Hacker Crackdown

Fred A. Kulack  -  AS/400e  Java and Java DB2 access, Jdbc, JTA, etc...
IBM in Rochester, MN  (Phone: 507.253.5982   T/L 553-5982)
mailto:kulack@us.ibm.com   Personal: mailto:kulack@bresnanlink.net
AOL Instant Messenger: Home:FKulack  Work:FKulackWrk

+---
| This is the JAVA/400 Mailing List!
| To submit a new message, send your mail to JAVA400-L@midrange.com.
| To subscribe to this list send email to JAVA400-L-SUB@midrange.com.
| To unsubscribe from this list send email to JAVA400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner: joe@zappie.net
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.