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 java.util.Map;
21  import javax.xml.namespace.QName;
22  import sk.uniba.euromath.document.schema.plug.IAttributeListRuleP;
23  import sk.uniba.euromath.document.schema.plug.IAttributeRuleP;
24  import sk.uniba.euromath.document.schema.plug.INameListP;
25  /***
26   * Wraps the <code>AttributeListRuleP</code> interface.
27   * @author Martin Vysny
28   */
29  public class AttributeListRule {
30  	private final IAttributeListRuleP listRule;
31  	/***
32  	 * Constructs a wrapper instance.
33  	 * @param listRule wrap this rule.
34  	 */
35  	public AttributeListRule(IAttributeListRuleP listRule) {
36  		super();
37  		this.listRule = listRule;
38  	}
39  	/***
40  	 * Returns lists of creatable attributes. Each <code>NameListP</code>
41  	 * instance describes one attribute rule, with possible multiple names. So,
42  	 * for one NameListP instance, each QName in map
43  	 * <code>NameListP.getLocalNames()</code> must map to one instance of
44  	 * <code>AttributeRule</code>.
45  	 * @return list of creatable attributes.
46  	 */
47  	public List<INameList<AttributeRule>> getList() {
48  		List<? extends INameListP<? extends IAttributeRuleP>> list = listRule.getList();
49  		List<INameList<AttributeRule>> result = new ArrayList<INameList<AttributeRule>>(
50  				list.size());
51  		for (INameListP<? extends IAttributeRuleP> nl : list) {
52  			result.add(new NameListWrapper<AttributeRule, IAttributeRuleP>(nl,
53  					providerInstance));
54  		}
55  		return result;
56  	}
57  	/***
58  	 * The data provider for namelist.
59  	 * @author Martin Vysny
60  	 */
61  	private class ForeignAttributesProvider implements
62  			INameListWrapperDataProvider<IAttributeRuleP> {
63  		/*
64  		 * (non-Javadoc)
65  		 * @see sk.uniba.euromath.document.schema.INameListWrapperDataProvider#getForeignRules(sk.uniba.euromath.document.schema.plug.NameListP)
66  		 */
67  		public Map<QName,IAttributeRuleP> getForeignRules(INameListP original) {
68  			return SchemaPool.getInstance().getExportedAttributes(
69  					original.getNamespaceUri(), original);
70  		}
71  	}
72  	/***
73  	 * The instance of the data provider.
74  	 */
75  	private final ForeignAttributesProvider providerInstance = new ForeignAttributesProvider();
76  }