krysalis-version/src/java/org/krysalis/version/ant/nested VersionMarkerNestedElement.java,NONE,1.1 VersionSpecificationNestedElement.java,NONE,1.1 VersionNestedElement.java,NONE,1.1 VersionFormatNestedElement.java,NONE,1.1 NestedElement.java,NONE,1.1

Nick Chalko <[email protected]> Tue, 09 Nov 2004 07:36:29 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-version/src/java/org/krysalis/version/ant/nested
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30983/src/java/org/krysalis/version/ant/nested

Added Files:
	VersionMarkerNestedElement.java 
	VersionSpecificationNestedElement.java 
	VersionNestedElement.java VersionFormatNestedElement.java 
	NestedElement.java 
Log Message:
Everything at least compiles now.

--- NEW FILE: NestedElement.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.ant.nested;


import org.apache.tools.ant.Location;
import org.apache.tools.ant.ProjectComponent;

public class NestedElement {
	private final ProjectComponent rootComponent;

	public NestedElement(ProjectComponent rootComponent) {
		this.rootComponent=rootComponent;
	}



	/**
	 * Get the root component that owns this nested element.
	 * This will be a task or top level data type
	 * @return Root component
	 */
	public ProjectComponent getRootComponent() {
		return rootComponent;
	}

	public Location getLocation() {
		return null;}
}

--- NEW FILE: VersionMarkerNestedElement.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.ant.nested;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.Task;
import org.krysalis.version.Version;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionIdentifier;
import org.krysalis.version.VersionMarker;
import org.krysalis.version.ant.stamp.DefaultVersionMarkerAttributes;
import org.krysalis.version.ant.stamp.VersionMarkerAttribute;
import org.krysalis.version.impl.CompoundVersion;
import org.krysalis.version.impl.apache.ApacheVersion;
import org.krysalis.version.impl.apache.ApacheVersionMarker;

/**
 * 
 * @author: $Author: chalko $
 * @version: $Revision: 1.1 $
 */
public class VersionMarkerNestedElement extends NestedElement {

	private String m_versionId = null;

	private String m_version = null;
	private VersionNestedElement m_versionBean = null;

	private DefaultVersionMarkerAttributes m_defaultAttributes = null;
	private final List m_attributeList = new ArrayList();

	//:TODO: Add These...
	private final List m_annotationList = new ArrayList();

	private BuildException m_ant;

	public VersionMarkerNestedElement(ProjectComponent component, String versionId) {
		super(component);

		m_versionId = versionId;
	}

	public VersionMarkerNestedElement(Task task) {
		super(task);
	}

	//:TODO: If no version info, but version id -- then load it?

	public VersionMarker getVersionMarker() {
		VersionMarker versionMarker = null;
		
			HashMap attributes = getAttributes();

			//
			// One could embed a <version nested element
			//
			ApacheVersion version = getVersionObject();

			versionMarker =
				new ApacheVersionMarker(
					new VersionIdentifier(getVersionId()),
					version,
					attributes);

		
		return versionMarker;
	}

	public CompoundVersion getCompoundVersionObject() {
		return (CompoundVersion) getVersionObject();
	}

	public ApacheVersion getVersionObject() {
		ApacheVersion version = null;

		if ((null == m_versionBean) && (null == m_version))
			throw new BuildException(
				"Missing mandatory <version sub-element or 'version' attribute.",
				m_ant.getLocation());

		if ((null != m_versionBean) && (null != m_version))
			throw new BuildException(
				"Use one of <version sub-element or 'version' attribute, not both.",
				m_ant.getLocation());

		if (null != m_versionBean)
			version = (ApacheVersion) m_versionBean.getVersionObject();

		else {
			try {
				//
				// Attempt to parse the attribute
				//
				version = new ApacheVersion(m_version);
			}
			catch (VersionException ve) {
				throw new BuildException(
					"Invalid 'version' attribute : \"" + m_version + "\"",
					ve,
					m_ant.getLocation());
			}

		}

		return version;
	}

	private HashMap getAttributes() {
		HashMap attributes = new HashMap();
		if (null != m_defaultAttributes)
			for (Iterator i = m_defaultAttributes.getList().iterator();
				i.hasNext();
				) {
				processAttribute(attributes, (VersionMarkerAttribute) i.next());
			}

		for (Iterator i = m_attributeList.iterator(); i.hasNext();) {
			processAttribute(attributes, (VersionMarkerAttribute) i.next());
		}

		return attributes;
	}

