View Javadoc
1   /*
2    * reserved comment block
3    * DO NOT REMOVE OR ALTER!
4    */
5   /*
6    * Copyright 2001-2004 The Apache Software Foundation.
7    *
8    * Licensed under the Apache License, Version 2.0 (the "License");
9    * you may not use this file except in compliance with the License.
10   * You may obtain a copy of the License at
11   *
12   *      http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package com.sun.org.apache.xerces.internal.impl.xs.traversers;
22  
23  import com.sun.org.apache.xerces.internal.impl.xs.SchemaGrammar;
24  import com.sun.org.apache.xerces.internal.impl.xs.SchemaSymbols;
25  import com.sun.org.apache.xerces.internal.impl.xs.XSAnnotationImpl;
26  import com.sun.org.apache.xerces.internal.impl.xs.XSNotationDecl;
27  import com.sun.org.apache.xerces.internal.impl.xs.util.XSObjectListImpl;
28  import com.sun.org.apache.xerces.internal.util.DOMUtil;
29  import com.sun.org.apache.xerces.internal.xs.XSObjectList;
30  import org.w3c.dom.Element;
31  
32  /**
33   * The notation declaration schema component traverser.
34   *
35   * <notation
36   *   id = ID
37   *   name = NCName
38   *   public = anyURI
39   *   system = anyURI
40   *   {any attributes with non-schema namespace . . .}>
41   *   Content: (annotation?)
42   * </notation>
43   *
44   * @xerces.internal
45   *
46   * @author Rahul Srivastava, Sun Microsystems Inc.
47   * @author Elena Litani, IBM
48   * @version $Id: XSDNotationTraverser.java,v 1.7 2010-11-01 04:40:02 joehw Exp $
49   */
50  class  XSDNotationTraverser extends XSDAbstractTraverser {
51  
52      XSDNotationTraverser (XSDHandler handler,
53              XSAttributeChecker gAttrCheck) {
54          super(handler, gAttrCheck);
55      }
56  
57      XSNotationDecl traverse(Element elmNode,
58              XSDocumentInfo schemaDoc,
59              SchemaGrammar grammar) {
60  
61          // General Attribute Checking for elmNode
62          Object[] attrValues = fAttrChecker.checkAttributes(elmNode, true, schemaDoc);
63          //get attributes
64          String  nameAttr   = (String) attrValues[XSAttributeChecker.ATTIDX_NAME];
65  
66          String  publicAttr = (String) attrValues[XSAttributeChecker.ATTIDX_PUBLIC];
67          String  systemAttr = (String) attrValues[XSAttributeChecker.ATTIDX_SYSTEM];
68          if (nameAttr == null) {
69              reportSchemaError("s4s-att-must-appear", new Object[]{SchemaSymbols.ELT_NOTATION, SchemaSymbols.ATT_NAME}, elmNode);
70              fAttrChecker.returnAttrArray(attrValues, schemaDoc);
71              return null;
72          }
73  
74          if (systemAttr == null && publicAttr == null) {
75              reportSchemaError("PublicSystemOnNotation", null, elmNode);
76              publicAttr = "missing";
77          }
78  
79          XSNotationDecl notation = new XSNotationDecl();
80          notation.fName = nameAttr;
81          notation.fTargetNamespace = schemaDoc.fTargetNamespace;
82          notation.fPublicId = publicAttr;
83          notation.fSystemId = systemAttr;
84  
85          //check content
86          Element content = DOMUtil.getFirstChildElement(elmNode);
87          XSAnnotationImpl annotation = null;
88  
89          if (content != null && DOMUtil.getLocalName(content).equals(SchemaSymbols.ELT_ANNOTATION)) {
90              annotation = traverseAnnotationDecl(content, attrValues, false, schemaDoc);
91              content = DOMUtil.getNextSiblingElement(content);
92          }
93          else {
94              String text = DOMUtil.getSyntheticAnnotation(elmNode);
95              if (text != null) {
96                  annotation = traverseSyntheticAnnotation(elmNode, text, attrValues, false, schemaDoc);
97              }
98          }
99          XSObjectList annotations;
100         if (annotation != null) {
101             annotations = new XSObjectListImpl();
102             ((XSObjectListImpl) annotations).addXSObject(annotation);
103         } else {
104             annotations = XSObjectListImpl.EMPTY_LIST;
105         }
106         notation.fAnnotations = annotations;
107         if (content!=null){
108             Object[] args = new Object [] {SchemaSymbols.ELT_NOTATION, "(annotation?)", DOMUtil.getLocalName(content)};
109             reportSchemaError("s4s-elt-must-match.1", args, content);
110 
111         }
112         if (grammar.getGlobalNotationDecl(notation.fName) == null) {
113             grammar.addGlobalNotationDecl(notation);
114         }
115 
116         // also add it to extended map
117         final String loc = fSchemaHandler.schemaDocument2SystemId(schemaDoc);
118         final XSNotationDecl notation2 = grammar.getGlobalNotationDecl(notation.fName, loc);
119         if (notation2 == null) {
120             grammar.addGlobalNotationDecl(notation, loc);
121         }
122 
123         // handle duplicates
124         if (fSchemaHandler.fTolerateDuplicates) {
125             if (notation2 != null) {
126                 notation = notation2;
127             }
128             fSchemaHandler.addGlobalNotationDecl(notation);
129         }
130         fAttrChecker.returnAttrArray(attrValues, schemaDoc);
131 
132         return notation;
133     }
134 }