krysalis-version/src/java/org/krysalis/version/constraint/result ConstraintResult.java,NONE,1.1 ConstraintResultSet.java,NONE,1.1

[email protected]
Newsgroups gmane.comp.krysalis.sandbox
Message-ID <[email protected]>
Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/constraint/result
In directory sc8-pr-cvs1:/tmp/cvs-serv18085/src/java/org/krysalis/version/constraint/result

Added Files:
	ConstraintResult.java ConstraintResultSet.java 
Log Message:
1) Refactored some shared behaviours
2) Worked on constraints colelcting/evaluating/result sets...

--- NEW FILE: ConstraintResult.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.constraint.result;

import java.io.PrintWriter;

import org.krysalis.version.constraint.Constraint;
import org.krysalis.version.constraint.ConstraintConclusion;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.debug.Dumpable;
import org.krysalis.version.util.note.AnnotationScratchpad;

/**
 *
 * @author $Author: arb_jack $
 * @version $Revision: 1.1 $
 * 
 */
public class ConstraintResult implements Dumpable {

    static final int UNSET = 0;
    static final int INFORMATION = 1;
    static final int WARNING = 2;
    static final int ERROR = 3;

    private int m_severity = UNSET;
    private String m_message = null;
    private Constraint m_constraint = null;
    private ConstraintConclusion m_conclusion = null;
    private AnnotationScratchpad m_pad = null;

    public ConstraintResult(
        int severity,
        String message,
        Constraint constraint,
        ConstraintConclusion conclusion,
        AnnotationScratchpad pad) {
        m_severity = severity;
        m_message = message;
        m_constraint = constraint;
        m_conclusion = conclusion;
        m_pad = pad;
    }

    /**
     * Returns the conclusion.
     * @return ConstraintConclusion
     */
    public ConstraintConclusion getConclusion() {
        return m_conclusion;
    }

    /**
     * Returns the constraint.
     * @return Constraint
     */
    public Constraint getConstraint() {
        return m_constraint;
    }

    /**
     * Returns the pad.
     * @return AnnotationScratchpad
     */
    public AnnotationScratchpad getPad() {
        return m_pad;
    }

    /**
     * Sets the conclusion.
     * @param conclusion The conclusion to set
     */
    public void setConclusion(ConstraintConclusion conclusion) {
        m_conclusion = conclusion;
    }

    /**
     * Sets the constraint.
     * @param constraint The constraint to set
     */
    public void setConstraint(Constraint constraint) {
        m_constraint = constraint;
    }

    /**
     * Sets the pad.
     * @param pad The pad to set
     */
    public void setPad(AnnotationScratchpad pad) {
        m_pad = pad;
    }

    /**
     * Returns the severity.
     * @return int
     */
    public int getSeverity() {
        return m_severity;
    }

    /**
     * Sets the severity.
     * @param severity The severity to set
     */
    public void setSeverity(int severity) {
        m_severity = severity;
    }
    /**
     * Returns the message.
     * @return String
     */
    public String getMessage() {
        return m_message;
    }

    /**
     * Sets the message.
     * @param message The message to set
     */
    public void setMessage(String message) {
        m_message = message;
    }

    public String getSeverityAsString() {
        String str = "unset";

        switch (m_severity) {
            case INFORMATION :
                {
                    str = "INFORMATION";
                    break;
                }
            case WARNING :
                {
                    str = "WARNING";
                    break;
                }
            case ERROR :
                {
                    str = "ERROR";
                    break;
                }
        }

        return str;
    }

    public void dump(PrintWriter out, int depth) {
        String indent = DebugUtils.getIndent(depth);

        out.print(indent);
        out.print("Severity: ");
        out.println(getSeverityAsString());

        out.print(indent);
        out.print("Constraint: ");
        out.println(m_constraint);

        out.print(indent);
        out.print("Conclusion: ");
        out.println(m_conclusion);

        if (null != m_pad && m_pad.hasAnnotations()) {
            out.print(indent);
            out.print("Notes: ");
            m_pad.dump(out, depth + 1);
        }
    }
}

