1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 31 import org.objectweb.openccm.ast.api.StorageHomeKeyDecl; 32 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 33 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl; 34 35 import org.objectweb.openccm.generator.java.ast.api.*; 36 import org.objectweb.openccm.generator.java.ast.lib.*; 37 38 import org.objectweb.openccm.generator.common.lib.GenerationException; 39 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator; 40 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator; 41 42 43 50 public class PSDLKeyMapping 51 implements org.objectweb.openccm.pss.generator.common.api.PSDLKeyMapping 52 { 53 54 60 61 private StorageHomeKeyDecl key_; 62 63 69 72 73 public PSDLKeyMapping() 74 { 75 key_ = null; 77 } 78 79 85 92 protected void 93 mapFactoryParameters( PSDL_JavaTranslator translator, 94 AbstractStorageTypeDecl ast, 95 MethodObject method ) 96 { 97 String [] members = null, 98 members_type = null, 99 states_name = null; 100 StorageTypeStateMemberDecl sm = null; 101 org.objectweb.openccm.ast.api.StorageTypeDecl st = null; 102 103 members = key_.getMemberList().getStrings(); 104 members_type = new java.lang.String [members.length]; 105 states_name = new java.lang.String [members.length]; 106 try{ 107 st = (org.objectweb.openccm.ast.api.StorageTypeDecl) ast; 108 }catch(java.lang.ClassCastException ex){ 109 st = null; 110 } 111 for (int i=0; i<members.length; i++) 112 { 113 sm = ast.getState(members[i]); 115 members_type[i] = translator.toJava( sm.getType() ); 116 states_name[i] = StateMemberMapping.mapStateName( members[i] ); 117 if (st == null) 118 { 119 if ( PSDLMappingTools.getMarshalledType(st, sm) != null) 120 states_name[i] = StateMemberMapping.mapMarshalledStateName( members[i] ); 121 } 122 } 123 method.getImpl().addContextValue("fields_names", members); 124 method.getImpl().addContextValue("states_names", states_name); 125 method.getImpl().addContextValue("fields_types", members_type); 126 method.getImpl().addContextValue("nb", new Integer (members.length) ); 127 } 128 129 135 140 public void 141 setKey(StorageHomeKeyDecl key) 142 { 143 key_ = key; 144 } 145 146 153 public void 154 toJava(PSDL2JavaGenerator generator, 155 InterfaceObject obj, 156 AbstractStorageTypeDecl ast) 157 throws GenerationException 158 { 159 MethodObject method = null; 160 161 method = new MethodObjectImpl(); 163 method.addComment("The find_by_"+key_.getName()+" method."); 164 method.setName("find_by_"+key_.getName()); 165 method.setReturnType( generator.getTranslator().getAbsoluteName(ast) ); 166 StateMemberMapping.mapStateListToParameters 167 ( generator, 168 key_.getMemberList().getStrings(), 169 method, 170 ast ); 171 method.addException("org.omg.CosPersistentState.NotFound"); 172 method.getImpl().setMacro("SH_KEY_FIND_BY"); 173 mapFactoryParameters(generator.getTranslator(), ast, method); 174 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(ast)); 175 obj.addMethod(method); 176 177 method = new MethodObjectImpl(); 179 method.addComment("The find_ref_by_"+key_.getName()+" method."); 180 method.setName("find_ref_by_"+key_.getName()); 181 method.setReturnType("byte[]"); 182 StateMemberMapping.mapStateListToParameters 183 ( generator, 184 key_.getMemberList().getStrings(), 185 method, 186 ast ); 187 mapFactoryParameters(generator.getTranslator(), ast, method); 188 method.getImpl().setMacro("SH_KEY_FIND_REF_BY"); 189 method.getImpl().addContextValue("key_name", key_.getName()); 190 obj.addMethod(method); 191 } 192 193 } 194 | Popular Tags |