1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 31 import org.objectweb.openccm.ast.api.StorageHomeFactoryDecl; 32 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 33 import org.objectweb.openccm.ast.api.StorageTypeDecl; 34 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl; 35 36 import org.objectweb.openccm.generator.java.ast.api.*; 37 import org.objectweb.openccm.generator.java.ast.lib.*; 38 39 import org.objectweb.openccm.generator.common.lib.GenerationException; 40 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator; 41 42 43 50 public class PSDLFactoryMapping 51 implements org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping 52 { 53 54 60 61 private StorageHomeFactoryDecl factory_; 62 63 69 72 73 public PSDLFactoryMapping() 74 { 75 factory_ = null; 77 } 78 79 85 91 96 public void 97 setFactory(StorageHomeFactoryDecl factory) 98 { 99 factory_ = factory; 100 } 101 102 110 public void 111 toJava(PSDL2JavaGenerator generator, 112 InterfaceObject obj, 113 AbstractStorageTypeDecl ast, 114 StorageTypeDecl st) 115 throws GenerationException 116 { 117 MethodObject method = null; 118 String [] states = null; 119 120 method = new MethodObjectImpl(); 121 method.addComment("The " + factory_.getName() + " factory."); 122 method.setName(factory_.getName()); 123 method.setReturnType( generator.getTranslator().getAbsoluteName(ast) ); 124 states = factory_.getMemberList().getStrings(); 125 StateMemberMapping.mapStateListToParameters 126 ( generator, 127 states, 128 method, 129 ast ); 130 obj.addMethod(method); 131 132 if (st != null) 133 { 134 StorageTypeStateMemberDecl state = null; 135 java.util.List states_list = new java.util.ArrayList (); 136 for (int i=0; i<states.length; i++) 137 { 138 state = (StorageTypeStateMemberDecl)generator.getDeclaration(ast, states[i]); 140 141 if (state == null) 142 { 143 AbstractStorageTypeDecl[] implemented = null; 144 145 implemented = ast.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes(); 147 if(implemented.length > 0) 148 { 149 int j = 0; 150 while( (j<implemented.length) && (state == null) ) 151 { 152 state = (StorageTypeStateMemberDecl)generator.getDeclaration(implemented[j], states[i]); 153 j++; 154 } 155 } 156 if (state == null) 157 { 158 String msg = "State Member '"+states[i]+"' not found!"; 159 throw new GenerationException(msg); 160 } 161 } 162 states_list.add(state); 163 } 164 method.getImpl().setMacro("SH_CREATE1_METHOD"); 165 method.getImpl().addContextValue("states", states_list); 166 method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(st)); 167 } 168 } 169 } 170 | Popular Tags |