krysalis-version/src/java/org/krysalis/version/constraint/impl VersionIdentifierConstraint.java,NONE,1.1 VersionDataConstraint.java,NONE,1.1 VersionDataComparisonConstraint.java,NONE,1.1 VersionDataRangeConstraint.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/impl
In directory sc8-pr-cvs1:/tmp/cvs-serv19694/src/java/org/krysalis/version/constraint/impl

Added Files:
	VersionIdentifierConstraint.java VersionDataConstraint.java 
	VersionDataComparisonConstraint.java 
	VersionDataRangeConstraint.java 
Log Message:
Making constraint processing more descriptive

--- NEW FILE: VersionIdentifierConstraint.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.impl;

import java.io.PrintWriter;

import org.krysalis.version.constraint.Constraint;
import org.krysalis.version.constraint.ConstraintConclusion;
import org.krysalis.version.constraint.result.ConstraintResult;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.internal.VersionIdentifier;
import org.krysalis.version.resolve.VersionMetadata;
import org.krysalis.version.resolve.VersionResolver;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.note.AnnotationScratchpad;

/**
 * @author ajack
 */
public abstract class VersionIdentifierConstraint implements Constraint {
    protected VersionIdentifier m_identifier = null;

    public VersionIdentifierConstraint(VersionIdentifier dependentVersion) {
        m_identifier = dependentVersion;
    }

    /**
     * 
     * If we can resolve it, we have it most certinaly, if not --- it
     * just  might not be version friendly.
     * 
     * @see org.krysalis.version.constraint.Constraint#check()
     */
    public ConstraintResult check() throws VersionException {
        AnnotationScratchpad pad = new AnnotationScratchpad();

        String message = "Version [" + m_identifier + "] not found";

        VersionMetadata ref =
            VersionResolver.getResolver().resolve(m_identifier);

        int severity = ConstraintResult.WARNING;
        ConstraintConclusion conclusion =
            ConstraintConclusion.UNCERTAINLY_UNSATISFIED;

        if (null != ref) {
            severity = ConstraintResult.INFORMATION;
            conclusion = ConstraintConclusion.CERTAINLY_SATISFIED;
            message =
                "Version ["
                    + m_identifier
                    + "] found as ["
                    + ref.getVersion()
                    + "]";
        }

        return new ConstraintResult(severity, message, this, conclusion, pad);
    }

    /**
     * Returns the identifier.
     * @return VersionIdentifier
     */
    public VersionIdentifier getIdentifier() {
        return m_identifier;
    }

    /**
     * Sets the identifier.
     * @param identifier The identifier to set
     */
    public void setIdentifier(VersionIdentifier identifier) {
        m_identifier = identifier;
    }

    public String toString() {
        return DebugUtils.getShortName(getClass()) + " : " + m_identifier;
    }

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

        out.print(indent);
        out.print("Constraint: ");
        out.println(DebugUtils.getShortName(getClass()));

        out.print(indent);
        out.print("Identifier: ");
        out.println(m_identifier);
    }
}

--- NEW FILE: VersionDataConstraint.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.impl;

import org.krysalis.version.internal.VersionIdentifier;
import org.krysalis.version.internal.data.VersionData;

/**
 * @author ajack
 */
public abstract class VersionDataConstraint extends VersionIdentifierConstraint {
    private VersionData m_data = null;

    public VersionDataConstraint(
        VersionIdentifier identifier,
        VersionData data) {
        super(identifier);

        m_data = data;
    }
}

--- NEW FILE: VersionDataComparisonConstraint.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.impl;

import java.io.PrintWriter;

import org.krysalis.version.Version;
import org.krysalis.version.constraint.ConstraintConclusion;
import org.krysalis.version.constraint.result.ConstraintResult;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.internal.VersionIdentifier;
import org.krysalis.version.internal.data.VersionData;
import org.krysalis.version.internal.data.util.VersionDataComparison;
import org.krysalis.version.resolve.VersionMetadata;
import org.krysalis.version.resolve.VersionResolver;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.note.AnnotationScratchpad;

/**
 * @author ajack
 */
