KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > metadata > parser > JdoMap


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

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 JavaDoc;
19 import java.util.Collections JavaDoc;
20
21 /**
22  * Map element from a .jdo file.
23  */

24 public final class JdoMap extends JdoElement {
25
26     public String JavaDoc keyType;
27     public int embeddedKey;
28     public String JavaDoc valueType;
29     public int embeddedValue;
30     public JdoExtension[] extensions;
31     public JdoField parent;
32
33     public JdoElement getParent() { return parent; }
34
35     /**
36      * Get information for this element to be used in building up a
37      * context string.
38      * @see #getContext
39      */

40     public String JavaDoc getSubContext() {
41         return "map";
42     }
43
44     public String JavaDoc toString() {
45         StringBuffer JavaDoc s = new StringBuffer JavaDoc();
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 JavaDoc out, String JavaDoc indent) {
62         out.println(indent + this);
63         String JavaDoc 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     /**
72      * Get the fully qualified name of our value type (or null if none).
73      */

74     public String JavaDoc getValueTypeQName() {
75         return getQName(valueType);
76     }
77
78     /**
79      * Get the fully qualified name of our key type (or null if none).
80      */

81     public String JavaDoc getKeyTypeQName() {
82         return getQName(keyType);
83     }
84
85     private String JavaDoc getQName(String JavaDoc n) {
86         if (n == null) return null;
87         int i = n.indexOf('.');
88         if (i >= 0) return n;
89         String JavaDoc 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     /**
112      * May not update key of value types. Only columns may be renamed.
113      */

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