class ViewRegistry {

  public void installViewInstance(ViewInstanceEntity instanceEntity)
      throws ValidationException, IllegalArgumentException, SystemException {
    ViewEntity viewEntity = getDefinition(instanceEntity.getViewName());

    if (viewEntity != null) {
      String instanceName = instanceEntity.getName();
      String viewName = viewEntity.getCommonName();
      String version = viewEntity.getVersion();

      if (getInstanceDefinition(viewName, version, instanceName) == null) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Creating view instance {}/{}/{}", viewName, version, instanceName);
        }

        instanceEntity.validate(viewEntity, Validator.ValidationContext.PRE_CREATE);
        setPersistenceEntities(instanceEntity);

        ViewInstanceEntity persistedInstance = mergeViewInstance(instanceEntity, viewEntity.getResourceType());

        instanceEntity.setViewInstanceId(persistedInstance.getViewInstanceId());
        syncViewInstance(instanceEntity, persistedInstance);

        try {
          // bind the view instance to a view
          bindViewInstance(viewEntity, instanceEntity);
        } catch (Exception e) {
          String message = "Caught exception installing view instance.";
          LOG.error(message, e);
          throw new IllegalStateException(message, e);
        }
        // update the registry
        addInstanceDefinition(viewEntity, instanceEntity);

        // add the web app context
        handlerList.addViewInstance(instanceEntity);
      }

    } else {
      String message = "Attempt to install an instance for an unknown view " +
          instanceEntity.getViewName() + ".";

      LOG.error(message);
      throw new IllegalArgumentException(message);
    }
  }

  @Inject public  ViewRegistry(AmbariEventPublisher publisher);

}