KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.j2ee.persistence.entitygenerator;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.List JavaDoc;
24 import org.openide.filesystems.FileObject;
25
26 /**
27  * Abstract description of an entity class
28  * (either CMP or Java Persistence API).
29  *
30  * @author Chris Webster, Martin Adamek, Andrei Badea
31  */

32 public class EntityClass {
33     
34     private final String JavaDoc tableName;
35     private final FileObject rootFolder;
36     private final String JavaDoc className;
37     private final String JavaDoc packageName;
38     
39     private List JavaDoc<RelationshipRole> roles;
40     private List JavaDoc<EntityMember> fields;
41     private boolean usePkField;
42     private String JavaDoc pkFieldName;
43     private CMPMappingModel mappingModel;
44     
45     public EntityClass(String JavaDoc tableName, FileObject rootFolder, String JavaDoc packageName, String JavaDoc className) {
46         this.tableName = tableName;
47         this.rootFolder = rootFolder;
48         this.packageName = packageName;
49         this.className = className;
50         
51         roles = Collections.<RelationshipRole>emptyList();
52         fields = new ArrayList JavaDoc<EntityMember>();
53         mappingModel = new CMPMappingModel();
54     }
55     
56     public void addRole(RelationshipRole role) {
57         if (roles == Collections.<RelationshipRole>emptyList()) {
58             roles = new ArrayList JavaDoc<RelationshipRole>();
59         }
60         roles.add(role);
61     }
62     
63     public List JavaDoc<RelationshipRole> getRoles() {
64         return roles;
65     }
66     
67     public List JavaDoc<EntityMember> getFields() {
68         return fields;
69     }
70     
71     public void setFields(List JavaDoc<EntityMember> fields) {
72         this.fields = fields;
73     }
74     
75     public String JavaDoc toString() {
76         String JavaDoc cmpFields = ""; // NOI18N
77
for (EntityMember entityMember : getFields()) {
78             cmpFields += " " + entityMember.getMemberName() + (entityMember.isPrimaryKey() ? " (PK) " : " "); // NOI18N
79
}
80         return "bean name " + getClassName() + // NOI18N
81
"\ncmp-fields "+ cmpFields; // NOI18N
82
}
83     
84     public FileObject getRootFolder() {
85         return rootFolder;
86     }
87     
88     public String JavaDoc getPackage() {
89         return packageName;
90     }
91     
92     public String JavaDoc getTableName() {
93         return tableName;
94     }
95     
96     public String JavaDoc getClassName() {
97         return className;
98     }
99     
100     public FileObject getPackageFileObject() {
101         String JavaDoc relative = packageName.replace('.', '/');
102         return rootFolder.getFileObject(relative);
103     }
104     
105     public CMPMappingModel getCMPMapping() {
106         mappingModel.getCMPFieldMapping().clear();
107         for (EntityMember entityMember : getFields()) {
108             mappingModel.setTableName(entityMember.getTableName());
109             mappingModel.getCMPFieldMapping().put(entityMember.getMemberName(), entityMember.getColumnName());
110         }
111         return mappingModel;
112     }
113     
114     public void usePkField(boolean usePkField) {
115         this.usePkField = usePkField;
116     }
117     
118     public boolean isUsePkField() {
119         return usePkField;
120     }
121     
122     public String JavaDoc getPkFieldName() {
123         return pkFieldName;
124     }
125     
126     public void setPkFieldName(String JavaDoc pkFieldName) {
127         this.pkFieldName = pkFieldName;
128     }
129 }
130
Popular Tags