[jboss-cvs] jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml ...

Ales Justin ales.justin at genera-lynx.com
Wed Feb 28 10:43:13 EST 2007


  User: alesj   
  Date: 07/02/28 10:43:13

  Added:       src/ioc/org/jboss/seam/ioc/microcontainer/xml     
                        AbstractComponentMetaData.java
                        SeamSchemaInitializer.java LookupHandler.java
                        AbstractLookupMetaData.java ComponentHandler.java
  Log:
  Initial MC int code (some parts still commented - waiting for MC upgrade), fixing builds for separate Spring and MC handling.
  
  Revision  Changes    Path
  1.1      date: 2007/02/28 15:43:13;  author: alesj;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml/AbstractComponentMetaData.java
  
  Index: AbstractComponentMetaData.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.seam.ioc.microcontainer.xml;
  
  import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
  import org.jboss.seam.ScopeType;
  
  /**
   * Component meta data.
   * Adding component ScopeType.
   *
   * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
   */
  public class AbstractComponentMetaData extends AbstractBeanMetaData
  {
      protected ScopeType scope;
  
      public ScopeType getScope()
      {
          return scope;
      }
  
      public void setScope(ScopeType scope)
      {
          this.scope = scope;
      }
  }
  
  
  
  1.1      date: 2007/02/28 15:43:13;  author: alesj;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml/SeamSchemaInitializer.java
  
  Index: SeamSchemaInitializer.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.seam.ioc.microcontainer.xml;
  
  import javax.xml.namespace.QName;
  
  import org.jboss.kernel.plugins.deployment.xml.BeanAnnotationInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanClassLoaderInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanConstructorInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanCreateInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanDemandsInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanDependsInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanDestroyInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanInstallInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanPropertyInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanSchemaBinding20;
  import org.jboss.kernel.plugins.deployment.xml.BeanStartInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanStopInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanSuppliesInterceptor;
  import org.jboss.kernel.plugins.deployment.xml.BeanUninstallInterceptor;
  import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
  import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingInitializer;
  import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
  
  /**
   * Seam schema initializer.
   *
   * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
   */
  public class SeamSchemaInitializer implements SchemaBindingInitializer
  {
      /** The namespace */
      public static final String SEAM_COMPONENT_NS = "urn:jboss:seam-components:1.0";
  
      /** The bean binding */
      public static final QName componentTypeQName = new QName(SEAM_COMPONENT_NS, "componentType");
  
      /** The bean binding */
      public static final QName lookupTypeQName = new QName(SEAM_COMPONENT_NS, "lookupType");
  
      public SchemaBinding init(SchemaBinding schema)
      {
          // remove replace in xml binding
          schema.setReplacePropertyRefs(false);
          // init component
          initComponent(schema);
          // init lookup
          initLookup(schema);
          return schema;
      }
  
      protected void initComponent(SchemaBinding schema)
      {
          TypeBinding componentType = schema.getType(componentTypeQName);
          // handler
          componentType.setHandler(ComponentHandler.HANDLER);
          // bean has a classloader
          componentType.pushInterceptor(BeanSchemaBinding20.classloaderQName, BeanClassLoaderInterceptor.INTERCEPTOR);
          // bean has a constructor
          componentType.pushInterceptor(BeanSchemaBinding20.constructorQName, BeanConstructorInterceptor.INTERCEPTOR);
          // bean has properties
          componentType.pushInterceptor(BeanSchemaBinding20.propertyQName, BeanPropertyInterceptor.INTERCEPTOR);
          // bean has a create
          componentType.pushInterceptor(BeanSchemaBinding20.createQName, BeanCreateInterceptor.INTERCEPTOR);
          // bean has a start
          componentType.pushInterceptor(BeanSchemaBinding20.startQName, BeanStartInterceptor.INTERCEPTOR);
          // bean has a stop
          componentType.pushInterceptor(BeanSchemaBinding20.stopQName, BeanStopInterceptor.INTERCEPTOR);
          // bean has a destroy
          componentType.pushInterceptor(BeanSchemaBinding20.destroyQName, BeanDestroyInterceptor.INTERCEPTOR);
          // bean has annotations
          componentType.pushInterceptor(BeanSchemaBinding20.annotationQName, BeanAnnotationInterceptor.INTERCEPTOR);
          // bean has installs
          componentType.pushInterceptor(BeanSchemaBinding20.installQName, BeanInstallInterceptor.INTERCEPTOR);
          // bean has uninstalls
          componentType.pushInterceptor(BeanSchemaBinding20.uninstallQName, BeanUninstallInterceptor.INTERCEPTOR);
          // bean has depends
          componentType.pushInterceptor(BeanSchemaBinding20.dependsQName, BeanDependsInterceptor.INTERCEPTOR);
          // bean has demands
          componentType.pushInterceptor(BeanSchemaBinding20.demandQName, BeanDemandsInterceptor.INTERCEPTOR);
          // bean has supplies
          componentType.pushInterceptor(BeanSchemaBinding20.supplyQName, BeanSuppliesInterceptor.INTERCEPTOR);
      }
  
      protected void initLookup(SchemaBinding schema)
      {
          TypeBinding lookuptype = schema.getType(lookupTypeQName);
          // handler
          lookuptype.setHandler(LookupHandler.HANDLER);
      }
  
  }
  
  
  
  1.1      date: 2007/02/28 15:43:13;  author: alesj;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml/LookupHandler.java
  
  Index: LookupHandler.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.seam.ioc.microcontainer.xml;
  
  import javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  
  import org.jboss.kernel.plugins.deployment.xml.DependencyHandler;
  import org.jboss.seam.ScopeType;
  import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
  import org.xml.sax.Attributes;
  
  /**
   * Seam component lookup handler.
   * Handling scope and create attribute.
   *
   * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
   */
  public class LookupHandler extends DependencyHandler
  {
      public static final LookupHandler HANDLER = new LookupHandler();
  
      @Override
      public Object startElement(Object object, QName qName, ElementBinding elementBinding)
      {
          return new AbstractLookupMetaData();
      }
  
      @Override
      public void attributes(Object object, QName qName, ElementBinding elementBinding, Attributes attrs, NamespaceContext namespaceContext)
      {
          super.attributes(object, qName, elementBinding, attrs, namespaceContext);
          AbstractLookupMetaData lookup = (AbstractLookupMetaData) object;
          for (int i = 0; i < attrs.getLength(); ++i)
          {
             String localName = attrs.getLocalName(i);
             if ("scope".equals(localName))
                lookup.setScope(ScopeType.valueOf(attrs.getValue(i)));
             else if ("create".equals(localName))
                lookup.setCreate(Boolean.parseBoolean(attrs.getValue(i)));
          }
      }
  }
  
  
  
  1.1      date: 2007/02/28 15:43:13;  author: alesj;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml/AbstractLookupMetaData.java
  
  Index: AbstractLookupMetaData.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.seam.ioc.microcontainer.xml;
  
  import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
  import org.jboss.beans.metadata.spi.MetaDataVisitor;
  import org.jboss.dependency.plugins.AbstractDependencyItem;
  import org.jboss.dependency.spi.Controller;
  import org.jboss.dependency.spi.ControllerContext;
  import org.jboss.dependency.spi.ControllerState;
  import org.jboss.dependency.spi.DependencyItem;
  import org.jboss.reflect.spi.TypeInfo;
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.util.JBossStringBuilder;
  
  /**
   * Injecting Seam components into MC beans.
   *
   * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
   */
  public class AbstractLookupMetaData extends AbstractDependencyValueMetaData
  {
      protected ScopeType scope;
      protected Boolean create = Boolean.TRUE;
  
      public void initialVisit(MetaDataVisitor visitor)
      {
         // update - context is member field
         ControllerContext context = visitor.getControllerContext();
         Object name = context.getName();
         Object iDependOn = getUnderlyingValue();
         ControllerState whenRequired = null; //whenRequiredState; // update
         if (whenRequired == null)
         {
            whenRequired = visitor.getContextState();
         }
  
         DependencyItem item = new ComponentDependencyItem(name, iDependOn, whenRequired);
         visitor.addDependency(item);
  
  //       visitor.initialVisit(this);
      }
  
      @Override
      public Object getValue(TypeInfo typeInfo, ClassLoader classLoader) throws Throwable
      {
          Object component;
          if (scope != null)
          {
             component = Component.getInstance((String)value, scope, create);
          }
          else
          {
             component = Component.getInstance((String)value, create);
          }
          if (property != null && component != null)
          {
  /*
              // uncomment once we update MC
              KernelController controller = ((KernelController)context.getController());
              KernelConfigurator configurator = controller.getKernel().getConfigurator();
              BeanInfo beanInfo = configurator.getBeanInfo(component.getClass());
              component = beanInfo.getProperty(component, property);
  */
          }
          if (component != null && typeInfo != null)
          {
              // change to new TypeInfo.isAssignable after update
              if (typeInfo.getType().isAssignableFrom(component.getClass()) == false)
                  throw new IllegalArgumentException("Illegal component class type: " + this + ", expected: " + typeInfo);
          }
          return component;
      }
  
      public ScopeType getScope()
      {
          return scope;
      }
  
      public void setScope(ScopeType scope)
      {
          this.scope = scope;
      }
  
      public Boolean getCreate()
      {
          return create;
      }
  
      public void setCreate(Boolean create)
      {
          this.create = create;
      }
  
      @Override
      public void toString(JBossStringBuilder buffer)
      {
         super.toString(buffer);
         if (scope != null)
            buffer.append(" scope=").append(scope);
         if (create != null)
            buffer.append(" create=").append(create);
      }
  
      private class ComponentDependencyItem extends AbstractDependencyItem
      {
          public ComponentDependencyItem(Object name, Object iDependOn, ControllerState whenRequied)
          {
              super(name, iDependOn, whenRequied, dependentState);
          }
  
          @Override
          public boolean resolve(Controller controller)
          {
              setResolved(Component.getInstance((String)getIDependOn()) != null);
              return isResolved();
          }
      }
  
  }
  
  
  
  1.1      date: 2007/02/28 15:43:13;  author: alesj;  state: Exp;jboss-seam/src/ioc/org/jboss/seam/ioc/microcontainer/xml/ComponentHandler.java
  
  Index: ComponentHandler.java
  ===================================================================
  /*
  * JBoss, Home of Professional Open Source
  * Copyright 2006, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
  package org.jboss.seam.ioc.microcontainer.xml;
  
  import java.util.HashSet;
  import java.util.Set;
  import javax.xml.namespace.NamespaceContext;
  import javax.xml.namespace.QName;
  
  import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
  import org.jboss.beans.metadata.spi.AnnotationMetaData;
  import org.jboss.kernel.plugins.deployment.xml.BeanHandler;
  import org.jboss.seam.ScopeType;
  import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
  import org.xml.sax.Attributes;
  
  /**
   * Component handler.
   * Adding Seam annotations - @Name and @Scope.
   *
   * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
   */
  public class ComponentHandler extends BeanHandler
  {
      public static final ComponentHandler HANDLER = new ComponentHandler();
  
      @Override
      public Object startElement(Object object, QName qName, ElementBinding elementBinding)
      {
          return new AbstractComponentMetaData();
      }
  
      @Override
      public void attributes(Object object, QName qName, ElementBinding elementBinding, Attributes attrs, NamespaceContext namespaceContext)
      {
          super.attributes(object, qName, elementBinding, attrs, namespaceContext);
          AbstractComponentMetaData component = (AbstractComponentMetaData)object;
          for (int i = 0; i < attrs.getLength(); ++i)
          {
              String localName = attrs.getLocalName(i);
              if ("scope".equals(localName))
                  component.setScope(ScopeType.valueOf(attrs.getValue(i)));
          }
      }
  
      @Override
      public Object endElement(Object object, QName qName, ElementBinding elementBinding)
      {
          AbstractComponentMetaData component = (AbstractComponentMetaData)super.endElement(object, qName, elementBinding);
          Set<AnnotationMetaData> annotations = component.getAnnotations();
          if (annotations == null)
          {
              annotations = new HashSet<AnnotationMetaData>();
              component.setAnnotations(annotations);
          }
          AbstractAnnotationMetaData nameAnnotation = new AbstractAnnotationMetaData();
          // update nameAnnotation.setAnnotation("@" + Name.class + "(" + component.getBean() + ")");
          annotations.add(nameAnnotation);
          if (component.getScope() != null)
          {
              AbstractAnnotationMetaData scopeAnnotation = new AbstractAnnotationMetaData();
              // update scopeAnnotation.setAnnotation("@" + Scope.class + "(" + component.getScope() + ")");
              annotations.add(scopeAnnotation);
          }
          return component;
      }
  }
  
  
  



More information about the jboss-cvs-commits mailing list