1 16 package org.apache.cocoon.portal.source; 17 18 import java.io.IOException ; 19 import java.net.MalformedURLException ; 20 import java.util.Map ; 21 22 import org.apache.avalon.framework.context.Context; 23 import org.apache.avalon.framework.context.ContextException; 24 import org.apache.avalon.framework.context.Contextualizable; 25 import org.apache.avalon.framework.logger.AbstractLogEnabled; 26 import org.apache.avalon.framework.service.ServiceException; 27 import org.apache.avalon.framework.service.ServiceManager; 28 import org.apache.avalon.framework.service.Serviceable; 29 import org.apache.avalon.framework.thread.ThreadSafe; 30 import org.apache.cocoon.portal.PortalService; 31 import org.apache.cocoon.portal.coplet.CopletInstanceData; 32 import org.apache.excalibur.source.Source; 33 import org.apache.excalibur.source.SourceException; 34 import org.apache.excalibur.source.SourceFactory; 35 36 44 public class CopletSourceFactory 45 extends AbstractLogEnabled 46 implements SourceFactory, Serviceable, ThreadSafe, Contextualizable { 47 48 protected ServiceManager manager; 49 protected Context context; 50 51 54 public void service(ServiceManager serviceManager) throws ServiceException { 55 this.manager = serviceManager; 56 } 57 58 61 public void contextualize(Context context) throws ContextException { 62 this.context = context; 63 } 64 65 68 public Source getSource(String location, Map parameters) 69 throws MalformedURLException , IOException { 70 71 String uri = location; 72 String protocol = null; 73 74 int position = location.indexOf(':') + 1; 76 if (position != 0) { 77 protocol = location.substring(0, position); 78 location = location.substring(position+2); 79 } 80 PortalService service = null; 81 try { 82 service = (PortalService)this.manager.lookup(PortalService.ROLE); 83 CopletInstanceData coplet = service.getComponentManager().getProfileManager().getCopletInstanceData(location); 84 if ( coplet == null ) { 85 throw new IOException ("Unable to get coplet for " + location); 86 } 87 CopletSource copletSource = 88 new CopletSource(uri, protocol, 89 coplet); 90 copletSource.contextualize(this.context); 91 copletSource.service(this.manager); 92 return copletSource; 93 } catch (ContextException ce) { 94 throw new SourceException("Unable to lookup profile manager.", ce); 95 } catch (ServiceException ce) { 96 throw new SourceException("Unable to lookup profile manager.", ce); 97 } finally { 98 this.manager.release(service); 99 } 100 } 101 102 105 public void release(Source source) { 106 } 108 109 } 110 | Popular Tags |