[jboss-cvs] JBossAS SVN: r88716 - in branches/Branch_5_x: connector/src/resources/deployers and 24 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 12 09:19:55 EDT 2009
Author: emuckenhuber
Date: 2009-05-12 09:19:55 -0400 (Tue, 12 May 2009)
New Revision: 88716
Added:
branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/MCFDGComponentMapper.java
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/TempManagedComponentImpl.java
branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceDeploymentComponentMapper.java
branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentComponentMapper.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistence.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreation.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractPersistenceFactory.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPersistencePlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistenceDelegate.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationDelegate.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHelper.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceConstants.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceFactory.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/AbstractComponentMapper.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapper.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapperRegistry.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedComponent.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceRoot.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/CompositeMetaData.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponent.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponentMapper.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestDeployment.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestMgtComponentImpl.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/AbstractComponentMapperTest.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/ComponentMapperUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMgtComponentImpl.java
Removed:
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/AbstractManagedObjectRecreationPlugin.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/MOCreatorPlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreation.java
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/ManagedObjectRemoveHandler.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java
Modified:
branches/Branch_5_x/connector/src/resources/deployers/jca-deployers-jboss-beans.xml
branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml
branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml
branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java
branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/LazyPredeterminedManagedObjects.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.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/AttachmentPropertyPopulator.java
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/ManagedObjectPersistencePlugin.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/support/GenericSupportMetaData.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/GenericValueUnitTestCase.java
branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossServicePersistenceFormatTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JMSDestinationPersistenceFormatTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/LocalDataSourcePersistenceFormatTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ManagementViewUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
branches/Branch_5_x/testsuite/src/resources/profileservice/override/testQueue-service.xml
branches/Branch_5_x/testsuite/src/resources/profileservice/override/testTopic-service.xml
branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/jboss-service.xml
branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/profileservice-test-ds.xml
Log:
[JBAS-6227] update attachment persistence to use a componentmapper.
Added: branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/MCFDGComponentMapper.java
===================================================================
--- branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/MCFDGComponentMapper.java (rev 0)
+++ branches/Branch_5_x/connector/src/main/org/jboss/resource/deployers/management/MCFDGComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,105 @@
+/*
+ * 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.resource.deployers.management;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
+import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.AbstractComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+
+/**
+ * A ManagedConnectionFactoryDeploymentMetaData persistence ComponentMapper.
+ * This will handle the persistence operations for the MCFDeploymentMetaData.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class MCFDGComponentMapper extends AbstractComponentMapper
+{
+
+ public MCFDGComponentMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected void setComponentName(PersistedComponent component, ManagedObject mo)
+ {
+ ManagedConnectionFactoryDeploymentMetaData metaData =
+ (ManagedConnectionFactoryDeploymentMetaData) mo.getAttachment();
+ // Set the current name;
+ component.setName(metaData.getJndiName());
+ }
+
+ @Override
+ protected ManagedObject getComponent(Object attachment, PersistedComponent component, boolean create)
+ {
+ ManagedConnectionFactoryDeploymentGroup deployment = (ManagedConnectionFactoryDeploymentGroup) attachment;
+ ManagedConnectionFactoryDeploymentMetaData metaData = null;
+ if(deployment.getDeployments() != null && deployment.getDeployments().isEmpty() == false)
+ {
+ for(ManagedConnectionFactoryDeploymentMetaData md : deployment.getDeployments())
+ {
+ if(md.getJndiName().equals(component.getOriginalName()))
+ {
+ metaData = md;
+ break;
+ }
+ }
+ }
+ if(metaData == null && create)
+ {
+ // TODO create new attachment
+ }
+ if(metaData == null)
+ throw new IllegalStateException("could not find deployment " + component.getOriginalName());
+ return getMOF().initManagedObject(metaData, null);
+ }
+
+ @Override
+ protected void removeComponent(Object attachment, PersistedComponent component)
+ {
+ ManagedConnectionFactoryDeploymentGroup deployment = (ManagedConnectionFactoryDeploymentGroup) attachment;
+ if(deployment.getDeployments() != null && deployment.getDeployments().isEmpty() == false)
+ {
+ List<ManagedConnectionFactoryDeploymentMetaData> deployments = new ArrayList<ManagedConnectionFactoryDeploymentMetaData>();
+ for(ManagedConnectionFactoryDeploymentMetaData md : deployment.getDeployments())
+ {
+ if(md.getJndiName().equals(component.getOriginalName()) == false)
+ deployments.add(md);
+ }
+ deployment.setDeployments(deployments);
+ }
+ }
+
+ public String getType()
+ {
+ return ManagedConnectionFactoryDeploymentGroup.class.getName();
+ }
+
+}
+
Modified: branches/Branch_5_x/connector/src/resources/deployers/jca-deployers-jboss-beans.xml
===================================================================
--- branches/Branch_5_x/connector/src/resources/deployers/jca-deployers-jboss-beans.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/connector/src/resources/deployers/jca-deployers-jboss-beans.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -177,5 +177,10 @@
</constructor>
<property name="connectionFactoryType">no-tx-connection-factory</property>
</bean>
+
+ <!-- The ManagedConnectionFactoryDeploymentGroup component mapper -->
+ <bean name="MCFDGComponentMapper" class="org.jboss.resource.deployers.management.MCFDGComponentMapper">
+ <constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
+ </bean>
</deployment>
Modified: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/ManagementViewImpl.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -649,7 +649,7 @@
if (mc != null && md.getComponent(mo.getName()) == null)
{
ComponentType type = new ComponentType(mc.type(), mc.subtype());
- ManagedComponentImpl comp = new ManagedComponentImpl(type, md, mo);
+ ManagedComponentImpl comp = new TempManagedComponentImpl(type, md, mo);
md.addComponent(mo.getName(), comp);
log.debug("Processing ManagementComponent("+mo.getName()+"): "+comp);
Set<ManagedComponent> typeComps = compByCompType.get(type);
Added: branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/TempManagedComponentImpl.java
===================================================================
--- branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/TempManagedComponentImpl.java (rev 0)
+++ branches/Branch_5_x/profileservice/src/main/org/jboss/profileservice/management/TempManagedComponentImpl.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profileservice.management;
+
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.RunStateMapper;
+import org.jboss.managed.plugins.ManagedComponentImpl;
+
+/**
+ * Temp managed component impl where getParent points to the defining
+ * ManagedObject.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TempManagedComponentImpl extends ManagedComponentImpl
+{
+ private static final long serialVersionUID = 1;
+
+ public TempManagedComponentImpl(ComponentType type, ManagedDeployment owner, ManagedObject mo)
+ {
+ this(type, owner, mo, null);
+ }
+ public TempManagedComponentImpl(ComponentType type, ManagedDeployment owner, ManagedObject mo,
+ RunStateMapper stateMapper)
+ {
+ super(type, owner, mo, stateMapper);
+ }
+
+ @Override
+ public ManagedCommon getParent()
+ {
+ return getDelegate();
+ }
+
+}
Modified: branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml
===================================================================
--- branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -162,11 +162,23 @@
<property name="tempDirURI">${jboss.server.home.url}temp${/}cluster-repo</property>
</bean>
- <!-- The attachment store -->
+ <!-- A persistence factory for creating the persisted format of ManagedComponents -->
+ <bean name="PersistenceFactory" class="org.jboss.system.server.profileservice.persistence.AbstractPersistenceFactory">
+ <constructor><parameter><inject bean="ManagedObjectFactory" /></parameter></constructor>
+ <!-- Accept any ComponentMapper -->
+ <incallback method="addComponentMapper" />
+ <uncallback method="removeComponentMapper" />
+ <!-- Accept any ManagedObjectPersistencePlugin -->
+ <incallback method="addPersistencePlugin" />
+ <uncallback method="removePersistencePlugin" />
+ </bean>
+
+ <!-- The attachment store -->
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
<constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
+ <property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
<property name="metaDataFilter"><bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter" /></property>
</bean>
@@ -179,7 +191,16 @@
<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
</bean>
- <bean name="ProfileServicePersistenceDeployer" class="org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer" />
+ <bean name="ProfileServicePersistenceDeployer" class="org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer">
+ <property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
+ </bean>
+
+ <bean name="KernelDeploymentComponentMapper" class="org.jboss.deployers.plugins.managed.KernelDeploymentMapper">
+ <constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
+ </bean>
+ <bean name="ServiceDeploymentComponentMapper" class="org.jboss.system.deployers.managed.ServiceDeploymentComponentMapper">
+ <constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
+ </bean>
<!-- A filter for excluding files from the scanner -->
<bean name="DeploymentFilter" class="org.jboss.virtual.plugins.vfs.helpers.ExtensibleFilter">
Modified: branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml
===================================================================
--- branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -123,11 +123,23 @@
<property name="checker"><inject bean="StructureModificationChecker" /></property>
</bean>
+ <!-- A persistence factory for creating the persisted format of ManagedComponents -->
+ <bean name="PersistenceFactory" class="org.jboss.system.server.profileservice.persistence.AbstractPersistenceFactory">
+ <constructor><parameter><inject bean="ManagedObjectFactory" /></parameter></constructor>
+ <!-- Accept any ComponentMapper -->
+ <incallback method="addComponentMapper" />
+ <uncallback method="removeComponentMapper" />
+ <!-- Accept any ManagedObjectPersistencePlugin -->
+ <incallback method="addPersistencePlugin" />
+ <uncallback method="removePersistencePlugin" />
+ </bean>
+
<!-- The attachment store -->
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore">
<constructor><parameter><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>
<property name="mainDeployer"><inject bean="MainDeployer" /></property>
<property name="serializer"><inject bean="AttachmentsSerializer" /></property>
+ <property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
<property name="metaDataFilter"><bean class="org.jboss.system.server.profile.basic.XmlIncludeVirtualFileFilter" /></property>
</bean>
@@ -140,8 +152,17 @@
<property name="attachmentStore"><inject bean="AttachmentStore" /></property>
</bean>
- <bean name="ProfileServicePersistenceDeployer" class="org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer" />
-
+ <bean name="ProfileServicePersistenceDeployer" class="org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer">
+ <property name="persistenceFactory"><inject bean="PersistenceFactory" /></property>
+ </bean>
+
+ <bean name="KernelDeploymentComponentMapper" class="org.jboss.deployers.plugins.managed.KernelDeploymentComponentMapper">
+ <constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
+ </bean>
+ <bean name="ServiceDeploymentComponentMapper" class="org.jboss.system.deployers.managed.ServiceDeploymentComponentMapper">
+ <constructor><parameter><inject bean="PersistenceFactory" /></parameter></constructor>
+ </bean>
+
<!-- A filter for excluding files from the scanner -->
<bean name="DeploymentFilter" class="org.jboss.virtual.plugins.vfs.helpers.ExtensibleFilter">
<!-- Files starting with theses strings are ignored -->
Modified: branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -28,6 +28,7 @@
import org.jboss.beans.info.spi.PropertyInfo;
import org.jboss.beans.metadata.spi.AnnotationMetaData;
import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.dependency.KernelController;
@@ -181,7 +182,6 @@
propertyInfo = beanInfo.getProperty(name);
Object bean = locateBean(attachment.getName());
- Object value = null;
MetaValue mvalue = null;
if(propertyInfo.isReadable() == false)
{
@@ -194,10 +194,40 @@
{
String getterClassName = propertyInfo.getGetter().getDeclaringClass().getName();
if(getterClassName.equals(attachment.getClass().getName()))
+ {
+ // use attachment
mvalue = delegateICF.getValue(beanInfo, property, metaData, attachment);
+ }
+ else if(bean != null)
+ {
+ // use bean (if installed)
+ mvalue = delegateICF.getValue(beanInfo, property, metaData, bean);
+ }
else
- mvalue = delegateICF.getValue(beanInfo, property, metaData, bean);
-
+ {
+ // Try to find the property in the meta data
+ PropertyMetaData md = null;
+ if(attachment.getProperties() != null && attachment.getProperties().isEmpty() == false)
+ {
+ for(PropertyMetaData bp : attachment.getProperties())
+ {
+ if(name.equals(bp.getName()))
+ {
+ md = bp;
+ break;
+ }
+ }
+ if(md != null)
+ {
+ // TODO add metaMapping
+ if(md.getValue() != null)
+ {
+ mvalue = metaValueFactory.create(md.getValue().getUnderlyingValue(),
+ propertyInfo.getType());
+ }
+ }
+ }
+ }
}
catch(Throwable e)
{
@@ -240,7 +270,7 @@
Object plainValue = unwrapValue(property, propertyInfo.getType(), value);
Object bean = locateBean(beanName);
- // Only update if the bean is not null
+ // Only update the bean if installed
if(bean != null)
propertyInfo.set(bean, plainValue);
@@ -277,4 +307,5 @@
}
return metaValueFactory.unwrap(value, typeInfo);
}
+
}
Added: branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentComponentMapper.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentComponentMapper.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/KernelDeploymentComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,143 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.deployers.plugins.managed;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.AbstractComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+
+/**
+ * A AbstractKernelDeployment persistence ComponentMapper.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class KernelDeploymentComponentMapper extends AbstractComponentMapper
+{
+
+ public KernelDeploymentComponentMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected void setComponentName(PersistedComponent component, ManagedObject mo)
+ {
+ BeanMetaData bmd = (BeanMetaData) mo.getAttachment();
+ // Set the current name
+ component.setName(bmd.getName());
+ }
+
+ @Override
+ protected ManagedObject getComponent(Object attachment, PersistedComponent component, boolean create)
+ {
+ AbstractKernelDeployment deployment = (AbstractKernelDeployment) attachment;
+ Map<String, BeanMetaData> beans = new HashMap<String, BeanMetaData>();
+ for(BeanMetaData bmd : deployment.getBeans())
+ {
+ beans.put(bmd.getName(), bmd);
+ }
+ BeanMetaData bmd = beans.get(component.getOriginalName());
+ // Create a new Bean
+ if(bmd == null && create)
+ {
+ AbstractBeanMetaData bean = createEmptyBeanMetaData(component);
+ if(deployment.getBeanFactories() == null)
+ deployment.setBeanFactories(new ArrayList<BeanMetaDataFactory>());
+
+ deployment.getBeanFactories().add(bean);
+ bmd = bean;
+ }
+ if(bmd == null)
+ {
+ throw new IllegalStateException("Could not find bean: " + component.getOriginalName());
+ }
+ // TODO we need the MetaData here!
+ MetaData metaData = null;
+ return getMOF().initManagedObject(bmd, metaData);
+ }
+
+ @Override
+ protected void removeComponent(Object attachment, PersistedComponent component)
+ {
+ AbstractKernelDeployment deployment = (AbstractKernelDeployment) attachment;
+ if(deployment.getBeanFactories() != null && deployment.getBeanFactories().isEmpty() == false)
+ {
+ boolean removed = false;
+ List<BeanMetaDataFactory> beanFactories = new ArrayList<BeanMetaDataFactory>();
+ for(BeanMetaDataFactory bmdf : deployment.getBeanFactories())
+ {
+ if(bmdf instanceof AbstractBeanMetaData)
+ {
+ AbstractBeanMetaData bean = (AbstractBeanMetaData) bmdf;
+ if(bean.getName().equals(component.getOriginalName()))
+ {
+ removed = true;
+ }
+ else
+ {
+ beanFactories.add(bmdf);
+ }
+ }
+ else
+ {
+ beanFactories.add(bmdf);
+ }
+ }
+ if(! removed)
+ throw new IllegalStateException("Could not remove component " + component.getOriginalName());
+ // Update deployment
+ deployment.setBeanFactories(beanFactories);
+ }
+ }
+
+ protected AbstractBeanMetaData createEmptyBeanMetaData(PersistedComponent component)
+ {
+ AbstractBeanMetaData bean = new AbstractBeanMetaData();
+ bean.setName(component.getOriginalName());
+ // See if we stored the bean class name
+ String beanClassName = component.getTemplateName();
+ if(beanClassName == null)
+ beanClassName = component.getClassName();
+ if(beanClassName != null && beanClassName.equals(AbstractBeanMetaData.class.getName()) == false)
+ bean.setBean(beanClassName);
+ return bean;
+ }
+
+ public String getType()
+ {
+ return AbstractKernelDeployment.class.getName();
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/LazyPredeterminedManagedObjects.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/LazyPredeterminedManagedObjects.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/LazyPredeterminedManagedObjects.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -28,7 +28,7 @@
import org.jboss.deployers.spi.attachments.AttachmentsFactory;
import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.system.server.profileservice.persistence.deployer.ProfileServicePersistenceDeployer;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.system.server.profileservice.repository.AbstractFileAttachmentsSerializer;
/**
@@ -180,7 +180,7 @@
return attachments.contains(name.substring(ProfileServicePersistenceDeployer.PERSISTED_ATTACHMENT_PREFIX.length()));
}
- private PersistedManagedObject loadAttachment(String name)
+ private PersistenceRoot loadAttachment(String name)
{
if(! ishandleAttachment(name))
return null;
@@ -191,7 +191,7 @@
// deploy/deployment/child/attachmentName
String attachmentName = relativePath + attachmentClassName;
// Load attachment
- return serializer.loadAttachment(attachmentName, PersistedManagedObject.class);
+ return serializer.loadAttachment(attachmentName, PersistenceRoot.class);
}
catch(Exception e)
{
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/attachments/RepositoryAttachmentMetaData.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -28,6 +28,7 @@
import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlRootElement;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
import org.jboss.xb.annotations.JBossXmlSchema;
/**
@@ -36,7 +37,7 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
- at JBossXmlSchema(namespace = "urn:org:jboss:profileservice:attachments:1.0", elementFormDefault = XmlNsForm.QUALIFIED,
+ at JBossXmlSchema(namespace = PersistenceConstants.REPOSITORY_NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED,
xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") })
@XmlRootElement(name = "attachments-metadata")
public class RepositoryAttachmentMetaData
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistence.java (from rev 88576, 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/AbstractManagedObjectPersistence.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistence.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,326 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import java.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;
+
+/**
+ * A abstract ManagedObject persistence helper.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractManagedObjectPersistence
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectPersistence.class);
+
+ /** The value persistence. */
+ private final AbstractValuePersistence valuePersistence;
+
+ protected AbstractManagedObjectPersistence(AbstractValuePersistence valuePersistence)
+ {
+ if(valuePersistence == null)
+ throw new IllegalArgumentException("null value persistence.");
+
+ this.valuePersistence = valuePersistence;
+ }
+
+ public AbstractValuePersistence getValuePersistence()
+ {
+ return 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)
+ {
+ PersistedManagedObject persisted = new PersistedManagedObject();
+ 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());
+ }
+ }
+ String name = mo.getName();
+ if(mo.getComponentName() != null && mo.getComponentName() instanceof String)
+ name = (String) mo.getComponentName();
+
+ if(persisted.getOriginalName() == null)
+ persisted.setOriginalName(name);
+
+ // Set the managed-object meta information
+ persisted.setName(name);
+ 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;
+ }
+
+}
+
Deleted: 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-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectPersistencePlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,328 +0,0 @@
-/*
- * 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;
- }
-
-}
-
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreation.java (from rev 88576, 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/AbstractManagedObjectRecreation.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreation.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,226 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import org.jboss.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;
+
+/**
+ * A abstract ManagedObject recreation helper.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractManagedObjectRecreation
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectRecreation.class);
+
+ /** The value recreation. */
+ private final AbstractValueRecreation valueRecreation;
+
+ public AbstractManagedObjectRecreation(AbstractValueRecreation valueRecreation)
+ {
+ this.valueRecreation = valueRecreation;
+ }
+
+ public AbstractValueRecreation getValueRecreation()
+ {
+ return this.valueRecreation;
+ }
+
+ /**
+ * Process the properties of the persisted ManagedObject.
+ *
+ * @param persisted the persisted managed object
+ * @param mo the ManagedObject
+ */
+ 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());
+ }
+ }
+ }
+
+ /**
+ * Process a managed property and set it's values to the attachment.
+ *
+ * @param persisted the persisted property
+ * @param property the managed property
+ * @param attachment the attachment
+ * @return the meta value of this property
+ */
+ protected MetaValue processManagedProperty(PersistedProperty persisted, ManagedProperty property, Object attachment)
+ {
+ if(attachment == null)
+ throw new IllegalArgumentException("null attachment");
+
+ // Get the property name
+ String name = property.getMappedName() != null ? property.getMappedName() : property.getName();
+ // Process the property
+ MetaValue metaValue = processManagedProperty(persisted, property);
+ // Set value
+ setValue(name, property, attachment);
+ // Return
+ return metaValue;
+ }
+
+ /**
+ * Set the value to the managed property/
+ *
+ * @param name the property name
+ * @param property the managed property itself
+ * @param attachment the attachment
+ */
+ protected abstract void setValue(String name, ManagedProperty property, Object attachment);
+
+ /**
+ * Process the managed property.
+ *
+ * @param persisted the persisted property
+ * @param property the managed property
+ * @return the value
+ */
+ protected MetaValue processManagedProperty(PersistedProperty persisted, ManagedProperty property)
+ {
+ return processManagedProperty(persisted, property, false);
+ }
+
+ /**
+ * Process the managed property.
+ *
+ * @param persisted the persisted property
+ * @param property the managed property
+ * @param trace enable trace logs
+ * @return the value
+ */
+ 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, trace))
+ {
+ 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;
+ }
+
+ /**
+ * Call the value recreation to recreate a persisted value.
+ *
+ * @param value the persisted value
+ * @param metaType the meta type
+ * @return the meta value
+ */
+ 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;
+ }
+
+}
+
Deleted: 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 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractManagedObjectRecreationPlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,185 +0,0 @@
-/*
- * 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/AbstractPersistenceFactory.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractPersistenceFactory.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractPersistenceFactory.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,320 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.system.server.profileservice.persistence.component.ComponentMapper;
+import org.jboss.system.server.profileservice.persistence.component.ComponentMapperRegistry;
+import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
+
+/**
+ * The abstract persistence factory.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AbstractPersistenceFactory extends PersistenceFactory
+{
+
+ /** The component mapper registry. */
+ private final ComponentMapperRegistry componentMapper = ComponentMapperRegistry.getInstance();
+
+ /** The delegating persistence plugin. */
+ private final DelegatingPersistencePlugin persistencePlugin;
+
+ /** The recreation helper. */
+ private final ManagedObjectRecreationHelper recreationHelper;
+
+ public AbstractPersistenceFactory()
+ {
+ this(ManagedObjectFactory.getInstance());
+ }
+
+ public AbstractPersistenceFactory(ManagedObjectFactory managedObjectFactory)
+ {
+ super(managedObjectFactory);
+ this.recreationHelper = new ManagedObjectRecreationHelper(managedObjectFactory);
+ this.persistencePlugin = new DelegatingPersistencePlugin(recreationHelper);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public ManagedObjectPersistencePlugin getPersistencePlugin()
+ {
+ return persistencePlugin;
+ }
+
+ /**
+ * Apply the persisted information to a attachment.
+ *
+ * @param root the persistence root
+ * @param attachment the root attachment
+ * @param classLoader the classloader
+ */
+ @Override
+ public void restorePersistenceRoot(PersistenceRoot root, Object parentAttachment, ClassLoader classLoader)
+ {
+ if(root == null)
+ throw new IllegalArgumentException("null root");
+ if(parentAttachment == null)
+ throw new IllegalArgumentException("null attachment");
+
+ if(root.getComponents() != null && root.getComponents().isEmpty() == false)
+ {
+ // Set the classloader
+ recreationHelper.setLoader(classLoader);
+ try
+ {
+ // Restore the components
+ ComponentMapper mapper = getComponentMapper(parentAttachment.getClass().getName());
+ for(PersistedComponent component : root.getComponents())
+ {
+ mapper.restoreComponent(parentAttachment, component);
+ }
+ }
+ finally
+ {
+ recreationHelper.setLoader(null);
+ }
+ }
+ }
+
+ /**
+ * Add a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ @Override
+ public PersistenceRoot addComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component)
+ {
+ ComponentMapper mapper = getComponentMapper(parent);
+ PersistedComponent persistedComponent = mapper.addComponent(parent.getAttachment(), component);
+ return addPersistedComponent(root, persistedComponent);
+ }
+
+ /**
+ * Remove a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ @Override
+ public PersistenceRoot removeComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component)
+ {
+ ComponentMapper mapper = getComponentMapper(parent);
+ PersistedComponent persistedComponent = mapper.removeComponent(parent.getAttachment(), component);
+ return addPersistedComponent(root, persistedComponent);
+ }
+
+ /**
+ * Update a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ @Override
+ public PersistenceRoot updateComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component)
+ {
+ ComponentMapper mapper = getComponentMapper(parent);
+ PersistedComponent persistedComponent = mapper.updateComponent(parent.getAttachment(), component);
+ return addPersistedComponent(root, persistedComponent);
+ }
+
+ /**
+ * Reset a component. This will remove the persisted information.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ @Override
+ public PersistenceRoot resetComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component)
+ {
+ ComponentMapper mapper = getComponentMapper(parent);
+ PersistedComponent persistedComponent = mapper.updateComponent(parent.getAttachment(), component);
+ // Map the components
+ Map<String, PersistedComponent> components = mapComponents(root);
+ // Remove the component
+ PersistedComponent previous = components.remove(persistedComponent.getOriginalName());
+ if(previous == null)
+ previous = components.remove(persistedComponent.getName());
+ // Set the new values
+ root.setComponents(new ArrayList<PersistedComponent>(components.values()));
+ return root;
+ }
+
+ /**
+ * Add a persisted component to the root. This will map and override
+ * existing components.
+ *
+ * @param root the persistence root
+ * @param component the persisted component
+ * @return the update persistence root
+ */
+ protected PersistenceRoot addPersistedComponent(PersistenceRoot root, PersistedComponent component)
+ {
+ Map<String, PersistedComponent> components = mapComponents(root);
+ PersistedComponent previous = components.remove(component.getOriginalName());
+ if(previous == null)
+ previous = components.remove(component.getName());
+ // Add the persisted component
+ components.put(component.getName(), component);
+
+ // Override with some previous information
+ if(previous != null)
+ {
+ // A added component should remain on added
+ if(previous.getModificationInfo() == ModificationInfo.ADDED
+ && component.getModificationInfo() == ModificationInfo.MODIFIED)
+ component.setModificationInfo(ModificationInfo.ADDED);
+
+ // Just remove a previously added component
+ if(previous.getModificationInfo() == ModificationInfo.ADDED
+ && component.getModificationInfo() == ModificationInfo.REMOVED)
+ components.remove(component.getName());
+
+ // Override the name
+ if(previous.getOriginalName() != null)
+ component.setOriginalName(previous.getOriginalName());
+ }
+
+ root.setComponents(new ArrayList<PersistedComponent>(components.values()));
+ return root;
+ }
+
+ /**
+ * Get the component mapper for a given ManagedObject.
+ *
+ * @param parent the managed object
+ * @return the component mapper
+ * @throws IllegalStateException if no mapper is registered for this type
+ */
+ protected ComponentMapper getComponentMapper(ManagedObject parent)
+ {
+ String type = parent.getAttachmentName();
+ if(type == null && parent.getAttachment() != null)
+ type = parent.getAttachment().getClass().getName();
+
+ return getComponentMapper(type);
+ }
+
+ /**
+ * Get the component mapper for a given type.
+ *
+ * @param type the type
+ * @return the component mapper
+ * @throw IllegalArgumentException for a null type
+ * @throws IllegalStateException if no mapper is registered for this type
+ */
+ protected ComponentMapper getComponentMapper(String type)
+ {
+ if(type == null)
+ throw new IllegalArgumentException("null type");
+
+ ComponentMapper mapper = componentMapper.getMapper(type);
+ if(mapper == null)
+ throw new IllegalStateException("no mapper registered for type: " + type);
+
+ return mapper;
+ }
+
+ /**
+ * Map the components based on their names.
+ *
+ * @param root the persistence root
+ * @return a map of persisted components
+ */
+ protected static Map<String, PersistedComponent> mapComponents(PersistenceRoot root)
+ {
+ Map<String, PersistedComponent> map = new HashMap<String, PersistedComponent>();
+ if(root.getComponents() != null && root.getComponents().isEmpty() == false)
+ {
+ for(PersistedComponent component : root.getComponents())
+ {
+ // Map this based on the name, as this should
+ // match the original name of the new component
+ map.put(component.getName(), component);
+ }
+ }
+ return map;
+ }
+
+ /**
+ * InstallCallback for adding a component mapper.
+ *
+ * @param mapper the component mapper
+ */
+ public void addComponentMapper(ComponentMapper mapper)
+ {
+ componentMapper.addMapper(mapper);
+ }
+
+ /**
+ * UnInstallCallback for removing a component mapper.
+ *
+ * @param mapper the component mapper
+ * @return the removed component mapper
+ */
+ public ComponentMapper removeComponentMapper(ComponentMapper mapper)
+ {
+ return componentMapper.removeComponentMapper(mapper);
+ }
+
+ /**
+ * InstallCallback for adding a persistence plugin.
+ *
+ * @param plugin the persistence plugin
+ */
+ public void addPersistencePlugin(ManagedObjectPersistencePlugin plugin)
+ {
+ persistencePlugin.addPlugin(plugin);
+ }
+
+ /**
+ * UnInstallCallback for removing a persistence plugin.
+ *
+ * @param plugin the plugin
+ */
+ public void removePersistencePlugin(ManagedObjectPersistencePlugin plugin)
+ {
+ persistencePlugin.removePlugin(plugin);
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValuePersistence.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -73,14 +73,14 @@
/** The plugin. */
private final ManagedObjectPersistencePlugin plugin;
- public AbstractValuePersistence(ManagedObjectPersistencePlugin plugin, MetaValueFactory metaValueFactory)
+ public AbstractValuePersistence(ManagedObjectPersistencePlugin callback, MetaValueFactory metaValueFactory)
{
- if(plugin == null)
- throw new IllegalArgumentException("Null managed object plugin.");
+ if(callback == null)
+ throw new IllegalArgumentException("Null managed object persistence callback.");
if(metaValueFactory == null)
throw new IllegalArgumentException("Null meta value factory.");
- this.plugin = plugin;
+ this.plugin = callback;
this.metaValueFactory = metaValueFactory;
}
Modified: 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 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AbstractValueRecreation.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -74,6 +74,11 @@
import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
/**
+ * The abstract value recreation creates MetaValues based on the persisted
+ * managed object information and the MetaTypes of the ManagedObject used
+ * for persistence. The recreation of ManagedObjects itself is delegated
+ * to a ManagedObjectRecreationPlugin.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -84,10 +89,10 @@
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);
+ private final static Logger log = Logger.getLogger(AbstractValueRecreation.class);
/** The recreation plugin. */
- private final ManagedObjectRecreationPlugin plugin;
+ private final ManagedObjectPersistencePlugin plugin;
static
{
@@ -116,18 +121,21 @@
simpleTypes.put(boolean.class.getName(), boolean.class);
}
- public AbstractValueRecreation(ManagedObjectRecreationPlugin plugin)
+ public AbstractValueRecreation(ManagedObjectPersistencePlugin callback)
{
- this.plugin = plugin;
+ if(callback == null)
+ throw new IllegalArgumentException("null managed object persistence callback");
+
+ this.plugin = callback;
}
- public ManagedObjectRecreationPlugin getPlugin()
+ public ManagedObjectPersistencePlugin getPlugin()
{
return plugin;
}
/**
- * Create the meta value, based on the xml persited
+ * Create the meta value, based on the xml persisted
* value and the generated MetaType.
*
* @param valueElement the persisted xml element
@@ -284,7 +292,7 @@
// Put
values.put(persistedValue.getName(), metaValue);
}
- }
+ }
return new CompositeValueSupport(type, values);
}
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/AttachmentPropertyPopulator.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -22,24 +22,44 @@
package org.jboss.system.server.profileservice.persistence;
import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.WeakHashMap;
import javax.management.ObjectName;
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
import org.jboss.logging.Logger;
import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metatype.api.types.CollectionMetaType;
import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.InstanceFactory;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.plugins.values.ListInstanceFactory;
+import org.jboss.metatype.plugins.values.SetInstanceFactory;
+import org.jboss.metatype.plugins.values.SortedSetInstanceFactory;
import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.reflect.spi.ClassInfo;
/**
* The AttachmentPropertyPopulator, this writes the values of a
- * ManagedProperty to a attachment.
+ * ManagedProperty to the attachment using a registered ICF.
*
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
@@ -47,23 +67,60 @@
public class AttachmentPropertyPopulator
{
- /** The managed object factory. */
- private ManagedObjectFactory managedObjectFactory;
-
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(AttachmentPropertyPopulator.class);
+
/** The meta value factory. */
- private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ private static final MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
- /** The logger. */
- private static final Logger log = Logger.getLogger(AttachmentPropertyPopulator.class);
+ /** The configuration */
+ private static final Configuration configuration;
+
+ /** The managed object factory. */
+ private final ManagedObjectFactory managedObjectFactory;
+
+ /** The helper. */
+ private final ManagedObjectRecreationHelper helper;
+
+ /** The instance factory builders */
+ private Map<Class<?>, InstanceFactory<?>> instanceFactoryMap = new WeakHashMap<Class<?>, InstanceFactory<?>>();
- public AttachmentPropertyPopulator()
+ static
{
- this.managedObjectFactory = ManagedObjectFactory.getInstance();
+ configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
+ {
+ public Configuration run()
+ {
+ return new PropertyConfiguration();
+ }
+ });
}
- public AttachmentPropertyPopulator(ManagedObjectFactory managedObjectFactory)
+ public <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory)
{
+ synchronized(instanceFactoryMap)
+ {
+ if (factory == null)
+ instanceFactoryMap.remove(clazz);
+ else
+ instanceFactoryMap.put(clazz, factory);
+ }
+ }
+
+ public AttachmentPropertyPopulator(ManagedObjectFactory managedObjectFactory,
+ ManagedObjectRecreationHelper helper)
+ {
+ if(managedObjectFactory == null)
+ throw new IllegalArgumentException("null managed object factory.");
+ if(helper == null)
+ throw new IllegalArgumentException("null helper");
+
this.managedObjectFactory = managedObjectFactory;
+ this.helper = helper;
+ // set default collection instance factories
+ setInstanceFactory(List.class, ListInstanceFactory.INSTANCE);
+ setInstanceFactory(Set.class, SetInstanceFactory.INSTANCE);
+ setInstanceFactory(SortedSet.class, SortedSetInstanceFactory.INSTANCE);
}
/**
@@ -89,25 +146,75 @@
// Get the meta data information
MetaType metaType = property.getMetaType();
MetaValue value = property.getValue();
+ if(value != null)
+ metaType = value.getMetaType();
- // FIXME skip CompositeValueInvocationHandler
- MetaMapper mapper = property.getTransientAttachment(MetaMapper.class);
- if (mapper == null && metaType.isComposite())
+ MetaMapper<?> mapper = property.getTransientAttachment(MetaMapper.class);
+ if (mapper == null)
{
- if(metaType.getTypeName().equals(ObjectName.class.getName()) == false)
+ if(metaType.isComposite())
{
- // unwrap
- Object unwrapped = metaValueFactory.unwrap(value, propertyInfo.getType());
- if (Proxy.isProxyClass(unwrapped.getClass()))
- return;
+ // FIXME skip CompositeValueInvocationHandler
+ if(metaType.getTypeName().equals(ObjectName.class.getName()) == false)
+ {
+ // unwrap
+ Object unwrapped = metaValueFactory.unwrap(value, propertyInfo.getType());
+ if(unwrapped != null)
+ {
+ if (Proxy.isProxyClass(unwrapped.getClass()))
+ throw new IllegalStateException("cannot unwrap composite value for property " + property.getName()
+ + " maybe missing @MetaMapping? " + metaType.getTypeName());
+ }
+ }
}
+ else if(metaType.isCollection())
+ {
+ CollectionMetaType collectionMetaType = (CollectionMetaType) metaType;
+ if(collectionMetaType.getElementType() == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ // FIXME
+ Collection<?> newCollection = unwrapGenericCollection((CollectionValue) value, propertyInfo);
+ propertyInfo.set(attachment, newCollection);
+ return;
+ }
+ }
}
// Set value
InstanceClassFactory icf = managedObjectFactory.getInstanceClassFactory(attachment.getClass(), null);
BeanInfo beanInfo = propertyInfo.getBeanInfo();
icf.setValue(beanInfo, property, attachment, value);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected Collection<?> unwrapGenericCollection(CollectionValue collection, PropertyInfo propertyInfo) throws Throwable
+ {
+ // Create a new collection
+ BeanInfo beanInfo = configuration.getBeanInfo(propertyInfo.getType());
+ Collection newCollection = (Collection) createNewInstance(beanInfo);
+ // unwrap generic collection
+ for(MetaValue value : collection.getElements())
+ {
+ ManagedObject o = (ManagedObject) ((GenericValue)value).getValue();
+ newCollection.add(o.getAttachment());
+ }
+ return newCollection;
}
+
+ @SuppressWarnings("deprecation")
+ protected Object createNewInstance(BeanInfo beanInfo) throws Throwable
+ {
+ ClassInfo classInfo = beanInfo.getClassInfo();
+ if (classInfo.isInterface())
+ {
+ InstanceFactory<?> instanceFactory = instanceFactoryMap.get(classInfo.getType());
+ if (instanceFactory == null)
+ throw new IllegalArgumentException("Cannot instantiate interface BeanInfo, missing InstanceFactory: " + classInfo);
+ return instanceFactory.instantiate(beanInfo);
+ }
+ return beanInfo.newInstance();
+ }
+
}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPersistencePlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPersistencePlugin.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultManagedObjectPersistencePlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * The default ManagedObject persistence plugin.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultManagedObjectPersistencePlugin implements ManagedObjectPersistencePlugin
+{
+
+ /** The default persistence delegate. */
+ private final DefaultPersistenceDelegate persistenceDelegate;
+
+ /** The default recreation delegate. */
+ private final DefaultRecreationDelegate recreationDelegate;
+
+ public DefaultManagedObjectPersistencePlugin(AbstractValuePersistence valuePersistence,
+ AbstractValueRecreation valueRecreation, ManagedObjectRecreationHelper helper)
+ {
+ // Create the delegates
+ this.persistenceDelegate = new DefaultPersistenceDelegate(valuePersistence);
+ this.recreationDelegate = new DefaultRecreationDelegate(valueRecreation, helper);
+ }
+
+ public String getType()
+ {
+ return Object.class.getName();
+ }
+
+ public AbstractValuePersistence getValuePersistence()
+ {
+ return persistenceDelegate.getValuePersistence();
+ }
+
+ public AbstractValueRecreation getValueRecreation()
+ {
+ return recreationDelegate.getValueRecreation();
+ }
+
+ public PersistedManagedObject createPersistedManagedObject(ManagedObject mo)
+ {
+ return persistenceDelegate.createPersistedManagedObject(mo);
+ }
+
+ public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ return persistenceDelegate.createPersistedManagedObject(persisted, mo);
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted)
+ {
+ return recreationDelegate.createManagedObject(persisted);
+ }
+
+ public ManagedObject updateManagedObject(PersistedManagedObject persisted, ManagedObject mo)
+ {
+ return recreationDelegate.updateManagedObject(persisted, mo);
+ }
+
+}
+
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistenceDelegate.java (from rev 88576, 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/DefaultPersistenceDelegate.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistenceDelegate.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * The default persistence plugin. This will create a PersistedManagedObject
+ * with it's properties.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultPersistenceDelegate extends AbstractManagedObjectPersistence
+{
+
+ public DefaultPersistenceDelegate(AbstractValuePersistence valuePersistence)
+ {
+ super(valuePersistence);
+ }
+
+ @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;
+ }
+
+}
+
Deleted: 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/DefaultPersistencePlugin.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultPersistencePlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,62 +0,0 @@
-/*
- * 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;
- }
-
-}
-
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationDelegate.java (from rev 88576, 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/DefaultRecreationDelegate.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationDelegate.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * The default ManagedObject recreation plugin. This will process and update
+ * the ManagedObject and it's properties.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DefaultRecreationDelegate extends AbstractManagedObjectRecreation
+{
+
+ /** The recreation helper. */
+ private final ManagedObjectRecreationHelper helper;
+
+ public DefaultRecreationDelegate(AbstractValueRecreation valueRecreation, ManagedObjectRecreationHelper helper)
+ {
+ super(valueRecreation);
+ if(helper == null)
+ throw new IllegalArgumentException("null helper");
+
+ this.helper = helper;
+ }
+
+ public ManagedObject createManagedObject(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object.");
+
+ String className = persisted.getTemplateName();
+ if(className == null)
+ className = persisted.getClassName();
+
+ ManagedObject mo = createManagedObjectSkeleton(className);
+ if(mo == null)
+ throw new RuntimeException("could not recreate managed object for class " + className);
+ return updateManagedObject(persisted, mo);
+ }
+
+ public ManagedObject updateManagedObject(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;
+ }
+
+ protected ManagedObject createManagedObjectSkeleton(String className)
+ {
+ try
+ {
+ return this.helper.createManagedObjectSkeleton(className);
+ }
+ catch(ClassNotFoundException cnfe)
+ {
+ throw new RuntimeException("could not recreate attachment", cnfe);
+ }
+ }
+
+ @Override
+ protected void setValue(String name, ManagedProperty property, Object attachment)
+ {
+ try
+ {
+ this.helper.setValue(name, property, attachment);
+ }
+ catch (Throwable e)
+ {
+ throw new RuntimeException("Could not set value for property: " + property, e);
+ }
+ }
+}
+
Deleted: 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 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DefaultRecreationPlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,81 +0,0 @@
-/*
- * 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-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingPersistencePlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -30,6 +30,8 @@
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
/**
+ * A delegating persistence plugin.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -48,19 +50,32 @@
/** The value persistence. */
private final AbstractValuePersistence valuePersistence;
- public DelegatingPersistencePlugin()
+ /** The value recreation. */
+ private AbstractValueRecreation valueRecreation;
+
+ public DelegatingPersistencePlugin(ManagedObjectRecreationHelper helper)
{
- this(new DefaultPersistencePlugin());
+ this.valuePersistence = new AbstractValuePersistence(this, metaValueFactory);
+ this.valueRecreation = new AbstractValueRecreation(this);
+ this.defaultPlugin = new DefaultManagedObjectPersistencePlugin(valuePersistence, valueRecreation, helper);
}
- public DelegatingPersistencePlugin(ManagedObjectPersistencePlugin defaultPlugin)
+ public String getType()
{
- this.valuePersistence = new AbstractValuePersistence(this, metaValueFactory);
- this.defaultPlugin = defaultPlugin;
- this.defaultPlugin.setValuePersistence(valuePersistence);
+ return Object.class.getName();
}
/**
+ * Get the value recreation.
+ *
+ * @return the value recreation
+ */
+ public AbstractValuePersistence getValuePersistence()
+ {
+ return this.valuePersistence;
+ }
+
+ /**
* Create a persisted managed object.
*
* @param mo the managed object
@@ -94,6 +109,49 @@
}
/**
+ * Get the value persistence.
+ *
+ * @return the value persistence
+ */
+ public AbstractValueRecreation getValueRecreation()
+ {
+ return this.valueRecreation;
+ }
+
+ /**
+ * Create a persisted managed object
+ *
+ * @param mo the managed object
+ * @return the persistence xml meta data for managed object
+ */
+ public ManagedObject createManagedObject(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+
+ ManagedObjectPersistencePlugin plugin = getPlugin(persisted);
+ return plugin.createManagedObject(persisted);
+ }
+
+ /**
+ * 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 ManagedObject updateManagedObject(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(persisted);
+ return plugin.updateManagedObject(persisted, mo);
+ }
+
+ /**
* Extract the type name and get the plugin.
*
* @param mo the managed object
@@ -109,6 +167,23 @@
}
/**
+ * Get the plugin registered for persisted managed object.
+ *
+ * @param persisted the persisted managed object
+ * @return the ManagedObject recreation plugin
+ */
+ protected ManagedObjectPersistencePlugin 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);
+ }
+
+ /**
* Get the plugin.
*
* @param type the managed object type
@@ -130,14 +205,13 @@
*
* @param plugin the plugin to add
*/
- public void addPlugin(AbstractManagedObjectPersistencePlugin plugin)
+ public void addPlugin(ManagedObjectPersistencePlugin 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);
}
@@ -146,7 +220,7 @@
*
* @param plugin the plugin to remove
*/
- public void removePlugin(AbstractManagedObjectPersistencePlugin plugin)
+ public void removePlugin(ManagedObjectPersistencePlugin plugin)
{
if(plugin == null)
throw new IllegalArgumentException("Null plugin.");
@@ -156,14 +230,4 @@
this.plugins.remove(plugin.getType());
}
- public AbstractValuePersistence getValuePersistence()
- {
- return this.valuePersistence;
- }
-
- public void setValuePersistence(AbstractValuePersistence valuePersistence)
- {
- //
- }
-
}
Deleted: 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 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/DelegatingRecreationPlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,99 +0,0 @@
-/*
- * 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;
- }
-
-}
-
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/MOCreatorPlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,92 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.system.server.profileservice.persistence;
-
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
-import org.jboss.metadata.spi.MetaData;
-
-/**
- * ManagedObject creator plugin.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class MOCreatorPlugin
-{
-
- /** The classloader. */
- private ClassLoader loader;
-
- /** The managed object factory. */
- private ManagedObjectFactory managedObjectFactory;
-
- public MOCreatorPlugin()
- {
- this.managedObjectFactory = ManagedObjectFactoryBuilder.create();
- }
-
- public MOCreatorPlugin(ManagedObjectFactory managedObjectFactory)
- {
- this.managedObjectFactory = managedObjectFactory;
- }
-
- public ManagedObjectFactory getMOF()
- {
- return managedObjectFactory;
- }
-
- public void setMOF(ManagedObjectFactory managedObjectFactory)
- {
- this.managedObjectFactory = managedObjectFactory;
- }
-
- public ClassLoader getClassLoader()
- {
- if(this.loader == null)
- return Thread.currentThread().getContextClassLoader();
- return this.loader;
- }
-
- public void setClassLoader(ClassLoader classLoader)
- {
- this.loader = classLoader;
- }
-
- public ManagedObject createManagedObject(String clazz, MetaData metaData) throws Exception
- {
- return getMOF().createManagedObject(createManagedObjectClass(clazz), metaData);
- }
-
- public ManagedObject initManagedObject(Object o, MetaData metaData) throws Exception
- {
- return getMOF().initManagedObject(o, metaData);
- }
-
- protected Class<?> createManagedObjectClass(String clazz) throws Exception
- {
- return getClassLoader().loadClass(clazz);
- }
-
-}
-
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedGenericOverrideHandler.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,325 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.system.server.profileservice.persistence;
-
-import java.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;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.Stack;
-import java.util.WeakHashMap;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.config.plugins.property.PropertyConfiguration;
-import org.jboss.config.spi.Configuration;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.GenericValueSupport;
-import org.jboss.metatype.api.values.InstanceFactory;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.plugins.values.ListInstanceFactory;
-import org.jboss.metatype.plugins.values.SetInstanceFactory;
-import org.jboss.metatype.plugins.values.SortedSetInstanceFactory;
-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;
-
-/**
- * A handler for updating generic values.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ManagedGenericOverrideHandler extends ManagedObjectOverride
-{
-
- /** The instance factory builders */
- private Map<Class<?>, InstanceFactory<?>> instanceFactoryMap = new WeakHashMap<Class<?>, InstanceFactory<?>>();
-
- /** The merging stack. */
- private Stack<MergingProperties> properties = new Stack<MergingProperties>();
-
- /** The configuration */
- private static Configuration configuration;
-
- static
- {
- configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
- {
- public Configuration run()
- {
- return new PropertyConfiguration();
- }
- });
- }
-
- public ManagedGenericOverrideHandler()
- {
- // set default collection instance factories
- setInstanceFactory(List.class, ListInstanceFactory.INSTANCE);
- setInstanceFactory(Set.class, SetInstanceFactory.INSTANCE);
- setInstanceFactory(SortedSet.class, SortedSetInstanceFactory.INSTANCE);
- }
-
- public <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory)
- {
- synchronized(instanceFactoryMap)
- {
- if (factory == null)
- instanceFactoryMap.remove(clazz);
- else
- instanceFactoryMap.put(clazz, factory);
- }
- }
-
- @Override
- protected void processProperty(ManagedProperty property, PersistedProperty propertyElement, Object attachment,
- boolean trace) throws Throwable
- {
-
- if (property == null)
- throw new IllegalStateException("Null property");
-
- // The propertyInfo
- PropertyInfo info = property.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
- if(info.isReadable() == false)
- {
- log.trace("Skipping not readable property " + info);
- return;
- }
-
- // Push the merging item
- MergingProperties item = new MergingProperties(attachment, info, propertyElement);
- this.properties.push(item);
- try
- {
- super.processProperty(property, propertyElement, attachment, trace);
- }
- finally
- {
- this.properties.pop();
- }
- }
-
- @Override
- protected void setValue(ManagedProperty property, MetaValue value, Object attachment) throws Throwable
- {
- if(value == null)
- return;
-
- if (value.getMetaType().isGeneric())
- {
- // FIXME
- if(value.getMetaType().equals(GENERIC_PERSISTED_VALUE_TYPE))
- {
- // See if we need to recreate a managed object
- PersistedGenericValue moElement = (PersistedGenericValue) ((GenericValue) value).getValue();
- if (moElement.getManagedObject() == null)
- return;
-
- if (moElement.getManagedObject().getClassName() == null
- && moElement.getManagedObject().getTemplateName() == null)
- return;
-
- ManagedObject mo = createManagedObject(moElement.getManagedObject());
- value = new GenericValueSupport(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, mo);
- }
- }
- //
- super.setValue(property, value, attachment);
- }
-
-
- /**
- * Create a merged collection value.
- *
- * @param original the original collection
- * @param override the override collection
- * @return the merged collection
- * @throws Throwable
- */
- @Override
- protected CollectionValue mergeCollection(CollectionValue original, CollectionValue override, boolean trace)
- throws Throwable
- {
- CollectionMetaType metaType = original.getMetaType();
- if (metaType.getElementType().isGeneric())
- {
- // Check if the recreation was wrapping the correct value
-// CollectionMetaType overrideMetaType = override.getMetaType();
-// if(overrideMetaType.getElementType().equals(GENERIC_PERSISTED_VALUE_TYPE) == false)
-// throw new IllegalStateException("Wrong generic value type: " + overrideMetaType.getElementType());
-
-
- // Extract the information
- MergingProperties item = this.properties.peek();
- PropertyInfo propertyInfo = item.getPropertyInfo();
- Object attachment = item.getAttachment();
-
- if(propertyInfo.isWritable() == false)
- {
- log.debug("Ignoring not writable property: " + propertyInfo);
- return null;
- }
-
- // Extract original collection
- Collection<?> c = (Collection<?>) propertyInfo.get(attachment);
- // Skip
- if(c == null || c.isEmpty())
- return null;
-
-
- // This should not happen
- 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();
-
- // Create a new collection
- BeanInfo beanInfo = configuration.getBeanInfo(propertyInfo.getType());
- Collection newCollection = (Collection) createNewInstance(beanInfo);
-
- while (rawIterator.hasNext())
- {
- // The raw object
- Object o = rawIterator.next();
-
- // Skip generic values which are not annotated
- GenericValue originalGeneric = (GenericValue) originalIterator.next();
-
- // Extract the generic information
- GenericValue overrideGeneric = (GenericValue) overrideIterator.next();
- PersistedGenericValue overrideGenericValue = (PersistedGenericValue) overrideGeneric.getValue();
-
- // Skip not annotated managed objects
- if(originalGeneric.getValue() == null)
- {
- newCollection.add(o);
- continue;
- }
- // Remove a ManagedObject
- Object og = originalGeneric.getValue();
- if ((og instanceof ManagedObject))
- {
- ManagedObject originalMO = (ManagedObject) og;
- String name = originalMO.getName();
- if(removedNames.contains(name))
- continue;
- }
-
- // process the generic value
- processGenericValue(originalGeneric, overrideGenericValue, trace);
-
- newCollection.add(o);
- }
- propertyInfo.set(attachment, newCollection);
-
- // This does not need to get populated
- return null;
- }
- else
- {
- // Normal merge
- return super.mergeCollection(original, override, trace);
- }
- }
-
- @SuppressWarnings("deprecation")
- protected Object createNewInstance(BeanInfo beanInfo) throws Throwable
- {
- ClassInfo classInfo = beanInfo.getClassInfo();
- if (classInfo.isInterface())
- {
- InstanceFactory<?> instanceFactory = instanceFactoryMap.get(classInfo.getType());
- if (instanceFactory == null)
- throw new IllegalArgumentException("Cannot instantiate interface BeanInfo, missing InstanceFactory: " + classInfo);
-
- return instanceFactory.instantiate(beanInfo);
- }
- return beanInfo.newInstance();
- }
-
- public static class MergingProperties
- {
- /** The attachment. */
- private Object attachment;
-
- /** The managed object. */
- private PropertyInfo propertyInfo;
-
- /** The persisted property. */
- private PersistedProperty propertyElement;
-
- public MergingProperties(Object attachment, PropertyInfo info, PersistedProperty propertyElement)
- {
- this.attachment = attachment;
- this.propertyInfo = info;
- this.propertyElement = propertyElement;
- }
-
- public Object getAttachment()
- {
- return attachment;
- }
- public PropertyInfo getPropertyInfo()
- {
- return propertyInfo;
- }
- public PersistedProperty getPropertyElement()
- {
- return propertyElement;
- }
- }
-
-}
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectOverride.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,287 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.system.server.profileservice.persistence;
-
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-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.GenericValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.TableValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedValue;
-
-/**
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ManagedObjectOverride extends ManagedObjectRecreation
-{
-
- /** The logger. */
- protected static final Logger log = Logger.getLogger(ManagedObjectOverride.class);
-
- /** The attachment property populator. */
- private AttachmentPropertyPopulator populator = new AttachmentPropertyPopulator();
-
- public ManagedObject update(Object attachment, PersistedManagedObject element) throws Throwable
- {
- if (attachment == null)
- throw new IllegalArgumentException("Null attachment");
- if (element == null)
- throw new IllegalArgumentException("Null persisted information.");
-
- // The managed object
- ManagedObject mo = buildManagedObject(attachment);
-
- //
- if(mo == null)
- return null;
-
- // Update
- updateManagedObject(mo, element, attachment);
-
- return mo;
- }
-
- public void updateManagedObject(ManagedObject mo, PersistedManagedObject element, Object attachment)
- throws Throwable
- {
- if(mo == null)
- throw new IllegalArgumentException("Null managed object.");
- if(element == null)
- throw new IllegalArgumentException("Null persisted information.");
- //
- if(attachment == null)
- attachment = mo.getAttachment();
- if(attachment == null)
- throw new IllegalArgumentException("Null attachment.");
-
- boolean trace = log.isTraceEnabled();
-
- // Process properties
- for (PersistedProperty persisted : element.getProperties())
- {
- ManagedProperty property = mo.getProperty(persisted.getName());
- // Process
- processProperty(property, persisted, attachment, trace);
- }
- }
-
- protected void processProperty(ManagedProperty property, PersistedProperty propertyElement, Object attachment,
- boolean trace) throws Throwable
- {
- if (property == null)
- throw new IllegalStateException("Null property");
-
- // Get the original values
- MetaValue metaValue = property.getValue();
- MetaType metaType = property.getMetaType();
- if (metaValue != null)
- metaType = metaValue.getMetaType();
-
- //
- PersistedValue valueElement = propertyElement.getValue();
-
- // Recreate the metaValue
- MetaValue override = createMetaValue(valueElement, metaType);
-
- // Process
- MetaValue value = processMetaValue(metaValue, override, trace);
-
- //
- setValue(property, value, attachment);
- }
-
- protected void setValue(ManagedProperty property, MetaValue value, Object attachment)
- throws Throwable
- {
- // Skip null metaValues
- if(value == null)
- return;
-
- // Set the values
- property.setField(Fields.VALUE, value);
- // Update meta type
- property.setField(Fields.META_TYPE, value.getMetaType());
-
- // Populate the values
- populator.processManagedProperty(property.getName(), property, attachment);
- }
-
- protected MetaValue processMetaValue(MetaValue original, MetaValue override, boolean trace) throws Throwable
- {
- if (override == null)
- return original;
- if (original == null)
- return override;
-
- if (original.getMetaType() == null)
- throw new IllegalStateException("Original meta value is null " + original);
-
-
- // Now try to merge
- MetaType metaType = original.getMetaType();
- MetaValue metaValue = null;
- if (metaType.isSimple())
- {
- metaValue = override;
- }
- else if (metaType.isEnum())
- {
- metaValue = override;
- }
- else if (metaType.isCollection())
- {
- metaValue = mergeCollection(
- (CollectionValue) original,
- (CollectionValue) override, trace);
- }
- else if (metaType.isGeneric())
- {
- metaValue = mergeGenericValue(
- (GenericValue) original,
- (GenericValue) override, trace);
- }
- else if (metaType.isComposite())
- {
- metaValue = mergeCompositeValue(
- (CompositeValue) original,
- (CompositeValue) override, trace);
- }
- else if (metaType.isTable())
- {
- metaValue = mergeTableValue(
- (TableValue) original,
- (TableValue) override, trace);
- }
- else if (metaType.isArray())
- {
- metaValue = mergeArray(
- (ArrayValue) original,
- (ArrayValue) override, trace);
- }
- else
- {
- throw new IllegalStateException("unknown metaType");
- }
- return metaValue;
- }
-
- /**
- * Merge a composite value.
- *
- * @param original
- * @param override
- * @return
- */
- protected CompositeValue mergeCompositeValue(CompositeValue original, CompositeValue override, boolean trace)
- {
- return override;
- }
-
- /**
- * Merge a table
- *
- * @param original
- * @param override
- * @return
- */
- protected TableValue mergeTableValue(TableValue original, TableValue override, boolean trace)
- {
- return override;
- }
-
- /**
- * Create a merged array value.
- *
- * @param original the original array
- * @param override the override array
- * @return the merged array
- */
- protected ArrayValue mergeArray(ArrayValue original, ArrayValue override, boolean trace)
- {
- return override;
- }
-
- /**
- * Create a merged collection value.
- *
- * @param original the original collection
- * @param override the override collection
- * @return the merged collection
- * @throws Throwable
- */
- protected CollectionValue mergeCollection(CollectionValue original, CollectionValue override, boolean trace)
- throws Throwable
- {
- return override;
- }
-
- /**
- * Merge a generic value.
- *
- * @param original the original generic value
- * @param override the override generic value
- * @return the merged value
- */
- protected GenericValue mergeGenericValue(GenericValue original, GenericValue override, boolean trace)
- throws Throwable
- {
- Object v = override.getValue();
- if (v instanceof PersistedGenericValue)
- {
- PersistedGenericValue moElement = (PersistedGenericValue) override.getValue();
-
- return processGenericValue(original, moElement, trace);
- }
- // Don't do anything
- return null;
- }
-
- protected GenericValue processGenericValue(GenericValue original, PersistedGenericValue override, boolean trace)
- throws Throwable
- {
- // Don't do anything
- if(override.getManagedObject() == null)
- return null;
-
- Object o = original.getValue();
- if ((o instanceof ManagedObject))
- {
- ManagedObject originalMO = (ManagedObject) o;
-
- // process
- updateManagedObject(originalMO, override.getManagedObject(), originalMO.getAttachment());
- return original;
- }
- throw new RuntimeException("Cannot merge original: " + original + ", override: " + override);
- }
-
-}
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPeristenceHandler.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,80 +0,0 @@
-/*
- * 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;
-
-/**
- * Create a xml representation of a Managed Object.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ManagedObjectPeristenceHandler
-{
-
- /** . */
- private final ManagedObjectPersistencePlugin plugin;
-
- public ManagedObjectPeristenceHandler()
- {
- this.plugin = new DelegatingPersistencePlugin();
- }
-
- /**
- * Create the persistence meta data for a ManagedObject.
- *
- * @param mo the managed object
- * @return the persistence meta data
- */
- public PersistedManagedObject createPersistenceMetaData(ManagedObject mo)
- {
- if(mo == null)
- throw new IllegalArgumentException("Null managedObject.");
-
- return getPlugin().createPersistedManagedObject(mo);
- }
-
- /**
- * Process a managed object.
- *
- * @param moElement the xml meta data.
- * @param mo the managed object
- * @return isModified
- */
- public void processManagedObject(PersistedManagedObject persisted, ManagedObject mo)
- {
- if(persisted == null)
- throw new IllegalArgumentException("Null rootElement.");
- if(mo == null)
- throw new IllegalArgumentException("null managedObject");
-
- getPlugin().createPersistedManagedObject(persisted, mo);
- }
-
- protected ManagedObjectPersistencePlugin getPlugin()
- {
- return this.plugin;
- }
-
-}
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectPersistencePlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -25,6 +25,9 @@
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
/**
+ * The managed object persistence plugin, handling the persistence
+ * of a ManagedObject.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -32,18 +35,25 @@
{
/**
+ * Get the plugin type.
+ *
+ * @return the type
+ */
+ String getType();
+
+ /**
* Get the value persistence.
*
* @return the value persistence
*/
- AbstractValuePersistence getValuePersistence();
+ AbstractValuePersistence getValuePersistence();
/**
- * Set the value persistence.
+ * Get the value recreation.
*
- * @param valuePersistence the value persistence
+ * @return the value recreation
*/
- void setValuePersistence(AbstractValuePersistence valuePersistence);
+ AbstractValueRecreation getValueRecreation();
/**
* Create a persisted managed object
@@ -62,4 +72,21 @@
*/
PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo);
+ /**
+ * Create a managed object, based on the persisted information.
+ *
+ * @param persisted the persisted managed object
+ * @return the managed object
+ */
+ ManagedObject createManagedObject(PersistedManagedObject persisted);
+
+ /**
+ * Update a managed object, based on the persisted information.
+ *
+ * @param persisted the persisted managed object
+ * @param mo the managed object
+ * @return the managed object
+ */
+ ManagedObject updateManagedObject(PersistedManagedObject persisted, ManagedObject mo);
+
}
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreation.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreation.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreation.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,595 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.system.server.profileservice.persistence;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.MutableManagedObject;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.EnumMetaType;
-import org.jboss.metatype.api.types.GenericMetaType;
-import org.jboss.metatype.api.types.MapCompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.Name;
-import org.jboss.metatype.api.types.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.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;
-
-/**
- * This handler recreates only the ManagedObject based on the persisted meta data.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ManagedObjectRecreation
-{
- /** The generic type of a persisted generic value */
- public final static GenericMetaType GENERIC_PERSISTED_VALUE_TYPE = new GenericMetaType(PersistedGenericValue.class.getName(), "persisted generic value");
-
- /** The meta data. */
- private MetaData metaData;
-
- /** The plugin. */
- private MOCreatorPlugin plugin;
-
- /** The simple types. */
- private final static Map<String, Class<? extends Serializable>> simpleTypes = new HashMap<String, Class<? extends Serializable>>();
-
- /** The logger. */
- private final static Logger log = Logger.getLogger(ManagedObjectRecreation.class);
-
- static
- {
- // Fill simple types map.
- simpleTypes.put(BigDecimal.class.getName(), BigDecimal.class);
- simpleTypes.put(BigInteger.class.getName(), BigInteger.class);
- simpleTypes.put(Boolean.class.getName(), Boolean.class);
- simpleTypes.put(Byte.class.getName(), Byte.class);
- simpleTypes.put(Character.class.getName(), Character.class);
- simpleTypes.put(Date.class.getName(), Date.class);
- simpleTypes.put(Double.class.getName(), Double.class);
- simpleTypes.put(Float.class.getName(), Float.class);
- simpleTypes.put(Integer.class.getName(), Integer.class);
- simpleTypes.put(Long.class.getName(), Long.class);
- simpleTypes.put(Short.class.getName(), Short.class);
- simpleTypes.put(String.class.getName(), String.class);
- simpleTypes.put(Name.class.getName(), Name.class);
- // 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 ManagedObjectRecreation()
- {
- this.plugin = new MOCreatorPlugin();
- }
-
- protected ManagedObject createManagedObject(PersistedManagedObject moElement) throws Exception
- {
- if(moElement == null)
- throw new IllegalArgumentException("Null persisted meta data.");
- if(moElement.getClassName() == null)
- throw new IllegalArgumentException("Null class-name for managed object.");
-
- // Check if we need to use a template for the managed object
- String className = moElement.getTemplateName();
- if(className == null)
- {
- className = moElement.getClassName();
- }
- ManagedObject mo = buildManagedObject(className);
-
-
- if(mo instanceof MutableManagedObject)
- {
- // Update the name
- ((MutableManagedObject) mo).setName(moElement.getName());
-
- if(moElement.getTemplateName() != null)
- {
- // Override the actual attachment
- Class<?> attachment = plugin.getClassLoader().loadClass(moElement.getClassName());
- ((MutableManagedObject) mo).setAttachment(attachment.newInstance());
- }
- }
-
- // Process
- processManagedObject(moElement, mo);
-
- // Return
- return mo;
- }
-
- /**
- * Process a ManagedObject.
- *
- * @param moElement the persisted xml meta data.
- * @param mo the managed object
- * @return the attachment meta data.
- */
- private void processManagedObject(PersistedManagedObject moElement, ManagedObject mo)
- {
- if(moElement == null)
- throw new IllegalArgumentException("Null rootElement.");
- if(mo == null)
- throw new IllegalArgumentException("null managedObject");
-
- // Get the xml to see what we need to merge
- if(moElement.getProperties() != null && moElement.getProperties().isEmpty() == false)
- {
- for(PersistedProperty propertyElement : moElement.getProperties())
- {
- ManagedProperty property = mo.getProperty(propertyElement.getName());
- if(property == null)
- throw new IllegalStateException("unable to find propery: "+ property);
-
- // Skip all non configuration properties
- if(! property.hasViewUse(ViewUse.CONFIGURATION))
- continue;
-
- // getProperty
- processManagedProperty(propertyElement, propertyElement.getName(), property, mo.getAttachment());
- }
- }
- }
-
- /**
- * Build a managed object based on the attachment.
- *
- * @param attachment the attachment
- * @return the ManagedObject
- * @throws Exception
- */
- protected ManagedObject buildManagedObject(Object attachment) throws Exception
- {
- return plugin.initManagedObject(attachment, null);
- }
-
-
- /**
- * Build a managedObject based on the className
- *
- * @param className the name of the class
- * @return the ManagedObject
- * @throws Exception
- */
- protected ManagedObject buildManagedObject(String className) throws Exception
- {
- return plugin.createManagedObject(className, metaData);
- }
-
- /**
- * Process a ManagedProperty.
- *
- * @param propertyElement the persisted xml meta data.
- * @param name the property name.
- * @param property the managed property.
- */
- protected void processManagedProperty(PersistedProperty propertyElement, String name, ManagedProperty property, Object attachment)
- {
- // Get MetaType
- MetaType metaType = property.getMetaType();
- // Process the value
- PersistedValue persistedValue = propertyElement.getValue();
- if(persistedValue != null)
- {
- // recurse = true
- MetaValue value = createMetaValue(persistedValue, metaType);
- // Set the value Field
- property.setField(Fields.VALUE, value);
- // Update meta type
- if(value != null)
- property.setField(Fields.META_TYPE, value.getMetaType());
- }
- // Done
- }
-
- /**
- * Create the meta value, based on the xml persited
- * value and the generated MetaType.
- *
- * @param valueElement the persisted xml element
- * @param type the meta type.
- * @return the created meta value.
- */
- protected MetaValue createMetaValue(PersistedValue valueElement, MetaType metaType)
- {
- if(log.isTraceEnabled())
- {
- log.trace("processing value " + valueElement + " type: " + metaType);
- }
-
- if(valueElement 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()));
- }
- }
- // Generic values are getting wrapped differently
- if(type.isGeneric())
- {
- type = new CollectionMetaType(type.getClassName(), "", GENERIC_PERSISTED_VALUE_TYPE);
- }
- return new CollectionValueSupport(type, elementList.toArray(new MetaValue[elementList.size()]));
- }
-
- /**
- * Create generic value.
- *
- * @param genericElement the persisted generic xml meta data
- * @param metaType the generic meta type
- * @return the generic value
- */
- protected GenericValue createGenericValue(PersistedGenericValue genericElement, GenericMetaType metaType)
- {
- // If we don't recurse, someone else needs to extract the managed object
- return new GenericValueSupport(GENERIC_PERSISTED_VALUE_TYPE, genericElement);
- }
-
- /**
- * 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;
- }
-
- 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;
- }
- }
-
-}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHelper.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHelper.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationHelper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+
+/**
+ * A recreation helper.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ManagedObjectRecreationHelper
+{
+
+ /** The loader. */
+ private final ThreadLocal<ClassLoader> loader = new ThreadLocal<ClassLoader>();
+
+ /** The managed object factory. */
+ private final ManagedObjectFactory mangedObjectFactory;
+
+ /** The attachment property populator. */
+ private final AttachmentPropertyPopulator attachmentPopulator;
+
+ public ManagedObjectRecreationHelper(ManagedObjectFactory mangedObjectFactory)
+ {
+ if(mangedObjectFactory == null)
+ throw new IllegalArgumentException("null managed object factory");
+
+ this.mangedObjectFactory = mangedObjectFactory;
+ this.attachmentPopulator = new AttachmentPropertyPopulator(mangedObjectFactory, this);
+ }
+
+ public ClassLoader getLoader()
+ {
+ return this.loader.get();
+ }
+
+ public void setLoader(ClassLoader loader)
+ {
+ this.loader.set(loader);
+ }
+
+ /**
+ * Set a value to a managed property. This delegates
+ * to the AttachmentPropertyPopulator.
+ *
+ * @param name the property name
+ * @param property the managed property
+ * @param attachment the attachment
+ * @throws Throwable for any erro
+ */
+ public void setValue(String name, ManagedProperty property, Object attachment) throws Throwable
+ {
+ attachmentPopulator.processManagedProperty(name, property, attachment);
+ }
+
+ /**
+ * Create a ManagedObject skeleton based on a class name.
+ *
+ * @param className the class name
+ * @return the ManagedObject, null if the class has no ManagementObject annotations
+ * @throws ClassNotFoundException
+ */
+ protected ManagedObject createManagedObjectSkeleton(String className) throws ClassNotFoundException
+ {
+ Class<?> clazz = loadClass(className);
+ return mangedObjectFactory.createManagedObject(clazz);
+ }
+
+ /**
+ * Load class.
+ *
+ * @param className the class name
+ * @return the class
+ * @throws ClassNotFoundException
+ */
+ protected Class<?> loadClass(String className) throws ClassNotFoundException
+ {
+ ClassLoader cl = getLoader();
+ if(cl == null)
+ cl = SecurityActions.getContextClassLoader();
+ return cl.loadClass(className);
+ }
+
+ private static final class SecurityActions
+ {
+ public static ClassLoader getContextClassLoader()
+ {
+ if (System.getSecurityManager() == null)
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ }
+ }
+ }
+
+}
+
Deleted: 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 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRecreationPlugin.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,60 +0,0 @@
-/*
- * 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);
-
-}
-
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/ManagedObjectRemoveHandler.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,88 +0,0 @@
-/*
- * 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.ManagedCommon;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
-
-/**
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class ManagedObjectRemoveHandler extends ManagedObjectPeristenceHandler
-{
-
- /** 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 ManagedObjectPersistencePlugin getPlugin()
- {
- return this.plugin;
- }
-
- public class RemovePlugin extends DefaultPersistencePlugin
- {
-
- @Override
- public PersistedManagedObject createPersistedManagedObject(PersistedManagedObject persisted, ManagedObject mo)
- {
- if(mo != null)
- {
- if(mo.getName() == removeItem.getName())
- {
- persisted.setModificationInfo(ModificationInfo.REMOVED);
- return persisted;
- }
- else
- {
- return super.createPersistedManagedObject(persisted, mo);
- }
- }
- else
- {
- return super.createPersistedManagedObject(persisted, mo);
- }
- }
-
- @Override
- public String getType()
- {
- return null;
- }
- }
-
-}
Copied: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceConstants.java (from rev 88417, branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java)
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceConstants.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceConstants.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * The PersistenceConstants.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class PersistenceConstants
+{
+
+ /** The repository xml namespace. */
+ public static final String REPOSITORY_NAMESPACE_1_0 = "urn:org:jboss:profileservice:attachments:1.0";
+
+ /** The component xml namespace. */
+ public static final String COMPONENT_NAMESPACE_1_0 = "urn:org:jboss:profileservice:persistence:managed-component:1.0";
+
+ /** The managed-object name. */
+ public static final String MANAGED_OBJECT_ELEMENT_NAME = "managed-object";
+
+ /** The managed-component name. */
+ public static final String MANAGED_COMPONENT_ELEMENT_NAME = "managed-component";
+
+}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceFactory.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceFactory.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/PersistenceFactory.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
+
+/**
+ * The persistence factory.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class PersistenceFactory
+{
+
+ /** The managed object factory. */
+ private final ManagedObjectFactory managedObjectFactory;
+
+ protected PersistenceFactory(ManagedObjectFactory managedObjectFactory)
+ {
+ if(managedObjectFactory == null)
+ throw new IllegalArgumentException("null managed object factory");
+ //
+ this.managedObjectFactory = managedObjectFactory;
+ }
+
+ /**
+ * Get the managed object factory.
+ *
+ * @return the manged object factory
+ */
+ public ManagedObjectFactory getManagedObjectFactory()
+ {
+ return managedObjectFactory;
+ }
+
+ /**
+ * Get the persistence plugin.
+ *
+ * @return the persistence plugin
+ */
+ public abstract ManagedObjectPersistencePlugin getPersistencePlugin();
+
+ /**
+ * Apply the persisted information to a attachment.
+ *
+ * @param root the persistence root
+ * @param attachment the root attachment
+ * @param classLoader the classloader
+ */
+ public abstract void restorePersistenceRoot(PersistenceRoot root, Object attachment, ClassLoader classLoader);
+
+ /**
+ * Add a ManagedComponent.
+ *
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public PersistenceRoot addComponent(ManagedObject parent, ManagedComponent component)
+ {
+ if(parent == null)
+ throw new IllegalArgumentException("null parent managed object");
+ if(component == null)
+ throw new IllegalArgumentException("null managed component");
+
+ PersistenceRoot root = new PersistenceRoot();
+ return addComponent(root, parent, component);
+ }
+
+ /**
+ * Add a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public abstract PersistenceRoot addComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component);
+
+ /**
+ * Update a ManagedComponent.
+ *
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public PersistenceRoot updateComponent(ManagedObject parent, ManagedComponent component)
+ {
+ if(parent == null)
+ throw new IllegalArgumentException("null parent managed object");
+ if(component == null)
+ throw new IllegalArgumentException("null managed component");
+
+ PersistenceRoot root = new PersistenceRoot();
+ return updateComponent(root, parent, component);
+ }
+
+ /**
+ * Update a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public abstract PersistenceRoot updateComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component);
+
+ /**
+ * Remove a ManagedComponent.
+ *
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public PersistenceRoot removeComponent(ManagedObject parent, ManagedComponent component)
+ {
+ if(parent == null)
+ throw new IllegalArgumentException("null parent managed object");
+ if(component == null)
+ throw new IllegalArgumentException("null managed component");
+
+ PersistenceRoot root = new PersistenceRoot();
+ return removeComponent(root, parent, component);
+ }
+
+ /**
+ * Remove a ManagedComponent.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public abstract PersistenceRoot removeComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component);
+
+ /**
+ * Reset a component. This will remove the persisted information.
+ *
+ * @param root the persistence root
+ * @param parent the parent managed object
+ * @param component the managed component
+ * @return the updated persistence root
+ */
+ public abstract PersistenceRoot resetComponent(PersistenceRoot root, ManagedObject parent, ManagedComponent component);
+
+}
+
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/AbstractComponentMapper.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/AbstractComponentMapper.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/AbstractComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,189 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence.component;
+
+import java.util.ArrayList;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPersistencePlugin;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
+
+/**
+ * The abstract component mapper.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractComponentMapper implements ComponentMapper
+{
+
+ /** The persistence factory. */
+ private final PersistenceFactory persistenceFactory;
+
+ public AbstractComponentMapper(PersistenceFactory persistenceFactory)
+ {
+ if(persistenceFactory == null)
+ throw new IllegalArgumentException("null persistence factory");
+
+ this.persistenceFactory = persistenceFactory;
+ }
+
+ public ManagedObjectPersistencePlugin getPersistencePlugin()
+ {
+ return persistenceFactory.getPersistencePlugin();
+ }
+
+ public ManagedObjectFactory getMOF()
+ {
+ return persistenceFactory.getManagedObjectFactory();
+ }
+
+ public void restoreComponent(Object attachment, PersistedComponent component)
+ {
+ if(attachment == null)
+ throw new IllegalArgumentException("null attachment");
+ if(component == null)
+ throw new IllegalArgumentException("null component");
+
+ // Check what we need to do
+ ModificationInfo modification = component.getModificationInfo();
+ if(modification == null)
+ modification = ModificationInfo.MODIFIED;
+ switch(modification)
+ {
+ case ADDED:
+ updateComponent(attachment, component, true);
+ break;
+ case MODIFIED:
+ updateComponent(attachment, component, false);
+ break;
+ case REMOVED:
+ removeComponent(attachment, component);
+ break;
+ }
+ }
+
+ public PersistedComponent addComponent(Object attachment, ManagedComponent component)
+ {
+ return createPersistedComponent(attachment, component, ModificationInfo.ADDED);
+ }
+
+ public PersistedComponent updateComponent(Object attachment, ManagedComponent component)
+ {
+ return createPersistedComponent(attachment, component, ModificationInfo.MODIFIED);
+ }
+
+ public PersistedComponent removeComponent(Object attachment, ManagedComponent component)
+ {
+ PersistedComponent persisted = createPersistedComponent(attachment, component, ModificationInfo.REMOVED);
+ // FIXME cleanup properties, as they are not need for removed components
+ persisted.setProperties(new ArrayList<PersistedProperty>());
+ return persisted;
+ }
+
+ /**
+ * Remove a component from the attachment.
+ *
+ * @param attachment the attachment
+ * @param component the component to remove
+ */
+ protected abstract void removeComponent(Object attachment, PersistedComponent component);
+
+ /**
+ * Get a ManagedObject for a given component, based on the information
+ * in the attachment descriptor.
+ *
+ * @param attachment the attachment
+ * @param component the component
+ * @param create whether to create a non existing component or not
+ * @return the managed object for the component
+ */
+ protected abstract ManagedObject getComponent(Object attachment, PersistedComponent component, boolean create);
+
+ /**
+ * Create the persisted information for a given ManagedComponent.
+ *
+ * @param attachment the attachment
+ * @param component the managed component
+ * @return the persisted component
+ */
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // ManagedObject mo = component.getDeployment().getManagedObject(component.getName());
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persisted = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persistedComponent = new PersistedComponent(persisted);
+ setComponentName(persistedComponent, mo);
+ return persistedComponent;
+ }
+
+ /**
+ * Set the current name for this component.
+ *
+ * @param component the persisted component
+ * @param mo the managed object
+ */
+ protected abstract void setComponentName(PersistedComponent component, ManagedObject mo);
+
+ /**
+ * Update a attachment descriptor based on the persisted
+ * component information.
+ *
+ * @param attachment the attachment
+ * @param component the persisted component
+ * @param added whether this component was added or not
+ */
+ protected void updateComponent(Object attachment, PersistedComponent component, boolean added)
+ {
+ ManagedObject mo = getComponent(attachment, component, added);
+ getPersistencePlugin().updateManagedObject(component, mo);
+ }
+
+ /**
+ * Create a persisted component for a given ManagedComponent.
+ *
+ * @param attachment the attachment
+ * @param component the managed component
+ * @param modification the modification info
+ * @return the persisted component
+ */
+ protected PersistedComponent createPersistedComponent(Object attachment, ManagedComponent component, ModificationInfo modification)
+ {
+ if(attachment == null)
+ throw new IllegalArgumentException("null attachment");
+ if(component == null)
+ throw new IllegalArgumentException("null component");
+ if(modification == null)
+ throw new IllegalArgumentException("null modification info");
+ // Create the component and set the modification information
+ PersistedComponent persisted = createComponent(attachment, component);
+ persisted.setModificationInfo(modification);
+ return persisted;
+ }
+
+}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapper.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapper.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence.component;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public interface ComponentMapper
+{
+
+ /**
+ * Get the component mapper type.
+ *
+ * @return the type
+ */
+ String getType();
+
+ /**
+ * Restore a component based on the persisted information.
+ *
+ * @param attachment the attachment
+ * @param component the persisted component
+ */
+ void restoreComponent(Object attachment, PersistedComponent component);
+
+ /**
+ * Add a component.
+ *
+ * @param attachment the parent attachment
+ * @param component the managed component
+ * @return the persisted managed component
+ */
+ PersistedComponent addComponent(Object attachment, ManagedComponent component);
+
+ /**
+ * Update a component.
+ *
+ * @param attachment the parent attachment
+ * @param component the managed component
+ * @return the persisted managed component
+ */
+ PersistedComponent updateComponent(Object attachment, ManagedComponent component);
+
+ /**
+ * Remove a component.
+ *
+ * @param attachment the parent attachment
+ * @param component the managed component
+ * @return the persisted managed component
+ */
+ PersistedComponent removeComponent(Object attachment, ManagedComponent component);
+
+}
+
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapperRegistry.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapperRegistry.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/component/ComponentMapperRegistry.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence.component;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * A component mapper registry.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ComponentMapperRegistry
+{
+
+ /** The instance. */
+ private static final ComponentMapperRegistry INSTANCE = new ComponentMapperRegistry();
+
+ /** The component mapper map. */
+ private final Map<String, ComponentMapper> map = new ConcurrentHashMap<String, ComponentMapper>();
+
+ protected ComponentMapperRegistry()
+ {
+ //
+ }
+
+ public static ComponentMapperRegistry getInstance()
+ {
+ return INSTANCE;
+ }
+
+ /**
+ * Get a component mapper.
+ *
+ * @param name the mapper type
+ * @return the mapper or null if not registered
+ */
+ public ComponentMapper getMapper(String name)
+ {
+ if(name == null)
+ throw new IllegalArgumentException("null name");
+
+ return this.map.get(name);
+ }
+
+ /**
+ * Add a component mapper.
+ *
+ * @param mapper the component mapper
+ */
+ public void addMapper(ComponentMapper mapper)
+ {
+ if(mapper == null)
+ throw new IllegalArgumentException("null mapper");
+ if(mapper.getType() == null)
+ throw new IllegalArgumentException("null mapper type");
+
+ this.map.put(mapper.getType(), mapper);
+ }
+
+ /**
+ * Remove a component mapper.
+ *
+ * @param mapper the component mapper
+ * @return the previous mapper or null
+ */
+ public ComponentMapper removeComponentMapper(ComponentMapper mapper)
+ {
+ if(mapper == null)
+ throw new IllegalArgumentException("null mapper");
+ if(mapper.getType() == null)
+ throw new IllegalArgumentException("null mapper type");
+
+ return this.map.remove(mapper.getType());
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/deployer/ProfileServicePersistenceDeployer.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -28,11 +28,8 @@
import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.logging.Logger;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
/**
* The ProfileService Persistence Deployer. This deployer applies the
@@ -47,12 +44,9 @@
/** The managed prefix. */
public static final String PERSISTED_ATTACHMENT_PREFIX = "PERISTED";
- /** The managed object override handler. */
- private ManagedGenericOverrideHandler overrideHandler = new ManagedGenericOverrideHandler();
+ /** The persistence factory. */
+ private PersistenceFactory persistenceFactory;
- /** The managed object factory. */
- private ManagedObjectFactory factory = ManagedObjectFactory.getInstance();
-
/** The Logger. */
private static final Logger log = Logger.getLogger(ProfileServicePersistenceDeployer.class);
@@ -63,14 +57,14 @@
setStage(DeploymentStages.PRE_REAL);
}
- public ManagedObjectFactory getManagedObjectFactory()
+ public PersistenceFactory getPersistenceFactory()
{
- return factory;
+ return persistenceFactory;
}
- public void setManagedObjectFactory(ManagedObjectFactory factory)
+ public void setPersistenceFactory(PersistenceFactory persistenceFactory)
{
- this.factory = factory;
+ this.persistenceFactory = persistenceFactory;
}
@Override
@@ -79,28 +73,21 @@
// Check all attachments, if they have a managed attachment
// TODO there might be a better way to do that ? :)
Set<String> attachments = unit.getTransientManagedObjects().getAttachments().keySet();
- for(String attachment : attachments)
+ for(String attachmentName : attachments)
{
- PersistedManagedObject persistedManagedObject = (PersistedManagedObject) unit.getAttachment(PERSISTED_ATTACHMENT_PREFIX + attachment);
-
- if(persistedManagedObject != null)
+ // Get the persisted information
+ PersistenceRoot root = (PersistenceRoot) unit.getAttachment(PERSISTED_ATTACHMENT_PREFIX + attachmentName);
+ if(root != null)
{
// Get the transient attachment
- Object instance = unit.getTransientManagedObjects().getAttachment(attachment);
+ Object instance = unit.getTransientManagedObjects().getAttachment(attachmentName);
try
{
- MetaData metaData = unit.getMetaData();
- ManagedObject original = factory.initManagedObject(instance, metaData);
-
- // Update the attachment
- overrideHandler.updateManagedObject(original, persistedManagedObject, instance);
-
- // Override
- unit.addAttachment(attachment, original.getAttachment());
+ getPersistenceFactory().restorePersistenceRoot(root, instance, unit.getClassLoader());
}
catch(Throwable e)
{
- log.debug("Failed to update the persisted attachment information", e);
+ log.warn("Failed to update the persisted attachment information", e);
}
}
}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedComponent.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedComponent.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedComponent.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence.xml;
+
+/**
+ * A persisted managed component.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class PersistedComponent extends PersistedManagedObject
+{
+
+ public PersistedComponent()
+ {
+ //
+ }
+
+ public PersistedComponent(PersistedManagedObject persisted)
+ {
+ if(persisted == null)
+ throw new IllegalArgumentException("null persisted managed object");
+
+ setName(persisted.getName());
+ setClassName(persisted.getClassName());
+ setProperties(persisted.getProperties());
+ setOriginalName(persisted.getOriginalName());
+ setTemplateName(persisted.getTemplateName());
+ // TODO the modificationInfo should be handled here
+ setModificationInfo(persisted.getModificationInfo());
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedCompositeValue.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -36,7 +36,7 @@
{
/** The values */
- List<PersistedValue> values;
+ private List<PersistedValue> values;
@XmlElements( value = {
@XmlElement(name = "null", type = NullValue.class),
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedGenericValue.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,10 +21,8 @@
*/
package org.jboss.system.server.profileservice.persistence.xml;
-import static org.jboss.system.server.profileservice.persistence.xml.PersistenceConstants.MANAGED_OBJECT_ELEMENT_NAME;
+import static org.jboss.system.server.profileservice.persistence.PersistenceConstants.MANAGED_OBJECT_ELEMENT_NAME;
-import java.io.Serializable;
-
import javax.xml.bind.annotation.XmlElement;
/**
@@ -33,12 +31,9 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-public class PersistedGenericValue extends AbstractPersisitedValue implements PersistedValue, Serializable
+public class PersistedGenericValue extends AbstractPersisitedValue implements PersistedValue
{
- /** The serialVersionUID */
- private static final long serialVersionUID = -6858198681439447173L;
-
/** A managed-object. */
private PersistedManagedObject managedObject;
@@ -53,14 +48,6 @@
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());
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistedManagedObject.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,7 +21,7 @@
*/
package org.jboss.system.server.profileservice.persistence.xml;
-import static org.jboss.system.server.profileservice.persistence.xml.PersistenceConstants.MANAGED_OBJECT_ELEMENT_NAME;
+import static org.jboss.system.server.profileservice.persistence.PersistenceConstants.MANAGED_OBJECT_ELEMENT_NAME;
import java.util.List;
@@ -32,6 +32,7 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
import org.jboss.xb.annotations.JBossXmlSchema;
/**
@@ -40,9 +41,9 @@
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
- at JBossXmlSchema(namespace = PersistenceConstants.NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED)
+ at JBossXmlSchema(namespace = PersistenceConstants.COMPONENT_NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED)
@XmlRootElement(name = MANAGED_OBJECT_ELEMENT_NAME)
- at XmlType(propOrder = {"originalName", "templateName", "modificationInfo", "properties"})
+ at XmlType(propOrder = {"originalName", "templateName", "properties"})
public class PersistedManagedObject extends AbstractElement
{
@@ -56,6 +57,7 @@
private List<PersistedProperty> properties;
/** The modification info. */
+ // TODO this should be in PersistedComponent
private ModificationInfo modificationInfo;
public PersistedManagedObject()
@@ -84,26 +86,26 @@
this.templateName = templateName;
}
- @XmlAttribute(name = "modification")
- public ModificationInfo getModificationInfo()
+ @XmlAttribute(name = "original-name")
+ public String getOriginalName()
{
- return this.modificationInfo;
+ return originalName;
}
- public void setModificationInfo(ModificationInfo info)
+ public void setOriginalName(String originalName)
{
- this.modificationInfo = info;
+ this.originalName = originalName;
}
- @XmlElement(name = "orignal-name")
- public String getOriginalName()
+ @XmlAttribute(name = "modification")
+ public ModificationInfo getModificationInfo()
{
- return originalName;
+ return this.modificationInfo;
}
- public void setOriginalName(String originalName)
+ public void setModificationInfo(ModificationInfo info)
{
- this.originalName = originalName;
+ this.modificationInfo = info;
}
@XmlElementWrapper(name="properties")
Deleted: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceConstants.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -1,39 +0,0 @@
-/*
- * 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;
-
-/**
- * The PersistenceConstants.
- *
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class PersistenceConstants
-{
-
- /** The xml namespace. */
- public static final String NAMESPACE_1_0 = "urn:org:jboss:profileservice:persistence:managed-object:1.0";
-
- /** The managed-object name. */
- public static final String MANAGED_OBJECT_ELEMENT_NAME = "managed-object";
-
-}
Added: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceRoot.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceRoot.java (rev 0)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/PersistenceRoot.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.system.server.profileservice.persistence.xml;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * The attachment persistence xml root.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at JBossXmlSchema(namespace = PersistenceConstants.COMPONENT_NAMESPACE_1_0, elementFormDefault = XmlNsForm.QUALIFIED)
+ at XmlRootElement(name = "root")
+ at XmlType(propOrder = {"components"})
+public class PersistenceRoot
+{
+
+ /** The components. */
+ private List<PersistedComponent> components;
+
+ @XmlElement(name = "component")
+ public List<PersistedComponent> getComponents()
+ {
+ return components;
+ }
+
+ public void setComponents(List<PersistedComponent> components)
+ {
+ this.components = components;
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/persistence/xml/package-info.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -19,7 +19,7 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
- at XmlSchema(namespace = "urn:org:jboss:profileservice:persistence:managed-object:1.0",
+ at XmlSchema(namespace = "urn:org:jboss:profileservice:persistence:managed-component:1.0",
elementFormDefault = XmlNsForm.QUALIFIED,
xmlns = { @XmlNs(namespaceURI = "http://www.w3.org/2001/XMLSchema", prefix = "xs") }
)
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/AbstractAttachmentStore.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -57,9 +57,8 @@
import org.jboss.system.server.profileservice.attachments.LazyPredeterminedManagedObjects;
import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaDataFactory;
-import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
-import org.jboss.system.server.profileservice.persistence.ManagedObjectRemoveHandler;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VirtualFileFilter;
@@ -71,6 +70,7 @@
*/
public class AbstractAttachmentStore implements AttachmentStore
{
+
/** The attachment store root. */
private final URI attatchmentStoreRoot;
@@ -89,8 +89,8 @@
/** The metadata name */
public static final String METADATA_NAME = "metadata";
- /** The managed object persistence handler. */
- private static final ManagedObjectPeristenceHandler handler = new ManagedObjectPeristenceHandler();
+ /** The persistence factory. */
+ private PersistenceFactory persistenceFactory;
/** The logger. */
private static final Logger log = Logger.getLogger(AbstractAttachmentStore.class);
@@ -119,6 +119,16 @@
this.deploymentFactory = deploymentFactory;
}
+ public PersistenceFactory getPersistenceFactory()
+ {
+ return persistenceFactory;
+ }
+
+ public void setPersistenceFactory(PersistenceFactory persistenceFactory)
+ {
+ this.persistenceFactory = persistenceFactory;
+ }
+
public MainDeployerStructure getMainDeployer()
{
return mainDeployer;
@@ -309,8 +319,7 @@
throw new IllegalArgumentException("Null managed component.");
// Create the remove handler
- ManagedObjectRemoveHandler removeHandler = new ManagedObjectRemoveHandler(comp);
- updateDeployment(deployment, comp, removeHandler);
+ updateDeployment(deployment, comp, true);
}
@@ -330,19 +339,17 @@
return;
// Update deployment
- updateDeployment(deployment, comp, handler);
+ updateDeployment(deployment, comp, false);
}
- public void updateDeployment(ProfileDeployment deployment, ManagedComponent comp, ManagedObjectPeristenceHandler persistenceHandler)
+ public void updateDeployment(ProfileDeployment deployment, ManagedComponent comp, boolean remove)
throws Exception
{
if(deployment == null)
throw new IllegalArgumentException("Null deployment.");
if(comp == null)
throw new IllegalArgumentException("Null managed component.");
- if(persistenceHandler == null)
- throw new IllegalArgumentException("Null persistence handler.");
if(deployment.getRoot() == null)
{
@@ -435,7 +442,7 @@
attachment.setClassName(managedObject.getAttachment().getClass().getName());
// Create the persistence information and add it as a transient attachment
- PersistedManagedObject persistedMO = createPersistedMetaData(managedObject, persistenceHandler);
+ PersistenceRoot persistedMO = createPersistedMetaData(managedObject, comp, remove);
attachment.setAttachment(persistedMO);
// Update lastModified
@@ -525,7 +532,7 @@
continue;
// Get the xml for the persisted attachment
- PersistedManagedObject root = (PersistedManagedObject) attachment.getAttachment();
+ PersistenceRoot root = (PersistenceRoot) attachment.getAttachment();
String attachmentPath = deploymentPath + attachment.getName();
// Serialize the attachment
@@ -550,14 +557,21 @@
/**
* create the xml meta data for persisting the managed object.
*
- * @param mo the managed object.
+ * @param parent the parent managed object.
+ * @param the managed object
* @param handler the persistence handler
* @return the xml metadata.
*/
- protected PersistedManagedObject createPersistedMetaData(ManagedObject mo, ManagedObjectPeristenceHandler handler)
+ protected PersistenceRoot createPersistedMetaData(ManagedObject parent, ManagedComponent component, boolean remove)
{
- // Return
- return handler.createPersistenceMetaData(mo);
+ if(remove)
+ {
+ return this.persistenceFactory.removeComponent(parent, component);
+ }
+ else
+ {
+ return this.persistenceFactory.updateComponent(parent, component);
+ }
}
/**
@@ -801,8 +815,7 @@
* @throws MalformedURLException
* @throws URISyntaxException
*/
- public static String createHash(String pathName)
- throws NoSuchAlgorithmException, MalformedURLException, URISyntaxException
+ public static String createHash(String pathName) throws NoSuchAlgorithmException
{
// buffer
StringBuffer buffer = new StringBuffer();
Modified: branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/main/org/jboss/system/server/profileservice/repository/JAXBAttachmentSerializer.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -32,8 +32,8 @@
import org.jboss.logging.Logger;
import org.jboss.system.server.profileservice.attachments.RepositoryAttachmentMetaData;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
-import org.jboss.system.server.profileservice.persistence.xml.PersistenceConstants;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
@@ -60,8 +60,8 @@
static
{
- resolver.addClassBinding("urn:org:jboss:profileservice:attachments:1.0", RepositoryAttachmentMetaData.class);
- resolver.addClassBinding(PersistenceConstants.NAMESPACE_1_0, PersistedManagedObject.class);
+ resolver.addClassBinding(PersistenceConstants.REPOSITORY_NAMESPACE_1_0, RepositoryAttachmentMetaData.class);
+ resolver.addClassBinding(PersistenceConstants.COMPONENT_NAMESPACE_1_0, PersistenceRoot.class);
}
public JAXBAttachmentSerializer(File dir)
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/CompositeMetaData.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/CompositeMetaData.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/CompositeMetaData.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.support;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class CompositeMetaData
+{
+
+ String string;
+ char character;
+ Integer integer;
+
+ public CompositeMetaData()
+ {
+ //
+ }
+
+ public CompositeMetaData(String string, char character, Integer integer)
+ {
+ this.string = string;
+ this.character = character;
+ this.integer = integer;
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+
+ public char getCharacter()
+ {
+ return character;
+ }
+
+ public void setCharacter(char character)
+ {
+ this.character = character;
+ }
+
+ public Integer getInteger()
+ {
+ return integer;
+ }
+
+ public void setInteger(Integer integer)
+ {
+ this.integer = integer;
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponent.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponent.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponent.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,78 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.support;
+
+import javax.management.ObjectName;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject(componentType = @ManagementComponent(type="test", subtype="test"))
+public class TestComponent
+{
+
+ String name;
+ ObjectName objectName;
+ CompositeMetaData composite;
+
+ @ManagementProperty
+ @ManagementObjectID
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ @ManagementProperty
+ public ObjectName getObjectName()
+ {
+ return objectName;
+ }
+
+ public void setObjectName(ObjectName objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ @ManagementProperty
+ public CompositeMetaData getComposite()
+ {
+ return composite;
+ }
+
+ public void setComposite(CompositeMetaData composite)
+ {
+ this.composite = composite;
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponentMapper.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponentMapper.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.AbstractComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TestComponentMapper extends AbstractComponentMapper
+{
+
+ public TestComponentMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // Note: this is using the TestMgtComponentImpl to get the MO
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persistedMO = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persisted = new PersistedComponent(persistedMO);
+ setComponentName(persisted, mo);
+ return persisted;
+ }
+
+ @Override
+ protected void setComponentName(PersistedComponent component, ManagedObject mo)
+ {
+ // Set the current name for tracking.
+ component.setName((String) ((SimpleValue)mo.getProperty("name").getValue()).getValue());
+ }
+
+ @Override
+ protected ManagedObject getComponent(Object attachment, PersistedComponent component, boolean create)
+ {
+ TestDeployment deployment = (TestDeployment) attachment;
+ TestComponent instance = null;
+ if(deployment.getComponents() != null && deployment.getComponents().isEmpty() == false)
+ {
+ for(TestComponent md : deployment.getComponents())
+ {
+ if(md.getName().equals(component.getOriginalName()))
+ {
+ instance = md;
+ break;
+ }
+ }
+ }
+ if(instance == null && create)
+ {
+ instance = createTestComponent(component);
+ deployment.getComponents().add(instance);
+ }
+ if(instance == null)
+ {
+ throw new IllegalStateException("could not find instance with name " + component.getOriginalName());
+ }
+ return getMOF().initManagedObject(instance, null);
+ }
+
+ @Override
+ protected void removeComponent(Object attachment, PersistedComponent component)
+ {
+ TestDeployment deployment = (TestDeployment) attachment;
+ List<TestComponent> components = new ArrayList<TestComponent>();
+ if(deployment.getComponents() != null && deployment.getComponents().isEmpty() == false)
+ {
+ for(TestComponent md : deployment.getComponents())
+ {
+ if(md.getName().equals(component.getOriginalName()) == false)
+ components.add(md);
+ }
+ deployment.setComponents(components);
+ }
+ }
+
+ protected TestComponent createTestComponent(PersistedComponent component)
+ {
+ TestComponent test = new TestComponent();
+ test.setName(component.getOriginalName());
+ return test;
+ }
+
+ public String getType()
+ {
+ return TestDeployment.class.getName();
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestDeployment.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestDeployment.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestDeployment.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class TestDeployment
+{
+
+ /** The test components. */
+ private List<TestComponent> components = new ArrayList<TestComponent>();
+
+ @ManagementProperty(managed = true)
+ public List<TestComponent> getComponents()
+ {
+ return components;
+ }
+
+ public void setComponents(List<TestComponent> components)
+ {
+ this.components = components;
+ }
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestMgtComponentImpl.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestMgtComponentImpl.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/support/TestMgtComponentImpl.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.support;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.plugins.DelegateManagedCommonImpl;
+
+/**
+ * A test managed component, to have access to the ManagedObject over
+ * the getParent() method.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TestMgtComponentImpl extends DelegateManagedCommonImpl
+ implements ManagedComponent, Serializable
+{
+
+ private ManagedObject mo;
+
+ public TestMgtComponentImpl(ManagedObject delegate)
+ {
+ super(delegate);
+ this.mo = delegate;
+ }
+
+ @Override
+ public ManagedCommon getParent()
+ {
+ return mo;
+ }
+
+ public Map<String, Annotation> getAnnotations()
+ {
+ // FIXME getAnnotations
+ return null;
+ }
+
+ public ManagedDeployment getDeployment()
+ {
+ // FIXME getDeployment
+ return null;
+ }
+
+ public RunState getRunState()
+ {
+ // FIXME getRunState
+ return null;
+ }
+
+ public ComponentType getType()
+ {
+ // FIXME getType
+ return null;
+ }
+
+ public boolean update()
+ {
+ // FIXME update
+ return false;
+ }
+
+
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/AbstractComponentMapperTest.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/AbstractComponentMapperTest.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/AbstractComponentMapperTest.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,104 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.test;
+
+import java.io.File;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.system.server.profileservice.persistence.AbstractPersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.ComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
+import org.jboss.test.BaseTestCase;
+import org.jboss.xb.binding.Unmarshaller;
+import org.jboss.xb.binding.UnmarshallerFactory;
+import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class AbstractComponentMapperTest extends BaseTestCase
+{
+
+ /** The managed object factory. */
+ private ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+
+ /** The persistence factory. */
+ private AbstractPersistenceFactory persistenceFactory = new AbstractPersistenceFactory();
+
+ /** The schema resolver. */
+ protected static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
+ static
+ {
+ resolver.addClassBinding(PersistenceConstants.COMPONENT_NAMESPACE_1_0, PersistenceRoot.class);
+ }
+
+ public AbstractComponentMapperTest(String name)
+ {
+ super(name);
+ }
+
+ protected ManagedObjectFactory getMOF()
+ {
+ return managedObjectFactory;
+ }
+
+ protected PersistenceFactory getPersistenceFactory()
+ {
+ return persistenceFactory;
+ }
+
+ protected void addComponentMapper(ComponentMapper mapper)
+ {
+ persistenceFactory.addComponentMapper(mapper);
+ }
+
+ protected PersistenceRoot restore(PersistenceRoot root) throws Exception
+ {
+ File file = File.createTempFile("test", null);
+ serialize(root, file);
+ return deserialize(file);
+ }
+
+ protected void serialize(PersistenceRoot moElement, File file) throws Exception
+ {
+ JAXBContext ctx = JAXBContext.newInstance(PersistenceRoot.class);
+ Marshaller marshaller = ctx.createMarshaller();
+ marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
+ marshaller.marshal(moElement, file);
+ marshaller.marshal(moElement, System.out);
+ }
+
+ protected PersistenceRoot deserialize(File file) throws Exception
+ {
+ Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
+ return (PersistenceRoot) unmarshaller.unmarshal(file.toURL().openStream(), resolver);
+ }
+
+}
+
Added: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/ComponentMapperUnitTestCase.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/ComponentMapperUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/component/persistence/test/ComponentMapperUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,220 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.server.profileservice.component.persistence.test;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.management.ObjectName;
+
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
+import org.jboss.test.server.profileservice.component.persistence.support.CompositeMetaData;
+import org.jboss.test.server.profileservice.component.persistence.support.TestComponent;
+import org.jboss.test.server.profileservice.component.persistence.support.TestComponentMapper;
+import org.jboss.test.server.profileservice.component.persistence.support.TestDeployment;
+import org.jboss.test.server.profileservice.component.persistence.support.TestMgtComponentImpl;
+
+/**
+ * Basic component mapper unit test case.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ComponentMapperUnitTestCase extends AbstractComponentMapperTest
+{
+
+ public ComponentMapperUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
+ public void testAdd() throws Exception
+ {
+ // Add the component mapper
+ addComponentMapper(new TestComponentMapper(getPersistenceFactory()));
+
+ TestComponent addComponent = createComponentMetaData("component3",
+ new ObjectName("org.jboss:type=testComponent3"),
+ createCompositeMetaData("composite3", 'c', new Integer(3)));
+
+ ManagedObject temp = getMOF().initManagedObject(addComponent, null);
+ ManagedComponent component = new TestMgtComponentImpl(temp);
+
+ ManagedObject mo = createDeploymentMO();
+ PersistenceRoot root = getPersistenceFactory().addComponent(mo, component);
+
+ root = restore(root);
+
+ TestDeployment attachment = createDeploymentMetaData();
+ getPersistenceFactory().restorePersistenceRoot(root, attachment, null);
+
+ //
+ assertEquals(3, attachment.getComponents().size());
+ }
+
+ public void testUpdate() throws Exception
+ {
+ // Add the component mapper
+ addComponentMapper(new TestComponentMapper(getPersistenceFactory()));
+
+ // Get the components
+ ManagedObject mo = createDeploymentMO();
+ Iterator<?> iterator = ((CollectionValue) mo.getProperty("components").getValue()).iterator();
+ ManagedObject component1 = (ManagedObject) ((GenericValue) iterator.next()).getValue();
+ ManagedObject component2 = (ManagedObject) ((GenericValue) iterator.next()).getValue();
+
+ // create the persistence information
+ TestMgtComponentImpl tComp1 = new TestMgtComponentImpl(component1);
+ PersistenceRoot root = getPersistenceFactory().updateComponent(mo, tComp1);
+ TestMgtComponentImpl tComp2 = new TestMgtComponentImpl(component2);
+ root = getPersistenceFactory().updateComponent(root, mo, tComp2);
+
+ assertNotNull(root.getComponents());
+ // serialize / deserialize
+ PersistenceRoot persisted = restore(root);
+
+ // Create a new root attachment with empty components
+ TestDeployment test = new TestDeployment();
+ test.getComponents().add(createComponentMetaData("component1", null, null));
+ test.getComponents().add(createComponentMetaData("component2", null, null));
+ // Apply the persisted information, which should recreate the missing properties
+ getPersistenceFactory().restorePersistenceRoot(persisted, test, null);
+ assertFalse(test.getComponents().isEmpty());
+
+ // Check if the properties are available again
+ for(TestComponent restoredComponent : test.getComponents())
+ {
+ assertNotNull("null object name "+ restoredComponent.getName(), restoredComponent.getObjectName());
+ assertNotNull("null composite "+ restoredComponent.getName(), restoredComponent.getComposite());
+ }
+ }
+
+ public void testRemove() throws Exception
+ {
+ // Add the component mapper
+ addComponentMapper(new TestComponentMapper(getPersistenceFactory()));
+
+ // Get the components
+ ManagedObject mo = createDeploymentMO();
+ Iterator<?> iterator = ((CollectionValue) mo.getProperty("components").getValue()).iterator();
+ ManagedObject component1 = (ManagedObject) ((GenericValue) iterator.next()).getValue();
+
+ // create the persistence information
+ TestMgtComponentImpl tComp1 = new TestMgtComponentImpl(component1);
+ PersistenceRoot root = getPersistenceFactory().removeComponent(mo, tComp1);
+ PersistenceRoot persisted = restore(root);
+
+ // Check removed
+ TestDeployment deployment = createDeploymentMetaData();
+ getPersistenceFactory().restorePersistenceRoot(persisted, deployment, null);
+ assertEquals(1, deployment.getComponents().size());
+
+ // Reset
+ root = getPersistenceFactory().resetComponent(persisted, mo, tComp1);
+ persisted = restore(root);
+ assertNull(persisted.getComponents());
+ }
+
+ public void testNameChanges() throws Exception
+ {
+ // Add the component mapper
+ addComponentMapper(new TestComponentMapper(getPersistenceFactory()));
+
+ // Get the components
+ ManagedObject mo = createDeploymentMO();
+
+ PersistenceRoot root = new PersistenceRoot();
+
+ TestDeployment deployment = updateName(root, mo, "change1");
+ mo = getMOF().initManagedObject(deployment, null);
+
+ deployment = updateName(root, mo, "change2");
+ mo = getMOF().initManagedObject(deployment, null);
+
+ deployment = updateName(root, mo, "change3");
+ mo = getMOF().initManagedObject(deployment, null);
+
+ }
+
+ protected TestDeployment updateName(PersistenceRoot root, ManagedObject mo, String name) throws Exception
+ {
+ Iterator<?> iterator = ((CollectionValue) mo.getProperty("components").getValue()).iterator();
+ ManagedObject component = (ManagedObject) ((GenericValue) iterator.next()).getValue();
+
+ component.getProperty("name").setValue(SimpleValueSupport.wrap(name));
+ root = getPersistenceFactory().updateComponent(root, mo, new TestMgtComponentImpl(component));
+ root = restore(root);
+
+ TestDeployment deployment = createDeploymentMetaData();
+ getPersistenceFactory().restorePersistenceRoot(root, deployment, null);
+ return deployment;
+ }
+
+ protected ManagedObject createDeploymentMO() throws Exception
+ {
+ return getMOF().initManagedObject(createDeploymentMetaData(), null);
+ }
+
+ protected TestDeployment createDeploymentMetaData() throws Exception
+ {
+ TestDeployment deployment = new TestDeployment();
+ List<TestComponent> components = new ArrayList<TestComponent>();
+ components.add(
+ createComponentMetaData("component1",
+ new ObjectName("org.jboss:type=testComponent1"),
+ createCompositeMetaData("composite1", 'a', new Integer(1))));
+ components.add(
+ createComponentMetaData("component2",
+ new ObjectName("org.jboss:type=testComponent2"),
+ createCompositeMetaData("composite2", 'b', new Integer(2))));
+ deployment.setComponents(components);
+ return deployment;
+ }
+
+ protected TestComponent createComponentMetaData(String name, ObjectName objectName,
+ CompositeMetaData composite)
+ {
+ TestComponent component = new TestComponent();
+ component.setName(name);
+ component.setObjectName(objectName);
+ component.setComposite(composite);
+ return component;
+ }
+
+ protected CompositeMetaData createCompositeMetaData(String name, char character, Integer integer)
+ {
+ return new CompositeMetaData(name, character, integer);
+ }
+
+}
+
Modified: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/support/GenericSupportMetaData.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/support/GenericSupportMetaData.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/support/GenericSupportMetaData.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -35,8 +35,12 @@
public class GenericSupportMetaData
{
+ /** The list. */
List<SimpleGenericMetaData> list;
+ /** The array. */
+ SimpleGenericMetaData[][] array;
+
@ManagementProperty(managed = true)
public List<SimpleGenericMetaData> getList()
{
@@ -48,5 +52,16 @@
this.list = list;
}
+ @ManagementProperty(managed = true)
+ public SimpleGenericMetaData[][] getArray()
+ {
+ return array;
+ }
+
+ public void setArray(SimpleGenericMetaData[][] array)
+ {
+ this.array = array;
+ }
+
}
Modified: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/AbstractPersistenceFormatTest.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -31,9 +31,9 @@
import org.jboss.metatype.api.types.MetaTypeFactory;
import org.jboss.metatype.api.values.MetaValueFactory;
import org.jboss.system.server.profileservice.persistence.DelegatingPersistencePlugin;
-import org.jboss.system.server.profileservice.persistence.DelegatingRecreationPlugin;
import org.jboss.system.server.profileservice.persistence.ManagedObjectPersistencePlugin;
-import org.jboss.system.server.profileservice.persistence.ManagedObjectRecreationPlugin;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectRecreationHelper;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
import org.jboss.test.BaseTestCase;
import org.jboss.xb.binding.Unmarshaller;
@@ -48,19 +48,27 @@
{
/** The managed object factory */
- private ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+ private static final ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+ /** A helper. */
+ private static final ManagedObjectRecreationHelper helper;
+
+ /** The schema resolver. */
+ protected static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+
/** The meta value factory */
private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
/** The meta type factory */
private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
- protected static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ /** The persistence plugin. */
+ private DelegatingPersistencePlugin plugin = new DelegatingPersistencePlugin(helper);
static
{
- resolver.addClassBinding("urn:org:jboss:profileservice:persistence:managed-object:1.0", PersistedManagedObject.class);
+ resolver.addClassBinding(PersistenceConstants.COMPONENT_NAMESPACE_1_0, PersistedManagedObject.class);
+ helper = new ManagedObjectRecreationHelper(managedObjectFactory);
}
public AbstractPersistenceFormatTest(String name)
@@ -68,9 +76,14 @@
super(name);
}
+ protected ManagedObjectPersistencePlugin getPersistencePlugin()
+ {
+ return this.plugin;
+ }
+
protected ManagedObjectFactory getMOF()
{
- return this.managedObjectFactory;
+ return managedObjectFactory;
}
protected MetaValueFactory getMVF()
@@ -90,12 +103,6 @@
protected PersistedManagedObject restore(ManagedObject mo) throws Exception
{
- DelegatingPersistencePlugin plugin = new DelegatingPersistencePlugin();
- return restore(mo, plugin);
- }
-
- protected PersistedManagedObject restore(ManagedObject mo, ManagedObjectPersistencePlugin plugin) throws Exception
- {
PersistedManagedObject moElement = plugin.createPersistedManagedObject(mo);
File file = File.createTempFile("test", null);
@@ -124,15 +131,10 @@
return update(mo, moElement);
}
- protected ManagedObject update(ManagedObject mo, PersistedManagedObject moElement)
+ protected ManagedObject update(ManagedObject mo, PersistedManagedObject persisted)
{
- DelegatingRecreationPlugin plugin = new DelegatingRecreationPlugin();
- return update(plugin, mo, moElement);
+ return getPersistencePlugin().updateManagedObject(persisted, mo);
}
- protected ManagedObject update(ManagedObjectRecreationPlugin plugin, ManagedObject mo, PersistedManagedObject moElement)
- {
- return plugin.createManagedObject(moElement, mo);
- }
}
Modified: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/GenericValueUnitTestCase.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/GenericValueUnitTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/GenericValueUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -28,7 +28,6 @@
import org.jboss.metatype.api.values.CollectionValue;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
import org.jboss.test.server.profileservice.persistence.support.GenericSupportMetaData;
import org.jboss.test.server.profileservice.persistence.support.SimpleGenericMetaData;
@@ -47,21 +46,20 @@
public void test() throws Throwable
{
-
ManagedObject mo = createTestMO();
CollectionValue collection = (CollectionValue) mo.getProperty("list").getValue();
ManagedObject child2 = (ManagedObject) ((GenericValue) collection.getElements()[1]).getValue();
child2.getProperty("string").setValue(SimpleValueSupport.wrap("changedName"));
-
+ // TODO test generic array
+
PersistedManagedObject moElement = restore(mo);
- ManagedGenericOverrideHandler handler = new ManagedGenericOverrideHandler();
- ManagedObject restored = handler.update(createTestMetaData(), moElement);
+ ManagedObject restored = update(new GenericSupportMetaData(), moElement);
GenericSupportMetaData md = (GenericSupportMetaData) restored.getAttachment();
assertNotNull(md);
-
+
SimpleGenericMetaData child = md.getList().get(1);
assertEquals(child.getString(), "changedName");
}
@@ -87,7 +85,17 @@
return metaData;
}
+
+ protected SimpleGenericMetaData[][] createArray()
+ {
+ SimpleGenericMetaData child1 = createSImple("array11", 11, null);
+ SimpleGenericMetaData child2 = createSImple("array12", 12, null);
+ SimpleGenericMetaData child3 = createSImple("array21", 21, null);
+ SimpleGenericMetaData child4 = createSImple("array22", 22, null);
+ return new SimpleGenericMetaData[][] {{child1, child2}, {child3, child4}};
+ }
+
private SimpleGenericMetaData createSImple(String string, int integer, SimpleGenericMetaData child)
{
return new SimpleGenericMetaData(string, integer, child);
Modified: branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java
===================================================================
--- branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system/src/tests/org/jboss/test/server/profileservice/persistence/test/TestNestedPeristenceFormatUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -36,7 +36,6 @@
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
@@ -101,8 +100,7 @@
enableTrace("org.jboss.system.server.profileservice.persistence");
// Recreate
- ManagedGenericOverrideHandler handler = new ManagedGenericOverrideHandler();
- mo = handler.update(createNestedTestMetaData(), restored);
+ mo = update(createNestedTestMetaData(), restored);
deployment = getDeployment("ChangedName", mo);
assertNotNull("changed name deployment null", deployment);
Added: branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceDeploymentComponentMapper.java
===================================================================
--- branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceDeploymentComponentMapper.java (rev 0)
+++ branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceDeploymentComponentMapper.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,142 @@
+/*
+ * 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.deployers.managed;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.system.metadata.ServiceDeployment;
+import org.jboss.system.metadata.ServiceMetaData;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.AbstractComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+
+/**
+ * The ServiceDeployment component mapper. This handles the ServiceMetaData
+ * components in a ServiceDeployment.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ServiceDeploymentComponentMapper extends AbstractComponentMapper
+{
+
+ /** The logger. */
+ private static final Logger log = Logger.getLogger(ServiceDeploymentComponentMapper.class);
+
+ public ServiceDeploymentComponentMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected void setComponentName(PersistedComponent component, ManagedObject mo)
+ {
+ ServiceMetaData md = (ServiceMetaData) mo.getAttachment();
+ String name = md.getObjectName().getCanonicalName();
+ component.setName(name);
+ }
+
+ @Override
+ protected ManagedObject getComponent(Object attachment, PersistedComponent component, boolean create)
+ {
+ ServiceDeployment deployment = (ServiceDeployment) attachment;
+ ServiceMetaData service = null;
+ List<ServiceMetaData> services = deployment.getServices();
+ if(services == null)
+ {
+ services = new ArrayList<ServiceMetaData>();
+ deployment.setServices(services);
+ }
+ if(services != null && services.isEmpty() == false)
+ {
+ for(ServiceMetaData metaData : services)
+ {
+ if(metaData.getObjectName().getCanonicalName().equals(component.getOriginalName()))
+ {
+ service = metaData;
+ break;
+ }
+ }
+ }
+ if(service == null && create)
+ {
+ // Create a new empty service meta data
+ service = createEmptyServiceMetaData(component);
+ deployment.getServices().add(service);
+ }
+ if(service == null)
+ {
+ throw new IllegalStateException("could not find service with name " + component.getOriginalName());
+ }
+ return getMOF().initManagedObject(service, null);
+ }
+
+ @Override
+ protected void removeComponent(Object attachment, PersistedComponent component)
+ {
+ ServiceDeployment deployment = (ServiceDeployment) attachment;
+ List<ServiceMetaData> services = deployment.getServices();
+ if(services != null && services.isEmpty() == false)
+ {
+ for(ServiceMetaData metaData : services)
+ {
+ // Ignore the removed bean
+ if(metaData.getObjectName().getCanonicalName().
+ equals(component.getOriginalName()) == false)
+ services.add(metaData);
+ }
+ }
+ deployment.setServices(services);
+ }
+
+ protected ServiceMetaData createEmptyServiceMetaData(PersistedComponent component)
+ {
+ ServiceMetaData service = new ServiceMetaData();
+ ObjectName objectName = null;
+ try
+ {
+ objectName = new ObjectName(component.getOriginalName());
+ service.setObjectName(objectName);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ // TODO: this should not happen, but we might could just ignore this
+ // as the Persistence should restore the object name anyway
+ throw new RuntimeException("failed to create object name for component " + component, e);
+ }
+ log.debug("created service "+ component.getOriginalName());
+ return service;
+ }
+
+ public String getType()
+ {
+ return ServiceDeployment.class.getName();
+ }
+
+}
+
Modified: branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java
===================================================================
--- branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/system-jmx/src/main/org/jboss/system/deployers/managed/ServiceMetaDataICF.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,6 +21,7 @@
*/
package org.jboss.system.deployers.managed;
+import java.beans.PropertyEditor;
import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.HashMap;
@@ -52,6 +53,7 @@
import org.jboss.system.metadata.ServiceTextValueMetaData;
import org.jboss.system.metadata.ServiceValueContext;
import org.jboss.system.metadata.ServiceValueMetaData;
+import org.jboss.util.propertyeditor.PropertyEditors;
import org.w3c.dom.Element;
/**
@@ -59,6 +61,7 @@
*
* @author Scott.Stark at jboss.org
* @author Dimitris.Andreadis at jboss.org
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
public class ServiceMetaDataICF implements InstanceClassFactory<ServiceMetaData>
@@ -149,6 +152,7 @@
ClassLoader prevLoader = SecurityActions.getContextClassLoader();
Object value = null;
+ MetaType metaType = property.getMetaType();
MetaValue mvalue = null;
ObjectName mbean = md.getObjectName();
String attrName = null;
@@ -171,12 +175,11 @@
}
}
// If the value is null, look to mbean for the value
- if (value == null)
+ if (value == null && getMbeanServer() != null)
{
try
{
- if(getMbeanServer() != null)
- value = getMbeanServer().getAttribute(mbean, name);
+ value = getMbeanServer().getAttribute(mbean, name);
}
catch (AttributeNotFoundException e)
{
@@ -207,16 +210,26 @@
if (value instanceof ServiceTextValueMetaData)
{
ServiceTextValueMetaData text = (ServiceTextValueMetaData) value;
- // TODO: cache this somehow
- HashMap<String, MBeanAttributeInfo> attrs = ServiceConfigurator.getAttributeMap(mbeanServer, mbean);
- MBeanAttributeInfo mbi = attrs.get(attrName);
- ServiceValueContext svc = new ServiceValueContext(mbeanServer, controller, mbi, loader);
- value = text.getValue(svc);
+ try
+ {
+ // TODO: cache this somehow
+ HashMap<String, MBeanAttributeInfo> attrs = ServiceConfigurator.getAttributeMap(mbeanServer, mbean);
+ MBeanAttributeInfo mbi = attrs.get(attrName);
+ ServiceValueContext svc = new ServiceValueContext(mbeanServer, controller, mbi, loader);
+ value = text.getValue(svc);
+ }
+ catch(Exception e)
+ {
+ // TODO: better way to determine if the bean was installed, as this does not make much sense
+ PropertyEditor editor = PropertyEditors.getEditor(metaType.getTypeName());
+ editor.setAsText(text.getText());
+ value = editor.getValue();
+ }
}
else if (value instanceof ServiceDependencyValueMetaData)
{
ServiceDependencyValueMetaData depends = (ServiceDependencyValueMetaData) value;
- value = depends.getDependency();
+ value = depends.getObjectName();
}
else if (value instanceof ServiceElementValueMetaData)
{
@@ -304,7 +317,7 @@
PropertyInfo propertyInfo = beanInfo.getProperty(name);
plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
}
-
+
if (attributeValue == null)
{
String aname = mapAttributeName(md, name);
@@ -312,16 +325,26 @@
{
ServiceAttributeMetaData attr = new ServiceAttributeMetaData();
attr.setName(aname);
- md.addAttribute(attr);
+ // Check if this is mapped to a Element
if(mappedType != null && mappedType.equals(Element.class))
{
attributeValue = new ServiceElementValueMetaData();
}
- else
- {
- attributeValue = new ServiceTextValueMetaData("");
+ else if(plainValue != null)
+ {
+ // Create a text value
+ String textValue = String.valueOf(plainValue);
+ // Don't create a empty value
+ if(textValue.trim().length() > 0 )
+ attributeValue = new ServiceTextValueMetaData(textValue);
}
+ // Don't create a null serviceAttribute
+ if(attributeValue == null)
+ return;
+
+ // Add
attr.setValue(attributeValue);
+ md.addAttribute(attr);
}
}
if (attributeValue != null)
@@ -329,8 +352,9 @@
// Unwrap the ServiceValueMetaData types
if (attributeValue instanceof ServiceTextValueMetaData)
{
+ String textValue = plainValue != null ? String.valueOf(plainValue) : null;
ServiceTextValueMetaData text = (ServiceTextValueMetaData) attributeValue;
- text.setText(String.valueOf(plainValue));
+ text.setText(textValue);
}
else if (attributeValue instanceof ServiceElementValueMetaData)
{
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,13 +21,14 @@
*/
package org.jboss.test.profileservice.persistenceformat.support;
+import org.jboss.managed.api.annotation.ManagementObject;
import org.jboss.managed.api.annotation.ManagementProperty;
/**
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
-//@ManagementObject(name = "SimpleBean")
+ at ManagementObject(name = "SimpleBean")
public class SimpleAnnotatedBean
{
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMgtComponentImpl.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMgtComponentImpl.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMgtComponentImpl.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -0,0 +1,90 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.profileservice.persistenceformat.support;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.RunState;
+import org.jboss.managed.plugins.DelegateManagedCommonImpl;
+
+/**
+ *
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TestMgtComponentImpl extends DelegateManagedCommonImpl
+ implements ManagedComponent, Serializable
+{
+
+ private ManagedObject mo;
+
+ public TestMgtComponentImpl(ManagedObject delegate)
+ {
+ super(delegate);
+ this.mo = delegate;
+ }
+
+ @Override
+ public ManagedCommon getParent()
+ {
+ return mo;
+ }
+
+ public Map<String, Annotation> getAnnotations()
+ {
+ // FIXME getAnnotations
+ return null;
+ }
+
+ public ManagedDeployment getDeployment()
+ {
+ // FIXME getDeployment
+ return null;
+ }
+
+ public RunState getRunState()
+ {
+ // FIXME getRunState
+ return null;
+ }
+
+ public ComponentType getType()
+ {
+ // FIXME getType
+ return null;
+ }
+
+ public boolean update()
+ {
+ // FIXME update
+ return false;
+ }
+
+}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -26,12 +26,18 @@
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
-import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.AbstractPersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.PersistenceConstants;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.component.ComponentMapper;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.test.JBossTestCase;
+import org.jboss.test.profileservice.persistenceformat.support.TestMgtComponentImpl;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
@@ -49,12 +55,15 @@
/** The meta value factory */
private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ /** The persistence factory. */
+ private AbstractPersistenceFactory persistenceFactory = new AbstractPersistenceFactory();
+
/** The schema resolver */
protected static final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
static
{
- resolver.addClassBinding("urn:org:jboss:profileservice:persistence:managed-object:1.0", PersistedManagedObject.class);
+ resolver.addClassBinding(PersistenceConstants.COMPONENT_NAMESPACE_1_0, PersistenceRoot.class);
}
public AbstractPersistenceFormatTest(String name)
@@ -62,9 +71,9 @@
super(name);
}
- protected ManagedObjectFactory getMOF()
+ protected AbstractManagedObjectFactory getMOF()
{
- return this.managedObjectFactory;
+ return (AbstractManagedObjectFactory) this.managedObjectFactory;
}
protected MetaValueFactory getMVF()
@@ -72,37 +81,52 @@
return this.metaValueFactory;
}
+ protected PersistenceFactory getPersistenceFactory()
+ {
+ return persistenceFactory;
+ }
+
protected ManagedObject initManagedObject(Object o)
{
return getMOF().initManagedObject(o, null);
}
- protected PersistedManagedObject createPersisted(ManagedObject mo)
+ protected ManagedComponent createComponent(ManagedObject mo)
{
- ManagedObjectPeristenceHandler persistence = new ManagedObjectPeristenceHandler();
- return persistence.createPersistenceMetaData(mo);
+ return new TestMgtComponentImpl(mo);
}
- protected PersistedManagedObject restore(ManagedObject mo) throws Exception
+ protected void addComponentMapper(ComponentMapper mapper)
{
- File file = File.createTempFile("test", null);
- serialize(createPersisted(mo), file);
- return deserialize(file);
+ persistenceFactory.addComponentMapper(mapper);
}
- protected void serialize(PersistedManagedObject moElement, File file) throws Exception
+ protected PersistenceRoot updateComponent(ManagedObject parent, ManagedComponent component) throws Exception
{
- JAXBContext ctx = JAXBContext.newInstance(PersistedManagedObject.class);
+ PersistenceRoot root = getPersistenceFactory().updateComponent(parent, component);
+ return restore(root);
+ }
+
+ protected PersistenceRoot restore(PersistenceRoot root) throws Exception
+ {
+ File f = File.createTempFile("test", null);
+ serialize(root, f);
+ return deserialize(f);
+ }
+
+ protected void serialize(PersistenceRoot moElement, File file) throws Exception
+ {
+ JAXBContext ctx = JAXBContext.newInstance(PersistenceRoot.class);
Marshaller marshaller = ctx.createMarshaller();
marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
marshaller.marshal(moElement, file);
marshaller.marshal(moElement, System.out);
}
- protected PersistedManagedObject deserialize(File file) throws Exception
+ protected PersistenceRoot deserialize(File file) throws Exception
{
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
- return (PersistedManagedObject) unmarshaller.unmarshal(file.toURL().openStream(), resolver);
+ return (PersistenceRoot) unmarshaller.unmarshal(file.toURL().openStream(), resolver);
}
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,21 +21,30 @@
*/
package org.jboss.test.profileservice.persistenceformat.test;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaDataFactory;
import org.jboss.beans.metadata.spi.PropertyMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.deployers.plugins.managed.BeanMetaDataICF;
+import org.jboss.deployers.plugins.managed.KernelDeploymentComponentMapper;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.plugins.deployment.AbstractKernelDeployment;
import org.jboss.kernel.spi.dependency.KernelController;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
import org.jboss.metadata.spi.MetaData;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.test.profileservice.persistenceformat.support.SimpleAnnotatedBean;
/**
@@ -53,14 +62,16 @@
/** The controller. */
private KernelController controller;
+
+ /** Some random bean names. */
+ private final static String[] BEAN_NAMES = new String[] {"TestBean", "SimpleAnnotatedBean", "OtherBean"};
public JBossBeansPersistenceFormatTestCase(String name)
{
super(name);
}
-
- protected void setUp() throws Exception
+ public void setUp() throws Exception
{
super.setUp();
// Bootstrap
@@ -70,65 +81,151 @@
kernel = bootstrap.getKernel();
//
controller = kernel.getController();
- }
-
- protected BeanMetaData installBean() throws Throwable
- {
- BeanMetaDataBuilder builder = getSimpleBeanMetaDataBuilder();
- // Add a value
- builder.addPropertyMetaData("stringProperty", "testValue");
- // Install
- controller.install(builder.getBeanMetaData());
- return builder.getBeanMetaData();
- }
-
- public void test() throws Throwable
- {
- // InstallBean
- BeanMetaData md = installBean();
-
// setUp beanICF
BeanMetaDataICF beanICF = new BeanMetaDataICF();
beanICF.setController(controller);
- beanICF.setDelegateICF(((AbstractManagedObjectFactory)getMOF()).getDefaultInstanceFactory());
+ beanICF.setDelegateICF(((AbstractManagedObjectFactory)
+ getMOF()).getDefaultInstanceFactory());
getMOF().addInstanceClassFactory(beanICF);
+ addComponentMapper(new TestMapper(getPersistenceFactory()));
+ }
+
+ public void testUpdateComponent() throws Throwable
+ {
+ // Install
+ KernelDeployment deployment = createKernelDeployment(BEAN_NAMES);
+ // install
+ installDeployment(deployment);
- KernelControllerContext ctx = (KernelControllerContext) controller.getInstalledContext("SimpleAnnotatedBean");
- assertNotNull(ctx);
+ // Create the managed objects
+ ManagedObject deploymentMO = getMOF().initManagedObject(deployment, null);
+ ManagedObject mo = getBeanMO("SimpleAnnotatedBean");
+ assertNotNull("null mo", mo);
+ assertTrue(mo.getAttachment() instanceof BeanMetaData);
+ ManagedComponent component = createComponent(mo);
+ assertNotNull(component);
+ assertEquals(component.getAttachmentName(), SimpleAnnotatedBean.class.getName());
+
+ // Change value
+ component.getProperty("stringProperty").setValue(SimpleValueSupport.wrap("changedTestValue"));
- MetaData metaData = kernel.getMetaDataRepository().getMetaData(ctx);
- assertNotNull(metaData);
-
- ManagedObject mo = getMOF().initManagedObject(md, null, metaData, "SimpleAnnotatedBean", null);
- assertNotNull(mo);
+ PersistenceRoot root = updateComponent(deploymentMO, component);
+ assertNotNull(root);
- PersistedManagedObject moElement = restore(mo);
- assertNotNull(moElement);
-
// Uninstall for offline attachment persistence
- controller.uninstall("SimpleAnnotatedBean");
+ uninstallDeployment(deployment);
- ManagedGenericOverrideHandler override = new ManagedGenericOverrideHandler();
- // Try to restore the information without the installed bean
- mo = getMOF().initManagedObject(getSimpleBeanMetaDataBuilder().getBeanMetaData(), null);
+ // Recreate the kernel deployment
+ deployment = createKernelDeployment(BEAN_NAMES);
+ getPersistenceFactory().restorePersistenceRoot(root, deployment, null);
+
+ // check bean meta data
+ BeanMetaData bmd = getBeanMetaData(deployment, "SimpleAnnotatedBean");
+ boolean sawProperty = false;
+ for(PropertyMetaData prop : bmd.getProperties())
+ {
+ if(prop.getName().equals("stringProperty"))
+ {
+ assertEquals("changedTestValue", prop.getValue().getUnderlyingValue());
+ sawProperty = true;
+ }
+ }
+ assertTrue(sawProperty);
+
+ // install
+ installDeployment(deployment);
+ mo = getBeanMO("SimpleAnnotatedBean");
assertNotNull(mo);
- override.updateManagedObject(mo, moElement, mo.getAttachment());
- Set<PropertyMetaData> properties = ((BeanMetaData)mo.getAttachment()).getProperties();
- assertNotNull(properties);
- // TODO
- assertEquals(1, properties.size());
+ assertEquals(SimpleValueSupport.wrap("changedTestValue"),
+ mo.getProperty("stringProperty").getValue());
+
}
- protected BeanMetaDataBuilder getSimpleBeanMetaDataBuilder()
+ protected ManagedObject getBeanMO(String name)
{
- BeanMetaDataBuilder b = BeanMetaDataBuilder.createBuilder("SimpleAnnotatedBean", SimpleAnnotatedBean.class.getName());
- b.addAnnotation("@org.jboss.managed.api.annotation.ManagementObject(name=\"simpleBean\")");
- return b;
+ KernelControllerContext ctx = (KernelControllerContext) controller.getInstalledContext(name);
+ assertNotNull(ctx);
+ BeanMetaData bmd = ctx.getBeanMetaData();
+ assertNotNull("null BeanMetaData", bmd);
+ MetaData metaData = kernel.getMetaDataRepository().getMetaData(ctx);
+ assertNotNull("null MetaData", metaData);
+ return getMOF().initManagedObject(bmd, null, metaData, name, null);
}
+ protected void installDeployment(KernelDeployment deployment) throws Throwable
+ {
+ for(BeanMetaDataFactory factory : deployment.getBeanFactories())
+ {
+ for(BeanMetaData bmd : factory.getBeans())
+ controller.install(bmd);
+ }
+ }
+ protected void uninstallDeployment(KernelDeployment deployment)
+ {
+ for(BeanMetaDataFactory factory : deployment.getBeanFactories())
+ {
+ for(BeanMetaData bmd : factory.getBeans())
+ controller.uninstall(bmd.getName());
+ }
+ }
+
+ protected BeanMetaData getBeanMetaData(KernelDeployment deployment, String name)
+ {
+ BeanMetaData bmd = null;
+ for(BeanMetaDataFactory factory : deployment.getBeanFactories())
+ {
+ for(BeanMetaData beanMetaData : factory.getBeans())
+ {
+ if(beanMetaData.getName().equals(name))
+ {
+ bmd = beanMetaData;
+ break;
+ }
+ }
+ }
+ assertNotNull("null beanMetaData for " + name, bmd);
+ return bmd;
+ }
+
+ protected KernelDeployment createKernelDeployment(String... beans)
+ {
+ AbstractKernelDeployment deployment = new AbstractKernelDeployment();
+ List<BeanMetaDataFactory> beanFactories = new ArrayList<BeanMetaDataFactory>();
+ for(String beanName : beans)
+ beanFactories.add(createBeanDataFactory(beanName));
+ deployment.setBeanFactories(beanFactories);
+ return deployment;
+ }
+
+ protected BeanMetaDataFactory createBeanDataFactory(String name)
+ {
+ BeanMetaDataBuilder b = BeanMetaDataBuilder.createBuilder(name, SimpleAnnotatedBean.class.getName());
+ b.addAnnotation("@org.jboss.managed.api.annotation.ManagementObject(name=\""+ name +"\")");
+ b.addPropertyMetaData("stringProperty", "test" + name);
+ return b.asBeanMetaDataFactory();
+ }
+
+ private static final class TestMapper extends KernelDeploymentComponentMapper
+ {
+ public TestMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // Note: this is using the TestMgtComponentImpl to get the MO
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persisted = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persistedComponent = new PersistedComponent(persisted);
+ setComponentName(persistedComponent, mo);
+ return persistedComponent;
+ }
+ }
+
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossServicePersistenceFormatTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossServicePersistenceFormatTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossServicePersistenceFormatTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -22,6 +22,7 @@
package org.jboss.test.profileservice.persistenceformat.test;
import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -30,7 +31,11 @@
import javax.xml.bind.Marshaller;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedObject;
import org.jboss.mx.loading.LoaderRepositoryFactory.LoaderRepositoryConfig;
+import org.jboss.system.deployers.managed.ServiceDeploymentComponentMapper;
+import org.jboss.system.metadata.ServiceAttributeMetaData;
import org.jboss.system.metadata.ServiceConstructorMetaData;
import org.jboss.system.metadata.ServiceDependencyMetaData;
import org.jboss.system.metadata.ServiceDeployment;
@@ -38,14 +43,22 @@
import org.jboss.system.metadata.ServiceDeploymentParser;
import org.jboss.system.metadata.ServiceMetaData;
import org.jboss.system.metadata.ServiceMetaDataParser;
+import org.jboss.system.metadata.ServiceValueMetaData;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPersistencePlugin;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.ModificationInfo;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.system.server.profileservice.repository.AbstractFileAttachmentsSerializer;
import org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer;
import org.w3c.dom.Document;
/**
- * Testing the marshalling/unmarshalling with the JAXBAttachmentSerializer
- * for ServiceDeployment (jboss-service.xml).
+ * Persistence test for ServiceMetaData components.
*
+ * TODO the ManagedObject view of ServiceMetaData needs to be completed.
+ *
* @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
* @version $Revision$
*/
@@ -56,28 +69,74 @@
{
super(name);
}
-
- public void testJbossService() throws Exception
+
+
+ public void testServiceMetaData() throws Exception
{
- // Parse
+ // Don't use the ServiceMetaDataICF - to be able to test plain
+ // ServiceMetaData without MOClass override...
+ // getMOF().addInstanceClassFactory(new ServiceMetaDataICF());
+
+ addComponentMapper(new TestMapper(getPersistenceFactory()));
+
ServiceDeployment deployment = parseJbossServiceXml("profileservice/persistence/jboss-service.xml");
- assertNotNull(deployment);
- // Create serializer
- AbstractFileAttachmentsSerializer serializer = getAttachmentSerializer();
- // Save
- serializer.saveAttachment("test", deployment);
- // Restore
- ServiceDeployment restored = serializer.loadAttachment("test", ServiceDeployment.class);
- assertNotNull(restored);
- // Assert services
- assertServices(deployment.getServices(), restored.getServices());
- // loader repository
- assertLoaderRepository(deployment.getLoaderRepositoryConfig(), restored.getLoaderRepositoryConfig());
- // classpath
- assertClassPaths(deployment.getClassPaths(), restored.getClassPaths());
+ // Manually create a persistence view
+ List<ServiceMetaData> services = deployment.getServices();
+ List<PersistedComponent> components = new ArrayList<PersistedComponent>();
+ ManagedObjectPersistencePlugin plugin = getPersistenceFactory().getPersistencePlugin();
+ for(ServiceMetaData md : deployment.getServices())
+ {
+ // Bypass the ServiceMetaDataICF...
+ ManagedObject mo = getMOF().initManagedObject(md, null);
+ PersistedManagedObject persisted = plugin.createPersistedManagedObject(mo);
+
+ // Fix the names, as we don't use the ServiceMetaDataICF
+ String name = md.getObjectName().getCanonicalName();
+ persisted.setName(name);
+ persisted.setOriginalName(name);
+ persisted.setModificationInfo(ModificationInfo.ADDED);
+
+ components.add(new PersistedComponent(persisted));
+ }
+
+ PersistenceRoot root = new PersistenceRoot();
+ root.setComponents(components);
+ root = restore(root);
+
+ // Test if we can recreate a complete view, without
+ // requiring any previous service
+ deployment = new ServiceDeployment();
+ deployment.setServices(new ArrayList<ServiceMetaData>());
+
+ getPersistenceFactory().restorePersistenceRoot(root, deployment, null);
+
+ assertServices(services, deployment.getServices());
+
}
+//
+// public void testJbossService() throws Exception
+// {
+// // Parse
+// ServiceDeployment deployment = parseJbossServiceXml("profileservice/persistence/jboss-service.xml");
+// assertNotNull(deployment);
+// // Create serializer
+// AbstractFileAttachmentsSerializer serializer = getAttachmentSerializer();
+// // Save
+// serializer.saveAttachment("test", deployment);
+// // Restore
+// ServiceDeployment restored = serializer.loadAttachment("test", ServiceDeployment.class);
+// assertNotNull(restored);
+//
+// // Assert services
+// assertServices(deployment.getServices(), restored.getServices());
+// // loader repository
+// assertLoaderRepository(deployment.getLoaderRepositoryConfig(), restored.getLoaderRepositoryConfig());
+// // classpath
+// assertClassPaths(deployment.getClassPaths(), restored.getClassPaths());
+// }
+
protected void assertServices(List<ServiceMetaData> original, List<ServiceMetaData> restored)
{
assertNotNull(original);
@@ -143,7 +202,55 @@
{
assertNull(restored.getDependencies());
}
+
+ assertAttributes(original.getAttributes(), restored.getAttributes());
+
}
+
+ protected void assertAttributes(List<ServiceAttributeMetaData> original, List<ServiceAttributeMetaData> restored)
+ {
+ if(original == null)
+ {
+ assertNull(restored);
+ return;
+ }
+ else
+ {
+ assertNotNull(restored);
+ }
+
+ assertEquals(original.size(), restored.size());
+ if(original.isEmpty())
+ return;
+
+ Map<String, ServiceAttributeMetaData> attributesMap = new HashMap<String, ServiceAttributeMetaData>();
+ for(ServiceAttributeMetaData attribute : restored)
+ attributesMap.put(attribute.getName(), attribute);
+
+ for(ServiceAttributeMetaData attribute : original)
+ assertAttributeMetaData(attribute, attributesMap.get(attribute.getName()));
+ }
+
+ protected void assertAttributeMetaData(ServiceAttributeMetaData original, ServiceAttributeMetaData restored)
+ {
+ assertNotNull(original);
+ assertNotNull(original.getName(), restored);
+
+ if(original.getValue() == null)
+ {
+ assertNull(restored.getValue());
+ return;
+ }
+ else
+ {
+ assertNotNull(restored.getValue());
+ }
+
+ ServiceValueMetaData value = original.getValue();
+ // TODO we need some MetaMapping for attributes
+ assertEquals(original.getName(), value.getClass().getName(), restored.getValue().getClass().getName());
+ }
+
protected void assertServiceConstructor(ServiceConstructorMetaData original, ServiceConstructorMetaData restored)
{
@@ -285,5 +392,26 @@
return getAttachmentsStoreDir();
}
}
+
+ private static final class TestMapper extends ServiceDeploymentComponentMapper
+ {
+
+ public TestMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // Note: this is using the TestMgtComponentImpl to get the MO
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persisted = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persistedComponent = new PersistedComponent(persisted);
+ setComponentName(persistedComponent, mo);
+ return persistedComponent;
+ }
+
+ }
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JMSDestinationPersistenceFormatTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JMSDestinationPersistenceFormatTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JMSDestinationPersistenceFormatTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -24,22 +24,28 @@
import java.io.File;
import java.util.List;
+import javax.management.ObjectName;
import javax.xml.parsers.DocumentBuilderFactory;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedObject;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.metatype.api.values.CollectionValue;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.system.deployers.managed.ServiceDeploymentComponentMapper;
import org.jboss.system.deployers.managed.ServiceMetaDataICF;
import org.jboss.system.metadata.ServiceAttributeMetaData;
+import org.jboss.system.metadata.ServiceDependencyValueMetaData;
import org.jboss.system.metadata.ServiceDeployment;
import org.jboss.system.metadata.ServiceDeploymentParser;
import org.jboss.system.metadata.ServiceMetaData;
import org.jboss.system.metadata.ServiceMetaDataParser;
import org.jboss.system.metadata.ServiceTextValueMetaData;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.w3c.dom.Document;
/**
@@ -76,25 +82,34 @@
{
// Set the ICF
getMOF().addInstanceClassFactory(new ServiceMetaDataICF());
+ // TODO create dependency on messaging project ?
+// getMOF().addManagedObjectDefinition(new QueueMODefinition(getMOF()));
+// getMOF().addManagedObjectDefinition(new TopicMODefinition(getMOF()));
+ // Add the testmapper
+ addComponentMapper(new TestMapper(getPersistenceFactory()));
+
// create
ManagedObject deploymentMO = getDeploymentMO(xmlName);
+ ManagedComponent component = createJMSComponent(deploymentMO);
+
// update property
- getProperty(deploymentMO, "downCacheSize").setValue(SimpleValueSupport.wrap(123456));
+ component.getProperty("downCacheSize").setValue(SimpleValueSupport.wrap(123456));
- PersistedManagedObject moElement = restore(deploymentMO);
+ ServiceDeployment deployment = parseJbossServiceXml(xmlName);
+ PersistenceRoot root = updateComponent(deploymentMO, component);
+ getPersistenceFactory().restorePersistenceRoot(root, deployment, null);
- ManagedGenericOverrideHandler handler = new ManagedGenericOverrideHandler();
- ManagedObject restored = handler.update(parseJbossServiceXml(xmlName), moElement);
+ //
+ ManagedObject restored = getMOF().initManagedObject(deployment, null);
+ component = createJMSComponent(restored);
// assert
- assertEquals(SimpleValueSupport.wrap(123456), getProperty(restored, "downCacheSize").getValue());
+ assertEquals(SimpleValueSupport.wrap(123456), component.getProperty("downCacheSize").getValue());
// Assert attachment meta data
- ServiceDeployment deployment = (ServiceDeployment) restored.getAttachment();
- assertNotNull(deployment);
ServiceMetaData service = deployment.getServices().get(0);
assertNotNull(service);
boolean foundAttribute = false;
@@ -106,10 +121,32 @@
assertEquals("123456", text);
foundAttribute = true;
}
+ else if("ServerPeer".equals(attribute.getName()))
+ {
+ ServiceDependencyValueMetaData value = ((ServiceDependencyValueMetaData) attribute.getValue());
+ ObjectName name = value.getObjectName();
+ assertNotNull(name);
+ }
+ else if("ExpiryQueue".equals(attribute.getName()))
+ {
+ ServiceTextValueMetaData value = (ServiceTextValueMetaData) attribute.getValue();
+ assertNotNull(value.getText());
+ }
}
assertTrue(foundAttribute);
}
+ protected ManagedComponent createJMSComponent(ManagedObject serviceDeploymentMO)
+ {
+ assertNotNull(serviceDeploymentMO);
+ CollectionValue collection = (CollectionValue) serviceDeploymentMO.getProperty("services").getValue();
+ assertNotNull(collection);
+ GenericValue topic = (GenericValue) collection.iterator().next();
+ assertNotNull(topic);
+ ManagedObject topicMO = (ManagedObject) topic.getValue();
+ return createComponent(topicMO);
+ }
+
protected ManagedProperty getProperty(ManagedObject serviceDeploymentMO, String propertyName)
{
assertNotNull(serviceDeploymentMO);
@@ -151,4 +188,23 @@
return deployment;
}
+ private static final class TestMapper extends ServiceDeploymentComponentMapper
+ {
+
+ public TestMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // Note: this is using the TestMgtComponentImpl to get the MO
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persisted = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persistedComponent = new PersistedComponent(persisted);
+ setComponentName(persistedComponent, mo);
+ return persistedComponent;
+ }
+
+ }
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/LocalDataSourcePersistenceFormatTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/LocalDataSourcePersistenceFormatTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/LocalDataSourcePersistenceFormatTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -29,18 +29,21 @@
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.sax.SAXSource;
+import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
import org.jboss.metatype.api.values.CollectionValue;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.resource.deployers.management.LocalDSInstanceClassFactory;
+import org.jboss.resource.deployers.management.MCFDGComponentMapper;
import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentGroup;
import org.jboss.resource.metadata.mcf.ManagedConnectionFactoryDeploymentMetaData;
import org.jboss.system.deployers.managed.ServiceMetaDataICF;
import org.jboss.system.metadata.ServiceMetaData;
-import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
+import org.jboss.system.server.profileservice.persistence.PersistenceFactory;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedComponent;
import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistenceRoot;
import org.jboss.util.xml.JBossEntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
@@ -60,11 +63,17 @@
super(name);
}
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ }
+
public void testProfileServiceTestDS() throws Throwable
{
getMOF().addInstanceClassFactory(new LocalDSInstanceClassFactory());
- // FIXME
getMOF().addInstanceClassFactory(new ServiceMetaDataICF());
+ //
+ addComponentMapper(new TestMapper(getPersistenceFactory()));
// Initial parsing of the dataSource deployment
ManagedConnectionFactoryDeploymentGroup deployment = parseDataSource("profileservice/persistence/profileservice-test-ds.xml");
@@ -72,26 +81,28 @@
ManagedObject mo = getMOF().initManagedObject(deployment, null);
+ ManagedComponent c = createDSComponent(mo);
// Change values
- getManagedProperty(mo, "min-pool-size").setValue(SimpleValueSupport.wrap(13));
- getManagedProperty(mo, "max-pool-size").setValue(SimpleValueSupport.wrap(53));
+ c.getProperty("min-pool-size").setValue(SimpleValueSupport.wrap(13));
+ c.getProperty("max-pool-size").setValue(SimpleValueSupport.wrap(53));
- PersistedManagedObject moelement = restore(mo);
- assertNotNull(moelement);
+ PersistenceRoot root = updateComponent(mo, c);
+ assertNotNull(root);
- enableTrace("org.jboss.system");
-
// Recreate
deployment = parseDataSource("profileservice/persistence/profileservice-test-ds.xml");
- ManagedGenericOverrideHandler handler = new ManagedGenericOverrideHandler();
- ManagedObject restored = handler.update(deployment, moelement);
- assertNotNull(restored);
+ // update the information
+ getPersistenceFactory().restorePersistenceRoot(root, deployment, null);
- assertEquals(SimpleValueSupport.wrap(13), getManagedProperty(mo, "min-pool-size").getValue());
- assertEquals(SimpleValueSupport.wrap(53), getManagedProperty(mo, "max-pool-size").getValue());
+ // Create the MO again
+ mo = getMOF().initManagedObject(deployment, null);
+ c = createDSComponent(mo);
+ assertEquals(SimpleValueSupport.wrap(13), c.getProperty("min-pool-size").getValue());
+ assertEquals(SimpleValueSupport.wrap(53), c.getProperty("max-pool-size").getValue());
- ManagedConnectionFactoryDeploymentGroup mcfdg = (ManagedConnectionFactoryDeploymentGroup) restored.getAttachment();
+ // Assert the attachment
+ ManagedConnectionFactoryDeploymentGroup mcfdg = deployment;
assertNotNull(mcfdg);
// Assert services
assertServices(mcfdg.getServices());
@@ -125,12 +136,12 @@
}
}
- protected ManagedProperty getManagedProperty(ManagedObject mo, String propertyName)
+ protected ManagedComponent createDSComponent(ManagedObject deployment)
{
- CollectionValue collection = (CollectionValue) mo.getProperty("deployments").getValue();
+ CollectionValue collection = (CollectionValue) deployment.getProperty("deployments").getValue();
GenericValue generic = (GenericValue) collection.iterator().next();
- ManagedObject deployment = (ManagedObject) generic.getValue();
- return deployment.getProperty(propertyName);
+ ManagedObject mo = (ManagedObject) generic.getValue();
+ return createComponent(mo);
}
protected ManagedConnectionFactoryDeploymentGroup parseDataSource(String resource) throws Exception
@@ -151,4 +162,25 @@
ManagedConnectionFactoryDeploymentGroup.class);
return elem.getValue();
}
+
+ private static class TestMapper extends MCFDGComponentMapper
+ {
+
+ public TestMapper(PersistenceFactory persistenceFactory)
+ {
+ super(persistenceFactory);
+ }
+
+ @Override
+ protected PersistedComponent createComponent(Object attachment, ManagedComponent component)
+ {
+ // Note: this is using the TestMgtComponentImpl to get the MO
+ ManagedObject mo = (ManagedObject) component.getParent();
+ PersistedManagedObject persisted = getPersistencePlugin().createPersistedManagedObject(mo);
+ PersistedComponent persistedComponent = new PersistedComponent(persisted);
+ setComponentName(persistedComponent, mo);
+ return persistedComponent;
+ }
+
+ }
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.profileservice.template.test;
+import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@@ -68,12 +70,11 @@
// info.getProperties().get("name").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "Test"));
// info.getProperties().get("JNDIName").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "TestJNDIName"));
//
-// info.getProperties().get("serverPeer").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue")));
-// info.getProperties().get("DLQ").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateDLQ")));
-// info.getProperties().get("expiryQueue").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue")));
+// info.getProperties().get("serverPeer").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue"));
+// info.getProperties().get("DLQ").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue,name=PrivateDLQ"));
+// info.getProperties().get("expiryQueue").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue"));
// info.getProperties().get("securityConfig").setValue(createComposityType());
//
-//
// DeploymentTemplate t = new JmsDestinationTemplate();
// // Try to apply the template and delete the file afterwards
// t.applyTemplate(info);
@@ -85,11 +86,10 @@
// TopicServiceMO.class);
//
// info.getProperties().get("name").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "Test"));
-// info.getProperties().get("JNDIName").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "TestJNDIName"));
-//
-// info.getProperties().get("serverPeer").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue")));
-// info.getProperties().get("DLQ").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateDLQ")));
-// info.getProperties().get("expiryQueue").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue")));
+// info.getProperties().get("JNDIName").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "TestJNDIName"));
+// info.getProperties().get("serverPeer").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue"));
+// info.getProperties().get("DLQ").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue,name=PrivateDLQ"));
+// info.getProperties().get("expiryQueue").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue"));
// info.getProperties().get("securityConfig").setValue(createComposityType());
//
// DeploymentTemplate t = new JmsDestinationTemplate();
@@ -127,6 +127,12 @@
return new CompositeValueSupport(compositeMetaType, map);
}
+
+ @Override
+ protected Collection<String> getExcludes()
+ {
+ return Collections.singleton("destinationType");
+ }
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/JmsDestinationUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -54,6 +54,7 @@
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedOperation;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.RunState;
import org.jboss.managed.plugins.ManagedOperationMatcher;
import org.jboss.metatype.api.types.MapCompositeMetaType;
import org.jboss.metatype.api.types.MetaType;
@@ -285,6 +286,20 @@
assertEquals("testCreateQueue2", queue2.getName());
}
+
+ public void testQueueRunState() throws Exception
+ {
+ ManagementView mgtView = getManagementView();
+ ManagedComponent queue = mgtView.getComponent("testCreateQueue", QueueType);
+ assertNotNull(queue);
+ assertEquals("running", RunState.RUNNING, queue.getRunState());
+ ManagedOperation stop = getOperation(queue, "stop", new String[0]);
+ stop.invoke(new MetaValue[0]);
+
+ mgtView.reload();
+ queue = mgtView.getComponent("testCreateQueue", QueueType);
+ log.info("runtstate: " + queue.getRunState());
+ }
public void testRemoveQueue() throws Exception
{
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ManagementViewUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ManagementViewUnitTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ManagementViewUnitTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -25,6 +25,7 @@
import org.jboss.deployers.spi.management.KnownDeploymentTypes;
import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ManagedDeployment;
/**
* Test ManagementView operations.
@@ -51,13 +52,15 @@
for(KnownDeploymentTypes type : KnownDeploymentTypes.values())
{
+ log.debug("----- deployment type: " + type);
+
Set<String> deploymentNames = mgtView.getDeploymentNamesForType(type.getType());
-
if(deploymentNames != null)
{
for(String deploymentName : deploymentNames)
{
- mgtView.getDeployment(deploymentName);
+ ManagedDeployment deployment = mgtView.getDeployment(deploymentName);
+ log.debug(deployment.getSimpleName());
}
}
}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServerManagedObjectsTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -23,6 +23,7 @@
import java.net.InetAddress;
import java.net.URL;
+import java.util.Collection;
import java.util.Map;
import java.util.Set;
@@ -334,6 +335,14 @@
assertEquals(RunState.RUNNING, mc.getRunState());
}
+ public void testMBeanFactory() throws Exception
+ {
+ ManagementView mgtView = getManagementView();
+ Collection<ManagedComponent> components = mgtView.getComponentsForType(new ComponentType("MBean", "WebApplicationManager"));
+ assertNotNull(components);
+
+ }
+
/**
* Obtain the ProfileService.ManagementView
* @return
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-05-12 13:19:55 UTC (rev 88716)
@@ -188,6 +188,7 @@
// assertNotNull("property bindingSets has no value", val);
// assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
// getLog().info(((CollectionValue) val).getElements());
+ managementView.updateComponent(component);
}
public void testPortsDefault() throws Exception
Modified: branches/Branch_5_x/testsuite/src/resources/profileservice/override/testQueue-service.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/profileservice/override/testQueue-service.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/resources/profileservice/override/testQueue-service.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -3,7 +3,7 @@
<mbean xmbean-dd="xmdesc/Queue-xmbean.xml"
name="jboss.messaging.destination:service=Queue,name=testQueue"
code="org.jboss.jms.server.destination.QueueService">
- <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.QueueServiceMO)</annotation>
+
<attribute name="JNDIName">testQueue</attribute>
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
Modified: branches/Branch_5_x/testsuite/src/resources/profileservice/override/testTopic-service.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/profileservice/override/testTopic-service.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/resources/profileservice/override/testTopic-service.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -3,7 +3,7 @@
<mbean xmbean-dd="xmdesc/Topic-xmbean.xml"
name="jboss.messaging.destination:service=Topic,name=testTopic"
code="org.jboss.jms.server.destination.TopicService">
- <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
+
<attribute name="JNDIName">testTopic</attribute>
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends>jboss.messaging:service=PostOffice</depends>
Modified: branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/jboss-service.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/jboss-service.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/jboss-service.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -14,6 +14,8 @@
<mbean code="org.jboss.deployment.MainDeployer"
name="jboss.system:service=MainDeployer">
+
+ <annotation>@org.jboss.managed.api.annotation.ManagementObject</annotation>
<!-- This is used to delegate the deployment handling -->
<attribute name="KernelMainDeployer"><inject bean="MainDeployer" /></attribute>
<!-- This is used to validate incomplete deployments -->
Modified: branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/profileservice-test-ds.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/profileservice-test-ds.xml 2009-05-12 12:46:21 UTC (rev 88715)
+++ branches/Branch_5_x/testsuite/src/resources/profileservice/persistence/profileservice-test-ds.xml 2009-05-12 13:19:55 UTC (rev 88716)
@@ -17,7 +17,17 @@
</metadata>
</local-tx-datasource>
+ <mbean code="org.jboss.security.plugins.JaasSecurityDomain"
+ name="jboss.security:service=JaasSecurityDomain,domain=ServerMasterPassword">
+ <constructor>
+ <arg type="java.lang.String" value="ServerMasterPassword"/>
+ </constructor>
+ <attribute name="KeyStorePass">{CLASS}org.jboss.security.plugins.FilePassword:${jboss.server.home.dir}/conf/server.password</attribute>
+ <attribute name="Salt">abcdefgh</attribute>
+ <attribute name="IterationCount">13</attribute>
+ </mbean>
+
<mbean code="org.jboss.jdbc.HypersonicDatabase"
name="jboss:service=Hypersonic,database=profileserviceTestDB">
<attribute name="Database">profileserviceTestDB</attribute>
More information about the jboss-cvs-commits
mailing list