1 26 27 package org.objectweb.openccm.pss.generator.hibernate.lib; 28 29 31 import org.objectweb.openccm.generator.java.ast.api.*; 32 import org.objectweb.openccm.generator.java.ast.lib.*; 33 34 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator; 35 import org.objectweb.openccm.pss.generator.common.lib.PSDLTools; 36 37 38 46 public class StateMemberMapping 47 extends org.objectweb.openccm.pss.generator.common.lib.StateMemberMapping 48 { 49 50 56 62 65 public StateMemberMapping() 66 { 67 super(); 68 } 69 70 76 81 private String 82 mapHibernateGetter() 83 { 84 return "get" + state_.getName() + "_state"; 85 } 86 87 private String 88 mapHibernateSetter() 89 { 90 return "set" + state_.getName() + "_state"; 91 } 92 93 99 106 public void 107 toJavaAccessors( PSDL_JavaTranslator translator, 108 InterfaceObject obj, 109 boolean finalAccessor ) 110 { 111 MethodObject method = null; 112 ParameterObject param = null; 113 114 if (PSDLTools.isAbstractStorageTypeReference(state_.getType())) 115 { 116 method = new MethodObjectImpl(); 118 method.addComment("Get the "+state_.getName()+" value."); 119 method.addComment(" "); 120 method.addComment("@return The "+state_.getName()+" value."); 121 method.setName( state_.getName() ); 122 method.setReturnType( translator.RefToJava(state_.getType()) ); 123 method.setFinal( finalAccessor ); 124 method.getImpl().setMacro("REF_GET_METHOD"); 125 method.getImpl().addContextValue("st_type", translator.RefToJava(state_.getType()) ); 126 method.getImpl().addContextValue("state", state_.getName()); 127 obj.addMethod(method); 128 129 method = new MethodObjectImpl(); 131 method.addComment("Get the "+state_.getName()+" value."); 132 method.addComment(" "); 133 method.addComment("@param yr - Use to have a different signature."); 134 method.addComment(" "); 135 method.addComment("@return The "+state_.getName()+" value."); 136 method.setName( state_.getName() ); 137 method.setReturnType( translator.toJava(state_.getType()) ); 138 method.setFinal( finalAccessor ); 139 param = new ParameterObjectImpl(); 140 param.setName("yr"); 141 param.setType("org.omg.CosPersistentState.YieldRef"); 142 method.addParameter(param); 143 method.getImpl().setMacro("GET_METHOD"); 144 method.getImpl().addContextValue("var", mapStateName()); 145 obj.addMethod(method); 146 147 method = new MethodObjectImpl(); 149 method.addComment("Get the "+state_.getName()+" value."); 150 method.addComment("Special for Hibernate"); 151 method.addComment("@return The "+state_.getName()+" value."); 152 method.setName( mapHibernateGetter() ); 153 method.setReturnType( translator.toJava(state_.getType()) ); 154 method.setFinal( finalAccessor ); 155 method.getImpl().setMacro("GET_METHOD"); 156 method.getImpl().addContextValue("var", mapStateName()); 157 obj.addMethod(method); 158 159 if (!state_.isReadonly()) 160 { 161 method = new MethodObjectImpl(); 163 method.addComment("Set the "+state_.getName()+" value."); 164 method.addComment(" "); 165 method.addComment("@param new_one - The value to set."); 166 method.setName( state_.getName() ); 167 method.setReturnType("void"); 168 method.setFinal( finalAccessor ); 169 param = new ParameterObjectImpl(); 170 param.setName("new_one"); 171 param.setType( translator.RefToJava(state_.getType()) ); 172 method.addParameter(param); 173 method.getImpl().setMacro("REF_SET_METHOD"); 174 method.getImpl().addContextValue("var", mapStateName()); 175 method.getImpl().addContextValue("value", "new_one"); 176 obj.addMethod(method); 177 178 method = new MethodObjectImpl(); 180 method.addComment("Set the "+state_.getName()+" value."); 181 method.addComment(" "); 182 method.addComment("@param new_one_ref - The value reference to set."); 183 method.setName( state_.getName() ); 184 method.setReturnType("void"); 185 method.setFinal( finalAccessor ); 186 param = new ParameterObjectImpl(); 187 param.setName("new_one_ref"); 188 param.setType( translator.toJava(state_.getType()) ); 189 method.addParameter(param); 190 method.getImpl().setMacro("SET_METHOD"); 191 method.getImpl().addContextValue("var", mapStateName()); 192 method.getImpl().addContextValue("value", "new_one_ref"); 193 obj.addMethod(method); 194 195 method = new MethodObjectImpl(); 197 method.addComment("Set the "+state_.getName()+" value."); 198 method.addComment("Special for Hibernate"); 199 method.addComment("@param new_one - The value to set."); 200 method.setName( mapHibernateSetter() ); 201 method.setReturnType("void"); 202 method.setFinal( finalAccessor ); 203 param = new ParameterObjectImpl(); 204 param.setName("new_one"); 205 param.setType( translator.toJava(state_.getType()) ); 206 method.addParameter(param); 207 method.getImpl().setMacro("SET_METHOD"); 208 method.getImpl().addContextValue("var", mapStateName()); 209 method.getImpl().addContextValue("value", "new_one"); 210 obj.addMethod(method); 211 } 212 } 213 else 214 { 215 method = new MethodObjectImpl(); 217 method.addComment("Get the "+state_.getName()+" value."); 218 method.addComment(" "); 219 method.addComment("@return The "+state_.getName()+" value."); 220 method.setName( state_.getName() ); 221 method.setReturnType( translator.toJava(state_.getType()) ); 222 method.setFinal( finalAccessor ); 223 method.getImpl().setMacro("GET_METHOD"); 224 method.getImpl().addContextValue("var", mapStateName()); 225 obj.addMethod(method); 226 227 method = new MethodObjectImpl(); 229 method.addComment("Get the "+state_.getName()+" value."); 230 method.addComment("Special for Hibernate"); 231 method.addComment("@return The "+state_.getName()+" value."); 232 method.setName( mapHibernateGetter() ); 233 method.setReturnType( translator.toJava(state_.getType()) ); 234 method.setFinal( finalAccessor ); 235 method.getImpl().setMacro("GET_METHOD"); 236 method.getImpl().addContextValue("var", mapStateName()); 237 obj.addMethod(method); 238 239 if (!state_.isReadonly()) 240 { 241 method = new MethodObjectImpl(); 243 method.addComment("Set the "+state_.getName()+" value."); 244 method.addComment(" "); 245 method.addComment("@param new_one - The value to set."); 246 method.setName( state_.getName() ); 247 method.setReturnType("void"); 248 method.setFinal( finalAccessor ); 249 param = new ParameterObjectImpl(); 250 param.setName("new_one"); 251 param.setType( translator.toJava(state_.getType()) ); 252 method.addParameter(param); 253 method.getImpl().setMacro("SET_METHOD"); 254 method.getImpl().addContextValue("var", mapStateName()); 255 method.getImpl().addContextValue("value", "new_one"); 256 obj.addMethod(method); 257 258 method = new MethodObjectImpl(); 260 method.addComment("Set the "+state_.getName()+" value."); 261 method.addComment("Special for Hibernate"); 262 method.addComment("@param new_one - The value to set."); 263 method.setName( mapHibernateSetter() ); 264 method.setReturnType("void"); 265 method.setFinal( finalAccessor ); 266 param = new ParameterObjectImpl(); 267 param.setName("new_one"); 268 param.setType( translator.toJava(state_.getType()) ); 269 method.addParameter(param); 270 method.getImpl().setMacro("SET_METHOD"); 271 method.getImpl().addContextValue("var", mapStateName()); 272 method.getImpl().addContextValue("value", "new_one"); 273 obj.addMethod(method); 274 275 if ( !PSDLTools.isImmutable(state_.getType()) 276 && !PSDLTools.isAbstractStorageType(state_.getType()) ) 277 { 278 method = new MethodObjectImpl(); 280 method.addComment("Update the "+state_.getName()+" value."); 281 method.addComment(" "); 282 method.addComment("@param fu - ForUpdate."); 283 method.setName( state_.getName() ); 284 method.setReturnType( translator.toJava(state_.getType()) ); 285 method.setFinal( finalAccessor ); 286 param = new ParameterObjectImpl(); 287 param.setName("fu"); 288 param.setType("org.omg.CosPersistentState.ForUpdate"); 289 method.addParameter(param); 290 method.getImpl().setMacro("GET_UPDATE_METHOD"); 291 method.getImpl().addContextValue("var", mapStateName()); 292 obj.addMethod(method); 293 } 294 } 295 } 296 } 297 298 } 299 | Popular Tags |