use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class Expression method match.
public static final Message match(String matchString, Navajo inMessage, MappableTreeNode o, Message parent) throws SystemException {
try {
StringTokenizer tokens = new StringTokenizer(matchString, ";");
String matchSet = tokens.nextToken();
if (matchSet == null)
throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
String matchValue = tokens.nextToken();
if (matchValue == null)
throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
Operand value = evaluate(matchValue, inMessage, o, parent, null, null, null, null);
List<Property> properties;
if (parent == null)
properties = inMessage.getProperties(matchSet);
else
properties = parent.getProperties(matchSet);
for (int i = 0; i < properties.size(); i++) {
Property prop = properties.get(i);
Message parentMsg = prop.getParentMessage();
if (prop.getValue().equals(value.value))
return parentMsg;
}
} catch (NavajoException e) {
throw new SystemException(-1, e.getMessage(), e);
}
return null;
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class SaxHandler method parseProperty.
private final void parseProperty(Map<String, String> h) throws NavajoException {
// logger.info("NAME: "+(String)h.get("name"));
String sLength = null;
String myName = h.get(Property.PROPERTY_NAME);
String myValue = h.get(Property.PROPERTY_VALUE);
String subType = h.get(Property.PROPERTY_SUBTYPE);
String description = h.get(Property.PROPERTY_DESCRIPTION);
String direction = h.get(Property.PROPERTY_DIRECTION);
String type = h.get(Property.PROPERTY_TYPE);
sLength = h.get(Property.PROPERTY_LENGTH);
String cardinality = h.get(Property.PROPERTY_CARDINALITY);
String extendsProp = h.get(Property.PROPERTY_EXTENDS);
String reference = h.get(Property.PROPERTY_REFERENCE);
String key = h.get(Property.PROPERTY_KEY);
String bind = h.get(Property.PROPERTY_BIND);
String method = h.get(Property.PROPERTY_METHOD);
Integer plength = null;
Property definitionProperty = null;
String subtype = null;
int length = 0;
try {
if (sLength != null) {
length = Integer.parseInt(sLength);
plength = Integer.valueOf(length);
}
} catch (Exception e1) {
// logger.info("ILLEGAL LENGTH IN PROPERTY " + myName + ": " +
// sLength);
}
if (myName == null) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without a name ");
}
boolean isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType) {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, cardinality, description, direction);
} else {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, type, myValue, length, description, direction, subtype);
}
if (messageStack.isEmpty()) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without being inside a message, probably an input error");
}
Message current = messageStack.peek();
current.addProperty(currentProperty);
BaseMessageImpl arrayParent = (BaseMessageImpl) current.getArrayParentMessage();
if (arrayParent != null && arrayParent.isArrayMessage()) {
definitionProperty = arrayParent.getPropertyDefinition(myName);
if (definitionProperty != null) {
if (description == null || "".equals(description)) {
description = definitionProperty.getDescription();
}
if (direction == null || "".equals(direction)) {
direction = definitionProperty.getDirection();
}
if (type == null || "".equals(type)) {
type = definitionProperty.getType();
}
if (plength == null) {
length = definitionProperty.getLength();
}
if (subType == null) {
if (definitionProperty.getSubType() != null) {
currentProperty.setSubType(definitionProperty.getSubType());
}
} else {
if (definitionProperty.getSubType() != null) {
/**
* Concatenated subtypes. The if the same key of a subtype is present
* in both the property and the definition property.
*/
currentProperty.setSubType(definitionProperty.getSubType() + "," + subType);
}
}
}
}
if (subType == null && NavajoFactory.getInstance().getDefaultSubtypeForType(type) != null) {
currentProperty.setSubType(NavajoFactory.getInstance().getDefaultSubtypeForType(type));
} else {
currentProperty.setSubType(subType);
}
if (type == null && current.isArrayMessage()) {
logger.info("Found undefined property: " + currentProperty.getName());
}
isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType && definitionProperty != null) {
if (cardinality == null) {
cardinality = definitionProperty.getCardinality();
}
type = Property.SELECTION_PROPERTY;
List<Selection> l = definitionProperty.getAllSelections();
for (int i = 0; i < l.size(); i++) {
BaseSelectionImpl s1 = (BaseSelectionImpl) l.get(i);
BaseSelectionImpl s2 = (BaseSelectionImpl) s1.copy(currentDocument);
currentProperty.addSelection(s2);
}
}
currentProperty.setType(type);
currentProperty.setDescription(description);
currentProperty.setDirection(direction);
currentProperty.setCardinality(cardinality);
currentProperty.setLength(length);
currentProperty.setExtends(extendsProp);
currentProperty.setKey(key);
currentProperty.setReference(reference);
currentProperty.setBind(bind);
currentProperty.setMethod(method);
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class SaxHandler method mergeDefinitionMessage.
private void mergeDefinitionMessage() {
Message currentMessage = messageStack.peek();
if (currentMessage == null) {
return;
}
Message parentMessage = currentMessage.getParentMessage();
if (parentMessage == null) {
return;
}
Message def = parentMessage.getDefinitionMessage();
if (def == null) {
return;
}
List<Property> props = def.getAllProperties();
for (int i = 0; i < props.size(); i++) {
Property src = props.get(i);
Property dest = currentMessage.getProperty(src.getName());
if (dest == null) {
dest = src.copy(currentDocument);
currentMessage.addProperty(dest);
}
}
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class SaxHandler method parseSelection.
private final void parseSelection(Map<String, String> h) throws NavajoException {
String name = h.get("name");
String value = h.get("value");
int selected = Integer.parseInt(h.get("selected"));
Property definitionProperty = null;
BaseMessageImpl arrayParent = (BaseMessageImpl) currentProperty.getParentMessage().getArrayParentMessage();
if (arrayParent != null) {
definitionProperty = arrayParent.getPropertyDefinition(currentProperty.getName());
}
if (definitionProperty == null || definitionProperty.getSelected().getName().equals(Selection.DUMMY_SELECTION) || currentProperty.getParentMessage().getType().equals(Message.MSG_TYPE_DEFINITION)) {
Selection s = NavajoFactory.getInstance().createSelection(currentDocument, name, value, selected != 0);
currentProperty.addSelection(s);
} else {
if (currentProperty.getSelectionByValue(value) != null && selected == 1) {
currentProperty.setSelectedByValue(value);
} else {
Selection s = NavajoFactory.getInstance().createSelection(currentDocument, name, value, selected != 0);
currentProperty.addSelection(s);
}
}
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class TMLSerializer method serializeMessage.
private final void serializeMessage(Message m, byte type, boolean hidePropertyName, OutputStream os) throws IOException {
os.write(serializeMessageTag(m.getName(), type));
for (Property p : m.getAllProperties()) {
serializeProperty(p, type, hidePropertyName, os);
}
int index = 0;
for (Message cm : m.getAllMessages()) {
byte childType = (cm.isArrayMessage() ? ARRAY_MESSAGE_CODE : m.isArrayMessage() ? ARRAY_MESSAGE_ELT_CODE : MESSAGE_CODE);
serializeMessage(cm, childType, (index > 0 && childType == ARRAY_MESSAGE_ELT_CODE), os);
index++;
}
os.write(MESSAGE_CLOSE_CODE);
}
Aggregations