1 26 27 package org.objectweb.openccm.corba.trader; 28 29 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 43 44 public class TypeRepositoryFeed 45 extends ApplicationBase 46 { 47 48 54 protected ServiceTypeActions _actions; 55 56 62 63 public 64 TypeRepositoryFeed() 65 { 66 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 80 86 92 101 public int 102 run(java.lang.String [] args) 103 { 104 return run(args, TheTradingService.getRepository()); 105 } 106 107 114 public int 115 run(java.lang.String [] args, org.omg.CosTradingRepos.ServiceTypeRepository repos) 116 { 117 String filename = args[0]; 118 boolean failed = false; 119 120 if (!new java.io.File (filename).exists()) 121 getConsole().error("File " + filename + " not found!"); 122 123 java.io.File file = new java.io.File (filename); 124 getConsole().message("Reading from file " + filename + "..."); 125 126 Services services; 128 try { 129 services = ServicesUnmarshaller.unmarshal(file); 130 } catch (java.io.IOException 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 list = services.getServiceList(); 139 for (java.util.Iterator 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 if (failed) { 184 getConsole().message("Compilation failed."); 185 return -1; 186 } 187 188 getConsole().message("Compilation completed."); 190 return 0; 191 } 192 193 199 204 public static void 205 main(String [] args) 206 { 207 TypeRepositoryFeed trfeed = new TypeRepositoryFeed(); 208 trfeed.runMain(args); 209 } 210 } 211 | Popular Tags |