001: /*
002: * $Id: DataSectionElementSpec.java,v 1.16 2007/09/18 11:20:47 agoubard Exp $
003: *
004: * Copyright 2003-2007 Orange Nederland Breedband B.V.
005: * See the COPYRIGHT file for redistribution and use restrictions.
006: */
007: package org.xins.common.spec;
008:
009: import java.util.List;
010: import java.util.Map;
011:
012: import org.xins.common.MandatoryArgumentChecker;
013:
014: /**
015: * Specification of a data section element.
016: *
017: * @version $Revision: 1.16 $ $Date: 2007/09/18 11:20:47 $
018: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
019: *
020: * @since XINS 1.3.0
021: */
022: public final class DataSectionElementSpec {
023:
024: /**
025: * Name of the element, cannot be <code>null</code>.
026: */
027: private final String _name;
028:
029: /**
030: * Description of the element, cannot be <code>null</code>.
031: */
032: private final String _description;
033:
034: /**
035: * Flag indicating that the element can have PCDATA.
036: */
037: private final boolean _isPCDataAllowed;
038:
039: /**
040: * The sub elements of the element, cannot be <code>null</code>.
041: */
042: private final Map _subElements;
043:
044: /**
045: * The attributes of the element, cannot be <code>null</code>.
046: */
047: private final Map _attributes;
048:
049: /**
050: * The attribute combos of the element, cannot be <code>null</code>.
051: */
052: private final List _attributeCombos;
053:
054: /**
055: * Creates a new instance of <code>DataSectionElementSpec</code>.
056: *
057: * @param name
058: * the name of the data section element, cannot be <code>null</code>.
059: *
060: * @param description
061: * the description of the data section element, cannot be <code>null</code>.
062: *
063: * @param isPCDataAllowed
064: * <code>true</code> if the element can contain text, <code>false</code> otherwise.
065: *
066: * @param subElements
067: * the sub elements that can contain this element, cannot be <code>null</code>.
068: *
069: * @param attributes
070: * the possible attributes for this element, cannot be <code>null</code>.
071: *
072: * @param attributeCombos
073: * the attribute combos for this element, cannot be <code>null</code>.
074: */
075: DataSectionElementSpec(String name, String description,
076: boolean isPCDataAllowed, Map subElements, Map attributes,
077: List attributeCombos) {
078: _name = name;
079: _description = description;
080: _isPCDataAllowed = isPCDataAllowed;
081: _attributes = attributes;
082: _subElements = subElements;
083: _attributeCombos = attributeCombos;
084: }
085:
086: /**
087: * Gets the name of the data element.
088: *
089: * @return
090: * The name of the data element, never <code>null</code>.
091: */
092: public String getName() {
093:
094: return _name;
095: }
096:
097: /**
098: * Gets the description of the data element.
099: *
100: * @return
101: * The description of the data element, never <code>null</code>.
102: */
103: public String getDescription() {
104:
105: return _description;
106: }
107:
108: /**
109: * Gets the specified sub element that are included in this element.
110: *
111: * @param elementName
112: * the name of the element, cannot be <code>null</code>.
113: *
114: * @return
115: * The specification of the sub element, never <code>null</code>.
116: *
117: * @throws IllegalArgumentException
118: * if <code>elementName == null</code>.
119: *
120: * @throws EntityNotFoundException
121: * if the element does not have any sub element with the specified name.
122: */
123: public DataSectionElementSpec getSubElement(String elementName)
124: throws IllegalArgumentException, EntityNotFoundException {
125:
126: MandatoryArgumentChecker.check("elementName", elementName);
127:
128: DataSectionElementSpec element = (DataSectionElementSpec) _subElements
129: .get(elementName);
130:
131: if (element == null) {
132: throw new EntityNotFoundException("Sub element \""
133: + elementName + "\" not found in the element \""
134: + _name + "\".");
135: }
136:
137: return element;
138: }
139:
140: /**
141: * Gets the specification of the sub elements that are included in this element.
142: * The key is the name of the element, the value is the {@link DataSectionElementSpec} object.
143: *
144: * @return
145: * the specification of the sub elements, never <code>null</code>.
146: */
147: public Map getSubElements() {
148:
149: return _subElements;
150: }
151:
152: /**
153: * Gets the specification of the specified attribute of the element.
154: *
155: * @param attributeName
156: * the name of the attribute, cannot be <code>null</code>.
157: *
158: * @return
159: * The specification of the attribute, never <code>null</code>.
160: *
161: * @throws EntityNotFoundException
162: * if the element does not have any attribute with the specified name.
163: *
164: * @throws IllegalArgumentException
165: * if <code>attributeName == null</code>.
166: */
167: public ParameterSpec getAttribute(String attributeName)
168: throws EntityNotFoundException, IllegalArgumentException {
169:
170: MandatoryArgumentChecker.check("attributeName", attributeName);
171:
172: ParameterSpec attribute = (ParameterSpec) _attributes
173: .get(attributeName);
174:
175: if (attribute == null) {
176: throw new EntityNotFoundException("Attribute \""
177: + attributeName + "\" not found in the element \""
178: + _name + "\".");
179: }
180:
181: return attribute;
182: }
183:
184: /**
185: * Gets the attributes of the element.
186: * The key is the name of the attribute, the value is the {@link ParameterSpec} object.
187: *
188: * @return
189: * The specification of the attributes, never <code>null</code>.
190: */
191: public Map getAttributes() {
192:
193: return _attributes;
194: }
195:
196: /**
197: * Returns whether the element can contain a PCDATA text.
198: *
199: * @return
200: * <code>true</code> if the element can contain text, <code>false</code> otherwise.
201: */
202: public boolean isPCDataAllowed() {
203:
204: return _isPCDataAllowed;
205: }
206:
207: /**
208: * Gets the attribute combos defined for the element.
209: * A list of {@link AttributeComboSpec} object.
210: *
211: * @return
212: * the list of the attribute combos define for the element, never <code>null</code>.
213: *
214: * @since XINS 1.4.0
215: */
216: public List getAttributeCombos() {
217:
218: return _attributeCombos;
219: }
220: }
|