KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.xml.namespace.QName JavaDoc;
25 import org.jboss.xb.binding.metadata.PropertyMetaData;
26 import org.jboss.xb.binding.metadata.ValueMetaData;
27 import org.jboss.xb.binding.JBossXBRuntimeException;
28 import org.jboss.xb.binding.sunday.marshalling.AttributeMarshaller;
29 import org.jboss.xb.binding.sunday.marshalling.DefaultAttributeMarshaller;
30
31 /**
32  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
33  * @version <tt>$Revision: 1958 $</tt>
34  */

35 public class AttributeBinding
36 {
37    private final SchemaBinding schema;
38    private final QName JavaDoc qName;
39    private final TypeBinding type;
40    private AttributeHandler handler;
41    private AttributeMarshaller marshaller = DefaultAttributeMarshaller.INSTANCE;
42    private PropertyMetaData propertyMetaData;
43    private ValueMetaData valueMetaData;
44    /** The default="value" constraint for the attribute */
45    private String JavaDoc defaultConstraint;
46    private boolean mapEntryKey;
47    private boolean mapEntryValue;
48    private ValueAdapter valueAdapter;
49    private boolean required;
50
51    public AttributeBinding(SchemaBinding schema, QName JavaDoc qName, TypeBinding type, AttributeHandler handler)
52    {
53       this.schema = schema;
54       this.qName = qName;
55       this.type = type;
56       this.handler = handler;
57
58       if(qName == null)
59       {
60          throw new JBossXBRuntimeException("Each attribute should have a non-null QName!");
61       }
62    }
63
64    public QName JavaDoc getQName()
65    {
66       return qName;
67    }
68
69    public TypeBinding getType()
70    {
71       return type;
72    }
73
74    public AttributeHandler getHandler()
75    {
76       return handler;
77    }
78
79    public void setHandler(AttributeHandler handler)
80    {
81       this.handler = handler;
82    }
83
84    public AttributeMarshaller getMarshaller()
85    {
86       return marshaller;
87    }
88
89    public void setMarshaller(AttributeMarshaller marshaller)
90    {
91       this.marshaller = marshaller;
92    }
93
94    public PropertyMetaData getPropertyMetaData()
95    {
96       return propertyMetaData;
97    }
98
99    public void setPropertyMetaData(PropertyMetaData propertyMetaData)
100    {
101       this.propertyMetaData = propertyMetaData;
102    }
103
104    public ValueMetaData getValueMetaData()
105    {
106       return valueMetaData != null ? valueMetaData : type.getValueMetaData();
107    }
108
109    public void setValueMetaData(ValueMetaData valueMetaData)
110    {
111       this.valueMetaData = valueMetaData;
112    }
113
114    public void setMapEntryKey(boolean mapEntryKey)
115    {
116       this.mapEntryKey = mapEntryKey;
117    }
118
119    public boolean isMapEntryKey()
120    {
121       return mapEntryKey;
122    }
123
124    public boolean isMapEntryValue()
125    {
126       return mapEntryValue;
127    }
128
129    public void setMapEntryValue(boolean mapEntryValue)
130    {
131       this.mapEntryValue = mapEntryValue;
132    }
133
134    public String JavaDoc getDefaultConstraint()
135    {
136       return defaultConstraint;
137    }
138
139    public void setDefaultConstraint(String JavaDoc value)
140    {
141       defaultConstraint = value;
142    }
143
144    public SchemaBinding getSchema()
145    {
146       return schema;
147    }
148
149    public ValueAdapter getValueAdapter()
150    {
151       return valueAdapter == null ? type.getValueAdapter() : valueAdapter;
152    }
153
154    public void setValueAdapter(ValueAdapter valueAdapter)
155    {
156       this.valueAdapter = valueAdapter;
157    }
158
159    public String JavaDoc toString()
160    {
161       return super.toString() + "[" + qName + "]";
162    }
163
164    public void setRequired(boolean required)
165    {
166       this.required = required;
167    }
168
169    public boolean getRequired()
170    {
171       return required;
172    }
173 }
174
Popular Tags