}
public VirtualFile applyTemplate(DeploymentTemplateInfo sourceInfo) throws Exception {
try {
DeploymentTemplateInfo targetInfo = this.targetTemplate.getInfo();
// override these properties always.
targetInfo.getProperties().get("connection-definition").setValue(SimpleValueSupport.wrap(ConnectionFactory.class.getName()));//$NON-NLS-1$
targetInfo.getProperties().get("rar-name").setValue(SimpleValueSupport.wrap(((ConnectorTemplateInfo)getInfo()).getRarName()));//$NON-NLS-1$
//config-properties list
List<String> connectorPropNames = RaXmlPropertyConverter.getPropertyNames(((ConnectorTemplateInfo)getInfo()).getRarName());
Map<String, String> configProps = ConnectorDeploymentTemplate.propertiesAsMap(sourceInfo, connectorPropNames.toArray(new String[connectorPropNames.size()]), info.getName());
configProps.put(ConnectorTemplateInfo.TEMPLATE_NAME, getInfo().getName());
// template properties specific to the template
Map<String, ManagedProperty> propertyMap = targetInfo.getProperties();
// walk through the supplied properties and assign properly to either template
// or config-properties.
for (String key:sourceInfo.getProperties().keySet()) {
ManagedProperty mp = propertyMap.get(key);
if (mp != null) {
// property found in target, so just add as value
MetaValue value = sourceInfo.getProperties().get(key).getValue();
if (ManagedUtil.sameValue(mp.getDefaultValue(), value)) {
continue;
}
if (value != null) {
mp.setValue(value);
}
}
else {
// property not found in the target; add as "config-property"
mp = sourceInfo.getProperties().get(key);
if (ManagedUtil.sameValue(mp.getDefaultValue(), mp.getValue())) {
continue;
}
if (mp.getValue() != null) {
configProps.put(key, ManagedUtil.stringValue(mp.getValue()));
configProps.put(key+".type", mp.getValue().getMetaType().getClassName());//$NON-NLS-1$
}
}
}
if (configProps.size() > 0) {
MetaValue metaValue = ManagedUtil.compositeValueMap(configProps);
targetInfo.getProperties().get("config-property").setValue(metaValue);//$NON-NLS-1$
}
return this.targetTemplate.applyTemplate(targetInfo);
} catch (NoSuchDeploymentException e) {
throw new AdminComponentException(e.getMessage(), e);