KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > ccm > runtime > ServicesSetImpl


1 // ====================================================================
2
//
3
// ECM: The Extensible Container Model
4
// Copyright (C) 2004 THALES
5
// Contact: openccm-ecm@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): Mathieu Vadet.
23
// Initial Funding: IST COACH European project (IST-2001-34445)
24
// http://www.ist-coach.org
25
//
26
// ====================================================================
27

28
29
30 package org.objectweb.ccm.runtime;
31
32 import org.objectweb.corba.runtime.*;
33
34 /**
35  ** <p>Default implementation of the <tt>ServicesSet</tt> interface.</p>
36  **/

37 public class ServicesSetImpl
38 extends org.omg.CORBA.LocalObject JavaDoc
39 implements ServicesSet
40 {
41     // services set
42
static final private String JavaDoc _class_name = "ServicesSetImpl";
43     private ServiceImpl[] _services;
44     private CORBAServiceRef[] _degen_services;
45     private ORBService _orb_service;
46
47     // default constructor
48
public
49     ServicesSetImpl(ServiceImpl[] services,
50                     CORBAServiceRef[] dservices,
51                     ORBService orbs)
52     {
53         // services set
54
_services = services;
55         _degen_services = dservices;
56         _orb_service = orbs;
57     }
58
59     //
60
// internal operations
61
//
62

63     private ServiceImpl
64     findServiceById(String JavaDoc sid)
65     {
66         ServiceImpl[] services = _services;
67         for (int i=0;i<services.length;i++) {
68             if (services[i].service_id().equals(sid)) {
69                 return services[i];
70             }
71         }
72
73         return null;
74     }
75
76     private PolicyImpl[]
77     asPolicies(org.coach.ECM.CCDPolicyRef[] prefs)
78     {
79         // create policy object for each policy
80
ServiceImpl service = null;
81         PolicyImpl[] pols = new PolicyImpl[prefs.length];
82         for (int i=0;i<prefs.length;i++) {
83             // get service for policy
84
service = findServiceById(prefs[i].service_id);
85
86             // check if found
87
if (service==null) {
88                 final String JavaDoc opname = "asPolicies";
89                 final String JavaDoc msg = "FAILED (service not found: "+prefs[i].service_id+")";
90                 TheLogger.error(_class_name, opname, msg);
91                 return null;
92             }
93
94             // create policy
95
pols[i] = (PolicyImpl)service.create_policy(prefs[i].policyref, prefs[i].policyvalue);
96         }
97
98         return pols;
99     }
100
101     //
102
// IDL:objectweb.org/ccm/runtime/ServicesSet:1.0
103
//
104

105     final public Service
106     find_service(String JavaDoc sid)
107     {
108         return findServiceById(sid);
109     }
110
111     final public org.omg.CORBA.Object JavaDoc
112     find_degenerated_service(String JavaDoc regname)
113     {
114         // find ref on the ORB service
115
org.omg.CORBA.Object JavaDoc ref = _orb_service.resolve_initial_references(regname);
116
117         // check that the registration name correspond to a degenerated service
118
CORBAServiceRef[] dservices = _degen_services;
119         boolean isds = false;
120         for (int i=0;i<dservices.length;i++) {
121             if (dservices[i].orb_registration_name.equals(regname)) {
122                 isds = true;
123                 break;
124             }
125         }
126
127         if (isds) {
128             // NOTE: can ref be null is this case ? normally no
129
return ref;
130         }
131
132         final String JavaDoc opname = "find_degenerated_service";
133         final String JavaDoc msg = "regname is not a degenerated service: "+regname;
134         TheLogger.debug(_class_name, opname, msg);
135
136         return null;
137     }
138
139     final public Policy[]
140     get_policies(String JavaDoc uuid, String JavaDoc sname)
141     {
142         // obtain component installation
143
org.omg.CORBA.Object JavaDoc ref = null;
144         org.coach.ECM.ExtComponentInstallation extci = null;
145
146         ref = _orb_service.resolve_initial_references("ExtComponentInstallation");
147         extci = org.coach.ECM.ExtComponentInstallationHelper.narrow(ref);
148
149         // obtain component archive
150
org.coach.ECM.ComponentArchive carch = extci.get_component_archive(uuid);
151
152         // obtain policy refs
153
org.coach.ECM.CCDPolicyRef[] prefs = carch.get_policies_for_target(sname);
154
155         //
156
return asPolicies(prefs);
157     }
158 }
Popular Tags