krysalis-version/src/java/org/krysalis/version/impl/apache ApacheVersionFormat.java,NONE,1.1 ApacheVersionComparator.java,NONE,1.1 ApacheVersionMarker.java,NONE,1.1 ApacheVersion.java,NONE,1.1 ApacheVersionSpecification.java,NONE,1.1

Nick Chalko <[email protected]> Tue, 09 Nov 2004 06:40:31 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/impl/apache
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20857/src/java/org/krysalis/version/impl/apache

Added Files:
	ApacheVersionFormat.java ApacheVersionComparator.java 
	ApacheVersionMarker.java ApacheVersion.java 
	ApacheVersionSpecification.java 
Log Message:
Mucho Refactoring.

--- NEW FILE: ApacheVersionMarker.java ---
package org.krysalis.version.impl.apache;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.krysalis.version.Version;
import org.krysalis.version.VersionConstants;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionFormat;
import org.krysalis.version.VersionIdentifier;
import org.krysalis.version.VersionSpecification;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author [email protected]
 */
public class ApacheVersionMarker implements org.krysalis.version.VersionMarker {

	public final static String VERSION_MARKER_TAG = "versionMarker";

	public final static String VERSION_ID_ATTRIBUTE = "versionId";

	private static final Map l_parts = new HashMap();
	static {
		l_parts.put(ApacheVersion.VERSION_TAG, ApacheVersion.class);
	}

	private VersionIdentifier m_identifier;

	private ApacheVersion m_version;

	public final static VersionFormat FORMAT = new ApacheVersionFormat();

	/** Extended Optional Settings... */
	//:TODO: final on these two?
	private Map m_attributes = null;

	private List m_annotations = null;

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(ApacheVersionMarker other) {
		super();

		m_identifier = other.m_identifier;
		m_version = other.m_version;

		validate();
	}

	/**
	 * Constructor for ApacheVersion.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(VersionIdentifier id, ApacheVersion version) {
		m_identifier = id;
		m_version = version;
		validate();
	}

	public Map importProperties(Map properties) throws VersionException {
		return m_version.importProperties(properties);
	}

	public String getId() {
		return m_identifier.toString();
	}

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

	public Version getVersion() {
		return m_version;
	}

	public ApacheVersion getApacheVersion() {
		return m_version;
	}

	// :TODO: Nick, let me complete 'MASK' in format first
	// :TODO: Nick, this really a description?
	// Please let me complete 'MASK' in format first
	public String getLongVersion() {
		return FORMAT.format(m_version.getData(), VersionFormat.LONG);
	}

	//  Please let me complete 'MASK' in format first
	public String getShortVersion() {
		return FORMAT.format(m_version.getData(), VersionFormat.SHORT);
	}

	public int hashCode() {
		int hashCode = 0;

		if (null != m_identifier)
			hashCode = m_identifier.hashCode();

		if (null != m_version)
			hashCode += m_version.hashCode();

		return hashCode;
	}

	public boolean equals(Object other) {
		boolean equal = false;

		if (other instanceof ApacheVersionMarker) {
			ApacheVersionMarker otherVersionMarker = (ApacheVersionMarker) other;

			equal = otherVersionMarker.m_identifier.equals(m_identifier);

			if (equal)
				equal = otherVersionMarker.m_version.equals(m_version);
		} else
			throw new IllegalArgumentException("Not a ApacheVersionMarker: "
					+ other.getClass() + " : " + other.toString());

		return equal;
	}

	public int compareTo(Object other) {
		int comparison = -1;

		if (other instanceof ApacheVersionMarker) {
			ApacheVersionMarker otherVersionMarker = (ApacheVersionMarker) other;

			comparison = otherVersionMarker.m_identifier
					.compareTo(m_identifier);

			if (0 == comparison)
				comparison = otherVersionMarker.m_version.compareTo(m_version);
		} else
			throw new IllegalArgumentException("Not a ApacheVersionMarker: "
					+ other.getClass() + " : " + other.toString());

		return comparison;
	}

	public String toString() {

		String v = FORMAT.toVersionString(m_version.getData());
		return m_identifier + " version " + v;
	}

	public void dump(PrintWriter out, int depth, boolean verbose) {
		final String indent = "    ";

		if (verbose) {

			if (null != m_identifier)
				m_identifier.dump(out, depth + 1, verbose);

			if (null != m_version)
				m_version.dump(out, depth + 1, verbose);

			if (null != m_annotations) {
				for (Iterator ai = m_annotations.iterator(); ai.hasNext();) {
					Object note = ai.next();
					out.println(" - " + note.toString());
				}
			}

			if (null != m_attributes) {
				for (Iterator ai = m_attributes.keySet().iterator(); ai
						.hasNext();) {
					Object key = ai.next();
					Object value = m_attributes.get(key);

					out.println(" - " + key + " -> [" + value.toString() + "]");
				}
			}
		} else {
			out.print(indent);
			out.print(m_identifier.toString());
			out.print(" : ");
			out.println(m_version.toString());

			if (null != m_attributes) {
				out.print(indent);
				out.print("Attributes :");
				out.println(m_attributes);
			}

			if (null != m_annotations) {
				out.print(indent);
				out.print("Annotations :");
				out.println(m_annotations);
			}
		}
	}

	/**
	 * Returns the attributes.
	 * 
	 * @return Map
	 */
	public Map getAttributes() {
		return m_attributes;
	}

