public static String getUri(ToDefinition input) {
   String key = input.getUri();
   if (Strings2.isEmpty(key)) {
     String ref = input.getRef();
     if (!Strings2.isEmpty(ref)) {
       return "ref:" + ref;
     }
   }
   return key;
 }
 public static String getExchangePattern(ToDefinition input) {
   String pattern = input.getPattern() != null ? input.getPattern().name() : null;
   if (Strings2.isEmpty(pattern)) {
     return null;
   }
   return pattern;
 }
  /** Returns the summary label of a node for visualisation purposes */
  public static String getDisplayText(OptionalIdentifiedDefinition camelNode) {
    String id = camelNode.getId();
    if (!Strings2.isEmpty(id)) {
      return id;
    }
    if (camelNode instanceof FromDefinition) {
      FromDefinition node = (FromDefinition) camelNode;
      return getUri(node);
    } else if (camelNode instanceof ToDefinition) {
      ToDefinition node = (ToDefinition) camelNode;
      return getUri(node);
    } else if (camelNode instanceof BeanDefinition) {
      BeanDefinition node = (BeanDefinition) camelNode;
      return "bean " + getOrBlank(node.getRef());
    } else if (camelNode instanceof CatchDefinition) {
      CatchDefinition node = (CatchDefinition) camelNode;
      List exceptions = node.getExceptions();
      if (exceptions != null && exceptions.size() > 0) {
        return "catch " + exceptions;
      } else {
        return "catch " + Expressions.getExpressionOrElse(node.getHandled());
      }
    } else if (camelNode instanceof ChoiceDefinition) {
      return "choice";
    } else if (camelNode instanceof ConvertBodyDefinition) {
      ConvertBodyDefinition node = (ConvertBodyDefinition) camelNode;
      return "convertBody " + getOrBlank(node.getType());
    } else if (camelNode instanceof EnrichDefinition) {
      EnrichDefinition node = (EnrichDefinition) camelNode;
      // return "enrich " + getOrBlank(node.getResourceUri());
      return "enrich " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof FinallyDefinition) {
      return "finally";
    } else if (camelNode instanceof InOnlyDefinition) {
      InOnlyDefinition node = (InOnlyDefinition) camelNode;
      return "inOnly " + getOrBlank(node.getUri());
    } else if (camelNode instanceof InOutDefinition) {
      InOutDefinition node = (InOutDefinition) camelNode;
      return "inOut " + getOrBlank(node.getUri());
    } else if (camelNode instanceof InterceptSendToEndpointDefinition) {
      InterceptSendToEndpointDefinition node = (InterceptSendToEndpointDefinition) camelNode;
      return "intercept " + getOrBlank(node.getUri());
    } else if (camelNode instanceof LogDefinition) {
      LogDefinition node = (LogDefinition) camelNode;
      return "log " + getOrBlank(node.getLogName());
    } else if (camelNode instanceof MarshalDefinition) {
      return "marshal";
    } else if (camelNode instanceof OnExceptionDefinition) {
      OnExceptionDefinition node = (OnExceptionDefinition) camelNode;
      return "on exception " + getOrBlank(node.getExceptions());
    } else if (camelNode instanceof OtherwiseDefinition) {
      return "otherwise";
    } else if (camelNode instanceof PollEnrichDefinition) {
      PollEnrichDefinition node = (PollEnrichDefinition) camelNode;
      // TODO
      // return "poll enrich " + getOrBlank(node.getResourceUri());
      return "poll enrich " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof RemoveHeaderDefinition) {
      RemoveHeaderDefinition node = (RemoveHeaderDefinition) camelNode;
      return "remove header " + getOrBlank(node.getHeaderName());
    } else if (camelNode instanceof RemovePropertyDefinition) {
      RemovePropertyDefinition node = (RemovePropertyDefinition) camelNode;
      return "remove property " + getOrBlank(node.getPropertyName());
    } else if (camelNode instanceof RollbackDefinition) {
      RollbackDefinition node = (RollbackDefinition) camelNode;
      return "rollback " + getOrBlank(node.getMessage());
    } else if (camelNode instanceof SetExchangePatternDefinition) {
      SetExchangePatternDefinition node = (SetExchangePatternDefinition) camelNode;
      ExchangePattern pattern = node.getPattern();
      if (pattern == null) {
        return "setExchangePattern";
      } else {
        return "set " + pattern;
      }
    } else if (camelNode instanceof SortDefinition) {
      SortDefinition node = (SortDefinition) camelNode;
      return "sort " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof WhenDefinition) {
      WhenDefinition node = (WhenDefinition) camelNode;
      return "when " + Expressions.getExpressionOrElse(node.getExpression());
    } else if (camelNode instanceof UnmarshalDefinition) {
      return "unmarshal";
    } else if (camelNode instanceof TryDefinition) {
      return "try";
    } else if (camelNode instanceof LoadBalanceDefinition) {
      LoadBalanceDefinition load = (LoadBalanceDefinition) camelNode;
      return load.getShortName();
      /*
                  TODO

         			if (load.getRef() != null) {
         				return "custom " + getOrBlank(load.getRef());
         			} else if (load.getLoadBalancerType() != null) {
         				if (load.getLoadBalancerType().getClass().isAssignableFrom(CustomLoadBalancerDefinition.class)) {
         					CustomLoadBalancerDefinition custom = (CustomLoadBalancerDefinition) load.getLoadBalancerType();
         					return "custom " + getOrBlank(custom.getRef());
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(FailoverLoadBalancerDefinition.class)) {
         					return "failover";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(RandomLoadBalancerDefinition.class)) {
         					return "random";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(RoundRobinLoadBalancerDefinition.class)) {
         					return "round robin";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(StickyLoadBalancerDefinition.class)) {
         					return "sticky";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(TopicLoadBalancerDefinition.class)) {
         					return "topic";
         				} else if (load.getLoadBalancerType().getClass().isAssignableFrom(WeightedLoadBalancerDefinition.class)) {
         					return "weighted";
         				}
         			} else {
         				return "load balance";
         			}
      */
    }

    String answer = null;
    try {
      answer = camelNode.getLabel();
    } catch (Exception e) {
      // ignore errors in Camel
    }
    if (Strings2.isBlank(answer)) {
      answer = getPatternName(camelNode);
    }
    return answer;
  }
 public static String getOrBlank(String text) {
   return Strings2.isEmpty(text) ? "" : text;
 }