Issue 306: started converting to name based instead of id based vcloud operations

This commit is contained in:
Adrian Cole 2010-07-11 18:53:00 -07:00
parent 23c9bbe33c
commit b641dbc1f1
1 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,54 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
package org.jclouds.vcloud.functions;
import java.net.URI;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.VDC;
import com.google.common.base.Function;
/**
*
* @author Adrian Cole
*/
@Singleton
public class VDCNameToEndpoint implements Function<Object, URI> {
private final URI defaultVDC;
private final Organization org;
@Inject
public VDCNameToEndpoint(Organization org, @VDC URI defaultVDC) {
this.org = org;
this.defaultVDC = defaultVDC;
}
public URI apply(Object from) {
try {
return from == null ? defaultVDC : org.getVDCs().get(from).getLocation();
} catch (NullPointerException e) {
throw new IllegalArgumentException("vdc name: " + from + " not in " + org.getVDCs());
}
}
}