1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 31 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl; 32 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 33 34 import org.objectweb.openccm.generator.java.ast.api.*; 35 import org.objectweb.openccm.generator.java.ast.lib.*; 36 37 import org.objectweb.openccm.generator.common.lib.GenerationException; 38 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator; 39 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator; 40 41 42 49 public class StateMemberMapping 50 implements org.objectweb.openccm.pss.generator.common.api.StateMemberMapping 51 { 52 53 59 60 protected StorageTypeStateMemberDecl state_; 61 62 68 71 public StateMemberMapping() 72 { 73 state_ = null; 75 } 76 77 83 89 94 public void 95 setStateMember(StorageTypeStateMemberDecl state) 96 { 97 state_ = state; 98 } 99 100 105 public String 106 mapStateName() 107 { 108 return mapStateName( state_.getName() ); 109 } 110 111 116 protected String 117 mapMarshalledStateName() 118 { 119 return mapMarshalledStateName( state_.getName() ); 120 } 121 122 129 public void 130 toJavaAccessors( PSDL_JavaTranslator translator, 131 InterfaceObject obj, 132 boolean finalAccessor ) 133 { 134 } 136 137 143 public void 144 toJavaReadOnlyStateMemberModifier( PSDL_JavaTranslator translator, 145 ClassObject clazz ) 146 { 147 MethodObject method = null; 148 ParameterObject param = null; 149 150 method = new MethodObjectImpl(); 151 method.addComment("Set the "+state_.getName()+" value."); 152 method.addComment(" "); 153 method.addComment("@param initial_value - The value to set."); 154 method.setName( "set_" + state_.getName() ); 155 method.setReturnType("void"); 156 method.setFinal(true); 157 param = new ParameterObjectImpl(); 158 param.setName("initial_value"); 159 param.setType( translator.toJava(state_.getType()) ); 160 method.addParameter(param); 161 method.getImpl().setMacro("SET_METHOD"); 162 method.getImpl().addContextValue("var", mapStateName()); 163 method.getImpl().addContextValue("value", "initial_value"); 164 clazz.addMethod(method); 165 } 166 167 174 public void 175 toJavaAttribute(PSDL_JavaTranslator translator, 176 ClassObject clazz, 177 org.objectweb.openccm.ast.api.StorageTypeDecl st) 178 { 179 AttributeObject att = null; 180 String marshalled_type = null; 181 182 att = new AttributeObjectImpl(); 183 att.addComment("The "+state_.getName()+" state."); 184 att.setName( mapStateName() ); 185 att.setType( translator.toJava(state_.getType()) ); 186 att.setModifier( ModifierKindImpl.mk_private ); 187 clazz.addAttribute(att); 188 189 marshalled_type = PSDLMappingTools.getMarshalledType(st, state_); 191 if (marshalled_type != null) 192 { 193 att = new AttributeObjectImpl(); 195 att.addComment("The " + state_.getName() + " marshalled state."); 196 att.setName( mapMarshalledStateName() ); 197 att.setType(marshalled_type); 198 att.setModifier( ModifierKindImpl.mk_private ); 199 clazz.addAttribute(att); 200 } 201 } 202 203 209 public void 210 toJavaParameter( PSDL_JavaTranslator translator, 211 MethodObject method ) 212 { 213 ParameterObject param = null; 214 215 param = new ParameterObjectImpl(); 217 param.setName( state_.getName() ); 218 param.setType( translator.toJava(state_.getType()) ); 219 method.addParameter(param); 220 } 221 222 230 public static void 231 mapStateListToParameters( PSDL2JavaGenerator generator, 232 String [] states, 233 MethodObject method, 234 AbstractStorageTypeDecl ast ) 235 throws GenerationException 236 { 237 StorageTypeStateMemberDecl state = null; 238 ParameterObject param = null; 239 240 for (int i=0; i<states.length; i++) 241 { 242 state = (StorageTypeStateMemberDecl)generator.getDeclaration(ast, states[i]); 244 245 if (state == null) 246 { 247 AbstractStorageTypeDecl[] implemented = null; 248 249 implemented = ast.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 251 if (implemented.length > 0) 252 { 253 int j = 0; 254 while( (j<implemented.length) && (state == null) ) 255 { 256 state = (StorageTypeStateMemberDecl)generator.getDeclaration(implemented[j], states[i]); 257 j++; 258 } 259 } 260 if (state == null) 261 { 262 String msg = "State Member '"+states[i]+"' not found!"; 263 throw new GenerationException(msg); 264 } 265 } 266 267 org.objectweb.openccm.pss.generator.common.api.StateMemberMapping smm 269 = new StateMemberMapping(); 270 smm.setStateMember(state); 271 smm.toJavaParameter(generator.getTranslator(), method); 272 } 273 } 274 275 282 public static String 283 mapStateName(String name) 284 { 285 return name + "_state"; 286 } 287 288 295 public static String 296 mapMarshalledStateName(String name) 297 { 298 return name + "_marshalled"; 299 } 300 } 301 | Popular Tags |