1 /*** 2 * Julia: France Telecom's implementation of the Fractal API 3 * Copyright (C) 2001-2002 France Telecom R&D 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: Eric.Bruneton@rd.francetelecom.com 20 * 21 * Author: Eric Bruneton 22 */ 23 24 package org.objectweb.fractal.julia.factory; 25 26 import org.objectweb.fractal.api.Component; 27 import org.objectweb.fractal.api.NoSuchInterfaceException; 28 import org.objectweb.fractal.api.control.NameController; 29 import org.objectweb.fractal.api.factory.InstantiationException; 30 31 /** 32 * Provides a name copy function to a {@link Template}. 33 * <br> 34 * <br> 35 * <b>Requirements</b> 36 * <ul> 37 * <li>none (the template component may provide a {@link NameController} 38 * interface, but this is not mandatory - in this case this mixin does 39 * nothing).</li> 40 * </ul> 41 */ 42 43 public abstract class NameTemplateMixin implements Template { 44 45 // ------------------------------------------------------------------------- 46 // Private constructor 47 // ------------------------------------------------------------------------- 48 49 private NameTemplateMixin () { 50 } 51 52 // ------------------------------------------------------------------------- 53 // Fields and methods added and overriden by the mixin class 54 // ------------------------------------------------------------------------- 55 56 /** 57 * Calls the overriden method and then sets the name of the created component. 58 * The name of the created component is initialized to the name of this 59 * template, if both components have a {@link NameController} interface 60 * (otherwise this mixin does nothing). 61 * 62 * @return the instantiated component. 63 * @throws InstantiationException if the component controller cannot be 64 * instantiated. 65 */ 66 67 public Component newFcControllerInstance () throws InstantiationException { 68 Component comp = _super_newFcControllerInstance(); 69 if (_this_weaveableOptNC != null) { 70 try { 71 // copies the name of this template to the component, if applicable 72 String name = _this_weaveableOptNC.getFcName(); 73 ((NameController)comp.getFcInterface("name-controller")).setFcName(name); 74 } catch (NoSuchInterfaceException ignored) { 75 } 76 } 77 return comp; 78 } 79 80 // ------------------------------------------------------------------------- 81 // Fields and methods required by the mixin class in the base class 82 // ------------------------------------------------------------------------- 83 84 /** 85 * The <tt>weaveableOptNC</tt> field required by this mixin. This field is 86 * supposed to reference the {@link NameController} interface of the component 87 * to which this controller object belongs. 88 */ 89 90 public NameController _this_weaveableOptNC; 91 92 /** 93 * The {@link Template#newFcControllerInstance newFcControllerInstance} 94 * overriden by this mixin. 95 * 96 * @return the instantiated component. 97 * @throws InstantiationException if the component controller cannot be 98 * instantiated. 99 */ 100 101 public abstract Component _super_newFcControllerInstance () 102 throws InstantiationException; 103 } 104