Пример #1
0
    @Override
    public Component tagToComponent(
        String tagName, ComponentFactory componentFactory, DesignContext context) {
      // Extract the package and class names.
      // Otherwise, get the full class name using the prefix to package
      // mapping. Example: "v-vertical-layout" ->
      // "com.vaadin.ui.VerticalLayout"
      String[] parts = tagName.split("-", 2);
      if (parts.length < 2) {
        throw new DesignException("The tagname '" + tagName + "' is invalid: missing prefix.");
      }
      String prefixName = parts[0];
      String packageName = context.getPackage(prefixName);
      if (packageName == null) {
        throw new DesignException("Unknown tag: " + tagName);
      }
      String[] classNameParts = parts[1].split("-");
      String className = "";
      for (String classNamePart : classNameParts) {
        // Split will ignore trailing and multiple dashes but that
        // should be
        // ok
        // <v-button--> will be resolved to <v-button>
        // <v--button> will be resolved to <v-button>
        className += SharedUtil.capitalize(classNamePart);
      }
      String qualifiedClassName = packageName + "." + className;

      Component component = componentFactory.createComponent(qualifiedClassName, context);

      if (component == null) {
        throw new DesignException(
            "Got unexpected null component from "
                + componentFactory.getClass().getName()
                + " for class "
                + qualifiedClassName);
      }

      return component;
    }