1 Reply Latest reply: Apr 25, 2012 3:19 AM by Frank Nimphius-Oracle RSS

    How Do I Use Generics with Framework Extension Classes?

    809249
      Hi Guys and Gals,

      I've been writing alot of duplicate code lately for ViewObjects that are all basically the same. So it occurred to me that perhaps I could put shared code in a Framework Extension Class. My problem lies in the fact that I do quite a bit of class casting as well. I thought perhaps Generics could come to the rescue. But uh ... I don't really know anything about them, which makes asking the right questions or even researching difficult.

      Here's an example of what I would like to accomplish.

      I have many different Master-Detail ViewObjects which are all pretty much the same. For example ...

      PurchaseOrder (1-*) PoRows
      SalesOrder (1-*) SoRows
      Invoice (1-*) InvoiceRows
      etc...

      Here is sample code for the PurchaseOrder / PoRows
        public void cancelDocument()
        {
          RowIterator ri = this.getPoRowsVO();  // access the detail view object
          RowSetIterator rsi = ((RowSet)ri).createRowSetIterator(null);
          while(rsi.hasNext())
          {
            PoRowsVORowImpl next = (PoRowsVORowImpl)rsi.next();
            next.cancelRow();  // call a detail view object method exposed to the client
          }
          rsi.closeRowSetIterator();
        }
      However, these two lines are cause for ponderance
           1.  RowIterator ri = this.getPoRowsVO();
           2.  PoRowsVORowImpl next = (PoRowsVORowImpl)rsi.next();
      Which leads me to two questions:

      1) How do I access the Detail part of the relationship in a framwork extension class generically?
      2) If I have to cast, is there a way to read the class type through reflection and cast using a generic method with what I've found?

      I would think writing common methods in a Framework Extension class would really help make maintaining my code easier, and I could see how it would be a powerful tool. But how would one get around these ViewObject specific problems?

      Will
        • 1. Re: How Do I Use Generics with Framework Extension Classes?
          Frank Nimphius-Oracle
          Hi,

          you are correct, Generics has a different meaning in Java then what you ask for.

          Actually to access a detail row set from a parent row, you can use code like this:
              public void voRowCancel(){
                  for (int i = 0; i < this.getAttributeCount(); i++)
                      {            
                         if(this.getStructureDef().getAttributeDef(i).getAttributeKind() == AttributeDef.ATTR_ASSOCIATED_ROWITERATOR){
                           RowSet rs = (RowSet) this.getAttribute(i);
                          // ... to do ...
                      }
              }
          However, the code you invoke is on a custom implementation class, which makes it difficult to get to this from here.

          Frank