public class VersionDataComparisonConstraint
    extends VersionIdentifierConstraint {
    private VersionDataComparison m_comparison = null;

    public VersionDataComparisonConstraint(
        VersionIdentifier identifier,
        VersionDataComparison comparison) {
        super(identifier);

        m_comparison = comparison;
    }

    /**
     * @see org.apache.commons.version.model.constraint.Constraint#resolve()
     */
    public ConstraintResult check() throws VersionException {
        AnnotationScratchpad pad = new AnnotationScratchpad();

        VersionMetadata ref =
            VersionResolver.getResolver().resolve(m_identifier);

        int severity = ConstraintResult.WARNING;
        String message = "Version [" + m_identifier + "] not found";
        ConstraintConclusion conclusion =
            ConstraintConclusion.UNCERTAINLY_UNSATISFIED;

        if (null != ref) {

            Version resolvedVersion = ref.getVersion();
            if (null != resolvedVersion) {
                
                message =
                    "Version [" + m_identifier + "] found as [" + resolvedVersion + "]";

                if (m_comparison.evaluate(new VersionData(resolvedVersion))) {

                    severity = ConstraintResult.INFORMATION;
                    conclusion = ConstraintConclusion.CERTAINLY_SATISFIED;
                }
                else {
                    severity = ConstraintResult.ERROR;
                    conclusion = ConstraintConclusion.CERTAINLY_UNSATISFIED;
                }
            }
        }

        return new ConstraintResult(severity, message, this, conclusion, pad);
    }

    public String toString() {
        return super.toString() + " : " + m_comparison;
    }

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

        super.dump(out,depth);

        out.print(indent);
        out.print("Comparison: ");
        out.println(m_comparison);
    }
}

--- NEW FILE: VersionDataRangeConstraint.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.impl;

import java.io.PrintWriter;

import org.krysalis.version.Version;
import org.krysalis.version.constraint.ConstraintConclusion;
import org.krysalis.version.constraint.result.ConstraintResult;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.internal.VersionIdentifier;
import org.krysalis.version.internal.data.VersionData;
import org.krysalis.version.internal.data.util.VersionDataRange;
import org.krysalis.version.resolve.VersionMetadata;
import org.krysalis.version.resolve.VersionResolver;
import org.krysalis.version.util.debug.DebugUtils;
import org.krysalis.version.util.note.AnnotationScratchpad;

/**
 * @author ajack
 */
public class VersionDataRangeConstraint extends VersionIdentifierConstraint {
    private VersionDataRange m_range = null;

    public VersionDataRangeConstraint(
        VersionIdentifier identifier,
        VersionDataRange range) {
        super(identifier);

        m_range = range;
    }

    /**
     * @see org.apache.commons.version.model.constraint.Constraint#resolve()
     */
    public ConstraintResult check() throws VersionException {
        AnnotationScratchpad pad = new AnnotationScratchpad();

        String message = "Version [" + m_identifier + "] not found";
        int severity = ConstraintResult.WARNING;
        ConstraintConclusion conclusion =
            ConstraintConclusion.UNCERTAINLY_UNSATISFIED;

        VersionMetadata ref =
            VersionResolver.getResolver().resolve(m_identifier);

        if (null != ref) {
            Version resolvedVersion = ref.getVersion();
            if (null != resolvedVersion) {
                message =
                    "Version ["
                        + m_identifier
                        + "] found as ["
                        + resolvedVersion
                        + "]";
                        
                if (m_range.inRange(new VersionData(resolvedVersion))) {
                    conclusion = ConstraintConclusion.CERTAINLY_SATISFIED;
                    severity = ConstraintResult.INFORMATION;
                    message += " and is in range";
                }
                else {
                    conclusion = ConstraintConclusion.CERTAINLY_UNSATISFIED;
                    severity = ConstraintResult.ERROR;
                    message += " but is not in range";
                }
            }
        }

        return new ConstraintResult(severity, message, this, conclusion, pad);

    }

    public String toString() {
        return super.toString() + ":" + m_range;
    }

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

        out.print(indent);
        out.print("Constraint: ");
        out.println(DebugUtils.getShortName(getClass()));

        out.print(indent);
        out.print("Identifier: ");
        out.println(m_identifier);
    }
}




-------------------------------------------------------
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.