Update of /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/specification
In directory sc8-pr-cvs1:/tmp/cvs-serv20296/src/java/org/krysalis/version/specification
Modified Files:
VersionSpecificationImpl.java
Added Files:
VersionSpecificationFactory.java
Log Message:
First stab at replacing Formats with Specifications for "non-Krysalis" formats.
Fixed some bugs via new tests.
--- NEW FILE: VersionSpecificationFactory.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.specification;
import java.util.HashMap;
import java.util.Iterator;
import org.krysalis.version.exception.VersionException;
import org.krysalis.version.internal.InternalVersionConstants;
/**
* @author ajack
*/
public class VersionSpecificationFactory {
private static HashMap l_registry = null;
static {
l_registry = new HashMap();
registerVersionSpecification(
InternalVersionConstants.KRYSALIS_VERSION_ID,
KrysalisVersionSpecification.class);
registerVersionSpecification(
InternalVersionConstants.ECLIPSE_VERSION_ID,
EclipseVersionSpecification.class);
registerVersionSpecification(
InternalVersionConstants.JAVASOFT_VERSION_ID,
JavasoftVersionSpecification.class);
registerVersionSpecification(
InternalVersionConstants.JAKARTA_COMMONS_VERSION_ID,
JakartaCommonsVersionSpecification.class);
registerVersionSpecification(
InternalVersionConstants.MAVEN_VERSION_ID,
MavenVersionSpecification.class);
}
public static VersionSpecification createEclipseVersionSpecification() {
return new EclipseVersionSpecification();
}
public static VersionSpecification createMavenVersionSpecification() {
return new MavenVersionSpecification();
}
public static VersionSpecification createJavasoftVersionSpecification() {
return new JavasoftVersionSpecification();
}
public static VersionSpecification createKrysalisVersionSpecification() {
return new KrysalisVersionSpecification();
}
public static VersionSpecification createJakartaCommonsVersionSpecification() {
return new JakartaCommonsVersionSpecification();
}
/** Default */
public static VersionSpecification createDefaultVersionSpecification() {
return new KrysalisVersionSpecification();
}
/** Named */
public static VersionSpecification createVersionSpecificationFromId(final String identifier)
throws VersionException {
//:TODO: Implement..
// Register existing formats by ID
// allow users to register...
VersionSpecification format = null;
synchronized (l_registry) {
Class registeredClass = (Class) l_registry.get(identifier);
if (null != registeredClass) {
try {
Object formatInst = registeredClass.newInstance();
format = (VersionSpecification) formatInst;
}
catch (Exception e) {
throw new VersionException(
"Failed to instantiate registered format for identifier ["
+ identifier
+ "]",
e);
}
}
else {
//:TODO: Be helpful, show them what you do have...
throw new VersionException(
"No registered format for identifier [" + identifier + "]");
}
}
return new KrysalisVersionSpecification();
}
public static void registerVersionSpecification(
String id,
Class formatClass) {
synchronized (l_registry) {
l_registry.put(id, formatClass);
}
}
public static Iterator getRegisteredSpecificationIds() {
return l_registry.keySet().iterator();
}
public static Iterator getRegisteredSpecifications() {
return l_registry.entrySet().iterator();
}
}
Index: VersionSpecificationImpl.java
===================================================================
RCS file: /cvsroot/metamorphosis/krysalis-version/src/java/org/krysalis/version/specification/VersionSpecificationImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** VersionSpecificationImpl.java 7 Mar 2003 20:01:43 -0000 1.1
--- VersionSpecificationImpl.java 10 Mar 2003 20:44:16 -0000 1.2
***************
*** 64,68 ****
* @author ajack
*/
! public abstract class VersionSpecificationImpl implements VersionSpecification {
public String getName() {
--- 64,69 ----
* @author ajack
*/
! public abstract class VersionSpecificationImpl
! implements VersionSpecification {
public String getName() {
***************
*** 75,88 ****
}
-
public void dump(PrintWriter out, int depth) {
final String indent = DebugUtils.getIndent(depth);
!
out.print(indent);
out.println("Specification Name:" + getName());
!
out.print(indent);
out.println("Specification Id:" + getId());
!
out.print(indent);
out.println("Description:" + getDescription());
--- 76,88 ----
}
public void dump(PrintWriter out, int depth) {
final String indent = DebugUtils.getIndent(depth);
!
out.print(indent);
out.println("Specification Name:" + getName());
!
out.print(indent);
out.println("Specification Id:" + getId());
!
out.print(indent);
out.println("Description:" + getDescription());
***************
*** 93,96 ****
--- 93,112 ----
out.print(indent);
out.println("Format:" + getVersionFormat());
+ }
+
+ public boolean equals(Object other) {
+ boolean equal = false;
+
+ if (other instanceof VersionSpecification) {
+ VersionSpecification otherSpecification = (VersionSpecification) other;
+
+ equal = getId().equals(otherSpecification.getId());
+ }
+
+ return equal;
+ }
+
+ public int hashCode() {
+ return getId().hashCode();
}
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
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.