package bvyy.database;
// Copyright(C)1998 Brian Yap
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 675 Mass
// Ave, Cambridge, MA 02139, USA.
import java.beans.*;
import java.io.*;
import java.util.*;
/**
* A Category defines the defualt types of things available in the world.
* Generally I expect there will be one type of category for evry type of
* generic thing within the world.
*
* @version 0.0.1 31 October 1998
* @author (c) 1998 Brian Voon Yee Yap
*/
public class Category extends Thing implements Serializable{
private String pluralName;
private Hashtable mandatoryCharacteristicsForConstruction = new Hashtable();
private Hashtable optionalChracterisctisForConstruction = new Hashtable();
private Hashtable mandatoryCharacteristicsForDeconstruction = new Hashtable();
private Hashtable optionalCharacteristicsForDeconstruction = new Hashtable();
private Hashtable mandatoryToolsForConstruction = new Hashtable();
private Hashtable optionalToolsForConstruction = new Hashtable();
private Hashtable mandatoryToolsForDeconstruction = new Hashtable();
private Hashtable optionalToolsForDeconstruction = new Hashtable();
private Hashtable mandatoryComponents = new Hashtable();
private Hashtable optionalComponents = new Hashtable();
private Boolean root = false;
private bvyy.database.Category parent = null;
private Hashtable children = new Hashtable();
/**
*
*/
public Category() {
super();
pluralName = this.getName();
}
/**
* Creates a thing based on this category.
*
*
* - Checks to see if the list of components is complete. If not, throws
* a Construction Failed Exception with the missing components
* attached.
* - Checks to see if the list of tools is complete. If not, throws
* a Construction Failed Exception with the missing tools
* attached.
* - Checks to see if the list of capabilities is complete. If not, throws
* a Construction Failed Exception with the missing capabilities
* attached.
* - Checks to see if the list of characteristics is complete. If not,
* throws a Construction Failed Exception with the missing
* characteristics attached.
* - Crates a the Thing.
* - Attaches a vetoable change listener (this) to the Thing to allow
* validation of changes to the Thing.
*
*
* @param the set of things to be used to build the thing.
* @exception ContructionFailedExcpetion If this exception is thrown as the
* result of a failurs in the check of
* the components, capabilities and
* tools, then all the failures are
* returned.
*/
public Thing buildThing(Hashtable components,
Hashtable tools,
Hashtable capabilities,
Hashtable characterisitcs,
Thing location)
throws ContructionFailedExcpetion{
System.out.println("Category: Build Thing");
private RealThing theThing;
private VetoableChangeListener vcl;
private Thing thisMandatoryComponent;
private Thing thisComponent;
private Thing thisMandatoryTool;
private Thing thisTool;
private Capability thisMandatoryCapabilities;
private Capability thisCapability;
private Characteristic thisMandatoryCharacteristics;
private Characteristic thisCharacteristics;
private ContructionFailedExcpetion contructionFailedExcpetion = null;
// Check the Components.
for (Enumeration e = getMandatoryComponents.elements() ; e.hasMoreElements() ;) {
thisMandatoryComponent=(Thing)e.nextElement();
if (components.contains(thisMandatoryComponent.getName()) {
thisComponent=(Thing)components.get(thisMandatoryComponent.getName())
if (thisMandatoryComponent.getQuantity() > thisComponent.getQuantity()){
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingComponent(thisMandatoryComponent);
}
} else {
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingComponent(thisMandatoryComponent);
}
}
// Check the Tools.
for (Enumeration e = getMandatoryToolsForConstruction.elements() ; e.hasMoreElements() ;) {
thisMandatoryTool=(Thing)e.nextElement();
if (Ttools.contains(thisMandatoryTool.getName()) {
//needs fixing, copied from components. Needs to look at the quality etc...
thisTool=(Thing)tools.get(thisMandatoryTool.getName())
if (thisMandatoryTool.getQuantity() > thisTool.getQuantity()){
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingComponent(thisMandatoryTool);
}
} else {
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingTool(thisMandatoryTool);
}
}
// Check the Capabilities.
for (Enumeration e = getMandatoryToolsForConstruction.elements() ; e.hasMoreElements() ;) {
thisMandatoryCapabilities=(Thing)e.nextElement();
if (capabilities.contains(thisMandatoryCapabilities.getName()) {
thisCapability=(Thing)capabilities.get(thisMandatoryCapabilities.getName())
//needs fixing, copied from components. Needs to look at the skill level etc...
if (thisMandatoryCapabilities.getQuantity() > thisCapability.getQuantity()){
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingComponent(thisMandatoryCapabilities);
}
} else {
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingCapability(thisMandatoryCapabilities);
}
}
// Check the characterisics
for (Enumeration e = getMandatoryCharacteristicsForConstruction.elements() ; e.hasMoreElements() ;) {
thisMandatoryCharacteristics=(Thing)e.nextElement();
if (characterisitcs.contains(thisMandatoryCharacteristics.getName()) {
thisCharacteristics=(Thing)characterisitcs.get(thisMandatoryCharacteristics.getName())
//needs fixing, copied from components. Needs to look at the ?? value ?? etc...
if (thisMandatoryCharacteristics.getQuantity() > thisCharacteristics.getQuantity()){
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingComponent(thisMandatoryCharacteristics);
}
} else {
if (contructionFailedExcpetion == null) {
contructionFailedExcpetion = new ContructionFailedExcpetion("Missing Components, Tools or Characteristics");
}
contructionFailedExcpetion.addMissingCapability(thisMandatoryCharacteristics);
}
}
// If there is an excption - throw it.
if (contructionFailedExcpetion != null) {
throw contructionFailedExcpetion;
}
// Create the thing.
theThing = new RealThing(this,
components,
tools,
capabilities,
characterisitcs,
location);
// Add this as a vetoable listener.
theThing.addVetoableChangeListener(vcl);
return theThing;
}
/**
* This provides the plural version of the name if it is different from
* the singular version.
*
* @param newPluralName the new plural name.
*/
public void setPluralName(String newPluralName) {
pluralName = newPluralName;
}
/**
* This provides the plural version of the name if it is different from
* the singular version.
*/
public String getPluralName() {
return pluralName;
}
/**
* This provides a list of characteristics that must be present for the object
* to be created. This will replace the existing set of mandatory
* characteristics.
*
* @param newMandatoryCharacteristicsForConstruction the list of new mandatory
* characteristics.
*/
public void setMandatoryCharacteristicsForConstruction(java.util.Vector newMandatoryCharacteristicsForConstruction) {
mandatoryCharacteristicsForConstruction = newMandatoryCharacteristicsForConstruction;
}
/**
* Gets the list of mandatory characteristics for this category.
*
* @return a vector containing the mandatory characteristics.
*/
public java.util.Vector getMandatoryCharacteristicsForConstruction() {
return mandatoryCharacteristicsForConstruction;
}
/**
* This provides a list of optional characteristis that can be used in the
* construction of objects belonging to this category. This will replace the
* existing set of optional characteristics.
*
* @param newOptionalChracterisctisForConstruction the list of new optional
* characteristics.
*/
public void setOptionalChracterisctisForConstruction(java.util.Vector newOptionalChracterisctisForConstruction) {
optionalChracterisctisForConstruction = newOptionalChracterisctisForConstruction;
}
/**
* Gets the list of optional characteristics for this category.
*
* @return a vector containing the optional characteristics.
*/
public java.util.Vector getOptionalChracterisctisForConstruction() {
return optionalChracterisctisForConstruction;
}
/**
* This provides a list of characteristics that must be present for the object
* to be disassembled. This will replace the existing set of mandatory
* characteristics.
*
* @param newMandatoryCharacteristicsForDeconstruction the list of new
* mandatory
* characteristics.
*/
public void setMandatoryCharacteristicsForDeconstruction(java.util.Vector newMandatoryCharacteristicsForDeconstruction) {
mandatoryCharacteristicsForDeconstruction = newMandatoryCharacteristicsForDeconstruction;
}
/**
* Gets the list of mandatory characteristics for this category.
*
* @return a vector containing the mandatory characteristics.
*/
public java.util.Vector getMandatoryCharacteristicsForDeconstruction() {
return mandatoryCharacteristicsForDeconstruction;
}
/**
*
*/
public void setOptionalCharacteristicsForDeconstruction(java.util.Vector newOptionalCharacteristicsForDeconstruction) {
optionalCharacteristicsForDeconstruction = newOptionalCharacteristicsForDeconstruction;
}
/**
*
*/
public java.util.Vector getOptionalCharacteristicsForDeconstruction() {
return optionalCharacteristicsForDeconstruction;
}
/**
* This provides a list of mandatory tools that must be present for the object
* to be created. This will replace the existing set of mandatory tools.
*
* @param newMandatoryToolsForConstruction the new set of tools.
*/
public void setMandatoryToolsForConstruction(java.util.Vector newMandatoryToolsForConstruction) {
mandatoryToolsForConstruction = newMandatoryToolsForConstruction;
}
/**
* Gets the list of mandatory tools for construction for this category.
*
* @return a vector containing the tools for construction.
*/
public java.util.Vector getMandatoryToolsForConstruction() {
return mandatoryToolsForConstruction;
}
/**
*
*/
public void setOptionalToolsForConstruction(java.util.Vector newOptionalToolsForConstruction) {
optionalToolsForConstruction = newOptionalToolsForConstruction;
}
/**
*
*/
public java.util.Vector getOptionalToolsForConstruction() {
return optionalToolsForConstruction;
}
/**
* This provides a list of tools that must be present for the object to be
* disassembled. This will replace the existing set of mandatory tools.
*
* @param newMandatoryToolsForDeconstruction the new set of tools.
*/
public void setMandatoryToolsForDeconstruction(java.util.Vector newMandatoryToolsForDeconstruction) {
mandatoryToolsForDeconstruction = newMandatoryToolsForDeconstruction;
}
/**
* Gets the list of mandatory tools for deconstruction for this category.
*
* @return a vector containing the tools for deconstruction.
*/
public java.util.Vector getMandatoryToolsForDeconstruction() {
return mandatoryToolsForDeconstruction;
}
/**
*
*/
public void setOptionalToolsForDeconstruction(java.util.Vector newOptionalToolsForDeconstruction) {
optionalToolsForDeconstruction = newOptionalToolsForDeconstruction;
}
/**
*
*/
public java.util.Vector getOptionalToolsForDeconstruction() {
return optionalToolsForDeconstruction;
}
/**
* This provides a list of components that must be present for the object to
* be in existence. This will replace the existing set of mandatory components.
*
* @param newMandatoryComponents the new components.
*/
public void setMandatoryComponents(java.util.Vector newMandatoryComponents) {
mandatoryComponents = newMandatoryComponents;
}
/**
* Gets the list of mandatory components for this category.
*
* @return a vector containing the mandatory components.
*/
public java.util.Vector getMandatoryComponents() {
return mandatoryComponents;
}
/**
* This provides a list of components that may be present for the object to
* be in existence. This will replace the existing set of optional components.
*
* @param newOptionalComponents the new components.
*/
public void setOptionalComponents(java.util.Vector newOptionalComponents) {
optionalComponents = newOptionalComponents;
}
/**
* Gets the list of optional components for this category.
*
* @return a vector containing the optional components.
*/
public java.util.Vector getOptionalComponents() {
return optionalComponents;
}
/**
*
*/
public void setRoot(Boolean newRoot) {
root = newRoot;
}
/**
*
*/
public Boolean getRoot() {
return root;
}
/**
*
*/
public void setParent(bvyy.database.Category newParent) {
parent = newParent;
}
/**
*
*/
public bvyy.database.Category getParent() {
return parent;
}
/**
*
*/
public void setChildren(java.util.Vector newChildren) {
children = newChildren;
}
/**
*
*/
public java.util.Vector getChildren() {
return children;
}
}