[jboss-cvs] jboss-seam/examples/spring/src/org/jboss/seam/ioc/microcontainer ...
Ales Justin
ales.justin at genera-lynx.com
Fri Feb 9 12:37:18 EST 2007
User: alesj
Date: 07/02/09 12:37:18
Added: examples/spring/src/org/jboss/seam/ioc/microcontainer
SeamComponentRegistryPlugin.java
MicrocontainerComponent.java
Log:
Added youngm's Spring code + my initial MC code (need to write scopes first in MC in order to fully support integration with Seam).
Revision Changes Path
1.1 date: 2007/02/09 17:37:18; author: alesj; state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/ioc/microcontainer/SeamComponentRegistryPlugin.java
Index: SeamComponentRegistryPlugin.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;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import org.jboss.kernel.plugins.registry.AbstractKernelRegistryEntry;
import org.jboss.kernel.spi.registry.KernelRegistryEntry;
import org.jboss.kernel.spi.registry.KernelRegistryPlugin;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
/**
* Do a Seam component lookup for MC beans.
* Lookup name can be a class or simple string.
* With string you can determine scopeType and create param:
* * name=somename;create=false;scope=SESSION
*
* We can add some xml + XB binding code to make Seam --> MC
* more informative - with create and scope as attributes.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
public class SeamComponentRegistryPlugin implements KernelRegistryPlugin
{
private static Pattern SCOPE = Pattern.compile(";scope=([a-zA-Z]+)");
private static Pattern CREATE = Pattern.compile(";create=(true|false)");
public KernelRegistryEntry getEntry(Object object)
{
String componentName = object.toString();
Object component;
if (object instanceof Class)
{
component = Component.getInstance((Class<?>)object);
}
else
{
// scope and create
Boolean create = parseCreate(componentName);
ScopeType scopeType = parseScopeType(componentName);
// shorter name?
int p = componentName.indexOf(";");
if (p > 0)
componentName = componentName.substring(p);
// register component
if (scopeType != null)
{
component = Component.getInstance(componentName, scopeType, create);
}
else
{
component = Component.getInstance(componentName, create);
}
}
return new AbstractKernelRegistryEntry(componentName, component);
}
protected static Boolean parseCreate(String name)
{
Boolean create = Boolean.TRUE;
Matcher createMatcher = CREATE.matcher(name);
if (createMatcher.find())
{
create = Boolean.parseBoolean(createMatcher.group(1));
}
return create;
}
protected static ScopeType parseScopeType(String name)
{
ScopeType scopeType = null;
Matcher scopeMatcher = SCOPE.matcher(name);
if (scopeMatcher.find())
{
scopeType = ScopeType.valueOf(scopeMatcher.group(1));
}
return scopeType;
}
}
1.1 date: 2007/02/09 17:37:18; author: alesj; state: Exp;jboss-seam/examples/spring/src/org/jboss/seam/ioc/microcontainer/MicrocontainerComponent.java
Index: MicrocontainerComponent.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;
import org.jboss.seam.ioc.IoCComponent;
import org.jboss.seam.ScopeType;
import org.jboss.dependency.spi.Controller;
/**
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
public class MicrocontainerComponent extends IoCComponent
{
private Controller controller;
public MicrocontainerComponent(Class clazz, String name, ScopeType scope, Controller controller)
{
super(clazz, name, scope);
this.controller = controller;
}
protected String getIoCName()
{
return "Microcontainer";
}
protected Object instantiateIoCBean() throws Exception
{
return controller.getInstalledContext(getName()).getTarget();
}
}
More information about the jboss-cvs-commits
mailing list