Esempio n. 1
0
    // Depth first
    public void walkJAXBElements(Object parent) {

      List children = getChildren(parent);
      if (children != null) {

        for (Object o : children) {

          // if its wrapped in javax.xml.bind.JAXBElement, get its
          // value; this is ok, provided the results of the Callback
          // won't be marshalled
          o = XmlUtils.unwrap(o);

          // workaround for broken getParent (since 3.0.0)
          if (o instanceof Child) {
            if (parent instanceof SdtBlock) {
              ((Child) o).setParent(((SdtBlock) parent).getSdtContent());
              /*
              * getParent on eg a P in a SdtBlock should return SdtContentBlock, as
              * illustrated by the following code:
              *
              	SdtBlock sdtBloc = Context.getWmlObjectFactory().createSdtBlock();
              	SdtContentBlock sdtContentBloc = Context.getWmlObjectFactory().createSdtContentBlock();
              	sdtBloc.setSdtContent(sdtContentBloc);
              	P p = Context.getWmlObjectFactory().createP();
              	sdtContentBloc.getContent().add(p);
              	String result = XmlUtils.marshaltoString(sdtBloc, true);
              	System.out.println(result);
              	SdtBlock rtp = (SdtBlock)XmlUtils.unmarshalString(result, Context.jc, SdtBlock.class);
              	P rtr = (P)rtp.getSdtContent().getContent().get(0);
              	System.out.println(rtr.getParent().getClass().getName() );
              *
              * Similarly, P is the parent of R; the p.getContent() list is not the parent
              *
              	P p = Context.getWmlObjectFactory().createP();
              	R r = Context.getWmlObjectFactory().createR();
              	p.getContent().add(r);
              	String result = XmlUtils.marshaltoString(p, true);
              	P rtp = (P)XmlUtils.unmarshalString(result);
              	R rtr = (R)rtp.getContent().get(0);
              	System.out.println(rtr.getParent().getClass().getName() );
              */
              // TODO: other corrections
            } else {
              ((Child) o).setParent(parent);
            }
          }

          this.apply(o);

          if (this.shouldTraverse(o)) {
            walkJAXBElements(o);
          }
        }
      }
    }
    @Override
    public void walkJAXBElements(Object parent) {

      List children = getChildren(parent);
      if (children != null) {

        for (Object o : children) {

          // if its wrapped in javax.xml.bind.JAXBElement, get its
          // value; this is ok, provided the results of the Callback
          // won't be marshalled
          o = XmlUtils.unwrap(o);

          // workaround for broken getParent (since 3.0.0)
          if (o instanceof Child) {
            if (parent instanceof SdtBlock) {
              ((Child) o).setParent(((SdtBlock) parent).getSdtContent().getContent());
              // Is that the right semantics for parent object?
              // TODO: other corrections
            } else {
              ((Child) o).setParent(parent);
            }
          }

          this.apply(o);

          if (o instanceof SdtBlock) {
            ll.addLast((SdtBlock) o);
          }

          if (this.shouldTraverse(o)) {
            walkJAXBElements(o);
          }

          if (o instanceof SdtBlock) {
            ll.removeLast();
          }
        }
      }
    }
  @Override // so we can manage the stack
  public void walkJAXBElements(Object parent) {

    if (parent instanceof P) {
      pStack.push((P) parent);
    }

    // Same as superclass:
    List children = getChildren(parent);
    if (children != null) {

      for (Object o : children) {

        // if its wrapped in javax.xml.bind.JAXBElement, get its
        // value; this is ok, provided the results of the Callback
        // won't be marshalled
        o = XmlUtils.unwrap(o);

        // workaround for broken getParent (since 3.0.0)
        if (o instanceof Child) {
          if (parent instanceof SdtBlock) {
            ((Child) o).setParent(((SdtBlock) parent).getSdtContent());
          } else {
            ((Child) o).setParent(parent);
          }
        }

        this.apply(o);

        if (this.shouldTraverse(o)) {
          walkJAXBElements(o);
        }
      }
    }

    if (parent instanceof P) {
      pStack.pop();
    }
  }