[jboss-cvs] JBossAS SVN: r84037 - in trunk/system/src: main/org/jboss/system/server/profileservice/persistence and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 10 03:23:56 EST 2009
Author: emuckenhuber
Date: 2009-02-10 03:23:56 -0500 (Tue, 10 Feb 2009)
New Revision: 84037
Added:
trunk/system/src/main/org/jboss/system/server/profileservice/attachments/package-info.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistence.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHandler.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/CollectionMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/NestedTestMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/PrimitiveMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleArrayMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleStringMapMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleTableMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/TestMetaData.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/ArrayValueUnitTestCase.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/BasicPersistenceFormatUnitTestCase.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/CollectionValueUnitTestCase.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/MapCompositeUnitTestCase.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TableValueUnitTestCase.java
trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java
Modified:
trunk/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectUpdateHandler.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedArrayValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedEnumValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedTableValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java
trunk/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java
Log:
update attachment persistence
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -24,14 +24,20 @@
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
/**
* Metadata describing the persisted deployment attachments.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
+ at JBossXmlSchema(namespace = "urn:org:jboss:profileservice:attachments:1.0", elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") })
@XmlRootElement(name = "attachments-metadata")
public class RepositoryAttachmentMetaData
{
Added: trunk/system/src/main/org/jboss/system/server/profileservice/attachments/package-info.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/attachments/package-info.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/attachments/package-info.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+ at XmlSchema(namespace = "urn:org:jboss:profileservice:attachments:1.0",
+ elementFormDefault = XmlNsForm.QUALIFIED,
+ xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") }
+)
+package org.jboss.system.server.profileservice.attachments;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
+
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,149 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.system.server.profileservice.persistence;
+
+import java.io.Serializable;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+
+/**
+ * The AttachmentPropertyPopulator, this writes the values of a
+ * ManagedProperty to a attachment.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AttachmentPropertyPopulator
+{
+
+ /** The managed object factory. */
+ private ManagedObjectFactory managedObjectFactory;
+
+ /** The meta value factory. */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AttachmentPropertyPopulator.class);
+
+ public AttachmentPropertyPopulator()
+ {
+ this.managedObjectFactory = ManagedObjectFactory.getInstance();
+ }
+
+ public AttachmentPropertyPopulator(ManagedObjectFactory managedObjectFactory)
+ {
+ this.managedObjectFactory = managedObjectFactory;
+ }
+
+ /**
+ * Process a ManagedProperty.
+ *
+ * @param propertyElement the persisted xml meta data.
+ * @param name the property name.
+ * @param property the managed property.
+ * @param attachment the managed object attachment.
+ */
+ public void processManagedProperty(String name, ManagedProperty property, Object attachment) throws Throwable
+ {
+ boolean trace = log.isTraceEnabled();
+ PropertyInfo propertyInfo = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ // Skip not writable properties
+ if (propertyInfo == null || propertyInfo.isWritable() == false)
+ {
+ if (trace)
+ log.debug("skipping property " + name + " is not writable");
+ return;
+ }
+
+ // Get the meta data information
+ MetaType metaType = property.getMetaType();
+ MetaValue value = property.getValue();
+
+ // FIXME skip CompositeValueInvocationHandler
+ if (metaType.isComposite())
+ {
+ // unwrap
+ Object unwrapped = metaValueFactory.unwrap(value, propertyInfo.getType());
+ if (Proxy.isProxyClass(unwrapped.getClass()))
+ return;
+ }
+
+ // Unwrap generic managed objects
+ if(metaType.isCollection())
+ {
+ value = hackGenericCollectionSupport((CollectionValue) value);
+ }
+
+ // Set value
+ InstanceClassFactory icf = managedObjectFactory.getInstanceClassFactory(attachment.getClass(), null);
+ BeanInfo beanInfo = propertyInfo.getBeanInfo();
+ icf.setValue(beanInfo, property, attachment, value);
+
+ }
+
+ /**
+ * Hack generic values in collections.
+ *
+ * @param collection
+ * @return
+ */
+ protected CollectionValue hackGenericCollectionSupport(CollectionValue collection)
+ {
+ if(collection.getMetaType().getElementType().isGeneric())
+ {
+ List<GenericValue> values = new ArrayList<GenericValue>();
+ for(MetaValue value : collection.getElements())
+ {
+ Object o = ((GenericValue)value).getValue();
+ if(o instanceof ManagedObject)
+ {
+ ManagedObject mo = (ManagedObject) o;
+ GenericMetaType metaType = new GenericMetaType(mo.getAttachmentName(), mo.getName());
+
+ values.add(new GenericValueSupport(metaType, (Serializable) mo.getAttachment()));
+ //
+ }
+ }
+ return new CollectionValueSupport(collection.getMetaType(), values.toArray( new MetaValue[values.size()] ));
+ }
+ return collection;
+ }
+
+}
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metadata.spi.MetaData;
+
+/**
+ * ManagedObject creator plugin.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MOCreatorPlugin
+{
+
+ /** The classloader. */
+ private ClassLoader loader;
+
+ /** The managed object factory. */
+ private ManagedObjectFactory managedObjectFactory;
+
+ public MOCreatorPlugin()
+ {
+ this.managedObjectFactory = ManagedObjectFactory.getInstance();
+ }
+
+ public MOCreatorPlugin(ManagedObjectFactory managedObjectFactory)
+ {
+ this.managedObjectFactory = managedObjectFactory;
+ }
+
+ public ManagedObjectFactory getMOF()
+ {
+ return managedObjectFactory;
+ }
+
+ public void setMOF(ManagedObjectFactory managedObjectFactory)
+ {
+ this.managedObjectFactory = managedObjectFactory;
+ }
+
+ public ClassLoader getClassLoader()
+ {
+ if(this.loader == null)
+ return Thread.currentThread().getContextClassLoader();
+ return this.loader;
+ }
+
+ public void setClassLoader(ClassLoader classLoader)
+ {
+ this.loader = classLoader;
+ }
+
+ public ManagedObject createManagedObject(String clazz, MetaData metaData) throws Exception
+ {
+ return getMOF().createManagedObject(createManagedObjectClass(clazz), metaData);
+ }
+
+ public ManagedObject initManagedObject(Object o, MetaData metaData) throws Exception
+ {
+ return getMOF().initManagedObject(o, metaData);
+ }
+
+ protected Class<?> createManagedObjectClass(String clazz) throws Exception
+ {
+ return getClassLoader().loadClass(clazz);
+ }
+
+}
+
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverrideHandler.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,444 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.system.server.profileservice.persistence;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * Override information of a managed object.
+ *
+ * FIXME merging of collections, arrays and tables does not really make sense
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ManagedObjectOverrideHandler
+{
+
+ /** The managed object update handler */
+ private ManagedObjectRecreationHandler updateHandler = new ManagedObjectRecreationHandler();
+
+ /** The attachment property populator. */
+ private AttachmentPropertyPopulator populator = new AttachmentPropertyPopulator();
+
+ /** The logger. */
+ protected static final Logger log = Logger.getLogger(ManagedObjectOverrideHandler.class);
+
+ public ManagedObject updateManagedObject(PersistedManagedObject moElement, ManagedObject original) throws Exception
+ {
+ if(moElement == null)
+ throw new IllegalArgumentException("Null persisted meta data.");
+
+ // Create the override object
+ ManagedObject override = updateHandler.createManagedObject(moElement);
+
+ boolean trace = log.isTraceEnabled();
+ return updateManagedObject(original, override, trace);
+ }
+
+ public ManagedObject updateManagedObject(ManagedObject original, ManagedObject override, boolean trace)
+ {
+ if(original == null)
+ return override;
+ if(override == null)
+ return original;
+
+ // Sanity check
+ if(original.getName().equals(override.getName()) == false)
+ throw new IllegalArgumentException("Name don't match [original="
+ + original.getName() + ", override="
+ + override.getName() + "]");
+
+ // AttachmentName
+ if(original.getAttachmentName().equals(override.getAttachmentName()) == false)
+ throw new IllegalArgumentException("Attachments don't match [original="
+ + original.getAttachmentName() + ", override="
+ + override.getAttachmentName() + "]");
+
+ for(String name : override.getPropertyNames())
+ {
+ updateProperty(
+ original.getProperty(name),
+ override.getProperty(name),
+ original.getAttachment(),
+ trace);
+ }
+ return original;
+ }
+
+ protected void updateProperty(ManagedProperty original, ManagedProperty override, Object attachment, boolean trace)
+ {
+ if(original == null)
+ throw new IllegalArgumentException("Null original.");
+ if(override == null)
+ throw new IllegalArgumentException("Null override.");
+
+ if(! original.hasViewUse(ViewUse.CONFIGURATION))
+ return;
+
+ // Skip not readable properties
+ PropertyInfo propertyInfo = original.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ if(propertyInfo != null && propertyInfo.isReadable() == false)
+ return;
+
+ if(trace)
+ log.trace("processing property : " + original);
+
+ // Process the meta value.
+ MetaValue merged = getMetaValue(original.getValue(), override.getValue(), trace);
+
+ // Set the values
+ original.setField(Fields.VALUE, merged);
+ // Update meta type
+ if(merged != null)
+ original.setField(Fields.META_TYPE, merged.getMetaType());
+
+ try
+ {
+ this.populator.processManagedProperty(original.getName(), original, attachment);
+ }
+ catch(Throwable t)
+ {
+ log.debug("Cannot popluate value information of property: " + original);
+ }
+
+ }
+
+ private MetaValue getMetaValue(MetaValue original, MetaValue override, boolean trace)
+ {
+ if(override == null)
+ return original;
+ if(original == null)
+ return override;
+
+ if(original.getMetaType() == null)
+ throw new IllegalStateException("Original meta value is null "+ original);
+
+ if(original.getMetaType().getTypeName().equals(override.getMetaType().getTypeName()) == false)
+ throw new RuntimeException("Cannot merge two different types original: "+ original.getMetaType() + " override: " + override.getMetaType());
+
+ // Now try to merge
+ MetaType metaType = original.getMetaType();
+ MetaValue metaValue = null;
+ if(metaType.isSimple())
+ {
+ metaValue = override;
+ }
+ else if(metaType.isEnum())
+ {
+ metaValue = override;
+ }
+ else if(metaType.isCollection())
+ {
+ metaValue = mergeCollection(
+ (CollectionValue) original,
+ (CollectionValue) override, trace);
+ }
+ else if(metaType.isGeneric())
+ {
+ metaValue = mergeGenericValue(
+ (GenericValue) original,
+ (GenericValue) override, trace);
+ }
+ else if(metaType.isComposite())
+ {
+ mergeCompositeValue(
+ (CompositeValue) original,
+ (CompositeValue) original, trace);
+ }
+ else if(metaType.isTable())
+ {
+ mergeTableValue(
+ (TableValue) original,
+ (TableValue) override, trace);
+ }
+ else if(metaType.isArray())
+ {
+ metaValue = mergeArray(
+ (ArrayValue) original,
+ (ArrayValue) override, trace);
+ }
+ else
+ {
+ throw new IllegalStateException("unknown metaType");
+ }
+ return metaValue;
+ }
+
+ /**
+ * Merge a composite value.
+ * TODO this just returns the new composite value.
+ *
+ * @param original
+ * @param override
+ * @return
+ */
+ private CompositeValue mergeCompositeValue(CompositeValue original, CompositeValue override, boolean trace)
+ {
+ if(original instanceof MapCompositeValueSupport)
+ return mergeMapCompositeValue((MapCompositeValueSupport)original, (MapCompositeValueSupport)override);
+
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ // The override information
+ for(String index : override.getMetaType().itemSet())
+ {
+ MetaValue originalValue = original.get(index);
+ MetaValue overrideValue = override.get(index);
+
+ MetaValue merged = getMetaValue(originalValue, overrideValue, trace);
+ map.put(index, merged);
+ }
+ // Additionally add the original ones
+ for(String index : original.getMetaType().itemSet())
+ {
+ if(map.containsKey(index) == false)
+ {
+ MetaValue value = original.get(index);
+ map.put(index, value);
+ }
+ }
+ return new CompositeValueSupport(original.getMetaType(), map);
+ }
+
+ /**
+ * Merge a map composite value.
+ * This overrides the values from the original items, with the
+ * override item values.
+ *
+ * @param original
+ * @param override
+ * @return
+ */
+ private MapCompositeValueSupport mergeMapCompositeValue(MapCompositeValueSupport original, MapCompositeValueSupport override)
+ {
+ for(String index : override.getMetaType().itemSet())
+ {
+ MetaValue overrideValue = override.get(index);
+ original.put(index, overrideValue);
+ }
+ return original;
+ }
+
+ /**
+ * Merge a table
+ * TODO this return just the override table
+ *
+ * @param original
+ * @param override
+ * @return
+ */
+ private TableValue mergeTableValue(TableValue original, TableValue override, boolean trace)
+ {
+ if(trace)
+ log.trace("merging table value original[indexNames=" + original.getMetaType().getIndexNames()
+ + "] override[indexNames=" + override.getMetaType().getIndexNames() +"]");
+
+ // Use override
+ return override;
+ }
+
+ /**
+ * Create a merged array value.
+ *
+ * @param original the original array
+ * @param override the override array
+ * @return the merged array
+ */
+ private ArrayValue mergeArray(ArrayValue original , ArrayValue override, boolean trace)
+ {
+ if( original.getLength() != override.getLength())
+ {
+ log.debug("overriding array : " + original);
+ return override;
+ }
+
+ List<Object> values = new ArrayList<Object>();
+ Iterator<Object> io = original.iterator();
+ Iterator<Object> iv = override.iterator();
+
+ while(io.hasNext())
+ {
+ Object originalValue = io.next();
+ Object overrideValue = iv.next();
+ Object merged = null;
+
+ if(originalValue instanceof MetaValue
+ && overrideValue instanceof MetaValue)
+ {
+ merged = getMetaValue(
+ (MetaValue) originalValue,
+ (MetaValue) overrideValue, trace);
+ }
+ else if(originalValue != null && originalValue.getClass().isArray()
+ && overrideValue != null && overrideValue.getClass().isArray())
+ {
+ merged = mergeSubArray(originalValue, overrideValue, trace);
+ }
+ else
+ {
+ throw new RuntimeException("Could not process values original: " + original +", override: " + override);
+ }
+ values.add(merged);
+ }
+ return new ArrayValueSupport(original.getMetaType(), values.toArray());
+ }
+
+ /**
+ * Merge a sub array.
+ *
+ * @param original the original sub element
+ * @param override the override sub element
+ * @return the merged values
+ */
+ private Object mergeSubArray(Object original, Object override, boolean trace)
+ {
+ List<Object> values = new ArrayList<Object>();
+ int originalSize = Array.getLength(original);
+ int overrideSize = Array.getLength(override);
+
+ if(originalSize != overrideSize)
+ throw new RuntimeException("Could not process sub-array original size: " + originalSize + ", override size: " + overrideSize);
+
+ for(int i = 0; i < originalSize; i++)
+ {
+ Object originalElement = Array.get(original, i);
+ Object overrideElement = Array.get(override, i);
+ Object merged = null;
+
+ if(originalElement instanceof MetaValue
+ && overrideElement instanceof MetaValue)
+ {
+ merged = getMetaValue((MetaValue) originalElement, (MetaValue) overrideElement, trace);
+ }
+ else if ( originalElement != null && originalElement.getClass().isArray()
+ && overrideElement != null && overrideElement.getClass().isArray())
+ {
+ merged = mergeSubArray(originalElement, overrideElement, trace);
+ }
+ else
+ {
+ throw new RuntimeException("Could not process values original: " + original +", override: " + override);
+ }
+ values.add(merged);
+ }
+ return values.toArray();
+ }
+
+ /**
+ * Create a merged collection value.
+ *
+ * @param original the original collection
+ * @param override the override collection
+ * @return the merged collection
+ */
+ private CollectionValue mergeCollection(CollectionValue original, CollectionValue override, boolean trace)
+ {
+
+ if(trace)
+ log.trace("merging collection orginal[size=" + original.getSize() + "], override[size="+ override.getSize() + "]");
+
+ CollectionMetaType metaType = original.getMetaType();
+ if(original.getSize() != override.getSize())
+ {
+ // FIXME
+ List<MetaValue> values = new ArrayList<MetaValue>();
+ if(original.getElements() != null)
+ values.addAll(Arrays.asList(original.getElements()));
+ if(override.getElements() != null)
+ values.addAll(Arrays.asList(override.getElements()));
+
+ return new CollectionValueSupport(metaType, values.toArray( new MetaValue[ values.size() ]));
+ }
+
+ // The new values.
+ List<MetaValue> values = new ArrayList<MetaValue>();
+ Iterator<MetaValue> io = original.iterator();
+ Iterator<MetaValue> iv = override.iterator();
+ while(io.hasNext())
+ {
+ MetaValue originalValue = io.next();
+ MetaValue overrideValue = iv.next();
+ MetaValue merged = getMetaValue(originalValue, overrideValue, trace);
+ values.add(merged);
+ }
+ return new CollectionValueSupport(metaType, values.toArray( new MetaValue[values.size()] ));
+ }
+
+ /**
+ * Merge a generic value.
+ *
+ * @param original the original generic value
+ * @param override the override generic value
+ * @return the merged value
+ */
+ private GenericValue mergeGenericValue(GenericValue original, GenericValue override, boolean trace)
+ {
+ Object o = original.getValue();
+ Object v = override.getValue();
+
+ if( (o instanceof ManagedObject)
+ && (v instanceof ManagedObject))
+ {
+ ManagedObject originalMO = (ManagedObject) o;
+ ManagedObject overrideMO = (ManagedObject) v;
+
+ if(trace)
+ log.trace("trying to merge original[name=" + originalMO.getName() + ",attachment=" + originalMO.getAttachment().getClass()
+ + "], override[name=" + overrideMO.getName() + ",attachment=" + overrideMO.getAttachment().getClass() + "]");
+
+ // merge
+ ManagedObject merged = updateManagedObject(originalMO , overrideMO, trace);
+ return new GenericValueSupport(original.getMetaType(), merged);
+ }
+ if(o == null && v == null) return new GenericValueSupport(original.getMetaType(), null);
+ throw new RuntimeException("Cannot merge original: " + original + ", override: "+ override);
+ }
+
+}
+
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -21,35 +21,8 @@
*/
package org.jboss.system.server.profileservice.persistence;
-import java.util.Set;
-
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.Fields;
import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedArrayValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedEnumValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedSimpleValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedTableValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
/**
* Create a xml representation of a Managed Object.
@@ -59,360 +32,31 @@
*/
public class ManagedObjectPeristenceHandler
{
- /** The meta value factory. */
- MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+
+ /** The actual handler */
+ private static final ManagedObjectPersistence handler = new ManagedObjectPersistence();
- /** The logger. */
- private static final Logger log = Logger.getLogger(ManagedObjectPeristenceHandler.class);
-
/**
- * Process a managed object.
+ * Create the persistence meta data for a ManagedObject.
*
- * @param moElement the xml meta data.
* @param mo the managed object
- * @return isModified
+ * @return the persistence meta data
*/
- public boolean processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
+ public PersistedManagedObject createPersistenceMetaData(ManagedObject mo)
{
- if(moElement == null)
- throw new IllegalArgumentException("Null rootElement.");
- if(mo == null)
- throw new IllegalArgumentException("null managedObject");
-
- moElement.setName(mo.getName());
- moElement.setClassName(mo.getAttachmentName());
-
- // Store the original name, if it does not exist.
- if(moElement.getOriginalName() == null)
- moElement.setOriginalName(mo.getName());
-
- boolean changed = false;
- Set<String> propertyNames = mo.getPropertyNames();
- for(String propertyName : propertyNames)
- {
- ManagedProperty property = mo.getProperty(propertyName);
- if(property == null)
- throw new IllegalStateException("unable to find propery: "+ property);
-
- if(! property.hasViewUse(ViewUse.CONFIGURATION))
- continue;
-
- // getProperty
- PersistedProperty propertyElement = moElement.get(propertyName);
- if(propertyElement == null)
- propertyElement = new PersistedProperty(property.getName());
- boolean propertyChanged = processManagedProperty(propertyElement, propertyName, property);
-
- if(propertyChanged)
- {
- changed = true;
- moElement.put(propertyName, propertyElement);
- }
- }
- return changed;
+ return handler.createPersistenceMetaData(mo);
}
/**
- * Process a ManagedProperty.
+ * Process a managed object.
*
- * @param persistedProperty the xml property meta data.
- * @param name the property name.
- * @param property the managed property.
- * @return isModified.
+ * @param moElement the xml meta data.
+ * @param mo the managed object
+ * @return isModified
*/
- protected boolean processManagedProperty(PersistedProperty persistedProperty, String name, ManagedProperty property)
+ public void processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
{
- boolean trace = log.isTraceEnabled();
- PropertyInfo propertyInfo = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
- // Skip not readable properties
- if(propertyInfo != null && propertyInfo.isReadable() == false)
- {
- if(trace)
- log.trace("property "+ name + "is not readable");
- return false;
- }
-
- // TODO Check if property was modified
- // MetaType metaType = property.getMetaType();
- // if( ! metaType.isCollection() && ! metaType.isArray() )
- // {
- // if(property.isModified() == false)
- // return false;
- // }
-
- // Get MetaValue
- MetaValue value = property.getValue();
- // Check if there is a previous persisted property value
- PersistedValue persistedValue = persistedProperty.getValue();
- // Process
- boolean changed = false;
- if(value != null)
- {
- // Create a new value, if needed
- if(persistedValue == null)
- persistedValue = createPersistedValue(value.getMetaType());
- // Process
- changed = processMetaValue(persistedValue, value);
- }
-
- persistedProperty.setValue(persistedValue);
-
- return changed;
+ handler.processManagedObject(moElement, mo);
}
-
- /**
- * Process a MetaValue.
- *
- * @param valueElement the xml metadata.
- * @param value the meta value.
- * @return isModified.
- */
- protected boolean processMetaValue(PersistedValue valueElement, MetaValue value)
- {
- // FIXME a MetaValue should never be null ?
- if(value == null)
- return false;
-
- // TODO we need to know if the MetaValue was modified too.
- boolean changed = false;
- MetaType metaType = value.getMetaType();
-
- if(metaType.isSimple())
- {
- changed = processSimpleValue((PersistedSimpleValue) valueElement, (SimpleValue) value);
- }
- else if(metaType.isEnum())
- {
- changed = processEnumValue((PersistedEnumValue) valueElement, (EnumValue) value);
- }
- else if(metaType.isCollection())
- {
- changed = processCollectionValue((PersistedCollectionValue) valueElement, (CollectionValue) value);
- }
- else if(metaType.isGeneric())
- {
- changed = processGenericValue((PersistedGenericValue) valueElement, (GenericValue) value);
- }
- else if(metaType.isComposite())
- {
- changed = processCompositeValue((PersistedCompositeValue) valueElement, (CompositeValue) value);
- }
- else if(metaType.isArray())
- {
- changed = processArrayValue((PersistedArrayValue) valueElement, (ArrayValue) value);
- }
- else if(metaType.isTable())
- {
- throw new UnsupportedOperationException("Persisting a table value.");
- }
- else
- {
- throw new IllegalStateException("unknown metaType");
- }
- return changed;
- }
-
- /**
- * Process a simple value.
- *
- * @param valueElement the xml meta data.
- * @param value the simple value.
- * @return isModified.
- */
- protected boolean processSimpleValue(PersistedSimpleValue valueElement, SimpleValue value)
- {
- valueElement.setValue(convertSimple2String(value));
- return true;
- }
-
- /**
- * Process a enumValue.
- *
- * @param enumElement the xml meta data.
- * @param value the enum value.
- */
- protected boolean processEnumValue(PersistedEnumValue enumElement, EnumValue value)
- {
- enumElement.setValue(value.getValue());
- return true;
- }
-
- /**
- * Process a collection value.
- *
- * @param valueElement the xml meta data.
- * @param value the collection value.
- * @return isModified.
- */
- protected boolean processCollectionValue(PersistedCollectionValue valueElement, CollectionValue value)
- {
- boolean changed = false;
- for(MetaValue child : value.getElements())
- {
- PersistedValue persistedValue = createPersistedValue(child.getMetaType());
-
- if( processMetaValue(persistedValue, child) == true)
- changed = true;
-
- valueElement.addValue(persistedValue);
- }
- return changed;
- }
-
- /**
- * Process a generic value.
- *
- * @param genericElement the xml metadata.
- * @param value the generic value.
- * @return isModified.
- */
- protected boolean processGenericValue(PersistedGenericValue genericElement, GenericValue value)
- {
- Object o = value.getValue();
- if(o == null)
- return false;
-
- boolean changed = false;
- if(o instanceof ManagedObject)
- {
- PersistedManagedObject mo = new PersistedManagedObject();
- if(processManagedObject(mo, (ManagedObject) o) == true)
- changed = true;
- genericElement.setManagedObject(mo);
- return changed;
- }
- else
- {
- throw new IllegalStateException("The value of GenericValue must be a ManagedObject: " + value);
- }
- }
-
- /**
- * Process the array value.
- *
- * @param array the xml meta data.
- * @param value the array value.
- * @return isModified.
- */
- protected boolean processArrayValue(PersistedArrayValue array, ArrayValue value)
- {
- ArrayMetaType metaType = value.getMetaType();
-
- if(! metaType.getElementType().isSimple())
- throw new UnsupportedOperationException("Persisting a non primitive array.");
-
- boolean changed = false;
- for(int i = 0; i < value.getLength(); i++)
- {
- MetaValue metaValue = (MetaValue) value.getValue(i);
- PersistedValue persistedValue = createPersistedValue(metaType.getElementType());
-
- if(processMetaValue(persistedValue, metaValue) == true)
- changed = true;
-
- array.addValue(persistedValue);
- }
- return changed;
- }
-
- /**
- * Process a composite value.
- *
- * @param composite the xml meta data.
- * @param value the composite value.
- * @return isModified.
- */
- protected boolean processCompositeValue(PersistedCompositeValue composite, CompositeValue value)
- {
- CompositeMetaType metaType = value.getMetaType();
-
- boolean changed = false;
- for(String item : metaType.itemSet())
- {
- MetaValue itemValue = value.get(item);
-
- // FIXME a value should never be null ?
- MetaType itemType = null;
- if(itemValue != null)
- {
- itemType = itemValue.getMetaType();
- }
- else
- {
- itemType = metaType.getType(item);
- }
-
- PersistedValue persistedValue = createPersistedValue(itemType);
- persistedValue.setName(item);
-
- if(processMetaValue(persistedValue, itemValue) == true)
- changed = true;
-
- composite.put(item, persistedValue);
- }
- return changed;
- }
- /**
- * Create an empty xml value representation.
- *
- * @param metaType the meta type.
- * @return a empty xml meta data, based on the meta type.
- */
- protected static PersistedValue createPersistedValue(MetaType metaType)
- {
- if(metaType.isSimple())
- {
- return new PersistedSimpleValue();
- }
- else if(metaType.isEnum())
- {
- return new PersistedEnumValue();
- }
- else if(metaType.isCollection())
- {
- return new PersistedCollectionValue();
- }
- else if(metaType.isGeneric())
- {
- return new PersistedGenericValue();
- }
- else if(metaType.isComposite())
- {
- return new PersistedCompositeValue();
- }
- else if(metaType.isTable())
- {
- return new PersistedTableValue();
- }
- else if(metaType.isArray())
- {
- return new PersistedArrayValue();
- }
- else
- {
- throw new IllegalStateException("unknown metaType");
- }
- }
-
- /**
- * Convert a simple meta value to a String.
- *
- * @param value the simple meta value.
- * @return the string.
- */
- protected String convertSimple2String(SimpleValue value)
- {
- // TODO a metaValue should never be null?
- if(value == null)
- return null;
-
- Object unwrappedValue = metaValueFactory.unwrap(value);
-
- if(unwrappedValue == null)
- return null;
-
- return ("" + unwrappedValue);
- }
-
}
\ No newline at end of file
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistence.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistence.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistence.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,490 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.system.server.profileservice.persistence;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedArrayValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedEnumValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedSimpleValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedTableValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ManagedObjectPersistence
+{
+
+ /** The meta value factory. */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ManagedObjectPersistence.class);
+
+ /**
+ * Create the persistence meta data for a ManagedObject.
+ *
+ * @param mo the managed object
+ * @return the persistence meta data
+ */
+ public PersistedManagedObject createPersistenceMetaData(ManagedObject mo)
+ {
+ if(mo == null)
+ throw new IllegalArgumentException("Null managedObject.");
+
+ PersistedManagedObject moElement = new PersistedManagedObject();
+ processManagedObject(moElement, mo);
+ return moElement;
+ }
+
+ /**
+ * Process a managed object.
+ *
+ * @param moElement the xml meta data.
+ * @param mo the managed object
+ * @return isModified
+ */
+ public void processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
+ {
+ if(moElement == null)
+ throw new IllegalArgumentException("Null rootElement.");
+ if(mo == null)
+ throw new IllegalArgumentException("null managedObject");
+
+ boolean trace = log.isTraceEnabled();
+
+ // Set the template and class-name
+ String className = mo.getAttachmentName();
+ if(mo.getAttachment() != null)
+ {
+ Class<?> attachment = mo.getAttachment().getClass();
+ className = attachment.getName();
+ // Set the template name
+ if(className.equals(mo.getAttachmentName()) == false)
+ {
+ // If the MO template is different from the actual attachment
+ moElement.setTemplateName(mo.getAttachmentName());
+ }
+ }
+
+ // Set the managed-object meta information
+ moElement.setName(mo.getName());
+ moElement.setClassName(className);
+
+ // Process the properties
+ List<PersistedProperty> properties = moElement.getProperties();
+ if(properties == null)
+ {
+ properties = new ArrayList<PersistedProperty>();
+ moElement.setProperties(properties);
+ }
+ for(String propertyName : mo.getPropertyNames())
+ {
+ ManagedProperty property = mo.getProperty(propertyName);
+ if(property == null)
+ throw new IllegalStateException("unable to find propery: "+ property);
+
+ if(! property.hasViewUse(ViewUse.CONFIGURATION))
+ continue;
+
+ // getProperty
+ PropertyInfo propertyInfo = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ // Skip not readable properties
+ if(propertyInfo != null && propertyInfo.isReadable() == false)
+ {
+ if(trace)
+ log.trace("skipping property "+ propertyName + "is not readable");
+ continue;
+ }
+
+ PersistedProperty propertyElement = createPersistedProperty(
+ propertyName,
+ property.getValue(),
+ property.getMetaType());
+
+ properties.add(propertyElement);
+ }
+ }
+
+ /**
+ * Create the persisted property.
+ *
+ * @param name the property name
+ * @param value the meta value
+ * @param metaType the meta type
+ * @return the property
+ */
+ protected PersistedProperty createPersistedProperty(String name, MetaValue value, MetaType metaType)
+ {
+ if(name == null)
+ throw new IllegalArgumentException("Null name.");
+ if(metaType == null)
+ throw new IllegalArgumentException("Null meta type.");
+
+ // Create Property
+ PersistedProperty property = new PersistedProperty(name);
+ // Create persisted value
+ PersistedValue persistedValue = createPersistedValue(value, metaType);
+ //
+ property.setValue(persistedValue);
+ // Return
+ return property;
+ }
+
+ /**
+ * Create the peristed xml meta data.
+ *
+ * @param value the meta value
+ * @param metaType the meta type
+ * @return the xml value.
+ */
+ protected PersistedValue createPersistedValue(MetaValue value, MetaType metaType)
+ {
+ if(log.isTraceEnabled())
+ log.trace("creating persisted value for : " + value + " with metaType " + metaType);
+
+ if(value == null)
+ return emtpyPersistedValue(metaType);
+
+ // Override the metaType e.g. the MapCompositeValueSupport
+ metaType = value.getMetaType();
+
+ PersistedValue persistedValue = null;
+ if(metaType.isSimple())
+ {
+ persistedValue = createSimpleValue(
+ (SimpleValue) value);
+ }
+ else if(metaType.isEnum())
+ {
+ persistedValue = createEnumValue(
+ (EnumValue) value);
+ }
+ else if(metaType.isCollection())
+ {
+ persistedValue = createCollectionValue(
+ (CollectionValue) value);
+ }
+ else if(metaType.isGeneric())
+ {
+ persistedValue = createGenericValue(
+ (GenericValue) value);
+ }
+ else if(metaType.isComposite())
+ {
+ persistedValue = createCompositeValue(
+ (CompositeValue) value,
+ (CompositeMetaType) metaType);
+ }
+ else if(metaType.isArray())
+ {
+ persistedValue = createArrayValue(
+ (ArrayValue) value,
+ (ArrayMetaType) metaType);
+ }
+ else if(metaType.isTable())
+ {
+ persistedValue = createTableValue(
+ (TableValue) value);
+ }
+ else
+ {
+ throw new IllegalStateException("unknown metaType");
+ }
+ return persistedValue;
+ }
+
+ /**
+ * Create the persistence enum value.
+ *
+ * @param value the enum value
+ * @return the enum xml meta data
+ */
+ private PersistedEnumValue createEnumValue(EnumValue value)
+ {
+ PersistedEnumValue persistedValue = new PersistedEnumValue();
+ persistedValue.setValue(value.getValue());
+ return persistedValue;
+ }
+
+ /**
+ * Create the persistence simple value.
+ *
+ * @param value the simple value
+ * @return the simple xml meta data
+ */
+ private PersistedSimpleValue createSimpleValue(SimpleValue value)
+ {
+ PersistedSimpleValue persistedValue = new PersistedSimpleValue();
+ persistedValue.setValue(convertSimple2String(value));
+ return persistedValue;
+ }
+
+ /**
+ * Create the persistence collection value.
+ *
+ * @param value the collection value
+ * @return the collection xml meta data
+ */
+ private PersistedCollectionValue createCollectionValue(CollectionValue value)
+ {
+ PersistedCollectionValue collection = new PersistedCollectionValue();
+ for(MetaValue child : value.getElements())
+ {
+ PersistedValue persistedValue = createPersistedValue(child, child.getMetaType());
+ collection.addValue(persistedValue);
+ }
+ return collection;
+ }
+
+ /**
+ * Create the persistence generic value.
+ *
+ * @param value the generic value
+ * @return the generic xml meta data
+ */
+ private PersistedGenericValue createGenericValue(GenericValue value)
+ {
+ //
+ PersistedGenericValue generic = new PersistedGenericValue();
+ Object o = value.getValue();
+ if(o == null)
+ return generic;
+
+ if(o instanceof ManagedObject)
+ {
+ PersistedManagedObject mo = createPersistenceMetaData((ManagedObject) o);
+ generic.setManagedObject(mo);
+ }
+ else
+ {
+ throw new IllegalStateException("The value of GenericValue must be a ManagedObject: " + value);
+ }
+ return generic;
+ }
+
+ /**
+ * Create the persistence array value.
+ *
+ * @param value the array value
+ * @return
+ */
+ private PersistedArrayValue createArrayValue(ArrayValue value, ArrayMetaType metaType)
+ {
+ //
+ PersistedArrayValue array = new PersistedArrayValue();
+ MetaType elementType = metaType.getElementType();
+ for (int i = 0; i < value.getLength(); i++)
+ {
+ PersistedValue persistedValue = null;
+ Object subElement = value.getValue(i);
+
+ if (subElement instanceof MetaValue)
+ {
+ persistedValue = createPersistedValue((MetaValue) subElement, elementType);
+ }
+ else if (subElement != null && subElement.getClass().isArray())
+ {
+ persistedValue = unwrapArray(array, subElement, elementType);
+ }
+ // Add to parent
+ array.addValue(persistedValue);
+ }
+ return array;
+ }
+
+ /**
+ * Unwrap array.
+ *
+ * @param array the parent array
+ * @param element the array value
+ * @param type the element meta type
+ * @return the persistence xml meta data
+ */
+ protected PersistedArrayValue unwrapArray(PersistedArrayValue array, Object element, MetaType type)
+ {
+ PersistedArrayValue newElement = new PersistedArrayValue();
+ int subSize = Array.getLength(element);
+ for (int i = 0; i < subSize; i++)
+ {
+ PersistedValue persistedValue = null;
+ Object subElement = Array.get(element, i);
+ if (subElement instanceof MetaValue)
+ {
+ persistedValue = createPersistedValue((MetaValue) subElement, type);
+ }
+ if (subElement != null && subElement.getClass().isArray())
+ {
+ persistedValue = unwrapArray(newElement, subElement, type);
+ }
+
+ newElement.addValue(persistedValue);
+ }
+ return newElement;
+ }
+
+ /**
+ * Create the persistence composite value.
+ *
+ * @param value the composite value
+ * @param metaType the composite meta type
+ * @return the persistence composite xml meta data
+ */
+ private PersistedCompositeValue createCompositeValue(CompositeValue value, CompositeMetaType metaType)
+ {
+ //
+ PersistedCompositeValue composite = new PersistedCompositeValue();
+ // Fix the values
+ List<PersistedValue> values = composite.getValues();
+ if(values == null)
+ {
+ values = new ArrayList<PersistedValue>();
+ composite.setValues(values);
+ }
+ for(String item : metaType.itemSet())
+ {
+ MetaType itemType = metaType.getType(item);
+ MetaValue itemValue = value.get(item);
+
+ // Create item
+ PersistedValue persistedValue = createPersistedValue(itemValue, itemType);
+ persistedValue.setName(item);
+
+ values.add(persistedValue);
+ }
+ return composite;
+ }
+
+ /**
+ * Create the persistence table value.
+ *
+ * @param value the table value
+ * @return the persistence table xml meta data
+ */
+ private PersistedTableValue createTableValue(TableValue value)
+ {
+ PersistedTableValue table = new PersistedTableValue();
+ // Fix the entries
+ List<PersistedCompositeValue> entries = table.getEntries();
+ if(entries == null)
+ {
+ entries = new ArrayList<PersistedCompositeValue>();
+ table.setEntries(entries);
+ }
+ // Process values
+ Collection<CompositeValue> values = value.values();
+ for(CompositeValue entry : values)
+ {
+ entries.add(createCompositeValue(entry, entry.getMetaType()));
+ }
+ return table;
+ }
+
+ /**
+ * Create a emtpy xml meta data, based on the meta type
+ *
+ * @param metaType the meta type
+ * @return the peristence value
+ */
+ protected static PersistedValue emtpyPersistedValue(MetaType metaType)
+ {
+ if(metaType.isSimple())
+ {
+ return new PersistedSimpleValue();
+ }
+ else if(metaType.isEnum())
+ {
+ return new PersistedEnumValue();
+ }
+ else if(metaType.isCollection())
+ {
+ return new PersistedCollectionValue();
+ }
+ else if(metaType.isGeneric())
+ {
+ return new PersistedGenericValue();
+ }
+ else if(metaType.isComposite())
+ {
+ return new PersistedCompositeValue();
+ }
+ else if(metaType.isTable())
+ {
+ return new PersistedTableValue();
+ }
+ else if(metaType.isArray())
+ {
+ return new PersistedArrayValue();
+ }
+ else
+ {
+ throw new IllegalStateException("unknown metaType");
+ }
+ }
+
+ /**
+ * Convert a simple meta value to a String.
+ *
+ * @param value the simple meta value.
+ * @return the string.
+ */
+ protected String convertSimple2String(SimpleValue value)
+ {
+ if(value == null)
+ throw new IllegalArgumentException("Null value.");
+
+ Object unwrappedValue = metaValueFactory.unwrap(value);
+ if(unwrappedValue == null)
+ return null;
+ // Convert to String
+ return ("" + unwrappedValue);
+ }
+}
+
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHandler.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHandler.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,558 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.system.server.profileservice.persistence;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedObject;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.EnumMetaType;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.Name;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.types.TableMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.EnumValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.metatype.api.values.TableValueSupport;
+import org.jboss.metatype.plugins.types.StringName;
+import org.jboss.reflect.plugins.ValueConvertor;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedArrayValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedEnumValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedSimpleValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedTableValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
+
+/**
+ * This handler recreates only the ManagedObject based on the persisted meta data.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ManagedObjectRecreationHandler
+{
+ /** The meta data. */
+ private MetaData metaData;
+
+ /** The plugin. */
+ private MOCreatorPlugin plugin;
+
+ /** The simple types. */
+ private final static Map<String, Class<? extends Serializable>> simpleTypes = new HashMap<String, Class<? extends Serializable>>();
+
+ /** The logger. */
+ private final static Logger log = Logger.getLogger(ManagedObjectRecreationHandler.class);
+
+ static
+ {
+ // Fill simple types map.
+ simpleTypes.put(BigDecimal.class.getName(), BigDecimal.class);
+ simpleTypes.put(BigInteger.class.getName(), BigInteger.class);
+ simpleTypes.put(Boolean.class.getName(), Boolean.class);
+ simpleTypes.put(Byte.class.getName(), Byte.class);
+ simpleTypes.put(Character.class.getName(), Character.class);
+ simpleTypes.put(Date.class.getName(), Date.class);
+ simpleTypes.put(Double.class.getName(), Double.class);
+ simpleTypes.put(Float.class.getName(), Float.class);
+ simpleTypes.put(Integer.class.getName(), Integer.class);
+ simpleTypes.put(Long.class.getName(), Long.class);
+ simpleTypes.put(Short.class.getName(), Short.class);
+ simpleTypes.put(String.class.getName(), String.class);
+ simpleTypes.put(Name.class.getName(), Name.class);
+ }
+
+ public ManagedObjectRecreationHandler()
+ {
+ this.plugin = new MOCreatorPlugin();
+ }
+
+ public ManagedObjectRecreationHandler(MOCreatorPlugin plugin)
+ {
+ this.plugin = plugin;
+ }
+
+ public ManagedObjectRecreationHandler(MOCreatorPlugin plugin, MetaData metaData)
+ {
+ this(plugin);
+ this.metaData = metaData;
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject moElement) throws Exception
+ {
+ if(moElement == null)
+ throw new IllegalArgumentException("Null persisted meta data.");
+ if(moElement.getClassName() == null)
+ throw new IllegalArgumentException("Null class-name for managed object.");
+
+ // Check if we need to use a template for the managed object
+ String className = moElement.getTemplateName();
+ if(className == null)
+ {
+ className = moElement.getClassName();
+ }
+ ManagedObject mo = buildManagedObject(className);
+
+
+ if(mo instanceof MutableManagedObject)
+ {
+ // Update the name
+ ((MutableManagedObject) mo).setName(moElement.getName());
+
+ if(moElement.getTemplateName() != null)
+ {
+ // Override the actual attachment
+ Class<?> attachment = plugin.getClassLoader().loadClass(moElement.getClassName());
+ ((MutableManagedObject) mo).setAttachment(attachment.newInstance());
+ }
+ }
+
+ // Process
+ processManagedObject(moElement, mo);
+
+ // Return
+ return mo;
+ }
+
+ /**
+ * Process a ManagedObject.
+ *
+ * @param moElement the persisted xml meta data.
+ * @param mo the managed object
+ * @return the attachment meta data.
+ */
+ public void processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
+ {
+ if(moElement == null)
+ throw new IllegalArgumentException("Null rootElement.");
+ if(mo == null)
+ throw new IllegalArgumentException("null managedObject");
+
+ // Get the xml to see what we need to merge
+ if(moElement.getProperties() != null && moElement.getProperties().isEmpty() == false)
+ {
+ for(PersistedProperty propertyElement : moElement.getProperties())
+ {
+ ManagedProperty property = mo.getProperty(propertyElement.getName());
+ if(property == null)
+ throw new IllegalStateException("unable to find propery: "+ property);
+
+ // Skip all non configuration properties
+ if(! property.hasViewUse(ViewUse.CONFIGURATION))
+ continue;
+
+ // getProperty
+ processManagedProperty(propertyElement, propertyElement.getName(), property, mo.getAttachment());
+ }
+ }
+ }
+
+ /**
+ * Build a managedObject based on the className
+ *
+ * @param className the name of the class
+ * @return the ManagedObject
+ * @throws Exception
+ */
+ protected ManagedObject buildManagedObject(String className) throws Exception
+ {
+ return plugin.createManagedObject(className, metaData);
+ }
+
+ /**
+ * Process a ManagedProperty.
+ *
+ * @param propertyElement the persisted xml meta data.
+ * @param name the property name.
+ * @param property the managed property.
+ */
+ protected void processManagedProperty(PersistedProperty propertyElement, String name, ManagedProperty property, Object attachment)
+ {
+ // Get MetaType
+ MetaType metaType = property.getMetaType();
+ // Process the value
+ PersistedValue persistedValue = propertyElement.getValue();
+ if(persistedValue != null)
+ {
+ MetaValue value = createMetaValue(persistedValue, metaType);
+ // Set the value Field
+ property.setField(Fields.VALUE, value);
+ // Update meta type
+ if(value != null)
+ property.setField(Fields.META_TYPE, value.getMetaType());
+ }
+ // Done
+ }
+
+ /**
+ * Create the meta value, based on the xml persited
+ * value and the generated MetaType.
+ *
+ * @param valueElement the persisted xml element
+ * @param type the meta type.
+ * @return the created meta value.
+ */
+ protected MetaValue createMetaValue(PersistedValue valueElement, MetaType metaType)
+ {
+ if(log.isTraceEnabled())
+ {
+ log.trace("processing value " + valueElement + " type: " + metaType);
+ }
+
+ if(valueElement == null)
+ return null;
+
+ MetaValue metaValue = null;
+ if(metaType.isSimple())
+ {
+ metaValue = createSimpleValue(
+ (PersistedSimpleValue) valueElement,
+ (SimpleMetaType) metaType);
+ }
+ else if(metaType.isEnum())
+ {
+ metaValue = createEnumValue(
+ (PersistedEnumValue) valueElement,
+ (EnumMetaType) metaType);
+ }
+ else if(metaType.isCollection())
+ {
+ metaValue = createCollectionValue(
+ (PersistedCollectionValue) valueElement,
+ (CollectionMetaType) metaType);
+ }
+ else if(metaType.isGeneric())
+ {
+ metaValue = createGenericValue(
+ (PersistedGenericValue) valueElement,
+ (GenericMetaType) metaType);
+ }
+ else if(metaType.isComposite())
+ {
+ metaValue = createCompositeValue(
+ (PersistedCompositeValue) valueElement,
+ (CompositeMetaType) metaType);
+ }
+ else if(metaType.isTable())
+ {
+ metaValue = createTableValue(
+ (PersistedTableValue) valueElement,
+ (TableMetaType)metaType);
+ }
+ else if(metaType.isArray())
+ {
+ metaValue = createArrayValue(
+ (PersistedArrayValue) valueElement,
+ (ArrayMetaType) metaType);
+ }
+ else
+ {
+ throw new IllegalStateException("unknown metaType");
+ }
+ return metaValue;
+ }
+
+ /**
+ * Create simple value.
+ *
+ * @param valueElement the persisted xml meta data.
+ * @param value the simple value.
+ * @return a simple value.
+ */
+ protected SimpleValue createSimpleValue(PersistedSimpleValue valueElement, SimpleMetaType metaType)
+ {
+ String elementValue = valueElement.getValue();
+
+ Serializable converted = null;
+ if(elementValue != null)
+ {
+ if(metaType.equals(SimpleMetaType.STRING))
+ {
+ converted = (String) elementValue;
+ }
+ else if (metaType.equals(SimpleMetaType.NAMEDOBJECT))
+ {
+ converted = new StringName(elementValue);
+ }
+ else if (metaType.equals(SimpleMetaType.VOID))
+ {
+ //
+ }
+ else
+ {
+ converted = convert2Type(metaType.getTypeName(), elementValue);
+ }
+ }
+ return SimpleValueSupport.wrap(converted);
+ }
+
+ /**
+ * Process an Enum value.
+ *
+ * @param enumElement the persisted xml meta data.
+ * @param value the enum value.
+ * @return a enum value.
+ */
+ protected EnumValue createEnumValue(PersistedEnumValue enumElement, EnumMetaType type)
+ {
+ return new EnumValueSupport(type, enumElement.getValue());
+ }
+
+ /**
+ * Create composite value.
+ *
+ * @param composite the persisted xml meta data.
+ * @param value the composite value.
+ * @return a composite value.
+ */
+ protected CompositeValue createCompositeValue(PersistedCompositeValue composite, CompositeMetaType type)
+ {
+ // Handle the mapCompositeMetaType differently
+ if(type instanceof MapCompositeMetaType)
+ return handleMapCompositeMetaType(composite, (MapCompositeMetaType) type);
+
+ // Create composite value
+ Map<String, MetaValue> values = new HashMap<String, MetaValue>();
+ if(composite.getValues() != null && composite.getValues().isEmpty() == false)
+ {
+ for(PersistedValue persistedValue : composite.getValues())
+ {
+ MetaType elementType = type.getType(persistedValue.getName());
+ if(elementType == null)
+ throw new IllegalStateException("Failed to process composite value: " + persistedValue.getName());
+
+ // Create
+ MetaValue metaValue = createMetaValue(persistedValue, elementType);
+ // Put
+ values.put(persistedValue.getName(), metaValue);
+ }
+ }
+ return new CompositeValueSupport(type, values);
+ }
+
+ /**
+ * Create the MapCompositeValueSupport value.
+ *
+ * @param composite the persisted composite xml meta data
+ * @param type the MapComposite meta type
+ * @return the MapCompositeValueSupport
+ */
+ protected MapCompositeValueSupport handleMapCompositeMetaType(PersistedCompositeValue composite, MapCompositeMetaType type)
+ {
+ Map<String, MetaValue> values = new HashMap<String, MetaValue>();
+ if(composite.getValues() != null && composite.getValues().isEmpty() == false)
+ {
+ for(PersistedValue persistedValue : composite.getValues())
+ {
+ MetaValue value = createMetaValue(persistedValue, type.getValueType());
+ values.put(persistedValue.getName(), value);
+ }
+ }
+ return new MapCompositeValueSupport(values, type);
+ }
+
+ /**
+ * Process a collection.
+ *
+ * @param collection the persisted xml meta data.
+ * @param value the collection value.
+ * @return a collection value.
+ */
+ protected CollectionValue createCollectionValue(PersistedCollectionValue collection, CollectionMetaType type)
+ {
+ List<MetaValue> elementList = new ArrayList<MetaValue>();
+ if(collection.getValues() != null && collection.getValues().isEmpty() == false)
+ {
+ for(PersistedValue element : collection.getValues())
+ {
+ elementList.add(
+ createMetaValue(element, type.getElementType()));
+ }
+ }
+ return new CollectionValueSupport(type, elementList.toArray(new MetaValue[elementList.size()]));
+ }
+
+ /**
+ * Create generic value.
+ *
+ * @param genericElement the persisted generic xml meta data
+ * @param metaType the generic meta type
+ * @return the generic value
+ */
+ protected GenericValue createGenericValue(PersistedGenericValue genericElement, GenericMetaType metaType)
+ {
+ if (ManagedObject.class.getName().equals(metaType.getTypeName()))
+ {
+ PersistedManagedObject persisted = genericElement.getManagedObject();
+ ManagedObject mo = null;
+ if(persisted != null)
+ {
+ try
+ {
+ mo = createManagedObject(persisted);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Could not create ManagedObject for class: " + persisted.getClassName(), t);
+ }
+ }
+ return new GenericValueSupport(metaType, mo);
+ }
+ throw new IllegalStateException("Cannot reproduce generic object: " + metaType);
+ }
+
+ /**
+ * Create the table value.
+ *
+ * @param table the persisted table value.
+ * @param type the table meta type.
+ * @return the table value.
+ */
+ protected TableValue createTableValue(PersistedTableValue table, TableMetaType type)
+ {
+ TableValueSupport support = new TableValueSupport(type);
+ if(table.getEntries() != null && table.getEntries().isEmpty() == false)
+ {
+ for(PersistedCompositeValue entry : table.getEntries())
+ {
+ support.put(createCompositeValue(entry, type.getRowType()));
+ }
+ }
+ return support;
+ }
+
+ /**
+ * Create array value.
+ *
+ * @param valueElement the persisted array xml value
+ * @param type the array meta type
+ * @return the array value
+ */
+ @SuppressWarnings("unchecked")
+ protected ArrayValue createArrayValue(PersistedArrayValue valueElement, ArrayMetaType type)
+ {
+ int size = valueElement.size();
+ List values = new ArrayList(size);
+ for(PersistedValue elementValue : valueElement.getValues())
+ {
+ if(elementValue instanceof PersistedArrayValue)
+ {
+ values.add(
+ recreateArrayValue((PersistedArrayValue) elementValue, type.getElementType()));
+ }
+ else
+ {
+ MetaValue value = createMetaValue(elementValue, type.getElementType());
+ values.add(value);
+ }
+ }
+ return new ArrayValueSupport(type, values.toArray());
+ }
+
+ /**
+ * Recreate the array values.
+ *
+ * @param valueElement the persisted xml value
+ * @param type the element type
+ * @return the recreated array
+ */
+ @SuppressWarnings("unchecked")
+ protected Object recreateArrayValue(PersistedArrayValue valueElement, MetaType type)
+ {
+ List values = new ArrayList(valueElement.size());
+ for(PersistedValue elementValue : valueElement.getValues())
+ {
+ if(elementValue instanceof PersistedArrayValue)
+ {
+ values.add(
+ recreateArrayValue((PersistedArrayValue) elementValue, type));
+ }
+ else
+ {
+ MetaValue value = createMetaValue(elementValue, type);
+ values.add(value);
+ }
+ }
+ return values.toArray();
+ }
+
+ /**
+ * Convert simple types.
+ *
+ * @param clazz a primitive serializable class.
+ * @param value the String
+ * @return the converted object, null in case of any failure.
+ */
+ public Serializable convert2Type(String className, String value)
+ {
+ if(value == null)
+ return null;
+
+ Class<?> clazz = simpleTypes.get(className);
+ if(clazz == null)
+ throw new IllegalStateException("Cannot find simple type entry for "+ value + " and class "+ className);
+
+ try
+ {
+ return (Serializable) ValueConvertor.convertValue(clazz, value);
+ }
+ catch(Throwable t)
+ {
+ log.debug("could convert "+ value +" to " + clazz.getName());
+ return null;
+ }
+ }
+
+}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectUpdateHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectUpdateHandler.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectUpdateHandler.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -21,133 +21,39 @@
*/
package org.jboss.system.server.profileservice.persistence;
-import java.io.Serializable;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.logging.Logger;
import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.annotation.ViewUse;
import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.EnumMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.Name;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.types.TableMetaType;
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.ArrayValueSupport;
-import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.CollectionValueSupport;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.CompositeValueSupport;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.EnumValueSupport;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.metatype.api.values.TableValueSupport;
-import org.jboss.metatype.plugins.types.StringName;
-import org.jboss.reflect.plugins.ValueConvertor;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedArrayValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedEnumValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedSimpleValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
-
/**
* Handler for merging the persisted information with a ManagedObject.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class ManagedObjectUpdateHandler
+ at Deprecated
+public class ManagedObjectUpdateHandler extends ManagedObjectRecreationHandler
{
+
+ /** The attachment property populator. */
+ private AttachmentPropertyPopulator populator;
- /** The managed object factory. */
- ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
-
- /** The meta value factory. */
- MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
-
- /** The simple types. */
- private static final Map<String, Class<? extends Serializable>> simpleTypes = new HashMap<String, Class<? extends Serializable>>();
-
/** The logger. */
private final static Logger log = Logger.getLogger(ManagedObjectUpdateHandler.class);
-
- static
+
+ public ManagedObjectUpdateHandler()
{
- // Fill simple types map.
- simpleTypes.put(BigDecimal.class.getName(), BigDecimal.class);
- simpleTypes.put(BigInteger.class.getName(), BigInteger.class);
- simpleTypes.put(Boolean.class.getName(), Boolean.class);
- simpleTypes.put(Byte.class.getName(), Byte.class);
- simpleTypes.put(Character.class.getName(), Character.class);
- simpleTypes.put(Date.class.getName(), Date.class);
- simpleTypes.put(Double.class.getName(), Double.class);
- simpleTypes.put(Float.class.getName(), Float.class);
- simpleTypes.put(Integer.class.getName(), Integer.class);
- simpleTypes.put(Long.class.getName(), Long.class);
- simpleTypes.put(Short.class.getName(), Short.class);
- simpleTypes.put(String.class.getName(), String.class);
- simpleTypes.put(Name.class.getName(), Name.class);
+ super();
+ this.populator = new AttachmentPropertyPopulator(ManagedObjectFactory.getInstance());
}
- /**
- * Process a ManagedObject.
- *
- * @param moElement the persisted xml meta data.
- * @param mo the managed object
- * @return the attachment meta data.
- */
- public Object processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
+ public ManagedObjectUpdateHandler(MOCreatorPlugin plugin)
{
- if(moElement == null)
- throw new IllegalArgumentException("Null rootElement.");
- if(mo == null)
- throw new IllegalArgumentException("null managedObject");
-
- Object attachment = mo.getAttachment();
-
- // Get the xml to see what we need to merge
- Set<String> propertyNames = moElement.keySet();
- for(String propertyName : propertyNames)
- {
- ManagedProperty property = mo.getProperty(propertyName);
- if(property == null)
- throw new IllegalStateException("unable to find propery: "+ property);
-
- // Skip statistic - although they should not be persisted anyway
- if(property.hasViewUse(ViewUse.STATISTIC))
- continue;
-
- // getProperty
- PersistedProperty propertyElement = moElement.get(propertyName);
- processManagedProperty(propertyElement, propertyName, property, attachment);
- }
- return attachment;
+ super(plugin);
+ this.populator = new AttachmentPropertyPopulator(plugin.getMOF());
}
/**
@@ -158,376 +64,31 @@
* @param property the managed property.
* @param attachment the managed object attachment.
*/
+ @Override
protected void processManagedProperty(PersistedProperty propertyElement, String name, ManagedProperty property, Object attachment)
{
boolean trace = log.isTraceEnabled();
PropertyInfo propertyInfo = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
-
+
// Skip not readable properties
- if(propertyInfo != null && propertyInfo.isReadable() == false)
+ if (propertyInfo != null && propertyInfo.isReadable() == false)
{
- if(trace)
- log.trace("property "+ name + "is not readable");
+ if (trace)
+ log.trace("property " + name + "is not readable");
return;
}
-
- // Get MetaValue
- MetaValue value = property.getValue();
- if(value == null)
- {
- value = createEmptyMetaValue(property.getMetaType());
- }
-
- // Get the xml value
- PersistedValue persistedValue = propertyElement.getValue();
- // Skip null values
- if(value != null && persistedValue != null)
- {
- // Process the meta value.
- MetaValue merged = processMetaValue(persistedValue, value);
- // If merged != null
- if(merged != null)
- {
- // TODO Can this be null anyway ?
- if(propertyInfo == null)
- return;
- // throw new IllegalStateException("null propertyInfo");
-
- // Skip not writable properties
- if(propertyInfo.isWritable() == false)
- {
- if(trace)
- log.trace("property "+ name + "is not writable");
- return;
- }
-
- // FIXME Ignore some metaTypes for now
- MetaType metaType = merged.getMetaType();
- if( ! metaType.isCollection()
- && ! metaType.isArray()
- && ! metaType.isTable() )
- {
-
- try
- {
- // set the value Field
- property.setField(Fields.VALUE, merged);
-
- // FIXME skip CompositeValueInvocationHandler
- if( metaType.isComposite() )
- {
- // unwrap
- Object unwrapped = metaValueFactory.unwrap(merged, propertyInfo.getType());
- if(Proxy.isProxyClass(unwrapped.getClass()))
- return;
- }
-
- // Set value
- InstanceClassFactory icf = managedObjectFactory.getInstanceClassFactory(attachment.getClass(), null);
- BeanInfo beanInfo = propertyInfo.getBeanInfo();
- icf.setValue(beanInfo, property, attachment, merged);
- }
- catch(Throwable t)
- {
- log.debug("failed to set value to property: "+ propertyInfo, t);
- }
- }
- }
- }
- else
- {
- return;
- }
- }
-
- /**
- * Process a MetaValue.
- *
- * @param valueElement the persisted xml meta data.
- * @param value the meta value.
- * @return a meta value.
- */
- protected MetaValue processMetaValue(PersistedValue valueElement, MetaValue value)
- {
- MetaType metaType = value.getMetaType();
-
- MetaValue metaValue = null;
- if(metaType.isSimple())
- {
- metaValue = processSimpleValue(
- (PersistedSimpleValue) valueElement,
- (SimpleValue) value);
- }
- else if(metaType.isEnum())
- {
- metaValue = processEnumValue(
- (PersistedEnumValue) valueElement,
- (EnumValue) value);
- }
- else if(metaType.isCollection())
- {
- metaValue = processCollectionValue(
- (PersistedCollectionValue) valueElement,
- (CollectionValue) value);
- }
- else if(metaType.isGeneric())
- {
- metaValue = processGenericValue(
- (PersistedGenericValue) valueElement,
- (GenericValue) value);
- }
- else if(metaType.isComposite())
- {
- metaValue = processCompositeValue(
- (PersistedCompositeValue) valueElement,
- (CompositeValue) value);
- }
- else if(metaType.isTable())
- {
- // FIXME process Table
- }
- else if(metaType.isArray())
- {
- metaValue = processArrayValue(
- (PersistedArrayValue) valueElement,
- (ArrayValue) value);
- }
- else
- {
- throw new IllegalStateException("unknown metaType");
- }
- return metaValue;
- }
-
- /**
- * Process an Enum value.
- *
- * @param enumElement the persisted xml meta data.
- * @param value the enum value.
- * @return a enum value.
- */
- protected EnumValue processEnumValue(PersistedEnumValue enumElement, EnumValue value)
- {
- return new EnumValueSupport(value.getMetaType(), enumElement.getValue());
- }
-
- /**
- * Process a collection.
- * TODO - support merging of collections.
- *
- * @param collection the persisted xml meta data.
- * @param value the collection value.
- * @return a collection value.
- */
- protected CollectionValue processCollectionValue(PersistedCollectionValue collection, CollectionValue value)
- {
- if(collection.size() == 0)
- return value;
+ // Recreate the MO from xml
+ super.processManagedProperty(propertyElement, name, property, attachment);
- // FIXME merge collections
- if(collection.size() != value.getSize())
- {
- log.warn("unable to merge collection: " + value);
- return value;
- }
-
- ArrayList<MetaValue> elementList = new ArrayList<MetaValue>();
- Iterator<PersistedValue> i = collection.getValues().iterator();
- for(MetaValue item : value)
- {
- MetaValue newValue = processMetaValue(i.next(), item);
- if(newValue != null)
- {
- elementList.add(newValue);
- }
- }
- return new CollectionValueSupport(value.getMetaType(), elementList.toArray(new MetaValue[elementList.size()]));
- }
-
- /**
- * Process a GenericValue.
- *
- * @param genericElement the persisted xml meta data.
- * @param value the generic value.
- * @return a generic value.
- */
- protected MetaValue processGenericValue(PersistedGenericValue genericElement, GenericValue value)
- {
- PersistedManagedObject po = genericElement.getManagedObject();
- if(po == null || value.getValue() == null)
- return value;
-
- if(value.getValue() instanceof ManagedObject)
- {
- ManagedObject mo = (ManagedObject) value.getValue();
- processManagedObject(po, mo);
-
- return value;
- }
- else
- {
- throw new IllegalStateException("The value of GenericValue must be a ManagedObject: " + value);
- }
- }
-
- /**
- * Process composite value.
- *
- * @param composite the persisted xml meta data.
- * @param value the composite value.
- * @return a composite value.
- */
- protected CompositeValue processCompositeValue(PersistedCompositeValue composite, CompositeValue value)
- {
- CompositeMetaType metaType = value.getMetaType();
- Map<String, MetaValue> values = new HashMap<String, MetaValue>();
-
- for(String key : composite.keySet())
- {
- MetaValue metaValue = value.get(key);
- if(metaValue == null)
- {
- metaValue = createEmptyMetaValue(metaType.getType(key));
- }
- PersistedValue persistedValue = composite.get(key);
-
- metaValue = processMetaValue(persistedValue, metaValue);
-
- values.put(key, metaValue);
- }
- return new CompositeValueSupport(metaType, values);
- }
-
- /**
- * process an arrayValue.
- * FIXME - support merging of arrays.
- *
- * @param array the persisted xml meta data.
- * @param value the array value.
- * @return a array value.
- */
- protected ArrayValue processArrayValue(PersistedArrayValue array, ArrayValue value)
- {
- // FIXME
- if(array.size() != value.getLength())
- {
- log.debug("cannot merge array: " + value);
- return null;
- }
-
- ArrayList<MetaValue> arrayList = new ArrayList<MetaValue>();
- for(int i = 0; i < value.getLength(); i++)
- {
- PersistedValue persisted = array.getValue(i);
- MetaValue restored = processMetaValue(persisted, (MetaValue) value.getValue(i));
- if(restored != null)
- arrayList.add(restored);
- }
-
- return new ArrayValueSupport(value.getMetaType(), arrayList.toArray(new MetaValue[arrayList.size()]));
- }
-
- /**
- * Process simple value.
- *
- * @param valueElement the persisted xml meta data.
- * @param value the simple value.
- * @return a simple value.
- */
- protected SimpleValue processSimpleValue(PersistedSimpleValue valueElement, SimpleValue value)
- {
- SimpleMetaType metaType = value.getMetaType();
- String elementValue = valueElement.getValue();
-
- Serializable converted = null;
- if(elementValue != null)
- {
- if(metaType.equals(SimpleMetaType.STRING))
- {
- converted = (String) elementValue;
- }
- else if (metaType.equals(SimpleMetaType.NAMEDOBJECT))
- {
- converted = new StringName(elementValue);
- }
- else if (metaType.equals(SimpleMetaType.VOID))
- {
- //
- }
- else
- {
- converted = convert2Type(metaType.getTypeName(), elementValue);
- }
- }
- return SimpleValueSupport.wrap(converted);
- }
-
- /**
- * Create a empty meta value, based on a given MetaType.
- *
- * @param metaType the meta type.
- * @return a meta value.
- */
- protected MetaValue createEmptyMetaValue(MetaType metaType)
- {
- MetaValue metaValue = null;
- if(metaType.isSimple())
- {
- metaValue = new SimpleValueSupport((SimpleMetaType) metaType, null);
- }
- else if(metaType.isEnum())
- {
- metaValue = new EnumValueSupport((EnumMetaType) metaType, (String) null);
- }
- else if(metaType.isCollection())
- {
- metaValue = new CollectionValueSupport((CollectionMetaType) metaType);
- }
- else if(metaType.isGeneric())
- {
- // TODO
- }
- else if(metaType.isComposite())
- {
- metaValue = new CompositeValueSupport((CompositeMetaType) metaType);
- }
- else if(metaType.isTable())
- {
- metaValue = new TableValueSupport((TableMetaType) metaType);
- }
- else if(metaType.isArray())
- {
- metaValue = new ArrayValueSupport((ArrayMetaType) metaType);
- }
- return metaValue;
- }
-
- /**
- * Convert simple types.
- *
- * @param clazz a primitive serializable class.
- * @param value the String
- * @return the converted object, null in case of any failure.
- */
- public Serializable convert2Type(String className, String value)
- {
- if(value == null)
- return null;
-
- Class<?> clazz = simpleTypes.get(className);
- if(clazz == null)
- throw new IllegalStateException("Cannot find simple type entry for "+ value + " and class "+ className);
-
try
{
- return (Serializable) ValueConvertor.convertValue(clazz, value);
+ this.populator.processManagedProperty(name, property, attachment);
}
catch(Throwable t)
{
- log.debug("could convert "+ value +" to " + clazz.getName());
- return null;
+ log.debug("Cannot popluate value information of porperty" + property);
}
}
-
+
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -30,9 +30,8 @@
import org.jboss.logging.Logger;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
import org.jboss.metadata.spi.MetaData;
-import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectOverrideHandler;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
/**
@@ -48,10 +47,10 @@
/** The managed prefix. */
public static final String PERSISTED_ATTACHMENT_PREFIX = "PERISTED";
- /** The managed update handler. */
- private ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+ /** The managed object override handler. */
+ private ManagedObjectOverrideHandler overrideHandler = new ManagedObjectOverrideHandler();
- private final ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
+ private final ManagedObjectFactory factory = ManagedObjectFactory.getInstance();
/** The Logger. */
private static final Logger log = Logger.getLogger(ProfileServicePersistenceDeployer.class);
@@ -79,14 +78,20 @@
{
// Get the transient attachment
Object instance = unit.getTransientManagedObjects().getAttachment(attachment);
- // Create the managed object
- ManagedObject mo = factory.initManagedObject(instance, metaData);
- // Update the attachment
- Object o = handler.processManagedObject(persistedManagedObject, mo);
- // Debug
- log.debug("updated attachment with persisted information: " + o);
- // Override
- unit.addAttachment(attachment, o);
+ try
+ {
+ // Create the original
+ ManagedObject original = factory.initManagedObject(instance, metaData);
+ // Update the attachment
+ original = overrideHandler.updateManagedObject(persistedManagedObject, original);
+
+ // Override
+ unit.addAttachment(attachment, original.getAttachment());
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to update the persisted attachment information", e);
+ }
}
}
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedArrayValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedArrayValue.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedArrayValue.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -29,6 +29,6 @@
*/
public class PersistedArrayValue extends PersistedCollectionValue
{
-
+
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -21,7 +21,6 @@
*/
package org.jboss.system.server.profileservice.persistence.xml;
-import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
@@ -33,9 +32,12 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class PersistedCompositeValue extends AbstractMapSupport<PersistedValue> implements PersistedValue
+public class PersistedCompositeValue extends AbstractElement implements PersistedValue
{
+ /** The values */
+ List<PersistedValue> values;
+
@XmlElements( value = {
@XmlElement(name = "simple", type = PersistedSimpleValue.class),
@XmlElement(name = "enum", type = PersistedEnumValue.class),
@@ -47,17 +49,17 @@
})
public List<PersistedValue> getValues()
{
- return new ArrayList<PersistedValue>(super.values());
+ return this.values;
}
public void setValues(List<PersistedValue> values)
{
- super.createMap(values);
+ this.values = values;
}
protected void toString(StringBuilder builder)
{
- builder.append(", keySet = ").append(keySet());
+ builder.append(", keySet = ").append(this.values);
}
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedEnumValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedEnumValue.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedEnumValue.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -30,6 +30,16 @@
public class PersistedEnumValue extends PersistedSimpleValue
{
+ public PersistedEnumValue()
+ {
+ super();
+ }
+
+ public PersistedEnumValue(String name)
+ {
+ super(name);
+ }
+
@Override
protected void toString(StringBuilder builder)
{
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -23,16 +23,13 @@
import static org.jboss.system.server.profileservice.persistence.xml.PersistenceConstants.MANAGED_OBJECT_ELEMENT_NAME;
-import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.XmlNs;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
import org.jboss.xb.annotations.JBossXmlSchema;
@@ -42,19 +39,16 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
- at JBossXmlSchema(
- xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") },
- ignoreUnresolvedFieldOrClass=false,
- namespace = PersistenceConstants.NAMESPACE_1_0,
- elementFormDefault = XmlNsForm.QUALIFIED,
- normalizeSpace=true)
+ at JBossXmlSchema(namespace = PersistenceConstants.NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name = MANAGED_OBJECT_ELEMENT_NAME)
- at XmlType(name = "managedObjectType", namespace = PersistenceConstants.NAMESPACE_1_0)
-public class PersistedManagedObject extends AbstractMapSupport<PersistedProperty>
+public class PersistedManagedObject extends AbstractElement
{
- /** The original name. */
- private String originalName;
+ /** The template name. */
+ private String templateName;
+ /** The properties */
+ private List<PersistedProperty> properties;
+
public PersistedManagedObject()
{
//
@@ -70,32 +64,32 @@
super(name, className);
}
- @XmlAttribute(name = "original-name")
- public String getOriginalName()
+ @XmlAttribute(name = "template-name")
+ public String getTemplateName()
{
- return originalName;
+ return templateName;
}
- public void setOriginalName(String originalName)
+ public void setTemplateName(String templateName)
{
- this.originalName = originalName;
+ this.templateName = templateName;
}
@XmlElementWrapper(name="properties")
@XmlElement(name = "property")
public List<PersistedProperty> getProperties()
{
- return new ArrayList(super.values());
+ return this.properties;
}
public void setProperties(List<PersistedProperty> properties)
{
- super.createMap(properties);
+ this.properties = properties;
}
protected void toString(StringBuilder builder)
{
- builder.append(", original-name = ").append(getOriginalName());
+ builder.append(", template-name = ").append(getTemplateName());
}
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedTableValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedTableValue.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedTableValue.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -21,8 +21,12 @@
*/
package org.jboss.system.server.profileservice.persistence.xml;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
/**
- * TODO The persisted TableValue.
+ * The persisted TableValue.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
@@ -30,5 +34,18 @@
public class PersistedTableValue extends AbstractElement implements PersistedValue
{
+ /** The entries. */
+ List<PersistedCompositeValue> entries;
+
+ @XmlElement(name = "entry")
+ public List<PersistedCompositeValue> getEntries()
+ {
+ return entries;
+ }
+
+ public void setEntries(List<PersistedCompositeValue> entries)
+ {
+ this.entries = entries;
+ }
+
}
-
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -31,7 +31,7 @@
{
/** The xml namespace. */
- public static final String NAMESPACE_1_0 = "urn:jboss:managed-persistence:1.0";
+ public static final String NAMESPACE_1_0 = "urn:org:jboss:profileservice:persistence:managed-object:1.0";
/** The managed-object name. */
public static final String MANAGED_OBJECT_ELEMENT_NAME = "managed-object";
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
- at XmlSchema(namespace = PersistenceConstants.NAMESPACE_1_0,
+ at XmlSchema(namespace = "urn:org:jboss:profileservice:persistence:managed-object:1.0",
elementFormDefault = XmlNsForm.QUALIFIED,
xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") }
)
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java 2009-02-10 08:22:31 UTC (rev 84036)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -24,35 +24,42 @@
import java.io.File;
import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.namespace.QName;
import org.jboss.logging.Logger;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
+import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceConstants;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
/**
* A basic JAXB attachment Serializer.
*
+ * It uses JAXB for marshalling the meta data and JBoss XB to unmarshal.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
public class JAXBAttachmentSerializer extends AbstractFileAttachmentsSerializer
{
- /** The logger */
+ /** The logger. */
private static final Logger log = Logger.getLogger(JAXBAttachmentSerializer.class);
- /** The QNAME for the root element */
- private static final QName ROOT_NAME = new QName("attachment");
-
/** The attachment suffix. */
private static final String ATTACHMENT_SUFFIX = ".attachment.xml";
+ /** The default schema resolver. */
+ private static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+ static
+ {
+ resolver.addClassBinding("urn:org:jboss:profileservice:attachments:1.0", RepositoryAttachmentMetaData.class);
+ resolver.addClassBinding(PersistenceConstants.NAMESPACE_1_0, PersistedManagedObject.class);
+ }
+
public JAXBAttachmentSerializer(File dir)
{
super(dir);
@@ -61,18 +68,14 @@
@SuppressWarnings("unchecked")
protected <T> T loadAttachment(File attachmentsStore, Class<T> expected) throws Exception
{
- JAXBContext ctx = JAXBContext.newInstance(expected);
- Unmarshaller unmarshaller = ctx.createUnmarshaller();
- // FIXME this is a hack
- if(PersistedManagedObject.class.getName().equals(expected.getName()))
- {
- hack(unmarshaller);
- }
- return (T) unmarshaller.unmarshal(attachmentsStore);
+ // JBoss XB
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ return (T) unmarshaller.unmarshal(attachmentsStore.toURL().openStream(), resolver);
}
protected void saveAttachment(File attachmentsStore, Object attachment) throws Exception
{
+ // JAXB
log.trace("saveAttachments, attachmentsStore="+attachmentsStore+ ", attachment="+attachment);
JAXBContext ctx = JAXBContext.newInstance(attachment.getClass());
Marshaller marshaller = ctx.createMarshaller();
@@ -80,11 +83,6 @@
marshaller.marshal(attachment, attachmentsStore);
}
- protected static <T> JAXBElement<T> createRootElement(Class<T> expected, Object o)
- {
- return new JAXBElement<T>(ROOT_NAME, expected, (T) o);
- }
-
@Override
protected File getAttachmentPath(String baseName)
{
@@ -92,36 +90,4 @@
return new File(getAttachmentsStoreDir(), vfsPath);
}
- private void hack(Unmarshaller unmarshaller)
- {
- unmarshaller.setListener(new PeristedManagedObjectHandler());
- }
-
- /**
- * Hack handler for JAXB.
- */
- private static class PeristedManagedObjectHandler extends Unmarshaller.Listener
- {
- @Override
- public void afterUnmarshal(Object target, Object parent)
- {
- if(parent instanceof PersistedManagedObject)
- {
- if(target instanceof PersistedProperty)
- {
- PersistedProperty p = (PersistedProperty) target;
- ((PersistedManagedObject) parent).put(p.getName(), p);
- }
- }
- else if(parent instanceof PersistedCompositeValue)
- {
- if(target instanceof PersistedValue)
- {
- PersistedValue v = (PersistedValue) target;
- ((PersistedCompositeValue) parent).put(v.getName(), v);
- }
- }
- }
- }
-
}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/CollectionMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/CollectionMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/CollectionMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.support;
+
+import java.util.List;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class CollectionMetaData
+{
+
+ List<String> collection;
+
+ @ManagementProperty
+ public List<String> getCollection()
+ {
+ return collection;
+ }
+
+ public void setCollection(List<String> collection)
+ {
+ this.collection = collection;
+ }
+
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/NestedTestMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/NestedTestMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/NestedTestMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,53 @@
+/*
+ * 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.test.server.profileservice.persistence.support;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 82920 $
+ */
+ at ManagementObject
+public class NestedTestMetaData implements Serializable
+{
+
+ List<TestMetaData> deployments;
+
+ @ManagementProperty(managed = true)
+ public List<TestMetaData> getDeployments()
+ {
+ return deployments;
+ }
+
+ public void setDeployments(List<TestMetaData> deployments)
+ {
+ this.deployments = deployments;
+ }
+
+
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/PrimitiveMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/PrimitiveMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/PrimitiveMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,78 @@
+/*
+ * 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.test.server.profileservice.persistence.support;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 82920 $
+ */
+ at ManagementObject
+public class PrimitiveMetaData implements Serializable
+{
+ /** The name */
+ String name;
+
+ /** The optional name */
+ String optionalName;
+
+ /** The integer */
+ int integer;
+
+ @ManagementProperty
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @ManagementProperty
+ public int getInteger()
+ {
+ return integer;
+ }
+
+ public void setInteger(int integer)
+ {
+ this.integer = integer;
+ }
+
+ @ManagementProperty
+ public String getOptionalName()
+ {
+ return optionalName;
+ }
+
+ public void setOptionalName(String optionalName)
+ {
+ this.optionalName = optionalName;
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleArrayMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleArrayMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleArrayMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.support;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class SimpleArrayMetaData
+{
+ /** one dimension */
+ char[] test1D;
+
+ /** two dimensions */
+ char[][] test2D;
+
+ /** three dimensions */
+ char[][][] test3D;
+
+ @ManagementProperty
+ public char[] getTest1D()
+ {
+ return test1D;
+ }
+
+ public void setTest1D(char[] test1D)
+ {
+ this.test1D = test1D;
+ }
+
+ @ManagementProperty
+ public char[][] getTest2D()
+ {
+ return test2D;
+ }
+
+ public void setTest2D(char[][] test2D)
+ {
+ this.test2D = test2D;
+ }
+
+ @ManagementProperty
+ public char[][][] getTest3D()
+ {
+ return test3D;
+ }
+
+ public void setTest3D(char[][][] test3D)
+ {
+ this.test3D = test3D;
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleStringMapMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleStringMapMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleStringMapMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.support;
+
+import java.util.Map;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class SimpleStringMapMetaData
+{
+ Map<String, String> map;
+
+ @ManagementProperty
+ public Map<String, String> getMap()
+ {
+ return map;
+ }
+
+ public void setMap(Map<String, String> map)
+ {
+ this.map = map;
+ }
+
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleTableMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleTableMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/SimpleTableMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.support;
+
+import java.util.Map;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class SimpleTableMetaData
+{
+
+ Map<Integer, String> map;
+
+ @ManagementProperty
+ public Map<Integer, String> getMap()
+ {
+ return map;
+ }
+
+ public void setMap(Map<Integer, String> map)
+ {
+ this.map = map;
+ }
+
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/TestMetaData.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/TestMetaData.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/support/TestMetaData.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,134 @@
+/*
+ * 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.test.server.profileservice.persistence.support;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 82920 $
+ */
+ at ManagementObject
+public class TestMetaData implements Serializable
+{
+
+ String name;
+
+ /** The primitive */
+ PrimitiveMetaData primitive;
+
+ /** A primitive List */
+ List<String> list;
+
+ Map<String, String> testMap;
+
+ Character[] charArray;
+
+ char[][] test2dChar;
+
+ Map<Integer, String> table;
+
+ @ManagementProperty
+ @ManagementObjectID
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @ManagementProperty
+ public PrimitiveMetaData getPrimitive()
+ {
+ return primitive;
+ }
+
+ public void setPrimitive(PrimitiveMetaData primitive)
+ {
+ this.primitive = primitive;
+ }
+
+ @ManagementProperty
+ public List<String> getList()
+ {
+ return list;
+ }
+
+ public void setList(List<String> list)
+ {
+ this.list = list;
+ }
+
+ @ManagementProperty
+ public Map<String, String> getTestMap()
+ {
+ return testMap;
+ }
+
+ public void setTestMap(Map<String, String> testMap)
+ {
+ this.testMap = testMap;
+ }
+
+ @ManagementProperty
+ public Character[] getCharArray()
+ {
+ return charArray;
+ }
+
+ public void setCharArray(Character[] charArray)
+ {
+ this.charArray = charArray;
+ }
+
+ @ManagementProperty
+ public char[][] getTest2dChar()
+ {
+ return test2dChar;
+ }
+
+ public void setTest2dChar(char[][] test2dChar)
+ {
+ this.test2dChar = test2dChar;
+ }
+
+ @ManagementProperty
+ public Map<Integer, String> getTable()
+ {
+ return table;
+ }
+
+ public void setTable(Map<Integer, String> table)
+ {
+ this.table = table;
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,181 @@
+/*
+ * 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.test.server.profileservice.persistence.test;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.repository.AbstractFileAttachmentsSerializer;
+import org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer;
+import org.jboss.test.BaseTestCase;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 82920 $
+ */
+public abstract class AbstractPersistenceFormatTest extends BaseTestCase
+{
+
+ /** The managed object factory */
+ private ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+
+ /** The meta value factory */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+
+ /** The meta type factory */
+ private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
+
+ protected static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+ static
+ {
+ resolver.addClassBinding("urn:org:jboss:profileservice:persistence:managed-object:1.0", PersistedManagedObject.class);
+ }
+
+ public AbstractPersistenceFormatTest(String name)
+ {
+ super(name);
+ }
+
+ protected ManagedObjectFactory getMOF()
+ {
+ return this.managedObjectFactory;
+ }
+
+ protected MetaValueFactory getMVF()
+ {
+ return this.metaValueFactory;
+ }
+
+ protected MetaTypeFactory getMTF()
+ {
+ return this.metaTypeFactory;
+ }
+
+ protected ManagedObject initManagedObject(Object o)
+ {
+ return getMOF().initManagedObject(o, null);
+ }
+
+ protected AbstractFileAttachmentsSerializer getAttachmentSerializer() throws Exception
+ {
+ return getAttachmentSerializer(false);
+ }
+
+ protected AbstractFileAttachmentsSerializer getAttachmentSerializer(boolean logToSystemOut) throws Exception
+ {
+ File tempFile = File.createTempFile(getName(), null);
+ return createSerializer(tempFile, logToSystemOut);
+ }
+
+ /**
+ * Create the attachment Serializer.
+ * Use a tempFile for storing the Xml.
+ *
+ * @param tempFile the temp File
+ * @return a AttachmentSerializer.
+ * @throws Exception
+ */
+ protected AbstractFileAttachmentsSerializer createSerializer(File tempFile) throws Exception
+ {
+ return createSerializer(tempFile, false);
+ }
+
+ protected AbstractFileAttachmentsSerializer createSerializer(final File tempFile, final boolean logToSystemOut) throws Exception
+ {
+ return new TempAttachmentSerializer(tempFile);
+ }
+
+ private class TempAttachmentSerializer extends JAXBAttachmentSerializer
+ {
+ public TempAttachmentSerializer(File tempFile)
+ {
+ super(tempFile);
+ }
+
+// @Override
+// protected <T> T loadAttachment(File attachmentsStore, Class<T> expected) throws Exception
+// {
+// Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+// JBossXBBuilder builder = new JBossXBBuilder();
+// SchemaBinding binding = builder.build(expected);
+// return (T) u.unmarshal(attachmentsStore.getAbsolutePath(), binding);
+// }
+
+ @Override
+ protected void saveAttachment(File attachmentsStore, Object attachment) throws Exception
+ {
+ log.trace("saveAttachments, attachmentsStore="+attachmentsStore+ ", attachment="+attachment);
+ JAXBContext ctx = JAXBContext.newInstance(attachment.getClass());
+ Marshaller marshaller = ctx.createMarshaller();
+ marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
+ marshaller.marshal(attachment, attachmentsStore);
+ marshaller.marshal(attachment, System.out);
+ }
+
+ @Override
+ protected File getAttachmentPath(String baseName)
+ {
+ // Return the temp file
+ return getAttachmentsStoreDir();
+ }
+ }
+
+ protected PersistedManagedObject restore(ManagedObject mo) throws Exception
+ {
+ PersistedManagedObject moElement = new PersistedManagedObject();
+
+ ManagedObjectPeristenceHandler persistence = new ManagedObjectPeristenceHandler();
+ persistence.processManagedObject(moElement, mo);
+
+ File file = File.createTempFile("test", null);
+ serialize(moElement, file);
+ return deserialize(file);
+ }
+
+ protected void serialize(PersistedManagedObject moElement, File file) throws Exception
+ {
+ JAXBContext ctx = JAXBContext.newInstance(PersistedManagedObject.class);
+ Marshaller marshaller = ctx.createMarshaller();
+ marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
+ marshaller.marshal(moElement, file);
+ marshaller.marshal(moElement, System.out);
+ }
+
+ protected PersistedManagedObject deserialize(File file) throws Exception
+ {
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ return (PersistedManagedObject) unmarshaller.unmarshal(file.toURL().openStream(), resolver);
+ }
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/ArrayValueUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/ArrayValueUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/ArrayValueUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.test;
+
+import java.util.Arrays;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectRecreationHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.server.profileservice.persistence.support.SimpleArrayMetaData;
+
+/**
+ * Simple attachment persistence test for array values.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ArrayValueUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public ArrayValueUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleArray() throws Exception
+ {
+ ManagedObject mo = initMO();
+ PersistedManagedObject moElement = restore(mo);
+
+ assertNotNull(moElement);
+
+ ManagedObjectRecreationHandler handler = new ManagedObjectRecreationHandler();
+ ManagedObject restored = handler.createManagedObject(moElement);
+
+ assertNotNull(restored.getProperties());
+ assertEquals(3, restored.getProperties().size());
+
+ // Test 1D
+ ArrayValue test1D = (ArrayValue) restored.getProperty("test1D").getValue();
+ assertNotNull(test1D);
+
+ char[] unwrapped1D = (char[]) getMVF().unwrap(test1D);
+ assertNotNull(unwrapped1D);
+ assertTrue(Arrays.equals(init1D(), unwrapped1D));
+
+ // Test 2D
+ ArrayValue test2D = (ArrayValue) restored.getProperty("test2D").getValue();
+ assertNotNull(test2D);
+ assertEquals(2, test2D.getMetaType().getDimension());
+
+ char[][] unwrapped2D = (char[][]) getMVF().unwrap(test2D);
+ assertNotNull(unwrapped2D);
+ assertEquals(2, unwrapped2D.length);
+ assertEquals('a', unwrapped2D[0][0]);
+ assertEquals('f', unwrapped2D[1][1]);
+
+ // Test 3D
+ ArrayValue test3D = (ArrayValue) restored.getProperty("test3D").getValue();
+ assertNotNull(test3D);
+ assertEquals(3, test3D.getMetaType().getDimension());
+
+ char[][][] unwrapped3D = (char[][][]) getMVF().unwrap(test3D);
+ assertNotNull(unwrapped3D);
+
+ assertEquals(3, unwrapped3D[0].length);
+ assertEquals(3, unwrapped3D[0][0].length);
+ assertEquals(2, unwrapped3D[0][1].length);
+ assertEquals(2, unwrapped3D[0][2].length);
+ assertEquals('g', unwrapped3D[0][2][0]);
+ assertEquals('h', unwrapped3D[0][2][1]);
+ }
+
+ protected ManagedObject initMO()
+ {
+ SimpleArrayMetaData instance = new SimpleArrayMetaData();
+ instance.setTest1D(init1D());
+ instance.setTest2D(init2D());
+ instance.setTest3D(init3D());
+
+ return getMOF().initManagedObject(instance, null);
+ }
+
+ protected char[] init1D()
+ {
+ return new char[] {'a', 'b', 'c'};
+ }
+
+ protected char[][] init2D()
+ {
+ return new char[][] {{'a', 'b', 'c'}, { 'e', 'f'}};
+ }
+
+ protected char[][][] init3D()
+ {
+ return new char[][][] {{{'a', 'b', 'c'}, { 'e', 'f'}, {'g', 'h'}}};
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/BasicPersistenceFormatUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/BasicPersistenceFormatUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/BasicPersistenceFormatUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,267 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.server.profileservice.persistence.support.PrimitiveMetaData;
+import org.jboss.test.server.profileservice.persistence.support.TestMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class BasicPersistenceFormatUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public BasicPersistenceFormatUnitTestCase(String name)
+ {
+ // FIXME SimplePersistenceFormatUnitTestCase constructor
+ super(name);
+ }
+ public void testPrimitive() throws Exception
+ {
+ // Create initial model
+ ManagedObject mo = createPrimitiveMO();
+ assertNotNull(mo);
+
+ ManagedProperty p = mo.getProperty("name");
+ assertNotNull(p);
+ p.setValue(SimpleValueSupport.wrap("newName"));
+
+ p = mo.getProperty("integer");
+ p.setValue(SimpleValueSupport.wrap(111));
+
+ mo.getProperty("optionalName").setValue(SimpleValueSupport.wrap("optional"));
+
+ // Assert the restored information
+ PersistedManagedObject restored = restore(mo);
+ assertNotNull(restored);
+
+ ManagedObjectUpdateHandler merger = new ManagedObjectUpdateHandler();
+ // init again;
+ mo = createPrimitiveMO();
+
+ assertEquals("testName", getMVF().unwrap(mo.getProperty("name").getValue()));
+
+ merger.processManagedObject(restored, mo);
+
+ assertEquals("newName", getMVF().unwrap(mo.getProperty("name").getValue()));
+ assertEquals(111, getMVF().unwrap(mo.getProperty("integer").getValue()));
+ assertEquals("optional", ((SimpleValue) mo.getProperty("optionalName").getValue()).getValue());
+
+ }
+
+ public void testMetaDataPrimitive() throws Exception
+ {
+ ManagedObject mo = createTestMetaDataMO();
+ assertNotNull(mo);
+ ManagedProperty p = mo.getProperty("primitive");
+ assertNotNull(p);
+
+ CompositeValue nested = (CompositeValue) p.getValue();
+ MetaValue name = nested.get("name");
+ assertNotNull(name);
+ MetaValue integer = nested.get("integer");
+ assertNotNull(integer);
+
+ // Change values
+ Map<String, MetaValue> changedMap = new HashMap<String, MetaValue>();
+ changedMap.put("name", new SimpleValueSupport(
+ (SimpleMetaType) name.getMetaType(), "newName"));
+ changedMap.put("integer", new SimpleValueSupport(
+ (SimpleMetaType) integer.getMetaType(), 111));
+
+ // Set new values
+ p.setValue(
+ new CompositeValueSupport(nested.getMetaType(), changedMap)
+ );
+
+ // Save and restore
+ PersistedManagedObject restored = restore(mo);
+ assertNotNull(restored);
+
+ // Create again
+ mo = createTestMetaDataMO();
+
+ // Merge
+ ManagedObjectUpdateHandler merger = new ManagedObjectUpdateHandler();
+ merger.processManagedObject(restored, mo);
+
+ p = mo.getProperty("primitive");
+ nested = (CompositeValue) p.getValue();
+ name = nested.get("name");
+ assertNotNull(name);
+ integer = nested.get("integer");
+ assertNotNull(integer);
+
+ //
+ assertEquals(111, ((SimpleValue) integer).getValue());
+ assertEquals("newName", ((SimpleValue) name).getValue());
+ }
+
+
+ public void testMetaDataMap() throws Exception
+ {
+ ManagedObject mo = createTestMetaDataMO();
+ assertNotNull(mo);
+
+ ManagedProperty p = mo.getProperty("testMap");
+ assertNotNull(p);
+
+ MapCompositeValueSupport composite = (MapCompositeValueSupport) p.getValue();
+ assertNotNull(composite);
+
+ SimpleValue v = (SimpleValue) composite.get("testString2");
+ assertNotNull(v);
+
+ composite.put("testString2", SimpleValueSupport.wrap("changedString"));
+
+ PersistedManagedObject restored = restore(mo);
+ assertNotNull(restored);
+
+ mo = createTestMetaDataMO();
+
+ ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+ mo = handler.createManagedObject(restored);
+
+ p = mo.getProperty("testMap");
+ assertNotNull(p);
+
+ CompositeValue changedComposite = (CompositeValue) p.getValue();
+ assertNotNull(changedComposite);
+
+ v = (SimpleValue) changedComposite.get("testString2");
+ assertEquals("changedString", v.getValue());
+ }
+
+ public void testPrimitiveArray() throws Exception
+ {
+ ManagedObject mo = createTestMetaDataMO();
+ assertNotNull(mo);
+
+ ManagedProperty p = mo.getProperty("charArray");
+ assertNotNull(p);
+
+ ArrayValue a = (ArrayValue) p.getValue();
+ assertNotNull(a);
+
+ SimpleValueSupport svs = (SimpleValueSupport) a.getValue(1);
+ assertNotNull(svs);
+ svs.setValue('H');
+
+ PersistedManagedObject restored = restore(mo);
+ assertNotNull(restored);
+
+ //
+ mo = createTestMetaDataMO();
+
+ ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+ handler.processManagedObject(restored, mo);
+
+ p = mo.getProperty("charArray");
+ assertNotNull(p);
+
+ a = (ArrayValue) p.getValue();
+ assertNotNull(a);
+
+ assertEquals('H', ((SimpleValue) a.getValue(1)).getValue());
+ }
+
+ protected ManagedObject createMO(Object o)
+ {
+ return getMOF().initManagedObject(o, null);
+ }
+
+ protected ManagedObject createPrimitiveMO()
+ {
+ PrimitiveMetaData md = createPrimitive();
+ assertNotNull(md);
+ return createMO(md);
+ }
+
+ protected ManagedObject createTestMetaDataMO()
+ {
+ return createMO(createTestMetaData());
+ }
+
+ protected TestMetaData createTestMetaData()
+ {
+ TestMetaData test = new TestMetaData();
+ test.setPrimitive(createPrimitive());
+
+ // Create list
+ List<String> list = new ArrayList<String>();
+
+ list.add("String1");
+ list.add("String2");
+ list.add("String3");
+
+ test.setList(list);
+
+ // Create map
+ Map<String, String> map = new HashMap<String, String>();
+
+ map.put("testString1", "string1");
+ map.put("testString2", "string2");
+ map.put("testString3", "string3");
+
+ test.setTestMap(map);
+
+
+ // Create primitive array
+
+ Character[] array = new Character[3];
+
+ array[0] = 'A';
+ array[1] = 'B';
+ array[2] = 'C';
+
+ test.setCharArray(array);
+
+ return test;
+ }
+
+ protected PrimitiveMetaData createPrimitive()
+ {
+ PrimitiveMetaData primitive = new PrimitiveMetaData();
+ primitive.setInteger(12);
+ primitive.setName("testName");
+ return primitive;
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/CollectionValueUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/CollectionValueUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/CollectionValueUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.server.profileservice.persistence.support.CollectionMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class CollectionValueUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public CollectionValueUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void test() throws Exception
+ {
+ ManagedObject mo = initMO();
+ PersistedManagedObject moElement = restore(mo);
+ assertNotNull(moElement);
+
+ ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+ ManagedObject restored = handler.createManagedObject(moElement);
+ assertNotNull(restored);
+
+ assertNotNull(restored.getProperty("collection"));
+
+ List<String> restoredList = ((CollectionMetaData) restored.getAttachment()).getCollection();
+ assertNotNull(restoredList);
+ assertEquals(3, restoredList.size());
+ assertTrue(restoredList.containsAll(initList()));
+
+ }
+
+
+ protected ManagedObject initMO()
+ {
+ CollectionMetaData instance = new CollectionMetaData();
+ instance.setCollection(initList());
+ return getMOF().initManagedObject(instance, null);
+ }
+
+ protected List<String> initList()
+ {
+ List<String> list = new ArrayList<String>();
+ list.add("string1");
+ list.add("string2");
+ list.add("string3");
+ return list;
+ }
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/MapCompositeUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/MapCompositeUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/MapCompositeUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectRecreationHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.server.profileservice.persistence.support.SimpleStringMapMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MapCompositeUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public MapCompositeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void test() throws Exception
+ {
+ ManagedObject mo = initMO();
+
+ ManagedProperty p = mo.getProperty("map");
+ assertNotNull(p);
+ MapCompositeValueSupport value = (MapCompositeValueSupport) p.getValue();
+ assertNotNull(value);
+ assertNotNull(value.get("test1"));
+ getLog().debug("keys: " + value.getMetaType().itemSet());
+
+ enableTrace("org.jboss.system");
+ PersistedManagedObject moElement = restore(mo);
+ assertNotNull(moElement);
+
+ ManagedObjectRecreationHandler handler = new ManagedObjectRecreationHandler();
+ ManagedObject restored = handler.createManagedObject(moElement);
+ assertNotNull(restored);
+ }
+
+ protected ManagedObject initMO()
+ {
+ SimpleStringMapMetaData instance = new SimpleStringMapMetaData();
+ instance.setMap(initMap());
+
+ return getMOF().initManagedObject(instance, null);
+ }
+
+ protected Map<String, String> initMap()
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ map.put("test1", "one");
+ map.put("test2", "two");
+ map.put("test3", "three");
+ return map;
+ }
+
+}
+
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TableValueUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TableValueUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TableValueUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, 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.test.server.profileservice.persistence.test;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.TableMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectRecreationHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.server.profileservice.persistence.support.SimpleTableMetaData;
+
+
+/**
+ * Simple attachment persistence test for table values.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TableValueUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public TableValueUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleTableValue() throws Exception
+ {
+ ManagedObject mo = initMO();
+ assertNotNull(mo);
+
+ // Restore
+ PersistedManagedObject moElement = restore(mo);
+ assertNotNull(moElement);
+ assertNotNull(moElement.getProperties());
+
+ // Recreate MO
+ ManagedObjectRecreationHandler handler = new ManagedObjectRecreationHandler();
+ ManagedObject restored = handler.createManagedObject(moElement);
+
+ // Assert
+ ManagedProperty p = restored.getProperty("map");
+ assertTrue(p.getValue() instanceof TableValue);
+ assertTrue(p.getMetaType() instanceof TableMetaType);
+
+ TableValue table = (TableValue) p.getValue();
+ assertRow(table, 1, "one");
+ assertRow(table, 2, "two");
+ assertRow(table, 3, "three");
+ }
+
+ protected void assertRow(TableValue table, Serializable key, Serializable value)
+ {
+ CompositeValue v = (CompositeValue) table.get(new MetaValue[] { SimpleValueSupport.wrap(key) });
+ assertNotNull(v);
+ // Assert value
+ SimpleValue simple = (SimpleValue) v.get("value");
+ assertNotNull(simple);
+ assertEquals(value, simple.getValue());
+ }
+
+ protected ManagedObject initMO()
+ {
+ SimpleTableMetaData t = new SimpleTableMetaData();
+ t.setMap(initMap());
+
+ return getMOF().initManagedObject(t, null);
+ }
+
+ protected Map<Integer, String> initMap()
+ {
+ Map<Integer, String> map = new HashMap<Integer, String>();
+ map.put(1, "one");
+ map.put(2, "two");
+ map.put(3, "three");
+ return map;
+ }
+
+}
Added: trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java
===================================================================
--- trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java (rev 0)
+++ trunk/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java 2009-02-10 08:23:56 UTC (rev 84037)
@@ -0,0 +1,267 @@
+/*
+ * 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.test.server.profileservice.persistence.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.repository.AbstractFileAttachmentsSerializer;
+import org.jboss.test.server.profileservice.persistence.support.NestedTestMetaData;
+import org.jboss.test.server.profileservice.persistence.support.PrimitiveMetaData;
+import org.jboss.test.server.profileservice.persistence.support.TestMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision: 82920 $
+ */
+public class TestNestedPeristenceFormatUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+ public TestNestedPeristenceFormatUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void test() throws Exception
+ {
+ ManagedObject mo = createNestedMO();
+
+ // deployment1
+ ManagedObject deployment = getDeployment("testDeployment1", mo);
+ assertNotNull(deployment);
+ deployment.getProperty("");
+
+ ManagedProperty p = deployment.getProperty("primitive");
+ assertNotNull(p);
+
+ CompositeValue composite = (CompositeValue) p.getValue();
+
+ Map<String, MetaValue> valueMap = new HashMap<String, MetaValue>();
+ valueMap.put("optionalName",
+ new SimpleValueSupport(SimpleMetaType.STRING, "changed"));
+ valueMap.put("integer", new SimpleValueSupport(
+ SimpleMetaType.INTEGER, 111));
+
+ //
+ p.setValue(new CompositeValueSupport(composite.getMetaType(), valueMap));
+
+ ManagedProperty property = deployment.getProperty("name");
+ assertNotNull(property);
+ property.setValue(SimpleValueSupport.wrap("ChangedName"));
+
+ // deployment3
+ deployment = getDeployment("testDeployment3", mo);
+ assertNotNull(deployment);
+
+ property = deployment.getProperty("name");
+ assertNotNull(property);
+ property.setValue(SimpleValueSupport.wrap("ChangedName3"));
+
+ PersistedManagedObject restored = process(mo);
+ assertNotNull(restored);
+ PersistedCollectionValue collection = (PersistedCollectionValue) restored.getProperties().get(0).getValue();
+ assertNotNull(collection);
+ PersistedManagedObject o = ((PersistedGenericValue) collection.getValues().get(0)).getManagedObject();
+ assertNotNull(o);
+
+ enableTrace("org.jboss.system.server.profileservice.persistence");
+
+ // Recreate
+ ManagedObjectUpdateHandler test = new ManagedObjectUpdateHandler();
+ mo = test.createManagedObject(restored);
+
+ deployment = getDeployment("ChangedName", mo);
+ assertNotNull("changed name deployment null", deployment);
+
+ p = deployment.getProperty("primitive");
+ assertNotNull(p);
+
+ composite = (CompositeValue) p.getValue();
+ assertNotNull(composite);
+
+ assertEquals("changed", ((SimpleValue)composite.get("optionalName")).getValue());
+
+
+ deployment = getDeployment("testDeployment2", mo);
+ assertNotNull(deployment);
+
+ deployment = getDeployment("ChangedName3", mo);
+ assertNotNull(deployment);
+
+ // Null
+ deployment = getDeployment("testDeployment1", mo);
+ assertNull(deployment);
+ // Null
+ deployment = getDeployment("testDeployment3", mo);
+ assertNull(deployment);
+
+ NestedTestMetaData md = (NestedTestMetaData) mo.getAttachment();
+ assertNotNull(md);
+
+ assertNotNull(md.getDeployments());
+ }
+
+ protected ManagedObject getDeployment(String name, ManagedObject mo)
+ {
+
+ ManagedProperty p = mo.getProperty("deployments");
+ CollectionValue collection = (CollectionValue) p.getValue();
+
+ assertTrue(p.getMetaType().isCollection());
+ assertNotNull("null collection", collection);
+ assertEquals(3, collection.getSize());;
+
+ for(MetaValue value : collection)
+ {
+ ManagedObject deployment = (ManagedObject) ((GenericValue) value).getValue();
+
+ ManagedProperty nameProp = deployment.getProperty("name");
+ assertNotNull(nameProp);
+
+ String deploymentName = (String) ((SimpleValue) deployment.getProperty("name").getValue()).getValue();
+
+ if(name.equals(deploymentName))
+ return deployment;
+ }
+ return null;
+ }
+
+ protected PersistedManagedObject process(ManagedObject mo) throws Exception
+ {
+ // Create root;
+ PersistedManagedObject persisted = new PersistedManagedObject();
+ // Create xml elements
+ ManagedObjectPeristenceHandler handler = new ManagedObjectPeristenceHandler();
+ handler.processManagedObject(persisted, mo);
+
+ // Save
+ AbstractFileAttachmentsSerializer serializer = getAttachmentSerializer(true);
+ serializer.saveAttachment("test", persisted);
+ // Restore
+ return serializer.loadAttachment("test", PersistedManagedObject.class);
+ }
+
+ protected ManagedObject createNestedMO()
+ {
+ return createMO(createNestedTestMetaData());
+ }
+
+ protected ManagedObject createMO(Object o)
+ {
+ return getMOF().initManagedObject(o, null);
+ }
+
+ protected NestedTestMetaData createNestedTestMetaData()
+ {
+ NestedTestMetaData test = new NestedTestMetaData();
+
+ List<TestMetaData> deployments = new ArrayList<TestMetaData>();
+
+ deployments.add(createTestMetaData("testDeployment1"));
+ deployments.add(createTestMetaData("testDeployment2"));
+ deployments.add(createTestMetaData("testDeployment3"));
+
+ test.setDeployments(deployments);
+ return test;
+ }
+
+ protected TestMetaData createTestMetaData(String name)
+ {
+ TestMetaData test = new TestMetaData();
+
+ //
+ test.setName(name);
+
+ // primitive
+ test.setPrimitive(createPrimitive());
+
+ // Create list
+ List<String> list = new ArrayList<String>();
+
+ list.add("String1");
+ list.add("String2");
+ list.add("String3");
+
+ test.setList(list);
+
+ // Create map
+ Map<String, String> map = new HashMap<String, String>();
+
+ map.put("testString1", "string1");
+ map.put("testString2", "string2");
+ map.put("testString3", "string3");
+
+ test.setTestMap(map);
+
+ // Create primitive array
+ Character[] array = new Character[3];
+
+ array[0] = 'A';
+ array[1] = 'B';
+ array[2] = 'C';
+
+ test.setCharArray(array);
+
+ // Create 2D array
+ char[][] test2D = {{'h', 'e'}, {'l', 'l', 'o'}};
+ test.setTest2dChar(test2D);
+
+ getLog().debug(test2D.length);
+
+ // Create table
+ Map<Integer, String> table = new HashMap<Integer, String>();
+ table.put(1, "one");
+ table.put(2, "two");
+ table.put(3, "three");
+
+ test.setTable(table);
+
+ return test;
+ }
+
+ protected PrimitiveMetaData createPrimitive()
+ {
+ PrimitiveMetaData primitive = new PrimitiveMetaData();
+ primitive.setInteger(12);
+ primitive.setName("testName");
+ return primitive;
+ }
+
+}
+
More information about the jboss-cvs-commits
mailing list