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 package org.apache.tapestry.annotations;
015
016 import java.util.Collection;
017 import java.util.Iterator;
018
019 import org.apache.hivemind.ApplicationRuntimeException;
020 import org.apache.hivemind.HiveMind;
021 import org.apache.tapestry.enhance.EnhancementOperation;
022 import org.apache.tapestry.enhance.EnhancementWorker;
023 import org.apache.tapestry.spec.IComponentSpecification;
024 import org.apache.tapestry.spec.IContainedComponent;
025
026 /**
027 * An enhancement worker which performs several housekeeping tasks
028 * relating to injected components.
029 * Currently the worker ensures that copies of components contain
030 * the correct bindings.
031 *
032 * @author Andreas Andreou
033 * @since 4.1.1
034 */
035 public class ComponentHousekeepingWorker implements EnhancementWorker
036 {
037 public void performEnhancement( EnhancementOperation op, IComponentSpecification spec )
038 {
039 for ( Iterator i = spec.getComponentIds().iterator(); i.hasNext(); )
040 {
041 String id = ( String ) i.next();
042 IContainedComponent cc = spec.getComponent(id);
043 String copyOf = cc.getCopyOf();
044 Collection bindingNames = cc.getBindingNames();
045
046 if (HiveMind.isNonBlank(copyOf) && bindingNames.size() == 0)
047 {
048 IContainedComponent source = spec.getComponent(copyOf);
049 if (source == null)
050 throw new ApplicationRuntimeException(AnnotationMessages.unableToCopy(copyOf));
051
052 AnnotationUtils.copyBindings(source, cc);
053 }
054 }
055 }
056 }