public NodeData(String id, Object node, String imagePrefix) {
this.id = id;
this.imagePrefix = imagePrefix;
if (node instanceof ProcessorDefinition) {
ProcessorDefinition processorType = (ProcessorDefinition)node;
this.edgeLabel = processorType.getLabel();
}
if (node instanceof FromDefinition) {
FromDefinition fromType = (FromDefinition)node;
this.tooltop = fromType.getLabel();
this.label = removeQueryString(this.tooltop);
this.url = "http://camel.apache.org/message-endpoint.html";
} else if (node instanceof ToDefinition) {
ToDefinition toType = (ToDefinition)node;
this.tooltop = toType.getLabel();
this.label = removeQueryString(this.tooltop);
this.edgeLabel = "";
this.url = "http://camel.apache.org/message-endpoint.html";
} else if (node instanceof FilterDefinition) {
this.image = imagePrefix + "MessageFilterIcon.png";
this.label = "Filter";
this.nodeType = "Message Filter";
} else if (node instanceof WhenDefinition) {
this.image = imagePrefix + "MessageFilterIcon.png";
this.nodeType = "When Filter";
this.label = "When";
this.url = "http://camel.apache.org/content-based-router.html";
} else if (node instanceof OtherwiseDefinition) {
this.nodeType = "Otherwise";
this.edgeLabel = "";
this.url = "http://camel.apache.org/content-based-router.html";
this.tooltop = "Otherwise";
} else if (node instanceof ChoiceDefinition) {
this.image = imagePrefix + "ContentBasedRouterIcon.png";
this.nodeType = "Content Based Router";
this.label = "Choice";
this.edgeLabel = "";
ChoiceDefinition choice = (ChoiceDefinition)node;
List<ProcessorDefinition> outputs = new ArrayList<ProcessorDefinition>(choice.getWhenClauses());
if (choice.getOtherwise() != null) {
outputs.add(choice.getOtherwise());
}
this.outputs = outputs;
} else if (node instanceof RecipientListDefinition) {
this.image = imagePrefix + "RecipientListIcon.png";
this.nodeType = "Recipient List";
} else if (node instanceof RoutingSlipDefinition) {
this.image = imagePrefix + "RoutingTableIcon.png";
this.nodeType = "Routing Slip";
this.url = "http://camel.apache.org/routing-slip.html";
this.tooltop = ((RoutingSlipDefinition) node).getHeaderName();
} else if (node instanceof SplitDefinition) {
this.image = imagePrefix + "SplitterIcon.png";
this.nodeType = "Splitter";
} else if (node instanceof AggregateDefinition) {
this.image = imagePrefix + "AggregatorIcon.png";
this.nodeType = "Aggregator";
} else if (node instanceof ResequenceDefinition) {
this.image = imagePrefix + "ResequencerIcon.png";
this.nodeType = "Resequencer";
} else if (node instanceof BeanDefinition) {
BeanDefinition beanRef = (BeanDefinition) node;
// TODO
//this.image = imagePrefix + "Bean.png";
this.nodeType = "Bean Ref";
this.label = beanRef.getLabel() + " Bean";
this.shape = "box";
}
// lets auto-default as many values as we can
if (isEmpty(this.nodeType) && node != null) {
// TODO we could add this to the model?
String name = node.getClass().getName();
int idx = name.lastIndexOf('.');
if (idx > 0) {
name = name.substring(idx + 1);
}
if (name.endsWith("Type")) {
name = name.substring(0, name.length() - 4);
}
this.nodeType = insertSpacesBetweenCamelCase(name);
}
if (this.label == null) {
if (isEmpty(this.image)) {
this.label = this.nodeType;
this.shape = "box";
} else if (isNotEmpty(this.edgeLabel)) {
this.label = "";
} else {
this.label = node.toString();
}
}
if (isEmpty(this.tooltop)) {
if (isNotEmpty(this.nodeType)) {
String description = isNotEmpty(this.edgeLabel) ? this.edgeLabel : this.label;
this.tooltop = this.nodeType + ": " + description;
} else {
this.tooltop = this.label;
}
}
if (isEmpty(this.url) && isNotEmpty(this.nodeType)) {
this.url = "http://camel.apache.org/" + this.nodeType.toLowerCase().replace(' ', '-') + ".html";
}
if (node instanceof ProcessorDefinition && this.outputs == null) {
ProcessorDefinition processorType = (ProcessorDefinition)node;
this.outputs = processorType.getOutputs();
}
}