	/**
	 * Sets the attributes.
	 * 
	 * @param attributes
	 *            The attributes to set
	 */
	public void setAttributes(Map attributes) {
		m_attributes = attributes;
	}

	public void setAttribute(String key, Object value) {
		if (null == m_attributes)
			m_attributes = new HashMap();

		m_attributes.put(key, value);
	}

	public Object getAttribute(String key) {
		Object value = null;

		if (null != m_attributes)
			value = m_attributes.get(key);

		return value;
	}

	public String getAttributeAsString(String key) {
		Object value = null;

		if (null != m_attributes)
			value = m_attributes.get(key);

		return ((null != value) ? value.toString() : null);
	}

	public void addAnnotation(Object note) {
		if (null == m_annotations)
			m_annotations = new ArrayList();

		m_annotations.add(note);
	}

	/**
	 * Returns the annotations.
	 * 
	 * @return List
	 */
	public List getAnnotations() {
		return m_annotations;
	}

	/**
	 * Sets the annotations.
	 * 
	 * @param annotations
	 *            The annotations to set
	 */
	public void setAnnotations(List annotations) {
		m_annotations = annotations;
	}

	private void validate() {
		if (null == m_identifier) {
			throw new IllegalArgumentException("Invalid (null) identifier");
		}
		//m_identifier.validate();

		if (null == m_version) {
			throw new IllegalArgumentException("Invalid (null) version");
		}
		m_version.validate();
	}

	

	/**
	 * The Date this version was Built.
	 * 
	 * @return the Date the version was Built
	 */
	public Date getBuildDate() {
		return (Date) m_attributes.get(VersionConstants.BUILD_DATETIME);
	}



	public void consumeDOMElement(String tag, Element element) {
	}

	public void consumeDOMObject(String tag, Object object) {
		if (object instanceof ApacheVersion)
			m_version = (ApacheVersion) object;
	}

	
}


--- NEW FILE: ApacheVersionFormat.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.version.impl.apache;
import java.util.Date;
import java.util.StringTokenizer;

import org.apache.depot.common.log.Logger;
import org.apache.depot.version.Version;
import org.apache.depot.version.impl.ApacheVersion;
import org.apache.depot.version.impl.VersionImplementationConstants;
import org.apache.depot.version.impl.data.ReleaseLevel;
import org.apache.depot.version.impl.data.VersionData;
import org.apache.depot.version.impl.data.VersionDataElement;
import org.apache.depot.version.impl.data.VersionDataElementSet;
import org.apache.depot.version.specification.formatting.VersionFormat;
import org.apache.depot.version.specification.formatting.VersionFormatException;
import org.krysalis.version.impl.VersionFormatImpl;

/**
 * @author ajack
 */
public class ApacheVersionFormat extends VersionFormatImpl {
	//:TODO: Make it sensetive to elements...
	private VersionDataElementSet m_elements = null;

	public ApacheVersionFormat() {
		m_elements = VersionDataElementSet.DEFAULT;
	}

