accessing outer class variables

Hi,

The java stylesheet produces variable declarations within the runTest()
method.

When defining filters you don't have access to the outer class variables
from within the produced inner class.

Is there a way to define class level variables ?

As a workaround I tried to locally declare variables within the inner
class by doing:


  <var name="myfilter"         type="DOMBuilderFilter">
     <var name="name"            type="DOMString"/>
     <var name='SHOW_ELEMENT'    type='int'    value='1'/>
     <var name='FILTER_ACCEPT'   type='short'  value='1'/>
     <var name='FILTER_REJECT'   type='short'  value='2'/>
     <var name='FILTER_SKIP'     type='short'  value='3'/>


     <startElement>
        <nodeName var="name" obj="elt"/>
        <if>
            <equals actual="name" expected='"elt1"' ignoreCase="false"/>
            <return value="FILTER_REJECT"/>
          <else>
            <return value="FILTER_ACCEPT"/>
          </else>
        </if>
     </startElement>

     <acceptNode>
            <return value="FILTER_ACCEPT"/>
     </acceptNode>

     <whatToShow interface="DOMBuilderFilter">
       <get>
        <return value="SHOW_ELEMENT"/>
       </get>
     </whatToShow>

  </var>



This produces a java test as follows:


public class DOMBuilderFilterTest extends DOMTestCase {

   public DOMBuilderFilterTest(DOMTestDocumentBuilderFactory factory){
      super(factory);
   }

   private class DOMBuilderFilterN1E extends DOMTestInnerClass implements
DOMBuilderFilter {
     String name;
     int SHOW_ELEMENT;
     short FILTER_ACCEPT;
     short FILTER_REJECT;
     short FILTER_SKIP;

     public DOMBuilderFilterN1E(DOMTestCase test, int SHOW_ELEMENT, short
FILTER_ACCEPT, short FILTER_REJECT, short FILTER_SKIP) {
        super(test);
        this.SHOW_ELEMENT = SHOW_ELEMENT;
        this.FILTER_ACCEPT = FILTER_ACCEPT;
        this.FILTER_REJECT = FILTER_REJECT;
        this.FILTER_SKIP = FILTER_SKIP;
     }
     public short startElement(Element elt) {

      .......
  }



  public void runTest() throws java.lang.Throwable {
     DOMBuilderFilter myfilter = new DOMBuilderFilterN1E(this, 1, 1, 2, 3 );

     .....
  }
  ......
}



The problem with this workaround is that the variables that are passed to
the constructor of the inner class are not properly typed.

     DOMBuilderFilter myfilter = new DOMBuilderFilterN1E(this, 1, 1, 2, 3 );

should be:

     DOMBuilderFilter myfilter = new DOMBuilderFilterN1E(this, (int)1,
(short)1, (short)2, (short)3 );


Since 1 is by default int.


Jeroen

Received on Sunday, 26 January 2003 11:07:28 UTC