[jboss-cvs] JBossAS SVN: r87890 - in trunk/system/src/main/org/jboss/system/server/profileservice/persistence: deployer and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Apr 27 14:20:17 EDT 2009
Author: emuckenhuber
Date: 2009-04-27 14:20:17 -0400 (Mon, 27 Apr 2009)
New Revision: 87890
Added:
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPlugin.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValueVisitor.java
Modified:
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.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/AbstractPersisitedValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCollectionValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.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/PersistedSimpleValue.java
trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValue.java
Log:
update attachment persistence.
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,328 @@
+/*
+ * 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.system.server.profileservice.persistence;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+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.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+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;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractManagedObjectPersistencePlugin implements ManagedObjectPersistencePlugin
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectPersistencePlugin.class);
+
+ /** The value persistence. */
+ private AbstractValuePersistence valuePersistence;
+
+ public AbstractValuePersistence getValuePersistence()
+ {
+ return valuePersistence;
+ }
+
+ public void setValuePersistence(AbstractValuePersistence valuePersistence)
+ {
+ if(valuePersistence == null)
+ throw new IllegalArgumentException("null value persistence.");
+
+ this.valuePersistence = valuePersistence;
+ }
+
+ /**
+ * Get the type for this plugin.
+ *
+ * @return the type
+ */
+ public abstract String getType();
+
+ /**
+ * Create a persisted managed object.
+ *
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ public PersistedManagedObject createPersistedManagedObject(ManagedObject mo)
+ {
+ PersistedManagedObject persisted = new PersistedManagedObject();
+ persisted.setOriginalName(mo.getName());
+ return createPersistedManagedObject(persisted, mo);
+ }
+
+ /**
+ * Process a managed object.
+ *
+ * @param persisted the xml meta data
+ * @param mo the managed object
+ * @return isModified
+ */
+ public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("Null persisted managed object.");
+ if(mo == null)
+ throw new IllegalArgumentException("Null managed object");
+
+ // 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
+ persisted.setTemplateName(mo.getAttachmentName());
+ }
+ }
+ if(persisted.getOriginalName() == null)
+ persisted.setOriginalName(mo.getName());
+
+ // Set the managed-object meta information
+ persisted.setName(mo.getName());
+ persisted.setClassName(className);
+
+ return persisted;
+ }
+
+ /**
+ * Process the properties of the ManagedObject.
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ */
+ protected void processProperties(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ boolean trace = log.isTraceEnabled();
+ processProperties(persisted, mo, trace);
+ }
+
+ /**
+ * Process the properties of the ManagedObject.
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ * @param trace enable trace logs
+ */
+ protected void processProperties(PersistedManagedObject persisted, ManagedObject mo, boolean trace)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("Null persisted object");
+ if(mo == null)
+ throw new IllegalArgumentException("Null managed object.");
+
+ //
+ Map<String, PersistedProperty> properties = getPersistedProperties(persisted);
+ for(String propertyName : mo.getPropertyNames())
+ {
+ //
+ ManagedProperty property = mo.getProperty(propertyName);
+ PersistedProperty persistedProperty = properties.get(propertyName);
+
+ if(persistedProperty == null)
+ {
+ // Create a new peristed property
+ persistedProperty = createPersistedProperty(property);
+ }
+
+ // Process
+ if(processProperty(property, persistedProperty, trace))
+ {
+ persisted.getProperties().add(persistedProperty);
+ }
+ }
+ }
+
+ /**
+ * Create a persisted property.
+ *
+ * @param property the managed Property.
+ * @param persisted
+ * @return
+ */
+ protected PersistedProperty createPersistedProperty(ManagedProperty property)
+ {
+ if(property == null)
+ throw new IllegalArgumentException("Null managed property.");
+
+ PersistedProperty persisted = new PersistedProperty();
+ persisted.setName(property.getName());
+ return persisted;
+ }
+
+ /**
+ * Process a managed property.
+ *
+ * @param property the managed property
+ * @param persisted the persisted property
+ * @return true, if the property was processed
+ */
+ protected boolean processProperty(ManagedProperty property, PersistedProperty persisted)
+ {
+ boolean trace = log.isTraceEnabled();
+ return processProperty(property, persisted, trace);
+ }
+
+ /**
+ * Process a managed property.
+ *
+ * @param property the managed property
+ * @param persisted the persisted property
+ * @param trace enable trace logs
+ * @return true, if the property was processed
+ */
+ protected boolean processProperty(ManagedProperty property, PersistedProperty persisted, boolean trace)
+ {
+ if(property == null)
+ throw new IllegalArgumentException("Null managed property.");
+ if(persisted == null)
+ throw new IllegalArgumentException("Null persisted property.");
+
+ boolean processed = false;
+ // Check if we need to process this property
+ if(isProcessProperty(property, trace))
+ {
+ //
+ MetaValue metaValue = property.getField(Fields.VALUE, MetaValue.class);
+ MetaType metaType = property.getField(Fields.META_TYPE, MetaType.class);
+ // Override metaType
+ if(metaValue != null)
+ metaType = metaValue.getMetaType();
+
+ // Create the persisted value
+ PersistedValue value = createPersistedValue(metaValue, metaType, persisted.getValue());
+ if(value != null)
+ {
+ persisted.setValue(value);
+ if(trace)
+ log.trace("value for property ("+ property.getName() +"): " + value);
+ processed = true;
+ }
+ }
+ return processed;
+ }
+
+ /**
+ * Create a persisted value. This delegates the value creation
+ * to the ValuePeristence.
+ *
+ * @param metaValue the meta value
+ * @param metaType the meta type
+ * @param persisted the persisted value
+ * @return the created persisted value
+ */
+ private PersistedValue createPersistedValue(MetaValue metaValue, MetaType metaType, PersistedValue persisted)
+ {
+ return getValuePersistence().createPersistedValue(metaValue, metaType, persisted);
+ }
+
+ /**
+ * Does this property needs to be processed.
+ *
+ * @param property the managed property
+ * @param trace enable trace logs
+ * @return false if the property does not need to be processed otherwise true
+ */
+ protected boolean isProcessProperty(ManagedProperty property, boolean trace)
+ {
+ boolean process = false;
+ //
+ if(property == null)
+ return process;
+
+ // Skip non configuration properties
+ if(property.hasViewUse(ViewUse.CONFIGURATION) == false)
+ {
+ if(trace)
+ log.trace("Skip non configuration property: " + property.getName());
+ return process;
+ }
+ // Skip read only properties
+ if(property.isReadOnly())
+ {
+ if(trace)
+ log.trace("Skip readOnly property: " + property.getName());
+ return process;
+ }
+ // Skip removed properties
+ if(property.isRemoved())
+ {
+ if(trace)
+ log.trace("Skip removed property: " + property.getName());
+ return process;
+ }
+ // Skip read only properties
+ PropertyInfo propertyInfo = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ if(propertyInfo != null && propertyInfo.isReadable() == false)
+ {
+ if(trace)
+ log.trace("Skip non readable property: " + property.getName());
+ return process;
+ }
+ return true;
+ }
+
+ /**
+ * Get a map of persisted managed objects, with the property name as key.
+ *
+ * @param persisted the persisted managed object
+ * @return a map of persisted properties
+ */
+ protected static Map<String, PersistedProperty> getPersistedProperties(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("Null persisted managed object.");
+
+ Map<String, PersistedProperty> properties = new HashMap<String, PersistedProperty>();
+ List<PersistedProperty> list = persisted.getProperties();
+ if(list == null)
+ {
+ list = new ArrayList<PersistedProperty>();
+ persisted.setProperties(list);
+ }
+ if(list.isEmpty() == false)
+ {
+ for(PersistedProperty p : list)
+ properties.put(p.getName(), p);
+ }
+ return properties;
+ }
+
+}
+
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,479 @@
+/*
+ * 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.system.server.profileservice.persistence;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+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.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.system.server.profileservice.persistence.xml.NullValue;
+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.PersistedPair;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedPropertiesValue;
+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;
+
+/**
+ * The AbstractValuePersistence creates a xml representation of MetaValues
+ * which are used for the ProfileService attachment persistence.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AbstractValuePersistence
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractValuePersistence.class);
+
+ /** The meta value factory. */
+ private final MetaValueFactory metaValueFactory;
+
+ /** The plugin. */
+ private final ManagedObjectPersistencePlugin plugin;
+
+ public AbstractValuePersistence(ManagedObjectPersistencePlugin plugin, MetaValueFactory metaValueFactory)
+ {
+ if(plugin == null)
+ throw new IllegalArgumentException("Null managed object plugin.");
+ if(metaValueFactory == null)
+ throw new IllegalArgumentException("Null meta value factory.");
+
+ this.plugin = plugin;
+ this.metaValueFactory = metaValueFactory;
+ }
+
+ /**
+ * Get the meta value factory.
+ *
+ * @return the meta value factory
+ */
+ public MetaValueFactory getMetaValueFactory()
+ {
+ return this.metaValueFactory;
+ }
+
+ protected ManagedObjectPersistencePlugin getPlugin()
+ {
+ return this.plugin;
+ }
+
+ /**
+ * 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)
+ {
+ return createPersistedValue(value, metaType, null);
+ }
+
+ /**
+ * Create the peristed xml meta data.
+ *
+ * @param value the meta value
+ * @param metaType the meta type
+ * @param persisted
+ * @return the xml value.
+ */
+ protected PersistedValue createPersistedValue(MetaValue value, MetaType metaType, PersistedValue persisted)
+ {
+ if(log.isTraceEnabled())
+ log.trace("creating persisted value for : " + value + " with metaType " + metaType);
+
+ if(value == null)
+ return new NullValue();
+
+ // 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 if(metaType.isProperties())
+ {
+ persistedValue = createPropertiesValue(
+ (PropertiesMetaValue) 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
+ */
+ protected 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
+ */
+ protected 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
+ */
+ protected 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
+ */
+ protected PersistedGenericValue createGenericValue(GenericValue value)
+ {
+ //
+ PersistedGenericValue generic = new PersistedGenericValue();
+ return createGenericValue(value, generic);
+ }
+
+ /**
+ * Create the persistence generic value.
+ *
+ * @param value the generic value
+ * @param the persisted generic value
+ * @return the generic xml meta data
+ */
+ protected PersistedGenericValue createGenericValue(GenericValue value, PersistedGenericValue generic)
+ {
+ Object o = value.getValue();
+ if(o == null)
+ return generic;
+
+ if(o instanceof ManagedObject)
+ {
+ PersistedManagedObject mo;
+
+ if(generic.getManagedObject() == null)
+ mo = plugin.createPersistedManagedObject((ManagedObject) o);
+ else
+ mo = plugin.createPersistedManagedObject(generic.getManagedObject(), (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
+ */
+ protected 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);
+ }
+ else 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
+ * @param the persisted composite value
+ * @return the persistence composite xml meta data
+ */
+ protected 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
+ * @param the persisted table
+ * @return the persistence table xml meta data
+ */
+ protected 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 the persistence properties value.
+ *
+ * @param value the properties value
+ * @param the persisted properties
+ * @return the persistence properties xml meta data
+ */
+ protected PersistedValue createPropertiesValue(PropertiesMetaValue value)
+ {
+ PersistedPropertiesValue properties = new PersistedPropertiesValue();
+ List<PersistedPair> pairs = properties.getEntries();
+ if(pairs == null)
+ {
+ pairs = new ArrayList<PersistedPair>();
+ properties.setEntries(pairs);
+ }
+ for(Object key : value.keySet())
+ {
+ Object kvalue = value.get(key);
+ PersistedPair pair = new PersistedPair(key.toString(), kvalue.toString());
+ pairs.add(pair);
+ }
+ return properties;
+ }
+
+ /**
+ * 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 if(metaType.isProperties())
+ {
+ return new PersistedPropertiesValue();
+ }
+ 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 = getMetaValueFactory().unwrap(value);
+ if(unwrappedValue == null)
+ return null;
+ // Convert to String
+ return ("" + unwrappedValue);
+ }
+
+}
\ No newline at end of file
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPlugin.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPlugin.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPlugin.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,62 @@
+/*
+ * 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.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultManagedObjectPlugin extends AbstractManagedObjectPersistencePlugin
+{
+
+ public DefaultManagedObjectPlugin()
+ {
+ //
+ }
+
+ public DefaultManagedObjectPlugin(AbstractValuePersistence valuePersistence)
+ {
+ setValuePersistence(valuePersistence);
+ }
+
+ @Override
+ public String getType()
+ {
+ return Object.class.getName();
+ }
+
+ @Override
+ public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ // Create the persisted information
+ persisted = super.createPersistedManagedObject(persisted, mo);
+ // Process the properties
+ processProperties(persisted, mo);
+ // Return
+ return persisted;
+ }
+
+}
+
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,172 @@
+/*
+ * 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.system.server.profileservice.persistence;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DelegatingPersistencePlugin implements ManagedObjectPersistencePlugin
+{
+
+ /** The meta data plugins. */
+ private Map<String, ManagedObjectPersistencePlugin> plugins = new ConcurrentHashMap<String, ManagedObjectPersistencePlugin>();
+
+ /** The default plugin. */
+ private final ManagedObjectPersistencePlugin defaultPlugin;
+
+ /** The meta value factory. */
+ private final MetaValueFactory metaValueFactory = MetaValueFactoryBuilder.create();
+
+ /** The value persistence. */
+ private final AbstractValuePersistence valuePersistence;
+
+ public DelegatingPersistencePlugin()
+ {
+ this(new DefaultManagedObjectPlugin());
+ }
+
+ public DelegatingPersistencePlugin(ManagedObjectPersistencePlugin defaultPlugin)
+ {
+ this.valuePersistence = new AbstractValuePersistence(this, metaValueFactory);
+ this.defaultPlugin = defaultPlugin;
+ this.defaultPlugin.setValuePersistence(valuePersistence);
+ }
+
+ /**
+ * Create a persisted managed object.
+ *
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ public PersistedManagedObject createPersistedManagedObject(ManagedObject mo)
+ {
+ if(mo == null)
+ throw new IllegalArgumentException("Null managed object.");
+
+ ManagedObjectPersistencePlugin plugin = getPlugin(mo);
+ return plugin.createPersistedManagedObject(mo);
+ }
+
+ /**
+ * Create a persisted managed object
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("Null persisted managed object.");
+ if(mo == null)
+ throw new IllegalArgumentException("Null managed object.");
+
+ ManagedObjectPersistencePlugin plugin = getPlugin(mo);
+ return plugin.createPersistedManagedObject(persisted, mo);
+ }
+
+ /**
+ * Extract the type name and get the plugin.
+ *
+ * @param mo the managed object
+ * @return the managed object plugin
+ */
+ protected ManagedObjectPersistencePlugin getPlugin(ManagedObject mo)
+ {
+ String type = mo.getAttachmentName();
+ if(type == null && mo.getAttachment() != null)
+ type = mo.getAttachment().getClass().getName();
+ // As the console is creating their own ManagedObjectImpl
+ // it could happen that the MO is not populated correctly.
+ if(type == null)
+ return defaultPlugin;
+ return getPlugin(type);
+ }
+
+ /**
+ * Get the plugin.
+ *
+ * @param type the managed object type
+ * @return the managed object plugin
+ */
+ public ManagedObjectPersistencePlugin getPlugin(String type)
+ {
+ if(type == null)
+ throw new IllegalArgumentException("Null type.");
+
+ ManagedObjectPersistencePlugin plugin = this.plugins.get(type);
+ if(plugin == null)
+ plugin = defaultPlugin;
+ return plugin;
+ }
+
+ /**
+ * Add a managed object plugin.
+ *
+ * @param plugin the plugin to add
+ */
+ public void addPlugin(AbstractManagedObjectPersistencePlugin plugin)
+ {
+ if(plugin == null)
+ throw new IllegalArgumentException("Null plugin.");
+ if(plugin.getType() == null)
+ throw new IllegalArgumentException("Null plugin type.");
+
+ plugin.setValuePersistence(this.valuePersistence);
+ this.plugins.put(plugin.getType(), plugin);
+ }
+
+ /**
+ * Remove a managed object plugin.
+ *
+ * @param plugin the plugin to remove
+ */
+ public void removePlugin(AbstractManagedObjectPersistencePlugin plugin)
+ {
+ if(plugin == null)
+ throw new IllegalArgumentException("Null plugin.");
+ if(plugin.getType() == null)
+ throw new IllegalArgumentException("Null plugin type.");
+
+ this.plugins.remove(plugin.getType());
+ }
+
+ public AbstractValuePersistence getValuePersistence()
+ {
+ return this.valuePersistence;
+ }
+
+ public void setValuePersistence(AbstractValuePersistence valuePersistence)
+ {
+ //
+ }
+
+}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -24,6 +24,7 @@
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Collection;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -52,6 +53,7 @@
import org.jboss.reflect.spi.ClassInfo;
import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
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;
/**
@@ -203,6 +205,23 @@
if(c.size() < override.getSize())
throw new IllegalStateException("c.size() < override.getSize()");
+ // First identify the names of removed components
+ HashSet<String> removedNames = new HashSet<String>();
+ for (MetaValue mv : override)
+ {
+ // Extract the generic information
+ GenericValue overrideGeneric = (GenericValue) mv;
+ PersistedGenericValue overrideGenericValue = (PersistedGenericValue) overrideGeneric.getValue();
+ PersistedManagedObject pmo = overrideGenericValue.getManagedObject();
+ if (pmo.getModificationInfo() != ModificationInfo.REMOVED)
+ continue;
+ String name = overrideGenericValue.getManagedObject().getName();
+ if (name == null)
+ name = overrideGenericValue.getManagedObject().getOriginalName();
+ if (name != null)
+ removedNames.add(name);
+ }
+
Iterator<?> rawIterator = c.iterator();
Iterator<MetaValue> originalIterator = original.iterator();
Iterator<MetaValue> overrideIterator = override.iterator();
@@ -210,7 +229,7 @@
// Create a new collection
BeanInfo beanInfo = configuration.getBeanInfo(propertyInfo.getType());
Collection newCollection = (Collection) createNewInstance(beanInfo);
-
+
while (rawIterator.hasNext())
{
// The raw object
@@ -229,14 +248,16 @@
newCollection.add(o);
continue;
}
-
// Remove a ManagedObject
- ModificationInfo modificationInfo = overrideGenericValue.getModificationInfo();
- if(modificationInfo != null && modificationInfo == ModificationInfo.REMOVED)
+ Object og = originalGeneric.getValue();
+ if ((og instanceof ManagedObject))
{
- continue;
+ ManagedObject originalMO = (ManagedObject) og;
+ String name = originalMO.getName();
+ if(removedNames.contains(name))
+ continue;
}
-
+
// process the generic value
processGenericValue(originalGeneric, overrideGenericValue, trace);
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -108,10 +108,6 @@
//
PersistedValue valueElement = propertyElement.getValue();
- if (valueElement.getModificationInfo() == null)
- {
- // TODO
- }
// Recreate the metaValue
MetaValue override = createMetaValue(valueElement, metaType);
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-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -21,43 +21,8 @@
*/
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.PropertiesMetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.TableValue;
-import org.jboss.system.server.profileservice.persistence.xml.NullValue;
-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.PersistedPair;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedPropertiesValue;
-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.
@@ -67,13 +32,15 @@
*/
public class ManagedObjectPeristenceHandler
{
+
+ /** . */
+ private final ManagedObjectPersistencePlugin plugin;
- /** The meta value factory. */
- private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ public ManagedObjectPeristenceHandler()
+ {
+ this.plugin = new DelegatingPersistencePlugin();
+ }
- /** The logger. */
- private static final Logger log = Logger.getLogger(ManagedObjectPeristenceHandler.class);
-
/**
* Create the persistence meta data for a ManagedObject.
*
@@ -85,9 +52,7 @@
if(mo == null)
throw new IllegalArgumentException("Null managedObject.");
- PersistedManagedObject moElement = new PersistedManagedObject();
- processManagedObject(moElement, mo);
- return moElement;
+ return getPlugin().createPersistedManagedObject(mo);
}
/**
@@ -97,427 +62,19 @@
* @param mo the managed object
* @return isModified
*/
- public void processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
+ public void processManagedObject(PersistedManagedObject persisted, ManagedObject mo)
{
- if(moElement == null)
+ if(persisted == 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(), trace);
-
- properties.add(propertyElement);
- }
+ getPlugin().createPersistedManagedObject(persisted, mo);
}
- /**
- * 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, boolean trace)
+ protected ManagedObjectPersistencePlugin getPlugin()
{
- if(name == null)
- throw new IllegalArgumentException("Null name.");
- if(metaType == null)
- throw new IllegalArgumentException("Null meta type.");
-
- if(trace)
- log.trace("processing property name="+ name + "[metaValue="+ value + ", metaType="+ metaType + "]" );
-
- // Create Property
- PersistedProperty property = new PersistedProperty(name);
- // Create persisted value
- PersistedValue persistedValue = createPersistedValue(value, metaType);
-// persistedValue.setModificationInfo(ModificationInfo.MODIFIED);
- //
- property.setValue(persistedValue);
- // Return
- return property;
+ return this.plugin;
}
- /**
- * 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 new NullValue();
-
- // 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 if(metaType.isProperties())
- {
- persistedValue = createPropertiesValue(
- (PropertiesMetaValue) 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
- */
- protected 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
- */
- protected 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
- */
- protected 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
- */
- protected 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
- */
- protected 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);
- }
- else 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
- */
- protected 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
- */
- protected 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;
- }
-
- protected PersistedValue createPropertiesValue(PropertiesMetaValue value)
- {
- PersistedPropertiesValue properties = new PersistedPropertiesValue();
- List<PersistedPair> pairs = properties.getEntries();
- if(pairs == null)
- {
- pairs = new ArrayList<PersistedPair>();
- properties.setEntries(pairs);
- }
- for(Object key : value.keySet())
- {
- Object kvalue = value.get(key);
- PersistedPair pair = new PersistedPair(key.toString(), kvalue.toString());
- pairs.add(pair);
- }
- return properties;
- }
-
- /**
- * 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/ManagedObjectPersistencePlugin.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,65 @@
+/*
+ * 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.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface ManagedObjectPersistencePlugin
+{
+
+ /**
+ * Get the value persistence.
+ *
+ * @return the value persistence
+ */
+ AbstractValuePersistence getValuePersistence();
+
+ /**
+ * Set the value persistence.
+ *
+ * @param valuePersistence the value persistence
+ */
+ void setValuePersistence(AbstractValuePersistence valuePersistence);
+
+ /**
+ * Create a persisted managed object
+ *
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ PersistedManagedObject createPersistedManagedObject(ManagedObject mo);
+
+ /**
+ * Create a persisted managed object
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo);
+
+}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -23,9 +23,8 @@
import org.jboss.managed.api.ManagedCommon;
import org.jboss.managed.api.ManagedObject;
-import org.jboss.metatype.api.values.GenericValue;
import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
/**
*
@@ -38,28 +37,52 @@
/** The item to remove. */
private ManagedCommon removeItem = null;
+ private ManagedObjectPersistencePlugin plugin;
+
public ManagedObjectRemoveHandler(ManagedCommon removeItem)
{
+ super();
if(removeItem == null)
throw new IllegalArgumentException("Null component to remove.");
this.removeItem = removeItem;
+ this.plugin = new DelegatingPersistencePlugin(new RemovePlugin());
}
-
+
@Override
- protected PersistedGenericValue createGenericValue(GenericValue value)
+ protected ManagedObjectPersistencePlugin getPlugin()
{
- Object o = value.getValue();
- if(o instanceof ManagedObject)
+ return this.plugin;
+ }
+
+ public class RemovePlugin extends DefaultManagedObjectPlugin
+ {
+
+ @Override
+ public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
{
- ManagedObject mo = (ManagedObject) o;
- if(mo.getName() == removeItem.getName())
+ if(mo != null)
{
- PersistedGenericValue v = new PersistedGenericValue();
- v.setModificationInfo(ModificationInfo.REMOVED);
- return v;
+ if(mo.getName() == removeItem.getName())
+ {
+ persisted.setModificationInfo(ModificationInfo.REMOVED);
+ return persisted;
+ }
+ else
+ {
+ return super.createPersistedManagedObject(persisted, mo);
+ }
}
+ else
+ {
+ return super.createPersistedManagedObject(persisted, mo);
+ }
}
- return super.createGenericValue(value);
+
+ @Override
+ public String getType()
+ {
+ return null;
+ }
}
-
+
}
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-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -30,7 +30,6 @@
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.ManagedGenericOverrideHandler;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
@@ -52,7 +51,7 @@
private ManagedGenericOverrideHandler overrideHandler = new ManagedGenericOverrideHandler();
/** The managed object factory. */
- private final ManagedObjectFactory factory = ManagedObjectFactoryBuilder.create();
+ private ManagedObjectFactory factory = ManagedObjectFactory.getInstance();
/** The Logger. */
private static final Logger log = Logger.getLogger(ProfileServicePersistenceDeployer.class);
@@ -64,6 +63,16 @@
setStage(DeploymentStages.PRE_REAL);
}
+ public ManagedObjectFactory getManagedObjectFactory()
+ {
+ return factory;
+ }
+
+ public void setManagedObjectFactory(ManagedObjectFactory factory)
+ {
+ this.factory = factory;
+ }
+
@Override
protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
{
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/AbstractPersisitedValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/AbstractPersisitedValue.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/AbstractPersisitedValue.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -21,8 +21,8 @@
*/
package org.jboss.system.server.profileservice.persistence.xml;
-import javax.xml.bind.annotation.XmlAttribute;
+
/**
* A abstract persisted value.
*
@@ -31,26 +31,10 @@
*/
public abstract class AbstractPersisitedValue extends AbstractElement implements PersistedValue
{
- /** The modification info. */
- ModificationInfo info;
-
- @XmlAttribute(name = "modification")
- public ModificationInfo getModificationInfo()
+
+ public void visit(PersistedValueVisitor visitor)
{
- return this.info;
+ // nothing here
}
- public void setModificationInfo(ModificationInfo info)
- {
- this.info = info;
- }
-
- public boolean hasModificationFlag(ModificationInfo info)
- {
- if(info == null)
- return false;
-
- return this.info.equals(info);
- }
-
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCollectionValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCollectionValue.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCollectionValue.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -73,15 +73,21 @@
return values.size();
}
- public PersistedValue getValue(int i)
+ protected void toString(StringBuilder builder)
{
- if(values == null) return null; // throw Exception ?
- return this.values.get(i);
+ builder.append(", values = ").append(getValues());
}
- protected void toString(StringBuilder builder)
+ @Override
+ public void visit(PersistedValueVisitor visitor)
{
- builder.append(", values = ").append(getValues());
+ if(this.values != null && this.values.isEmpty() == false)
+ {
+ for(PersistedValue value : this.values)
+ {
+ value.visit(visitor);
+ }
+ }
}
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -52,10 +52,25 @@
{
this.managedObject = managedObject;
}
+
+ public boolean hasModificationFlag(ModificationInfo info)
+ {
+ if(managedObject == null)
+ return false;
+ return managedObject.getModificationInfo() == info;
+ }
+
protected void toString(StringBuilder builder)
{
builder.append(", managed-object = ").append(getManagedObject());
}
+ @Override
+ public void visit(PersistedValueVisitor visitor)
+ {
+ if(this.managedObject != null)
+ visitor.addPersistedManagedObject(this.managedObject);
+ }
+
}
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-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -30,6 +30,7 @@
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
import org.jboss.xb.annotations.JBossXmlSchema;
@@ -41,6 +42,7 @@
*/
@JBossXmlSchema(namespace = PersistenceConstants.NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name = MANAGED_OBJECT_ELEMENT_NAME)
+ at XmlType(propOrder = {"originalName", "templateName", "modificationInfo", "properties"})
public class PersistedManagedObject extends AbstractElement
{
@@ -53,6 +55,9 @@
/** The properties */
private List<PersistedProperty> properties;
+ /** The modification info. */
+ private ModificationInfo modificationInfo;
+
public PersistedManagedObject()
{
//
@@ -79,6 +84,17 @@
this.templateName = templateName;
}
+ @XmlAttribute(name = "modification")
+ public ModificationInfo getModificationInfo()
+ {
+ return this.modificationInfo;
+ }
+
+ public void setModificationInfo(ModificationInfo info)
+ {
+ this.modificationInfo = info;
+ }
+
@XmlElement(name = "orignal-name")
public String getOriginalName()
{
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedSimpleValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedSimpleValue.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedSimpleValue.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -41,9 +41,6 @@
/** The value. */
private String value;
- /** The modification info. */
- private ModificationInfo info;
-
public PersistedSimpleValue()
{
//
@@ -82,25 +79,6 @@
this.className = className;
}
- @XmlAttribute(name = "modification")
- public ModificationInfo getModificationInfo()
- {
- return this.info;
- }
-
- public void setModificationInfo(ModificationInfo info)
- {
- this.info = info;
- }
-
- public boolean hasModificationFlag(ModificationInfo info)
- {
- if(info == null)
- return false;
-
- return this.info.equals(info);
- }
-
@XmlValue
public String getValue()
{
@@ -127,5 +105,10 @@
{
builder.append(", value = ").append(getValue());
}
+
+ public void visit(PersistedValueVisitor visitor)
+ {
+ // nothing here
+ }
}
Modified: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValue.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValue.java 2009-04-27 18:16:58 UTC (rev 87889)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValue.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -31,28 +31,10 @@
{
/**
- * Get the modification info for this value.
+ * Visit this value.
*
- * @return the modification info
+ * @param visitor the visitor
*/
- ModificationInfo getModificationInfo();
-
-
- /**
- * Set the modification info.
- *
- * @param info the modification info
- */
- void setModificationInfo(ModificationInfo info);
-
-
- /**
- * Check the modificationInfo.
- *
- * @param info the modification info.
- * @return this.info.equals(info);
- */
- boolean hasModificationFlag(ModificationInfo info);
-
+ void visit(PersistedValueVisitor visitor);
}
Added: trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValueVisitor.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValueVisitor.java (rev 0)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedValueVisitor.java 2009-04-27 18:20:17 UTC (rev 87890)
@@ -0,0 +1,67 @@
+/*
+ * 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.system.server.profileservice.persistence.xml;
+
+import java.util.Collection;
+
+import org.jboss.metatype.api.types.MetaType;
+
+
+/**
+ * A persisted value visitor, extracting persisted managed objects.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface PersistedValueVisitor
+{
+
+ /**
+ * Get the meta type of the property.
+ *
+ * @return the metaType.
+ */
+ MetaType getMetaType();
+
+ /**
+ * Get the persisted managed objects of this node.
+ *
+ * @return the persisted managed objects.
+ */
+ Collection<PersistedManagedObject> getManagedObjects();
+
+ /**
+ * Add a persisted managed object.
+ *
+ * @param mo the persisted managed object.
+ */
+ void addPersistedManagedObject(PersistedManagedObject mo);
+
+ /**
+ * Visit a persisted value.
+ *
+ * @param the value
+ */
+ void visit(PersistedValue value);
+
+}
+
More information about the jboss-cvs-commits
mailing list