	public ApacheVersionFormat(int elementMask) {
		m_elements = new VersionDataElementSet(elementMask);
	}

	public String getFormatId() {
		return org.krysalis.version.impl.VersionImplementationConstants.VERSION_PACKAGE;
	}

	public String getVersionFormatVersion() {
		return org.krysalis.version.impl.VersionImplementationConstants.VERSION_FORMAT_VERSION;
	}

	// public String getVersionFormatMask() {
	//    return "{MAJOR}.{MINOR}[.{POINT}][-{RELEASE_LEVEL}][-{BUILD_NUMBER}]";
	//}

	public String getVersionFormatDescription() {
		return "http://www.apache.org/version";
	}

	//
	//	{MAJOR}.{MINOR}[.{POINT}][-{RELEASE_LEVEL}][-{BUILD_NUMBER}]
	//
	public VersionData parseVersionData(String versionString)
			throws org.krysalis.version.VersionFormatException {
		int elementMask = 0;

		Logger.getLogger().debug(
				"Parse Apache Version String: [" + versionString + "]");

		StringTokenizer tokens = new StringTokenizer(versionString, ". ");

		//  ---------------------------------------------------------------------------
		//  Extract MAJOR (a mandatory element)
		elementMask |= VersionDataElement.ELEMENT_MAJOR;
		int major = parseInt(versionString, VersionDataElement.MAJOR, tokens
				.nextToken());

		//  ---------------------------------------------------------------------------
		// Extract MINOR
		int minor = VersionDataElement.MIN_MINOR;
		String overflow = "";
		if (tokens.hasMoreTokens()) {

			String minorToken = tokens.nextToken();

			// Terminated minor with a non-digit
			int nonNumericPos = findEndOfNumericalArea(minorToken);

			// If found, we have 'overflow', i.e. extra stuff
			if (-1 != nonNumericPos) {
				overflow = minorToken.substring(nonNumericPos);
				minorToken = minorToken.substring(0, nonNumericPos);
			}

			elementMask |= VersionDataElement.ELEMENT_MINOR;
			minor = parseInt(versionString, VersionDataElement.MINOR,
					minorToken);
		} else {
			// :TODO: Do we allow no minor? Throw Exception?
		}

		// Attach anything left after major/minor onto extra tokens
		if (tokens.hasMoreTokens())
			overflow = overflow + tokens.nextToken();

		Logger.getLogger().debug(
				"Major/Minor/Extra : [" + major + "/" + minor + "/" + overflow
						+ "]");

		int point = VersionDataElement.DEFAULT_BUILD_NUMBER;
		ReleaseLevel releaseLevel = ReleaseLevel.RELEASE;
		int releaseQualifier = VersionDataElement.DEFAULT_RELEASE_QUALIFIER;
		int buildNumber = VersionDataElement.DEFAULT_BUILD_NUMBER;
		Date buildDate = null;

		if (overflow.length() > 0) {
			StringTokenizer tokens2 = new StringTokenizer(overflow, "- ");

			String pointToken = "";
			String possiblePoint = "";
			String remainder = "";

			if (tokens2.hasMoreTokens())
				pointToken = tokens2.nextToken();

			try {
				possiblePoint = pointToken;

				//	Terminated point with a non-digit
				int nonNumericPos = findEndOfNumericalArea(possiblePoint);

				// If found, we have 'overflow', i.e. extra stuff
				if (-1 != nonNumericPos) {
					remainder = possiblePoint.substring(nonNumericPos);
					possiblePoint = possiblePoint.substring(0, nonNumericPos);
				}

				point = parseInt(versionString, VersionDataElement.POINT,
						possiblePoint);

				elementMask |= VersionDataElement.ELEMENT_POINT;
			} catch (VersionFormatException vfe) {
				remainder = pointToken;
			}

			if ((remainder.length() == 0) && tokens2.hasMoreTokens())
				remainder = tokens2.nextToken();

			Logger.getLogger().debug(
					"Point/Extra : [" + point + "/" + remainder + "]");

			if (remainder.length() > 0)
				try {
					// Extract Release Level (perhaps with Qualifier)
					int digitPosn = findNextNumeric(remainder);

					if (-1 == digitPosn) {
						// Release Level w/o a numeric qualifier
						elementMask |= VersionDataElement.ELEMENT_RELEASE_LEVEL;

						releaseLevel = parseReleaseLevel(versionString,
								remainder);
					} else {
						String possibleRL = remainder.substring(0, digitPosn);
						String possibleRQ = remainder.substring(digitPosn);

						// Release Level
						elementMask |= VersionDataElement.ELEMENT_RELEASE_LEVEL;

						releaseLevel = parseReleaseLevel(versionString,
								possibleRL);

						// Release Qualifier
						elementMask |= VersionDataElement.ELEMENT_RELEASE_QUALIFIER;

						releaseQualifier = parseInt(versionString,
								VersionDataElement.RELEASE_QUALIFIER,
								possibleRQ);
					}

					Logger.getLogger().debug(
							"RelaseLevel/Qualifier : [" + releaseLevel + "/"
									+ releaseQualifier + "]");

					if (tokens2.hasMoreTokens()) {

						String data = tokens2.nextToken();

						try {
							Date value = parseDate(data);

							elementMask |= VersionDataElement.ELEMENT_BUILD_DATE;
							buildDate = value;
						} catch (Exception e) {

							elementMask |= VersionDataElement.ELEMENT_BUILD_NUMBER;
							buildNumber = parseInt(versionString,
									VersionDataElement.BUILD_NUMBER, tokens2
											.nextToken());
						}
					}
				} catch (VersionFormatException vfe) {
					Logger.getLogger().debug("Previous", vfe);
					elementMask |= VersionDataElement.ELEMENT_BUILD_NUMBER;
					buildNumber = parseInt(versionString,
							VersionDataElement.BUILD_NUMBER, remainder);
				}
		}

		//:TODO: Trap remainder and fail if leftovers...

		return new VersionData(new VersionDataElementSet(elementMask), major,
				minor, releaseLevel, releaseQualifier, point, buildNumber,
				buildDate);
	}

