use of com.evolveum.midpoint.prism.ComplexTypeDefinitionImpl in project midpoint by Evolveum.
the class ConnectorFactoryConnIdImpl method generateConnectorConfigurationSchema.
private PrismSchema generateConnectorConfigurationSchema(ConnectorInfo cinfo, ConnectorType connectorType) {
LOGGER.trace("Generating configuration schema for {}", this);
APIConfiguration defaultAPIConfiguration = cinfo.createDefaultAPIConfiguration();
ConfigurationProperties icfConfigurationProperties = defaultAPIConfiguration.getConfigurationProperties();
if (icfConfigurationProperties == null || icfConfigurationProperties.getPropertyNames() == null || icfConfigurationProperties.getPropertyNames().isEmpty()) {
LOGGER.debug("No configuration schema for {}", this);
return null;
}
PrismSchema connectorSchema = new PrismSchemaImpl(connectorType.getNamespace(), prismContext);
// Create configuration type - the type used by the "configuration"
// element
PrismContainerDefinitionImpl<?> configurationContainerDef = ((PrismSchemaImpl) connectorSchema).createPropertyContainerDefinition(ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(), SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
// element with "ConfigurationPropertiesType" - the dynamic part of
// configuration schema
ComplexTypeDefinition configPropertiesTypeDef = ((PrismSchemaImpl) connectorSchema).createComplexTypeDefinition(new QName(connectorType.getNamespace(), ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_TYPE_LOCAL_NAME));
// Create definition of "configurationProperties" type
// (CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_TYPE_LOCAL_NAME)
int displayOrder = 1;
for (String icfPropertyName : icfConfigurationProperties.getPropertyNames()) {
ConfigurationProperty icfProperty = icfConfigurationProperties.getProperty(icfPropertyName);
QName propXsdType = ConnIdUtil.icfTypeToXsdType(icfProperty.getType(), icfProperty.isConfidential());
LOGGER.trace("{}: Mapping ICF config schema property {} from {} to {}", new Object[] { this, icfPropertyName, icfProperty.getType(), propXsdType });
PrismPropertyDefinitionImpl<?> propertyDefinifion = ((ComplexTypeDefinitionImpl) configPropertiesTypeDef).createPropertyDefinition(icfPropertyName, propXsdType);
propertyDefinifion.setDisplayName(icfProperty.getDisplayName(null));
propertyDefinifion.setHelp(icfProperty.getHelpMessage(null));
if (ConnIdUtil.isMultivaluedType(icfProperty.getType())) {
propertyDefinifion.setMaxOccurs(-1);
} else {
propertyDefinifion.setMaxOccurs(1);
}
if (icfProperty.isRequired() && icfProperty.getValue() == null) {
// If ICF says that the property is required it may not be in fact really required if it also has a default value
propertyDefinifion.setMinOccurs(1);
} else {
propertyDefinifion.setMinOccurs(0);
}
propertyDefinifion.setDisplayOrder(displayOrder);
displayOrder++;
}
// Create common ICF configuration property containers as a references
// to a static schema
configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_CONNECTOR_POOL_CONFIGURATION_TYPE, 0, 1);
configurationContainerDef.createPropertyDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_PRODUCER_BUFFER_SIZE_TYPE, 0, 1);
configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_TIMEOUTS_TYPE, 0, 1);
configurationContainerDef.createContainerDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_RESULTS_HANDLER_CONFIGURATION_TYPE, 0, 1);
configurationContainerDef.createPropertyDefinition(ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_ELEMENT, ConnectorFactoryConnIdImpl.CONNECTOR_SCHEMA_LEGACY_SCHEMA_TYPE, 0, 1);
// No need to create definition of "configuration" element.
// midPoint will look for this element, but it will be generated as part
// of the PropertyContainer serialization to schema
configurationContainerDef.createContainerDefinition(SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_PROPERTIES_ELEMENT_QNAME, configPropertiesTypeDef, 1, 1);
LOGGER.debug("Generated configuration schema for {}: {} definitions", this, connectorSchema.getDefinitions().size());
return connectorSchema;
}
Aggregations