package org.apache.fop.datatypes;
import java.lang.reflect.InvocationTargetException;
import java.util.LinkedList;
import java.util.Collection;
import java.util.Iterator;
import org.apache.fop.fo.properties.*;
import org.apache.fop.fo.PropertyConsts;
import org.apache.fop.fo.PropNames;
import org.apache.fop.fo.FONode;
import org.apache.fop.datatypes.PropertyValue;
import org.apache.fop.fo.expr.PropertyException;
public class PropertyValueList extends LinkedList implements PropertyValue {
protected int property;
public final int type;
public final PropertyConsts propertyConsts;
@paramproperty
public PropertyValueList(int property) throws PropertyException {
super();
if (property < 1 || property > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + property);
this.property = property;
type = PropertyValue.LIST;
propertyConsts = PropertyConsts.getPropertyConsts();
}
@parampropertyName
public PropertyValueList(String propertyName)
throws PropertyException
{
super();
property = PropNames.getPropertyIndex(propertyName);
if (property < 1 || property > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + property);
type = PropertyValue.LIST;
propertyConsts = PropertyConsts.getPropertyConsts();
}
@paramproperty@paramcPropertyValueList@exceptionIllegalArgumentExceptionPropertyValueList
public PropertyValueList(int property, Collection c)
throws PropertyException
{
super(c);
if (! (c instanceof PropertyValueList))
throw new IllegalArgumentException
("Collection is not a PropertyValueList.");
if (property < 1 || property > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + property);
this.property = property;
type = PropertyValue.LIST;
propertyConsts = PropertyConsts.getPropertyConsts();
}
@parampropertyName@paramcPropertyValueList@exceptionIllegalArgumentExceptionPropertyValueList
public PropertyValueList(String propertyName, Collection c)
throws PropertyException
{
super(c);
if (! (c instanceof PropertyValueList))
throw new IllegalArgumentException
("Collection is not a PropertyValueList.");
property = PropNames.getPropertyIndex(propertyName);
if (property < 1 || property > PropNames.LAST_PROPERTY_INDEX)
throw new PropertyException("Invalid property index: " + property);
type = PropertyValue.LIST;
propertyConsts = PropertyConsts.getPropertyConsts();
}
@paramo@return@exceptionIllegalArgumentException
public boolean add(Object o) {
if (! (o instanceof PropertyValue || o instanceof PropertyValueList))
throw new IllegalArgumentException
("Object is not a PropertyValue or a PropertyValueList.");
return super.add(o);
}
@paramo@exceptionIllegalArgumentException
public void addFirst(Object o) {
if (! (o instanceof PropertyValue || o instanceof PropertyValueList))
throw new IllegalArgumentException
("Object is not a PropertyValue or a PropertyValueList.");
super.addFirst(o);
}
@paramo@return@exceptionIllegalArgumentException
public void addLast(Object o) {
add(o);
}
@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 String toString() {
String str, cstr;
try {
str = "Property: " + PropNames.getPropertyName(property)
+ " Index: " + property + " List contents:\n";
Iterator contents = iterator();
while (contents.hasNext()) {
int i = 0, j = 0;
Object obj = contents.next();
try {
cstr = (String)(obj.getClass()
.getMethod("toString", null)
.invoke(obj, null));
} catch (IllegalAccessException e) {
throw new PropertyException (e);
} catch (NoSuchMethodException e) {
throw new PropertyException (e);
} catch (InvocationTargetException e) {
throw new PropertyException (e);
}
while (i < cstr.length() && j >= 0) {
j = cstr.indexOf('\n', j);
if (j >= 0) {
str = str + ">" + cstr.substring(i, ++j);
i = j;
} else {
str = str + ">" + cstr.substring(i);
i = cstr.length();
}
}
}
return str;
} catch (PropertyException e) {
throw new RuntimeException(e.getMessage());
}
}
public Object clone() {
return super.clone();
}
}