KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > model > RegistrationVisitor


1 /*
2 Copyright (c) 2004-2005, Dennis M. Sosnoski
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without modification,
6 are permitted provided that the following conditions are met:
7
8  * Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13  * Neither the name of JiBX nor the names of its contributors may be used
14    to endorse or promote products derived from this software without specific
15    prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */

28
29 package org.jibx.binding.model;
30
31
32 /**
33  * Model visitor for handling item registration. This works with the {@link
34  * org.jibx.binding.model.ValidationContext} class to handle registration of
35  * items which can be referenced by name or by function (such as ID values
36  * within an object structure). The only items of this type which are not
37  * handled by this visitor are <b>format</b> definitions. The formats need to be
38  * accessed during prevalidation, so they're registered during that pass.
39  *
40  * @author Dennis M. Sosnoski
41  * @version 1.0
42  */

43
44 public class RegistrationVisitor extends ModelVisitor
45 {
46     /** Validation context running this visitor. */
47     private final ValidationContext m_context;
48     
49     /**
50      * Constructor.
51      *
52      * @param vctx validation context that will run this visitor
53      */

54     public RegistrationVisitor(ValidationContext vctx) {
55         m_context = vctx;
56     }
57     
58     /**
59      * Visit binding model tree to handle registration.
60      *
61      * @param root node of tree to be visited
62      */

63     public void visitTree(ElementBase root) {
64         m_context.tourTree(root, this);
65     }
66     
67     /* (non-Javadoc)
68      * @see org.jibx.binding.model.ModelVisitor#visit(org.jibx.binding.model.StructureElementBase)
69      */

70     public boolean visit(StructureElementBase node) {
71         if (node.getLabel() != null) {
72             ValidationProblem problem =
73                 m_context.getCurrentDefinitions().addNamedStructure(node);
74             if (problem != null) {
75                 m_context.addProblem(problem);
76             }
77         }
78         return super.visit(node);
79     }
80     
81     /* (non-Javadoc)
82      * @see org.jibx.binding.model.ModelVisitor#visit(org.jibx.binding.model.MappingElement)
83      */

84     public boolean visit(MappingElement node) {
85         m_context.getCurrentDefinitions().addTemplate(node, m_context);
86         return super.visit(node);
87     }
88     
89     /* (non-Javadoc)
90      * @see org.jibx.binding.model.ModelVisitor#visit(org.jibx.binding.model.NamespaceElement)
91      */

92     public boolean visit(NamespaceElement node) {
93         ValidationProblem problem =
94             m_context.getCurrentDefinitions().addNamespace(node);
95         if (problem != null) {
96             m_context.addProblem(problem);
97         }
98         return super.visit(node);
99     }
100     
101     /* (non-Javadoc)
102      * @see org.jibx.binding.model.ModelVisitor#visit(org.jibx.binding.model.TemplateElement)
103      */

104     public boolean visit(TemplateElement node) {
105         m_context.getCurrentDefinitions().addTemplate(node, m_context);
106         return super.visit(node);
107     }
108 }
Popular Tags