21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 /* |
25 /* |
26 * Copyright (C) 2004-2011 |
26 * Copyright (C) 2004-2012 |
27 * |
27 * |
28 * Permission is hereby granted, free of charge, to any person obtaining a copy |
28 * Permission is hereby granted, free of charge, to any person obtaining a copy |
29 * of this software and associated documentation files (the "Software"), to deal |
29 * of this software and associated documentation files (the "Software"), to deal |
30 * in the Software without restriction, including without limitation the rights |
30 * in the Software without restriction, including without limitation the rights |
31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
44 * THE SOFTWARE. |
44 * THE SOFTWARE. |
45 */ |
45 */ |
46 package com.sun.xml.internal.rngom.digested; |
46 package com.sun.xml.internal.rngom.digested; |
47 |
47 |
|
48 import java.util.ArrayList; |
|
49 import java.util.List; |
|
50 |
48 import com.sun.xml.internal.rngom.ast.builder.Annotations; |
51 import com.sun.xml.internal.rngom.ast.builder.Annotations; |
49 import com.sun.xml.internal.rngom.ast.builder.BuildException; |
52 import com.sun.xml.internal.rngom.ast.builder.BuildException; |
50 import com.sun.xml.internal.rngom.ast.builder.CommentList; |
53 import com.sun.xml.internal.rngom.ast.builder.CommentList; |
51 import com.sun.xml.internal.rngom.ast.builder.Div; |
54 import com.sun.xml.internal.rngom.ast.builder.Div; |
52 import com.sun.xml.internal.rngom.ast.builder.Grammar; |
55 import com.sun.xml.internal.rngom.ast.builder.Grammar; |
55 import com.sun.xml.internal.rngom.ast.om.Location; |
58 import com.sun.xml.internal.rngom.ast.om.Location; |
56 import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation; |
59 import com.sun.xml.internal.rngom.ast.om.ParsedElementAnnotation; |
57 import com.sun.xml.internal.rngom.ast.om.ParsedPattern; |
60 import com.sun.xml.internal.rngom.ast.om.ParsedPattern; |
58 import com.sun.xml.internal.rngom.ast.util.LocatorImpl; |
61 import com.sun.xml.internal.rngom.ast.util.LocatorImpl; |
59 import org.w3c.dom.Element; |
62 import org.w3c.dom.Element; |
60 |
|
61 import java.util.ArrayList; |
|
62 import java.util.List; |
|
63 |
63 |
64 /** |
64 /** |
65 * @author Kohsuke Kawaguchi (kk@kohsuke.org) |
65 * @author Kohsuke Kawaguchi (kk@kohsuke.org) |
66 */ |
66 */ |
67 class GrammarBuilderImpl implements Grammar, Div { |
67 class GrammarBuilderImpl implements Grammar, Div { |
83 this.parent = parent; |
83 this.parent = parent; |
84 this.sb = sb; |
84 this.sb = sb; |
85 } |
85 } |
86 |
86 |
87 public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException { |
87 public ParsedPattern endGrammar(Location loc, Annotations anno) throws BuildException { |
88 if(anno!=null) |
88 // Harshit : Fixed possible NPE and issue in handling of annotations |
89 grammar.annotation = ((Annotation)anno).getResult(); |
89 if (anno != null) { |
90 if(additionalElementAnnotations!=null) { |
90 if (grammar.annotation != null) { |
91 if(grammar.annotation==null) |
91 grammar.annotation.contents.addAll(((Annotation) anno).getResult().contents); |
92 grammar.annotation = new DAnnotation(); |
92 } |
93 grammar.annotation.contents.addAll(additionalElementAnnotations); |
|
94 } |
93 } |
95 return grammar; |
94 return grammar; |
96 } |
95 } |
97 |
96 |
98 public void endDiv(Location loc, Annotations anno) throws BuildException { |
97 public void endDiv(Location loc, Annotations anno) throws BuildException { |
99 } |
98 } |
100 |
99 |
101 public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException { |
100 public void define(String name, Combine combine, ParsedPattern pattern, Location loc, Annotations anno) throws BuildException { |
102 if(name==START) |
101 if(name==START) { |
103 grammar.start = (DPattern)pattern; |
102 grammar.start = (DPattern)pattern; |
104 else { |
103 } else { |
105 // TODO: handle combine |
104 // TODO: handle combine |
106 DDefine d = grammar.getOrAdd(name); |
105 DDefine d = grammar.getOrAdd(name); |
107 d.setPattern( (DPattern) pattern ); |
106 d.setPattern( (DPattern) pattern ); |
108 if(anno!=null) |
107 if (anno!=null) { |
109 d.annotation = ((Annotation)anno).getResult(); |
108 d.annotation = ((Annotation)anno).getResult(); |
|
109 } |
110 } |
110 } |
111 } |
111 } |
112 |
112 |
113 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
113 public void topLevelAnnotation(ParsedElementAnnotation ea) throws BuildException { |
114 if(additionalElementAnnotations==null) |
114 // Harshit : Fixed issue in handling of annotations |
|
115 if (additionalElementAnnotations==null) { |
115 additionalElementAnnotations = new ArrayList<Element>(); |
116 additionalElementAnnotations = new ArrayList<Element>(); |
|
117 } |
116 additionalElementAnnotations.add(((ElementWrapper)ea).element); |
118 additionalElementAnnotations.add(((ElementWrapper)ea).element); |
|
119 if (grammar.annotation==null) { |
|
120 grammar.annotation = new DAnnotation(); |
|
121 } |
|
122 grammar.annotation.contents.addAll(additionalElementAnnotations); |
117 } |
123 } |
118 |
124 |
119 public void topLevelComment(CommentList comments) throws BuildException { |
125 public void topLevelComment(CommentList comments) throws BuildException { |
120 } |
126 } |
121 |
127 |