1 /*** 2 * Cecilia ADL Compiler 3 * Copyright (C) 2006-2007 STMicroelectronics 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Contact: fractal@objectweb.org 20 * 21 * Author: Matthieu Leclercq 22 */ 23 24 package org.objectweb.fractal.cecilia.adl.attributes; 25 26 import java.util.List; 27 import java.util.Map; 28 29 import org.objectweb.fractal.adl.ADLException; 30 import org.objectweb.fractal.adl.ComponentVisitor; 31 import org.objectweb.fractal.adl.Node; 32 import org.objectweb.fractal.adl.attributes.Attributes; 33 import org.objectweb.fractal.adl.attributes.AttributesContainer; 34 import org.objectweb.fractal.adl.components.ComponentContainer; 35 import org.objectweb.fractal.api.Component; 36 import org.objectweb.fractal.api.factory.InstantiationException; 37 import org.objectweb.fractal.task.core.AbstractTaskFactoryUser; 38 import org.objectweb.fractal.task.core.TaskException; 39 40 /** 41 * Abstract visitor component that creates a task that depends on the attributes 42 * of the component (if any). 43 */ 44 public abstract class AbstractAttributeVisitor extends AbstractTaskFactoryUser 45 implements 46 ComponentVisitor { 47 48 /** 49 * Creates the task that is returned by this visitor. 50 * 51 * @param container the component that is visited. 52 * @param attributes the {@link Attributes} node of the component. 53 * @return the created task. 54 * @throws InstantiationException if the instantiation of the task fails. 55 * @throws ADLException if the instantiation of the task fails. 56 */ 57 protected abstract Component createTask(ComponentContainer container, 58 final Attributes attributes) throws ADLException, TaskException; 59 60 // --------------------------------------------------------------------------- 61 // Implementation of the ComponentVisitor interface 62 // --------------------------------------------------------------------------- 63 64 /** 65 * Visits {@link ComponentContainer} nodes and call 66 * {@link #createTask(ComponentContainer, Attributes) createTask} if the given 67 * component contains an {@link Attributes} sub-nodes. 68 */ 69 public Component visit(final List<Node> path, 70 final ComponentContainer container, final Map<Object, Object> context) 71 throws ADLException, TaskException { 72 Attributes attributes = null; 73 if (container instanceof AttributesContainer) { 74 attributes = ((AttributesContainer) container).getAttributes(); 75 } 76 if (attributes == null) return null; 77 return createTask(container, attributes); 78 } 79 }