KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > corba > trader > QueryPoliciesHelper


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): Sylvain Leblanc
23 Contributor(s): Christophe Demarey.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.corba.trader;
28
29 // Package dependencies
30
import org.omg.CosTrading.FollowOption;
31
32 /**
33  * Provides an helper class in order to deal with standard trader
34  * querying policies. Mainly allows to check if a given policy exist
35  * and to retrieve the type code associated with this policy.
36  *
37  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
38  * @version 0.1
39  */

40 public abstract class QueryPoliciesHelper {
41
42     /**
43      * The policies supported by the query operation. This map
44      * contains the name of policies as keys and their related
45      * org.omg.CORBA.TypeCode as value.
46      */

47     private static java.util.Map JavaDoc query_policies = null;
48
49     // Static block used to initialize the query_policies map.
50
static {
51         java.util.HashMap JavaDoc hm = new java.util.HashMap JavaDoc();
52         org.omg.CORBA.TypeCode JavaDoc ul_tc = TraderTypeCodeUtils.getTypeCode("unsigned long");
53         org.omg.CORBA.TypeCode JavaDoc bool_tc = TraderTypeCodeUtils.getTypeCode("boolean");
54         org.omg.CORBA.TypeCode JavaDoc fo_tc = org.omg.CosTrading.FollowOptionHelper.type();
55         org.omg.CORBA.TypeCode JavaDoc tn_tc = org.omg.CosTrading.TraderNameHelper.type();
56         org.omg.CORBA.TypeCode JavaDoc os_tc = org.omg.CosTrading.AdminPackage.OctetSeqHelper.type();
57         
58         hm.put("search_card", ul_tc);
59         hm.put("match_card", ul_tc);
60         hm.put("return_card", ul_tc);
61         hm.put("hop_count", ul_tc);
62         hm.put("link_follow_rule", fo_tc);
63         hm.put("starting_trader", tn_tc);
64         hm.put("request_id", os_tc);
65         hm.put("exact_type_match", bool_tc);
66         hm.put("use_modifiable_properties", bool_tc);
67         hm.put("use_dynamic_properties", bool_tc);
68         hm.put("use_proxy_offers", bool_tc);
69         QueryPoliciesHelper.query_policies = hm;
70     }
71
72     /**
73      * Resolve the type code of a trading query policy.
74      *
75      * @param policy_name the policy name to resolve.
76      *
77      * @return The associated CORBA type code.
78      */

79     public static org.omg.CORBA.TypeCode JavaDoc
80     getQueryPolicyType(String JavaDoc policy_name)
81     {
82         return (org.omg.CORBA.TypeCode JavaDoc)QueryPoliciesHelper.query_policies.get(policy_name.toLowerCase());
83     }
84
85     /**
86      * Resolve the type code of a trading query policy.
87      *
88      * @param policy_name the policy name to resolve.
89      *
90      * @return The associated CORBA type code.
91      */

92     public static boolean
93     exist(String JavaDoc policy_name)
94     {
95         return QueryPoliciesHelper.query_policies.containsKey(policy_name.toLowerCase());
96     }
97     
98     /**
99      * Construct a standard CosTrading::Policy. As the given value is
100      * not associated to a type code, this method assumes that the
101      * policy must be an importer policy as specified in the Trading
102      * Object Service specification. Otherwise, the
103      * CosTrading::Property cannot be constructed and the
104      * <code>null</code> value is returned.
105      *
106      * @param name The name of the trader policy.
107      * @param value The value of the trader policy as a string.
108      *
109      * @return The CosTrading::Policy corresponding structure or null
110      * if this policy cannot be constructed.
111      */

112     public static org.omg.CosTrading.Policy
113     construct_policy(String JavaDoc name, String JavaDoc value)
114     {
115         org.omg.CORBA.TypeCode JavaDoc tc = QueryPoliciesHelper.getQueryPolicyType(name);
116         if (tc == null) return null;
117         org.omg.CORBA.Any JavaDoc any = null;
118         if (name.equals("link_follow_rule")) {
119             any = org.objectweb.openccm.corba.TheORB.getORB().create_any();
120             FollowOption opt = null;
121             if (value.equals("local_only")) opt = FollowOption.local_only;
122             else if (value.equals("if_no_local")) opt = FollowOption.if_no_local;
123             else opt = FollowOption.always;
124             org.omg.CosTrading.FollowOptionHelper.insert(any, opt);
125         } else {
126             any = TraderTypeCodeUtils.insertInAny(tc, value);
127         }
128         if (any == null) return null;
129         return new org.omg.CosTrading.Policy(name, any);
130     }
131 }
132
Popular Tags