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

Nick Chalko <[email protected]>
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-version/src/java/org/apache/depot/version/impl/apache
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3013/src/java/org/apache/depot/version/impl/apache

Added Files:
	ApacheVersionMarker.java ApacheVersionComparator.java 
	ApacheVersion.java 
Log Message:
The Apache implementation.

--- NEW FILE: ApacheVersionMarker.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.apache.depot.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.apache.depot.common.DepotException;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.common.util.debug.Dumpable;
import org.apache.depot.common.util.dom.DOMConsumer;
import org.apache.depot.common.util.dom.DOMProducer;
import org.apache.depot.common.util.dom.DOMUtils;
import org.apache.depot.version.Version;
import org.apache.depot.version.VersionConstants;
import org.apache.depot.version.VersionException;
import org.apache.depot.version.VersionMarker;
import org.apache.depot.version.impl.data.ReleaseLevel;
import org.apache.depot.version.specification.ApacheVersionSpecification;
import org.apache.depot.version.specification.VersionSpecification;
import org.apache.depot.version.specification.formatting.VersionFormat;
import org.apache.depot.version.specification.formatting.VersionFormatException;
import org.apache.depot.version.specification.formatting.format.ApacheVersionFormat;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author [email protected]
 */
public class ApacheVersionMarker implements 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();
	}

	public ApacheVersionMarker(String identifier, ApacheVersion version) {
		m_identifier = new VersionIdentifier(identifier);
		m_version = version;
		validate();
	}

	public ApacheVersionMarker(String identifier, CompoundVersion version)
			throws VersionException {
		m_identifier = new VersionIdentifier(identifier);
		m_version = new ApacheVersion(version);
		validate();
	}

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

		m_identifier = new VersionIdentifier(identifier);
		m_version = new ApacheVersion();
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(VersionIdentifier identifier, Date date) {
		super();

		m_identifier = identifier;
		m_version = new ApacheVersion(date);
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String identifier, Date date) {
		this(new VersionIdentifier(identifier), date);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, String data) throws VersionException {
		this(VersionImporter.importApacheVersionMarker(VersionIdentifier
				.importVersionIdentifier(id), data));
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(VersionIdentifier id, String data)
			throws VersionException {
		this(VersionImporter.importApacheVersionMarker(id, data));
	}

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

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

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, VersionSpecification specification,
			String data) throws VersionException {
		this(VersionImporter.importApacheVersionMarker(VersionIdentifier
				.importVersionIdentifier(id), specification, data));
	}

	public ApacheVersionMarker(String id, int major, int minor,
			ReleaseLevel releaseLevel, int buildNumber) {
		this(VersionIdentifier.importVersionIdentifier(id), new ApacheVersion(
				major, minor, releaseLevel, buildNumber));
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, VersionSpecification specification,
			String data, Map properties) throws VersionFormatException,
			VersionException {
		this(VersionImporter.importApacheVersionMarker(id, specification, data));
		importProperties(properties);
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, Map properties)
			throws VersionFormatException, VersionException {
		this(id);
		importProperties(properties);
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, VersionSpecification specification,
			String data, Map attributes, List annotations)
			throws VersionFormatException, VersionException {
		this(new VersionIdentifier(id), specification, data, attributes,
				annotations);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(VersionIdentifier id,
			VersionSpecification specification, String data, Map attributes,
			List annotations) throws VersionFormatException, VersionException {
		this(VersionImporter.importApacheVersionMarker(id, specification, data));

		importProperties(attributes);

		m_attributes = attributes;
		m_annotations = annotations;
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(VersionIdentifier id, Version version,
			Map attributes, List annotations) throws VersionFormatException,
			VersionException {
		this(id, version);

		// :TODO: Ensure importProperties does return the
		// ununsed ones
		m_attributes = importProperties(attributes);
		m_annotations = annotations;
		validate();
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, Version version, Map attributes,
			List annotations) throws VersionFormatException, VersionException {
		this(new VersionIdentifier(id), version);

		importProperties(attributes);

		m_attributes = attributes;
		m_annotations = annotations;
		validate();
	}

	/**
	 * @param string
	 * @param version
	 * @param attributes
	 * @param m_annotationList
	 * @param date
	 */
	public ApacheVersionMarker(String id, Version version, HashMap attributes,
			List annotationList, Date date) throws VersionFormatException,
			VersionException {
		this(id, version, attributes, annotationList);
		m_version.setBuildDate(date);
	}

	/**
	 * Constructor for Version.
	 * 
	 * @param other
	 */
	public ApacheVersionMarker(String id, String data, Map properties)
			throws VersionFormatException, VersionException {
		this(VersionImporter.importApacheVersionMarker(id, data));
		importProperties(properties);
		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 = DebugUtils.getIndent(depth);

		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();
	}

	public void produceDOM(Document document, Element element) {

		// 
		//  Import XML as 'smart'
		//
		Element v = document.createElement(VERSION_MARKER_TAG);
		DOMUtils.appendChild(document, element, v);

		Attr a = document.createAttribute(VERSION_ID_ATTRIBUTE);
		a.setNodeValue(getId());
		v.setAttributeNode(a);
		DOMUtils.produceDOM(document, v, m_version);
	}

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

	//
	//	XML handling
	//

	public ApacheVersionMarker(Element element) throws DepotException {
		//
		// Any attributes we need?
		//
		if (element.getNodeName().equals(VERSION_MARKER_TAG)) {
			DOMUtils.consumeDOMSubElements(this, l_parts, element);
		}
		// Identifier...
		m_identifier = new VersionIdentifier(element
				.getAttribute(VERSION_ID_ATTRIBUTE));
	}

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

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

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.depot.version.VersionMarker#getDefaultVersion()
	 */
	public String getDefaultVersion() {
		return FORMAT.format(m_version.getData(), VersionFormat.DEFUALT);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.apache.depot.version.VersionMarker#getSpecification()
	 */
	public VersionSpecification getSpecification() {
		return new ApacheVersionSpecification();
	}
}


--- 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.apache.depot.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.apache.depot.version.impl.apache;

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

import org.apache.depot.common.log.Logger;
import org.apache.depot.common.util.debug.DebugUtils;
import org.apache.depot.common.util.debug.Dumpable;
import org.apache.depot.common.util.dom.DOMConsumer;
import org.apache.depot.common.util.dom.DOMProducer;
import org.apache.depot.common.util.dom.DOMUtils;
import org.apache.depot.version.Version;
import org.apache.depot.version.VersionException;
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.impl.data.util.VersionDataIncrementor;
import org.apache.depot.version.specification.ApacheVersionSpecification;
import org.apache.depot.version.specification.DatetimestampedVersionSpecification;
import org.apache.depot.version.specification.VersionSpecification;
import org.apache.depot.version.specification.VersionSpecificationFactory;
import org.apache.depot.version.specification.formatting.VersionFormatException;
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);
		}

		// Else attempt to import using String
		return VersionImporter.importApacheVersion(version.toString());
	}

	/**
	 * 
	 * 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.apache.depot.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) {
	}
}




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