Examples of ComponentContainer


Examples of org.andromda.core.common.ComponentContainer

    public void discover()
    {
        AndroMDALogger.info("- discovering namespaces -");

        final XmlObjectFactory registryFactory = XmlObjectFactory.getInstance(NamespaceRegistry.class);
        final ComponentContainer container = ComponentContainer.instance();

        // - discover all registries and sort them by name
        final Map registryMap = this.discoverAllRegistries();
        final List registries = new ArrayList(registryMap.keySet());
        Collections.sort(
            registries,
            new NamespaceRegistryComparator());
        for (final Iterator iterator = registries.iterator(); iterator.hasNext();)
        {
            NamespaceRegistry registry = (NamespaceRegistry)iterator.next();
            final URL resource = (URL)registryMap.get(registry);
            final String registryName = registry.getName();

            // - only register if we haven't yet registered the namespace resource
            if (!this.registeredNamespaceResources.contains(resource))
            {
                final Namespaces namespaces = Namespaces.instance();
                final String namespace = registry.isShared() ? Namespaces.DEFAULT : registry.getName();

                // - first merge on the namespace registry descriptor (if needed)
                final Merger merger = Merger.instance();
                boolean requiresMerge = merger.requiresMerge(namespace);
                if (requiresMerge)
                {
                    registry =
                        (NamespaceRegistry)registryFactory.getObject(
                            merger.getMergedString(
                                ResourceUtils.getContents(resource),
                                namespace), resource);
                }

                // - add the resource root
                registry.addResourceRoot(this.getNamespaceResourceRoot(resource));
               
                // - only log the fact we've found the namespace registry, if we haven't done it yet
                if (!this.registeredRegistries.contains(registryName))
                {
                    AndroMDALogger.info("found namespace --> '" + registryName + "'");
                    this.registeredRegistries.add(registryName);
                }

                final NamespaceRegistry existingRegistry = namespaces.getRegistry(registryName);
                if (existingRegistry != null)
                {
                    // - if we already have an existing registry with the same name, copy
                    //   over any resources.
                    registry.copy(existingRegistry);
                }

                // - add the registry to the namespaces instance
                namespaces.addRegistry(registry);
                final String[] components = registry.getRegisteredComponents();
                final int componentNumber = components.length;
                for (int componentCtr = 0; componentCtr < componentNumber; componentCtr++)
                {
                    final String componentName = components[componentCtr];
                    final Component component = this.getComponent(componentName);
                    if (component == null)
                    {
                        throw new NamespaceComponentsException("'" + componentName +
                            "' is not a valid namespace component");
                    }

                    // - add any paths defined within the registry
                    component.addPaths(registry.getPaths(component.getName()));
                    if (!container.isRegisteredByNamespace(
                            registryName,
                            component.getType()))
                    {
                        AndroMDALogger.info("  +  registering component '" + componentName + "'");
                        final XmlObjectFactory componentFactory = XmlObjectFactory.getInstance(component.getType());
                        final URL componentResource =
                            this.getNamespaceResource(
                                registry.getResourceRoots(),
                                component.getPaths());
                        if (componentResource == null)
                        {
                            throw new NamespaceComponentsException("'" + componentName +
                                "' is not a valid component within namespace '" + namespace + "' (the " +
                                componentName + "'s descriptor can not be found)");
                        }
                        NamespaceComponent namespaceComponent =
                            (NamespaceComponent)componentFactory.getObject(componentResource);

                        // - now perform a merge of the descriptor (if we require one)
                        if (requiresMerge)
                        {
                            namespaceComponent =
                                (NamespaceComponent)componentFactory.getObject(
                                    merger.getMergedString(
                                        ResourceUtils.getContents(componentResource),
                                        namespace));
                        }

                        namespaceComponent.setNamespace(registryName);
                        namespaceComponent.setResource(componentResource);
                        container.registerComponentByNamespace(
                            registryName,
                            component.getType(),
                            namespaceComponent);
                    }
                }
View Full Code Here

Examples of org.apache.felix.scr.impl.config.ComponentContainer


    private ComponentContainer newContainer()
    {
        final ComponentMetadata metadata = newMetadata();
        ComponentContainer container = new ComponentContainer() {

            public BundleComponentActivator getActivator()
            {
                return null;
            }
View Full Code Here

Examples of org.apache.felix.scr.impl.config.ComponentContainer

     * @throws InvocationTargetException
     * @throws IllegalAccessException
     */
    private void ensureMethodNotFoundMethod( BaseObject obj, String methodName, DSVersion version )
    {
        ComponentContainer container = newContainer();
        SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() );
        ActivateMethod am = new ActivateMethod( methodName, methodName != null, obj.getClass(), version, false, false );
        am.invoke( obj, new ActivatorParameter( m_ctx, -1 ), null, icm );
        Method m = am.getMethod();
        assertNull( m );
View Full Code Here

Examples of org.apache.felix.scr.impl.config.ComponentContainer


    private void testMethod( final String methodName, final T1 component, final DSVersion dsVersion,
        final String expectCallPerformed )
    {
        ComponentContainer container = newContainer();
        SingleComponentManager icm = new SingleComponentManager( container, new ComponentMethods() );
        BindMethod bm = new BindMethod( methodName, component.getClass(),
                FakeService.class.getName(), dsVersion, false, ReferenceMetadata.ReferenceScope.bundle );
        RefPair refPair = new SingleRefPair( m_serviceReference );
        ComponentContextImpl<T1> cc = new ComponentContextImpl(icm, null);
View Full Code Here

Examples of org.apache.felix.scr.impl.config.ComponentContainer

    }
   
    private ComponentContainer newContainer()
    {
        final ComponentMetadata metadata = newMetadata();
        ComponentContainer container = new ComponentContainer() {

            public BundleComponentActivator getActivator()
            {
                return null;
            }
View Full Code Here

Examples of org.apache.felix.scrplugin.helper.ComponentContainer

            if (desc.getDescriptions(ComponentDescription.class).size() > 1) {
                iLog.addError("Class has more than one component definition." +
                             " Check the annotations and merge the definitions to a single definition.",
                                desc.getSource());
            } else {
                final ComponentContainer container = this.createComponent(desc, iLog);

                if (container.getComponentDescription().getSpecVersion() != null) {
                    if ( specVersion == null ) {
                        specVersion = container.getComponentDescription().getSpecVersion();
                        logger.debug("Setting used spec version to " + specVersion);
                    } else if (container.getComponentDescription().getSpecVersion().ordinal() > specVersion.ordinal() ) {
                        if ( this.options.getSpecVersion() != null) {
                            // if a spec version has been configured and a component requires a higher
                            // version, this is considered an error!
                            iLog.addError("Component " + container + " requires spec version " + container.getComponentDescription().getSpecVersion().name()
                                            + " but plugin is configured to use version " + this.options.getSpecVersion(),
                                            desc.getSource());
                        } else {
                            specVersion = container.getComponentDescription().getSpecVersion();
                            logger.debug("Setting used spec version to " + specVersion);
                        }
                    }
                } else {
                    if ( this.options.getSpecVersion() != null ) {
                        container.getComponentDescription().setSpecVersion(options.getSpecVersion());
                    } else {
                        container.getComponentDescription().setSpecVersion(SpecVersion.VERSION_1_0);
                    }
                }
                processedContainers.add(container);
            }
        }
View Full Code Here

Examples of org.apache.felix.scrplugin.helper.ComponentContainer

        // configuration pid in 1.2
        if ( componentDesc.getConfigurationPid() != null && !componentDesc.getConfigurationPid().equals(componentDesc.getName())) {
            componentDesc.setSpecVersion(SpecVersion.VERSION_1_2);
        }

        final ComponentContainer container = new ComponentContainer(desc, componentDesc);

        // Create metatype (if required)
        final MetatypeContainer ocd;
        if ( !componentDesc.isAbstract() && componentDesc.isCreateMetatype() ) {
            // OCD
            ocd = new MetatypeContainer();
            container.setMetatypeContainer( ocd );
            ocd.setId( componentDesc.getName() );
            if ( componentDesc.getLabel() != null ) {
                ocd.setName( componentDesc.getLabel() );
            }
            if ( componentDesc.getDescription() != null ) {
                ocd.setDescription( componentDesc.getDescription() );
            }

            // Factory pid
            if ( componentDesc.isSetMetatypeFactoryPid() ) {
                if ( componentDesc.getFactory() == null ) {
                    ocd.setFactoryPid( componentDesc.getName() );
                } else {
                    iLog.addWarning( "Component factory " + componentDesc.getName()
                        + " should not set metatype factory pid.", desc.getSource() );
                }
            }
        } else {
            ocd = null;
        }
        // metatype checks if metatype is not generated (FELIX-4033)
        if ( !componentDesc.isAbstract() && !componentDesc.isCreateMetatype() ) {
            if ( componentDesc.getLabel() != null && componentDesc.getLabel().trim().length() > 0 ) {
                iLog.addWarning(" Component " + componentDesc.getName() + " has set a label. However metatype is set to false. This label is ignored.",
                        desc.getSource());
            }
            if ( componentDesc.getDescription() != null && componentDesc.getDescription().trim().length() > 0 ) {
                iLog.addWarning(" Component " + componentDesc.getName() + " has set a description. However metatype is set to false. This description is ignored.",
                        desc.getSource());
            }
        }

        ClassDescription current = desc;
        boolean inherit;
        do {
            final ComponentDescription cd = current.getDescription(ComponentDescription.class);
            inherit = (cd == null ? true : cd.isInherit());

            if ( cd != null ) {
                if ( current != desc ) {
                    iLog.addWarning(" Component " + componentDesc.getName() + " is using the " +
                                    "deprecated inheritance feature and inherits from " + current.getDescribedClass().getName() +
                                    ". This feature will be removed in future versions.",
                                    desc.getSource());
                }
                // handle enabled and immediate
                if ( componentDesc.getEnabled() == null ) {
                    componentDesc.setEnabled(cd.getEnabled());
                }
                if ( componentDesc.getImmediate() == null ) {
                    componentDesc.setImmediate(cd.getImmediate());
                }

                // lifecycle methods
                if ( componentDesc.getActivate() == null && cd.getActivate() != null ) {
                    componentDesc.setActivate(cd.getActivate());
                }
                if ( componentDesc.getDeactivate() == null && cd.getDeactivate() != null ) {
                    componentDesc.setDeactivate(cd.getDeactivate());
                }
                if ( componentDesc.getModified() == null && cd.getModified() != null ) {
                    componentDesc.setModified(cd.getModified());
                }
                if ( componentDesc.getActivate() != null || componentDesc.getDeactivate() != null || componentDesc.getModified() != null ) {
                    // spec version must be at least 1.1
                    componentDesc.setSpecVersion(SpecVersion.VERSION_1_1);
                }
                if ( componentDesc.getConfigurationPolicy() != ComponentConfigurationPolicy.OPTIONAL ) {
                    // policy requires 1.1
                    componentDesc.setSpecVersion(SpecVersion.VERSION_1_1);
                }

            }
            // services, properties, references
            this.processServices(current, container);
            this.processProperties(current, container, ocd);
            this.processReferences(current, container);


            // go up in the class hierarchy
            if ( !inherit || current.getDescribedClass().getSuperclass() == null ) {
                current = null;
            } else {
                try {
                    current = this.scanner.getDescription(current.getDescribedClass().getSuperclass());
                } catch ( final SCRDescriptorFailureException sde) {
                    this.logger.debug(sde.getMessage(), sde);
                    iLog.addError(sde.getMessage(), current.getSource());
                } catch ( final SCRDescriptorException sde) {
                    this.logger.debug(sde.getSourceLocation() + " : " + sde.getMessage(), sde);
                    iLog.addError(sde.getMessage(), sde.getSourceLocation());
                }
            }
        } while ( current != null);

        // check service interfaces for properties
        if ( container.getServiceDescription() != null ) {
            for(final String interfaceName : container.getServiceDescription().getInterfaces()) {
                try {
                    final Class<?> interfaceClass = project.getClassLoader().loadClass(interfaceName);
                    final ClassDescription interfaceDesc = this.scanner.getDescription(interfaceClass);
                    if ( interfaceDesc != null ) {
                        this.processProperties(interfaceDesc, container, ocd);
                    }
                } catch ( final SCRDescriptorFailureException sde) {
                    this.logger.debug(sde.getMessage(), sde);
                    iLog.addError(sde.getMessage(), interfaceName);
                } catch ( final SCRDescriptorException sde) {
                    this.logger.debug(sde.getSourceLocation() + " : " + sde.getMessage(), sde);
                    iLog.addError(sde.getMessage(), sde.getSourceLocation());
                } catch (ClassNotFoundException e) {
                    this.logger.debug(e.getMessage(), e);
                    iLog.addError(e.getMessage(), interfaceName);
                }
            }
        }

        // global properties
        this.processGlobalProperties(desc, container.getProperties());

        // PID handling
        if ( componentDesc.isCreatePid() && !container.getProperties().containsKey(org.osgi.framework.Constants.SERVICE_PID)) {
            final PropertyDescription pid = new PropertyDescription(null);
            pid.setName( org.osgi.framework.Constants.SERVICE_PID );
            pid.setValue( componentDesc.getName() );
            pid.setType(PropertyType.String);

            container.getProperties().put(org.osgi.framework.Constants.SERVICE_PID, pid);
        }

        // check if component has spec version configured but requires a higher one
        if ( intitialComponentSpecVersion != null && componentDesc.getSpecVersion().ordinal() > intitialComponentSpecVersion.ordinal() ) {
            iLog.addError("Component " + container + " requires spec version " + container.getComponentDescription().getSpecVersion().name()
                    + " but component is configured to use version " + intitialComponentSpecVersion.name(),
                    desc.getSource());
        }
        return container;
    }
View Full Code Here

Examples of org.sonar.api.platform.ComponentContainer

  }

  @Test
  public void should_enable_all_phases() {
    ScanTask task = new ScanTask(mock(TaskContainer.class));
    ComponentContainer projectScanContainer = new ComponentContainer();
    projectScanContainer.add(mock(ProjectConfigurator.class), new ProjectReactor(ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo")),
      mock(Settings.class),
      mock(ResourceDao.class));
    task.scan(projectScanContainer);

    Phases phases = projectScanContainer.getComponentByType(Phases.class);
    assertThat(phases.isFullyEnabled()).isTrue();
  }
View Full Code Here

Examples of org.sonar.api.platform.ComponentContainer

  public void prepare() {
    projectBootstrapper = mock(ProjectBootstrapper.class);
    bootstrapProperties = new BootstrapProperties(Collections.<String, String>emptyMap());
    AnalysisMode analysisMode = new AnalysisMode(bootstrapProperties);
    when(projectBootstrapper.bootstrap()).thenReturn(new ProjectReactor(ProjectDefinition.create()));
    parentContainer = new ComponentContainer();
    parentContainer.add(System2.INSTANCE);
    parentContainer.add(bootstrapProperties);
    parentContainer.add(analysisMode);
    GlobalReferentials globalRef = new GlobalReferentials();
    settings = new GlobalSettings(bootstrapProperties, new PropertyDefinitions(), globalRef, analysisMode);
View Full Code Here

Examples of org.sonar.api.platform.ComponentContainer

  void addComponents(Collection components) {
    this.level4AddedComponents.addAll(components);
  }

  public void executeStartupTasks(ComponentContainer pico) {
    final ComponentContainer startupContainer = pico.createChild();
    startupContainer.addSingleton(IndexSynchronizer.class);
    startupContainer.addSingleton(RegisterMetrics.class);
    startupContainer.addSingleton(RegisterQualityGates.class);
    startupContainer.addSingleton(RegisterRules.class);
    startupContainer.addSingleton(RegisterQualityProfiles.class);
    startupContainer.addSingleton(JdbcDriverDeployer.class);
    startupContainer.addSingleton(RegisterDebtModel.class);
    startupContainer.addSingleton(GeneratePluginIndex.class);
    startupContainer.addSingleton(RegisterNewMeasureFilters.class);
    startupContainer.addSingleton(RegisterDashboards.class);
    startupContainer.addSingleton(RegisterPermissionTemplates.class);
    startupContainer.addSingleton(RenameDeprecatedPropertyKeys.class);
    startupContainer.addSingleton(LogServerId.class);
    startupContainer.addSingleton(RegisterServletFilters.class);
    startupContainer.addSingleton(CleanPreviewAnalysisCache.class);
    startupContainer.addSingleton(CopyRequirementsFromCharacteristicsToRules.class);
    startupContainer.addSingleton(AnalysisReportTaskCleaner.class);

    DoPrivileged.execute(new DoPrivileged.Task() {
      @Override
      protected void doPrivileged() {
        startupContainer.getComponentsByType(IndexSynchronizer.class).get(0).execute();
        startupContainer.startComponents();
        startupContainer.getComponentByType(ServerLifecycleNotifier.class).notifyStart();
      }
    });

    // Do not put the following statements in a finally block.
    // It would hide the possible exception raised during startup
    // See SONAR-3107
    startupContainer.stopComponents();

    pico.getComponentByType(DatabaseSessionFactory.class).clear();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.