KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > olap > mdxparse > CompoundId


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.olap.mdxparse;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17
18 /**
19  * can be any MDX object
20  */

21 public class CompoundId implements Exp {
22
23   private ArrayList JavaDoc names = new ArrayList JavaDoc();
24
25   /**
26    * c'tor
27    * @param name
28    * @param isKey
29    */

30   public CompoundId(String JavaDoc name, boolean isKey) {
31     names.add(new NamePart(name, isKey));
32   }
33
34   public CompoundId(String JavaDoc name) {
35     this(name, false);
36   }
37
38   public void append(String JavaDoc name, boolean isKey) {
39     names.add(new NamePart(name, isKey));
40   }
41
42   public void append(String JavaDoc name) {
43     names.add(new NamePart(name, false));
44   }
45
46   public String JavaDoc[] toStringArray() {
47     String JavaDoc[] ret = new String JavaDoc[names.size()];
48     int i = 0;
49     for (Iterator JavaDoc iter = names.iterator(); iter.hasNext();) {
50       NamePart np = (NamePart) iter.next();
51       ret[i++] = np.name;
52     }
53
54     return ret;
55   }
56
57   private class NamePart {
58     private String JavaDoc name;
59     private boolean isKey;
60     protected NamePart(String JavaDoc name, boolean isKey) {
61       this.name = name;
62       this.isKey = isKey;
63     }
64   }
65
66   /**
67    * format to MDX
68    * @see interface Exp
69    */

70   public String JavaDoc toMdx() {
71     String JavaDoc str = "";
72     boolean isFollow = false;
73     for (Iterator JavaDoc iter = names.iterator(); iter.hasNext();) {
74       NamePart np = (NamePart) iter.next();
75       if (isFollow)
76         str += ".";
77       isFollow = true;
78       str += np.name;
79     }
80
81     return str;
82   }
83   
84   private CompoundId(){
85     // default
86
}
87   
88   /**
89    *
90    * @see java.lang.Object#clone()
91    */

92   public Object JavaDoc clone() {
93     CompoundId cloned = new CompoundId();
94     for (Iterator JavaDoc iter = names.iterator(); iter.hasNext();) {
95       NamePart np = (NamePart) iter.next();
96       cloned.append(np.name, np.isKey);
97     }
98     return cloned;
99   }
100
101   /**
102    * @see com.tonbeller.jpivot.olap.mdxparse.Exp#accept
103    */

104   public void accept(ExpVisitor visitor) {
105     visitor.visitCompoundId(this);
106   }
107
108 } // End CompoundId
109

110
Popular Tags