KickJava   Java API By Example, From Geeks To Geeks.

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


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.objectweb.openccm.command.lib.ApplicationBase;
31 import org.objectweb.openccm.corba.trader.parser.Services;
32 import org.objectweb.openccm.corba.trader.parser.Service;
33 import org.objectweb.openccm.corba.trader.parser.ServicesUnmarshaller;
34 import org.objectweb.openccm.corba.TheTradingService;
35
36 /**
37  * Implementation of the str_feed command.
38  *
39  * @author <a HREF="mailto:Sylvain.Leblanc@lifl.fr">Sylvain Leblanc</a>
40  *
41  * @version 1.0
42  */

43
44 public class TypeRepositoryFeed
45      extends ApplicationBase
46 {
47
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     protected ServiceTypeActions _actions;
55
56     // ==================================================================
57
//
58
// Constructor.
59
//
60
// ==================================================================
61

62     /** The default constructor. */
63     public
64     TypeRepositoryFeed()
65     {
66         // Calls the CompilerBase constructor.
67
super(new org.objectweb.util.cmdline.lib.DefaultCommandLine("trader_feed",
68                                      "xml_file",
69                                      "Feed the CORBA Trader Service Type Repository with an XML service types file.",
70                                      true));
71
72     }
73
74     // ==================================================================
75
//
76
// Internal methods.
77
//
78
// ==================================================================
79

80     // ==================================================================
81
//
82
// Public methods for org.objectweb.util.cmdline.api.Application
83
//
84
// ==================================================================
85

86     // ==================================================================
87
//
88
// Public methods for org.objectweb.corba.command.api.Application
89
//
90
// ==================================================================
91

92     /**
93      * Runs the application.
94      *
95      * @param args The command line arguments.
96      * @param repos The service type repository in which the new
97      * service types will be registered.
98      *
99      * @return The status.
100      */

101     public int
102     run(java.lang.String JavaDoc[] args)
103     {
104         return run(args, TheTradingService.getRepository());
105     }
106
107     /**
108      * Runs the application.
109      *
110      * @param args The command line arguments.
111      *
112      * @return The status.
113      */

114     public int
115     run(java.lang.String JavaDoc[] args, org.omg.CosTradingRepos.ServiceTypeRepository repos)
116     {
117         String JavaDoc filename = args[0];
118         boolean failed = false;
119
120         if (!new java.io.File JavaDoc(filename).exists())
121             getConsole().error("File " + filename + " not found!");
122
123         java.io.File JavaDoc file = new java.io.File JavaDoc(filename);
124         getConsole().message("Reading from file " + filename + "...");
125
126         // Compiles the file.
127
Services services;
128         try {
129             services = ServicesUnmarshaller.unmarshal(file);
130         } catch (java.io.IOException JavaDoc ex) {
131             getConsole().error("Problem when unmarshalling " + filename);
132             return -1;
133         }
134         if(services == null) return -1;
135         _actions = new ServiceTypeActions(repos);
136
137         getConsole().message("Compiling " + filename + " file...");
138         java.util.List JavaDoc list = services.getServiceList();
139         for (java.util.Iterator JavaDoc iter = list.iterator() ; iter.hasNext() ; )
140         {
141             try {
142                 _actions.create_service((Service)iter.next());
143             } catch (org.omg.CosTrading.IllegalServiceType ex) {
144                 getConsole().error("Bad service type name '" +
145                                    ex.type + "'.");
146                 failed=true;
147             } catch (org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.ServiceTypeExists ex) {
148                 getConsole().error("Service definition '" +
149                                    ex.name +
150                                    "' already exist.");
151                 failed=true;
152             } catch (org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.InterfaceTypeMismatch ex) {
153                 getConsole().error("Invalid service OMG IDL interface: '" +
154                                    ex.derived_if +
155                                    "' in '" +
156                                    ex.derived_service + "'.");
157                 failed=true;
158             } catch (org.omg.CosTrading.IllegalPropertyName ex) {
159                 getConsole().error("Bad service property name: '" +
160                                    ex.name + "'.");
161                 failed=true;
162             } catch (org.omg.CosTrading.DuplicatePropertyName ex) {
163                 getConsole().error("Already defined property name: '" +
164                                    ex.name + "'.");
165                 failed=true;
166             } catch (org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.ValueTypeRedefinition ex) {
167                 getConsole().error("Property value type redefinition between '" +
168                                    ex.type_1 + "' and '" +
169                                    ex.type_2 + "' in property '" +
170                                    ex.definition_1.name + "'.");
171                 failed=true;
172             } catch (org.omg.CosTrading.UnknownServiceType ex) {
173                 getConsole().error("Unknown service definition: '" +
174                                    ex.type + "'.");
175                 failed=true;
176             } catch (org.omg.CosTradingRepos.ServiceTypeRepositoryPackage.DuplicateServiceTypeName ex) {
177                 getConsole().error("Duplicate super type: '" + ex.name + "'.");
178                 failed=true;
179             }
180         }
181
182         // At least one the services cannot compile
183
if (failed) {
184             getConsole().message("Compilation failed.");
185             return -1;
186         }
187
188         // All is OK.
189
getConsole().message("Compilation completed.");
190         return 0;
191     }
192
193     // ==================================================================
194
//
195
// Static public methods.
196
//
197
// ==================================================================
198

199     /**
200      * The main bootstrap method.
201      *
202      * @param args The command line arguments.
203      */

204     public static void
205     main(String JavaDoc[] args)
206     {
207         TypeRepositoryFeed trfeed = new TypeRepositoryFeed();
208         trfeed.runMain(args);
209     }
210 }
211
Popular Tags