package org.apache.fop.datatypes;
import org.apache.fop.fo.PropertyConsts;
import org.apache.fop.fo.PropNames;
import org.apache.fop.fo.properties.*;
import org.apache.fop.fo.FONode;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.datatypes.PropertyValue;
public abstract class AbstractPropertyValue
implements PropertyValue, Cloneable
{
protected int property;
public final int type;
public final PropertyConsts propertyConsts;
@paramindex@paramtype
public AbstractPropertyValue(int index, int type)
throws PropertyException
{
if (index < 1 || index > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + index);
if (type < 0 || type > PropertyValue.LAST_PROPERTY_TYPE)
throw new PropertyException("Invalid property type: " + type);
property = index;
this.type = type;
propertyConsts = PropertyConsts.getPropertyConsts();
}
@parampropertyName
public AbstractPropertyValue(String propertyName, int type)
throws PropertyException
{
propertyConsts = PropertyConsts.getPropertyConsts();
property = PropNames.getPropertyIndex(propertyName);
if (property < 1 || property > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + property);
if (type < 0 || type > PropertyValue.LAST_PROPERTY_TYPE)
throw new PropertyException("Invalid property type: " + type);
this.type = type;
}
@return
public int getProperty() {
return property;
}
public void setProperty(int index) throws PropertyException {
if (index < 0 || index > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + index);
property = index;
}
@return
public int getType() {
return type;
}
AbstractPropertyValue@paramtestProperty@paramtype
public void validate(int testProperty, int type)
throws PropertyException
{
if ((propertyConsts.getDataTypes(testProperty) & type) == 0) {
String pname = PropNames.getPropertyName(testProperty);
throw new PropertyException
("Datatype(s) " +
Property.listDataTypes(type) +
" not defined on " + pname);
}
}
@paramtype
public void validate(int type) throws PropertyException {
validate(property, type);
}
public static String typeString(int type) {
if (type < 0 || type >PropertyValue.LAST_PROPERTY_TYPE)
return "Property type out of range";
return PropertyValue.propertyTypes.get(type);
}
public String toString() {
try {
return "Property: " + PropNames.getPropertyName(property)
+ " Index: " + property + " Type: " +
typeString(type);
} catch (PropertyException e) {
throw new RuntimeException(e.getMessage());
}
}
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}