001: /*
002: * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
003: *
004: * This file is part of TransferCM.
005: *
006: * TransferCM is free software; you can redistribute it and/or modify it under the
007: * terms of the GNU General Public License as published by the Free Software
008: * Foundation; either version 2 of the License, or (at your option) any later
009: * version.
010: *
011: * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
012: * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
013: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
014: * details.
015: *
016: * You should have received a copy of the GNU General Public License along with
017: * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
018: * Fifth Floor, Boston, MA 02110-1301 USA
019: */
020:
021: package com.methodhead.shim;
022:
023: import com.methodhead.aikp.AutoIntKeyPersistable;
024:
025: import org.apache.commons.beanutils.DynaClass;
026: import org.apache.commons.beanutils.DynaProperty;
027: import org.apache.commons.beanutils.BasicDynaClass;
028: import com.methodhead.sitecontext.SiteContextCapable;
029: import com.methodhead.sitecontext.SiteContext;
030: import java.util.List;
031:
032: /**
033: * An HtmlFragment. The following fields are defined:
034: * <ul>
035: * <li><tt>int id = 0</tt></li>
036: * <li><tt>int sitecontext_id = 0</tt></li>
037: * <li><tt>String name = ""</tt></li>
038: * <li><tt>String value = ""</tt></li>
039: * </ul>
040: */
041: public class HtmlFragment extends AutoIntKeyPersistable implements
042: SiteContextCapable {
043:
044: private static DynaClass dynaClass_ = null;
045:
046: static {
047: DynaProperty[] dynaProperties = new DynaProperty[] {
048: new DynaProperty("id", Integer.class),
049: new DynaProperty("sitecontext_id", Integer.class),
050: new DynaProperty("name", String.class),
051: new DynaProperty("value", String.class) };
052:
053: dynaClass_ = new BasicDynaClass("shim_htmlfragment",
054: HtmlFragment.class, dynaProperties);
055: }
056:
057: // constructors /////////////////////////////////////////////////////////////
058:
059: public HtmlFragment() {
060: super (dynaClass_);
061: init();
062: }
063:
064: public HtmlFragment(DynaClass dynaClass) {
065: super (dynaClass);
066: init();
067: }
068:
069: // constants ////////////////////////////////////////////////////////////////
070:
071: // classes //////////////////////////////////////////////////////////////////
072:
073: // methods //////////////////////////////////////////////////////////////////
074:
075: protected void init() {
076: setInt("id", 0);
077: setInt("sitecontext_id", 0);
078: setString("name", "");
079: setString("value", "");
080: }
081:
082: public SiteContext getSiteContext() {
083: if (siteContext_ == null)
084: throw new ShimException("Site context is null.");
085:
086: return siteContext_;
087: }
088:
089: public void setSiteContext(SiteContext siteContext) {
090: siteContext_ = siteContext;
091: }
092:
093: public void saveNew() {
094: setInt("sitecontext_id", getSiteContext().getInt("id"));
095: super .saveNew();
096: }
097:
098: public List loadAll() {
099: return loadAll(dynaClass_, "sitecontext_id="
100: + getSiteContext().getInt("id"), "name");
101: }
102:
103: /**
104: * Deletes all fragments for the site context.
105: */
106: public void deleteAll() {
107: deleteAll(dynaClass_, "sitecontext_id="
108: + getSiteContext().getInt("id"));
109: }
110:
111: // properties ///////////////////////////////////////////////////////////////
112:
113: // attributes ///////////////////////////////////////////////////////////////
114:
115: private SiteContext siteContext_;
116: }
|