Package org.exoplatform.container.xml

Examples of org.exoplatform.container.xml.Component


         componentKey = (String)key;
      else
         componentKey = ((Class)key).getName();
      ConfigurationManager manager =
         (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
      Component component = manager.getComponent(componentKey);

      //
      try
      {
         InitParams params = null;
         boolean debug = false;
         if (component != null)
         {
            params = component.getInitParams();
            debug = component.getShowDeployInfo();
         }

         instance_ = exocontainer.createComponent(getComponentImplementation(), params);

         if (debug)
            log.debug("==> create  component : " + instance_);
         if (component != null && component.getComponentPlugins() != null)
         {
            addComponentPlugin(debug, instance_, component.getComponentPlugins(), exocontainer);
         }
         ExternalComponentPlugins ecplugins = manager.getConfiguration().getExternalComponentPlugins(componentKey);
         if (ecplugins != null)
         {
            addComponentPlugin(debug, instance_, ecplugins.getComponentPlugins(), exocontainer);
         }
         // check if component implement the ComponentLifecycle
         if (instance_ instanceof ComponentLifecycle)
         {
            ComponentLifecycle lc = (ComponentLifecycle)instance_;
            lc.initComponent(exocontainer);
         }
      }
      catch (Exception ex)
      {
         String msg = "Cannot instantiate component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, ex);
      }
      return instance_;
   }
