public static Class<?> getDescriptionClass(String type) { ResourceType resourceType = ResourceType.fromContentType(type); Class<?> clazz = CompositeComponentRegistry .metaByType(resourceType.getName()).descriptionClass; return clazz; }
@SuppressWarnings("unchecked") public static ComponentTemplate<?> deserializeComponent(Map<String, Object> obj, ObjectMapper objectMapper) { String contentType = (String) obj.get("type"); ResourceType resourceType = ResourceType.fromContentType(contentType); Class<? extends ResourceState> descriptionClass = CompositeComponentRegistry .metaByType(resourceType.getName()).descriptionClass; Map<String, Object> data = (Map<String, Object>) obj.get("data"); Map<String, NestedState> children = deserializeChildren(data, descriptionClass); ComponentTemplate<?> componentTemplate = objectMapper .convertValue(obj, ComponentTemplate.class); componentTemplate.children = children; return componentTemplate; }
private NestedState createComponentNestedState(ComponentTemplate<?> component) { NestedState nestedState = new NestedState(); nestedState.object = (ServiceDocument) component.data; nestedState.children = component.children; ResourceType resourceType = ResourceType.fromContentType(component.type); String factoryLink = CompositeComponentRegistry .descriptionFactoryLinkByType(resourceType.getName()); nestedState.factoryLink = factoryLink; return nestedState; }
@Test public void fromContentType() { ResourceType r = ResourceType.fromContentType("App.Closure"); assertSame(ResourceType.CLOSURE_TYPE, r); try { ResourceType.fromContentType("App.LoadBalancer"); fail("CONTAINER_LOAD_BALANCER_TYPE should throw error"); } catch (Exception ignored) { } }