Package org.apache.hivemind.definition

Examples of org.apache.hivemind.definition.ImplementationConstructor


        ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);

        ServicePointDefinition sp1 = helper.addServicePoint("Simple", Simple.class.getName());

        // Define inline implementation constructor, that passes the ShutdownCoordinator service if manual is true
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(module.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                Object result;
                if (manual) {
View Full Code Here


    private void addTranslatorManager(ModuleDefinition md, final ErrorHandler errorHandler)
    {
        ServicePointDefinition spd = helper.addServicePoint("TranslationManager", TranslatorManager.class.getName());

        // Define inline implementation constructor, that wires the Translators configuration
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                List translators = (List) context.getConfiguration("Translators");
                TranslatorManager result = new TranslatorManagerImpl(translators, errorHandler);
View Full Code Here

    private void addSymbolSource(ModuleDefinition md, final String servicePointId, final String configurationId)
    {
        ServicePointDefinition spd = helper.addServicePoint(servicePointId, SymbolSource.class.getName());

        // Define inline implementation constructor, that wires the corresponding configuration
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                DefaultsSymbolSource result = new DefaultsSymbolSource();
                result.setDefaults(((Map) context.getConfiguration(configurationId)).values());
View Full Code Here

    private void addSymbolExpander(ModuleDefinition md, final ErrorHandler errorHandler)
    {
        ServicePointDefinition spd = helper.addServicePoint("SymbolExpander", SymbolExpander.class.getName());

        // Define inline implementation constructor, that wires ErrorHandler and SymbolSources
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                List symbolSources = (List) context.getConfiguration("SymbolSources");
View Full Code Here

    {
        ModuleDefinitionImpl module = createModuleDefinition("hivemind.test.services");
        ModuleDefinitionHelper helper = new ModuleDefinitionHelper(module);
        ServicePointDefinition sp = helper.addServicePoint("Recursive", SimpleService.class.getName());

        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(module.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                Object result = new SimpleServiceImpl();
                // Here is the recursion
View Full Code Here

    private void addThreadLocale(ModuleDefinition md)
    {
        ServicePointDefinition spd = helper.addServicePoint("ThreadLocale", ThreadLocale.class.getName());

        // Define inline implementation constructor
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {

            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                // Get the Locale from the registry
View Full Code Here

    private void addEagerLoad(ModuleDefinition md)
    {
        ServicePointDefinition spd = helper.addServicePoint("EagerLoad", Runnable.class.getName());

        // Define inline implementation constructor, that wires the EagerLoad configuration
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                EagerLoader result = new EagerLoader();
                result.setServicePoints((List) context.getConfiguration("EagerLoad"));
View Full Code Here

    private void addStartup(ModuleDefinition md)
    {
        ServicePointDefinition spd = helper.addServicePoint("Startup", Runnable.class.getName());

        // Define inline implementation constructor, that wires the Startup configuration
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                StartupImpl result = new StartupImpl();
                result.setRunnables((List) context.getConfiguration("Startup"));
View Full Code Here

    private void addInterfaceSynthesizer(ModuleDefinition md)
    {
        ServicePointDefinition spd = helper.addServicePoint("InterfaceSynthesizer", InterfaceSynthesizer.class.getName());

        // Define inline implementation constructor
        ImplementationConstructor constructor = new AbstractServiceImplementationConstructor(md.getLocation())
        {
            public Object constructCoreServiceImplementation(ImplementationConstructionContext context)
            {
                InterfaceSynthesizerImpl result = new InterfaceSynthesizerImpl();
                // Manual wiring of the class factory
View Full Code Here

        Class serviceInterface = _servicePoint.getServiceInterface();
        Class declaredInterface = _servicePoint.getDeclaredInterface();

        ImplementationDefinition implementationDefinition = _servicePoint.getImplementationDefinition();
        ImplementationConstructor constructor = implementationDefinition.getServiceConstructor();
        // Get a reference to the module that provided the implementation
        String definingModuleId = implementationDefinition.getModuleId();
       
        Module definingModule = getRegistry().getModule(definingModuleId);
        ImplementationConstructionContext context = new ImplementationConstructionContextImpl(definingModule,
                _servicePoint);
        Object result = constructor.constructCoreServiceImplementation(context);

        if (result == null)
            throw new ApplicationRuntimeException(ServiceModelMessages
                    .factoryReturnedNull(_servicePoint), constructor.getLocation(), null);

        // The factory should provice something that either implements the service interface
        // or the declared interface. Again, they are normally the same, but with services
        // defined in terms of a class (not an interface), the service interface is
        // synthetic, and the declared interface is the actual class.

        if (!(serviceInterface.isInstance(result) || declaredInterface.isInstance(result)))
            throw new ApplicationRuntimeException(ServiceModelMessages.factoryWrongInterface(
                    _servicePoint,
                    result,
                    serviceInterface), constructor.getLocation(), null);

        HiveMind.setLocation(result, constructor.getLocation());

        return result;
    }
View Full Code Here

TOP

Related Classes of org.apache.hivemind.definition.ImplementationConstructor

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.