View Full Code Here


      if (instance_ != null)
         return instance_;

      //
      ExoContainer exocontainer = (ExoContainer)container;
      Component component = null;
      ConfigurationManager manager;
      String componentKey;
      try
      {
         InitParams params = null;
         boolean debug = false;
         synchronized (this)
         {
            // Avoid to create duplicate instances if it is called at the same time by several threads
            if (instance_ != null)
               return instance_;
            // Get the component
            Object key = getComponentKey();
            if (key instanceof String)
               componentKey = (String)key;
            else
               componentKey = ((Class<?>)key).getName();
            manager = (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
            component = manager.getComponent(componentKey);
            if (component != null)
            {
               params = component.getInitParams();
               debug = component.getShowDeployInfo();
            }
            // Please note that we cannot fully initialize the Object "instance_" before releasing other
            // threads because it could cause StackOverflowError due to recursive calls
            Object instance = exocontainer.createComponent(getComponentImplementation(), params);
            if (instance_ != null)
            {
               // Avoid instantiating twice the same component in case of a cyclic reference due
               // to component plugins
               return instance_;
            }
            exocontainer.addComponentToCtx(getComponentKey(), instance);
            if (debug)
               LOG.debug("==> create  component : " + instance_);
            if (component != null && component.getComponentPlugins() != null)
            {
               addComponentPlugin(debug, instance, component.getComponentPlugins(), exocontainer);
            }
            ExternalComponentPlugins ecplugins = manager.getConfiguration().getExternalComponentPlugins(componentKey);
            if (ecplugins != null)
            {
               addComponentPlugin(debug, instance, ecplugins.getComponentPlugins(), exocontainer);
            }
            // check if component implement the ComponentLifecycle
            if (instance instanceof ComponentLifecycle)
            {
               ComponentLifecycle lc = (ComponentLifecycle)instance;
               lc.initComponent(exocontainer);
            }
            instance_ = instance;
         }

      }
      catch (Exception ex)
      {
         String msg = "Cannot instantiate component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, ex);
      }
      finally
      {
View Full Code Here

         return;
      Iterator i = components.iterator();
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      while (i.hasNext())
      {
         Component component = (Component)i.next();
         String type = component.getType();
         String key = component.getKey();
         try
         {
            Class classType = loader.loadClass(type);
            if (key == null)
            {
               if (component.isMultiInstance())
               {
                  container.registerComponent(new ConstructorInjectionComponentAdapter(classType, classType));
                  LOG.debug("===>>> Thread local component " + classType.getName() + " registered.");
               }
               else
               {
                  container.registerComponentImplementation(classType);
               }
            }
            else
            {
               try
               {
                  Class keyType = loader.loadClass(key);
                  if (component.isMultiInstance())
                  {
                     container.registerComponent(new ConstructorInjectionComponentAdapter(keyType, classType));
                     LOG.debug("===>>> Thread local component " + classType.getName() + " registered.");
                  }
                  else
View Full Code Here

      if (instance_ != null)
         return instance_;

      //
      ExoContainer exocontainer = (ExoContainer)container;
      Component component = null;
      ConfigurationManager manager;
      String componentKey;
      try
      {
         InitParams params = null;
         boolean debug = false;
         synchronized (this)
         {
            // Avoid to create duplicate instances if it is called at the same time by several threads
            if (instance_ != null)
               return instance_;
            // Get the component
            Object key = getComponentKey();
            if (key instanceof String)
               componentKey = (String)key;
            else
               componentKey = ((Class)key).getName();
            manager = (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
            component = manager.getComponent(componentKey);
            if (component != null)
            {
               params = component.getInitParams();
               debug = component.getShowDeployInfo();
            }
            // Please note that we cannot fully initialize the Object "instance_" before releasing other
            // threads because it could cause StackOverflowError due to recursive calls
            instance_ = exocontainer.createComponent(getComponentImplementation(), params);
         }

         if (debug)
            log.debug("==> create  component : " + instance_);
         if (component != null && component.getComponentPlugins() != null)
         {
            addComponentPlugin(debug, instance_, component.getComponentPlugins(), exocontainer);
         }
         ExternalComponentPlugins ecplugins = manager.getConfiguration().getExternalComponentPlugins(componentKey);
         if (ecplugins != null)
         {
            addComponentPlugin(debug, instance_, ecplugins.getComponentPlugins(), exocontainer);
         }
         // check if component implement the ComponentLifecycle
         if (instance_ instanceof ComponentLifecycle)
         {
            ComponentLifecycle lc = (ComponentLifecycle)instance_;
            lc.initComponent(exocontainer);
         }
      }
      catch (Exception ex)
      {
         String msg = "Cannot instantiate component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, ex);
      }

      return instance_;
View Full Code Here

         ValuesParam valuesParam = comlp.getInitParams().getValuesParam("component-lifecycle-plugin-values-param-name");
         assertNotNull(valuesParam);
         assertNotNull(valuesParam.getValues());
         assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value1"));
         assertTrue(valuesParam.getValues().contains("component-lifecycle-plugin-values-param-value2"));
         Component c = conf.getComponent("component-key1");
         assertNotNull(c);
         assertEquals("component-type1", c.getType());
         PropertiesParam propertiesParam = c.getInitParams().getPropertiesParam("component-key1-properties-param-name");
         assertNotNull(propertiesParam);
         assertEquals("component-key1-properties-param-prop-value", propertiesParam.getProperty("component-key1-properties-param-prop-name"));
         c = conf.getComponent("component-type2");
         assertNotNull(c);
         ObjectParameter objectParameter = c.getInitParams().getObjectParam("component-key2-object-param-name");
         assertNotNull(objectParameter);
         MyObject o = (MyObject)objectParameter.getObject();
         assertNotNull(o);
         assertEquals("string-value", o.field1);
         assertEquals(1, o.field2);
         assertEquals(1l, o.field3);
         assertEquals(1d, o.field4);
         assertEquals(true, o.field5);
         assertNotNull(o.field6);
         assertEquals("entry-value", o.field6.get("entry-name"));
         assertNotNull(o.field7);
         assertTrue(o.field7.contains("string-value"));
         assertNotNull(o.field8);
         assertEquals(1, o.field8[0]);
         List list = c.getComponentPlugins();
         assertNotNull(list);
         assertFalse(list.isEmpty());
         ComponentPlugin cp = (ComponentPlugin)list.get(0);
         assertEquals("component-plugins-name", cp.getName());
         assertEquals("set-method-name", cp.getSetMethod());
View Full Code Here

         (Configuration)uctx.unmarshalDocument(url.openStream(), null);

      assertNotNull(conf);

      //
      Component component = conf.getComponent("component");
      assertNotNull(component);

      //
      assertValueParam("a_value", component, "a");
      assertValueParam("${b_value}", component, "b");
      assertValueParam("c_external_value", component, "c");
      assertValueParam("_d_external_value_", component, "d");

      //
      assertPropertyParam("a_value", component, "e", "e_a");
      assertPropertyParam("${b_value}", component, "e", "e_b");
      assertPropertyParam("c_external_value", component, "e", "e_c");
      assertPropertyParam("_d_external_value_", component, "e", "e_d");

      //
      ObjectParameter o = component.getInitParams().getObjectParam("f");
      assertNotNull(o);
      Person p = (Person)o.getObject();
      assertNotNull(p);
      assertEquals("a_value", p.address_a);
      assertEquals("${b_value}", p.address_b);
View Full Code Here

         return;
      Iterator i = components.iterator();
      ClassLoader loader = Thread.currentThread().getContextClassLoader();
      while (i.hasNext())
      {
         Component component = (Component)i.next();
         String type = component.getType();
         String key = component.getKey();
         try
         {
            Class classType = loader.loadClass(type);
            if (key == null)
            {
               if (component.isMultiInstance())
               {
                  container.registerComponent(new ConstructorInjectionComponentAdapter(classType, classType));
                  log.debug("===>>> Thread local component " + classType.getName() + " registered.");
               }
               else
               {
                  container.registerComponentImplementation(classType);
               }
            }
            else
            {
               try
               {
                  Class keyType = loader.loadClass(key);
                  if (component.isMultiInstance())
                  {
                     container.registerComponent(new ConstructorInjectionComponentAdapter(keyType, classType));
                     log.debug("===>>> Thread local component " + classType.getName() + " registered.");
                  }
                  else
View Full Code Here

      if (instance_ != null)
         return instance_;

      //
      ExoContainer exocontainer = (ExoContainer)container;
      Component component = null;
      ConfigurationManager manager;
      String componentKey;
      try
      {
         InitParams params = null;
         boolean debug = false;
         synchronized (this)
         {
            // Avoid to create duplicate instances if it is called at the same time by several threads
            if (instance_ != null)
               return instance_;
            // Get the component
            Object key = getComponentKey();
            if (key instanceof String)
               componentKey = (String)key;
            else
               componentKey = ((Class)key).getName();
            manager = (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
            component = manager.getComponent(componentKey);
            if (component != null)
            {
               params = component.getInitParams();
               debug = component.getShowDeployInfo();
            }
            // Please note that we cannot fully initialize the Object "instance_" before releasing other
            // threads because it could cause StackOverflowError due to recursive calls
            Object instance = exocontainer.createComponent(getComponentImplementation(), params);
            if (instance_ != null)
            {
               // Avoid instantiating twice the same component in case of a cyclic reference due
               // to component plugins
               return instance_;
            }
            instance_ = instance;
         }

         if (debug)
            log.debug("==> create  component : " + instance_);
         if (component != null && component.getComponentPlugins() != null)
         {
            addComponentPlugin(debug, instance_, component.getComponentPlugins(), exocontainer);
         }
         ExternalComponentPlugins ecplugins = manager.getConfiguration().getExternalComponentPlugins(componentKey);
         if (ecplugins != null)
         {
            addComponentPlugin(debug, instance_, ecplugins.getComponentPlugins(), exocontainer);
         }
         // check if component implement the ComponentLifecycle
         if (instance_ instanceof ComponentLifecycle)
         {
            ComponentLifecycle lc = (ComponentLifecycle)instance_;
            lc.initComponent(exocontainer);
         }
      }
      catch (Exception ex)
      {
         String msg = "Cannot instantiate component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, ex);
      }

      return instance_;
View Full Code Here

    * {@inheritDoc}
    */
   @SuppressWarnings("unchecked")
   protected ComponentTask<T> getCreateTask()
   {
      Component component = null;
      String componentKey;
      InitParams params = null;
      boolean debug = false;

      // Get the component
      Object key = getComponentKey();
      if (key instanceof String)
         componentKey = (String)key;
      else
         componentKey = ((Class<?>)key).getName();
      try
      {
         ConfigurationManager manager =
            (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
         component = manager == null ? null : manager.getComponent(componentKey);
         if (component != null)
         {
            params = component.getInitParams();
            debug = component.getShowDeployInfo();
         }
         if (debug)
            LOG.debug("==> get constructor of the component : " + getComponentImplementation());
         List<Dependency> lDependencies = new ArrayList<Dependency>();
         Constructor<?> constructor = container.getConstructor(getComponentImplementation(), lDependencies);
         setCreateDependencies(lDependencies);
         if (debug)
            LOG.debug("==> create component : " + getComponentImplementation());
         return (ComponentTask<T>)container.createComponentTask(constructor, params, lDependencies, this);
      }
      catch (Exception e)
      {
         String msg = "Cannot instantiate component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, e);
      }
   }
View Full Code Here

   /**
    * {@inheritDoc}
    */
   protected Collection<ComponentTask<Void>> getInitTasks()
   {
      Component component = null;
      String componentKey;
      boolean debug = false;

      // Get the component
      Object key = getComponentKey();
      if (key instanceof String)
         componentKey = (String)key;
      else
         componentKey = ((Class<?>)key).getName();
      try
      {
         ConfigurationManager manager =
            (ConfigurationManager)exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
         component = manager == null ? null : manager.getComponent(componentKey);
         if (component != null)
         {
            debug = component.getShowDeployInfo();
         }
         List<ComponentTask<Void>> tasks = new ArrayList<ComponentTask<Void>>();
         Set<Dependency> dependencies = new HashSet<Dependency>();

         final Class<T> implementationClass = getComponentImplementation();
         boolean isSingleton = this.isSingleton;
         boolean isInitialized = this.isInitialized;
         if (debug)
            LOG.debug("==> create  component : " + implementationClass.getName());
         boolean hasInjectableConstructor = !isSingleton || ContainerUtil.hasInjectableConstructor(implementationClass);
         boolean hasOnlyEmptyPublicConstructor =
            !isSingleton || ContainerUtil.hasOnlyEmptyPublicConstructor(implementationClass);
         if (hasInjectableConstructor || hasOnlyEmptyPublicConstructor)
         {
            // There is at least one constructor JSR 330 compliant or we already know
            // that it is not a singleton such that the new behavior is expected
            List<Dependency> lDependencies = new ArrayList<Dependency>();
            boolean isInjectPresent = container.initializeComponent(implementationClass, lDependencies, tasks, this);
            dependencies.addAll(lDependencies);
            isSingleton = manageScope(isSingleton, isInitialized, hasInjectableConstructor, isInjectPresent);
         }
         else if (!isInitialized)
         {
            // The adapter has not been initialized yet
            // The old behavior is expected as there is no constructor JSR 330 compliant
            isSingleton = this.isSingleton = true;
            scope.set(Singleton.class);
         }
         if (component != null && component.getComponentPlugins() != null)
         {
            addComponentPlugin(tasks, dependencies, debug, component.getComponentPlugins());
         }
         ExternalComponentPlugins ecplugins =
            manager == null ? null : manager.getConfiguration().getExternalComponentPlugins(componentKey);
         if (ecplugins != null)
         {
            addComponentPlugin(tasks, dependencies, debug, ecplugins.getComponentPlugins());
         }
         initDependencies.compareAndSet(null, new CopyOnWriteArraySet<Dependency>(dependencies));
         tasks.add(new ComponentTask<Void>("initialize component " + getComponentImplementation().getName(), container,
            this, ComponentTaskType.INIT)
         {
            public Void execute(CreationalContextComponentAdapter<?> cCtx) throws Exception
            {
               // check if component implement the ComponentLifecycle
               if (cCtx.get() instanceof ComponentLifecycle && exocontainer instanceof ExoContainer)
               {
                  ComponentLifecycle lc = (ComponentLifecycle)cCtx.get();
                  lc.initComponent((ExoContainer)exocontainer);
               }
               return null;
            }
         });
         if (!isInitialized)
         {
            this.isInitialized = true;
         }
         return tasks;
      }
      catch (Exception e)
      {
         String msg = "Cannot initialize component " + getComponentImplementation();
         if (component != null)
         {
            msg =
               "Cannot initialize component key=" + component.getKey() + " type=" + component.getType() + " found at "
                  + component.getDocumentURL();
         }
         throw new RuntimeException(msg, e);
      }
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.container.xml.Component

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.