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.bindings; 25 26 import org.objectweb.fractal.adl.Node; 27 import org.objectweb.fractal.adl.bindings.Binding; 28 import org.objectweb.fractal.adl.interfaces.Interface; 29 30 /** 31 * Utility class to manipulate decorations of {@link Binding} node. 32 */ 33 public final class BindingDecorationUtil { 34 35 /** 36 * A decoration set on {@link Binding} nodes, its value is the client 37 * interface node of the binding. The value of this decoration must be an 38 * {@link Interface} node. 39 * 40 * @see #getClientInterface(Binding) 41 * @see #setClientInterface(Binding, Interface) 42 */ 43 public static final String CLIENT_INTERFACE_DECORATION = "client-interface"; 44 45 /** 46 * A decoration set on {@link Binding} nodes, its value is the server 47 * interface node of the binding. The value of this decoration must be an 48 * {@link Interface} node. 49 * 50 * @see #getServerInterface(Binding) 51 * @see #setServerInterface(Binding, Interface) 52 */ 53 public static final String SERVER_INTERFACE_DECORATION = "server-interface"; 54 55 /** 56 * A decoration set on {@link Binding} nodes to say that a the binding must be 57 * established statically. The value of this decoration must be a 58 * {@link Boolean}. 59 * 60 * @see #setStaticallyBound(Binding, boolean) 61 * @see #isStaticallyBound(Binding) 62 * @see #isStaticallyBoundFalse(Binding) 63 */ 64 public static final String STATICALLY_BOUND_DECORATION = "statically-bound"; 65 66 private BindingDecorationUtil() { 67 } 68 69 /** 70 * Sets the {@link #CLIENT_INTERFACE_DECORATION} decoration to the given 71 * {@link Binding} node. 72 * 73 * @param binding the binding to which the decoration is set. 74 * @param clientItf the value of the decoration. 75 * @see #CLIENT_INTERFACE_DECORATION 76 */ 77 public static void setClientInterface(final Binding binding, 78 final Interface clientItf) { 79 ((Node) binding).astSetDecoration(CLIENT_INTERFACE_DECORATION, clientItf); 80 } 81 82 /** 83 * Returns the value of the {@link #CLIENT_INTERFACE_DECORATION} decoration of 84 * the given binding node. 85 * 86 * @param binding a binding node. 87 * @return The value of the {@link #CLIENT_INTERFACE_DECORATION} decoration or 88 * <code>null</code> if the given node has no such decoration. 89 */ 90 public static Interface getClientInterface(final Binding binding) { 91 return (Interface) ((Node) binding) 92 .astGetDecoration(CLIENT_INTERFACE_DECORATION); 93 } 94 95 /** 96 * Sets the {@link #SERVER_INTERFACE_DECORATION} decoration to the given 97 * {@link Binding} node. 98 * 99 * @param binding the binding to which the decoration is set. 100 * @param clientItf the value of the decoration. 101 * @see #SERVER_INTERFACE_DECORATION 102 */ 103 public static void setServerInterface(final Binding binding, 104 final Interface clientItf) { 105 ((Node) binding).astSetDecoration(SERVER_INTERFACE_DECORATION, clientItf); 106 } 107 108 /** 109 * Returns the value of the {@link #SERVER_INTERFACE_DECORATION} decoration of 110 * the given binding node. 111 * 112 * @param binding a binding node. 113 * @return The value of the {@link #SERVER_INTERFACE_DECORATION} decoration or 114 * <code>null</code> if the given node has no such decoration. 115 */ 116 public static Interface getServerInterface(final Binding binding) { 117 return (Interface) ((Node) binding) 118 .astGetDecoration(SERVER_INTERFACE_DECORATION); 119 } 120 121 /** 122 * Sets the {@link #STATICALLY_BOUND_DECORATION} decoration to the given node 123 * with the given boolean value. 124 * 125 * @param binding the binding to which the decoration is set. 126 * @param b the value of the decoration. 127 * @see #STATICALLY_BOUND_DECORATION 128 */ 129 public static void setStaticallyBound(final Binding binding, final boolean b) { 130 ((Node) binding).astSetDecoration(STATICALLY_BOUND_DECORATION, b); 131 } 132 133 /** 134 * Returns <code>true</code> if the given binding node has a 135 * {@link #STATICALLY_BOUND_DECORATION} decoration with the <code>true</code> 136 * value. 137 * 138 * @param binding a binding node. 139 * @return <code>true</code> if the given binding node has a 140 * {@link #STATICALLY_BOUND_DECORATION} decoration with the 141 * <code>true</code> value. 142 * @see #STATICALLY_BOUND_DECORATION 143 */ 144 public static boolean isStaticallyBound(final Binding binding) { 145 final Boolean b = (Boolean) ((Node) binding) 146 .astGetDecoration(STATICALLY_BOUND_DECORATION); 147 return b != null && b; 148 } 149 150 /** 151 * Returns <code>true</code> if the given binding node has a 152 * {@link #STATICALLY_BOUND_DECORATION} decoration with the <code>false</code> 153 * value. <b>Warning</b>: this method is not the oposite of the 154 * {@link #isStaticallyBound(Binding)} since if the decoration is not present, 155 * both of them return <code>false</code>. 156 * 157 * @param binding a binding node. 158 * @return <code>true</code> if the given binding node has a 159 * {@link #STATICALLY_BOUND_DECORATION} decoration with the 160 * <code>false</code> value. 161 * @see #STATICALLY_BOUND_DECORATION 162 */ 163 public static boolean isStaticallyBoundFalse(final Binding binding) { 164 final Boolean b = (Boolean) ((Node) binding) 165 .astGetDecoration(STATICALLY_BOUND_DECORATION); 166 return b != null && (!b); 167 } 168 169 }