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