1 17 package org.apache.ws.jaxme.xs.xml.impl; 18 19 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException; 20 import org.apache.ws.jaxme.xs.xml.XsAGOccurs; 21 import org.apache.ws.jaxme.xs.xml.XsObject; 22 import org.xml.sax.SAXException ; 23 24 25 45 public class XsAGOccursImpl implements XsAGOccurs { 46 private final XsObject owner; 47 private int minOccurs = 1, maxOccurs = 1; 48 49 public XsAGOccursImpl(XsObject pOwner) { 50 owner = pOwner; 51 } 52 53 public void setMaxOccurs(String pMaxOccurs) { 54 if ("unbounded".equals(pMaxOccurs)) { 55 maxOccurs = -1; 56 } else { 57 try { 58 maxOccurs = Integer.parseInt(pMaxOccurs); 59 if (maxOccurs < 0) { 60 throw new IllegalArgumentException (); 61 } 62 } catch (Exception e) { 63 throw new IllegalArgumentException ("Invalid value for maxOccurs: " + 64 pMaxOccurs + 65 "; expected 'unbounded' or a nonnegative integer value."); 66 } 67 } 68 } 69 70 public int getMaxOccurs() { 71 return maxOccurs; 72 } 73 74 public void setMinOccurs(int pMinOccurs) { 75 if (pMinOccurs < 0) { 76 throw new IllegalArgumentException ("Invalid value for minOccurs: " + 77 pMinOccurs + 78 "; expected a nonnegative integer value."); 79 } 80 minOccurs = pMinOccurs; 81 } 82 83 public int getMinOccurs() { 84 return minOccurs; 85 } 86 87 public void validate() throws SAXException { 88 if (maxOccurs != -1 && minOccurs > maxOccurs) { 89 throw new LocSAXException("The 'minOccurs' attribute value (" + 90 minOccurs + 91 ") is greater than the 'maxOccurs' attribute value (" + 92 maxOccurs + ")", owner.getLocator()); 93 } 94 } 95 } 96 | Popular Tags |