KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > descriptor > componentassembly > ccm > deployer > util > FindbyDeployer


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA - USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Briclet Frederic
23 Contributor(s): Christophe Contreras.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.util;
28
29 // Importation of all the required package
30
import org.objectweb.openccm.descriptor.componentassembly.*;
31 import org.omg.Components.HomeNotFound;
32
33 /**
34  * FindbyDeployer allow to resolve a find by tags returning the CORBA object found
35  *
36  * @author <a HREF="mailto:frederic.briclet@lifl.fr">Briclet Frederic</a>
37  *
38  * @version 0.1
39  */

40 public class FindbyDeployer
41        extends FindbyDeployerContext
42     {
43     // ==================================================================
44
//
45
// Internal state.
46
//
47
// ==================================================================
48

49     // ==================================================================
50
//
51
// Constructor.
52
//
53
// ==================================================================
54

55     // ==================================================================
56
//
57
// Internal method.
58
//
59
// ==================================================================
60

61
62     /**
63      * Internal method in charge to found the reference throw the homefinder.
64      * It search first the HomeFinder reference into the nameService and secondary
65      * use this homefinder reference to try to resolve the home name precised.
66      * If the home interface is found it is return, else an exception is raised
67      *
68      * @param hf The homefinder tags to resolve
69      * @return Return the home found
70      */

71     private org.omg.Components.CCMHome
72     proceedWithHomeFinder(Homefinder hf)
73     throws CannotResolveReferenceException
74     {
75        try{
76            /*Invoke a search by name into the homefinder*/
77             return getHomeFinder().find_home_by_name(hf.getName());
78        }
79        catch(HomeNotFound hnf)
80        {
81            throw new CannotResolveReferenceException(this,hnf,"Resolution failed using home finder ");
82        }
83     }
84       
85     
86      /**
87       * Internal fonction to resolve and retrieve a reference with the name service.
88       * The reference look up is defined in the Nameservice object tag. If any object
89       * can be found with this reference an exception is thrown.
90       *
91       * @param deployTable the internal table use to store information.
92       * @param service the namingservice tags to resolve
93       * @return Return the corba object found
94       */

95     private org.omg.CORBA.Object JavaDoc
96     proceedWithNameService(Namingservice service)
97     throws CannotResolveReferenceException
98     {
99
100         try{
101         
102             return getNamingContextExt()
103                     .resolve(getNamingContextExt().to_name(service.getName()));
104         }
105         catch(Exception JavaDoc e){
106             throw new CannotResolveReferenceException(this,e,"Resolution failed using name service.\n");
107         }
108     
109     }
110
111
112     // ==================================================================
113
//
114
// Public methods.
115
//
116
// ==================================================================
117
/**
118      * Internal method to resolve a reference point out by a findby component.
119      *
120      * @return Return the corba object found
121      */

122     public org.omg.CORBA.Object JavaDoc
123     resolveReference()
124     throws CannotResolveReferenceException
125     {
126         Findby fb=getFindby();
127         //TODO : reslving component with trader
128
if(fb!=null ) {
129             if(fb.getNamingservice()!=null)
130                 return proceedWithNameService(fb.getNamingservice());
131             else if(fb.getStringifiedobjectref()!=null)
132                 return org.objectweb.openccm.corba.TheORBSingleton.getORB().
133                     string_to_object(fb.getStringifiedobjectref().getValue());
134             else if(fb.getHomefinder()!=null)
135                 return proceedWithHomeFinder(fb.getHomefinder());
136         }
137         throw new CannotResolveReferenceException(this,null,"No resolution way precised");
138     }
139
140
141 }
142
Popular Tags