 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.plugin;
30 import nu.xom.Attribute;
31 import nu.xom.Element;
32 import nu.xom.Elements;
33 import nu.xom.ParentNode;
35 import org.apache.log4j.Category;
36 import org.apache.log4j.Logger;
37 import org.jetbrains.annotations.NotNull;
56 private static final String
FILTER =
"filter";
62 private static final String
BASH =
"bash";
93 boolean isAutoBoot =
false;
94 boolean isFilter =
false;
95 boolean isScript =
false;
96 final Elements modeElements = node.getChildElements(
"mode");
97 if (modeElements.size() == 0) {
100 for (
final Element modeChild :
new ElementsIterable(modeElements.get(0).getChildElements())) {
101 final boolean value = Boolean.valueOf(modeChild.getValue());
102 final String
name = modeChild.getLocalName();
105 }
else if (
name.equalsIgnoreCase(
FILTER) && value) {
107 }
else if (
name.equalsIgnoreCase(
BASH) && value) {
115 for (
final Element parameter :
new ElementsIterable(node.getChildElements(
"parameter"))) {
120 LOG.warn(
"Parameter type " + ex.getMessage() +
" in plugin " + pluginModel +
" is unknown");
136 final Element root =
new Element(
"script");
137 final Element
name =
new Element(
"name");
138 final Element code =
new Element(
"code");
139 name.appendChild(plugin.getName());
140 code.appendChild(
new Text(plugin.getCode()));
141 code.addAttribute(
new Attribute(
"xml:space",
"http://www.w3.org/XML/1998/namespace",
"preserve"));
142 root.appendChild(
name);
143 root.appendChild(code);
144 final ParentNode modes =
new Element(
"mode");
146 final Element autoBoot =
new Element(
AUTO_BOOT);
147 autoBoot.appendChild(Boolean.toString(plugin.isAutoBoot()));
148 final Element bash =
new Element(
BASH);
149 bash.appendChild(Boolean.toString(plugin.isScript()));
150 final Element filter =
new Element(
FILTER);
151 filter.appendChild(Boolean.toString(plugin.isFilter()));
152 modes.appendChild(autoBoot);
153 modes.appendChild(bash);
154 modes.appendChild(filter);
156 root.appendChild(modes);
158 root.appendChild(plugin.toXML(pluginParameter));
Element toXML(@NotNull final Plugin< G, A, R > plugin)
Converts a Plugin instance to XML representation.
static final String FILTER
Whether the plugin is a filter.
Base package of all Gridarta classes.
final PluginParameterFactory< G, A, R > pluginParameterFactory
The PluginParameterFactory to use.
void setScript(final boolean script)
Sets whether this plugin is a stand-alone plugin.
Converter for Plugin instances to or from XML representation.
PluginParameter< G, A, R, ?> createParameter(@NotNull final Element parameterNode)
Plugin< G, A, R > fromXML(@NotNull final Element node)
Creates a Plugin instance from XML representation.
void setCode(@NotNull final String code)
Sets the executable code of this plugin.
PluginModelParser(@NotNull final PluginParameterFactory< G, A, R > pluginParameterFactory)
Creates a new instance.
Reflects a game object (object on a map).
Thrown if a parameter does not exist.
static Element getChild(@NotNull final Element parentElement, @NotNull final String childName)
Returns a child Element of a parent element.
GameObjects are the objects based on Archetypes found on maps.
void addParameter(@NotNull final PluginParameter< G, A, R, ?> pluginParameter)
Adds a plugin parameter to this plugin.
PluginParameter< G, A, R, ?> createStringParameter(@NotNull final Element parameterNode)
Creates a new StringParameter from XML representation.
Interface for MapArchObjects.
void setAutoBoot(final boolean autoBoot)
Sets whether this plugin is run whenever the editor starts.
void setFilter(final boolean filter)
Sets whether this plugin is a filter.
static final Category LOG
The Logger for printing log messages.
Factory for Plugin Parameters.
void resetModified()
Marks the plugin as unmodified since last save.
XML related utility functions.
static final String BASH
Whether the plugin is a stand-alone plugin.
static final String AUTO_BOOT
Whether the plugin is in auto-boot mode.