KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > xb > binding > group > ValueListInitializer


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.group;
23
24 import java.util.Map JavaDoc;
25 import java.util.Collections JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.ArrayList JavaDoc;
28 import javax.xml.namespace.QName JavaDoc;
29 import org.jboss.xb.binding.JBossXBRuntimeException;
30 import org.jboss.xb.binding.sunday.unmarshalling.AttributeBinding;
31 import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
32 import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
33 import org.jboss.xb.binding.sunday.unmarshalling.CharactersHandler;
34
35 /**
36  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
37  * @version <tt>$Revision: 2045 $</tt>
38  */

39 public class ValueListInitializer
40 {
41    private int initializedState;
42    private Map JavaDoc attrIndex = Collections.EMPTY_MAP;
43    private Map JavaDoc elemIndex = Collections.EMPTY_MAP;
44    private List JavaDoc requiredBindings = Collections.EMPTY_LIST;
45
46    public void addRequiredAttribute(QName JavaDoc qName, AttributeBinding binding)
47    {
48 /*
49       Integer index = new Integer(requiredBindings.size());
50       switch(attrIndex.size())
51       {
52          case 0:
53             attrIndex = Collections.singletonMap(qName, index);
54             break;
55          case 1:
56             attrIndex = new HashMap(attrIndex);
57          default:
58             attrIndex.put(qName, index);
59       }
60       addBinding(binding);
61       initializedState += Math.abs(qName.hashCode());
62 */

63       throw new UnsupportedOperationException JavaDoc();
64    }
65
66    public void addRequiredElement(QName JavaDoc qName, ElementBinding binding)
67    {
68 /*
69       Integer index = new Integer(requiredBindings.size());
70       switch(elemIndex.size())
71       {
72          case 0:
73             elemIndex = Collections.singletonMap(qName, index);
74             break;
75          case 1:
76             elemIndex = new HashMap(elemIndex);
77          default:
78             elemIndex.put(qName, index);
79       }
80       addBinding(binding);
81       initializedState += Math.abs(qName.hashCode());
82 */

83       throw new UnsupportedOperationException JavaDoc();
84    }
85
86    public ValueList newValueList(ValueListHandler handler, Class JavaDoc targetClass)
87    {
88       return new ValueList(this, handler, targetClass);
89    }
90
91    public void addAttributeValue(QName JavaDoc qName, AttributeBinding binding, ValueList valueList, Object JavaDoc value)
92    {
93       Integer JavaDoc index = (Integer JavaDoc)attrIndex.get(qName);
94       if(index == null)
95       {
96          valueList.setAttributeValue(qName, binding, value);
97       }
98       else
99       {
100          if(isInitialized(valueList))
101          {
102             throw new JBossXBRuntimeException("The value list has already been initialized!");
103          }
104          valueList.setRequiredValue(index.intValue(), qName.hashCode(), value);
105       }
106    }
107
108    public void addTextValue(QName JavaDoc qName,
109                             ParticleBinding particle,
110                             CharactersHandler handler,
111                             ValueList valueList,
112                             Object JavaDoc value)
113    {
114       valueList.addTextValue(qName, particle, handler, value);
115    }
116
117    public void addTermValue(QName JavaDoc qName, ParticleBinding binding, Object JavaDoc handler, ValueList valueList, Object JavaDoc value, ParticleBinding parentParticle)
118    {
119       Integer JavaDoc index = (Integer JavaDoc)elemIndex.get(qName);
120       if(index == null)
121       {
122          if(binding.isRepeatable())
123          {
124             valueList.addRepeatableTermValue(qName, binding, handler, value, parentParticle);
125          }
126          else
127          {
128             valueList.addTermValue(qName, binding, handler, value, parentParticle);
129          }
130       }
131       else
132       {
133          if(isInitialized(valueList))
134          {
135             throw new JBossXBRuntimeException("The value list has already been initialized!");
136          }
137          valueList.setRequiredValue(index.intValue(), qName.hashCode(), value);
138       }
139    }
140
141    public boolean isInitialized(ValueList valueList)
142    {
143 // return requiredBindings.size() == 0 || initializedState == valueList.getState();
144
throw new UnsupportedOperationException JavaDoc();
145    }
146
147    public Object JavaDoc getAttributeValue(QName JavaDoc qName, ValueList valueList)
148    {
149 /*
150       Object value;
151       Integer index = (Integer)attrIndex.get(qName);
152       if(index == null)
153       {
154          value = valueList.getNonRequiredValue(qName);
155       }
156       else
157       {
158          value = valueList.getRequiredValue(index.intValue());
159       }
160       return value;
161 */

162       throw new UnsupportedOperationException JavaDoc();
163    }
164
165    public Object JavaDoc getElementValue(QName JavaDoc qName, ValueList valueList)
166    {
167 /*
168       Object value;
169       Integer index = (Integer)elemIndex.get(qName);
170       if(index == null)
171       {
172          value = valueList.getNonRequiredValue(qName);
173       }
174       else
175       {
176          value = valueList.getRequiredValue(index.intValue());
177       }
178       return value;
179 */

180       throw new UnsupportedOperationException JavaDoc();
181    }
182
183    public List JavaDoc getRequiredBindings()
184    {
185 // return requiredBindings;
186
throw new UnsupportedOperationException JavaDoc();
187    }
188
189    // Private
190

191    private void addBinding(Object JavaDoc binding)
192    {
193       if(requiredBindings == Collections.EMPTY_LIST)
194       {
195          requiredBindings = new ArrayList JavaDoc();
196       }
197       requiredBindings.add(binding);
198    }
199 }
200
Popular Tags