[jboss-cvs] JBossAS SVN: r81435 - in projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed: plugins/factory and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Nov 21 10:21:04 EST 2008
Author: alesj
Date: 2008-11-21 10:21:04 -0500 (Fri, 21 Nov 2008)
New Revision: 81435
Added:
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/BaseManagedObjectDefinition.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ConfigurableManagedObjectDefinition.java
Modified:
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ManagedObjectDefinition.java
projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
Log:
[JBMAN-40]; more options for MO definition.
Added: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/BaseManagedObjectDefinition.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/BaseManagedObjectDefinition.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/BaseManagedObjectDefinition.java 2008-11-21 15:21:04 UTC (rev 81435)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.managed.api.factory;
+
+import org.jboss.managed.spi.factory.ManagedObjectBuilder;
+import org.jboss.util.JBossObject;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Base managed object definition.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class BaseManagedObjectDefinition extends JBossObject
+{
+ private Class<?> type;
+ private ManagedObjectBuilder builder;
+
+ protected BaseManagedObjectDefinition()
+ {
+ }
+
+ protected BaseManagedObjectDefinition(Class<?> type, ManagedObjectBuilder builder)
+ {
+ this.type = type;
+ this.builder = builder;
+ }
+
+ /**
+ * Is definition valid.
+ *
+ * @return true if valid
+ */
+ public boolean isValid()
+ {
+ return type != null && builder != null;
+ }
+
+ /**
+ * Get type.
+ *
+ * @return the type
+ */
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ /**
+ * Set type.
+ *
+ * @param type the type
+ */
+ public void setType(Class<?> type)
+ {
+ this.type = type;
+ }
+
+ /**
+ * Get builder.
+ *
+ * @return the builder
+ */
+ public ManagedObjectBuilder getBuilder()
+ {
+ return builder;
+ }
+
+ /**
+ * Set builder.
+ *
+ * @param builder the builder
+ */
+ public void setBuilder(ManagedObjectBuilder builder)
+ {
+ this.builder = builder;
+ }
+
+ @Override
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ buffer.append("type=").append(type);
+ buffer.append(", builder=").append(builder);
+ }
+
+ @Override
+ protected void toString(JBossStringBuilder buffer)
+ {
+ buffer.append("type=").append(type);
+ buffer.append(", builder=").append(builder);
+ }
+}
\ No newline at end of file
Added: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ConfigurableManagedObjectDefinition.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ConfigurableManagedObjectDefinition.java (rev 0)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ConfigurableManagedObjectDefinition.java 2008-11-21 15:21:04 UTC (rev 81435)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.managed.api.factory;
+
+import org.jboss.managed.spi.factory.ManagedObjectBuilder;
+import org.jboss.util.JBossStringBuilder;
+
+/**
+ * Configurable managed object definition.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ConfigurableManagedObjectDefinition extends BaseManagedObjectDefinition
+{
+ private ManagedObjectFactory factory;
+
+ public ConfigurableManagedObjectDefinition()
+ {
+ }
+
+ public ConfigurableManagedObjectDefinition(Class<?> type, ManagedObjectBuilder builder)
+ {
+ super(type, builder);
+ }
+
+ public ConfigurableManagedObjectDefinition(ManagedObjectFactory factory)
+ {
+ this(factory, null, null);
+ }
+
+ public ConfigurableManagedObjectDefinition(ManagedObjectFactory factory, Class<?> type, ManagedObjectBuilder builder)
+ {
+ super(type, builder);
+ this.factory = factory;
+ }
+
+ /**
+ * Get factory internal.
+ *
+ * This method should be used
+ * when internally accessing MO factory
+ * as it will return default instance in case
+ * factory is not explicitly set.
+ *
+ * @return the MO factory
+ */
+ protected ManagedObjectFactory getMOFactory()
+ {
+ if (factory == null)
+ factory = ManagedObjectFactory.getInstance();
+
+ return factory;
+ }
+
+ /**
+ * Add builder to factory.
+ */
+ public void start()
+ {
+ if (isValid() == false)
+ throw new IllegalArgumentException("Definition is invalid: " + toString());
+
+ getMOFactory().setBuilder(getType(), getBuilder());
+ }
+
+ /**
+ * Remove builder from factory.
+ */
+ public void stop()
+ {
+ if (factory == null)
+ throw new IllegalArgumentException("Missing managed object factory");
+ if (getType() == null)
+ throw new IllegalArgumentException("Missing type");
+
+ getMOFactory().setBuilder(getType(), null);
+ }
+
+ /**
+ * Get managed obejct factory.
+ *
+ * @return the managed object factory
+ */
+ public ManagedObjectFactory getFactory()
+ {
+ return factory;
+ }
+
+ /**
+ * Set managed object factory.
+ *
+ * @param factory the managed object factory
+ */
+ public void setFactory(ManagedObjectFactory factory)
+ {
+ this.factory = factory;
+ }
+
+ @Override
+ public void toShortString(JBossStringBuilder buffer)
+ {
+ super.toShortString(buffer);
+ buffer.append(", factory=").append(factory);
+ }
+
+ @Override
+ protected void toString(JBossStringBuilder buffer)
+ {
+ super.toString(buffer);
+ buffer.append(", factory=").append(factory);
+ }
+}
\ No newline at end of file
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ManagedObjectDefinition.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ManagedObjectDefinition.java 2008-11-21 15:11:49 UTC (rev 81434)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/api/factory/ManagedObjectDefinition.java 2008-11-21 15:21:04 UTC (rev 81435)
@@ -28,114 +28,14 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class ManagedObjectDefinition
+public class ManagedObjectDefinition extends BaseManagedObjectDefinition
{
- private ManagedObjectFactory factory;
-
- private Class<?> type;
- private ManagedObjectBuilder builder;
-
public ManagedObjectDefinition()
{
}
- public ManagedObjectDefinition(ManagedObjectFactory factory)
+ public ManagedObjectDefinition(Class<?> type, ManagedObjectBuilder builder)
{
- this.factory = factory;
+ super(type, builder);
}
-
- public ManagedObjectDefinition(ManagedObjectFactory factory, Class<?> type, ManagedObjectBuilder builder)
- {
- this(factory);
- this.type = type;
- this.builder = builder;
- }
-
- /**
- * Add builder to factory.
- */
- public void start()
- {
- if (factory == null)
- throw new IllegalArgumentException("Missing managed object factory");
- if (type == null)
- throw new IllegalArgumentException("Missing type");
- if (builder == null)
- throw new IllegalArgumentException("Missing builder");
-
- factory.setBuilder(type, builder);
- }
-
- /**
- * Remove builder from factory.
- */
- public void stop()
- {
- if (factory == null)
- throw new IllegalArgumentException("Missing managed object factory");
- if (type == null)
- throw new IllegalArgumentException("Missing type");
-
- factory.setBuilder(type, null);
- }
-
- /**
- * Get managed obejct factory.
- *
- * @return the managed object factory
- */
- public ManagedObjectFactory getFactory()
- {
- return factory;
- }
-
- /**
- * Set managed object factory.
- *
- * @param factory the managed object factory
- */
- public void setFactory(ManagedObjectFactory factory)
- {
- this.factory = factory;
- }
-
- /**
- * Get type.
- *
- * @return the type
- */
- public Class<?> getType()
- {
- return type;
- }
-
- /**
- * Set type.
- *
- * @param type the type
- */
- public void setType(Class<?> type)
- {
- this.type = type;
- }
-
- /**
- * Get builder.
- *
- * @return the builder
- */
- public ManagedObjectBuilder getBuilder()
- {
- return builder;
- }
-
- /**
- * Set builder.
- *
- * @param builder the builder
- */
- public void setBuilder(ManagedObjectBuilder builder)
- {
- this.builder = builder;
- }
}
Modified: projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-21 15:11:49 UTC (rev 81434)
+++ projects/jboss-man/branches/Branch_2_0/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2008-11-21 15:21:04 UTC (rev 81435)
@@ -81,10 +81,11 @@
import org.jboss.reflect.spi.MethodInfo;
import org.jboss.reflect.spi.ParameterInfo;
import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.managed.api.factory.ManagedObjectDefinition;
/**
* The base ManagedObjectFactory implementation.
- *
+ *
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
* @version $Revision$
@@ -99,9 +100,9 @@
/** The managed object meta type */
public static final GenericMetaType MANAGED_OBJECT_META_TYPE = new GenericMetaType(ManagedObject.class.getName(), ManagedObject.class.getName());
-
+
/** The meta type factory */
- private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
+ private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
/** The meta value factory */
private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
@@ -157,7 +158,7 @@
/**
* Create an AbstractManagedObjectFactory the given factories, supporting
* information.
- *
+ *
* @param metaTypeFactory
* @param metaValueFactory
* @param defaultInstanceFactory
@@ -180,9 +181,36 @@
this.instanceFactories = instanceFactories;
}
+
/**
+ * Add managed object definition.
+ *
+ * @param definition the MO definition
+ */
+ public void addManagedObjectDefinition(ManagedObjectDefinition definition)
+ {
+ if (definition == null || definition.isValid() == false)
+ throw new IllegalArgumentException("Invalid MO definition: " + definition);
+
+ setBuilder(definition.getType(), definition.getBuilder());
+ }
+
+ /**
+ * Remove managed object definition.
+ *
+ * @param definition the MO definition
+ */
+ public void removeManagedObjectDefinition(ManagedObjectDefinition definition)
+ {
+ if (definition == null)
+ return;
+
+ setBuilder(definition.getType(), null);
+ }
+
+ /**
* Get the configuration
- *
+ *
* @return the configuration
*/
public Configuration getConfiguration()
@@ -190,7 +218,7 @@
return configuration;
}
-
+
public MetaTypeFactory getMetaTypeFactory()
{
return metaTypeFactory;
@@ -244,7 +272,7 @@
* Set the default InstanceClassFactory. This is used when there is not
* match an exact match by the {@linkplain #getInstanceClassFactory(Class)}
* factory method.
- *
+ *
* @param defaultInstanceFactory the default InstanceClassFactory to fall
* back to. It may be null if no default should be used.
*/
@@ -254,7 +282,7 @@
this.defaultInstanceFactory = defaultInstanceFactory;
}
-
+
public ManagedObjectPopulator<?> getDefaultManagedObjectPopulator()
{
return defaultManagedObjectPopulator;
@@ -281,7 +309,7 @@
ManagedObject result = createSkeletonManagedObject(clazz, metaData);
ManagedObjectPopulator<T> populator = getPopulator(clazz);
populator.createObject(result, clazz, metaData);
-
+
return result;
}
@@ -359,12 +387,12 @@
instanceFactories.put(clazz, factory);
log.debug("Set ICF for: "+clazz+", to: "+factory);
}
- }
+ }
}
/**
* Create a skeleton managed object
- *
+ *
* @param <T> the type
* @param clazz the clazz
* @return the skeleton managed object, null if clazz is not
@@ -379,7 +407,7 @@
ManagedObjectBuilder builder = getBuilder(clazz);
return builder.buildManagedObject(clazz, metaData);
}
-
+
/**
* The ManagedObjectBuilder.buildManagedObject implementation. This is based
* on the org.jboss.managed.api.annotation.* package annotations.
@@ -590,11 +618,11 @@
mandatory = managementProperty.mandatory();
if (mandatory)
fields.setField(Fields.MANDATORY, Boolean.TRUE);
-
+
boolean managed = false;
if (managementProperty != null)
managed = managementProperty.managed();
-
+
MetaType metaType;
if (managed)
{
@@ -657,7 +685,7 @@
operation information.
*/
Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
-
+
Set<MethodInfo> methodInfos = beanInfo.getMethods();
if (methodInfos != null && methodInfos.isEmpty() == false)
{
@@ -713,7 +741,7 @@
}
/**
- *
+ *
* @param methodInfo
* @param opAnnotation
* @return the managed operation
@@ -786,7 +814,7 @@
/**
* Get the builder for a class
- *
+ *
* @param clazz the class
* @return the builder
*/
@@ -803,7 +831,7 @@
/**
* Get the instance factory for a class
- *
+ *
* @param clazz the class
* @return the InstanceClassFactory
*/
@@ -826,7 +854,7 @@
/**
* Get the populator for a class
- *
+ *
* @param clazz the class
* @return the populator
*/
More information about the jboss-cvs-commits
mailing list