KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > multiview > RelationshipHelper


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.ddloaders.multiview;
21
22 import org.netbeans.modules.j2ee.dd.api.ejb.CmrField;
23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelation;
24 import org.netbeans.modules.j2ee.dd.api.ejb.EjbRelationshipRole;
25 import org.netbeans.modules.j2ee.dd.api.ejb.Relationships;
26
27 /**
28  * @author pfiala
29  */

30 public class RelationshipHelper {
31
32     private static final String JavaDoc MULTIPLICITY_MANY = "Many";
33     private static final String JavaDoc MULTIPLICITY_ONE = "One";
34
35     private final EjbRelation relation;
36
37     public static class RelationshipRoleHelper {
38
39         private final EjbRelationshipRole role;
40
41         public RelationshipRoleHelper(EjbRelationshipRole role) {
42             this.role = role;
43         }
44
45         public boolean isMultiple() {
46             return MULTIPLICITY_MANY.equals(role.getMultiplicity());
47         }
48
49         public void setMultiple(boolean multiple) {
50             role.setMultiplicity(multiple ? MULTIPLICITY_MANY : MULTIPLICITY_ONE);
51         }
52
53         public String JavaDoc getEjbName() {
54             return role.getRelationshipRoleSource().getEjbName();
55         }
56
57         public void setEjbName(String JavaDoc ejbName) {
58             role.getRelationshipRoleSource().setEjbName(ejbName);
59         }
60
61         public String JavaDoc getRoleName() {
62             return role.getEjbRelationshipRoleName();
63         }
64
65         public void setRoleName(String JavaDoc roleName) {
66             role.setEjbRelationshipRoleName(roleName);
67         }
68
69         public String JavaDoc getFieldName() {
70             CmrField field = role.getCmrField();
71             return field == null ? null : field.getCmrFieldName();
72         }
73
74         public String JavaDoc getFieldType() {
75             CmrField field = role.getCmrField();
76             return field == null ? null : field.getCmrFieldType();
77         }
78
79         public boolean isCascadeDelete() {
80             return role.isCascadeDelete();
81         }
82
83         public void setCascadeDelete(boolean cascadeDelete) {
84             role.setCascadeDelete(cascadeDelete);
85         }
86
87         public CmrField getCmrField() {
88             return role.getCmrField();
89         }
90
91         public void setCmrField(CmrField cmrField) {
92             role.setCmrField(cmrField);
93         }
94
95         public void setCmrField(String JavaDoc fieldName, String JavaDoc fieldType) {
96             CmrField field = role.getCmrField();
97             if (field == null) {
98                 role.setCmrField(field = role.newCmrField());
99             }
100             field.setCmrFieldName(fieldName);
101             field.setCmrFieldType(fieldType);
102         }
103
104     }
105
106     public final RelationshipRoleHelper roleA;
107     public final RelationshipRoleHelper roleB;
108
109     public RelationshipHelper(EjbRelation relation) {
110         this.relation = relation;
111         roleA = new RelationshipRoleHelper(relation.getEjbRelationshipRole());
112         roleB = new RelationshipRoleHelper(relation.getEjbRelationshipRole2());
113     }
114
115     public RelationshipHelper(Relationships singleRelationships) {
116         relation = singleRelationships.newEjbRelation();
117         EjbRelationshipRole roleA = newRole();
118         relation.setEjbRelationshipRole(roleA);
119         EjbRelationshipRole roleB = newRole();
120         relation.setEjbRelationshipRole2(roleB);
121         singleRelationships.addEjbRelation(relation);
122         this.roleA = new RelationshipRoleHelper(roleA);
123         this.roleB = new RelationshipRoleHelper(roleB);
124     }
125
126     private EjbRelationshipRole newRole() {
127         EjbRelationshipRole role = relation.newEjbRelationshipRole();
128         role.setRelationshipRoleSource(role.newRelationshipRoleSource());
129         return role;
130     }
131
132     public String JavaDoc getRelationName() {
133         return relation.getEjbRelationName();
134     }
135
136     public void setRelationName(String JavaDoc relationName) {
137         relation.setEjbRelationName(relationName);
138     }
139
140     public String JavaDoc getDescription() {
141         return relation.getDefaultDescription();
142     }
143
144     public void setDescription(String JavaDoc description) {
145         relation.setDescription(description);
146     }
147
148 }
149
Popular Tags