org.xlcloud.service.heat.template.fields.IntrinsicFunctionField Maven / Gradle / Ivy
/*
* Copyright 2012 AMG.lab, a Bull Group Company
*
* 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.xlcloud.service.heat.template.fields;
import org.apache.commons.lang.StringUtils;
import org.json.JSONException;
/**
* Intrinsic Function for AWS CloudFormation templates
*
* @see AWS CloudFormation Intrinsic Function Reference
*
* @author Piotr Kulasek-Szwed, AMG.net
*/
public enum IntrinsicFunctionField implements JsonKey {
REF("Ref"),
BASE64("Fn::Base64"),
JOIN("Fn::Join"),
GET_ATT("Fn::GetAtt"),
GET_AZS("Fn::GetAZs"),
FIND_IN_MAP("Fn::FindInMap");
private String jsonKey;
private IntrinsicFunctionField( String key ) {
this.jsonKey = key;
}
/** {@inheritDoc} */
@Override
public String jsonKey() {
return jsonKey;
}
/**
* @param key
* key to check, cannot be null or blank
* @return false if specified key doesn't correspond to any (supported)
* intrinsic function
*/
public static boolean isFunction(String key) {
try {
return getFunctionField(key) != null;
} catch (JSONException e) {
return false;
}
}
/**
* @param key
* key to check, cannot be null or blank
* @return {@link IntrinsicFunctionField} corresponding to specified key or
* null - if non of (supported) intrinsic functions correspond to
* one
* @throws JSONException
*/
public static IntrinsicFunctionField getFunctionField(String key) throws JSONException {
if (StringUtils.isBlank(key)) {
throw new JSONException("Intrinsic function name cannot be empty");
}
for (IntrinsicFunctionField field : values()) {
if (field.jsonKey.equals(key)) {
return field;
}
}
return null;
}
}