public static void validateConnection(Edge edge) throws GraphException {
Port fromPort = edge.getFromPort();
Port toPort = edge.getToPort();
if (edge instanceof ControlEdge) {
if (!(fromPort instanceof ControlPort && toPort instanceof ControlPort)) {
throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
}
} else if (edge instanceof DataEdge) {
if (fromPort instanceof EPRPort) {
// TODO
return;
}
if (!(fromPort instanceof DataPort || fromPort instanceof EPRPort)
|| !(toPort instanceof DataPort)) {
throw new GraphException(MessageConstants.UNEXPECTED_ERROR);
}
DataPort fromDataPort = (DataPort) fromPort;
DataPort toDataPort = (DataPort) toPort;
QName fromType = fromDataPort.getType();
QName toType = toDataPort.getType();
if (toDataPort.getEdges().size() > 1) {
throw new GraphException(
MessageConstants.MORE_THAN_ONE_CONNECTIONS);
}
// if connection came from the CEP register component it should be
// ok
if (fromPort.getNode() instanceof WSNode) {
if ("registerStream".equals(((WSNode) fromPort.getNode())
.getOperationName())) {
return;
}
}
if (!(fromType == null
|| fromType.equals(WSConstants.XSD_ANY_TYPE)
|| fromType.equals(new QName(WSConstants.XSD_NS_URI,
"anyType"))
|| toType == null
|| toType.equals(WSConstants.XSD_ANY_TYPE)
|| toType.equals(new QName(WSConstants.XSD_NS_URI,
"anyType")) || fromType.equals(toType)) && (fromType == null
|| fromType.equals(WSConstants.LEAD_ANY_TYPE)
|| fromType.equals(new QName(WSConstants.LEAD_NS_URI,
"anyType"))
|| toType == null
|| toType.equals(WSConstants.LEAD_ANY_TYPE)
|| toType.equals(new QName(WSConstants.LEAD_NS_URI,
"anyType")) || fromType.equals(toType))) {
throw new GraphException(
"Cannot connect ports with different types:"
+ " \nfrom=\t" + fromType + " \nto=\t" + toType
+ "");
}
}