1 package org.exolab.castor.xml.descriptors;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
8 import org.exolab.castor.xml.UnmarshalState;
9 import org.exolab.castor.xml.ValidationException;
10 import org.exolab.castor.xml.XMLClassDescriptor;
11 import org.exolab.castor.xml.XMLFieldDescriptor;
12
13 public abstract class BaseDescriptor implements XMLClassDescriptor {
14
15 /**
16 * Map holding the properties set and read by Natures.
17 */
18 private Map _properties = new HashMap();
19
20 /**
21 * Map holding the available natures.
22 */
23 private Set _natures = new HashSet();
24
25 /**
26 * Returns true if the given object represented by this XMLClassDescriptor
27 * can accept a member whose name is given. An XMLClassDescriptor can accept
28 * a field if it contains a descriptor that matches the given name and if
29 * the given object can hold this field (i.e a value is not already set for
30 * this field).
31 * <p>
32 * This is mainly used for container object (that can contain other
33 * objects), in this particular case the implementation returns false.
34 *
35 * @param name the name of the field to check
36 * @param namespace the namespace of the element. This may be null. Note: A
37 * null namespace is not the same as the default namespace unless the
38 * default namespace is also null.
39 * @param object the object represented by this XMLCLassDescriptor
40 * @return true if the given object represented by this XMLClassDescriptor
41 * can accept a member whose name is given.
42 */
43 public boolean canAccept(String name, String namespace, Object object) {
44 return false;
45 }
46
47 /**
48 * {@inheritDoc}
49 *
50 * @see org.exolab.castor.xml.XMLClassDescriptor#
51 * checkDescriptorForCorrectOrderWithinSequence(org.exolab.castor.xml.XMLFieldDescriptor,
52 * org.exolab.castor.xml.UnmarshalState, java.lang.String)
53 */
54 public void checkDescriptorForCorrectOrderWithinSequence(
55 XMLFieldDescriptor elementDescriptor, UnmarshalState parentState,
56 String xmlName) throws ValidationException {
57 // no implementation
58 }
59
60 /**
61 * {@inheritDoc}
62 *
63 * @see org.exolab.castor.xml.XMLClassDescriptor#isChoice()
64 */
65 public boolean isChoice() {
66 return false;
67 }
68
69 /**
70 * @see org.exolab.castor.builder.info.nature.PropertyHolder#
71 * getProperty(java.lang.String)
72 * @param name
73 * of the property
74 * @return value of the property
75 */
76 public Object getProperty(final String name) {
77 return _properties.get(name);
78 }
79
80 /**
81 * @see org.exolab.castor.builder.info.nature.PropertyHolder#
82 * setProperty(java.lang.String, java.lang.Object)
83 * @param name
84 * of the property
85 * @param value
86 * of the property
87 */
88 public void setProperty(final String name, final Object value) {
89 _properties.put(name, value);
90 }
91
92 /**
93 * @see org.exolab.castor.builder.info.nature.NatureExtendable#
94 * addNature(java.lang.String)
95 * @param nature
96 * ID of the Nature
97 */
98 public void addNature(final String nature) {
99 _natures.add(nature);
100 }
101
102 /**
103 * @see org.exolab.castor.builder.info.nature.NatureExtendable#
104 * hasNature(java.lang.String)
105 * @param nature
106 * ID of the Nature
107 * @return true if the Nature ID was added.
108 */
109 public boolean hasNature(final String nature) {
110 return _natures.contains(nature);
111 }
112
113
114 }