1 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 ; 31 32 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 .class ), 53 new DynaProperty( "sitecontext_id", Integer .class ), 54 new DynaProperty( "name", String .class ), 55 new DynaProperty( "value", String .class ) 56 }; 57 58 dynaClass_ = 59 new BasicDynaClass( 60 "shim_htmlfragment", HtmlFragment.class, dynaProperties ); 61 } 62 63 65 public HtmlFragment() { 66 super( dynaClass_ ); 67 init(); 68 } 69 70 public HtmlFragment( DynaClass dynaClass ) { 71 super( dynaClass ); 72 init(); 73 } 74 75 77 79 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 loadAll() { 106 return loadAll( 107 dynaClass_, "sitecontext_id=" + getSiteContext().getInt( "id" ), "name" ); 108 } 109 110 113 public void deleteAll() { 114 deleteAll( 115 dynaClass_, "sitecontext_id=" + getSiteContext().getInt( "id" ) ); 116 } 117 118 120 122 private SiteContext siteContext_; 123 } 124 | Popular Tags |