[jboss-cvs] JBossAS SVN: r88576 - branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat May 9 09:23:47 EDT 2009
Author: emuckenhuber
Date: 2009-05-09 09:23:47 -0400 (Sat, 09 May 2009)
New Revision: 88576
Added:
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreationPlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValueRecreation.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistencePlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationPlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingRecreationPlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationPlugin.java
Modified:
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java
Log:
add missing classes.
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java 2009-05-09 13:22:01 UTC (rev 88575)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -280,6 +280,13 @@
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)
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreationPlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreationPlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreationPlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -0,0 +1,185 @@
+/*
+ * 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.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 AbstractManagedObjectRecreationPlugin implements ManagedObjectRecreationPlugin
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectRecreationPlugin.class);
+
+ /** The value recreation. */
+ private AbstractValueRecreation valueRecreation;
+
+ public AbstractManagedObjectRecreationPlugin(AbstractValueRecreation valueRecreation)
+ {
+ this.valueRecreation = valueRecreation;
+ }
+
+ public AbstractValueRecreation getValueRecreation()
+ {
+ return this.valueRecreation;
+ }
+
+ public void setValueRecreation(AbstractValueRecreation valueRecreation)
+ {
+ this.valueRecreation = valueRecreation;
+ }
+
+ public abstract String getType();
+
+ protected void processProperties(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+ if(mo == null)
+ throw new IllegalArgumentException("null managed object");
+
+ // Get the xml to see what we need to update
+ if(persisted.getProperties() != null && persisted.getProperties().isEmpty() == false)
+ {
+ for(PersistedProperty propertyElement : persisted.getProperties())
+ {
+ ManagedProperty property = mo.getProperty(propertyElement.getName());
+ if(property == null)
+ throw new IllegalStateException("unable to find propery: "+ propertyElement.getName());
+
+ // getProperty
+ processManagedProperty(propertyElement, property, mo.getAttachment());
+ }
+ }
+ }
+
+ protected MetaValue processManagedProperty(PersistedProperty persisted, ManagedProperty property, Object attachment)
+ {
+ if(attachment == null)
+ throw new IllegalArgumentException("null attachment");
+ String name = property.getMappedName() != null ? property.getMappedName() : property.getName();
+ MetaValue metaValue = processManagedProperty(persisted, property);
+
+ setValue(name, property, attachment);
+
+ return metaValue;
+ }
+
+ protected abstract void setValue(String name, ManagedProperty property, Object attachment);
+
+ protected MetaValue processManagedProperty(PersistedProperty persisted, ManagedProperty property)
+ {
+ return processManagedProperty(persisted, property, false);
+ }
+
+ protected MetaValue processManagedProperty(PersistedProperty persisted, ManagedProperty property, boolean trace)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted property");
+ if(property == null)
+ throw new IllegalArgumentException("null managed property");
+
+ MetaValue metaValue = property.getValue();
+ PersistedValue persistedValue = persisted.getValue();
+ if(persistedValue != null && isProcessProperty(property, false))
+ {
+ MetaType metaType = property.getMetaType();
+ if(metaValue != null)
+ metaType = metaValue.getMetaType();
+
+ // Create the value based on the persisted information
+ metaValue = createValue(persistedValue, metaType);
+
+ // Update property
+ property.setField(Fields.VALUE, metaValue);
+ if(metaValue != null)
+ property.setField(Fields.META_TYPE, metaValue.getMetaType());
+ }
+ return metaValue;
+ }
+
+ protected MetaValue createValue(PersistedValue value, MetaType metaType)
+ {
+ return getValueRecreation().createMetaValue(value, metaType);
+ }
+
+ /**
+ * 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;
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValueRecreation.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValueRecreation.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValueRecreation.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -0,0 +1,471 @@
+/*
+ * 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.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.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.PropertiesMetaType;
+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.PropertiesMetaValue;
+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.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.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;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AbstractValueRecreation
+{
+
+ /** 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(ManagedObjectRecreation.class);
+
+ /** The recreation plugin. */
+ private final ManagedObjectRecreationPlugin plugin;
+
+ 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);
+ // primitive classes
+ simpleTypes.put(byte.class.getName(), byte.class);
+ simpleTypes.put(char.class.getName(), char.class);
+ simpleTypes.put(double.class.getName(), double.class);
+ simpleTypes.put(float.class.getName(), float.class);
+ simpleTypes.put(int.class.getName(), int.class);
+ simpleTypes.put(short.class.getName(), short.class);
+ simpleTypes.put(long.class.getName(), long.class);
+ simpleTypes.put(boolean.class.getName(), boolean.class);
+ }
+
+ public AbstractValueRecreation(ManagedObjectRecreationPlugin plugin)
+ {
+ this.plugin = plugin;
+ }
+
+ public ManagedObjectRecreationPlugin getPlugin()
+ {
+ return plugin;
+ }
+
+ /**
+ * 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
+ */
+ public MetaValue createMetaValue(PersistedValue valueElement, MetaType metaType)
+ {
+ if(log.isTraceEnabled())
+ {
+ log.trace("processing value " + valueElement + " type: " + metaType);
+ }
+
+ if(valueElement instanceof NullValue)
+ return null;
+
+ if(valueElement == null)
+ return null;
+
+ MetaValue metaValue = null;
+ try
+ {
+ 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 if(metaType.isProperties())
+ {
+ metaValue = createPropertiesValue(
+ (PersistedPropertiesValue) valueElement,
+ (PropertiesMetaType) metaType);
+ }
+ else
+ {
+ throw new IllegalStateException("unknown metaType");
+ }
+ }
+ finally
+ {
+ //
+ }
+ 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 new SimpleValueSupport(metaType, 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)
+ {
+ Serializable value = null;
+ if(genericElement.getManagedObject() != null)
+ {
+ value = getPlugin().createManagedObject(genericElement.getManagedObject());
+ }
+ return new GenericValueSupport(metaType, value);
+ }
+
+ /**
+ * 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 the properties value.
+ *
+ * @param value the persisted properties value
+ * @param metaType the properties meta type
+ * @return the properties value
+ */
+ protected MetaValue createPropertiesValue(
+ PersistedPropertiesValue value, PropertiesMetaType metaType)
+ {
+ PropertiesMetaValue properties = new PropertiesMetaValue();
+ for(PersistedPair pair : value.getEntries())
+ {
+ properties.setProperty(pair.getKey(), pair.getValue());
+ }
+
+ return properties;
+ }
+
+ /**
+ * 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;
+ }
+ }
+
+}
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistencePlugin.java (from rev 88417, branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPlugin.java)
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistencePlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistencePlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -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 DefaultPersistencePlugin extends AbstractManagedObjectPersistencePlugin
+{
+
+ public DefaultPersistencePlugin()
+ {
+ //
+ }
+
+ public DefaultPersistencePlugin(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: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationPlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationPlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationPlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -0,0 +1,81 @@
+/*
+ * 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.managed.api.ManagedProperty;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultRecreationPlugin extends AbstractManagedObjectRecreationPlugin
+{
+
+ /** attachment property populator. */
+ AttachmentPropertyPopulator propertyPopulator = new AttachmentPropertyPopulator();
+
+ public DefaultRecreationPlugin(AbstractValueRecreation valueRecreation)
+ {
+ super(valueRecreation);
+ }
+
+ @Override
+ public String getType()
+ {
+ return Object.class.getName();
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted)
+ {
+ throw new IllegalStateException("NYI");
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+ if(mo == null)
+ throw new IllegalArgumentException("null managed object");
+
+ // Process properties
+ processProperties(persisted, mo);
+
+ return mo;
+ }
+
+ @Override
+ protected void setValue(String name, ManagedProperty property, Object attachment)
+ {
+ try
+ {
+ this.propertyPopulator.processManagedProperty(name, property, attachment);
+ }
+ catch (Throwable e)
+ {
+ // FIXME
+ e.printStackTrace();
+ }
+ }
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java 2009-05-09 13:22:01 UTC (rev 88575)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -50,7 +50,7 @@
public DelegatingPersistencePlugin()
{
- this(new DefaultManagedObjectPlugin());
+ this(new DefaultPersistencePlugin());
}
public DelegatingPersistencePlugin(ManagedObjectPersistencePlugin defaultPlugin)
@@ -104,10 +104,7 @@
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);
}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingRecreationPlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingRecreationPlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingRecreationPlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -0,0 +1,99 @@
+/*
+ * 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.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DelegatingRecreationPlugin implements ManagedObjectRecreationPlugin
+{
+
+ /** The plugins. */
+ private Map<String, ManagedObjectRecreationPlugin> plugins = new ConcurrentHashMap<String, ManagedObjectRecreationPlugin>();
+
+ /** The default plugin. */
+ private ManagedObjectRecreationPlugin defaultPlugin;
+
+ /** The value recreation. */
+ private final AbstractValueRecreation valueRecreation;
+
+ public DelegatingRecreationPlugin()
+ {
+ this.valueRecreation = new AbstractValueRecreation(this);
+ this.defaultPlugin = new DefaultRecreationPlugin(valueRecreation);
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+ ManagedObjectRecreationPlugin plugin = getPlugin(persisted);
+ return plugin.createManagedObject(persisted);
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+ if(mo == null)
+ throw new IllegalArgumentException("null managed object");
+
+ ManagedObjectRecreationPlugin plugin = getPlugin(persisted);
+ return plugin.createManagedObject(persisted, mo);
+ }
+
+ protected ManagedObjectRecreationPlugin getPlugin(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+
+ String className = persisted.getTemplateName();
+ if(className == null)
+ className = persisted.getClassName();
+ return getPlugin(className);
+ }
+
+ protected ManagedObjectRecreationPlugin getPlugin(String type)
+ {
+ if(type == null)
+ throw new IllegalArgumentException("null plugin type");
+
+ ManagedObjectRecreationPlugin plugin = this.plugins.get(type);
+ if(plugin == null)
+ plugin = defaultPlugin;
+ return plugin;
+ }
+
+ public AbstractValueRecreation getValueRecreation()
+ {
+ return this.valueRecreation;
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationPlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationPlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationPlugin.java 2009-05-09 13:23:47 UTC (rev 88576)
@@ -0,0 +1,60 @@
+/*
+ * 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 ManagedObjectRecreationPlugin
+{
+
+ /**
+ * Get the value recreation.
+ *
+ * @return the value recreation.
+ */
+ AbstractValueRecreation getValueRecreation();
+
+ /**
+ * Create a managed object, based on the persisted information.
+ *
+ * @param persisted the persisted managed object
+ * @return
+ */
+ ManagedObject createManagedObject(PersistedManagedObject persisted);
+
+ /**
+ * Create a managed object, based on the persisted information.
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ * @return the managed object
+ */
+ ManagedObject createManagedObject(PersistedManagedObject persisted, ManagedObject mo);
+
+}
+
More information about the jboss-cvs-commits
mailing list