KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > RelationshipDescriptor


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment;
25
26 import java.util.*;
27 import java.lang.reflect.*;
28 import com.sun.enterprise.util.LocalStringManagerImpl;
29
30
31 /**
32  * This class contains information about relationships between
33  * EJB2.0 CMP EntityBeans.
34  * It represents information in the <ejb-relation> XML element.
35  *
36  * @author Sanjeev Krishnan
37  */

38
39 public final class RelationshipDescriptor extends Descriptor {
40
41     private static LocalStringManagerImpl localStrings =
42         new LocalStringManagerImpl(RelationshipDescriptor.class);
43
44     private RelationRoleDescriptor source; // descriptor for source role
45
private RelationRoleDescriptor sink; // descriptor for sink role
46

47     private boolean isBidirectional = true;
48     
49     public RelationshipDescriptor() {
50     }
51
52     public boolean isOneOne() {
53     return (!source.getIsMany() && !sink.getIsMany());
54     }
55     
56     public boolean isOneMany() {
57     return (!source.getIsMany() && sink.getIsMany());
58     }
59     
60     public boolean isManyOne() {
61     return (source.getIsMany() && !sink.getIsMany());
62     }
63     
64     public boolean isManyMany() {
65     return (source.getIsMany() && sink.getIsMany());
66     }
67
68     /**
69      * Checks whether an EjbCMPEntityDescriptor
70      * is a participant in this relationship.
71      */

72     public boolean hasParticipant(Descriptor desc) {
73         return ( (source.getOwner() == desc) || (sink.getOwner() == desc) );
74     }
75
76     public RelationRoleDescriptor getSource()
77     {
78     return source;
79     }
80     public void setSource(RelationRoleDescriptor source)
81     {
82     this.source = source;
83     }
84
85     public void setSink(RelationRoleDescriptor sink)
86     {
87     this.sink = sink;
88     }
89     public RelationRoleDescriptor getSink()
90     {
91     return sink;
92     }
93
94     public void setIsBidirectional(boolean isBidirectional)
95     {
96     this.isBidirectional = isBidirectional;
97     }
98     public boolean getIsBidirectional()
99     {
100     return isBidirectional;
101     }
102
103     public void print(StringBuffer JavaDoc toStringBuffer) {
104         toStringBuffer.append("From EJB ").append(getSource().getName()
105            ).append(" cmr field : ").append(getSource().getCMRField()
106            ).append("(").append(getSource().getCMRFieldType()).append(") to EJB ").append(getSink().getName()
107            ).append(" isMany ").append(getSource().getIsMany()
108            ).append(" cascade-delete ").append(getSource().getCascadeDelete());
109     }
110 }
111
Popular Tags