View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
11   */
12  /*
13   * This file is protected by the Mozilla Public License
14   * located in euromath2-bin.zip file, downloadable from
15   * http://sourceforge.net/projects/euromath2/.
16   */
17  package sk.uniba.euromath.document.schema;
18  import java.util.ArrayList;
19  import java.util.List;
20  import sk.baka.ikslibs.ptr.DOMPoint;
21  import sk.uniba.euromath.document.schema.plug.IElementSequenceRuleP;
22  import sk.uniba.euromath.document.schema.plug.IInsertListP;
23  /***
24   * Represents rule generating sequence of elements.
25   * @author Martin Vysny
26   */
27  public class ElementSequenceRule {
28  	/***
29  	 * Original rule.
30  	 */
31  	private final IElementSequenceRuleP seqRule;
32  	/***
33  	 * Constructs the wrapper.
34  	 * @param seqRule original rule.
35  	 */
36  	ElementSequenceRule(IElementSequenceRuleP seqRule) {
37  		super();
38  		this.seqRule = seqRule;
39  	}
40  	/***
41  	 * <p>
42  	 * Computes all possibilities of sequences, that can be generated by this
43  	 * rule. There must be only such insertlists, that doesn't contain optional
44  	 * elements. There must be no duplicite insertlists. If no elements are
45  	 * required to be created then an empty list shall be returned.
46  	 * </p>
47  	 * <p>
48  	 * All insertpoints in each returned insertlist must be equal to
49  	 * <code>start</code>. All one-item-length insertlists must be grouped
50  	 * together into one insert list.
51  	 * </p>
52  	 * @param start insertpoint, from which the numbering must start. It is
53  	 * guaranteed that <code>start.pos == 0</code> is true.
54  	 * @return array of Insertlists, that can generate sequence of element,
55  	 * never <code>null</code>.
56  	 */
57  	public List<InsertList> getSequences(DOMPoint start) {
58  		if (seqRule == null)
59  			return new ArrayList<InsertList>(0);
60  		List<? extends IInsertListP> seqs = seqRule.getSequences(start);
61  		List<InsertList> result = new ArrayList<InsertList>(seqs.size());
62  		for (IInsertListP ilP:seqs) {
63  			result.add(new InsertList(ilP));
64  		}
65  		return result;
66  	}
67  }