KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > persistence > entitygenerator > CMPMappingModel


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.persistence.entitygenerator;
21
22 import java.util.Arrays JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Map JavaDoc;
27
28 /**
29  * This class provides the mapping for entity cmp beans to the database table.
30  * This class is used by the application server plug-in to facilitate mapping.
31  * @author Chris Webster
32  */

33 public class CMPMappingModel {
34     private Map JavaDoc cmpFieldMapping;
35     private Map JavaDoc cmrFieldMapping;
36     private String JavaDoc tableName;
37     private Map JavaDoc cmrJoinMapping;
38     private Map JavaDoc <String JavaDoc, JoinTableColumnMapping> joinTableColumnMappings;
39     
40     public CMPMappingModel() {
41         cmpFieldMapping = new HashMap JavaDoc();
42         cmrFieldMapping = new HashMap JavaDoc();
43         cmrJoinMapping = new HashMap JavaDoc();
44         joinTableColumnMappings = new HashMap JavaDoc();
45     }
46     
47     public void setTableName(String JavaDoc tableName) {
48         this.tableName = tableName;
49     }
50     
51     public String JavaDoc getTableName() {
52         return tableName;
53     }
54     
55     public Map JavaDoc getCMPFieldMapping() {
56         return cmpFieldMapping;
57     }
58     
59     public void setCMPFieldMapping(Map JavaDoc m) {
60         cmpFieldMapping = m;
61     }
62     
63     public Map JavaDoc getCmrFieldMapping() {
64         return cmrFieldMapping;
65     }
66     
67     public void setCmrFieldMapping(Map JavaDoc m) {
68         cmrFieldMapping = m;
69     }
70     
71     public Map JavaDoc getJoinTableMapping() {
72         return cmrJoinMapping;
73     }
74     
75     public void setJoinTableMapping(Map JavaDoc m) {
76         cmrJoinMapping = m;
77     }
78     
79     public static class JoinTableColumnMapping {
80         private String JavaDoc[] columns;
81         private String JavaDoc[] referencedColumns;
82         private String JavaDoc[] inverseColumns;
83         private String JavaDoc[] referencedInverseColumns;
84
85         public String JavaDoc[] getColumns() {
86             return columns;
87         }
88
89         public void setColumns(String JavaDoc[] columns) {
90             this.columns = columns;
91         }
92
93         public String JavaDoc[] getReferencedColumns() {
94             return referencedColumns;
95         }
96
97         public void setReferencedColumns(String JavaDoc[] referencedColumns) {
98             this.referencedColumns = referencedColumns;
99         }
100
101         public String JavaDoc[] getInverseColumns() {
102             return inverseColumns;
103         }
104
105         public void setInverseColumns(String JavaDoc[] inverseColumns) {
106             this.inverseColumns = inverseColumns;
107         }
108
109         public String JavaDoc[] getReferencedInverseColumns() {
110             return referencedInverseColumns;
111         }
112
113         public void setReferencedInverseColumns(String JavaDoc[] referencedInverseColumns) {
114             this.referencedInverseColumns = referencedInverseColumns;
115         }
116     }
117     
118     public Map JavaDoc<String JavaDoc, JoinTableColumnMapping> getJoinTableColumnMppings() {
119         return joinTableColumnMappings;
120     }
121     
122     public void setJoiTableColumnMppings(Map JavaDoc<String JavaDoc, JoinTableColumnMapping> joinTableColumnMppings) {
123         this.joinTableColumnMappings = joinTableColumnMppings;
124     }
125     
126     public int hashCode() {
127         return tableName.hashCode();
128     }
129     
130     public boolean equals(Object JavaDoc o) {
131         if (! (o instanceof CMPMappingModel)) {
132             return false;
133         }
134         
135         CMPMappingModel other = (CMPMappingModel)o;
136         
137         if (cmrFieldMapping.size() != other.cmrFieldMapping.size()) {
138             return false;
139         }
140         
141         Iterator JavaDoc keyIt = cmrFieldMapping.keySet().iterator();
142         while (keyIt.hasNext()) {
143             String JavaDoc key = (String JavaDoc) keyIt.next();
144             String JavaDoc[] value = (String JavaDoc[]) cmrFieldMapping.get(key);
145             List JavaDoc l = Arrays.asList(value);
146             Object JavaDoc otherValue = other.cmrFieldMapping.get(key);
147             if (otherValue == null ||
148                 !l.equals(Arrays.asList((String JavaDoc[])other.cmrFieldMapping.get(key)))) {
149                 return false;
150             }
151         }
152         
153         return tableName.equals(other.tableName) &&
154             cmrJoinMapping.equals(other.cmrJoinMapping) &&
155             cmpFieldMapping.equals(other.cmpFieldMapping);
156     }
157
158 }
159
Popular Tags