	public String toVersionString(VersionData data) {
		return format(data, VersionFormat.DEFUALT);
	}

	private String shortFormat(VersionData data) {
		StringBuffer output = new StringBuffer();

		output.append(Integer.toString(data.getMajor()));
		if (m_elements.hasMinor()) {
			output.append(".");
			output.append(Integer.toString(data.getMinor()));
		}
		if (m_elements.hasPoint()) {
			int point = data.getPoint();
			if (point > VersionDataElement.UNSET_POINT) {
				output.append(".");
				output.append(Integer.toString(point));
			}
		}
		return output.toString();
	}

	private String defaultFormat(VersionData data) {
		StringBuffer output = new StringBuffer();

		output.append(Integer.toString(data.getMajor()));
		if (m_elements.hasMinor()) {
			output.append(".");
			output.append(Integer.toString(data.getMinor()));
		}
		if (m_elements.hasPoint()) {
			int point = data.getPoint();
			if (point > VersionDataElement.UNSET_POINT) {
				output.append(".");
				output.append(Integer.toString(point));
			}
		}

		if (m_elements.hasReleaseLevel()) {
			ReleaseLevel releaseLevel = data.getReleaseLevel();

			if (!ReleaseLevel.UNSET.equals(releaseLevel)) {

				String releaseLevelStr = releaseLevel.getAsString();
				if (releaseLevelStr.length() > 0) {
					output.append("-");
					output.append(releaseLevelStr);
					if (m_elements.hasReleaseQualifier()) {
						int releaseQualifier = data.getReleaseQualifier();
						if (1 < releaseQualifier) {
							output.append(Integer.toString(releaseQualifier));
						}
					}
				}
			}
		}
		if (m_elements.hasBuildNumber()) {
			if (VersionDataElement.UNSET_BUILD_NUMBER != data.getBuildNumber()) {
				output.append("-");
				output.append(data.getBuildNumber());

			}
		}
		return output.toString();
	}

