1 23 24 package org.objectweb.jorm.mapper.fos.generator; 25 26 import org.apache.velocity.context.Context; 27 28 import org.objectweb.jorm.generator.api.MOP; 29 import org.objectweb.jorm.generator.lib.CommonGenerator; 30 import org.objectweb.jorm.type.api.PType; 31 import org.objectweb.jorm.util.api.Loggable; 32 import org.objectweb.jorm.metainfo.api.Class; 33 import org.objectweb.jorm.api.PException; 34 import org.objectweb.util.monolog.api.Logger; 35 import org.objectweb.util.monolog.api.LoggerFactory; 36 37 40 public class FosBindingMOP implements MOP, Loggable { 41 protected Logger logger = null; 42 protected LoggerFactory loggerFactory = null; 43 44 public void initContext(Context ctx, Class clazz, 45 String projectName, 46 String mapperName) throws PException { 47 ctx.put("bindingMOPTools", this); 48 } 49 50 public String [] getTemplateLibraries() { 51 String [] libs = {CommonGenerator.MAPPER_TEMPLATE_DIR + "fos/generator/FosBinding.vm"}; 52 return libs; 53 } 54 55 public String getSerRead(PType type) 56 throws Exception { 57 return "read" + getSer(type); 58 } 59 60 public String getSerWrite(PType type) 61 throws Exception { 62 return "write" + getSer(type); 63 } 64 65 private String getSer(PType type) { 66 switch (type.getTypeCode()) { 67 case PType.TYPECODE_BOOLEAN: 68 return "Boolean"; 69 case PType.TYPECODE_BYTE: 70 return "Byte"; 71 case PType.TYPECODE_CHAR: 72 return "Char"; 73 case PType.TYPECODE_DOUBLE: 74 return "Double"; 75 case PType.TYPECODE_FLOAT: 76 return "Float"; 77 case PType.TYPECODE_INT: 78 return "Int"; 79 case PType.TYPECODE_LONG: 80 return "Long"; 81 case PType.TYPECODE_SHORT: 82 return "Short"; 83 default: 84 return "Object"; 85 } 86 } 87 88 public String getSerObjectCast(PType type) { 89 switch (type.getTypeCode()) { 90 case PType.TYPECODE_OBJBOOLEAN: 91 return "(Boolean) "; 92 case PType.TYPECODE_OBJBYTE: 93 return "(Byte) "; 94 case PType.TYPECODE_OBJCHAR: 95 return "(Character) "; 96 case PType.TYPECODE_OBJDOUBLE: 97 return "(Double) "; 98 case PType.TYPECODE_OBJFLOAT: 99 return "(Float) "; 100 case PType.TYPECODE_OBJINT: 101 return "(Integer) "; 102 case PType.TYPECODE_OBJLONG: 103 return "(Long) "; 104 case PType.TYPECODE_OBJSHORT: 105 return "(Short) "; 106 case PType.TYPECODE_STRING: 107 return "(String) "; 108 case PType.TYPECODE_DATE: 109 return "(Date) "; 110 case PType.TYPECODE_SERIALIZED: 111 return "(java.io.Serializable) "; 112 case PType.TYPECODE_BIGDECIMAL: 113 return "(java.math.BigDecimal) "; 114 case PType.TYPECODE_BYTEARRAY: 115 return "(byte[]) "; 116 case PType.TYPECODE_CHARARRAY: 117 return "(char[]) "; 118 default: 119 return ""; 120 } 121 } 122 123 125 public Logger getLogger() { 126 return logger; 127 } 128 129 public LoggerFactory getLoggerFactory() { 130 return loggerFactory; 131 } 132 133 public void setLogger(Logger l) { 134 logger = l; 135 } 136 137 public void setLoggerFactory(LoggerFactory lf) { 138 loggerFactory = lf; 139 if (loggerFactory != null && logger == null) 140 loggerFactory.getLogger(getClass().getName()); 141 } 142 } 143 | Popular Tags |