All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.popper.fw.impl.CycleException Maven / Gradle / Ivy

Go to download

Definition of the interfaces all Popper Framework implementations depend on

The newest version!
/*
 * This file is part of a Werum IT Solutions GmbH project.
 *
 * Copyright (c)
 *    Werum IT Solutions GmbH
 *    All rights reserved.
 *
 * This source file may be managed in different Java package structures,
 * depending on actual usage of the source file by the Copyright holders:
 *
 * for Werum:  com.werum.* or any other Werum owned Internet domain
 *
 * Any use of this file as part of a software system by none Copyright holders
 * is subject to license terms.
 *
 * Last Change: $Id: CycleException.java 178834 2016-09-12 14:01:01Z ditmar_goenen $
 */
package org.popper.fw.impl;

import java.lang.annotation.Annotation;
import java.util.Iterator;
import java.util.Set;

import org.jgrapht.alg.CycleDetector;
import org.jgrapht.graph.DefaultEdge;

/**
 * Exception thrown if {@link PageObjectImplementation} detects a cycle in
 * dependency tree
 *
 * @author Michael
 */
public class CycleException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	public CycleException(CycleDetector cycleDetector) {
        super("found cycle in Lifecycle management: " + cycleToString(cycleDetector));
    }

    private static String cycleToString(CycleDetector cycleDetector) {
        StringBuilder builder = new StringBuilder();

        // Get all vertices involved in cycles.
        Set cycleVertices = cycleDetector.findCycles();

        // Loop through vertices trying to find disjoint cycles.
        while (!cycleVertices.isEmpty()) {
            // Get a vertex involved in a cycle.
            Iterator iterator = cycleVertices.iterator();

            // Get all vertices involved with this vertex.
            Set subCycle = cycleDetector.findCyclesContainingVertex(iterator.next());
            for (Annotation sub : subCycle) {
                builder.append(" -> " + sub);
                cycleVertices.remove(sub);
            }
        }

        return builder.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy