Package org.jboss.errai.bus.server.service.metadata

Examples of org.jboss.errai.bus.server.service.metadata.MetaDataScanner


          config.getSerializableTypes().add(type);
        }
      };

      // Search for Errai extensions.
      MetaDataScanner scanner = context.getScanner();

      Set<Class<?>> extensionComponents = scanner.getTypesAnnotatedWith(ExtensionComponent.class);
      for (Class<?> loadClass : extensionComponents) {
        if (ErraiConfigExtension.class.isAssignableFrom(loadClass)) {
          // We have an annotated ErraiConfigExtension.  So let's configure it.
          final Class<? extends ErraiConfigExtension> clazz =
              loadClass.asSubclass(ErraiConfigExtension.class);
View Full Code Here


    sourceWriter.println("}");

    sourceWriter.println("public void initExtensions(final " + MessageBus.class.getName() + " bus) { ");
    sourceWriter.outdent();

    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    new BusClientConfigGenerator().generate(context, logger, sourceWriter, scanner, typeOracle);

    Set<Class<?>> extensionComponents = scanner.getTypesAnnotatedWith(ExtensionComponent.class);

    for (Class<?> cls : extensionComponents) {
      if (ExtensionGenerator.class.isAssignableFrom(cls)) {
        try {
View Full Code Here

    System.out.println(classStructureBuilder.toJavaString());
  }

  private void generateMarshallers(ConstructorBlockBuilder<?> constructor, Context classContext) {
    MetaDataScanner scanner = MetaDataScanner.createInstance();

    Set<Class<?>> exposed = new HashSet<Class<?>>(scanner.getTypesAnnotatedWith(ExposeEntity.class));
    exposed.addAll(scanner.getTypesAnnotatedWith(Portable.class));

    for (Class<?> clazz : exposed) {
      mappingContext.registerGeneratedMarshaller(clazz.getName());
    }
View Full Code Here

    this.configurator = configurator;
    this.bus = bus;

    try {

      MetaDataScanner scanner = configurator.getMetaDataScanner();
      Set<Class<?>> userEntities = scanner.getTypesAnnotatedWith(AuthUserEntity.class);
      for (Class<?> clazz : userEntities) {
        if (userEntity != null) {
          throw new ErraiBootstrapFailure("More than one @AuthUserEntity defined in classpath (" + userEntity.getName() + " and " + clazz.getName() + " cannot co-exist)");
        }
View Full Code Here

    }

    iocGenerator.generateAllProviders();
   
    final boolean applyFilter = in != null;
    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();

    /**
     * LoadToolSet
     */
    Set<Class<?>> toolsets = scanner.getTypesAnnotatedWith(LoadToolSet.class);
    for(Class<?> toolSetClass : toolsets)
    {
      JClassType clazz = typeOracle.findType(toolSetClass.getName());

      if ((!applyFilter || enabledTools.contains(clazz.getQualifiedSourceName())))
      {
        iocGenerator.addType(clazz);
        String instance = iocGenerator.generateInjectors(clazz);
        sourceWriter.println("workspace.addToolSet(" + instance + ");");
        logger.log(TreeLogger.Type.INFO, "Adding Errai Toolset: " + clazz.getQualifiedSourceName());
      }
    }

    /**
     * LoadTool
     */
    Set<Class<?>> tools = scanner.getTypesAnnotatedWith(LoadTool.class);
    for(Class<?> toolClass : tools)
    {
      JClassType clazz = typeOracle.findType(toolClass.getName());

      if ((!applyFilter || enabledTools.contains(clazz.getQualifiedSourceName())))
      {

        iocGenerator.addType(clazz);
        LoadTool loadTool = clazz.getAnnotation(LoadTool.class);

        logger.log(TreeLogger.Type.INFO, "Adding Errai Tool: " + clazz.getQualifiedSourceName());

        if (clazz.isAnnotationPresent(RequireRoles.class)) {
          RequireRoles requireRoles = clazz.getAnnotation(RequireRoles.class);

          StringBuilder rolesBuilder = new StringBuilder("new String[] {");
          String[] roles = requireRoles.value();

          for (int i = 0; i < roles.length; i++) {
            rolesBuilder.append("\"").append(roles[i].trim()).append("\"");
            if ((i + 1) < roles.length) rolesBuilder.append(", ");
          }
          rolesBuilder.append("}");

          generateWidgetProvisioning(context, clazz.getQualifiedSourceName(), loadTool, rolesBuilder, logger, sourceWriter);

        } else {
          generateWidgetProvisioning(context, clazz.getQualifiedSourceName(), loadTool, null, logger, sourceWriter);

        }
      }
      else if (clazz.isAnnotationPresent(LoginComponent.class))
      {
        sourceWriter.println("workspace.setLoginComponent(new " + clazz.getQualifiedSourceName() + "());");
      }
    }

    /**
     * Group order
     */
    Set<Class<?>> groupOrderClasses = scanner.getTypesAnnotatedWith(GroupOrder.class);
    for(Class<?> clazz : groupOrderClasses)
    {
      GroupOrder groupOrder = clazz.getAnnotation(GroupOrder.class);

      if ("".equals(groupOrder.value().trim())) return;
View Full Code Here

            typeOracle, buildContext, bootStrapClass, blockBuilder);

    injectFactory = new InjectorFactory(procContext);
    procFactory = new IOCProcessorFactory(injectFactory);

    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    Properties props = scanner.getProperties("ErraiApp.properties");
    if (props != null) {
      logger.log(TreeLogger.Type.INFO, "Checking ErraiApp.properties for configured types ...");

      for (Object o : props.keySet()) {
        String key = (String) o;
View Full Code Here

  private void generateExtensions(SourceWriter sourceWriter, ClassStructureBuilder<?> classBuilder,
                                  BlockBuilder<?> blockBuilder) {
    blockBuilder.append(Stmt.declareVariable("ctx", InterfaceInjectionContext.class,
            Stmt.newObject(InterfaceInjectionContext.class)));
    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();

    procFactory.process(scanner, procContext);
    procFactory.processAll();

    runAllDeferred();
View Full Code Here

  }

  public void initializeProviders() {

    final MetaClass typeProviderCls = MetaClassFactory.get(TypeProvider.class);
    MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
    /*
    * IOCDecoratorExtension.class
    */
    Set<Class<?>> iocExtensions = scanner
            .getTypesAnnotatedWith(org.jboss.errai.ioc.client.api.IOCExtension.class);
    List<IOCExtensionConfigurator> extensionConfigurators = new ArrayList<IOCExtensionConfigurator>();
    for (Class<?> clazz : iocExtensions) {
      try {
        Class<? extends IOCExtensionConfigurator> configuratorClass = clazz.asSubclass(IOCExtensionConfigurator.class);

        IOCExtensionConfigurator configurator = configuratorClass.newInstance();

        configurator.configure(procContext, injectFactory, procFactory);

        extensionConfigurators.add(configurator);
      }
      catch (Exception e) {
        throw new ErraiBootstrapFailure("unable to load IOC Extension Configurator: " + e.getMessage(), e);
      }
    }

    /**
     * CodeDecorator.class
     */
    Set<Class<?>> decorators = scanner.getTypesAnnotatedWith(CodeDecorator.class);
    for (Class<?> clazz : decorators) {
      try {
        Class<? extends IOCDecoratorExtension> decoratorClass = clazz.asSubclass(IOCDecoratorExtension.class);

        Class<? extends Annotation> annoType = null;
        Type t = decoratorClass.getGenericSuperclass();
        if (!(t instanceof ParameterizedType)) {
          throw new ErraiBootstrapFailure("code decorator must extend IOCDecoratorExtension<@AnnotationType>");
        }

        ParameterizedType pType = (ParameterizedType) t;
        if (IOCDecoratorExtension.class.equals(pType.getRawType())) {
          if (pType.getActualTypeArguments().length == 0
                  || !Annotation.class.isAssignableFrom((Class) pType.getActualTypeArguments()[0])) {
            throw new ErraiBootstrapFailure("code decorator must extend IOCDecoratorExtension<@AnnotationType>");
          }

          //noinspection unchecked
          annoType = ((Class) pType.getActualTypeArguments()[0]).asSubclass(Annotation.class);
        }

        injectFactory.getInjectionContext().registerDecorator(
                decoratorClass.getConstructor(new Class[]{Class.class}).newInstance(annoType));
      }
      catch (Exception e) {
        throw new ErraiBootstrapFailure("unable to load code decorator: " + e.getMessage(), e);
      }
    }

    /**
     * IOCProvider.class
     */
    Set<Class<?>> providers = scanner.getTypesAnnotatedWith(IOCProvider.class);
    for (Class<?> clazz : providers) {
      MetaClass bindType = null;
      MetaClass type = MetaClassFactory.get(clazz);

      boolean contextual = false;
      for (MetaClass iface : type.getInterfaces()) {
        if (iface.getFullyQualifiedName().equals(Provider.class.getName())) {
          injectFactory.addType(type);

          MetaParameterizedType pType = iface.getParameterizedType();
          MetaType typeParm = pType.getTypeParameters()[0];
          if (typeParm instanceof MetaParameterizedType) {
            bindType = (MetaClass) ((MetaParameterizedType) typeParm).getRawType();
          }
          else {
            bindType = (MetaClass) pType.getTypeParameters()[0];
          }

          boolean isContextual = false;
          for (MetaField field : type.getDeclaredFields()) {
            if (field.isAnnotationPresent(Inject.class)
                    && field.getType().isAssignableTo(ContextualProviderContext.class)) {

              isContextual = true;
              break;
            }
          }

          if (isContextual) {
            injectFactory.addInjector(new ContextualProviderInjector(bindType, type, procContext));
          }
          else {
            injectFactory.addInjector(new ProviderInjector(bindType, type, procContext));
          }
          break;
        }

        if (iface.getFullyQualifiedName().equals(ContextualTypeProvider.class.getName())) {
          contextual = true;

          MetaParameterizedType pType = iface.getParameterizedType();

          if (pType == null) {
            throw new InjectionFailure("could not determine the bind type for the IOCProvider class: "
                    + type.getFullyQualifiedName());
          }

          //todo: check for nested type parameters
          MetaType typeParm = pType.getTypeParameters()[0];
          if (typeParm instanceof MetaParameterizedType) {
            bindType = (MetaClass) ((MetaParameterizedType) typeParm).getRawType();
          }
          else {
            bindType = (MetaClass) pType.getTypeParameters()[0];
          }
          break;
        }
      }

      if (bindType == null) {
        for (MetaClass iface : type.getInterfaces()) {
          if (!typeProviderCls.isAssignableFrom(iface)) {
            continue;
          }

          MetaParameterizedType pType = iface.getParameterizedType();

          if (pType == null) {
            throw new InjectionFailure("could not determine the bind type for the IOCProvider class: "
                    + type.getFullyQualifiedName());
          }

          //todo: check for nested type parameters
          bindType = (MetaClass) pType.getTypeParameters()[0];
        }
      }

      if (bindType == null) {
        throw new InjectionFailure("the annotated provider class does not appear to implement " +
                TypeProvider.class.getName() + ": " + type.getFullyQualifiedName());
      }

      final MetaClass finalBindType = bindType;

      Injector injector;
      if (contextual) {
        injector = new ContextualProviderInjector(finalBindType, type, procContext);
      }
      else {
        injector = new ProviderInjector(finalBindType, type, procContext);
      }

      injectFactory.addInjector(injector);
    }

    /**
     * GeneratedBy.class
     */
    Set<Class<?>> generatedBys = scanner.getTypesAnnotatedWith(GeneratedBy.class);
    for (Class<?> clazz : generatedBys) {
      MetaClass type = MetaClassFactory.get(typeOracle, clazz);
      GeneratedBy anno = type.getAnnotation(GeneratedBy.class);
      Class<? extends ContextualTypeProvider> injectorClass = anno.value();

View Full Code Here

        sourceWriter.println("public InterfaceInjectionContext bootstrapContainer() { ");
        sourceWriter.outdent();
        sourceWriter.println("InterfaceInjectionContext ctx = new InterfaceInjectionContext();");

        MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();
        procFactory.process(scanner, procContext);

        runAllDeferred();

        sourceWriter.println("return ctx;");
View Full Code Here

    }

    public void initializeProviders(final GeneratorContext context, final TreeLogger logger, final SourceWriter sourceWriter) {

        final JClassType typeProviderCls;
        MetaDataScanner scanner = ScannerSingleton.getOrCreateInstance();

        try {
            typeProviderCls = typeOracle.getType(TypeProvider.class.getName());
        }
        catch (NotFoundException e) {
            throw new RuntimeException(e);
        }

        /**
         * IOCExtension.class
         */
        Set<Class<?>> iocExtensions = scanner.getTypesAnnotatedWith(IOCExtension.class);
        for (Class<?> clazz : iocExtensions) {
            try {
                Class<? extends IOCExtensionConfigurator> configuratorClass = clazz.asSubclass(IOCExtensionConfigurator.class);
                configuratorClass.newInstance().configure(procContext, injectFactory, procFactory);
            }
            catch (Exception e) {
                throw new ErraiBootstrapFailure("unable to load IOC Extension Configurator: " + e.getMessage(), e);
            }
        }

        /**
         * CodeDecorator.class
         */
        Set<Class<?>> decorators = scanner.getTypesAnnotatedWith(CodeDecorator.class);
        for (Class<?> clazz : decorators) {
            try {
                Class<? extends Decorator> decoratorClass = clazz.asSubclass(Decorator.class);

                Class<? extends Annotation> annoType = null;
                Type t = decoratorClass.getGenericSuperclass();
                if (!(t instanceof ParameterizedType)) {
                    throw new ErraiBootstrapFailure("code decorator must extend Decorator<@AnnotationType>");
                }

                ParameterizedType pType = (ParameterizedType) t;
                if (Decorator.class.equals(pType.getRawType())) {
                    if (pType.getActualTypeArguments().length == 0 || !Annotation.class.isAssignableFrom((Class) pType.getActualTypeArguments()[0])) {
                        throw new ErraiBootstrapFailure("code decorator must extend Decorator<@AnnotationType>");
                    }

                    annoType = ((Class) pType.getActualTypeArguments()[0]).asSubclass(Annotation.class);
                }

                injectFactory.getInjectionContext().registerDecorator(decoratorClass.getConstructor(new Class[]{Class.class}).newInstance(annoType));
            }
            catch (Exception e) {
                throw new ErraiBootstrapFailure("unable to load code decorator: " + e.getMessage(), e);
            }
        }

        /**
         * Provider.class
         */
        Set<Class<?>> providers = scanner.getTypesAnnotatedWith(Provider.class);
        for (Class<?> clazz : providers) {
            JClassType bindType = null;
            JClassType type = loadType(typeOracle, clazz);

            boolean contextual = false;
            for (JClassType iface : type.getImplementedInterfaces()) {
                if (iface.getQualifiedSourceName().equals(ContextualTypeProvider.class.getName())) {
                    contextual = true;

                    JParameterizedType pType = iface.isParameterized();

                    if (pType == null) {
                        throw new InjectionFailure("could not determine the bind type for the Provider class: " + type.getQualifiedSourceName());
                    }

                    bindType = pType.getTypeArgs()[0];
                    break;
                }
            }

            if (bindType == null) {
                for (JClassType iface : type.getImplementedInterfaces()) {
                    if (!typeProviderCls.isAssignableFrom(iface)) {
                        continue;
                    }

                    JParameterizedType pType = iface.isParameterized();

                    if (pType == null) {
                        throw new InjectionFailure("could not determine the bind type for the Provider class: " + type.getQualifiedSourceName());
                    }

                    bindType = pType.getTypeArgs()[0];
                }
            }

            if (bindType == null) {
                throw new InjectionFailure("the annotated provider class does not appear to implement " +
                        TypeProvider.class.getName() + ": " + type.getQualifiedSourceName());
            }

            final JClassType finalBindType = bindType;

            if (contextual) {
                injectFactory.addInjector(new ContextualProviderInjector(finalBindType, type));

            } else {
                injectFactory.addInjector(new ProviderInjector(finalBindType, type));
            }
        }


        /**
         * GeneratedBy.class
         */
        Set<Class<?>> generatedBys = scanner.getTypesAnnotatedWith(GeneratedBy.class);
        for (Class<?> clazz : generatedBys) {
            JClassType type = loadType(typeOracle, clazz);
            GeneratedBy anno = type.getAnnotation(GeneratedBy.class);
            Class<? extends ContextualTypeProvider> injectorClass = anno.value();

View Full Code Here

TOP

Related Classes of org.jboss.errai.bus.server.service.metadata.MetaDataScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.