static void validateResourceModel(ModelNode modelNode, boolean allowExternal) throws OperationFailedException { final BindingType type = BindingType.forName(modelNode.require(NamingSubsystemModel.BINDING_TYPE).asString()); if (type == BindingType.SIMPLE) { if (!modelNode.hasDefined(NamingBindingResourceDefinition.VALUE.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.VALUE.getName()); } if (modelNode.hasDefined(NamingBindingResourceDefinition.CACHE.getName()) && modelNode.get(NamingBindingResourceDefinition.CACHE.getName()).asBoolean()) { throw NamingLogger.ROOT_LOGGER.cacheNotValidForBindingType(type); } } else if (type == BindingType.OBJECT_FACTORY) { if (!modelNode.hasDefined(NamingBindingResourceDefinition.MODULE.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.MODULE.getName()); } if (!modelNode.hasDefined(NamingBindingResourceDefinition.CLASS.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.CLASS.getName()); } if (modelNode.hasDefined(NamingBindingResourceDefinition.CACHE.getName()) && modelNode.get(NamingBindingResourceDefinition.CACHE.getName()).asBoolean()) { throw NamingLogger.ROOT_LOGGER.cacheNotValidForBindingType(type); } } else if (type == BindingType.EXTERNAL_CONTEXT) { if (!allowExternal) { throw NamingLogger.ROOT_LOGGER.cannotRebindExternalContext(); } if (!modelNode.hasDefined(NamingBindingResourceDefinition.MODULE.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.MODULE.getName()); } if (!modelNode.hasDefined(NamingBindingResourceDefinition.CLASS.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.CLASS.getName()); } } else if (type == BindingType.LOOKUP) { if (!modelNode.hasDefined(NamingBindingResourceDefinition.LOOKUP.getName())) { throw NamingLogger.ROOT_LOGGER.bindingTypeRequiresAttributeDefined( type, NamingBindingResourceDefinition.LOOKUP.getName()); } if (modelNode.hasDefined(NamingBindingResourceDefinition.CACHE.getName()) && modelNode.get(NamingBindingResourceDefinition.CACHE.getName()).asBoolean()) { throw NamingLogger.ROOT_LOGGER.cacheNotValidForBindingType(type); } } else { throw NamingLogger.ROOT_LOGGER.unknownBindingType(type.toString()); } }
private static BindingType parseBindingType(String str) throws BindingConfigParseException { if (str == null) { throw new BindingConfigParseException(KEY_BINDING_TYPE); } try { return BindingType.valueOf(str); } catch (Exception e) { throw new BindingConfigParseException("error parsing " + KEY_BINDING_TYPE); } }