View Javadoc

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;
25  
26  import java.util.List;
27  import java.util.Map;
28  import java.util.TreeMap;
29  
30  import org.objectweb.fractal.adl.ADLException;
31  import org.objectweb.fractal.adl.components.ComponentContainer;
32  import org.objectweb.fractal.api.control.BindingController;
33  import org.objectweb.fractal.cecilia.adl.components.PrimitiveChecker;
34  
35  /**
36   * Basic implementation of the {@link PrimitiveChecker} interface. This
37   * implementation delegates definition compilation requests to a set of
38   * {@link PrimitiveChecker primitive-checkers} according to the alphabetical
39   * order of their client interface names.
40   */
41  public class PrimitiveCheckerDispatcher
42      implements
43        PrimitiveChecker,
44        BindingController {
45    /**
46     * Name of the collection interface bound to the {@link PrimitiveChecker
47     * PrimitiveCheckers} used by this checker.
48     */
49    public static final String           PRIMITIVE_CHECKERS   = "client-checker";
50  
51    /**
52     * The primitive checkers used by this checker.
53     */
54    public Map<String, PrimitiveChecker> primitiveCheckersItf = new TreeMap<String, PrimitiveChecker>();
55  
56    // ---------------------------------------------------------------------------
57    // Implementation of the PrimitiveChecker interface
58    // ---------------------------------------------------------------------------
59  
60    public void beforeSubComponentCheck(final List<ComponentContainer> path,
61        final ComponentContainer container, final Map<Object, Object> context)
62        throws ADLException {
63      for (final PrimitiveChecker checker : primitiveCheckersItf.values()) {
64        checker.beforeSubComponentCheck(path, container, context);
65      }
66    }
67  
68    public void afterSubComponentCheck(final List<ComponentContainer> path,
69        final ComponentContainer container, final Map<Object, Object> context)
70        throws ADLException {
71      for (final PrimitiveChecker checker : primitiveCheckersItf.values()) {
72        checker.afterSubComponentCheck(path, container, context);
73      }
74    }
75  
76    // ---------------------------------------------------------------------------
77    // Implementation of the BindingController interface
78    // ---------------------------------------------------------------------------
79  
80    public String[] listFc() {
81      return primitiveCheckersItf.keySet().toArray(
82          new String[primitiveCheckersItf.size()]);
83    }
84  
85    public Object lookupFc(final String itf) {
86      if (itf.startsWith(PRIMITIVE_CHECKERS)) {
87        return primitiveCheckersItf.get(itf);
88      }
89      return null;
90    }
91  
92    public void bindFc(final String itf, final Object value) {
93      if (itf.startsWith(PRIMITIVE_CHECKERS)) {
94        primitiveCheckersItf.put(itf, (PrimitiveChecker) value);
95      }
96    }
97  
98    public void unbindFc(final String itf) {
99      if (itf.startsWith(PRIMITIVE_CHECKERS)) {
100       primitiveCheckersItf.remove(itf);
101     }
102   }
103 }