1 23 24 package org.objectweb.jorm.mapper.rdb.metainfo; 25 26 import org.objectweb.jorm.metainfo.api.Class; 27 import org.objectweb.jorm.metainfo.api.ClassMapping; 28 import org.objectweb.jorm.metainfo.api.ClassProject; 29 import org.objectweb.jorm.metainfo.api.GenClassRef; 30 import org.objectweb.jorm.metainfo.api.Mapping; 31 import org.objectweb.jorm.metainfo.api.MetaObject; 32 import org.objectweb.jorm.metainfo.api.ParentClassMapping; 33 import org.objectweb.jorm.metainfo.lib.BasicMapping; 34 import org.objectweb.util.monolog.api.BasicLevel; 35 36 import java.util.Collection ; 37 import java.util.Iterator ; 38 39 40 41 44 public class RdbMapping extends BasicMapping { 45 52 public RdbMapping(String mapperName, MetaObject parent) { 53 super(mapperName, parent); 54 } 55 56 60 69 public ClassMapping createClassMapping(String ruleName) { 70 return createClassMultiMapping(ruleName); 71 } 72 73 80 public RdbClassMultiMapping createClassMultiMapping(String ruleName) { 81 RdbClassMultiMapping res = (RdbClassMultiMapping) getClassMapping(); 82 if (res == null) { 83 res = new RdbClassMultiMapping( 84 ruleName, getParent().getParent(), this); 85 setClassMapping(res); 86 res.setLogger(logger); 87 } else { 88 res.setRuleName(ruleName); 89 } 90 return res; 91 } 92 93 101 public RdbGenClassMapping createGenClassMapping(String ruleName, 102 MetaObject linkedMO) { 103 String gcid = ((GenClassRef) linkedMO).getGenClassId(); 104 if (logger.isLoggable(BasicLevel.DEBUG)) { 105 logger.log(BasicLevel.DEBUG, 106 "(gcid " + gcid + ")"); 107 } 108 RdbGenClassMapping res = (RdbGenClassMapping) getGenClassMapping(gcid); 109 if (res == null) { 110 res = new RdbGenClassMapping(ruleName, linkedMO, this); 111 res.setLogger(logger); 112 addGenClassMapping(gcid, res); 113 } else { 114 res.setRuleName(ruleName); 115 res.setLinkedMO(linkedMO); 116 } 117 return res; 118 } 119 120 121 public boolean isFilteredMapping() { 122 boolean isFilteredMapping = isFilteredMapping(this); 124 if (!isFilteredMapping) { 126 Class clazz = (Class ) getClassMapping().getLinkedMO(); 127 Collection cs = clazz.getSubClasses(); 128 if (cs.isEmpty()) { 129 return false; 130 } 131 String proj = ((ClassProject) getParent()).getProjectName(); 132 for (Iterator it = cs.iterator(); it.hasNext() && !isFilteredMapping;) { 133 Mapping m = ((Class ) it.next()).getClassProject(proj) 134 .getMapping(getMapperName()); 135 isFilteredMapping = isFilteredMapping(m); 136 } 137 } 138 return isFilteredMapping; 139 } 140 141 private boolean isFilteredMapping(Mapping m) { 142 Collection pcms = m.getClassMapping().getParentClassMappings(); 143 if (pcms.isEmpty()) { 144 return false; 145 } 146 boolean isFilteredMapping = false; 147 for(Iterator it=pcms.iterator(); it.hasNext() && !isFilteredMapping;) { 148 ParentClassMapping pcm = (ParentClassMapping) it.next(); 149 isFilteredMapping = 150 RdbClassMapping.MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES 151 .equalsIgnoreCase(pcm.getRuleName()); 152 } 153 return isFilteredMapping; 154 } 155 156 } 157 | Popular Tags |