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 JdoCollection extends JdoElement { 25 26 public String elementType; 27 public int embeddedElement; 28 public JdoExtension[] extensions; 29 public JdoField parent; 30 31 public JdoElement getParent() { return parent; } 32 33 38 public String getSubContext() { 39 return "collection"; 40 } 41 42 public String toString() { 43 StringBuffer s = new StringBuffer (); 44 s.append("collection elementType="); 45 s.append(elementType); 46 s.append(" embeddedElement="); 47 s.append(MDStaticUtils.toTriStateString(embeddedElement)); 48 return s.toString(); 49 } 50 51 public void dump() { 52 dump(Debug.OUT, ""); 53 } 54 55 public void dump(PrintStream out, String indent) { 56 out.println(indent + this); 57 if (extensions != null) { 58 for (int i = 0; i < extensions.length; i++) { 59 extensions[i].dump(out, indent + " "); 60 } 61 } 62 } 63 64 67 public String getElementTypeQName() { 68 if (elementType == null) return null; 69 int i = elementType.indexOf('.'); 70 if (i >= 0) return elementType; 71 String packageName = parent.parent.parent.name; 72 if (packageName.length() == 0) return elementType; 73 return packageName + '.' + elementType; 74 } 75 76 public JdoCollection createCopy(JdoField parent) { 77 JdoCollection tmp = new JdoCollection(); 78 tmp.parent = parent; 79 tmp.elementType = elementType; 80 tmp.embeddedElement = embeddedElement; 81 82 if (extensions != null) { 83 tmp.extensions = new JdoExtension[extensions.length]; 84 for (int i = 0; i < extensions.length; i++) { 85 tmp.extensions[i] = extensions[i].createCopy(tmp); 86 } 87 } 88 return tmp; 89 } 90 91 94 public void synchronizeForHorizontal(JdoCollection col) { 95 if (!elementType.equals(col.elementType)) { 96 throw BindingSupportImpl.getInstance().invalidOperation( 97 "May not override the element type of collection. " + 98 "\nAttemptin to change 'element-type' from " 99 + col.elementType + " to " + elementType); 100 } 101 102 if (col.extensions != null) { 103 JdoExtension[] copy = new JdoExtension[col.extensions.length]; 104 for (int i = 0; i < col.extensions.length; i++) { 105 copy[i] = col.extensions[i].createCopy(this); 106 } 107 if (extensions != null) { 108 JdoExtension.synchronize3(extensions, copy, Collections.EMPTY_SET, false); 109 } else { 110 extensions = copy; 111 } 112 } 113 } 114 115 121 public JdoExtension findCreate(int key, String value, boolean overwrite) { 122 if (extensions == null) { 123 extensions = new JdoExtension[] {createChild(key, value, this)}; 124 return extensions[0]; 125 } 126 127 JdoExtension ext = JdoExtension.find(key, extensions); 128 if (ext == null) { 129 extensions = addExtension(extensions, (ext = createChild(key, value, this))); 130 } else if (overwrite) { 131 ext.value = value; 132 } 133 return ext; 134 } 135 } 136 137 | Popular Tags |