+ @Override
+ public <T extends BaseIdentity> Class<? extends T> resolveIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass) {
+ final QName qName = QName.create(identityRef.getqNameOfIdentity());
+ IdentityCodec<?> identityCodec = codecRegistry.getIdentityCodec();
+ Class<? extends BaseIdentity> deserialized = identityCodec.deserialize(qName);
+ if (deserialized == null) {
+ throw new IllegalStateException("Unable to retrieve identity class for " + qName + ", null response from "
+ + codecRegistry);
+ }
+ if (expectedBaseClass.isAssignableFrom(deserialized)) {
+ return (Class<T>) deserialized;
+ } else {
+ LOG.error("Cannot resolve class of identity {} : deserialized class {} is not a subclass of {}.",
+ identityRef, deserialized, expectedBaseClass);
+ throw new IllegalArgumentException("Deserialized identity " + deserialized + " cannot be cast to " + expectedBaseClass);
+ }
+ }
+
+ @Override
+ public <T extends BaseIdentity> void validateIdentity(IdentityAttributeRef identityRef, Class<T> expectedBaseClass, JmxAttribute jmxAttribute) {
+ try {
+ resolveIdentity(identityRef, expectedBaseClass);
+ } catch (Exception e) {
+ throw JmxAttributeValidationException.wrap(e, jmxAttribute);
+ }
+ }
+