use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributes method extractAttribute.
/**
* Extract attribute.
*
* @param attributeType the attribute type
* @param expression the expression
* @param foundList the found list
* @return the class
*/
protected Class<?> extractAttribute(Class<?> attributeType, Expression expression, List<String> foundList) {
Class<?> returnType = String.class;
if (expression instanceof AttributeExpressionImpl) {
AttributeExpressionImpl attribute = (AttributeExpressionImpl) expression;
// Determine if attribute is a geometry
if ((GeometryTypeMapping.getGeometryType(attributeType) != GeometryTypeEnum.UNKNOWN) || (attributeType == Geometry.class)) {
if (!geometryFieldList.contains(attribute.getPropertyName())) {
geometryFieldList.add(attribute.getPropertyName());
}
} else {
if (!fieldList.containsKey(attribute.getPropertyName()) && (attribute.getPropertyName() != null)) {
DataSourceAttributeData field = new DataSourceAttributeData(attribute.getPropertyName(), attributeType, null);
processedFieldList.add(field);
fieldList.put(attribute.getPropertyName(), field);
foundList.add(attribute.getPropertyName());
}
}
} else if (expression instanceof FunctionExpression) {
FunctionExpression function = (FunctionExpression) expression;
FunctionName functionName = function.getFunctionName();
List<Parameter<?>> argumentList = functionName.getArguments();
int index = 0;
for (Expression parameterExpression : function.getParameters()) {
Parameter<?> parameter = argumentList.get(index);
extractAttribute(parameter.getType(), parameterExpression, foundList);
index++;
}
returnType = functionName.getReturn().getType();
} else if (expression instanceof LiteralExpressionImpl) {
LiteralExpressionImpl literal = (LiteralExpressionImpl) expression;
try {
Geometry geometry = reader.read(literal.toString());
if (geometry != null) {
returnType = Geometry.class;
}
} catch (ParseException e1) {
// Ignore
}
if (returnType == String.class) {
try {
@SuppressWarnings("unused") int integer = Integer.valueOf(literal.toString());
returnType = Integer.class;
} catch (NumberFormatException e) {
// Ignore
}
}
if (returnType == String.class) {
try {
@SuppressWarnings("unused") double doubleValue = Double.valueOf(literal.toString());
returnType = Double.class;
} catch (NumberFormatException e) {
// Ignore
}
}
}
return returnType;
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class ExtractAttributes method extractDefaultFields.
/**
* Extract default fields.
*
* @param sld the sld
*/
public void extractDefaultFields(StyledLayerDescriptor sld) {
if (sld != null) {
visit(sld);
// Check to see if any geometry fields have been added to processedFieldList
List<DataSourceAttributeData> fieldsToMoveToGeometryList = new ArrayList<DataSourceAttributeData>();
for (DataSourceAttributeData dsAttribute : processedFieldList) {
if (dsAttribute.getType() == Geometry.class) {
fieldsToMoveToGeometryList.add(dsAttribute);
}
}
// Move geometry fields to the correct list
for (DataSourceAttributeData ds : fieldsToMoveToGeometryList) {
geometryFieldList.add(ds.getName());
processedFieldList.remove(ds);
}
}
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class WindBarbDetails method populateExpression.
/**
* Populate expression.
*
* @param wellKnownName the well known name
*/
public void populateExpression(String wellKnownName) {
if (wellKnownName != null) {
int startSpeedOpenBracket = wellKnownName.indexOf("(");
int endSpeedCloseBracket = wellKnownName.indexOf(")");
if ((startSpeedOpenBracket < 0) || (endSpeedCloseBracket < 0)) {
// Invalid
return;
}
String windSpeed = wellKnownName.substring(startSpeedOpenBracket + 1, endSpeedCloseBracket);
int startUnitsOpenBracket = wellKnownName.indexOf("[");
int endUnitsOpenBracket = wellKnownName.indexOf("]");
if ((startUnitsOpenBracket < 0) || (endUnitsOpenBracket < 0)) {
// Invalid
return;
}
Expression windSpeedExpression = null;
if (AttributeUtils.isAttribute(windSpeed)) {
String propertyName = AttributeUtils.extract(windSpeed);
windSpeedExpression = getFilterFactory().property(propertyName);
DataSourceInterface dataSource = DataSourceFactory.getDataSource();
dataSource.addField(new DataSourceAttributeData(propertyName, Double.class, null));
} else {
windSpeedExpression = getFilterFactory().literal(windSpeed);
}
boolean isNorthernHemisphere = !wellKnownName.endsWith(HEMISPHERE_S);
fieldConfigVisitor.populateField(FieldIdEnum.WINDBARB_WINDSPEED, windSpeedExpression);
fieldConfigVisitor.populateBooleanField(FieldIdEnum.WINDBARB_NORTHERN_HEMISPHERE, isNorthernHemisphere);
String windSpeedUnits = wellKnownName.substring(startUnitsOpenBracket + 1, endUnitsOpenBracket);
fieldConfigVisitor.populateComboBoxField(FieldIdEnum.WINDBARB_WINDSPEED_UNITS, windSpeedUnits);
}
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class DataSourceAttributeDataTest method testEquals.
@Test
public void testEquals() {
String expectedName1 = "test name";
Class<?> expectedType1 = Integer.class;
Object expectedValue1 = Integer.valueOf(42);
DataSourceAttributeData dsa1 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue1);
DataSourceAttributeData dsa3 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue1);
assertEquals(dsa1, dsa1);
assertEquals(dsa1, dsa3);
assertEquals(dsa1.hashCode(), dsa1.hashCode());
assertFalse(dsa1.equals(null));
String expectedName2 = "test name2";
Class<?> expectedType2 = Double.class;
Object expectedValue2 = Integer.valueOf(24);
DataSourceAttributeData dsa2 = new DataSourceAttributeData(expectedName2, expectedType2, expectedValue2);
assertFalse(dsa1.equals(dsa2));
DataSourceAttributeData obj1 = new DataSourceAttributeData(expectedName1, expectedType2, expectedValue1);
assertFalse(dsa1.equals(obj1));
assertFalse(dsa1.equals(new DataSourceAttributeData(expectedName1, null, expectedValue1)));
assertFalse(dsa1.equals(new DataSourceAttributeData(null, expectedType1, expectedValue1)));
DataSourceAttributeData obj2 = new DataSourceAttributeData(expectedName1, expectedType1, expectedValue2);
assertTrue(dsa1.equals(obj2));
assertFalse(new DataSourceAttributeData(null, expectedType1, expectedValue1).equals(dsa1));
assertFalse(new DataSourceAttributeData(expectedName1, null, expectedValue1).equals(dsa1));
assertTrue(new DataSourceAttributeData(expectedName1, expectedType1, null).equals(dsa1));
DataSourceAttributeData obj3 = new DataSourceAttributeData(null, expectedType1, expectedValue1);
assertFalse(obj3.equals("wrong class"));
}
use of com.sldeditor.datasource.attribute.DataSourceAttributeData in project sldeditor by robward-scisys.
the class DataSourceAttributeDataTest method testSetType.
/**
* Test method for {@link com.sldeditor.datasource.attribute.DataSourceAttributeData#setType(java.lang.Class)}.
*/
@Test
public void testSetType() {
String expectedName = "test name";
Class<?> expectedType1 = Integer.class;
Object expectedValue = Integer.valueOf(42);
DataSourceAttributeData dsa = new DataSourceAttributeData(expectedName, expectedType1, expectedValue);
Class<?> expectedType2 = Float.class;
dsa.setType(expectedType2);
assertEquals(expectedType2, dsa.getType());
}
Aggregations