	/**
	 * Apply the named format to the VersionData.
	 * 
	 * @param data
	 *            The VersionData to format.
	 * @param format
	 *            The String name of the fromat to use (uses DEFAULT if null or
	 *            not found)
	 * @return the format string representation of the version data given.
	 */
	public String format(VersionData data, String format) {
		String result = null;

		if (format != null) {
			if (format.equals(VersionFormat.DEFUALT)) {
				result = defaultFormat(data);
			} else if (format.equals(VersionFormat.SHORT)) {
				result = shortFormat(data);
			}
		}
		return result == null ? defaultFormat(data) : result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.depot.version.specification.formatting.VersionFormat#parseVersion(java.lang.String)
	 */
	public Version parseVersion(String version) throws VersionFormatException {

		return new ApacheVersion(parseVersionData(version));
	}
}
--- NEW FILE: ApacheVersionComparator.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.version.impl.apache;

import java.util.Comparator;

/**
 * @author [email protected]
 */
public class ApacheVersionComparator implements Comparator {

	public static final ApacheVersionComparator INSTANCE =
		new ApacheVersionComparator();

	public int compare(Object first, Object second) {
		int comparison = -1;

		if (first instanceof ApacheVersion) {
			ApacheVersion firstVersion = (ApacheVersion) first;

			if (second instanceof ApacheVersion) {
				ApacheVersion secondVersion = (ApacheVersion) second;

				comparison =
					firstVersion.getData().compareTo(secondVersion.getData());

				// :TODO: Do we care about format comparison? Is it relevent
				// if the values are the same?
			}
			else
				throw new IllegalArgumentException(
					"Not a ApacheVersion: "
						+ second.getClass()
						+ " : "
						+ second.toString());
		}
		else
			throw new IllegalArgumentException(
				"Not a ApacheVersion: "
					+ first.getClass()
					+ " : "
					+ first.toString());

		return comparison;
	}

}

--- NEW FILE: ApacheVersion.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.version.impl.apache;

import java.io.PrintWriter;
import java.util.Comparator;
import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

import org.apache.depot.version.impl.data.ReleaseLevel;
import org.apache.depot.version.impl.data.VersionData;
import org.apache.depot.version.impl.data.VersionDataElement;
import org.apache.depot.version.impl.data.VersionDataElementSet;
import org.krysalis.version.Version;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionFormatException;
import org.krysalis.version.VersionSpecification;
import org.krysalis.version.VersionSpecificationFactory;
import org.krysalis.version.util.DebugUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * Apache Version. Has the genral form Major.minor.point. Major version are not
 * compatible. Minor version are backwards compatible. Point version are
 * forwards and backwards compatible.
 * 
 * @author [email protected]
 */
public class ApacheVersion implements Version, CompoundVersion{

	public final static String VERSION_TAG = "version";

	public final static ApacheVersion UNKNOWN = new ApacheVersion(
			new ApacheVersionSpecification(), VersionData.UNSET);

	/** The specification for this type of format */
	private final VersionSpecification m_specification;

	/** The data associated */
	private VersionData m_data;

	public static ApacheVersion fromVersion(Version version)
			throws VersionException {

		// If a known type, just clone it
		if (version instanceof ApacheVersion)
			return (ApacheVersion) version;
		else if (version instanceof CompoundVersion) {
			return new ApacheVersion((CompoundVersion) version);
		}

		throw new IllegalArgumentException("Don't know how to handle "+version.getClass());
	}

	/**
	 * 
	 * Construct an empty Version.
	 */
	public ApacheVersion() {
		super();

		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData();
	}

	/**
	 * Construct from another version.
	 * 
	 * @param other
	 */
	public ApacheVersion(ApacheVersion other) {
		super();

		m_specification = other.m_specification;
		m_data = new VersionData(other.m_data);
	}

	/*
	 * Construct from a CompoundVersion
	 * 
	 * @see CompoundVersion
	 */
	public ApacheVersion(CompoundVersion version) throws VersionException {
		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData(VersionDataElementSet.DEFAULT, version
				.getMajor(), version.getMinor(), ReleaseLevel
				.getFromString(version.getReleaseLevel()), version
				.getReleaseQualifier(), version.getPoint(), version
				.getBuildNumber(), version.getBuildDate());
	}

	/*
	 * Construct a standard version
	 */
	public ApacheVersion(int major, int minor, ReleaseLevel releaseLevel,
			int releaseQualifier, int point, int buildNumber, Date buildDate) {
		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData(VersionDataElementSet.DEFAULT, major, minor,
				releaseLevel, releaseQualifier, point, buildNumber, buildDate);
	}

