KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > axi > impl > PeerValidator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.axi.impl;
20
21 import org.netbeans.modules.xml.axi.AXIComponent;
22 import org.netbeans.modules.xml.axi.AXIDocument;
23 import org.netbeans.modules.xml.axi.AnyAttribute;
24 import org.netbeans.modules.xml.axi.AnyElement;
25 import org.netbeans.modules.xml.axi.Attribute;
26 import org.netbeans.modules.xml.axi.Compositor;
27 import org.netbeans.modules.xml.axi.Element;
28 import org.netbeans.modules.xml.axi.ContentModel;
29 import org.netbeans.modules.xml.axi.visitor.DefaultVisitor;
30 import org.netbeans.modules.xml.schema.model.All;
31 import org.netbeans.modules.xml.schema.model.AttributeReference;
32 import org.netbeans.modules.xml.schema.model.Choice;
33 import org.netbeans.modules.xml.schema.model.ElementReference;
34 import org.netbeans.modules.xml.schema.model.GlobalAttribute;
35 import org.netbeans.modules.xml.schema.model.GlobalAttributeGroup;
36 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
37 import org.netbeans.modules.xml.schema.model.GlobalElement;
38 import org.netbeans.modules.xml.schema.model.GlobalGroup;
39 import org.netbeans.modules.xml.schema.model.LocalAttribute;
40 import org.netbeans.modules.xml.schema.model.LocalElement;
41 import org.netbeans.modules.xml.schema.model.Schema;
42 import org.netbeans.modules.xml.schema.model.SchemaComponent;
43 import org.netbeans.modules.xml.schema.model.Sequence;
44
45 /**
46  * PeerValidator validates the peer in an AXIComponent.
47  * It is possible that the code generator, sets arbitrary peer values
48  * for various AXIComponent. AXI sync should treat those components as
49  * invalid. For example if there was an ElementImpl but the peer was found
50  * as an ElementReference then that ElementImpl is bad.
51  *
52  * @author Samaresh (Samaresh.Panda@Sun.Com)
53  */

54 public class PeerValidator extends DefaultVisitor {
55
56     private boolean result = true;
57         
58     /**
59      * Creates a new instance of PeerValidator
60      */

61     public PeerValidator() {
62     }
63     
64     public boolean validate(AXIComponent component) {
65         result = true;
66         component.accept(this);
67         return result;
68     }
69     
70     public void visit(AXIDocument root) {
71         if(! (root.getPeer() instanceof Schema) )
72             result = false;
73     }
74     
75     public void visit(Element element) {
76         SchemaComponent peer = element.getPeer();
77         if(element instanceof ElementImpl) {
78             if( !(peer instanceof GlobalElement) &&
79                 !(peer instanceof LocalElement) )
80                 result = false;
81         }
82         if(element instanceof ElementRef) {
83             if( !(peer instanceof ElementReference) )
84                 result = false;
85         }
86     }
87     
88     public void visit(AnyElement element) {
89         if(! (element.getPeer() instanceof org.netbeans.modules.xml.schema.model.AnyElement) )
90             result = false;
91     }
92     
93     public void visit(Attribute attribute) {
94         SchemaComponent peer = attribute.getPeer();
95         if(attribute instanceof AttributeImpl) {
96             if( !(peer instanceof GlobalAttribute) &&
97                 !(peer instanceof LocalAttribute) )
98                 result = false;
99         }
100         if(attribute instanceof AttributeRef) {
101             if( !(peer instanceof AttributeReference) )
102                 result = false;
103         }
104     }
105         
106     public void visit(AnyAttribute attribute) {
107         if(! (attribute.getPeer() instanceof org.netbeans.modules.xml.schema.model.AnyAttribute) )
108             result = false;
109     }
110     
111     public void visit(Compositor compositor) {
112         SchemaComponent peer = compositor.getPeer();
113         if( !(peer instanceof Sequence) &&
114             !(peer instanceof Choice) &&
115             !(peer instanceof All) )
116             result = false;
117     }
118     
119     public void visit(ContentModel contentModel) {
120         SchemaComponent peer = contentModel.getPeer();
121         if( !(peer instanceof GlobalComplexType) &&
122             !(peer instanceof GlobalGroup) &&
123             !(peer instanceof GlobalAttributeGroup) )
124             result = false;
125     }
126 }
127
Popular Tags