1 26 27 package org.objectweb.openccm.generator.translator.idl2java.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.InterfaceDecl; 33 import org.objectweb.openccm.ast.api.OperationDecl; 34 import org.objectweb.openccm.ast.api.AttributeDecl; 35 import org.objectweb.openccm.ast.api.Declaration; 36 import org.objectweb.openccm.ast.api.DeclarationKind; 37 import org.objectweb.openccm.ast.api.ParameterList; 38 import org.objectweb.openccm.ast.api.ExceptionList; 39 40 47 48 public class IDL_JavaTranslator 49 extends org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator 50 implements org.objectweb.openccm.generator.translator.idl2java.api.IDL_JavaTranslator 51 { 52 58 64 67 public IDL_JavaTranslator() 68 { 69 } 70 71 77 83 90 public MethodObject 91 map_operation(OperationDecl op) 92 { 93 MethodObject method = null; 94 95 method = new MethodObjectImpl(); 96 method.addComment("Implementation of the " + op.getAbsoluteName() + " operation."); 97 method.setName( checkKeywords(op.getName()) ); 98 method.setReturnType( toJava(op.getType()) ); 99 map_parameters( method, 100 op.getParameterList() ); 101 map_exceptions( method, 102 op.getExceptionList() ); 103 return method; 104 } 105 106 113 public MethodObject 114 map_attribute_accessor(AttributeDecl att) 115 { 116 MethodObject method = null; 117 118 method = new MethodObjectImpl(); 119 method.addComment("Implementation of the " + 120 att.getAbsoluteName() + " attribute as accessor operation."); 121 method.setName( checkKeywords(att.getName()) ); 122 method.setReturnType( toJava(att.getType()) ); 123 map_exceptions( method, 124 att.getExceptionList() ); 125 return method; 126 } 127 128 135 public MethodObject 136 map_attribute_mutator(AttributeDecl att) 137 { 138 if (!att.isReadonly()) 139 { 140 MethodObject method = null; 141 ParameterObject param = null; 142 143 method = new MethodObjectImpl(); 144 method.addComment("Implementation of the " + 145 att.getAbsoluteName() + " attribute as mutator operation."); 146 method.setName( checkKeywords(att.getName()) ); 147 method.setReturnType("void"); 148 149 param = new ParameterObjectImpl(); 150 param.setName( checkKeywords(att.getName()) ); 151 param.setType( toJava(att.getType()) ); 152 method.addParameter(param); 153 154 map_exceptions( method, 155 att.getExceptionList() ); 156 return method; 157 } 158 return null; 159 } 160 161 167 public void 168 map_parameters(MethodObject method, 169 ParameterList list) 170 { 171 org.objectweb.openccm.ast.api.Parameter[] params = null; 172 ParameterObject param = null; 173 174 params = list.getParameters(); 175 for (int i=0; i<params.length; i++) 176 { 177 param = new ParameterObjectImpl(); 178 param.setName( checkKeywords(params[i].getName()) ); 179 param.setType( toJava(params[i].getType(), params[i].getMode()) ); 180 method.addParameter(param); 181 } 182 } 183 184 190 public void 191 map_exceptions(MethodObject method, 192 ExceptionList list) 193 { 194 org.objectweb.openccm.ast.api.ExceptionDecl[] excs = null; 195 196 excs = list.getExceptions(); 197 for (int i=0; i<excs.length; i++) 198 { 199 method.addException( getAbsoluteName(excs[i]) ); 200 } 201 } 202 203 208 public void 209 mapInterfaceOps(ClassObject clazz, 210 InterfaceDecl itf) 211 { 212 Declaration[] decls = null; 213 MethodObject method = null; 214 215 decls = itf.getContents(false, DeclarationKind.dk_operation); 216 for (int i=0; i<decls.length; i++) 217 { 218 method = map_operation( (OperationDecl)decls[i] ); 219 method.getImpl().setMacro("BUSINESS_OP"); 220 method.getImpl().addContextValue("translator", this); 221 method.getImpl().addContextValue("obj", (OperationDecl)decls[i]); 222 clazz.addMethod(method); 223 } 224 } 225 226 232 } 233 | Popular Tags |