KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.sun.enterprise.deployment;
24
25     /** I am a pairing between a descriptor and a descriptor that has a JNDI name.
26     *@author Danny Coward
27     */

28
29 public class NamedReferencePair {
30     
31     // Types of named reference pairs
32
public static final int EJB = 1;
33     public static final int EJB_REF = 2;
34     public static final int RESOURCE_REF = 3;
35     public static final int RESOURCE_ENV_REF = 4;
36
37     private Descriptor referant;
38     private NamedDescriptor referee;
39     private int type;
40     
41     public static NamedReferencePair createEjbPair
42         (EjbDescriptor referant, EjbDescriptor referee)
43     {
44         return new NamedReferencePair(referant, referee, EJB);
45     }
46         
47     public static NamedReferencePair createEjbRefPair
48         (Descriptor referant, EjbReferenceDescriptor referee)
49     {
50         return new NamedReferencePair(referant, referee, EJB_REF);
51     }
52
53     public static NamedReferencePair createResourceRefPair
54         (Descriptor referant, ResourceReferenceDescriptor referee)
55     {
56         return new NamedReferencePair(referant, referee, RESOURCE_REF);
57     }
58
59     public static NamedReferencePair createResourceEnvRefPair
60         (Descriptor referant, JmsDestinationReferenceDescriptor referee)
61     {
62         return new NamedReferencePair(referant, referee, RESOURCE_ENV_REF);
63     }
64     
65     /** Construct a pairing between the given descriptor and the object
66     * it has with a jndi name.*/

67     protected NamedReferencePair(Descriptor referant, NamedDescriptor referee,
68                                  int type) {
69     this.referant = referant;
70     this.referee = referee;
71         this.type = type;
72     }
73
74     /** Gets the descriptor with the named descriptor. */
75     public Descriptor getReferant() {
76     return this.referant;
77     }
78     
79     /** Gets the named descriptor for the decriptor.*/
80     public NamedDescriptor getReferee() {
81     return this.referee;
82     }
83
84     public String JavaDoc getPairTypeName() {
85         switch(this.type) {
86             case EJB : return "EJB";
87             case EJB_REF : return "EJB REF";
88             case RESOURCE_REF : return "RESOURCE REF";
89             case RESOURCE_ENV_REF : return "RESOURCE ENV REF";
90         }
91         throw new IllegalStateException JavaDoc("unknown type = " + type);
92     }
93
94     public int getPairType() {
95         return this.type;
96     }
97
98     /** My pretty format. */
99     public void print(StringBuffer JavaDoc toStringBuffer) {
100     toStringBuffer.append("NRP: ").append(referant.getName()).append(" -> ").append(((Descriptor) referee).getName());
101     }
102     
103 }
104
Popular Tags