KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > methodhead > shim > HtmlFragment


1 /*
2  * Copyright (C) 2006 Methodhead Software LLC. All rights reserved.
3  *
4  * This file is part of TransferCM.
5  *
6  * TransferCM is free software; you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation; either version 2 of the License, or (at your option) any later
9  * version.
10  *
11  * TransferCM is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * TransferCM; if not, write to the Free Software Foundation, Inc., 51 Franklin St,
18  * Fifth Floor, Boston, MA 02110-1301 USA
19  */

20
21 package com.methodhead.shim;
22
23 import com.methodhead.aikp.AutoIntKeyPersistable;
24
25 import org.apache.commons.beanutils.DynaClass;
26 import org.apache.commons.beanutils.DynaProperty;
27 import org.apache.commons.beanutils.BasicDynaClass;
28 import com.methodhead.sitecontext.SiteContextCapable;
29 import com.methodhead.sitecontext.SiteContext;
30 import java.util.List JavaDoc;
31
32 /**
33  * An HtmlFragment. The following fields are defined:
34  * <ul>
35  * <li><tt>int id = 0</tt></li>
36  * <li><tt>int sitecontext_id = 0</tt></li>
37  * <li><tt>String name = ""</tt></li>
38  * <li><tt>String value = ""</tt></li>
39  * </ul>
40  */

41 public class HtmlFragment
42 extends
43   AutoIntKeyPersistable
44 implements
45   SiteContextCapable {
46
47   private static DynaClass dynaClass_ = null;
48
49   static {
50     DynaProperty[] dynaProperties =
51       new DynaProperty[] {
52         new DynaProperty( "id", Integer JavaDoc.class ),
53         new DynaProperty( "sitecontext_id", Integer JavaDoc.class ),
54         new DynaProperty( "name", String JavaDoc.class ),
55         new DynaProperty( "value", String JavaDoc.class )
56       };
57
58     dynaClass_ =
59       new BasicDynaClass(
60         "shim_htmlfragment", HtmlFragment.class, dynaProperties );
61   }
62
63   // constructors /////////////////////////////////////////////////////////////
64

65   public HtmlFragment() {
66     super( dynaClass_ );
67     init();
68   }
69
70   public HtmlFragment( DynaClass dynaClass ) {
71     super( dynaClass );
72     init();
73   }
74
75   // constants ////////////////////////////////////////////////////////////////
76

77   // classes //////////////////////////////////////////////////////////////////
78

79   // methods //////////////////////////////////////////////////////////////////
80

81   protected void init() {
82     setInt( "id", 0 );
83     setInt( "sitecontext_id", 0 );
84     setString( "name", "" );
85     setString( "value", "" );
86   }
87
88   public SiteContext getSiteContext() {
89     if ( siteContext_ == null )
90       throw new ShimException( "Site context is null." );
91
92     return siteContext_;
93   }
94
95   public void setSiteContext(
96     SiteContext siteContext ) {
97     siteContext_ = siteContext;
98   }
99
100   public void saveNew() {
101     setInt( "sitecontext_id", getSiteContext().getInt( "id" ) );
102     super.saveNew();
103   }
104
105   public List JavaDoc loadAll() {
106     return loadAll(
107       dynaClass_, "sitecontext_id=" + getSiteContext().getInt( "id" ), "name" );
108   }
109
110   /**
111    * Deletes all fragments for the site context.
112    */

113   public void deleteAll() {
114     deleteAll(
115       dynaClass_, "sitecontext_id=" + getSiteContext().getInt( "id" ) );
116   }
117
118   // properties ///////////////////////////////////////////////////////////////
119

120   // attributes ///////////////////////////////////////////////////////////////
121

122   private SiteContext siteContext_;
123 }
124
Popular Tags