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.OperationDecl; 35 import org.objectweb.openccm.ast.api.InterfaceDecl; 36 37 38 45 46 public class HomeImplMapping 47 implements org.objectweb.corba.generator.cif.api.HomeImplMapping 48 { 49 55 56 static public org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator translator_; 57 58 59 private org.objectweb.openccm.ast.utils.api.CompositionInfo comp_; 60 61 67 72 public HomeImplMapping(org.objectweb.openccm.ast.api.CompositionDecl composition) 73 { 74 comp_ = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition); 75 } 76 77 83 86 static 87 { 88 translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.IDL_JavaTranslator(); 89 } 90 91 96 private void 97 map_create_segments_op(ClassObject clazz) 98 { 99 MethodObject method = null; 100 ParameterObject param = null; 101 102 method = new MethodObjectImpl(); 104 method.addComment(" Method for the org.objectweb.ccm.runtime.cif.api.SegmentHome interface."); 105 method.addComment(" "); 106 method.addComment(" Create an executor segment from its identifier."); 107 method.addComment(" "); 108 method.addComment(" @param segid - The executor segment identifier."); 109 method.addComment(" "); 110 method.addComment(" @return - The executor segment created."); 111 method.setName("create_executor_segment"); 112 method.setReturnType("org.omg.Components.ExecutorSegmentBase"); 113 114 method.getImpl().setMacro("HOME_CREATE_SEGMENT"); 115 method.getImpl().addContextValue("package", translator_.getPackage(comp_.getHomeExecutor())); 116 method.getImpl().addContextValue("segments", comp_.getSegments()); 117 method.getImpl().addContextValue("component", comp_.getComponent()); 118 119 param = new ParameterObjectImpl(); 120 param.setName("segid"); 121 param.setType("int"); 122 method.addParameter(param); 123 clazz.addMethod(method); 124 } 125 126 131 private void 132 map_create_home_op(ClassObject clazz) 133 { 134 MethodObject method = null; 135 136 method = new MethodObjectImpl(); 137 method.addComment(" This method is called by the OpenCCM Component Server"); 138 method.addComment(" to create a home instance."); 139 method.addComment(" "); 140 method.addComment(" @return - The created home."); 141 method.setName("create_home"); 142 method.setReturnType("org.omg.Components.HomeExecutorBase"); 143 method.setStatic(true); 144 145 method.getImpl().setMacro("HOME_CREATE_HOME"); 146 method.getImpl().addContextValue("package", translator_.getPackage(comp_.getHomeExecutor())); 147 method.getImpl().addContextValue("home_name", comp_.getHome().getName() ); 148 149 clazz.addMethod(method); 150 } 151 152 157 private void 158 businessOperations(ClassObject clazz) 159 { 160 Declaration[] decls = null; 161 OperationDecl op = null; 162 InterfaceDecl itf = null; 163 MethodObject method = null; 164 165 itf = comp_.getHome().getLocalMapping(); 166 decls = itf.getContents(false, DeclarationKind.dk_operation); 167 168 for (int i=0;i<decls.length;i++) 169 { 170 op = (org.objectweb.openccm.ast.api.OperationDecl)decls[i]; 171 172 if ( (!op.getParent().getAbsoluteName().startsWith("::Components")) && 173 (!op.getName().equals("create")) ) 174 { 175 method = translator_.map_operation(op); 176 method.getImpl().setMacro("BUSINESS_OP"); 177 method.getImpl().addContextValue("translator", translator_); 178 method.getImpl().addContextValue("obj", op); 179 clazz.addMethod(method); 180 } 181 } 182 183 } 184 185 191 196 public void 197 toJavaHomeTemplate(Repository repository) 198 { 199 ClassObject clazz = null; 200 ConstructorObject ct = null; 201 202 clazz = new ClassObjectImpl(comp_.getHome().getName()+"Impl"); 203 clazz.addComment(" This is the CIDL-based implementation of "); 204 clazz.addComment(" OMG IDL3 " 205 + comp_.getHome().getId() 206 + " home type."); 207 clazz.addComment(""); 208 clazz.addComment(" This class inherits from the generated home executor skeleton class"); 209 clazz.addComment(" defined by OMG CIDL " 210 + translator_.getAbsoluteName( comp_.getHomeExecutor() ) 211 ); 212 clazz.addComment(""); 213 clazz.addComment(" @author OpenCCM CIF_Jimpl Compiler."); 214 clazz.setModifier(ModifierKindImpl.mk_public); 215 clazz.setPackage( translator_.getPackage(comp_.getHomeExecutor()) ); 216 clazz.addInheritedObject( translator_.getAbsoluteName(comp_.getHomeExecutor()) ); 217 218 ct = new ConstructorObjectImpl(); 220 clazz.addConstructor(ct); 221 222 map_create_segments_op(clazz); 224 map_create_home_op(clazz); 225 businessOperations(clazz); 226 227 repository.addObject(clazz); 229 } 230 231 237 } 238 | Popular Tags |