View Javadoc

1   package org.paneris.bibliomania;
2   
3   import java.util.Enumeration;
4   
5   import org.melati.Melati;
6   import org.melati.admin.AdminSpecialised;
7   import org.melati.poem.CachedSelection;
8   import org.melati.poem.CachedTailoredQuery;
9   import org.melati.poem.Column;
10  import org.melati.poem.Table;
11  import org.melati.template.MarkupLanguage;
12  import org.melati.poem.util.ArrayUtils;
13  import org.melati.poem.util.EmptyEnumeration;
14  import org.melati.poem.util.MappedEnumeration;
15  import org.melati.poem.Treeable;
16  import org.paneris.bibliomania.generated.SectionGroupBase;
17  
18  public class SectionGroup
19    extends SectionGroupBase
20    implements AdminSpecialised {
21  
22    public SectionGroup() {
23    }
24  
25    private CachedSelection sections = null;
26  
27    private boolean generic() {
28      Boolean genericL = getGeneric();
29      return genericL != null && genericL.booleanValue();
30    }
31  
32    public Enumeration getSections() {
33      if (getTroid() == null)
34        return new EmptyEnumeration();
35  
36      if (generic())
37        return getBibliomaniaDatabase().getSectionTable().selection();
38  
39      if (sections == null)
40        sections =
41          getBibliomaniaDatabase()
42            .getSectionTable()
43            .getGroupColumn()
44            .cachedSelectionWhereEq(troid());
45  
46      return sections.objects();
47    }
48  
49    public Enumeration getProductAssociations() {
50      return new EmptyEnumeration();
51    }
52  
53    public String getMetatag_description() {
54      return null;
55    }
56  
57    public String getMetatag_keywords() {
58      return null;
59    }
60  
61    public Enumeration getMembersSlowly() {
62      return getSections();
63    }
64  
65    public Unit getParentUnit() {
66      return null;
67    }
68  
69    public String getDisplayName() {
70      return getDisplayname();
71    }
72  
73    public void appendCacheSubpath(StringBuffer buffer) {
74      buffer.append("/g/");
75      buffer.append(troid());
76    }
77  
78    public boolean contains(Section section) {
79      return generic() || section.getGroup() == this;
80    }
81  
82    /**
83     * FIXME
84     */
85  
86    public long ftiTextID_start() {
87      return 0;
88    }
89  
90    /**
91     * FIXME
92     */
93  
94    public long ftiTextID_limit() {
95      return Long.MAX_VALUE;
96    }
97  
98    private CachedTailoredQuery authorsWithBooks = null;
99  
100   public Enumeration getAuthorsWithBooks() {
101     BibliomaniaDatabase b = getBibliomaniaDatabase();
102 
103     if (generic())
104       return b.getAuthorTable().selection();
105 
106     if (authorsWithBooks == null) {
107       authorsWithBooks =
108         new CachedTailoredQuery(
109           "DISTINCT",
110           new Column[] { b.getAuthorTable().troidColumn()},
111           new Table[] { b.getBookTable(), b.getSectionTable()},
112           "book.author = author.id AND book.section = section.id AND "
113             + "section.\"group\" = "
114             + troid(),
115           null);
116     }
117 
118     final Table authorTable = b.getAuthorTable();
119     return new MappedEnumeration(authorsWithBooks.selection_firstRaw()) {
120       public Object mapped(Object troid) {
121         return authorTable.getObject((Integer)troid);
122       }
123     };
124   }
125 
126   public SectionGroup getReadArea() {
127     return this;
128   }
129 
130   public Advert getAdvert() {
131     Advert a = null;
132     return a;
133   }
134   public Layout getLayout() {
135     Layout l = null;
136     return l;
137   }
138 
139   public String adminHandle(
140     Melati melatiContext,
141     MarkupLanguage markupLanguage)
142     throws Exception {
143     return null;
144   }
145 
146   public String adminSpecialFacilities(
147     Melati melatiContext,
148     MarkupLanguage markupLanguage)
149     throws Exception {
150     return getBibliomaniaDatabase().getWMTemplet("SectionGroup-specials");
151   }
152   
153   /* 
154    * @see org.melati.util.Treeable#getChildren()
155    */
156    public Treeable[] children = null;
157    
158    public Treeable[] getChildren() {
159      if (children == null) {
160        Object[] kids = ArrayUtils.arrayOf(getSections());
161        children = new Treeable[kids.length];
162        for (int i=0; i<kids.length; i++) {
163          children[i] = (Treeable)kids[i];
164        }
165      }
166      return children;
167    }
168   /* 
169    * @see org.melati.util.Treeable#getName()
170    */
171   public String getName() {
172     return getDisplayName();
173   }
174 
175 
176 }