fillModify(application, mc.getJndiMapper().getSource().getModifyList(),
mc.getJndiMapper().getMaps(), mc.getJndiMapper().getRegexps());
}
public void saveMapping(Application application, String mapFile) throws MappingException {
MapperConfig mapperConfig = new MapperConfig();
java.util.Collection variables = application.getVariables();
for (Iterator it = variables.iterator(); it.hasNext();) {
Variable variable = new Variable();
fr.norsys.mapper.console.model.Variable v = (fr.norsys.mapper.console.model.Variable)it.next();
BeanUtils.copyFilledProperties(variable, v);
mapperConfig.addVariable(variable);
}
Connection connection = application.getConnection();
mapperConfig.getJndiMapper().getSource().setName(connection.getName());
Config config = mapperConfig.getJndiMapper().getSource().getConfig();
config.getProperties().add(
new Property(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory"));
config.getProperties().add(
new Property(Context.PROVIDER_URL, connection.getUrl()));
config.getProperties().add(
new Property(Context.SECURITY_PRINCIPAL, connection.getUser()));
config.getProperties()
.add(
new Property(Context.SECURITY_CREDENTIALS, connection
.getPass()));
config.getProperties().add(
new Property("jndi.connection.pool.minPoolSize", connection
.getMinPoolSize()));
config.getProperties().add(
new Property("jndi.connection.pool.maxPoolSize", connection
.getMaxPoolSize()));
config.getProperties().add(
new Property("jndi.connection.pool.timeout", connection
.getTimeoutPool()));
config.getProperties().add(
new Property("jndi.connection.name", connection.getName()));
mapperConfig.getSubConfig().setName(
"http://norsys.fr/framework-ldap/jndi-configuration.dtd");
mapperConfig.getSubConfig().setClasse(
"fr.norsys.mapper.jndi.JNDIXMLConfigurator");
Mapper mapper = null;
for (Iterator it = application.getResources().iterator(); it
.hasNext();) {
Resource r = (Resource) (it.next());
String name = r.getName();
StringBuffer root = new StringBuffer();
Map inputMap = new Map("input-" + name);
Map outputMap = new Map("output-" + name);
if(r.getIdentifiant()!=null && r.getIdentifiant().length()>0){
root.append(r.getIdentifiant()).append(",");
}
root.append(r.getBaseDn());
if (ConsoleCst.SEARCH_MAPPER_TYPE.equals(r.getType())) {
mapper = new Search(name, "input-" + name, "output-" + name, r
.getFilter(), root.toString(), r.getScope(),
"true", "true", r.getCountLimit());
mapperConfig.getJndiMapper().getSource().getSearchList().add(mapper);
} else if (ConsoleCst.ADD_MAPPER_TYPE.equals(r.getType())) {
mapper = new Add(name, "input-" + name, "output-" + name, root.toString());
mapperConfig.getJndiMapper().getSource().getAddList().add(mapper);
} else if (ConsoleCst.DELETE_MAPPER_TYPE.equals(r.getType())) {
mapper = new Delete(name, "input-" + name, "output-" + name, root.toString());
mapperConfig.getJndiMapper().getSource().getDeleteList().add(mapper);
} else if (ConsoleCst.MODIFY_MAPPER_TYPE.equals(r.getType())) {
mapper = new Modify(name, "input-" + name, "output-" + name, root.toString());
mapperConfig.getJndiMapper().getSource().getModifyList().add(mapper);
}
for (Iterator it2 = r.getAttributes().iterator(); it2
.hasNext();) {
Attribute a = (Attribute)it2.next();
if(a.getRule() != null && !"".equals(a.getRule())) {
mapper.getRegexps().add(new RegExp(a.getName(),a.getRule(),a.getIgnoreNull()));
}
String type = a.getInputOutput();
if (ConsoleCst.INPUT_ATTRIBUTE_TYPE.equals(type)) {
inputMap.getAttributes().add(
new fr.norsys.mapper.console.mapping.Attribute(a
.getName(), a.getDefaultValue()));
} else if (ConsoleCst.OUTPUT_ATTRIBUTE_TYPE.equals(type)) {
outputMap.getAttributes().add(
new fr.norsys.mapper.console.mapping.Attribute(a
.getAttributeLDAP(), a.getName()));
} else if (ConsoleCst.INPUT_OUTPUT_ATTRIBUTE_TYPE.equals(type)) {
inputMap.getAttributes().add(
new fr.norsys.mapper.console.mapping.Attribute(a
.getName(), a.getDefaultValue()));
outputMap.getAttributes().add(
new fr.norsys.mapper.console.mapping.Attribute(a
.getAttributeLDAP(), a.getName()));
}
}
mapperConfig.getJndiMapper().getMaps().add(inputMap);
mapperConfig.getJndiMapper().getMaps().add(outputMap);
}
marshall(mapperConfig, mapFile);
}