| 1 |
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
package com.eprosima.idl.generator.manager; |
| 16 |
|
| 17 |
import java.util.Iterator; |
| 18 |
import java.util.Map; |
| 19 |
import java.util.HashMap; |
| 20 |
import java.util.Map.Entry; |
| 21 |
import java.util.Set; |
| 22 |
import java.util.List; |
| 23 |
import java.util.ArrayList; |
| 24 |
|
| 25 |
import org.stringtemplate.v4.*; |
| 26 |
import org.stringtemplate.v4.misc.STMessage; |
| 27 |
|
| 28 |
public class TemplateManager |
| 29 |
{ |
| 30 |
private Map<String, TemplateSTGroup> m_groups = new HashMap<String, TemplateSTGroup>(); |
| 31 |
|
| 32 |
private boolean st_error_ = false; |
| 33 |
|
| 34 |
private TemplateSTGroup current_template_stgroup_ = null; |
| 35 |
|
| 36 |
public TemplateSTGroup addGroup(String groupname) |
| 37 |
{ |
| 38 |
TemplateSTGroup group = new TemplateSTGroup(groupname); |
| 39 |
m_groups.put(groupname, group); |
| 40 |
return group; |
| 41 |
} |
| 42 |
|
| 43 |
public TemplateSTGroup addGroupFromString(String groupname, String text) |
| 44 |
{ |
| 45 |
TemplateSTGroup group = new TemplateSTGroup(groupname, text); |
| 46 |
m_groups.put(groupname, group); |
| 47 |
return group; |
| 48 |
} |
| 49 |
|
| 50 |
public TemplateGroup createTemplateGroup(String templatename) |
| 51 |
{ |
| 52 |
TemplateGroup tg = new TemplateGroup(this); |
| 53 |
Set<Entry<String, TemplateSTGroup>> set = m_groups.entrySet(); |
| 54 |
Iterator<Entry<String, TemplateSTGroup>> it = set.iterator(); |
| 55 |
|
| 56 |
while(it.hasNext()) |
| 57 |
{ |
| 58 |
Map.Entry<String, TemplateSTGroup> m = it.next(); |
| 59 |
|
| 60 |
// Obtain instance |
| 61 |
TemplateST template = new TemplateST(m.getValue(), templatename); |
| 62 |
tg.addTemplate(m.getKey(), template); |
| 63 |
} |
| 64 |
|
| 65 |
return tg; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
public STGroup createStringTemplateGroup(String templateGroupName) |
| 70 |
{ |
| 71 |
return new STGroupFile(templateGroupName, '$', '$'); |
| 72 |
} |
| 73 |
|
| 74 |
public void set_st_error() |
| 75 |
{ |
| 76 |
st_error_ = true; |
| 77 |
} |
| 78 |
|
| 79 |
public boolean get_st_error() |
| 80 |
{ |
| 81 |
return st_error_; |
| 82 |
} |
| 83 |
|
| 84 |
public void set_current_template_stgroup(TemplateSTGroup template_stgroup) |
| 85 |
{ |
| 86 |
current_template_stgroup_ = template_stgroup; |
| 87 |
} |
| 88 |
|
| 89 |
public boolean is_enabled_custom_property_in_current_group(String custom_property) |
| 90 |
{ |
| 91 |
if (null != current_template_stgroup_) |
| 92 |
{ |
| 93 |
return current_template_stgroup_.is_enabled_custom_property(custom_property); |
| 94 |
} |
| 95 |
|
| 96 |
return false; |
| 97 |
} |
| 98 |
} |