	private void processAttribute(
		HashMap attributes,
		VersionMarkerAttribute attr) {
		if (null != attr.getName()) {
			if (null != attr.getValue())
				attributes.put(attr.getName(), attr.getValue());
			else
				getRootComponent().log(
					"Named attribute ["
						+ attr.getName()
						+ "] without value. Attributed ignored.",
					Project.MSG_WARN);
		}
		else
			throw new BuildException("Invalid *unnamed* attribute: " + attr);

	}

	/**
	 * Set the versionId.
	 * 
	 * @param newName java.lang.String
	 */
	public void setVersionId(String versionId) {
		m_versionId = versionId;
	}

	/**
	 * Returns the attributeList.
	 * @return List
	 */
	public List getAttributeList() {
		return m_attributeList;
	}

	public boolean isVersionIdSet() {
		return null != m_versionId;
	}

	/**
	 * Returns the versionId.
	 * @return String
	 */
	public String getVersionId() {
		if (null == m_versionId)
			throw new BuildException(
				"Missing mandatory version identifier 'versionId'",
				m_ant.getLocation());

		return m_versionId;
	}

	//	-------------------------------------------------------------
	//	
	//	Nested Sub-Elements:	
	//	
	//	-------------------------------------------------------------

	public VersionMarkerAttribute createAttribute() {
		VersionMarkerAttribute attr =
			new VersionMarkerAttribute(getRootComponent());
		m_attributeList.add(attr);
		return attr;
	}

	public DefaultVersionMarkerAttributes createDefaultAttributes() {
		if (null != m_defaultAttributes)
			throw new BuildException(
				"Only one nested <defaultAttributes tag allowed.",
				getLocation());
		m_defaultAttributes =
			new DefaultVersionMarkerAttributes(getRootComponent());
		return m_defaultAttributes;
	}

	public VersionNestedElement createVersion() {
		if (null != m_versionBean)
			throw new BuildException(
				"Only one nested <version tag allowed.",
				getLocation());
		m_versionBean = new VersionNestedElement(getRootComponent());
		return m_versionBean;
	}
	/**
	 * @param string
	 */
	public void setVersion(String string) {
		m_version = string;
	}

	public boolean hasVersion() {
		return isVersionSet();
	}
	
	public boolean isVersionSet() {
		return ((null != m_version) || (null != m_versionBean));
	}
}

--- NEW FILE: VersionNestedElement.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.ant.nested;

import java.util.Date;

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.tools.ant.BuildException;
import org.apache.tools.ant.ProjectComponent;
import org.krysalis.version.Version;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionSpecification;
import org.krysalis.version.impl.CompoundVersion;
import org.krysalis.version.impl.apache.ApacheVersion;

/**
 * 
 * @author: $Author: chalko $
 * @version: $Revision: 1.1 $
 */
public class VersionNestedElement extends NestedElement {

	private VersionSpecificationNestedElement m_specificationBean = null;

	private String m_releaseLevel = null;
	private int m_releaseQualifier = VersionDataElement.UNSET_RELEASE_QUALIFIER;
	private int m_major = VersionDataElement.UNSET_MAJOR;
	private int m_minor = VersionDataElement.UNSET_MINOR;
	private int m_point = VersionDataElement.UNSET_POINT;
	private int m_buildNumber = VersionDataElement.UNSET_BUILD_NUMBER;
	private Date m_buildDate = VersionDataElement.UNSET_BUILD_DATE;

	private String m_version = null;

	public VersionNestedElement(ProjectComponent component) {
		super(component);
	}

	public CompoundVersion getCompoundVersionObject() {
		Version version = getVersionObject();

		CompoundVersion cv = null;

		if (version instanceof CompoundVersion)
			cv = (CompoundVersion) version;

		if (null == cv)
			throw new BuildException(
				"Not a compound version: " + version,
				getLocation());

		return cv;
	}
//:TODO: Allow users to specific the class to use...
	public Version getVersionObject() {
		Version version = null;
		try {

			if (null != m_specificationBean) {
				VersionSpecification specification =
					m_specificationBean.getVersionSpecificationObject();

				if (null != m_version)
					version = new ApacheVersion(m_version);
				else
					version =
						new ApacheVersion(
							specification,
							new VersionData(m_major,
									m_minor,
									ReleaseLevel.getFromString(m_releaseLevel),
									m_releaseQualifier,
									m_point,
									m_buildNumber,
									m_buildDate));
			}
			else {

				if (null != m_version)
					version = new ApacheVersion(m_version);
				else
					version =
						new ApacheVersion(
							new VersionData(m_major,
									m_minor,
									ReleaseLevel.getFromString(m_releaseLevel),
									m_releaseQualifier,
									m_point,
									m_buildNumber,
									m_buildDate));
			}
		}
		catch (VersionException ve) {
			throw new BuildException(ve, getLocation());
		}

		return version;
	}

