protected Location newLocationFromString(String spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) {
Matcher matcher = PATTERN.matcher(spec);
if (!matcher.matches()) {
throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify something like single(named:foo)");
}
String namedLocation = (String) locationFlags.get("named");
String args = matcher.group(2);
Map<String,?> locationArgs = KeyValueParser.parseMap(args);
Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null, namedLocation, properties);
MutableMap<String, Object> flags = MutableMap.<String, Object>builder()
.putAll(filteredProperties)
.putAll(locationFlags)
.removeAll("named")
.putAll(locationArgs).build();
if (locationArgs.get("target") == null) {
throw new IllegalArgumentException("target must be specified in single-machine spec");
}
String target = locationArgs.get("target").toString();
locationArgs.remove("target");
if (!managementContext.getLocationRegistry().canResolve(target)) {
throw new IllegalArgumentException("Invalid target location '" + target + "'; must be resolvable location");
}
return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class)
.configure("location", target)
.configure("locationFlags", flags));
}