1 2 12 package com.versant.core.metadata.parser; 13 14 import com.versant.core.metadata.MDStaticUtils; 15 import com.versant.core.common.Debug; 16 import com.versant.core.common.BindingSupportImpl; 17 18 import java.io.PrintStream ; 19 import java.util.Collections ; 20 21 24 public final class JdoMap extends JdoElement { 25 26 public String keyType; 27 public int embeddedKey; 28 public String valueType; 29 public int embeddedValue; 30 public JdoExtension[] extensions; 31 public JdoField parent; 32 33 public JdoElement getParent() { return parent; } 34 35 40 public String getSubContext() { 41 return "map"; 42 } 43 44 public String toString() { 45 StringBuffer s = new StringBuffer (); 46 s.append("map keyType="); 47 s.append(keyType); 48 s.append(" embeddedKey="); 49 s.append(MDStaticUtils.toTriStateString(embeddedKey)); 50 s.append(" valueType="); 51 s.append(valueType); 52 s.append(" embeddedValue="); 53 s.append(MDStaticUtils.toTriStateString(embeddedValue)); 54 return s.toString(); 55 } 56 57 public void dump() { 58 dump(Debug.OUT, ""); 59 } 60 61 public void dump(PrintStream out, String indent) { 62 out.println(indent + this); 63 String is = indent + " "; 64 if (extensions != null) { 65 for (int i = 0; i < extensions.length; i++) { 66 extensions[i].dump(out, is); 67 } 68 } 69 } 70 71 74 public String getValueTypeQName() { 75 return getQName(valueType); 76 } 77 78 81 public String getKeyTypeQName() { 82 return getQName(keyType); 83 } 84 85 private String getQName(String n) { 86 if (n == null) return null; 87 int i = n.indexOf('.'); 88 if (i >= 0) return n; 89 String packageName = parent.parent.parent.name; 90 if (packageName.length() == 0) return n; 91 return packageName + '.' + n; 92 } 93 94 public JdoMap createCopy(JdoField field) { 95 JdoMap tmp = new JdoMap(); 96 tmp.parent = field; 97 tmp.keyType = keyType; 98 tmp.embeddedKey = embeddedKey; 99 tmp.valueType = valueType; 100 tmp.embeddedValue = embeddedValue; 101 102 if (extensions != null) { 103 tmp.extensions = new JdoExtension[extensions.length]; 104 for (int i = 0; i < extensions.length; i++) { 105 tmp.extensions[i] = extensions[i].createCopy(tmp); 106 } 107 } 108 return tmp; 109 } 110 111 114 public void synchronizeForHorizontal(JdoMap map) { 115 if (!valueType.equals(map.valueType) || !keyType.equals(map.keyType)) { 116 throw BindingSupportImpl.getInstance().invalidOperation( 117 "May not override the key of value type of map. " + 118 "\nUpdated: " + this + "\nOriginal: " + map); 119 } 120 121 if (map.extensions != null) { 122 JdoExtension[] copy = new JdoExtension[map.extensions.length]; 123 for (int i = 0; i < map.extensions.length; i++) { 124 copy[i] = map.extensions[i].createCopy(this); 125 } 126 if (extensions != null) { 127 JdoExtension.synchronize3(extensions, copy, Collections.EMPTY_SET, false); 128 } else { 129 extensions = copy; 130 } 131 } 132 } 133 } 134 135 | Popular Tags |