	/**
	 * Gets the minor version number.
	 * @return Returns a java.lang.String
	 */
	public int getMinor() {
		return m_minor;
	}
	/**
	 * Sets the minor version number.
	 * @param minor The minor to set
	 */
	public void setMinor(int minor) {
		m_minor = minor;
	}
	/**
	 * Sets the major version number.
	 * @param major The major to set
	 */
	public void setMajor(int major) {
		m_major = major;
	}
	/**
	 * Sets the point.
	 * @param point The point to set
	 */
	public void setPoint(int point) {
		m_point = point;
	}

	/**
	 * Sets the releaseLevel.
	 * @param level The releaseLevel to set
	 */
	public void setReleaseLevel(String releaseLevel) {
		m_releaseLevel = releaseLevel;
	}

	/**
	 * Sets the releaseQualifier.
	 * @param releaseQualifier The releaseQualifier to set
	 */
	public void setReleaseQualifier(int releaseQualifier) {
		m_releaseQualifier = releaseQualifier;
	}

	/**
	 * Sets the level.
	 * @param level The level to set
	 */
	public void setBuildNumber(int buildNumber) {
		m_buildNumber = buildNumber;
	}

	public boolean isVersionSet() {
		return null != m_version;
	}

	/**
	 * Set the entire string.  This overides other settings.
	 * 
	 * @param version The version to set
	 */
	public void setVersion(String version) {
		m_version = version;
	}

	public VersionSpecificationNestedElement createSpecification() {
		//:TODO: Only one?
		m_specificationBean =
			new VersionSpecificationNestedElement(getRootComponent());
		return m_specificationBean;
	}

	/**
	 * Returns the buildNumber.
	 * @return String
	 */
	public int getBuildNumber() {
		return m_buildNumber;
	}

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

	/**
	 * Returns the point.
	 * @return String
	 */
	public int getPoint() {
		return m_point;
	}

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

	/**
	 * Returns the version.
	 * @return String
	 */
	public String getVersion() {
		return m_version;
	}
}

--- NEW FILE: VersionSpecificationNestedElement.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.ant.nested;
import org.apache.tools.ant.ProjectComponent;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionSpecification;
import org.krysalis.version.VersionSpecificationFactory;

/**
 * @author ajack
 */
public class VersionSpecificationNestedElement extends NestedElement {
    private String m_specificationId = null;
    private VersionFormatNestedElement m_formatBean = null;
    
    public VersionSpecificationNestedElement(ProjectComponent component) {
        super(component);
    }

    public VersionSpecification getVersionSpecificationObject() throws VersionException {
        VersionSpecification specification = null;

        if (null != m_specificationId)
            specification = VersionSpecificationFactory.createVersionSpecificationFromId(m_specificationId);
        else {
            specification = VersionSpecificationFactory.createDefaultVersionSpecification();
        }

        return specification;

    }
    
    public VersionFormatNestedElement createFormat() {
        m_formatBean = new VersionFormatNestedElement(getRootComponent());
        return m_formatBean;
    }
    
    //:TODO: (1) Wire In FormatNestedElement
    //:TODO: (2) Complete to be able to create specifications..
}

--- NEW FILE: VersionFormatNestedElement.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.ant.nested;
import org.apache.tools.ant.ProjectComponent;
import org.krysalis.version.VersionException;
import org.krysalis.version.VersionFormat;
import org.krysalis.version.VersionFormatFactory;

/**
 * @author ajack
 */
public class VersionFormatNestedElement extends NestedElement {
    private String m_formatId = null;

    public VersionFormatNestedElement(ProjectComponent component) {
        super(component);
    }

    public VersionFormat getVersionFormatObject() throws VersionException {
        VersionFormat format = null;

        if (null != m_formatId)
            format = VersionFormatFactory.createVersionFormatFromId(m_formatId);
        else {
            format = VersionFormatFactory.createDefaultVersionFormat();
        }

        return format;

    }

}



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