KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jibx > binding > def > MappingDirect


1 /*
2 Copyright (c) 2003-2004, 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.def;
30
31 import org.jibx.binding.classes.*;
32 import org.jibx.runtime.JiBXException;
33
34 /**
35  * Direct mapping using supplied marshaller and unmarshaller.
36  *
37  * @author Dennis M. Sosnoski
38  * @version 1.0
39  */

40
41 public class MappingDirect extends MappingBase
42 {
43     /** Direct mapping implementation. */
44     private final DirectObject m_mappingImpl;
45     
46     /** Class file to use for added code. */
47     private final BoundClass m_boundClass;
48     
49     /** Flag for code added to class (if appropriate). */
50     private boolean m_isGenerated;
51
52     /**
53      * Constructor.
54      *
55      * @param contain containing binding definition structure
56      * @param type bound class name
57      * @param dir direct object information
58      * @throws JiBXException on mapping definition conflict
59      */

60
61     public MappingDirect(IContainer contain, String JavaDoc type, DirectObject dir)
62         throws JiBXException {
63         super(contain, type, dir);
64         m_mappingImpl = dir;
65         m_boundClass = BoundClass.getInstance(type, null);
66     }
67
68     /**
69      * Get the mapped class information. This implements the method used by the
70      * base class.
71      *
72      * @return information for mapped class
73      */

74     
75     public BoundClass getBoundClass() {
76         return m_boundClass;
77     }
78     
79     //
80
// IMapping interface method definitions
81

82     public String JavaDoc getBoundType() {
83         return m_mappingImpl.getTargetClass().getName();
84     }
85     
86     public IComponent getImplComponent() {
87         return m_component;
88     }
89     
90     public ClassFile getMarshaller() throws JiBXException {
91         return m_mappingImpl.getMarshaller();
92     }
93     
94     public ClassFile getUnmarshaller() throws JiBXException {
95         return m_mappingImpl.getUnmarshaller();
96     }
97     
98     public NameDefinition getName() {
99         return m_mappingImpl.getName();
100     }
101
102     public void addNamespace(NamespaceDefinition ns) {
103         throw new IllegalStateException JavaDoc
104             ("Internal error: no namespace definition possible");
105     }
106
107     public boolean isAbstract() {
108         return false;
109     }
110
111     public void addExtension(MappingDefinition mdef) {
112         throw new IllegalStateException JavaDoc
113             ("Internal error: no extension possible");
114     }
115     
116     public IComponent buildRef(IContainer parent, IContextObj objc, String JavaDoc type,
117         PropertyDefinition prop) throws JiBXException {
118         return new DirectProperty(prop, m_mappingImpl);
119     }
120     
121     public void generateCode() throws JiBXException {
122         if (!m_isGenerated) {
123             if (m_boundClass.isDirectAccess()) {
124                 addIMarshallableMethod();
125                 addIUnmarshallableMethod();
126             }
127             m_isGenerated = true;
128         }
129     }
130
131     public void setLinkages() throws JiBXException {
132         m_mappingImpl.setLinkages();
133     }
134     
135     // DEBUG
136
public void print(int depth) {
137         BindingDefinition.indent(depth);
138         System.out.println("mapping direct " +
139              m_mappingImpl.getTargetClass().getName());
140     }
141 }
Popular Tags