]> gerrit.simantics Code Review - simantics/interop.git/blob - org.simantics.xml.sax/src/org/simantics/xml/sax/MultiplicityRestriction.java
Attribute namespace handling overrides.
[simantics/interop.git] / org.simantics.xml.sax / src / org / simantics / xml / sax / MultiplicityRestriction.java
1 package org.simantics.xml.sax;\r
2 \r
3 import org.w3._2001.xmlschema.Any;\r
4 import org.w3._2001.xmlschema.Element;\r
5 import org.w3._2001.xmlschema.Group;\r
6 \r
7 class MultiplicityRestriction {\r
8         long min;\r
9         long max;\r
10         \r
11         public MultiplicityRestriction(Element element) {\r
12                 long min = 1;\r
13                 if (element.getMinOccurs() != null)\r
14                         min = element.getMinOccurs().longValue();\r
15                 String element_maxS = element.getMaxOccurs();\r
16                 max = 1;\r
17                 \r
18                 if ("unbounded".equals(element_maxS)) {\r
19                         max = -1;\r
20                 } else if (element_maxS != null) {\r
21                         max = Long.parseLong(element_maxS);\r
22                         max = Math.max(min, max);\r
23                 }\r
24         }\r
25         \r
26         public MultiplicityRestriction(Group element) {\r
27                 long min = 1;\r
28                 if (element.getMinOccurs() != null)\r
29                         min = element.getMinOccurs().longValue();\r
30                 String element_maxS = element.getMaxOccurs();\r
31                 max = 1;\r
32                 \r
33                 if ("unbounded".equals(element_maxS)) {\r
34                         max = -1;\r
35                 } else if (element_maxS != null) {\r
36                         max = Long.parseLong(element_maxS);\r
37                         max = Math.max(min, max);\r
38                 }\r
39         }\r
40         \r
41         public MultiplicityRestriction(Any element) {\r
42                 long min = 1;\r
43                 if (element.getMinOccurs() != null)\r
44                         min = element.getMinOccurs().longValue();\r
45                 String element_maxS = element.getMaxOccurs();\r
46                 max = 1;\r
47                 \r
48                 if ("unbounded".equals(element_maxS)) {\r
49                         max = -1;\r
50                 } else if (element_maxS != null) {\r
51                         max = Long.parseLong(element_maxS);\r
52                         max = Math.max(min, max);\r
53                 }\r
54         }\r
55         \r
56         public long getMin() {\r
57                 return min;\r
58         }\r
59         \r
60         public long getMax() {\r
61                 return max;\r
62         }\r
63         \r
64         public boolean many() {\r
65                 return max != 1;\r
66         }\r
67         \r
68         public boolean single() {\r
69                 return max == 1;\r
70         }\r
71         \r
72         public boolean singleOptional() {\r
73                 return max == 1 && min == 0;\r
74         }\r
75         \r
76         public boolean singleRequired() {\r
77                 return max == 1 && min == 1;\r
78         }\r
79         \r
80         @Override\r
81         public boolean equals(Object obj) {\r
82                 if (obj == null)\r
83                         return false;\r
84                 if (!getClass().equals(obj.getClass()))\r
85                         return false;\r
86                 MultiplicityRestriction other = (MultiplicityRestriction)obj;\r
87                 return (min == other.min && max == other.max);\r
88         }\r
89         \r
90         @Override\r
91         public int hashCode() {\r
92                 return Long.hashCode(min) + Long.hashCode(max);\r
93         }\r
94 }