use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.
the class SynchronizedTag method formatNS3.
@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(NS3Utils.generateIndent(indent));
sb.append(Tags.SYNCHRONIZED + " ");
// Format attributes
AttributeAssignments aa = new AttributeAssignments();
aa.addMap(getAttributes());
sb.append(aa.format(false));
sb.append(" {\n");
w.write(sb.toString().getBytes());
// Loop over children
for (BaseNode n : getChildren()) {
if (n instanceof NS3Compatible) {
((NS3Compatible) n).formatNS3(indent + 1, w);
}
}
w.write((NS3Utils.generateIndent(indent) + "}\n").getBytes());
}
use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.
the class FieldTag method formatNS3.
@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(NS3Utils.generateIndent(indent));
// Check for condition
Map<String, String> map = getAttributes();
String adapterName = ((MapTag) getParent()).getAdapterName();
sb.append(NS3Utils.formatConditional(map.get("condition")));
if ((getChildren() == null || getChildren().size() == 0) && getConstant() == null && !isSetter && !myScript.getMapChecker().isField(adapterName, getName())) {
// No expressions defined, it is an "operation" not a "setter".
if (!myScript.getMapChecker().isMethod(adapterName, getName())) {
throw new Exception("Could not find method " + getName() + " of adapter " + adapterName);
}
sb.append(NS3Constants.ADAPTER_OPERATION + getName());
AttributeAssignments aa = new AttributeAssignments();
aa.addMap(map, "condition", "ref", "object");
sb.append(aa.format(false));
sb.append(NS3Constants.EOL_DELIMITER + "\n");
w.write(sb.toString().getBytes());
} else if (getChildren() != null && getChildren().get(0) instanceof MapTag) {
// <map ref=<array message> >
if (!NS3Utils.checkForDeclaredField(myScript, (MapTag) getParent(), getName())) {
throw new Exception("Could not find ref field " + getName() + " of adapter " + adapterName);
}
sb.append("$" + getName());
sb.append(" {\n");
w.write(sb.toString().getBytes());
// Mark map as a mapped message
((MapTag) getChildren().get(0)).setMappedMessage(true);
((MapTag) getChildren().get(0)).formatNS3(indent + 1, w);
w.write((NS3Utils.generateIndent(indent) + "}\n").getBytes());
} else {
// standard "setter" field
if (!NS3Utils.checkForDeclaredField(myScript, (MapTag) getParent(), getName())) {
throw new Exception("Could not find setter field " + getName() + " of adapter " + adapterName);
}
if (getConstant() != null) {
// setter with a constant string literal
sb.append("$" + getName() + " = ");
sb.append(NS3Utils.formatStringLiteral(indent, getConstant()));
w.write(sb.toString().getBytes());
} else if (getChildren() == null) {
// it must have a value attribute.
sb.append("$" + getName() + " = ");
sb.append(map.get("value"));
w.write(sb.toString().getBytes());
} else {
// setter with normal expression(s)
sb.append("$" + getName());
w.write(sb.toString().getBytes());
if (getChildren().size() == 1) {
ExpressionTag et = (ExpressionTag) getChildren().get(0);
if (et.getConstant() != null) {
w.write("=".getBytes());
} else {
w.write("=".getBytes());
}
et.formatNS3(0, w);
} else {
w.write("=\n".getBytes());
int index = 0;
for (BaseNode e : getChildren()) {
ExpressionTag et = (ExpressionTag) e;
et.formatNS3(indent + 1, w);
index++;
if (index < getChildren().size()) {
w.write("\n".getBytes());
}
}
}
}
w.write((NS3Constants.EOL_DELIMITER + "\n\n").getBytes());
}
}
use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.
the class MapTag method formatNS3.
@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
StringBuffer sb = new StringBuffer();
Map<String, String> map = getAttributes();
sb.append(NS3Utils.generateIndent(indent));
sb.append(NS3Utils.formatConditional(map.get("condition")));
if (isOldStyleMap && (getRefAttribute() == null || "".equals(getRefAttribute()))) {
sb.append("map" + NS3Constants.PARAMETERS_START + "object:\"" + getObject() + "\" " + NS3Constants.PARAMETERS_END);
if (!myScript.getMapChecker().isValidClass(getObject())) {
throw new Exception("Adapter class not found: " + getObject());
}
} else if ((field == null || "".equals(field)) && getAdapterName() != null && !"".equals(getAdapterName())) {
if (!myScript.getMapChecker().isValidAdapter(getAdapterName())) {
throw new Exception("Adapter not found: " + getAdapterName());
}
sb.append("map." + getAdapterName());
AttributeAssignments aa = new AttributeAssignments();
aa.addMap(map, "condition", "ref", "object");
sb.append(aa.format(false));
} else {
int index = 0;
if (isMappedMessage()) {
if (getRefAttribute().indexOf("[") == -1) {
sb.append("[" + getRefAttribute() + "] ");
} else {
sb.append(getRefAttribute());
}
} else {
if (super.getParent() != null) {
MapTag parent = (MapTag) super.getParent();
if (!NS3Utils.checkForDeclaredField(myScript, parent, getRefAttribute())) {
throw new Exception("Ref field not found: " + getRefAttribute() + " for adapter: " + parent.getAdapterName());
}
} else {
throw new Exception("Could not find parent map for ref field: " + getRefAttribute());
}
sb.append("$" + getRefAttribute() + " ");
}
if (getFilter() != null && !"".equals(getFilter())) {
sb.append(NS3Constants.PARAMETERS_START);
sb.append((index > 0 ? "," : "") + Attributes.FILTER + "=" + getFilter());
sb.append(NS3Constants.PARAMETERS_END);
}
}
if (isMappedSelection) {
sb.append(" {\n");
} else {
sb.append(" {\n\n");
}
w.write(sb.toString().getBytes());
// Loop over children
for (BaseNode n : getChildren()) {
if (n instanceof NS3Compatible) {
if (n instanceof PropertyTag && isMappedSelection) {
((PropertyTag) n).setPartOfMappedSelection(true);
}
((NS3Compatible) n).formatNS3(indent + 1, w);
}
}
w.write((NS3Utils.generateIndent(indent) + "}\n\n").getBytes());
}
use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.
the class FinallyTag method formatNS3.
@Override
public void formatNS3(int indent, OutputStream w) throws Exception {
StringBuffer sb = new StringBuffer();
sb.append(NS3Utils.generateIndent(indent));
sb.append("finally {\n");
w.write(sb.toString().getBytes());
// Loop over children
for (BaseNode n : getChildren()) {
if (n instanceof NS3Compatible) {
((NS3Compatible) n).formatNS3(indent + 1, w);
}
}
w.write((NS3Utils.generateIndent(indent) + "}\n").getBytes());
}
use of com.dexels.navajo.document.base.BaseNode in project navajo by Dexels.
the class NS3Utils method writeConditionalExpressions.
public static void writeConditionalExpressions(int indent, OutputStream w, List<? extends BaseNode> expressions) throws IOException {
if (expressions.size() == 1) {
ExpressionTag et = (ExpressionTag) expressions.get(0);
et.formatNS3(0, w);
} else {
w.write("\n".getBytes());
int index = 0;
for (BaseNode e : expressions) {
ExpressionTag et = (ExpressionTag) e;
index++;
if (index == expressions.size()) {
w.write(NS3Utils.generateIndent(indent + 1).getBytes());
w.write((NS3Constants.CONDITION_ELSE + " ").getBytes());
et.formatNS3(0, w);
} else {
et.formatNS3(indent + 1, w);
if (index < expressions.size()) {
w.write("\n".getBytes());
}
}
}
}
}
Aggregations