View Javadoc

1   package org.sat4j.csp.xml;
2   import org.xml.sax.Attributes;
3   
4   class Domain extends Element {
5   
6   	private static final String INTERVAL_SEPARATOR = "..";
7   	
8   	private StringBuilder allValues;
9   
10  
11  	public Domain(ICSPCallback out,String tagName) {
12  		super(out,tagName);
13  	}
14  
15  	public void startElement(Attributes att) {
16  		int nbValues = -1;
17  		String tmpValues = att.getValue("nbValues");
18  		if (tmpValues != null)
19  			nbValues = Integer.parseInt(tmpValues);
20  		getCB().beginDomain(att.getValue("name"), nbValues);
21  		allValues = new StringBuilder();
22  	}
23  
24  	public void endElement() {
25  		if (allValues != null) {
26  			String[] tokens = allValues.toString().trim().split("\\s+");
27  			int index;
28  			for (String token : tokens) {
29  				if (!token.equals("")) {
30  					index = token.indexOf(INTERVAL_SEPARATOR);
31  					if (index > -1)
32  						getCB().addDomainValue(Integer.parseInt(token.substring(0,index)),
33  								Integer.parseInt(token.substring(index+2)));
34  					else
35  						getCB().addDomainValue(Integer.parseInt(token));
36  				}
37  			}
38  		}
39  		getCB().endDomain();
40  	}
41  
42  	public void characters(String allValues) {
43  		this.allValues.append(allValues);
44  	}
45  
46  }