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.controllers; 25 26 import org.objectweb.fractal.adl.Node; 27 import org.objectweb.fractal.adl.interfaces.Interface; 28 import org.objectweb.fractal.adl.interfaces.InterfaceContainer; 29 30 /** 31 * Utility class to manipulate decorations of controller {@link Interface} node. 32 */ 33 public final class ControllerDecorationUtil { 34 private ControllerDecorationUtil() { 35 } 36 37 /** 38 * A decoration set on {@link Interface} node to indicate the symbol name of 39 * the V-Table that provides the implementation of this interface. 40 * 41 * @see #getVTable(Interface) 42 * @see #setVTable(Interface, String) 43 */ 44 public static final String V_TABLE_DECORATION = "vtbl"; 45 46 /** 47 * Sets the value of the {@link #V_TABLE_DECORATION} decoration. 48 * 49 * @param itf an interface node. 50 * @param value the value of the decoration. 51 * @see #V_TABLE_DECORATION 52 */ 53 public static void setVTable(final Interface itf, final String value) { 54 ((Node) itf).astSetDecoration(V_TABLE_DECORATION, value); 55 } 56 57 /** 58 * Returns the value of the {@link #V_TABLE_DECORATION} decoration of the 59 * given interface node. 60 * 61 * @param itf an interface node. 62 * @return The value of the {@link #V_TABLE_DECORATION} decoration or 63 * <code>null</code> if the given node has no such decoration. 64 * @see #V_TABLE_DECORATION 65 */ 66 public static String getVTable(final Interface itf) { 67 return (String) ((Node) itf).astGetDecoration(V_TABLE_DECORATION); 68 } 69 70 /** 71 * A decoration set on {@link Interface} node to indicate the suffix of the 72 * symbol name of the <code>self-data</code> of the interface. 73 * 74 * @see #getDataSuffix(Interface) 75 * @see #setDataSuffix(Interface, String) 76 */ 77 public static final String DATA_SUFFIX_DECORATION = "data"; 78 79 /** 80 * Sets the value of the {@link #DATA_SUFFIX_DECORATION} decoration. 81 * 82 * @param itf an interface node. 83 * @param value the value of the decoration. 84 * @see #DATA_SUFFIX_DECORATION 85 */ 86 public static void setDataSuffix(final Interface itf, final String value) { 87 ((Node) itf).astSetDecoration(DATA_SUFFIX_DECORATION, value); 88 } 89 90 /** 91 * Returns the value of the {@link #DATA_SUFFIX_DECORATION} decoration of the 92 * given interface node. 93 * 94 * @param itf an interface node. 95 * @return The value of the {@link #DATA_SUFFIX_DECORATION} decoration or 96 * <code>null</code> if the given node has no such decoration. 97 * @see #DATA_SUFFIX_DECORATION 98 */ 99 public static String getDataSuffix(final Interface itf) { 100 return (String) ((Node) itf).astGetDecoration(DATA_SUFFIX_DECORATION); 101 } 102 103 /** 104 * A decoration set on the <code>binding-controller</code> {@link Interface} 105 * node to indicate if the binding controller is implemented by the component 106 * implementation. 107 * 108 * @see #isCustomBindingController(Interface) 109 * @see #hasCustomBindingController(InterfaceContainer) 110 * @see #setCustomBindingController(Interface, boolean) 111 */ 112 public static final String CUSTOM_BC_DECORATION = "custom-binding-controller"; 113 114 /** 115 * Sets the value of the {@link #CUSTOM_BC_DECORATION} decoration to the given 116 * value. 117 * 118 * @param itf an interface node. This node is supposed to be the 119 * <code>binding-controller</code> interface. 120 * @param value the value of the decoration. 121 * @see #CUSTOM_BC_DECORATION 122 */ 123 public static void setCustomBindingController(final Interface itf, 124 final boolean value) { 125 ((Node) itf).astSetDecoration(CUSTOM_BC_DECORATION, value); 126 } 127 128 /** 129 * Returns <code>true</code> if and only if the given {@link Interface} node 130 * has a {@link #CUSTOM_BC_DECORATION} decoration with the <code>true</code> 131 * value. 132 * 133 * @param itf an interface node. 134 * @return the value of the {@link #CUSTOM_BC_DECORATION}, or 135 * <code>false</code> if it is not set. 136 * @see #CUSTOM_BC_DECORATION 137 */ 138 public static boolean isCustomBindingController(final Interface itf) { 139 final Boolean b = (Boolean) ((Node) itf) 140 .astGetDecoration(CUSTOM_BC_DECORATION); 141 return (b == null) ? false : b; 142 } 143 144 /** 145 * Helper method to retrieve the value of the {@link #CUSTOM_BC_DECORATION} 146 * decoration of the <code>binding-controller</code> interface node 147 * contained by the given container. 148 * 149 * @param itfContainer an {@link Interface} container. 150 * @return return the value of the {@link #CUSTOM_BC_DECORATION} decoration of 151 * the <code>"binding-controller"</code> interface node or 152 * <code>false</code> if the given interface container does not 153 * contain a <code>binding-controller</code> interface. 154 * @see #CUSTOM_BC_DECORATION 155 */ 156 public static boolean hasCustomBindingController( 157 final InterfaceContainer itfContainer) { 158 for (final Interface itf : itfContainer.getInterfaces()) { 159 if (itf.getName().equals("binding-controller")) 160 return isCustomBindingController(itf); 161 } 162 return false; 163 } 164 }