View Javadoc
1   /**
2    * Redistribution and use of this software and associated documentation
3    * ("Software"), with or without modification, are permitted provided
4    * that the following conditions are met:
5    *
6    * 1. Redistributions of source code must retain copyright
7    *    statements and notices.  Redistributions must also contain a
8    *    copy of this document.
9    *
10   * 2. Redistributions in binary form must reproduce the
11   *    above copyright notice, this list of conditions and the
12   *    following disclaimer in the documentation and/or other
13   *    materials provided with the distribution.
14   *
15   * 3. The name "Exolab" must not be used to endorse or promote
16   *    products derived from this Software without prior written
17   *    permission of Intalio, Inc.  For written permission,
18   *    please contact info@exolab.org.
19   *
20   * 4. Products derived from this Software may not be called "Exolab"
21   *    nor may "Exolab" appear in their names without prior written
22   *    permission of Intalio, Inc. Exolab is a registered
23   *    trademark of Intalio, Inc.
24   *
25   * 5. Due credit should be given to the Exolab Project
26   *    (http://www.exolab.org/).
27   *
28   * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS
29   * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
32   * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39   * OF THE POSSIBILITY OF SUCH DAMAGE.
40   *
41   * Copyright 1999-2003 (C) Intalio Inc. All Rights Reserved.
42   *
43   * $Id$
44   */
45  
46  package org.exolab.castor.xml.schema;
47  
48  import java.util.Enumeration;
49  import java.util.Iterator;
50  import java.util.Vector;
51  
52  import org.exolab.castor.xml.ValidationException;
53  import org.exolab.castor.xml.validators.ValidationUtils;
54  
55  /**
56   * An XML Schema ElementDecl
57   * @author <a href="mailto:kvisco@intalio.com">Keith Visco</a>
58   * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
59  **/
60  public class ElementDecl extends Particle implements Referable {
61      /** SerialVersionUID */
62      private static final long serialVersionUID = -7804351635137964219L;
63  
64     //-------------------/
65     //- Class Variables -/
66     //-------------------/
67  
68      /**
69       * Error message for a null argument
70      **/
71      private static String NULL_ARGUMENT
72          = "A null argument was passed to the constructor of " +
73             ElementDecl.class.getName();
74  
75  
76      //--------------------/
77      //- Member Variables -/
78      //--------------------/
79  
80      /**
81       * The block attribute for this element definition.
82      **/
83      private BlockList _block = null;
84  
85      /**
86       * collection of Identity Constraints
87      **/
88      private Vector _constraints = null;
89  
90      /**
91       * The default value for this element definition. Only
92       * useful for simpleContent.
93      **/
94      private String _default = null;
95  
96      /**
97       * The name of a reference to a top-level element declaration
98      **/
99      private String _elementRefName = null;
100 
101     /**
102      * The top-level element declaration this element reference points to
103     **/
104     private ElementDecl _referencedElement = null;
105 
106     /**
107      * The final value for this element definition.
108     **/
109     private FinalList _final = null;
110 
111     /**
112      * The fixed value for this element definition. Only
113      * used for simpleContent.
114     **/
115 	private String _fixed = null;
116 
117     /**
118      * The form type for this element definition.
119      * Specifies whether names should be qualified or unqualified.
120      * Uses the default Form from the parent Schema if unspecified.
121     **/
122     private Form _form = null;
123 
124     /**
125      * The unique ID for this element definition (optional).
126     **/
127     private String _id = null;
128 
129     /**
130      * Flag indicating whether or not this Element declaration is
131      * abstract
132     **/
133     private boolean _isAbstract = false;
134 
135     /**
136      * The element name
137     **/
138     private String _name = null;
139 
140     /**
141      * Flag indicating whether or not the element value may be null.
142     **/
143     private boolean _nillable = false;
144 
145     /**
146      * The parent for this ElementDecl
147     **/
148     private Structure _parent = null;
149 
150     /**
151      * The parent schema that this element declaration belongs to
152     **/
153     private Schema _schema = null;
154 
155     /**
156      * The substitutionGroup for this element definition.
157     **/
158     private String _substitutionGroup = null;
159 
160     /**
161      * The XMLType for this element declaration
162     **/
163     private XMLType _xmlType = null;
164 
165     /**
166      * Creates a new default element definition
167      * @param schema the XML Schema to which this element declaration
168      * belongs
169      * <BR />This element definition will not be valid until a name has
170      * been set
171     **/
172     public ElementDecl(Schema schema) {
173         this(schema, null);
174     } //-- ElementDecl
175 
176     /**
177      * Creates a new default element definition
178      * @param schema the XML Schema to which this Element Declaration
179      * belongs
180      * @param name the name of the Element being declared
181     **/
182     public ElementDecl(Schema schema, String name) {
183         super();
184         setName(name);
185         if (schema == null) {
186             String err = NULL_ARGUMENT + "; 'schema' must not be null.";
187             throw new IllegalArgumentException(err);
188         }
189         setSchema(schema);
190         _constraints = new Vector(3);
191     } //-- ElementDecl
192 
193     /**
194      * Adds the given IdentityConstraint to this element definition.
195      *
196      * @param constraint the IdentityConstraint to add.
197     **/
198     public void addIdentityConstraint(IdentityConstraint constraint) {
199         if (constraint == null) return;
200         _constraints.addElement(constraint);
201     } //-- addIdentityConstraint
202 
203 	/**
204 	 * Returns the value of the 'block' attribute for this element
205 	 *
206 	 * @return the value of the block attribute.
207 	**/
208 	public BlockList getBlock() {
209 		return _block;
210 	} //-- getBlock
211 
212     /**
213      * Returns the default value of this element definition.
214      *
215      * @return the default value of this element definition,
216      * or null if no default was specified.
217     **/
218     public String getDefaultValue() {
219         if (isReference()) {
220         	ElementDecl elem = getReference();
221             if (elem != null)
222                 return elem.getDefaultValue();
223         }
224         return _default;
225     } //-- getDefaultValue
226 
227 	/**
228 	 * Returns the value of the 'final' attribute for this element
229 	 * definition.
230 	 *
231 	 * @return the FinalList for this element definition.
232 	**/
233 	public FinalList getFinal() {
234 		return _final;
235 	} //-- getFinal
236 
237     /**
238      * Returns the fixed value of this element definition.
239      *
240      * @return the fixed value of this element definition,
241      * or null if no default was specified.
242      */
243     public String getFixedValue() {
244         if (isReference()) {
245             ElementDecl elem = getReference();
246             if (elem != null)
247                 return elem.getFixedValue();
248         }
249         return _fixed;
250     } //-- getFixedValue
251 
252     /**
253      * Returns the Form for this element definition. The Form object species
254      * whether or not names are qualified or unqualified in the scope of
255      * this element definition. If null, the Form should be obtained from the
256      * parent Schema.
257      *
258      * @return the Form for this element definition, or null if not set.
259     **/
260     public Form getForm() {
261         return _form;
262     } //-- getForm
263 
264     /**
265      * Returns the 'id' for this element definition.
266      *
267      * @return the 'id' for this element definition.
268     **/
269     public String getId() {
270         return _id;
271     } //-- getId
272 
273     /**
274      * Returns an Enumeration of IdentityConstraint objects contained within
275      * this element definition.
276      *
277      * @return an Enumeration of IdentityConstraint objects contained within
278      * this element definition.
279     **/
280     public Enumeration getIdentityConstraints() {
281         return _constraints.elements();
282     } //-- getIdentityConstraints
283 
284     /**
285      * Returns the name of this Element declaration. The name of the
286      * referenced element is returned if the 'ref' attribute was used.
287      * The name returned will be an NCName (no namespace prefix will
288      * be included with the name).
289      *
290      * @return the name of this element declaration
291      */
292     public String getName() {
293 		return getName(false);
294 	} //-- getName
295 
296     /**
297      * Returns the name of this Element declaration. The name
298      * returned, if not null, will be an NCName.
299      *
300      * @param ignoreRef if false the name of the referenced
301      * element (if specified) is returned, otherwise the
302      * localname (may be null).
303      *
304      * @return the name of this element declaration
305     **/
306     public String getName(boolean ignoreRef) {
307         if (isReference() && ignoreRef == false) {
308             String localName = _elementRefName;
309             //-- check for namespace prefix
310             int idx = localName.indexOf(':');
311             if (idx > 0) {
312                 localName = localName.substring(idx+1);
313             }
314             return localName;
315         }
316 		return _name;
317     } //-- getName
318 
319     /**
320      * Returns the parent of this ElementDecl, this value may be null if
321      * no parent has been set.
322      *
323      * @return the parent Structure of this ElementDecl
324     **/
325     public Structure getParent() {
326         return _parent;
327     } //-- getParent
328     /**
329      * Returns the XMLType (ComplexType or SimpleType) of this ElementDecl.
330      * @return the XMLType of this ElementDecl
331     **/
332     public XMLType getType() {
333         
334     	XMLType result = null;
335         
336         if (isReference()) {
337             ElementDecl element = getReference();
338             if (element != null) {
339             	return element.getType();
340             }
341             return null;
342         }
343 
344         
345         
346         if (_xmlType == null) return null;
347         //1--Anonymous types
348         if (_xmlType.getName() == null) return _xmlType.getType();
349         //--we look in the parent schema if we have redefinitions of types.
350         result = _xmlType.getType();
351         
352         //-- the current XML schema might have a MasterSchema where all the
353         //-- type definitions have a higher priority [this is useful when
354         //-- resolving redefined types for instance].
355         if (result != null) {
356         	Schema tempSchema = result.getSchema().getMasterSchema();
357         	if (tempSchema != null) {
358         		XMLType tempType = tempSchema.getType(result.getName());
359         		if (tempType != null) {
360         			result = tempType;
361         		}
362         	}
363         }
364         return result;
365     } //-- getXMLType
366 
367     /**
368      * Returns the ElementDecl that this element definition references.
369      * This will return null if this element definition does not reference
370      * a different element definition.
371      * @return the ElementDecl that this element definition references
372     **/
373     public ElementDecl getReference() {
374         if (_referencedElement != null) {
375             return _referencedElement;
376         }
377         
378         ElementDecl result = null;
379         if (_elementRefName != null) {
380             result = _schema.getElementDecl(_elementRefName);
381             if (result == null) {
382                 String err = "Unable to find element referenced :\" ";
383                 err += getName();
384                 err += "\"";
385                 throw new IllegalStateException(err);
386             }
387             _referencedElement = result;
388         }
389         return result;
390     } //-- getReference
391 
392     /**
393      * Returns the actual reference name of this AttributeDecl, or null
394      * if this AttributeDecl is not a reference. The name returned, if not
395      * null, will be a QName, possibly containing the namespace prefix.
396      * 
397      * @return the reference name
398      */
399     public String getReferenceName() {
400         return _elementRefName;
401     } //-- getReference
402     
403     /**
404      * Returns the Id used to Refer to this Object
405      *
406      * @return the Id used to Refer to this Object
407      * @see Referable
408     **/
409     public String getReferenceId() {
410         if (_name != null) return "element:"+_name;
411         return null;
412     } //-- getReferenceId
413 
414     /**
415      * Returns the XML Schema to which this element declaration belongs.
416      * @return the XML Schema to which this element declaration belongs.
417     **/
418     public Schema getSchema() {
419         return _schema;
420     } //-- getSchema
421 
422     /**
423      * Returns the substitutionGroup for this element declaration, or
424      * null if it's absent; if this {@link ElementDecl} instance is a reference
425      * to a global element definition, return its substitution group
426      *
427      * @return the substitutionGroup membership for this element
428      * declaration, or null if absent.
429     **/
430     public String getSubstitutionGroup() {
431         if (isReference()) {
432             return getReference().getSubstitutionGroup();
433         }
434        return _substitutionGroup;
435     } //-- getSubstitutionGroup
436     
437     /**
438      * Returns an enumeration of the elements that can be substitute to 
439      * this element declaration. 
440      * @return an enumeration of the elements that can be substitute to 
441      * this element declaration.
442      */
443     public Enumeration getSubstitutionGroupMembers() {
444     	Vector result = new Vector();
445     	Iterator<ElementDecl> enumeration = _schema.getElementDecls().iterator();
446     	while (enumeration.hasNext()) {
447     		ElementDecl temp  = (ElementDecl)enumeration.next();
448     		String subName = temp.getSubstitutionGroup();
449     		if (subName != null) {
450                 // no namespace(s) or default namespace in use
451                 if (subName.equals(_name)) { 
452                     result.add(temp);
453                 }
454                 // namespace(s) incl. prefix in use
455                 // TODO: find a better way of dealing with a namespace prefix
456                 else if (subName.endsWith(_name) && subName.indexOf(":") > 0) {
457                     result.add(temp);
458                 }
459             }
460     	}
461     	return result.elements();
462     }
463     
464     /**
465      * Returns true if this element definition is abstract
466      * @return true if this element definition is abstract
467     **/
468     public boolean isAbstract() {
469         if (isReference()) {
470             return _referencedElement.isAbstract();
471         }
472         return _isAbstract;
473     } //-- isAbstract
474 
475     /**
476      * Returns whether or not instances of this element definition
477      * may appear with no content.
478      *
479      * @return true if instances of this element definition
480      * may appear with no content, otherwise false.
481     **/
482     public boolean isNillable() {
483         if (isReference()) {
484             return _referencedElement.isNillable();
485         }
486         return _nillable;
487     } //-- isNullable
488 
489     /**
490      * Returns true if this element definition simply references another
491      * element Definition
492      * @return true if this element definition is a reference
493     **/
494     public boolean isReference() {
495         return (_elementRefName != null);
496     } //-- isReference
497 
498     /**
499      * Sets whether or not this element definition is abstract
500      * @param isAbstract a boolean when true indicates that this
501      * element definition should be abstract
502     **/
503     public void setAbstract(boolean isAbstract) {
504         _isAbstract = isAbstract;
505     } //-- isAbstract
506 
507     /**
508      * Returns true if this element has children (i.e if it
509      * holds attributes or elements).
510      * @return true if this element has children (i.e if it
511      * holds attributes or elements).
512      */
513     public boolean hasChildren() {
514         XMLType type = getType();
515         if (type instanceof SimpleType)
516            return false;
517 
518         if (type instanceof ComplexType) {
519             //complexContent ->sure to have children
520             if (((ComplexType)type).isComplexContent())
521                  return true;
522             //else check for contentModel group
523             else if ( ((ComplexType)type).getParticleCount() != 0 )
524                return true;
525             //else check for attributes
526             else {
527                 java.util.Enumeration temp = ((ComplexType)type).getAttributeDecls();
528                 return temp.hasMoreElements();
529             }
530         }
531 
532         return false;
533     } //-- hasChildren
534 
535     /**
536      * Removes the given IdentityConstraint from this element definition.
537      *
538      * @param constraint the IdentityConstraint to remove.
539      * @return true if the IdentityConstraint was contained within this
540      * element defintion.
541     **/
542     public boolean removeIdentityConstraint(IdentityConstraint constraint)
543     {
544         if (constraint ==  null) return false;
545         return _constraints.removeElement(constraint);
546     } //-- removeIdentityConstraint
547 
548 
549 	/**
550 	 * Sets the value of the 'block' attribute for this element
551 	 *
552 	 * @param block the value of the block attribute for this
553 	 * element definition.
554 	**/
555 	public void setBlock(BlockList block) {
556 	    _block = block;
557 	} //-- setBlock
558 
559 	/**
560 	 * Sets the value of the 'block' attribute for this element
561 	 *
562 	 * @param block the value of the block attribute for this
563 	 * element definition.
564 	**/
565 	public void setBlock(String block) {
566 	    if (block == null)
567 	        _block = null;
568 	    else
569 	        _block = new BlockList(block);
570 	} //-- setBlock
571 
572     /**
573      * Sets the default value for this element definition.
574      *
575      * @param value the default value for this element definition.
576     **/
577     public void setDefaultValue(String value) {
578         this._default = value;
579     } //-- setDefaultValue
580 
581 	/**
582 	 * Sets the value of the 'final' attribute for this element
583 	 * definition.
584 	 *
585 	 * @param finalList the value of the final attribute for this
586 	 * element definition.
587 	**/
588 	public void setFinal(FinalList finalList) {
589 	        _final = finalList;
590 	} //-- setFinal
591 
592 	/**
593 	 * Sets the value of the 'final' attribute for this element
594 	 * definition.
595 	 *
596 	 * @param finalValue the value of the final attribute for this
597 	 * element definition.
598 	**/
599 	public void setFinal(String finalValue) {
600 	    if (finalValue == null)
601 	        _final = null;
602 	    else
603 	        _final = new FinalList(finalValue);
604 	} //-- setFinal
605 
606     /**
607      * Sets the fixed value for this element definition.
608      *
609      * @param value the fixed value for this element definition.
610     **/
611     public void setFixedValue(String value) {
612         this._fixed = value;
613     } //-- setDefaultValue
614 
615     /**
616      * Sets the Form for this element definition. The Form object species
617      * whether or not names are qualified or unqualified in the scope of
618      * this element definition. If null, the Form is to be obtained from the
619      * parent Schema.
620      *
621      * @param form the Form type for this element definition.
622     **/
623     public void setForm(Form form) {
624         _form = form;
625     } //-- setForm
626 
627     /**
628      * Sets the Id for this element definition.
629      *
630      * @param id the Id for this element definition.
631     **/
632     public void setId(String id) {
633         _id = id;
634     } //-- setId
635 
636     /**
637      * Sets the name of the element that this Element definition defines.
638      *
639      * @param name the name of the defined element
640     **/
641     public void setName(String name) {
642 
643         if ((name == null) || (ValidationUtils.isNCName(name))) {
644             _name = name;
645         }
646         else {
647             String err = "error: '" + name + "' is not a valid NCName.";
648             throw new IllegalArgumentException(err);
649         }
650     } //-- setName
651 
652     /**
653      * Sets whether or not instances of this element definition may
654      * contain empty content
655      *
656      * @param nillable the flag when true indicates that instances
657      * of this element definition may appear with empty content
658     **/
659     public void setNillable(boolean nillable) {
660         _nillable = nillable;
661     } //-- setNillable
662 
663     /**
664      * Sets the parent for this ElementDecl.
665      *
666      * @param parent the parent Structure for this ElementDecl
667     **/
668     protected void setParent(Structure parent) {
669         if (parent != null) {
670             switch (parent.getStructureType()) {
671                 case Structure.GROUP:
672                 case Structure.MODELGROUP:
673                 case Structure.SCHEMA:
674                     break;
675                 default:
676                     String error = "Invalid parent for element.";
677                     throw new IllegalArgumentException(error);
678             }
679         }
680         _parent = parent;
681     } //-- setParent
682     /**
683      * Sets the reference for this element definition
684      * @param reference the Element definition that this definition references
685     **/
686     public void setReference(ElementDecl reference) {
687         if (reference == null) {
688             _elementRefName = null;
689             _referencedElement = null;
690         }
691         else {
692             if (reference.getSchema() == this.getSchema()) {
693                 _elementRefName = reference.getName();
694                 _referencedElement = reference;
695             }
696             else {
697                 String qName = reference.getName();
698                 String nsURI = reference.getSchema().getTargetNamespace();
699                 if (nsURI != null) {
700                     String prefix = getSchema().getNamespacePrefix(nsURI);
701                     if ((prefix != null) && (prefix.length() > 0))
702                         qName = prefix + ":" + qName;
703                 }
704                 _elementRefName = qName;
705                 _referencedElement = reference;
706             }
707         }
708     } //-- setReference
709 
710     /**
711      * Sets the name which this element declaration refers to
712      * @param referenceName the name of the element definition that this
713      * definition references
714     **/
715     public void setReferenceName(String referenceName) {
716         if ((referenceName == null) || (ValidationUtils.isQName(referenceName))) {
717             _elementRefName = referenceName;
718         }
719         else {
720             String err = "error: '" + referenceName + "' is not a valid QName.";
721             throw new IllegalArgumentException(err);
722         }
723     } //-- setReference
724 
725     /**
726      * Sets the substitutionGroup for this element definition.
727      *
728      * @param substitutionGroup the substitutionGroup for this
729      * element definition.
730     **/
731     public void setSubstitutionGroup(String substitutionGroup) {
732         _substitutionGroup = substitutionGroup;
733     } //-- setSubstitutionGroup
734 
735     /**
736      * Sets the XMLType for this Element declaration.
737      * @param type the XMLType for this element declaration.
738      * <BR />
739      * <B>Note:</B> This method is mutually exclusive with
740      * #setTypeReference, if a reference has previously been
741      * set it will be ignored.
742     **/
743     public void setType(XMLType type)
744     {
745         //-- reset parent of current type
746         if (_xmlType != null) {
747             _xmlType.setParent(null);
748         }
749         if (type != null) {
750             type.setParent(this);
751         }
752 
753         _xmlType = type;
754     } //-- setType
755 
756 
757     /**
758      * Sets the type of this element to be a reference.
759      */
760     public void setTypeReference(String name)
761     {
762         TypeReference reference= new TypeReference();
763         reference.setName(name);
764         reference.setSchema(_schema);
765         setType(reference);
766     }
767 
768     //-------------------------------/
769     //- Implementation of Structure -/
770     //-------------------------------/
771 
772     /**
773      * Returns the type of this Schema Structure
774      * @return the type of this Schema Structure
775     **/
776     public short getStructureType() {
777         return Structure.ELEMENT;
778     } //-- getStructureType
779 
780     /**
781      * Checks the validity of this element definition.
782      *
783      * @throws ValidationException when this element definition
784      * is invalid.
785     **/
786     public void validate() throws ValidationException {
787 
788         //-- If this element merely references another element definition
789         //-- just check that we can resolve the reference
790         if (_elementRefName != null) {
791             if (_schema.getElementDecl(_elementRefName) == null) {
792                 String err = "<element ref=\"" + _elementRefName + "\"> "+
793                     "is not resolvable.";
794                 throw new ValidationException(err);
795             }
796             return;
797         }
798 
799         if (_name == null)  {
800             String err = "<element> is missing required 'name' or " +
801                 "'ref' attribute.";
802             throw new ValidationException(err);
803         }
804 
805         //--check that the particle information is not present on top level 
806         //--element
807         
808         //--do you really allow parent to be null???
809         if (getParent() != null) {
810             if (getParent().getStructureType() == Structure.SCHEMA) {
811                 if (isMinOccursSet()) {
812                     String err = "'minOccurs' declaration is prohibited on top level element '/" + getName() + "'.";
813                     throw new ValidationException(err);
814                 }
815                 if (isMaxOccursSet()) {
816                     String err = "'maxOccurs' declaration is prohibited on top level element '/" + getName() + "'.";
817                     throw new ValidationException(err);
818                 }
819             }
820         }
821         
822         //-- If type is anonymous, make sure the type is valid.
823         //-- To prevent excess validation, we ONLY validate
824         //-- if the type is anonymous, because otherwise
825         //-- the Schema itself will validate the type.
826         XMLType type = getType();
827         if (type != null) {
828             if (type.isComplexType()) {
829                 ComplexType complexType = (ComplexType)type;
830                 if (!complexType.isTopLevel()) {
831                     complexType.validate();
832                 }
833             }
834             else if (type.isSimpleType()) {
835                 SimpleType simpleType = (SimpleType)type;
836                 if (simpleType.getParent() != simpleType.getSchema()) {
837                     simpleType.validate();
838                 }
839                 //-- print warning message if ID, IDREF, IDREFS, NMTOKEN, NTOKENS are
840                 //-- used as element type
841                 int typeCode =  simpleType.getTypeCode();
842                 switch (typeCode) {
843                     case SimpleTypesFactory.ID_TYPE:
844                     case SimpleTypesFactory.IDREF_TYPE:
845                     case SimpleTypesFactory.IDREFS_TYPE:
846                     case SimpleTypesFactory.NMTOKENS_TYPE:
847                     case SimpleTypesFactory.NMTOKEN_TYPE:
848                         String err = "Warning : For XML Compatibility " +
849                                 simpleType.getName()+" should be used only as attributes\n.";
850                         //--Future versions will log the message
851                         System.out.println(err);
852                         break;
853                     default:
854                         break;
855 
856                 }
857             }
858             //-- anyType
859             else {
860                 //-- nothing to validate anyType is always valid.
861             }
862             
863         }
864 
865     } //-- validate
866     
867     /**
868      * Sets the XMl schema to where this element has been defined
869      * @param schema The defining XML schema
870      */
871     private void setSchema(final Schema schema) {
872         _schema = schema;
873     }
874 
875     /**
876      * Indicates whether a type is set for this element definiion. 
877      * @return True if a type is set.
878      */
879     public boolean hasXMLType() {
880         return (_xmlType != null);
881     }
882     
883    
884 } //-- Element