View Javadoc

1   /*
2    * ----------------------------------------------------------------------
3    * Copyright (C) 2009 Enrique Lara (k957@68k.org)
4    *
5    * TinLizard is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public License
7    * as published by the Free Software Foundation; either version 3.0
8    * of the License, or (at your option) any later version.
9    *
10   * TinLizard is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public License
16   * along with TinLizard. If not, see http://www.gnu.org/licenses/.
17   * ----------------------------------------------------------------------
18   */
19  package tinlizard.web;
20  
21  import tinlizard.model.CurrentUser;
22  
23  import tinlizard.util.Messages;
24  
25  import java.util.ArrayList;
26  import java.util.Collection;
27  import java.util.Date;
28  import java.util.Iterator;
29  
30  import org.jvnet.localizer.Localizable;
31  
32  /***
33   * Bass Class for Web Accessible Collections.
34   */
35  @SuppressWarnings("unchecked")
36  public abstract class ObjectCollectionWeb extends ObjectWeb<Collection<Object>> implements Collection<ObjectWeb> {
37      private final String name;
38      private final Collection<Object> subject;
39      private final Collection<ObjectWeb> delegate;
40      private final Date created;
41      private final String createdBy;
42  
43      /***
44       * @deprecated
45       */
46      ObjectCollectionWeb(final String name) {
47          this.name = name;
48          this.subject = new ArrayList<Object>();
49          this.delegate = new ArrayList<ObjectWeb>();
50          this.created = new Date();
51          this.createdBy = Messages.SYSTEM();
52      }
53  
54      ObjectCollectionWeb(final Localizable name) {
55          this.name = name.toString(CurrentUser.getLocale());
56          this.subject = new ArrayList<Object>();
57          this.delegate = new ArrayList<ObjectWeb>();
58          this.created = new Date();
59          this.createdBy = Messages.SYSTEM();
60      }
61  
62      @Override
63      public String getName() {
64          return name;
65      }
66  
67      @Override
68      protected final Collection<Object> getSubject() {
69          return subject;
70      }
71  
72      protected final Collection<ObjectWeb> getDelegate() {
73          return delegate;
74      }
75  
76      public final Date getCreated() {
77          return this.created;
78      }
79  
80      public final String getCreatedBy() {
81          return this.createdBy;
82      }
83  
84      public final Date getLastModified() {
85          return getCreated();
86      }
87  
88      public final String getLastModifiedBy() {
89          return getCreatedBy();
90      }
91  
92      public final boolean add(final ObjectWeb o) {
93          return delegate.add(o);
94      }
95  
96      public final boolean addAll(final Collection<?extends ObjectWeb> c) {
97          return delegate.addAll(c);
98      }
99  
100     public final void clear() {
101         delegate.clear();
102     }
103 
104     public final boolean contains(final Object o) {
105         return delegate.contains(o);
106     }
107 
108     public final boolean containsAll(final Collection<?> c) {
109         return delegate.containsAll(c);
110     }
111 
112     public final boolean isEmpty() {
113         return delegate.isEmpty();
114     }
115 
116     public final Iterator<ObjectWeb> iterator() {
117         return delegate.iterator();
118     }
119 
120     public final boolean remove(final Object o) {
121         return delegate.remove(o);
122     }
123 
124     public final boolean removeAll(final Collection<?> c) {
125         return delegate.removeAll(c);
126     }
127 
128     public final boolean retainAll(final Collection<?> c) {
129         return delegate.retainAll(c);
130     }
131 
132     public final int size() {
133         return delegate.size();
134     }
135 
136     public final Object[] toArray() {
137         return delegate.toArray();
138     }
139 
140     public final Object[] toArray(final Object[] a) {
141         return delegate.toArray(a);
142     }
143 }