use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class ShapeSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
// $NON-NLS-1$
progress.begin(Messages.getString("ShapeSchemaProvider.1"), ProgressIndicator.UNKNOWN);
// DataStore store = new ShapefileDataStoreFactory().createDataStore(location.toURL());
// DataStore store = FileDataStoreFinder.getDataStore(getSource().getLocation().toURL());
ShapefileDataStore store = new ShapefileDataStore(getSource().getLocation().toURL());
store.setCharset(getCharset());
// TODO namespace from configuration parameter?!
String namespace = ShapefileConstants.SHAPEFILE_NS;
DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
// $NON-NLS-1$
progress.setCurrentTask(Messages.getString("ShapeSchemaProvider.2"));
// create type for augmented filename property
QName filenameTypeName = new QName(SHAPEFILE_AUGMENT_NS, "filenameType");
TypeDefinition filenameType = null;
if (getSharedTypes() != null) {
filenameType = getSharedTypes().getType(filenameTypeName);
}
if (filenameType == null) {
DefaultTypeDefinition fnt = new DefaultTypeDefinition(filenameTypeName);
fnt.setConstraint(MappableFlag.DISABLED);
fnt.setConstraint(MappingRelevantFlag.DISABLED);
fnt.setConstraint(Binding.get(String.class));
fnt.setConstraint(HasValueFlag.ENABLED);
filenameType = fnt;
}
// build type definitions based on Schema extracted by geotools
for (Name name : store.getNames()) {
SimpleFeatureType sft = store.getSchema(name);
try {
// create type definition
DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(namespace, sft.getName().getLocalPart()));
// constraints on main type
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
type.setConstraint(Binding.get(Instance.class));
for (AttributeDescriptor ad : sft.getAttributeDescriptors()) {
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(ad.getLocalName()), type, getTypeFromAttributeType(ad.getType(), schema, namespace));
// set constraints on property
// nillable
property.setConstraint(NillableFlag.get(ad.isNillable()));
// cardinality
property.setConstraint(Cardinality.get(ad.getMinOccurs(), ad.getMaxOccurs()));
// set metadata
property.setLocation(getSource().getLocation());
}
// add additional filename property
// String filename = sft.getName().getLocalPart();
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(SHAPEFILE_AUGMENT_NS, AUGMENTED_PROPERTY_FILENAME), type, filenameType);
property.setConstraint(Cardinality.CC_EXACTLY_ONCE);
property.setConstraint(NillableFlag.ENABLED);
schema.addType(type);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
progress.setCurrentTask(MessageFormat.format(// $NON-NLS-1$
Messages.getString("ShapeSchemaProvider.7"), sft.getTypeName()));
}
reporter.setSuccess(true);
return schema;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class XLSSchemaReader method loadFromSource.
@Override
protected Schema loadFromSource(ProgressIndicator progress, IOReporter reporter) throws IOProviderConfigurationException, IOException {
sheetNum = getParameter(InstanceTableIOConstants.SHEET_INDEX).as(int.class, 0);
progress.begin("Load XLS/XLSX schema", ProgressIndicator.UNKNOWN);
String namespace = "http://www.esdi-humboldt.eu/hale/xls";
DefaultSchema schema = new DefaultSchema(namespace, getSource().getLocation());
AnalyseXLSSchemaTable analyser;
try {
analyser = new AnalyseXLSSchemaTable(getSource().getLocation(), sheetNum);
header = analyser.getHeader();
// create type definition
String typename = getParameter(CommonSchemaConstants.PARAM_TYPENAME).as(String.class);
if (typename == null || typename.isEmpty()) {
reporter.setSuccess(false);
reporter.error(new IOMessageImpl("No Typename was set", null));
return null;
}
DefaultTypeDefinition type = new DefaultTypeDefinition(new QName(typename));
// constraints on main type
type.setConstraint(MappingRelevantFlag.ENABLED);
type.setConstraint(MappableFlag.ENABLED);
type.setConstraint(HasValueFlag.DISABLED);
type.setConstraint(AbstractFlag.DISABLED);
// set metadata for main type
type.setLocation(getSource().getLocation());
StringBuffer defaultPropertyTypeBuffer = new StringBuffer();
String[] comboSelections;
if (getParameter(PARAM_PROPERTYTYPE).isEmpty()) {
for (int i = 0; i < header.size(); i++) {
defaultPropertyTypeBuffer.append("java.lang.String");
defaultPropertyTypeBuffer.append(",");
}
defaultPropertyTypeBuffer.deleteCharAt(defaultPropertyTypeBuffer.lastIndexOf(","));
String combs = defaultPropertyTypeBuffer.toString();
comboSelections = combs.split(",");
} else {
comboSelections = getParameter(PARAM_PROPERTYTYPE).as(String.class).split(",");
}
String[] properties;
if (getParameter(PARAM_PROPERTY).isEmpty()) {
properties = header.toArray(new String[0]);
} else {
properties = getParameter(PARAM_PROPERTY).as(String.class).split(",");
}
// than the entries in the first line
if ((header.size() != properties.length && properties.length != 0) || (header.size() != comboSelections.length && comboSelections.length != 0)) {
fail("Not the same number of entries for property names, property types and words in the first line of the file");
}
for (int i = 0; i < comboSelections.length; i++) {
PropertyType propertyType = PropertyTypeExtension.getInstance().getFactory(comboSelections[i]).createExtensionObject();
DefaultPropertyDefinition property = new DefaultPropertyDefinition(new QName(properties[i]), type, propertyType.getTypeDefinition());
configureProperty(property);
}
boolean skip = Arrays.equals(properties, header.toArray(new String[0]));
type.setConstraint(new CSVConfiguration(CSVUtil.getSep(this), CSVUtil.getQuote(this), CSVUtil.getEscape(this), skip));
schema.addType(type);
} catch (Exception e) {
reporter.error(new IOMessageImpl("Cannot load xls/xlsx schema", e));
reporter.setSuccess(false);
return null;
}
reporter.setSuccess(true);
return schema;
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class XmlSchemaReader method setMetadata.
/**
* Set the metadata for a definition
*
* @param definition the definition
* @param annotated the XML annotated object
* @param schemaLocation the schema location
*/
public static void setMetadata(AbstractDefinition<?> definition, XmlSchemaAnnotated annotated, String schemaLocation) {
definition.setDescription(XMLSchemaIO.getDescription(annotated));
List<XmlSchemaAppInfo> appInfo = XMLSchemaIO.getAppInfo(annotated);
if (appInfo != null) {
XmlAppInfo constraint = new XmlAppInfo(appInfo);
if (definition instanceof DefaultPropertyDefinition) {
((DefaultPropertyDefinition) definition).setConstraint(constraint);
} else if (definition instanceof DefaultGroupPropertyDefinition) {
((DefaultGroupPropertyDefinition) definition).setConstraint(constraint);
} else if (definition instanceof DefaultTypeDefinition) {
((DefaultTypeDefinition) definition).setConstraint(constraint);
}
}
definition.setLocation(createLocationURI(schemaLocation, annotated));
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class XmlSchemaReader method createAttribute.
private void createAttribute(XmlSchemaAttribute attribute, DefinitionGroup declaringGroup, String schemaLocation, String schemaNamespace) {
// create attributes
QName typeName = attribute.getSchemaTypeName();
if (typeName != null) {
QName attributeName = determineAttributeName(attribute, schemaNamespace);
// resolve type by name
XmlTypeDefinition type = getTypeForAttribute(typeName, declaringGroup, attributeName);
// create property
DefaultPropertyDefinition property = new DefaultPropertyDefinition(attributeName, declaringGroup, type);
// set metadata and constraints
setMetadataAndConstraints(property, attribute, schemaLocation);
} else if (attribute.getSchemaType() != null) {
XmlSchemaSimpleType simpleType = attribute.getSchemaType();
// create an anonymous type
QName anonymousName = new QName(getTypeIdentifier(declaringGroup) + "/" + attribute.getName(), // $NON-NLS-2$
"AnonymousType");
AnonymousXmlType anonymousType = new AnonymousXmlType(anonymousName);
configureSimpleType(anonymousType, simpleType, schemaLocation);
// create property
DefaultPropertyDefinition property = new DefaultPropertyDefinition(determineAttributeName(attribute, schemaNamespace), declaringGroup, anonymousType);
// set metadata and constraints
setMetadataAndConstraints(property, attribute, schemaLocation);
} else if (attribute.getRefName() != null) {
// <attribute ref="REF_NAME" />
// reference to a named attribute
QName attName = attribute.getRefName();
XmlAttributeReferenceProperty property = new XmlAttributeReferenceProperty(attName, declaringGroup, this.index, attName);
// set metadata and constraints
setMetadataAndConstraints(property, attribute, schemaLocation);
} else {
/*
* Attribute with no type given has anySimpleType, see
* "http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#cAttribute_Declarations"
*/
// resolve type by name
XmlTypeDefinition type = index.getOrCreateType(new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "anySimpleType"));
// create property
DefaultPropertyDefinition property = new DefaultPropertyDefinition(determineAttributeName(attribute, schemaNamespace), declaringGroup, type);
// set metadata and constraints
setMetadataAndConstraints(property, attribute, schemaLocation);
}
}
use of eu.esdihumboldt.hale.common.schema.model.impl.DefaultPropertyDefinition in project hale by halestudio.
the class PropertyFunctionScriptPage method addActions.
@Override
protected void addActions(ToolBar toolbar, CompilingSourceViewer<GroovyAST> viewer) {
super.addActions(toolbar, viewer);
PageHelp.createToolItem(toolbar, this);
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.SOURCE, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
// create a dummy type with the variables as children
DefaultTypeDefinition dummy = new DefaultTypeDefinition(TypeStructureTray.VARIABLES_TYPE_NAME);
DefaultCustomPropertyFunction cf = getWizard().getUnfinishedFunction();
int index = 0;
for (EntityDefinition variable : getVariables()) {
DefaultCustomPropertyFunctionEntity source = cf.getSources().get(index);
if (variable.getDefinition() instanceof PropertyDefinition) {
PropertyDefinition prop = (PropertyDefinition) variable.getDefinition();
TypeDefinition propertyType;
boolean useInstanceValue = CustomGroovyTransformation.useInstanceVariableForSource(source);
if (useInstanceValue) {
// use instance type
propertyType = prop.getPropertyType();
} else {
// use dummy type with only the
// binding/HasValueFlag copied
DefaultTypeDefinition crippledType = new DefaultTypeDefinition(prop.getPropertyType().getName());
crippledType.setConstraint(prop.getPropertyType().getConstraint(Binding.class));
crippledType.setConstraint(prop.getPropertyType().getConstraint(HasValueFlag.class));
propertyType = crippledType;
}
DefaultPropertyDefinition dummyProp = new DefaultPropertyDefinition(new QName(source.getName()), dummy, propertyType);
// number of times
if (source.isEager())
dummyProp.setConstraint(Cardinality.CC_ANY_NUMBER);
}
index++;
}
return Collections.singleton(dummy);
}
});
TypeStructureTray.createToolItem(toolbar, this, SchemaSpaceID.TARGET, new TypeProvider() {
@Override
public Collection<? extends TypeDefinition> getTypes() {
DefaultCustomPropertyFunctionEntity target = getWizard().getUnfinishedFunction().getTarget();
if (target != null) {
return Collections.singleton(createDummyType(target));
}
return Collections.emptyList();
}
});
}
Aggregations