org.objectweb.fractal.mind.st.BoundInterfaceMap Maven / Gradle / Ivy
/**
* Copyright (C) 2009 STMicroelectronics
*
* This file is part of "Mind Compiler" is free software: you can redistribute
* it and/or modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Contact: [email protected]
*
* Authors: Ali Erdem Ozcan
* Contributors:
*/
package org.objectweb.fractal.mind.st;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Set;
import org.antlr.stringtemplate.StringTemplate;
public class BoundInterfaceMap extends HashMap {
/**
* Generated serial ID
*/
private static final long serialVersionUID = -7974148690318566114L;
final StringTemplateGroup group;
final String boundTo;
final String signature;
final StringTemplateComponentLoader pluginLoader;
public BoundInterfaceMap(final StringTemplateGroup group,
final String prefix, final String signature,
final StringTemplateComponentLoader pluginLoader) {
this.group = group;
this.boundTo = prefix;
this.signature = signature;
this.pluginLoader = pluginLoader;
StringTemplateGroup subgroup;
// Always load considering the supoerGroup which is equal to our group in
// order to support nested template maps with multiple hierarchies.
subgroup = (StringTemplateGroup) pluginLoader.loadGroup(boundTo, group);
if (!subgroup.implementsInterface(signature)) {
// Throw exception
}
final Set templateNames = new HashSet(subgroup.getTemplateNames());
for (final Object templateName : templateNames) {
final String localTemplateName = "__" + boundTo.replace('.', '_') + "_"
+ ((String) templateName);
this.put((String) templateName, localTemplateName);
// Get and prepare the receiver template
final StringTemplate receiverTemplate = subgroup
.getTemplateDefinition((String) templateName);
final StringTemplate skeletonTemplate = subgroup.defineTemplate(
((String) templateName) + "__Skeleton", receiverTemplate
.getTemplate());
for (final String mapName : subgroup.getMapsKeySet()) {
skeletonTemplate.defineFormalArgument(mapName,
new MapDelegateStringTemplate(subgroup.getMap(mapName)));
}
// Create a stub template
final StringTemplate stubTemplate = group.defineTemplate(
localTemplateName, "<__skeleton_template>");
stubTemplate.setFormalArguments((LinkedHashMap) receiverTemplate
.getFormalArguments());
stubTemplate
.defineFormalArgument("__skeleton_template", skeletonTemplate);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy