1 /***
2 * Copyright (c) 2002, CodeStreet LLC. All rights reserved.<p>
3 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following
4 * conditions are met:<p>
5 * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6 * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
7 * in the documentation and/or other materials provided with the distribution. Neither the name of CodeStreet LLC. nor the
8 * names of its contributors may be used to endorse or promote products derived from this software without specific prior written
9 * permission.<p>
10 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
11 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
12 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
13 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
14 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.<p>
16 */
17
18 package com.codestreet.messageforge;
19
20 import org.exolab.castor.mapping.*;
21
22
23 /***
24 * Mappings class to manage XML mappings.
25 * @author Jawaid Hakim.
26 */
27 public class RMapping
28 {
29 /***
30 * Ctor.
31 */
32 public RMapping()
33 {
34 }
35
36 /***
37 * Load mappings from file.
38 * @param filePath File to load.
39 */
40 public void loadMapping(String filePath) throws MappingException
41 {
42 try
43 {
44 Mapping mapping = new Mapping();
45 mapping.loadMapping(filePath);
46 loadMapping(mapping);
47 }
48 catch (java.io.IOException ex)
49 {
50 throw new MappingException(ex);
51 }
52 catch (org.exolab.castor.mapping.MappingException ex)
53 {
54 throw new MappingException(ex);
55 }
56 }
57
58 /***
59 * Load mappings from URL resource.
60 * @param url URL of resource.
61 */
62 public void loadMapping(java.net.URL url) throws MappingException
63 {
64 try
65 {
66 Mapping mapping = new Mapping();
67 mapping.loadMapping(url);
68 loadMapping(mapping);
69 }
70 catch (java.io.IOException ex)
71 {
72 throw new MappingException(ex);
73 }
74 catch (org.exolab.castor.mapping.MappingException ex)
75 {
76 throw new MappingException(ex);
77 }
78 }
79
80 /***
81 * Parse mappings
82 * @param mapping Mapping.
83 */
84 private void loadMapping(Mapping mapping) throws MappingException
85 {
86 try
87 {
88 // TODO
89 /*
90 org.exolab.castor.mapping.xml.MappingRoot root = mapping.getRoot();
91 ClassMapping[] mappings = root.getClassMapping();
92 for (int i = mappings.length - 1; i >= 0; --i)
93 {
94 ClassMapping map = mappings[i];
95 java.io.StringWriter writer = new java.io.StringWriter();
96 map.marshal(writer);
97 System.out.println(writer.toString());
98
99 for (int j = map.getFieldMappingCount() - 1; j >= 0; --j)
100 {
101 FieldMapping fldMap = map.getFieldMapping(j);
102 System.out.println(fldMap.getName() + " : " + fldMap.getType());
103 BindXml bindXml = fldMap.getBindXml();
104 System.out.println(bindXml.getName());
105 }
106 }
107 */
108
109 /*
110 MappingResolver resolver = mapping.getResolver(Mapping.XML);
111 for (java.util.Enumeration descriptors = resolver.listDescriptors(); descriptors.hasMoreElements(); )
112 {
113 XMLClassDescriptor desc = (XMLClassDescriptor)descriptors.nextElement();
114 FieldDescriptor[] fields = desc.getFields();
115 for (int i = fields.length - 1; i >= 0; --i)
116 {
117 XMLFieldDescriptor desc2 = (XMLFieldDescriptor)fields[i];
118 System.out.println(fields[i].getFieldName() + " : " + fields[i].getFieldType());
119 System.out.println(desc2.getXMLName() + " : " + desc2.getNodeType());
120 }
121 }
122 */
123 }
124 catch (Exception ex)
125 {
126 throw new MappingException(ex);
127 }
128 }
129
130 //private com.sun.java.util.collections.Map mappings_ = new com.sun.java.util.collections.HashMap();
131 }
This page was automatically generated by Maven