1 26 27 package org.objectweb.corba.generator.cif.lib; 28 29 import org.objectweb.openccm.generator.java.ast.api.*; 31 import org.objectweb.openccm.generator.java.ast.lib.*; 32 import org.objectweb.openccm.ast.api.Declaration; 33 import org.objectweb.openccm.ast.api.DeclarationKind; 34 import org.objectweb.openccm.ast.api.InterfaceDecl; 35 import org.objectweb.openccm.ast.api.AttributeDecl; 36 import org.objectweb.openccm.ast.api.OperationDecl; 37 import org.objectweb.openccm.ast.api.ProvidesDecl; 38 import org.objectweb.openccm.ast.api.ConsumesDecl; 39 import org.objectweb.openccm.ast.utils.api.ExecutorInfo; 40 41 42 49 50 public class ComponentImplMapping 51 implements org.objectweb.corba.generator.cif.api.ComponentImplMapping 52 { 53 59 60 static public org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator translator_; 61 62 63 private org.objectweb.openccm.ast.utils.api.CompositionInfo comp_; 64 65 71 76 public ComponentImplMapping(org.objectweb.openccm.ast.api.CompositionDecl composition) 77 { 78 comp_ = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition); 79 } 80 81 87 90 static 91 { 92 translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator(); 93 } 94 95 101 private void 102 sessionComponentOperations(ClassObject clazz) 103 { 104 MethodObject method = null; 105 ParameterObject param = null; 106 107 method = new MethodObjectImpl(); 109 method.addComment(" Complete the component configuration."); 110 method.addComment(" "); 111 method.addComment(" @exception org.omg.Components.InvalidConfiguration"); 112 method.addComment(" Thrown if the configuration is invalid."); 113 method.setName("configuration_complete"); 114 method.setReturnType("void"); 115 method.addException("org.omg.Components.InvalidConfiguration"); 116 method.getImpl().setMacro("COMP_CONFIGURATION_COMPLETE"); 117 clazz.addMethod(method); 118 119 method = new MethodObjectImpl(); 121 method.addComment(" Sets the session component context."); 122 method.addComment(" "); 123 method.addComment(" @param context The session component context."); 124 method.addComment(" "); 125 method.addComment(" @throw org.omg.Components.CCMException For any problems."); 126 method.setName("set_session_context"); 127 method.setReturnType("void"); 128 param = new ParameterObjectImpl(); 129 param.setName("context"); 130 param.setType("org.omg.Components.SessionContext"); 131 method.addParameter(param); 132 method.addException("org.omg.Components.CCMException"); 133 method.getImpl().setMacro("COMP_SET_SESSION_CONTEXT"); 134 clazz.addMethod(method); 135 136 method = new MethodObjectImpl(); 138 method.addComment(" Container callback to signal that the component is activated."); 139 method.addComment(" "); 140 method.addComment(" @throw org.omg.Components.CCMException For any problems."); 141 method.setName("ccm_activate"); 142 method.setReturnType("void"); 143 method.addException("org.omg.Components.CCMException"); 144 method.getImpl().setMacro("COMP_CCM_ACTIVATE"); 145 clazz.addMethod(method); 146 147 method = new MethodObjectImpl(); 149 method.addComment(" Container callback to signal that the component is passivated."); 150 method.addComment(" "); 151 method.addComment(" @throw org.omg.Components.CCMException For any problems."); 152 method.setName("ccm_passivate"); 153 method.setReturnType("void"); 154 method.addException("org.omg.Components.CCMException"); 155 method.getImpl().setMacro("COMP_CCM_PASSIVATE"); 156 clazz.addMethod(method); 157 158 method = new MethodObjectImpl(); 160 method.addComment(" Container callback to signal that the component is removed."); 161 method.addComment(" "); 162 method.addComment(" @throw org.omg.Components.CCMException For any problems."); 163 method.setName("ccm_remove"); 164 method.setReturnType("void"); 165 method.addException("org.omg.Components.CCMException"); 166 method.getImpl().setMacro("COMP_CCM_REMOVE"); 167 clazz.addMethod(method); 168 } 169 170 182 private void 183 businessOperations(ClassObject clazz) 184 { 185 Declaration[] decls = null; 186 InterfaceDecl itf = null; 187 AttributeDecl attr = null; 188 OperationDecl op = null; 189 MethodObject method = null; 190 191 itf = comp_.getComponent().getLocalMainMapping(); 192 decls = itf.getContents(false, DeclarationKind.dk_operation+ 193 DeclarationKind.dk_attribute); 194 195 for (int i=0; i<decls.length; i++) 196 { 197 if (decls[i].getDeclKind() == DeclarationKind.dk_attribute) 199 { 200 attr = (AttributeDecl)decls[i]; 201 202 method = translator_.map_attribute_accessor( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] ); 203 method.getImpl().setMacro("BUSINESS_OP"); 204 method.getImpl().addContextValue("translator", translator_); 205 method.getImpl().addContextValue("obj", decls[i]); 206 clazz.addMethod(method); 207 208 method = translator_.map_attribute_mutator( (org.objectweb.openccm.ast.api.AttributeDecl)decls[i] ); 209 if (method != null) 210 { 211 method.getImpl().setMacro("TODO"); 212 clazz.addMethod(method); 213 } 214 } 215 else 216 { 218 op = (OperationDecl)decls[i]; 219 220 if ( (!op.getParent().getAbsoluteName().startsWith("::Components")) && 221 (!op.getName().equals("get_")) ) 222 { 223 method = translator_.map_operation(op); 224 method.getImpl().setMacro("BUSINESS_OP"); 225 method.getImpl().addContextValue("translator", translator_); 226 method.getImpl().addContextValue("obj", op); 227 clazz.addMethod(method); 228 } 229 } 230 } 231 } 232 233 238 private void 239 facetsOperations(ClassObject clazz) 240 { 241 242 Declaration[] decls = null; 243 ProvidesDecl provide = null; 244 ConsumesDecl consume = null; 245 ExecutorInfo exec_info = null; 246 247 exec_info = new org.objectweb.openccm.ast.utils.lib.ExecutorInfo( 249 comp_.getComponentExecutor() ); 250 decls = exec_info.getMainSegmentFacets(); 251 252 for (int i = 0; i<decls.length; i++) 253 { 254 if(decls[i].getDeclKind() == DeclarationKind.dk_provides) 255 { 256 provide = (ProvidesDecl)decls[i]; 257 translator_.mapInterfaceOps(clazz, provide.getLocalMapping()); 258 } 259 else 260 { 261 consume = (ConsumesDecl)decls[i]; 262 translator_.mapInterfaceOps(clazz, consume.getEvent().getLocalConsumerMapping()); 263 } 264 } 265 } 266 267 273 278 public void 279 toJavaComponentTemplate(Repository repository) 280 { 281 ClassObject clazz = null; 282 ConstructorObject ct = null; 283 284 clazz = new ClassObjectImpl(comp_.getComponent().getName()+"Impl"); 285 clazz.addComment(" This is the CIDL-based implementation of the"); 286 clazz.addComment(" OMG IDL3 " 287 + comp_.getComponent().getId() 288 + " component type."); 289 clazz.addComment(""); 290 clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler."); 291 clazz.setModifier(ModifierKindImpl.mk_public); 292 clazz.setPackage( translator_.getPackage(comp_.getHomeExecutor()) ); 293 clazz.addInheritedObject( translator_.getPackage(comp_.getHomeExecutor()) + "." + 294 comp_.getComponentExecutor().getName() ); 295 296 ct = new ConstructorObjectImpl(); 298 clazz.addConstructor(ct); 299 300 businessOperations(clazz); 302 facetsOperations(clazz); 303 sessionComponentOperations(clazz); 304 305 repository.addObject(clazz); 307 } 308 309 315 } 316 | Popular Tags |