KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > SlicerBuilderImpl


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.table;
14
15 import java.util.ArrayList JavaDoc;
16 import java.util.List JavaDoc;
17
18 import org.w3c.dom.Element JavaDoc;
19
20 import com.tonbeller.jpivot.olap.model.Member;
21 import com.tonbeller.jpivot.olap.model.Property;
22 import com.tonbeller.jpivot.olap.navi.MemberProperties;
23 import com.tonbeller.jpivot.table.span.PropertyConfig;
24 import com.tonbeller.jpivot.table.span.PropertyUtils;
25 import com.tonbeller.jpivot.table.span.ScopedPropertyMetaSet;
26 import com.tonbeller.wcf.controller.RequestContext;
27
28 /**
29  * creates a DOM Element from slicer member
30  *
31  * @author av
32  */

33 public class SlicerBuilderImpl extends PartBuilderSupport implements SlicerBuilder {
34   
35   ScopedPropertyMetaSet visible;
36   MemberProperties extension;
37   PropertyConfig propertyConfig;
38   
39   public void startBuild(RequestContext context) {
40     propertyConfig = table.getPropertyConfig();
41     
42     extension = getExtension();
43     if (extension == null) {
44       // we can not handle individual visible properties w/o the extension
45
visible = null;
46       return;
47     }
48
49     List JavaDoc list = propertyConfig.getVisiblePropertyMetas();
50     if (list == null) {
51       visible = null;
52       return;
53     }
54     visible = new ScopedPropertyMetaSet(extension);
55     visible.addAll(list);
56   }
57
58   public void stopBuild() {
59     visible = null;
60     extension = null;
61     propertyConfig = null;
62   }
63
64   public Element JavaDoc build(Member m) {
65     Element JavaDoc e = table.elem("member");
66     e.setAttribute("level", m.getLevel().getLabel());
67     e.setAttribute("caption", m.getLabel());
68     e.setAttribute("depth", Integer.toString(m.getRootDistance()));
69     addMemberProperties(e, m);
70     return e;
71   }
72
73   private void addMemberProperties(Element JavaDoc e, Member m) {
74     if (!propertyConfig.isShowProperties())
75       return;
76
77     Property[] props = visibleProperties(m);
78     PropertyUtils.addProperties(e, props);
79   }
80
81   private Property[] visibleProperties(Member m) {
82     Property[] src = m.getProperties();
83     String JavaDoc scope = null;
84     if (extension != null)
85       scope = extension.getPropertyScope(m);
86     List JavaDoc list = new ArrayList JavaDoc();
87     for (int i = 0; i < src.length; i++) {
88       Property p = src[i];
89       if (PropertyUtils.isInline(p.getName()))
90         continue;
91       if (scope != null && visible != null) {
92         if (visible.contains(scope, p.getName()))
93             list.add(p);
94       }
95       else
96         list.add(p);
97     }
98     return (Property[])list.toArray(new Property[list.size()]);
99   }
100   
101   MemberProperties getExtension() {
102     return (MemberProperties) table.getOlapModel().getExtension(MemberProperties.ID);
103   }
104   
105   public boolean isAvailable() {
106     return getExtension() != null;
107   }
108   
109 }
Popular Tags