001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (C) Alkacon Software (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.acacia.client.export;
029
030import org.opencms.acacia.shared.CmsEntity;
031
032import org.timepedia.exporter.client.Export;
033import org.timepedia.exporter.client.ExportPackage;
034import org.timepedia.exporter.client.Exportable;
035
036/**
037 * Exportable wrapper for entity instances.<p>
038 */
039@Export
040@ExportPackage(value = "acacia")
041public class CmsEntityWrapper implements Exportable {
042
043    /** The entity wrapped by this wrapper. */
044    private CmsEntity m_entity;
045
046    /**
047     * Default constructor.<p>
048     */
049    public CmsEntityWrapper() {
050
051    }
052
053    /**
054     * Wrapper constructor.<p>
055     *
056     * @param entity the entity to be wrapped
057     */
058    public CmsEntityWrapper(CmsEntity entity) {
059
060        m_entity = entity;
061    }
062
063    /**
064     * Wrapper method.<p>
065     *
066     * @param attributeName argument for the wrapped method
067     * @param value argument for the wrapped method
068     */
069    public void addAttributeValueEntity(String attributeName, CmsEntityWrapper value) {
070
071        m_entity.addAttributeValue(attributeName, value.getEntity());
072    }
073
074    /**
075     * Wrapper method.<p>
076     *
077     * @param attributeName argument for the wrapped method
078     * @param value argument for the wrapped method
079     */
080    public void addAttributeValueString(String attributeName, String value) {
081
082        m_entity.addAttributeValue(attributeName, value);
083    }
084
085    /**
086     * Wrapper method.<p>
087     *
088     * @param attributeName parameter for the wrapped method
089     * @return the result of the wrapped method
090     */
091    public CmsEntityAttributeWrapper getAttribute(String attributeName) {
092
093        return new CmsEntityAttributeWrapper(m_entity.getAttribute(attributeName));
094    }
095
096    /**
097     * Wrapper method.<p>
098     *
099     * @return the result of the wrapped method
100     */
101    public CmsEntityAttributeWrapper[] getAttributes() {
102
103        return CmsWrapperUtils.arrayFromEntityAttributeList(m_entity.getAttributes());
104    }
105
106    /**
107     * Gets the wrapped entity.<p>
108     *
109     * @return the wrapped entity
110     */
111    public CmsEntity getEntity() {
112
113        return m_entity;
114    }
115
116    /**
117     * Wrapper method.<p>
118     *
119     * @return the result of the wrapped method
120     */
121    public String getId() {
122
123        return m_entity.getId();
124    }
125
126    /**
127     * Wrapper method.<p>
128     *
129     * @return the result of the wrapped method
130     */
131    public String getTypeName() {
132
133        return m_entity.getTypeName();
134    }
135
136    /**
137     * Wrapper method.<p>
138     *
139     * @param attributeName parameter for the wrapped method
140     * @return the result of the wrapped method
141     */
142    public boolean hasAttribute(String attributeName) {
143
144        return m_entity.hasAttribute(attributeName);
145    }
146
147    /**
148     * Wrapper method.<p>
149     *
150     * @param attributeName parameter for the wrapped method
151     * @param value parameter for the wrapped method
152     * @param index parameter for the wrapped method
153     */
154    public void insertAttributeValueEntity(String attributeName, CmsEntityWrapper value, int index) {
155
156        m_entity.insertAttributeValue(attributeName, value.getEntity(), index);
157    }
158
159    /**
160     * Wrapper method.<p>
161     *
162     * @param attributeName parameter for the wrapped method
163     * @param value parameter for the wrapped method
164     * @param index parameter for the wrapped method
165     */
166    public void insertAttributeValueString(String attributeName, String value, int index) {
167
168        m_entity.insertAttributeValue(attributeName, value, index);
169    }
170
171    /**
172     * Wrapper method.<p>
173     *
174     * @param attributeName parameter for the wrapped method
175     */
176    public void removeAttribute(String attributeName) {
177
178        m_entity.removeAttribute(attributeName);
179    }
180
181    /**
182     * Wrapper method.<p>
183     *
184     * @param attributeName parameter for the wrapped method
185     */
186    public void removeAttributeSilent(String attributeName) {
187
188        m_entity.removeAttributeSilent(attributeName);
189    }
190
191    /**
192     * Wrapper method.<p>
193     *
194     * @param attributeName parameter for the wrapped method
195     * @param index parameter for the wrapped method
196     */
197    public void removeAttributeValue(String attributeName, int index) {
198
199        m_entity.removeAttributeValue(attributeName, index);
200    }
201
202    /**
203     * Wrapper method.<p>
204     *
205     * @param attributeName parameter for the wrapped method
206     * @param value parameter for the wrapped method
207     */
208    public void setAttributeValueEntity(String attributeName, CmsEntityWrapper value) {
209
210        m_entity.setAttributeValue(attributeName, value.getEntity());
211    }
212
213    /**
214    public void setAttributeValueEntity(String attributeName, CmsEntityWrapper value, int index) {
215    
216        m_entity.setAttributeValue(attributeName, value.getEntity(), index);
217    }
218    
219    public void setAttributeValueString(String attributeName, String value) {
220    
221        m_entity.setAttributeValue(attributeName, value);
222    }
223    
224    /**
225     * Wrapper method.<p>
226     *
227     * @param attributeName parameter for the wrapped method
228     * @param value parameter for the wrapped method
229     * @param index parameter for the wrapped method
230     */
231    public void setAttributeValueString(String attributeName, String value, int index) {
232
233        m_entity.setAttributeValue(attributeName, value, index);
234    }
235
236    /**
237     * Sets the wrapped entity.<p>
238     *
239     * @param entity the entity to wrap
240     */
241    public void setEntity(CmsEntity entity) {
242
243        m_entity = entity;
244    }
245
246    /**
247     * Wrapper method.<p>
248     *
249     * @return the result of the wrapped method
250     */
251    public String toJSON() {
252
253        return m_entity.toJSON();
254    }
255}