1 54 55 package org.apache.jetspeed.services.cms.manager; 56 57 import java.util.Hashtable ; 59 60 import org.apache.turbine.services.TurbineServices; 62 import org.apache.turbine.util.TurbineException; 63 import org.apache.turbine.services.resources.TurbineResources; 64 65 66 import org.apache.jetspeed.services.cms.CmsService; 68 import org.apache.jetspeed.services.cms.JetspeedCMSException; 69 import org.apache.jetspeed.om.cms.CmsObject; 70 71 77 public class CmsFactory 78 { 79 80 private static String cmsManagerClassName = null; 81 private static Class cmsManagerClass = null; 82 private static Hashtable omClasses = new Hashtable (); 83 84 85 92 public static CmsManager getCmsManagerInstance(String namespace) 93 throws JetspeedCMSException 94 95 { 96 CmsManager cmsManager = null; 97 98 if (null == cmsManagerClassName) 99 { 100 try 101 { 102 cmsManagerClassName = TurbineResources.getString( 103 "services.CmsService.CmsManager." + namespace + ".class"); 104 105 cmsManagerClass = Class.forName(cmsManagerClassName); 106 } 107 catch(Exception e) 108 { 109 throw new JetspeedCMSException( 110 "CmsFactory: Failed to create a CmsManager object for CMS implementation: " + e.toString()); 111 } 112 } 113 114 try 115 { 116 cmsManager = (CmsManager) cmsManagerClass.newInstance(); 117 cmsManager.init(namespace); 118 119 } 120 catch(Exception e) 121 { 122 throw new JetspeedCMSException("Failed instantiate an CmsManager implementation object: " + e.toString()); 123 } 124 125 return cmsManager; 126 } 127 128 137 public static CmsObject getCmsOmInstance(String CmsOmName) 138 throws JetspeedCMSException 139 { 140 CmsObject cmsObject = null; 141 Class omClass = (Class ) omClasses.get(CmsOmName); 142 143 if (null == omClass) 144 { 145 try 146 { 147 String omClassName = TurbineResources.getString( 148 "services.CmsService.om." + CmsOmName + ".class"); 149 150 omClass = Class.forName(omClassName); 151 omClasses.put(CmsOmName, omClass); 152 } 153 catch(Exception e) 154 { 155 throw new JetspeedCMSException( 156 "CmsFactory: Failed to create a Cms object for : " + e.toString()); 157 } 158 } 159 160 try 161 { 162 cmsObject = (CmsObject) omClass.newInstance(); 163 164 } 165 catch(Exception e) 166 { 167 throw new JetspeedCMSException("Failed to instantiate an Cms implementation object: " + e.toString()); 168 } 169 170 return cmsObject; 171 172 } 173 174 } | Popular Tags |