KickJava   Java API By Example, From Geeks To Geeks.

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


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): _____________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.corba.trader;
28
29 // Package dependencies
30
import org.objectweb.openccm.corba.trader.parser.Service;
31 import org.objectweb.openccm.corba.trader.TraderTypeCodeUtils;
32 import org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.PropertyMode;
33
34 /**
35  * Utility class to perform various actions on the trading service.
36  */

37 public class ServiceTypeActions {
38
39     // ==================================================================
40
//
41
// Internal state.
42
//
43
// ==================================================================
44

45     /** The used service type repository. */
46     org.omg.CosTradingRepos.ServiceTypeRepository repos_;
47
48     // ==================================================================
49
//
50
// Constructors.
51
//
52
// ==================================================================
53

54     /**
55      * The default constructor.
56      */

57     public
58     ServiceTypeActions (org.omg.CosTradingRepos.ServiceTypeRepository repos)
59     {
60         repos_ = repos;
61     }
62
63     // ==================================================================
64
//
65
// Internal methods.
66
//
67
// ==================================================================
68

69     /**
70      * Convert a type code identifier as expressed in the service type
71      * DTD used in OpenCCM to a classical type code identifier, e.g.
72      * <code>sequence&lt;type&gt;</code> for sequence type codes and
73      * <code>unsigned type</code> for an unsigned type code.
74      *
75      * @param typeCodeId The type code identifier such as used in the
76      * OpenCCM service type DTD.
77      *
78      * @return The classical type code identifier associated or the original
79      * one if not representing a sequence or an undigned type.
80      */

81     private String JavaDoc
82     convertSequence(String JavaDoc typeCodeId)
83     {
84         if (! typeCodeId.endsWith("Seq") &&
85             ! typeCodeId.startsWith("unsigned")) return typeCodeId;
86         if (typeCodeId.startsWith("unsigned_long")) return "unsigned long";
87         if (typeCodeId.startsWith("unsigned_short")) return "unsigned short";
88         if (typeCodeId.startsWith("String")) return "sequence<string>";
89         if (typeCodeId.startsWith("Long")) return "sequence<long>";
90         if (typeCodeId.startsWith("ULong")) return "sequence<unsigned long>";
91         if (typeCodeId.startsWith("Short")) return "sequence<short>";
92         if (typeCodeId.startsWith("UShort")) return "sequence<unsigned short>";
93         if (typeCodeId.startsWith("Double")) return "sequence<double>";
94         if (typeCodeId.startsWith("Float")) return "sequence<float>";
95         if (typeCodeId.startsWith("Boolean")) return "sequence<boolean>";
96         if (typeCodeId.startsWith("Octet")) return "sequence<octet>";
97         if (typeCodeId.startsWith("Char")) return "sequence<char>";
98         return typeCodeId;
99     }
100
101     /**
102      * Returns the CosTrading property mode according to the given
103      * string.
104      *
105      * @param mode_name The string representation of the property
106      * mode. this could be "normal", "mandatory", "readonly" or
107      * "mandatory_readonly".
108      *
109      * @return The associated property mode. By default the
110      * "PROP_NORMAL" mode is returned.
111      */

112     protected PropertyMode
113     getPropertyMode(String JavaDoc mode_name) {
114         if (mode_name.startsWith("mandatory_readonly"))
115             return PropertyMode.PROP_MANDATORY_READONLY;
116         if (mode_name.startsWith("mandatory"))
117             return PropertyMode.PROP_MANDATORY;
118         if (mode_name.startsWith("readonly"))
119             return PropertyMode.PROP_READONLY;
120         //if (mode_name.startsWith("normal"))
121
return PropertyMode.PROP_NORMAL;
122     }
123
124     // ==================================================================
125
//
126
// Public methods.
127
//
128
// ==================================================================
129

130     /**
131      * Create a new service type described in a OpenCCM service type
132      * descriptor in the OMG Trading Service.
133      *
134      * @param desc The Service Type information on the service type to
135      * create contained in the descriptor.
136      *
137      * @return The service type incarnation number.
138      */

139     public org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.IncarnationNumber
140     create_service(Service desc)
141         throws org.omg.CosTrading.IllegalServiceType,
142         org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.ServiceTypeExists,
143         org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.InterfaceTypeMismatch,
144         org.omg.CosTrading.IllegalPropertyName,
145         org.omg.CosTrading.DuplicatePropertyName,
146         org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.ValueTypeRedefinition,
147         org.omg.CosTrading.UnknownServiceType,
148         org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.DuplicateServiceTypeName
149     {
150         // Retrieve the array of super type names
151
java.util.List JavaDoc superTypesList = desc.getSuperTypeList();
152         String JavaDoc[] superTypes = new String JavaDoc[superTypesList.size()];
153         int i = 0;
154         for (java.util.Iterator JavaDoc iter = superTypesList.iterator();
155              iter.hasNext() ; i++)
156         {
157             org.objectweb.openccm.corba.trader.parser.SuperType st;
158             st = (org.objectweb.openccm.corba.trader.parser.SuperType)iter.next();
159             superTypes[i] = st.getName();
160         }
161         
162         // Construct the list of org.omg.CosTrading.PropStruct
163
java.util.List JavaDoc properties = desc.getPropertyList();
164         org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.PropStruct[] props;
165         props = new org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.PropStruct[properties.size()];
166         i = 0;
167         for (java.util.Iterator JavaDoc iter = properties.iterator();
168              iter.hasNext() ; i++)
169         {
170             org.objectweb.openccm.corba.trader.parser.Property prop;
171             prop = (org.objectweb.openccm.corba.trader.parser.Property)iter.next();
172             org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.PropStruct cos_prop;
173             cos_prop = new org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.PropStruct();
174             cos_prop.name = prop.getName();
175             cos_prop.value_type = TraderTypeCodeUtils.getTypeCode(convertSequence(prop.getType()));
176             cos_prop.mode = getPropertyMode(prop.getMode());
177             props[i] = cos_prop;
178         }
179
180         return repos_.add_type(desc.getName(),
181                                desc.getXmlinterface().getName(),
182                                props, superTypes);
183     }
184 }
185
Popular Tags