--- NEW FILE: ConstraintResultSet.java ---
/*
The Krysalis Patchy Software License, Version 1.1_01

Copyright (c) 2002-2003 Nicola Ken Barozzi.  All rights reserved.

This Licence is compatible with the BSD licence as described and 
approved by http://www.opensource.org/, and is based on the
Apache Software Licence Version 1.1.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in
   the documentation and/or other materials provided with the
   distribution.

3. The end-user documentation included with the redistribution,
   if any, must include the following acknowledgment:
      "This product includes software developed for project
       Krysalis (http://www.krysalis.org/)."
   Alternately, this acknowledgment may appear in the software itself,
   if and wherever such third-party acknowledgments normally appear.

4. The names "Krysalis" and "Nicola Ken Barozzi" and
   "Krysalis Centipede" must not be used to endorse or promote products
   derived from this software without prior written permission. For
   written permission, please contact [email protected].

5. Products derived from this software may not be called "Krysalis",
   "Krysalis Centipede", nor may "Krysalis" appear in their name, without
    prior written permission of Nicola Ken Barozzi.

6. This software may contain voluntary contributions made by many 
   individuals, who decided to donate the code to this project in respect 
   of this licence.

THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
====================================================================
*/
package org.krysalis.version.constraint.result;

import java.util.Collection;

import org.krysalis.version.constraint.Constraint;
import org.krysalis.version.constraint.ConstraintConclusion;
import org.krysalis.version.util.collection.EntityList;
import org.krysalis.version.util.note.AnnotationScratchpad;

/**
 *
 * @author $Author: arb_jack $
 * @version $Revision: 1.1 $
 * 
 */
public class ConstraintResultSet extends EntityList {

    /**
     * Constructor for ConstraintResultSet.
     * @param name
     * @param initialCapacity
     */
    public ConstraintResultSet(int initialCapacity) {
        super("Constraint Result Set", initialCapacity);
    }

    /**
     * Constructor for ConstraintResultSet.
     * @param "Constraint Result Set"
     */
    public ConstraintResultSet() {
        super("Constraint Result Set");
    }

    /**
     * Constructor for ConstraintResultSet.
     * @param "Constraint Result Set"
     * @param c
     */
    public ConstraintResultSet(Collection c) {
        super("Constraint Result Set", c);
    }

    public void addError(
        String message,
        Constraint constraint,
        ConstraintConclusion conclusion,
        AnnotationScratchpad pad) {
        add(
            new ConstraintResult(
                ConstraintResult.ERROR,
                message,
                constraint,
                conclusion,
                pad));
    }

    public void addWarning(
        String message,
        Constraint constraint,
        ConstraintConclusion conclusion,
        AnnotationScratchpad pad) {
        add(
            new ConstraintResult(
                ConstraintResult.WARNING,
                message,
                constraint,
                conclusion,
                pad));
    }

    public void addInformation(
        String message,
        Constraint constraint,
        ConstraintConclusion conclusion,
        AnnotationScratchpad pad) {
        add(
            new ConstraintResult(
                ConstraintResult.INFORMATION,
                message,
                constraint,
                conclusion,
                pad));
    }

    public void add(
        int severity,
        String message,
        Constraint constraint,
        ConstraintConclusion conclusion,
        AnnotationScratchpad pad) {
        add(
            new ConstraintResult(
                severity,
                message,
                constraint,
                conclusion,
                pad));
    }

    public void addResultSet(ConstraintResultSet set) {
        addAll(set);
    }
}




-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger 
for complex code. Debugging C/C++ programs can leave you feeling lost and 
disoriented. TotalView can help you find your way. Available on major UNIX 
and Linux platforms. Try it free. www.etnus.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.