KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > xb > binding > sunday > unmarshalling > ParticleBinding


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.xb.binding.sunday.unmarshalling;
23
24 /**
25  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
26  * @version <tt>$Revision: 1958 $</tt>
27  */

28 public class ParticleBinding
29 {
30    private TermBinding term;
31    private int minOccurs = 1;
32    private int maxOccurs = -1;
33    private boolean maxOccursUnbounded;
34
35    public ParticleBinding(TermBinding term, int minOccurs, int maxOccurs, boolean maxOccursUnbounded)
36    {
37       this.term = term;
38       this.minOccurs = minOccurs;
39       this.maxOccurs = maxOccurs;
40       this.maxOccursUnbounded = maxOccursUnbounded;
41    }
42
43    public ParticleBinding(TermBinding term)
44    {
45       this.term = term;
46    }
47
48    public int getMinOccurs()
49    {
50       return minOccurs;
51    }
52
53    public int getMaxOccurs()
54    {
55       return maxOccurs;
56    }
57
58    public boolean getMaxOccursUnbounded()
59    {
60       return maxOccursUnbounded;
61    }
62
63    public void setMinOccurs(int minOccurs)
64    {
65       this.minOccurs = minOccurs;
66    }
67
68    public void setMaxOccurs(int maxOccurs)
69    {
70       this.maxOccurs = maxOccurs;
71    }
72
73    public void setMaxOccursUnbounded(boolean maxOccursUnbounded)
74    {
75       this.maxOccursUnbounded = maxOccursUnbounded;
76    }
77
78    public TermBinding getTerm()
79    {
80       return term;
81    }
82
83    public void setTerm(TermBinding term)
84    {
85       this.term = term;
86    }
87
88    public boolean isRepeatable()
89    {
90       return maxOccursUnbounded || maxOccurs > 1 || minOccurs > 1;
91    }
92
93    public boolean isRequired()
94    {
95       return isRequired(0);
96    }
97
98    public boolean isRequired(int occurs)
99    {
100       return minOccurs > occurs && (!term.isModelGroup() || ((ModelGroupBinding)term).hasRequiredParticle());
101    }
102    
103    public String JavaDoc toString()
104    {
105       return term.toString();
106    }
107 }
108
Popular Tags