KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.List JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.ArrayList JavaDoc;
27
28 import javax.xml.namespace.QName JavaDoc;
29 import org.jboss.xb.binding.metadata.AddMethodMetaData;
30 import org.jboss.xb.binding.metadata.ClassMetaData;
31 import org.jboss.xb.binding.metadata.MapEntryMetaData;
32 import org.jboss.xb.binding.metadata.PutMethodMetaData;
33 import org.jboss.xb.binding.metadata.ValueMetaData;
34 import org.jboss.xb.binding.JBossXBRuntimeException;
35 import org.jboss.xb.binding.sunday.marshalling.TermBeforeMarshallingCallback;
36 import org.jboss.xb.binding.sunday.xop.XOPUnmarshaller;
37
38 /**
39  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
40  * @version <tt>$Revision: 2139 $</tt>
41  */

42 public class ElementBinding
43    extends TermBinding
44 {
45    protected List JavaDoc interceptors = Collections.EMPTY_LIST;
46
47    protected QName JavaDoc qName;
48    protected TypeBinding typeBinding;
49    protected boolean nillable;
50
51    protected XOPUnmarshaller xopUnmarshaller;
52
53    public ElementBinding(SchemaBinding schema, QName JavaDoc qName, TypeBinding typeBinding)
54    {
55       super(schema);
56       this.qName = qName;
57       this.typeBinding = typeBinding;
58
59       if(qName == null)
60       {
61          throw new JBossXBRuntimeException("Each element must have a non-null QName!");
62       }
63    }
64
65    protected ElementBinding()
66    {
67    }
68    
69    public QName JavaDoc getQName()
70    {
71       return qName;
72    }
73
74    public List JavaDoc getInterceptors()
75    {
76       return interceptors;
77    }
78
79    public TypeBinding getType()
80    {
81       return typeBinding;
82    }
83
84    public void pushInterceptor(ElementInterceptor interceptor)
85    {
86       switch(interceptors.size())
87       {
88          case 0:
89             interceptors = Collections.singletonList(interceptor);
90             break;
91          case 1:
92             interceptors = new ArrayList JavaDoc(interceptors);
93          default:
94             interceptors.add(interceptor);
95
96       }
97    }
98
99    public ClassMetaData getClassMetaData()
100    {
101       ClassMetaData result = classMetaData;
102       if(result == null && mapEntryMetaData == null)
103       {
104          result = typeBinding.getClassMetaData();
105       }
106       return result;
107    }
108
109    public MapEntryMetaData getMapEntryMetaData()
110    {
111       MapEntryMetaData result = mapEntryMetaData;
112       if(result == null && classMetaData == null)
113       {
114          result = typeBinding.getMapEntryMetaData();
115       }
116       return result;
117    }
118
119    public ValueMetaData getValueMetaData()
120    {
121       return valueMetaData != null ? valueMetaData : typeBinding.getValueMetaData();
122    }
123
124    public PutMethodMetaData getPutMethodMetaData()
125    {
126       // todo should types be allowed to have putMethod metadata
127
return putMethodMetaData;
128    }
129
130    public AddMethodMetaData getAddMethodMetaData()
131    {
132       AddMethodMetaData result = addMethodMetaData;
133       if(result == null && putMethodMetaData == null && propertyMetaData == null)
134       {
135          result = typeBinding.getAddMethodMetaData();
136       }
137       return result;
138    }
139
140    public boolean isSkip()
141    {
142       return skip == null ? typeBinding.isSkip() : skip.booleanValue();
143    }
144
145    public ValueAdapter getValueAdapter()
146    {
147       return valueAdapter == null ? typeBinding.getValueAdapter() : valueAdapter;
148    }
149
150    public TermBeforeMarshallingCallback getBeforeMarshallingCallback()
151    {
152       return beforeMarshallingCallback == null ? typeBinding.getBeforeMarshallingCallback() : beforeMarshallingCallback;
153    }
154
155    public TermBeforeSetParentCallback getBeforeSetParentCallback()
156    {
157       return beforeSetParentCallback == null ? typeBinding.getBeforeSetParentCallback() : beforeSetParentCallback;
158    }
159
160    public boolean isNillable()
161    {
162       return nillable;
163    }
164
165    public void setNillable(boolean nillable)
166    {
167       this.nillable = nillable;
168    }
169
170    public boolean isModelGroup()
171    {
172       return false;
173    }
174
175    public boolean isWildcard()
176    {
177       return false;
178    }
179
180    public boolean isElement()
181    {
182       return true;
183    }
184
185    public XOPUnmarshaller getXopUnmarshaller()
186    {
187       return xopUnmarshaller == null ? typeBinding.getXopUnmarshaller() : xopUnmarshaller;
188    }
189
190    public void setXopUnmarshaller(XOPUnmarshaller xopUnmarshaller)
191    {
192       this.xopUnmarshaller = xopUnmarshaller;
193    }
194
195    public String JavaDoc toString()
196    {
197       return super.toString() + "(" + qName + ", type=" + typeBinding.getQName() + ")";
198    }
199 }
200
Popular Tags