001    // Copyright 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    
015    package org.apache.tapestry.services.impl;
016    
017    import org.apache.hivemind.impl.BaseLocatable;
018    
019    /**
020     * A contribution to the {@link org.apache.tapestry.services.Infrastructure} service. Defines
021     * a property of Infrastructure and the value for that property. The infrastructure is setup in a
022     * <em>mode</em> (currently, either "servlet" or "portlet"). Contributions that define a non-null
023     * mode are ignored unless their mode matches the Infrastructure mode.
024     * <p>
025     * There are two configuration points that control Infrastructure:
026     * <code>tapestry.Infrastructure</code> and <code>tapestry.InfrastructureOverride</code>.
027     * 
028     * @author Howard M. Lewis Ship
029     * @since 4.0
030     */
031    public class InfrastructureContribution extends BaseLocatable
032    {
033        private String _property;
034    
035        private String _mode;
036    
037        private DeferredObject _deferredObject;
038    
039        public void setDeferredObject(DeferredObject deferredObject)
040        {
041            _deferredObject = deferredObject;
042        }
043    
044        public void setValue(String value)
045        {
046            _deferredObject = new LiteralDeferredObject(value, getLocation());
047        }
048    
049        /**
050         * The object which should be exposed as the given Infrastructure property.
051         */
052        public Object getObject()
053        {
054            return _deferredObject.getObject();
055        }
056    
057        /**
058         * The mode for which this contribution applies, or null if the contribution applies to all
059         * modes.
060         */
061    
062        public String getMode()
063        {
064            return _mode;
065        }
066    
067        public void setMode(String mode)
068        {
069            _mode = mode;
070        }
071    
072        /**
073         * The property of the {@link org.apache.tapestry.services.Infrastructure}for which a value is
074         * to be provided.
075         */
076    
077        public String getProperty()
078        {
079            return _property;
080        }
081    
082        public void setProperty(String property)
083        {
084            _property = property;
085        }
086    
087        public boolean matchesMode(String mode)
088        {
089            // If our mode is null, then we only match null.
090    
091            if (_mode == mode)
092                return true;
093    
094            // Otherwise, match our non-null model against their possibly-null mode.
095    
096            return _mode != null && _mode.equals(mode);
097        }
098    }