001 // Copyright 2004, 2005 The Apache Software Foundation 002 // 003 // Licensed under the Apache License, Version 2.0 (the "License"); 004 // you may not use this file except in compliance with the License. 005 // You may obtain a copy of the License at 006 // 007 // http://www.apache.org/licenses/LICENSE-2.0 008 // 009 // Unless required by applicable law or agreed to in writing, software 010 // distributed under the License is distributed on an "AS IS" BASIS, 011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012 // See the License for the specific language governing permissions and 013 // limitations under the License. 014 package org.apache.tapestry.services.impl; 015 016 import java.io.IOException; 017 import java.util.List; 018 019 import org.apache.hivemind.ApplicationRuntimeException; 020 import org.apache.tapestry.IRequestCycle; 021 import org.apache.tapestry.services.ResponseBuilder; 022 import org.apache.tapestry.services.ResponseContributor; 023 import org.apache.tapestry.services.ResponseDelegateFactory; 024 025 /** 026 * Implementation of {@link ResponseDelegateFactory}. 027 * 028 * @author jkuhnert 029 */ 030 public class ResponseDelegateFactoryImpl implements ResponseDelegateFactory { 031 032 /** Configured response contribution choosers. */ 033 protected List _responseContributors; 034 035 /** 036 * {@inheritDoc} 037 */ 038 public ResponseBuilder getResponseBuilder(IRequestCycle cycle) 039 throws IOException 040 { 041 if (_responseContributors == null) 042 return null; 043 044 for (int i = 0; i < _responseContributors.size(); i++) { 045 ResponseContributor rc = (ResponseContributor)_responseContributors.get(i); 046 if (rc.handlesResponse(cycle)) 047 return rc.createBuilder(cycle); 048 } 049 050 throw new ApplicationRuntimeException(ImplMessages.unknownRequest()); 051 } 052 053 /** 054 * Sets a configured list of {@link ResponseContributor} objects to be used 055 * in processing ajax requests. 056 * 057 * @param responseContributors 058 */ 059 public void setResponseContributors(List responseContributors) 060 { 061 this._responseContributors = responseContributors; 062 } 063 }