protected void buildDefinition() {

        StartEvent startEvent = getStartEvent();
        EndEvent endEvent = getEndEvent();

        if (startEvent == null || endEvent == null) {
            throw new ASFModelException("The definition must have a StartEvent and a EndEvent.");
        }


        for (Flow flow : flows) {
            Node source = getNode(flow.getSourceRef());
            Node target = getNode(flow.getTargetRef());

            if (source == null) {
                throw new ASFModelException("Not found the source node :" + flow.getSourceRef());
            }

            if (target == null) {
                throw new ASFModelException("Not found the target node :" + flow.getTargetRef());
            }

            // no circle
            if (source == target) {
                throw new ASFModelException("Forbidden circle reference!(sourceRef=" + source.getId() + "," +
                        "targetRef=" + target.getId() + ")");
            }

            if (source == endEvent) {
                throw new ASFModelException("The flow sourceRef can not be EndEvent.");
            }

            if (target == startEvent) {
                throw new ASFModelException("The flow targetRef can not be StartEvent.");
            }
            source.addSuccessor(flow, target);
        }

        // validate model
        validateModel();
    }