You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general-cvs@xml.apache.org by pb...@apache.org on 2002/06/22 08:02:07 UTC
cvs commit: xml-site/targets/fop/design/alt.design co-routines.html
pbwest 2002/06/21 23:02:07
Added: targets/fop/design/alt.design co-routines.html
Log:
Added intro file; separate co-routines
Revision Changes Path
1.1 xml-site/targets/fop/design/alt.design/co-routines.html
Index: co-routines.html
===================================================================
<HTML><HEAD><SCRIPT language="JavaScript" src="resources/script.js" type="text/javascript"></SCRIPT><TITLE>Implementing co-routines</TITLE></HEAD><BODY alink="#cc0000" bgcolor="#ffffff" leftmargin="4" link="#039acc" marginheight="4" marginwidth="4" text="#000000" topmargin="4" vlink="#0086b2"><TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD align="left" height="60" rowspan="3" valign="top" width="135"><IMG border="0" height="60" hspace="0" src="resources/logo.gif" vspace="0" width="135"></TD><TD align="left" background="resources/line.gif" colspan="2" height="5" valign="top" width="100%"><IMG align="left" border="0" height="5" hspace="0" src="resources/line.gif" vspace="0" width="1"></TD><TD align="left" height="60" rowspan="3" valign="top" width="29"><IMG border="0" height="60" hspace="0" src="resources/right.gif" vspace="0" width="29"></TD></TR><TR><TD align="left" bgcolor="#0086b2" colspan="2" height="35" valign="top" width="100%"><IMG align="right" alt="" border="0" height="35" hspace="0" src="graphics/co-routines-header.jpg" vspace="0" width="456"></TD></TR><TR><TD align="left" background="resources/bottom.gif" bgcolor="#0086b2" height="20" valign="top" width="100%"><IMG align="left" border="0" height="20" hspace="0" src="resources/bottom.gif" vspace="0" width="3"></TD><TD align="right" background="resources/bottom.gif" bgcolor="#0086b2" height="20" valign="top" width="288"><TABLE border="0" cellpadding="0" cellspacing="0" width="288"><TR><TD align="left" height="20" valign="top" width="96"><A href="http://xml.apache.org/" onMouseOut="rolloverOff('xml');" onMouseOver="rolloverOn('xml');" target="new"><IMG alt="http://xml.apache.org/" border="0" height="20" hspace="0" name="xml" onLoad="rolloverLoad('xml','resources/button-xml-hi.gif','resources/button-xml-lo.gif');" src="resources/button-xml-lo.gif" vspace="0" width="96"></A></TD><TD align="left" height="20" valign="top" width="96"><A href="http://www.apache.org/" onMouseOut="rolloverOff('asf');" onMouseOver="rolloverOn('asf');" target="new"><IMG alt="http://www.apache.org/" border="0" height="20" hspace="0" name="asf" onLoad="rolloverLoad('asf','resources/button-asf-hi.gif','resources/button-asf-lo.gif');" src="resources/button-asf-lo.gif" vspace="0" width="96"></A></TD><TD align="left" height="20" valign="top" width="96"><A href="http://www.w3.org/" onMouseOut="rolloverOff('w3c');" onMouseOver="rolloverOn('w3c');" target="new"><IMG alt="http://www.w3.org/" border="0" height="20" hspace="0" name="w3c" onLoad="rolloverLoad('w3c','resources/button-w3c-hi.gif','resources/button-w3c-lo.gif');" src="resources/button-w3c-lo.gif" vspace="0" width="96"></A></TD></TR></TABLE></TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD align="left" valign="top" width="120"><IMG border="0" height="14" hspace="0" src="resources/join.gif" vspace="0" width="120"><BR>
<A href="http://xml.apache.org/fop/" onMouseOut="rolloverOff('side-ext-2');" onMouseOver="rolloverOn('side-ext-2');"><IMG alt="About FOP" border="0" height="12" hspace="0" name="side-ext-2" onLoad="rolloverLoad('side-ext-2','graphics/ext-2-label-2.jpg','graphics/ext-2-label-3.jpg');" src="graphics/ext-2-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="../index.html" onMouseOut="rolloverOff('side-ext-6');" onMouseOver="rolloverOn('side-ext-6');"><IMG alt="NEW DESIGN" border="0" height="12" hspace="0" name="side-ext-6" onLoad="rolloverLoad('side-ext-6','graphics/ext-6-label-2.jpg','graphics/ext-6-label-3.jpg');" src="graphics/ext-6-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="index.html" onMouseOut="rolloverOff('side-index');" onMouseOver="rolloverOn('side-index');"><IMG alt="Alt Design" border="0" height="12" hspace="0" name="side-index" onLoad="rolloverLoad('side-index','graphics/index-label-2.jpg','graphics/index-label-3.jpg');" src="graphics/index-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG alt="co-routines" border="0" height="12" hspace="0" src="graphics/co-routines-label-1.jpg" vspace="0" width="120"><BR>
<A href="galleys.html" onMouseOut="rolloverOff('side-galleys');" onMouseOver="rolloverOn('side-galleys');"><IMG alt="galleys" border="0" height="12" hspace="0" name="side-galleys" onLoad="rolloverLoad('side-galleys','graphics/galleys-label-2.jpg','graphics/galleys-label-3.jpg');" src="graphics/galleys-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="footnotes.html" onMouseOut="rolloverOff('side-footnotes');" onMouseOver="rolloverOn('side-footnotes');"><IMG alt="footnotes" border="0" height="12" hspace="0" name="side-footnotes" onLoad="rolloverLoad('side-footnotes','graphics/footnotes-label-2.jpg','graphics/footnotes-label-3.jpg');" src="graphics/footnotes-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="keeps.html" onMouseOut="rolloverOff('side-keeps');" onMouseOver="rolloverOn('side-keeps');"><IMG alt="keeps" border="0" height="12" hspace="0" name="side-keeps" onLoad="rolloverLoad('side-keeps','graphics/keeps-label-2.jpg','graphics/keeps-label-3.jpg');" src="graphics/keeps-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="spaces.html" onMouseOut="rolloverOff('side-spaces');" onMouseOver="rolloverOn('side-spaces');"><IMG alt="space-specifiers" border="0" height="12" hspace="0" name="side-spaces" onLoad="rolloverLoad('side-spaces','graphics/spaces-label-2.jpg','graphics/spaces-label-3.jpg');" src="graphics/spaces-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="alt.properties.html" onMouseOut="rolloverOff('side-alt.properties');" onMouseOver="rolloverOn('side-alt.properties');"><IMG alt="alt.properties" border="0" height="12" hspace="0" name="side-alt.properties" onLoad="rolloverLoad('side-alt.properties','graphics/alt.properties-label-2.jpg','graphics/alt.properties-label-3.jpg');" src="graphics/alt.properties-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="classes-overview.html" onMouseOut="rolloverOff('side-classes-overview');" onMouseOver="rolloverOn('side-classes-overview');"><IMG alt="Classes overview" border="0" height="12" hspace="0" name="side-classes-overview" onLoad="rolloverLoad('side-classes-overview','graphics/classes-overview-label-2.jpg','graphics/classes-overview-label-3.jpg');" src="graphics/classes-overview-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="properties-classes.html" onMouseOut="rolloverOff('side-properties-classes');" onMouseOver="rolloverOn('side-properties-classes');"><IMG alt="Properties classes" border="0" height="12" hspace="0" name="side-properties-classes" onLoad="rolloverLoad('side-properties-classes','graphics/properties-classes-label-2.jpg','graphics/properties-classes-label-3.jpg');" src="graphics/properties-classes-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="Properties.html" onMouseOut="rolloverOff('side-Properties');" onMouseOver="rolloverOn('side-Properties');"><IMG alt="Properties" border="0" height="12" hspace="0" name="side-Properties" onLoad="rolloverLoad('side-Properties','graphics/Properties-label-2.jpg','graphics/Properties-label-3.jpg');" src="graphics/Properties-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="PropertyConsts.html" onMouseOut="rolloverOff('side-PropertyConsts');" onMouseOver="rolloverOn('side-PropertyConsts');"><IMG alt="PropertyConsts" border="0" height="12" hspace="0" name="side-PropertyConsts" onLoad="rolloverLoad('side-PropertyConsts','graphics/PropertyConsts-label-2.jpg','graphics/PropertyConsts-label-3.jpg');" src="graphics/PropertyConsts-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="PropNames.html" onMouseOut="rolloverOff('side-PropNames');" onMouseOver="rolloverOn('side-PropNames');"><IMG alt="PropNames" border="0" height="12" hspace="0" name="side-PropNames" onLoad="rolloverLoad('side-PropNames','graphics/PropNames-label-2.jpg','graphics/PropNames-label-3.jpg');" src="graphics/PropNames-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="AbsolutePosition.html" onMouseOut="rolloverOff('side-AbsolutePosition');" onMouseOver="rolloverOn('side-AbsolutePosition');"><IMG alt="AbsolutePosition" border="0" height="12" hspace="0" name="side-AbsolutePosition" onLoad="rolloverLoad('side-AbsolutePosition','graphics/AbsolutePosition-label-2.jpg','graphics/AbsolutePosition-label-3.jpg');" src="graphics/AbsolutePosition-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="VerticalAlign.html" onMouseOut="rolloverOff('side-VerticalAlign');" onMouseOver="rolloverOn('side-VerticalAlign');"><IMG alt="VerticalAlign" border="0" height="12" hspace="0" name="side-VerticalAlign" onLoad="rolloverLoad('side-VerticalAlign','graphics/VerticalAlign-label-2.jpg','graphics/VerticalAlign-label-3.jpg');" src="graphics/VerticalAlign-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="BorderCommonStyle.html" onMouseOut="rolloverOff('side-BorderCommonStyle');" onMouseOver="rolloverOn('side-BorderCommonStyle');"><IMG alt="BorderCommonStyle" border="0" height="12" hspace="0" name="side-BorderCommonStyle" onLoad="rolloverLoad('side-BorderCommonStyle','graphics/BorderCommonStyle-label-2.jpg','graphics/BorderCommonStyle-label-3.jpg');" src="graphics/BorderCommonStyle-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="xml-parsing.html" onMouseOut="rolloverOff('side-xml-parsing');" onMouseOver="rolloverOn('side-xml-parsing');"><IMG alt="XML parsing" border="0" height="12" hspace="0" name="side-xml-parsing" onLoad="rolloverLoad('side-xml-parsing','graphics/xml-parsing-label-2.jpg','graphics/xml-parsing-label-3.jpg');" src="graphics/xml-parsing-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="property-parsing.html" onMouseOut="rolloverOff('side-property-parsing');" onMouseOver="rolloverOn('side-property-parsing');"><IMG alt="Property parsing" border="0" height="12" hspace="0" name="side-property-parsing" onLoad="rolloverLoad('side-property-parsing','graphics/property-parsing-label-2.jpg','graphics/property-parsing-label-3.jpg');" src="graphics/property-parsing-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="6" hspace="0" src="resources/separator.gif" vspace="0" width="120"><BR>
<A href="compound-properties.html" onMouseOut="rolloverOff('side-compound-properties');" onMouseOver="rolloverOn('side-compound-properties');"><IMG alt="Compound properties" border="0" height="12" hspace="0" name="side-compound-properties" onLoad="rolloverLoad('side-compound-properties','graphics/compound-properties-label-2.jpg','graphics/compound-properties-label-3.jpg');" src="graphics/compound-properties-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="traits.html" onMouseOut="rolloverOff('side-traits');" onMouseOver="rolloverOn('side-traits');"><IMG alt="Traits" border="0" height="12" hspace="0" name="side-traits" onLoad="rolloverLoad('side-traits','graphics/traits-label-2.jpg','graphics/traits-label-3.jpg');" src="graphics/traits-label-3.jpg" vspace="0" width="120"></A><BR>
<A href="user-agent-refs.html" onMouseOut="rolloverOff('side-user-agent-refs');" onMouseOver="rolloverOn('side-user-agent-refs');"><IMG alt="User agent refs" border="0" height="12" hspace="0" name="side-user-agent-refs" onLoad="rolloverLoad('side-user-agent-refs','graphics/user-agent-refs-label-2.jpg','graphics/user-agent-refs-label-3.jpg');" src="graphics/user-agent-refs-label-3.jpg" vspace="0" width="120"></A><BR>
<IMG border="0" height="14" hspace="0" src="resources/close.gif" vspace="0" width="120"><BR></TD><TD align="left" valign="top" width="*"><TABLE border="0" cellpadding="3" cellspacing="0"><TR><TD><BR>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" width="98%"><TR><TD align="right" height="7" valign="bottom" width="9"><IMG border="0" height="7" hspace="0" src="resources/bar-top-left.gif" vspace="0" width="9"></TD><TD background="resources/bar-border-top.gif"><IMG border="0" height="5" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD align="left" height="7" valign="bottom" width="9"><IMG border="0" height="7" hspace="0" src="resources/bar-top-right.gif" vspace="0" width="9"></TD></TR><TR><TD background="resources/bar-border-left.gif" width="9"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="9"></TD><TD bgcolor="#0086b2" width="100%"><FONT color="#ffffff" face="arial,helvetica,sanserif" size="+1"><IMG border="0" height="5" hspace="0" src="resources/void.gif" vspace="0" width="5"><B>Implementing Co-routines in FOP</B></FONT></TD><TD background="resources/bar-border-right.gif" width="9"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="9"></TD></TR><TR><TD align="right" height="12" valign="top" width="9"><IMG border="0" height="12" hspace="0" src="resources/bar-bottom-left.gif" vspace="0" width="9"></TD><TD background="resources/bar-border-bottom.gif"><IMG border="0" height="12" hspace="0" src="resources/void.gif" vspace="0"></TD><TD align="left" height="12" valign="top" width="9"><IMG border="0" height="12" hspace="0" src="resources/bar-bottom-right.gif" vspace="0" width="9"></TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0" width="98%"><TR><TD><FONT color="#000000" face="arial,helvetica,sanserif">
<P align="left">
All general page layout systems have to solve the same
fundamental problem: expressing a flow of text with its own
natural structure as a series of pages corresponding to the
physical and logical structure of the output medium. This
simple description disguises many complexities. Version 1.0
of the Recommendation, in Section 3, <I>Introduction to
Formatting </I>, includes the following comments.
</P>
<P><TABLE border="0" cellpadding="0" cellspacing="3" width="100%"><TR><TD valign="top" width="28"><IMG alt="Note" border="0" height="29" hspace="0" src="resources/note.gif" vspace="0" width="28"></TD><TD valign="top"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1"><I>
[Formatting] comprises several steps, some of which depend on
others in a non-sequential way.<BR> ...and...<BR>
[R]efinement is not necessarily a straightforward, sequential
procedure, but may involve look-ahead, back-tracking, or
control-splicing with other processes in the formatter.
</I></FONT></TD></TR></TABLE></P>
<P align="left">Section 3.1, <I>Conceptual Procedure</I>, includes:</P>
<P><TABLE border="0" cellpadding="0" cellspacing="3" width="100%"><TR><TD valign="top" width="28"><IMG alt="Note" border="0" height="29" hspace="0" src="resources/note.gif" vspace="0" width="28"></TD><TD valign="top"><FONT color="#000000" face="arial,helvetica,sanserif" size="-1"><I>
The procedure works by processing formatting objects. Each
object, while being processed, may initiate processing in
other objects. While the objects are hierarchically
structured, the processing is not; processing of a given
object is rather like a co-routine which may pass control to
other processes, but pick up again later where it left off.
</I></FONT></TD></TR></TABLE></P>
<DIV align="right"><TABLE border="0" cellpadding="0" cellspacing="0" width="95%"><TR><TD align="right" height="7" valign="bottom" width="9"><IMG border="0" height="7" hspace="0" src="resources/bar-top-left.gif" vspace="0" width="9"></TD><TD background="resources/bar-border-top.gif"><IMG border="0" height="5" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD align="left" height="7" valign="bottom" width="9"><IMG border="0" height="7" hspace="0" src="resources/bar-top-right.gif" vspace="0" width="9"></TD></TR><TR><TD background="resources/bar-border-left.gif" width="9"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="9"></TD><TD bgcolor="#0086b2" width="100%"><FONT color="#ffffff" face="arial,helvetica,sanserif"><IMG border="0" height="5" hspace="0" src="resources/void.gif" vspace="0" width="5"><B>Application of co-routines</B></FONT></TD><TD background="resources/bar-border-right.gif" width="9"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="9"></TD></TR><TR><TD align="right" height="12" valign="top" width="9"><IMG border="0" height="12" hspace="0" src="resources/bar-bottom-left.gif" vspace="0" width="9"></TD><TD background="resources/bar-border-bottom.gif"><IMG border="0" height="12" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD align="left" height="12" valign="top" width="9"><IMG border="0" height="12" hspace="0" src="resources/bar-bottom-right.gif" vspace="0" width="9"></TD></TR></TABLE><TABLE border="0" cellpadding="0" cellspacing="0" width="95%"><TR><TD><FONT color="#000000" face="arial,helvetica,sanserif">
<P align="left">
If one looks only at the flow side of the equation, it's
difficult to see what the problem might be. The ordering of
the elements of the flow is preserved in the area tree, and
where elements are in an hierarchical relationship in the
flow, they will generally be in an hierarchical relationship
in the area tree. In such circumstances, the recursive
processing of the flow seems quite natural.
</P>
<P align="left">
The problem becomes more obvious when one thinks about the
imposition of an unrelated page structure over the
hierarchical structure of the document content. Take, e.g.,
the processing of a nested flow structure which, at a certain
point, is scanning text and generating line-areas, nested
within other block areas and possibly other line areas. The
page fills in the middle of this process. Processing at the
lowest level in the tree must now suspend, immediately
following the production of the line-area which filled the
page. This same event, however, must also trigger the closing
and flushing to the area tree of every open area of which the last
line-area was a descendant.
</P>
<P align="left">
Once all of these areas have been closed, some dormant process
or processes must wake up, flush the area sub-tree
representing the page, and open a new page sub-tree in the
area tree. Then the whole nested structure of flow objects
and area production must be re-activated, at the point in
processing at which the areas of the previous page were
finalised, but with the new page environment. The most
natural way of expressing the temporal relationship of these
processes is by means of co-routines.
</P>
<P align="left">
Normal sub-routines (methods) display a hierarchical
relationship where process A suspends on invoking process B,
which on termination returns control to A which resumes from
the point of suspension. Co-routines instead have a parallel
relationship. Process A suspends on invoking process B, but
process B also suspends on returning control to process A. To
process B, this return of control appears to be an invocation
of process A. When process A subsequently invokes B and
suspends, B behaves as though its previous invocation of A has
returned, and it resumes from the point of that invocation.
So control bounces between the two, each one resuming where it
left off.<BR><BR>
<B>Figure 1</B>
</P>
<P align="center"><IMG alt="Co-routine diagram" border="0" hspace="4" src="coroutines.png" vspace="4"></P>
<P align="left">
For example, think of a page-production method working on a
complex page-sequence-master.
</P>
<DIV align="center"><TABLE border="0" cellpadding="0" cellspacing="4"><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#ffffff"><PRE>
void makePages(...) {
...
while (pageSequence.hasNext()) {
...
page = generateNextPage(...);
boolean over = flow.fillPage(page);
if (over) return;
}
}
</PRE></TD><TD bgcolor="#0086b2" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR><TR><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD><TD bgcolor="#0086b2" height="1" width="1"><IMG border="0" height="1" hspace="0" src="resources/void.gif" vspace="0" width="1"></TD></TR></TABLE></DIV>
<P align="left">
The <CODE><FONT face="courier, monospaced">fillPage()</FONT></CODE> method, when it fills a page, will
have unfinished business with the flow, which it will want to
resume at the next call; hence co-routines. One way to
implement them in Java is by threads synchronised on some
common argument-passing object.
</P>
</FONT></TD></TR></TABLE></DIV><BR>
</FONT></TD></TR></TABLE></DIV><BR>
</TD></TR></TABLE></TD></TR></TABLE><BR><TABLE border="0" cellpadding="0" cellspacing="0" width="100%"><TR><TD bgcolor="#0086b2"><IMG height="1" src="images/dot.gif" width="1"></TD></TR><TR><TD align="center"><FONT color="#0086b2" face="arial,helvetica,sanserif" size="-1"><I>
Copyright © 2001-2002 The Apache Software Foundation.
All Rights Reserved.
</I></FONT></TD></TR></TABLE></BODY></HTML>
---------------------------------------------------------------------
To unsubscribe, e-mail: general-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: general-cvs-help@xml.apache.org