[jboss-cvs] JBossAS SVN: r59752 - projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jan 18 03:52:36 EST 2007
Author: scott.stark at jboss.org
Date: 2007-01-18 03:52:35 -0500 (Thu, 18 Jan 2007)
New Revision: 59752
Added:
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImplFactory.java
Modified:
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DefaultFieldsImpl.java
projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
Log:
Add better support for simple creation
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DefaultFieldsImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DefaultFieldsImpl.java 2007-01-18 08:39:50 UTC (rev 59751)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/DefaultFieldsImpl.java 2007-01-18 08:52:35 UTC (rev 59752)
@@ -23,8 +23,12 @@
import java.io.Serializable;
import java.util.HashMap;
+import java.util.Set;
import org.jboss.managed.api.Fields;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
/**
* A default implementation of the Fields interface.
@@ -39,6 +43,90 @@
private HashMap<String, Serializable> fields = new HashMap<String, Serializable>();
+ public DefaultFieldsImpl()
+ {
+ }
+ public DefaultFieldsImpl(String name)
+ {
+ this.setName(name);
+ }
+
+ public String getName()
+ {
+ return getField(NAME, String.class);
+ }
+ public void setName(String name)
+ {
+ setField(NAME, name);
+ }
+
+ public String getDescription()
+ {
+ return getField(DESCRIPTION, String.class);
+ }
+ public void setDescription(String description)
+ {
+ setField(DESCRIPTION, description);
+ }
+
+ public MetaType getMetaType()
+ {
+ return getField(META_TYPE, MetaType.class);
+ }
+ public void setMetaType(MetaType type)
+ {
+ setField(META_TYPE, type);
+ }
+
+ public Object getValue()
+ {
+ return getField(VALUE);
+ }
+ public void setValue(Serializable value)
+ {
+ setField(VALUE, value);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set<MetaValue> getLegalValues()
+ {
+ return getField(LEGAL_VALUES, Set.class);
+ }
+ public void setLegalValues(Set<MetaValue> values)
+ {
+ setField(LEGAL_VALUES, (Serializable)values);
+ }
+
+ public Comparable getMinimumValue()
+ {
+ return getField(MINIMUM_VALUE, Comparable.class);
+ }
+ public void setMinimumValue(Comparable value)
+ {
+ setField(MINIMUM_VALUE, (Serializable)value);
+ }
+
+ public Comparable getMaximumValue()
+ {
+ return getField(MAXIMUM_VALUE, Comparable.class);
+ }
+ public void setMaximumValue(Comparable value)
+ {
+ setField(MAXIMUM_VALUE, (Serializable)value);
+ }
+
+ public boolean isMandatory()
+ {
+ Boolean result = getField(MANDATORY, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+ public void setMandatory(boolean flag)
+ {
+ setField(MANDATORY, flag);
+ }
+
public Serializable getField(String name)
{
return fields.get(name);
@@ -49,4 +137,32 @@
fields.put(name, value);
}
+ @SuppressWarnings("unchecked")
+ public <T> T getField(String fieldName, Class<T> expected)
+ {
+ if (fieldName == null)
+ throw new IllegalArgumentException("Null field name");
+ if (expected == null)
+ throw new IllegalArgumentException("Null expected type");
+
+ Serializable field = getField(fieldName);
+
+ if (field == null)
+ return null;
+
+ if (expected.isInstance(field))
+ return expected.cast(field);
+
+ if (field instanceof SimpleValue)
+ {
+ SimpleValue value = (SimpleValue) field;
+ Object result = value.getValue();
+ if (result == null)
+ return null;
+ return expected.cast(result);
+ }
+
+ throw new IllegalStateException("Field " + fieldName + " with value " + field + " is a of the expected type: " + expected.getName());
+ }
+
}
Modified: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2007-01-18 08:39:50 UTC (rev 59751)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImpl.java 2007-01-18 08:52:35 UTC (rev 59752)
@@ -70,10 +70,24 @@
* @throws IllegalArgumentException for null fields or
* missing Fields.NAME
*/
+ public ManagedPropertyImpl(String name)
+ {
+ this(null, new DefaultFieldsImpl(name));
+ }
+
+ /**
+ * Create a new ManagedProperty that is not associated to
+ * a ManagedObject.
+ *
+ * @param fields the fields
+ * @throws IllegalArgumentException for null fields or
+ * missing Fields.NAME
+ */
public ManagedPropertyImpl(Fields fields)
{
this(null, fields);
}
+
/**
* Create a new ManagedProperty.
*
@@ -148,11 +162,20 @@
{
return getField(Fields.DESCRIPTION, String.class);
}
+ public void setDescription(String description)
+ {
+ setField(Fields.DESCRIPTION, description);
+ }
+
public MetaType getMetaType()
{
return getField(Fields.META_TYPE, MetaType.class);
}
+ public void setMetaType(MetaType type)
+ {
+ setField(Fields.META_TYPE, type);
+ }
public Object getValue()
{
@@ -169,16 +192,28 @@
{
return getField(Fields.LEGAL_VALUES, Set.class);
}
+ public void setLegalValues(Set<MetaValue> values)
+ {
+ setField(Fields.LEGAL_VALUES, (Serializable)values);
+ }
public Comparable getMinimumValue()
{
return getField(Fields.MINIMUM_VALUE, Comparable.class);
}
+ public void setMinimumValue(Comparable value)
+ {
+ setField(Fields.MINIMUM_VALUE, (Serializable)value);
+ }
public Comparable getMaximumValue()
{
return getField(Fields.MAXIMUM_VALUE, Comparable.class);
}
+ public void setMaximumValue(Comparable value)
+ {
+ setField(Fields.MAXIMUM_VALUE, (Serializable)value);
+ }
public String checkValidValue(Serializable value)
{
@@ -193,6 +228,10 @@
return false;
return result;
}
+ public void setMandatory(boolean flag)
+ {
+ setField(Fields.MANDATORY, flag);
+ }
@Override
public String toString()
Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImplFactory.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImplFactory.java (rev 0)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImplFactory.java 2007-01-18 08:52:35 UTC (rev 59752)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * 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.managed.plugins;
+
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+
+/**
+ * javabean factory for ManagedPropertyImpls.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ManagedPropertyImplFactory
+{
+ public static ManagedProperty newInstance(String name, String description,
+ String metaType, boolean manadatory)
+ {
+ ManagedPropertyImpl property = new ManagedPropertyImpl(name);
+ property.setDescription(description);
+ property.setMandatory(manadatory);
+ property.setMetaType(SimpleMetaType.resolve(metaType));
+ return property;
+ }
+}
Property changes on: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/plugins/ManagedPropertyImplFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id,Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list