	/*
	 * Construct a standard version
	 */
	public ApacheVersion(int major, int minor, ReleaseLevel releaseLevel,
			int releaseQualifier, int point) {
		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData(VersionDataElementSet.DEFAULT, major, minor,
				releaseLevel, releaseQualifier, point,
				VersionDataElement.DEFAULT_BUILD_NUMBER,
				VersionDataElement.DEFAULT_BUILD_DATE);
	}

	/*
	 * Construct a standard version
	 */
	public ApacheVersion(int major, int minor, ReleaseLevel releaseLevel,
			int buildNumber) {
		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData(VersionDataElementSet.DEFAULT, major, minor,
				releaseLevel, VersionDataElement.DEFAULT_RELEASE_QUALIFIER,
				VersionDataElement.DEFAULT_POINT, buildNumber,
				VersionDataElement.DEFAULT_BUILD_DATE);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(Date date) {
		super();

		m_specification = new DatetimestampedVersionSpecification();
		m_data = new VersionData(date);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(VersionData data) {
		super();

		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = data;
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(String data) throws VersionException {
		this(VersionImporter.importApacheVersion(data));
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(VersionSpecification specification, String data)
			throws VersionException {
		this(VersionImporter.importApacheVersion(specification, data));
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(VersionSpecification specification, String data,
			Map properties) throws VersionFormatException, VersionException {
		this(VersionImporter.importApacheVersion(specification, data));

		m_data.importProperties(properties);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersion(String data, Map properties)
			throws VersionFormatException, VersionException {
		this(VersionImporter.importApacheVersion(data));
		m_data.importProperties(properties);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param specification
	 * @param data
	 */
	public ApacheVersion(final VersionSpecification specification,
			final VersionData data) {
		m_specification = specification;
		m_data = data;
	}

	public String getVersion() {
		return m_specification.getVersionFormat().toVersionString(m_data);
	}

	public int hashCode() {
		int hashCode = 0;

		if (null != m_specification)
			hashCode += m_specification.hashCode();
		if (null != m_data)
			hashCode = m_data.hashCode();

		return hashCode;
	}

	public boolean equals(Object other) {
		if (this == other) {
			return true;
		} else if (other instanceof ApacheVersion) {
			ApacheVersion otherVersion = (ApacheVersion) other;
			return otherVersion.m_data.equals(m_data);
		} else {

			return false;
		}

	}

	public int compareTo(Object other) {
		int comparison = -1;

		if (other instanceof ApacheVersion) {
			ApacheVersion otherVersion = (ApacheVersion) other;

			comparison = otherVersion.m_data.compareTo(m_data);
		} else
			throw new IllegalArgumentException("Not a ApacheVersion: "
					+ other.getClass() + " : " + other.toString());

		return comparison;
	}

	public Map importProperties(Map properties) throws VersionException {
		return m_data.importProperties(properties);
	}

	public VersionData getVersionData() {
		return m_data;
	}

	public Comparator getComparator() {
		return ApacheVersionComparator.INSTANCE;
	}

	/**
	 * Compute if this version is compatible with other.
	 * 
	 * "Compatible" means (in effect) this version is a "good replacement" for
	 * the other version.
	 * 
	 * The aspects of a version that are utilized are: - Major Version - Minor
	 * Version - Release Level
	 * 
	 * The more specified in this version, the more are considered.
	 * 
	 * Say (for example) one wanted something compatible with 1.0 then 1.0.1 is
	 * such, but 1.1 is not. As for "1" to get "1.*".
	 * 
	 * Release level is somewhat different, especially when none is set. No
	 * release level = RELEASE (by default) and as such 1.0 means 1.0-release,
	 * so only 1.0.* of level "release" would be compatible.
	 * 
	 * Note: "Compatibility" is not transitive.
	 *  
	 */
	public boolean isCompatible(Version other) {
		boolean compatible = false;

		//
		// If this is unset, then all are compatible...
		//
		if (isUnset())
			return true;

		if (other instanceof ApacheVersion) {
			ApacheVersion otherApacheVersion = (ApacheVersion) other;

			//
			// *other is unset, or major's equal
			//
			if ((VersionDataElement.UNSET_MAJOR == otherApacheVersion
					.getMajor())
					|| otherApacheVersion.getMajor() == getMajor()) {

				//
				// other is unset, or minor's equal
				//
				if ((VersionDataElement.UNSET_MINOR == otherApacheVersion
						.getMinor())
						|| getMinor() >= otherApacheVersion.getMinor()) {

					//
					//  *Other* Release Level Higher
					//
					if ((otherApacheVersion.getReleaseLevelObject().compareTo(
							getReleaseLevelObject()) >= 0)) {
						compatible = true;
					}

					else if (
					//
					// If we aren't expecting a release, don't be fussy...
					//
					!ReleaseLevel.RELEASE.equals(getReleaseLevelObject())) {
						compatible = true;
					} else {

						Logger.getLogger().debug(
								"Release Levels ["
										+ getReleaseLevelObject()
										+ ","
										+ otherApacheVersion
												.getReleaseLevelObject() + "]"
										+ " for " + this + ","
										+ otherApacheVersion
										+ " are *NOT* Compatible");
					}
				} else
					Logger.getLogger().debug(
							"Minor Version Numbers [" + getMinor() + ","
									+ otherApacheVersion.getMinor() + "]"
									+ " for " + this + " and "
									+ otherApacheVersion
									+ " are *NOT* Compatible");
			} else
				Logger.getLogger().debug(
						"Major Version Numbers [" + getMajor() + ","
								+ otherApacheVersion.getMajor() + "]" + " for "
								+ this + " and " + otherApacheVersion
								+ " are *NOT* Compatible");
		} else
			throw new IllegalArgumentException("Not a ApacheVersion: "
					+ other.getClass() + " : " + other.toString());

		return compatible;
	}

	/**
	 * Returns the data.
	 * 
	 * @return VersionData
	 */
	public VersionData getData() {
		return m_data;
	}

	/**
	 * Returns the format.
	 * 
	 * @return VersionSpecification
	 */
	public VersionSpecification getSpecification() {
		return m_specification;
	}

	/**
	 * Returns the major.
	 * 
	 * @return int
	 */
	public int getMajor() {
		return m_data.getMajor();
	}

	/**
	 * Returns the major.
	 * 
	 * @return int
	 */
	public void setMajor(int major) {
		m_data.setMajor(major);
	}

	/**
	 * Returns the minor.
	 * 
	 * @return int
	 */
	public int getMinor() {
		return m_data.getMinor();
	}

	/**
	 * Returns the minor.
	 * 
	 * @return int
	 */
	public void setMinor(int minor) {
		m_data.setMinor(minor);
	}

	/*
	 * @return Point
	 */
	public int getPoint() {
		return m_data.getPoint();
	}

	/**
	 * @param point
	 */
	public void setPoint(int point) {
		m_data.setPoint(point);
	}

	/**
	 * @return BuildNumber
	 */
	public int getBuildNumber() {
		return m_data.getBuildNumber();
	}

	/**
	 * Set the Build Number
	 * 
	 * @param buildNumber
	 */
	public void setBuildNumber(int buildNumber) {
		m_data.setBuildNumber(buildNumber);
	}

	/**
	 * Get the Build Date
	 * 
	 * @return
	 */
	public Date getBuildDate() {
		return m_data.getBuildDate();
	}

	/**
	 * Set the Build Date
	 * 
	 * @param date
	 */
	public void setBuildDate(Date date) {
		m_data.setBuildDate(date);
	}

	/**
	 * Returns the releaseLevel.
	 * 
	 * @return ReleaseLevel
	 */
	public String getReleaseLevel() {
		return m_data.getReleaseLevelAsString();
	}

	/**
	 * Returns the releaseLevel.
	 * 
	 * @return ReleaseLevel
	 */
	public void setReleaseLevel(String releaseLevel) throws VersionException {
		m_data.setReleaseLevel(ReleaseLevel.getFromString(releaseLevel));
	}

	/**
	 * Returns the releaseLevel.
	 * 
	 * @return ReleaseLevel
	 */
	public void setReleaseLevel(ReleaseLevel releaseLevel) {
		m_data.setReleaseLevel(releaseLevel);
	}

	/**
	 * Returns the releaseLevel.
	 * 
	 * @return ReleaseLevel
	 */
	public ReleaseLevel getReleaseLevelObject() {
		return m_data.getReleaseLevel();
	}

	/**
	 * Returns the releaseQualifier.
	 * 
	 * @return ReleaseQualifier
	 */
	public int getReleaseQualifier() {
		return m_data.getReleaseQualifier();
	}

	public void setReleaseQualifier(int releaseQualifier) {
		m_data.setReleaseQualifier(releaseQualifier);
	}

	/**
	 * Accepts (in string form) any of the elements of version data e.g. major
	 * or minor or point or release level or build number and returns an
	 * incremented version.
	 * 
	 * @see VersionDataElement
	 * @see org.krysalis.version.Version#increment(String)
	 */
	public Version increment(String element) throws VersionException {
		// Extract which element of the version data, e.g. "major"
		VersionDataElement dataElement = VersionDataElement
				.getFromString(element);
		// Construct a suitable incrementor
		VersionDataIncrementor incrementor = new VersionDataIncrementor(
				dataElement);
		// Increment the version data element, bumping the
		//	higher elements
		VersionData nextVersionData = incrementor.increment(m_data);
		// Construct the new immutable version
		return new ApacheVersion(m_specification, nextVersionData);
	}

	public boolean isUnset() {
		return m_data.isUnset();
	}

	public String toString() {
		// TODO handle this in a parent class.
		return m_specification.getVersionFormat().toVersionString(
				getVersionData());
	}

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

		if ((null != m_specification) && verbose) {
			out.print(indent);
			out.println("Specification:");
			m_specification.dump(out, depth + 1, verbose);
		}

		if (null != m_data) {
			if (verbose) {
				out.print(indent);
				out.println("Data:");
			}

			m_data.dump(out, (verbose ? depth + 1 : depth), verbose);
		}
	}

	void validate() {
		if (null == m_specification)
			throw new IllegalArgumentException(
					"Illegal (null) VersionSpecification on ApacheVersion.");
		if (null == m_data)
			throw new IllegalArgumentException(
					"Illegal (null) VersionData on ApacheVersion.");
	}

	public void produceDOM(Document document, Element element) {

		// 
		//  Import XML as 'smart'
		//
		//Element v = DOMUtils.insertElement(document, element, VERSION_TAG);

		DOMUtils.produceDOM(document, element, m_data);
	}

	//
	//	XML handling
	//

	public ApacheVersion(Element element) throws VersionException {
		// :TODO: Spec as attribute?
		m_specification = VersionSpecificationFactory
				.createDefaultVersionSpecification();
		m_data = new VersionData(element);
	}

	public void consumeDOMElement(String tag, Element element) {
	}

	public void consumeDOMObject(String tag, Object object) {
	}
}


--- NEW FILE: ApacheVersionSpecification.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.krysalis.version.impl.apache;
import java.util.Map;


import org.krysalis.version.impl.VersionSpecificationImpl;

/**
 * 
 * @author $Author: chalko $
 * @version $Revision: 1.1 $
 *  
 */
public class ApacheVersionSpecification extends VersionSpecificationImpl {

	/**
	 * @see org.apache.depot.version.specification.VersionSpecification#getId()
	 */
	public String getId() {
		return org.krysalis.version.impl.VersionImplementationConstants.VERSION_PACKAGE;
	}

	/**
	 * @see org.apache.depot.version.specification.VersionSpecification#getDescription()
	 */
	public String getDescription() {
		return "Apache Version Default Specification";
	}

	/**
	 * @see org.apache.depot.version.specification.VersionSpecification#getElementMask()
	 */
	public int getElementMask() {
		return VersionDataElementSet.DEFAULT.getElementMask();
	}

	/**
	 * @see org.apache.depot.version.specification.VersionSpecification#getVersionFormat()
	 */
	public org.krysalis.version.VersionFormat getVersionFormat() {
		return new ApacheVersionFormat();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.depot.version.specification.VersionSpecification#createVersionMarker(java.lang.String,
	 *      java.lang.String)
	 */
	public org.krysalis.version.VersionMarker createVersionMarker(org.krysalis.version.VersionIdentifier id,
			String versionString, Map properties) throws org.krysalis.version.VersionException {

		return new ApacheVersionMarker(id.getKey(), versionString,properties);
	}


}


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click