Author: tejones
Date: 2010-05-19 19:20:03 -0400 (Wed, 19 May 2010)
New Revision: 2145
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyListAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyMapAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertySimpleAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapterFactory.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapterFactory.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/AbstractPropertyMapToCompositeValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToArrayValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToCollectionValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToCompositeValueSupportAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToGenericValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToMapCompositeValueSupportAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToPropertiesValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToTableValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToEnumValueAdapter.java
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToSimpleValueAdapter.java
Removed:
trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java
Modified:
trunk/console/pom.xml
trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java
trunk/console/src/main/resources/META-INF/rhq-plugin.xml
Log:
TEIID-807: Added Translator creation logic
Modified: trunk/console/pom.xml
===================================================================
--- trunk/console/pom.xml 2010-05-19 21:07:59 UTC (rev 2144)
+++ trunk/console/pom.xml 2010-05-19 23:20:03 UTC (rev 2145)
@@ -159,6 +159,28 @@
</dependency> -->
</dependencies>
+
+ <build>
+ <outputDirectory>target/classes</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.xml</include>
+ <include>**/*.properties</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>false</filtering>
+ <excludes>
+ <exclude>**/*.xml</exclude>
+ <exclude>**/*.properties</exclude>
+ </excludes>
+ </resource>
+ </resources>
+ </build>
</project>
\ No newline at end of file
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2010-05-19 21:07:59 UTC
(rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/Facet.java 2010-05-19 23:20:03 UTC
(rev 2145)
@@ -29,13 +29,22 @@
import java.util.Map;
import java.util.Set;
+import javax.naming.NamingException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.deployers.spi.management.deploy.DeploymentManager;
import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
import org.rhq.core.domain.content.PackageDetailsKey;
import org.rhq.core.domain.content.PackageType;
import org.rhq.core.domain.content.transfer.DeployPackageStep;
@@ -45,13 +54,13 @@
import org.rhq.core.domain.measurement.AvailabilityType;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.content.version.PackageVersions;
import org.rhq.core.domain.resource.CreateResourceStatus;
import org.rhq.core.domain.resource.ResourceType;
import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.content.ContentFacet;
import org.rhq.core.pluginapi.content.ContentServices;
+import org.rhq.core.pluginapi.content.version.PackageVersions;
import org.rhq.core.pluginapi.inventory.CreateChildResourceFacet;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.inventory.DeleteResourceFacet;
@@ -104,22 +113,23 @@
* C:/opt/jboss-5.0.0.GA/server/default/deploy/foo.vdb).
*/
protected String deploymentName;
-
+
private PackageVersions versions = null;
-
- /**
- * Name of the backing package type that will be used when discovering packages. This
corresponds to the name of the
- * package type defined in the plugin descriptor. For simplicity, the package type
for VDBs is called "vdb". This is
- * still unique within the context of the parent resource type and lets this class
use the same package type name in
- * both cases.
- */
- private static final String PKG_TYPE_VDB = "vdb";
- /**
- * Architecture string used in describing discovered packages.
- */
- private static final String ARCHITECTURE = "noarch";
+ /**
+ * Name of the backing package type that will be used when discovering
+ * packages. This corresponds to the name of the package type defined in the
+ * plugin descriptor. For simplicity, the package type for VDBs is called
+ * "vdb". This is still unique within the context of the parent resource
+ * type and lets this class use the same package type name in both cases.
+ */
+ private static final String PKG_TYPE_VDB = "vdb";
+ /**
+ * Architecture string used in describing discovered packages.
+ */
+ private static final String ARCHITECTURE = "noarch";
+
abstract String getComponentType();
/**
@@ -299,7 +309,6 @@
// this simulates the plugin taking the new configuration and
// reconfiguring the managed resource
resourceConfiguration = report.getConfiguration().deepCopy();
-
report.setStatus(ConfigurationUpdateStatus.SUCCESS);
}
@@ -346,7 +355,7 @@
File deploymentFile = null;
if (this.deploymentName != null) {
- deploymentFile = new File(deploymentName.substring(7));
+ deploymentFile = new File(deploymentName.substring(7));
}
if (!deploymentFile.exists())
@@ -374,7 +383,7 @@
if (!deploymentFile.isDirectory())
packageDetails.setFileSize(deploymentFile.length());
packageDetails.setFileCreatedDate(null); // TODO: get created date via
- // SIGAR
+ // SIGAR
Set<ResourcePackageDetails> packages = new
HashSet<ResourcePackageDetails>();
packages.add(packageDetails);
@@ -398,9 +407,107 @@
return null;
}
+
+ protected static Configuration getDefaultPluginConfiguration(
+ ResourceType resourceType) {
+ ConfigurationTemplate pluginConfigDefaultTemplate = resourceType
+ .getPluginConfigurationDefinition().getDefaultTemplate();
+ return (pluginConfigDefaultTemplate != null) ? pluginConfigDefaultTemplate
+ .createConfiguration()
+ : new Configuration();
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see
org.rhq.core.pluginapi.inventory.CreateChildResourceFacet#createResource(org.rhq.core.pluginapi.inventory.CreateResourceReport)
+ */
@Override
- public CreateResourceReport createResource(
+ public CreateResourceReport createResource(CreateResourceReport report) {
+ ResourceType resourceType = report.getResourceType();
+ if (resourceType.getName().equals("Translators")){
+ createConfigurationBasedResource(report);
+ }else{
+ createContentBasedResource(report);
+ }
+
+ return report;
+ }
+
+ private CreateResourceReport createConfigurationBasedResource(
CreateResourceReport createResourceReport) {
+ ResourceType resourceType = createResourceReport.getResourceType();
+ Configuration defaultPluginConfig =
+ getDefaultPluginConfiguration(resourceType);
+ Configuration resourceConfig = createResourceReport
+ .getResourceConfiguration();
+ String resourceName = getResourceName(defaultPluginConfig,
+ resourceConfig);
+ ComponentType componentType = ProfileServiceUtil
+ .getComponentType(resourceType);
+ ManagementView managementView = null;;
+ try {
+ managementView = ProfileServiceUtil.getManagementView(
+ ProfileServiceUtil.getProfileService(), true);
+ } catch (NamingException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ if (ProfileServiceUtil.isManagedComponent(managementView,
+ resourceName, componentType)) {
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setErrorMessage("A " + resourceType.getName()
+ + " named '" + resourceName + "' already exists.");
+ return createResourceReport;
+ }
+
+ createResourceReport.setResourceName(resourceName);
+ String resourceKey = getResourceKey(resourceType, resourceName);
+ createResourceReport.setResourceKey(resourceKey);
+
+ PropertySimple templateNameProperty = resourceConfig
+ .getSimple(TranslatorComponent.Config.TEMPLATE_NAME);
+ String templateName = templateNameProperty.getStringValue();
+
+ DeploymentTemplateInfo template;
+ Set templateNamesSet = managementView.getTemplateNames();
+ try {
+ template = managementView.getTemplate(templateName);
+ Map<String, ManagedProperty> managedProperties = template
+ .getProperties();
+
+ ProfileServiceUtil.convertConfigurationToManagedProperties(
+ managedProperties, resourceConfig, resourceType);
+
+ LOG.debug("Applying template [" + templateName
+ + "] to create ManagedComponent of type [" + componentType
+ + "]...");
+ try {
+ managementView.applyTemplate(resourceName, template);
+ managementView.process();
+ createResourceReport.setStatus(CreateResourceStatus.SUCCESS);
+ } catch (Exception e) {
+ LOG.error("Unable to apply template [" + templateName
+ + "] to create ManagedComponent of type "
+ + componentType + ".", e);
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setException(e);
+ }
+ } catch (NoSuchDeploymentException e) {
+ LOG.error("Unable to find template [" + templateName + "].", e);
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setException(e);
+ } catch (Exception e) {
+ LOG.error("Unable to process create request", e);
+ createResourceReport.setStatus(CreateResourceStatus.FAILURE);
+ createResourceReport.setException(e);
+ }
+ return createResourceReport;
+ }
+
+ protected void createContentBasedResource(
+ CreateResourceReport createResourceReport) {
+
ResourcePackageDetails details = createResourceReport
.getPackageDetails();
PackageDetailsKey key = details.getKey();
@@ -417,7 +524,7 @@
createResourceReport
.setErrorMessage("Incorrect extension specified on filename ["
+ archivePath + "]");
- return createResourceReport;
+
}
DeploymentManager deploymentManager = ProfileServiceUtil
@@ -437,9 +544,29 @@
createResourceReport.setException(t);
}
- return createResourceReport;
-
}
+
+ private static String getResourceName(Configuration pluginConfig, Configuration
resourceConfig)
+ {
+ PropertySimple resourceNameProp =
pluginConfig.getSimple(TranslatorComponent.Config.RESOURCE_NAME);
+ if (resourceNameProp == null || resourceNameProp.getStringValue() == null)
+ throw new IllegalStateException("Property [" +
TranslatorComponent.Config.RESOURCE_NAME
+ + "] is not defined in the default plugin
configuration.");
+ String resourceNamePropName = resourceNameProp.getStringValue();
+ PropertySimple propToUseAsResourceName =
resourceConfig.getSimple(resourceNamePropName);
+ if (propToUseAsResourceName == null)
+ throw new IllegalStateException("Property [" +
resourceNamePropName
+ + "] is not defined in initial Resource configuration.");
+ return propToUseAsResourceName.getStringValue();
+ }
+
+ private String getResourceKey(ResourceType resourceType, String resourceName)
+ {
+ ComponentType componentType = ProfileServiceUtil.getComponentType(resourceType);
+ if (componentType == null)
+ throw new IllegalStateException("Unable to map " + resourceType +
" to a ComponentType.");
+ return componentType.getType() + ":" + componentType.getSubtype() +
":" + resourceName;
+ }
/**
* Returns an instantiated and loaded versions store access point.
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -35,6 +35,7 @@
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.teiid.rhq.admin.DQPManagementView;
import org.teiid.rhq.plugin.util.PluginConstants;
import org.teiid.rhq.plugin.util.ProfileServiceUtil;
@@ -174,6 +175,7 @@
}
}
+
@Override
public void stop() {
@@ -181,4 +183,6 @@
super.stop();
}
+
+
}
\ No newline at end of file
Deleted: trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/QueriesComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -1,130 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.rhq.plugin;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.measurement.MeasurementReport;
-import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
-import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries;
-import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Queries.Query;
-import org.teiid.rhq.plugin.objects.ExecutedResourceConfigurationResultImpl;
-
-
-/**
- * MetaMatrix Connector component class
- *
- */
-public class QueriesComponent extends Facet {
-
- private final Log LOG = LogFactory.getLog(QueriesComponent.class);
-
-
- private ExecutedResourceConfigurationResultImpl getQueries = null;
-
- /**
- * @see org.teiid.rhq.plugin.Facet#getComponentType()
- * @since 1.0
- */
- @Override
- String getComponentType() {
- return Queries.TYPE;
- }
-
- public void start(ResourceContext context) {
- super.start(context);
-
- Map defns =
context.getResourceType().getResourceConfigurationDefinition().getPropertyDefinitions();
-
- getQueries = new ExecutedResourceConfigurationResultImpl(
- this.getComponentType(),
- Query.GET_QUERIES,
- defns);
- }
-
- protected void setOperationArguments(String name, Configuration configuration,
- Map argumentMap) {
-
-
- }
-
- @Override
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
-
- }
-
- @Override
- public void getValues(MeasurementReport arg0,
- Set<MeasurementScheduleRequest> arg1) throws Exception {
- // TODO Auto-generated method stub
-
- }
-
-
- /**
- * The plugin container will call this method and it needs to obtain the
- * current configuration of the managed resource. Your plugin will obtain
- * the managed resource's configuration in your own custom way and populate
- * the returned Configuration object with the managed resource's
- * configuration property values.
- *
- * @see ConfigurationFacet#loadResourceConfiguration()
- *
- */
- @Override
- public Configuration loadResourceConfiguration() {
- // here we simulate the loading of the managed resource's configuration
- Configuration config = this.getResourceConfiguration() ;
- if (config == null) {
- // for this example, we will create a simple dummy configuration to
- // start with.
- // note that it is empty, so we're assuming there are no required
- // configs in the plugin descriptor.
- config = new Configuration();
-
-
- }
-
- getQueries.reset();
-
- execute(getQueries, new HashMap());
-
-
- config.put( (PropertyList) getQueries.getResult());
-
-
- this.setResourceConfiguration(config);
- return this.getResourceConfiguration();
- }
-
-
-}
\ No newline at end of file
Deleted: trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/SessionComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -1,154 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library 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 library 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 library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package org.teiid.rhq.plugin;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.rhq.core.domain.configuration.Configuration;
-import org.rhq.core.domain.configuration.PropertyList;
-import org.rhq.core.domain.measurement.AvailabilityType;
-import org.rhq.core.domain.measurement.MeasurementReport;
-import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
-import org.rhq.core.pluginapi.inventory.ResourceContext;
-import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session;
-import org.teiid.rhq.comm.ConnectionConstants.ComponentType.Runtime.Session.Query;
-import org.teiid.rhq.plugin.objects.ExecutedResourceConfigurationResultImpl;
-
-
-/**
- * MetaMatrix Connector component class
- *
- */
-public class SessionComponent extends Facet {
-
- private final Log LOG = LogFactory.getLog(SessionComponent.class);
-
-
- private ExecutedResourceConfigurationResultImpl getSessions = null;
-
- /**
- * @see org.teiid.rhq.plugin.Facet#getComponentType()
- * @since 1.0
- */
- @Override
- String getComponentType() {
- return Session.TYPE;
- }
-
- public void start(ResourceContext context) {
- super.start(context);
-
- Map defns =
context.getResourceType().getResourceConfigurationDefinition().getPropertyDefinitions();
-
- getSessions = new ExecutedResourceConfigurationResultImpl(
- this.getComponentType(),
- Query.GET_SESSIONS,
- defns);
- }
-
- protected void setOperationArguments(String name, Configuration configuration,
- Map argumentMap) {
-
-
- }
-
- @Override
- public AvailabilityType getAvailability() {
- return AvailabilityType.UP;
-
- }
-
- @Override
- public void getValues(MeasurementReport arg0,
- Set<MeasurementScheduleRequest> arg1) throws Exception {
- // TODO Auto-generated method stub
-
- }
-
-
- /**
- * The plugin container will call this method and it needs to obtain the
- * current configuration of the managed resource. Your plugin will obtain
- * the managed resource's configuration in your own custom way and populate
- * the returned Configuration object with the managed resource's
- * configuration property values.
- *
- * @see ConfigurationFacet#loadResourceConfiguration()
- *
- */
- @Override
- public Configuration loadResourceConfiguration() {
- // here we simulate the loading of the managed resource's configuration
- Configuration config = this.getResourceConfiguration() ;
- if (config == null) {
- // for this example, we will create a simple dummy configuration to
- // start with.
- // note that it is empty, so we're assuming there are no required
- // configs in the plugin descriptor.
- config = new Configuration();
-
-
- }
-
- getSessions.reset();
-
- execute(getSessions, new HashMap());
-
-
- config.put( (PropertyList) getSessions.getResult());
-
-
- this.setResourceConfiguration(config);
- return this.getResourceConfiguration();
- }
-
-
-// class SessionComparable implements Comparator {
-//
-// public int compare(Object arg0, Object arg1) {
-// // TODO Auto-generated method stub
-// Component a = (Component) arg0;
-// Component b = (Component) arg1;
-//
-// if ( a == null && b == null ) {
-// return 0;
-// }
-// if ( a != null && b == null ) {
-// return 1;
-// }
-// if ( a == null && b != null ) {
-// return -1;
-// }
-// int result = a.get.compareTo(b.getDisplayName());
-// return result;
-// }
-
-
-
- // }
-
-}
\ No newline at end of file
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -21,42 +21,56 @@
*/
package org.teiid.rhq.plugin;
-import java.util.Iterator;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
+import javax.naming.NamingException;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.profileservice.spi.NoSuchDeploymentException;
import org.rhq.core.domain.configuration.Configuration;
import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
import org.rhq.core.domain.measurement.MeasurementDataNumeric;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
-import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.domain.resource.CreateResourceStatus;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.measurement.MeasurementFacet;
import org.teiid.rhq.comm.ConnectionConstants;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
-
/**
* Component class for the MetaMatrix Host Controller process.
*
*/
public class TranslatorComponent extends Facet {
- private final Log LOG = LogFactory
- .getLog(TranslatorComponent.class);
+ private final Log LOG = LogFactory.getLog(TranslatorComponent.class);
+ public static interface Config {
+ String COMPONENT_TYPE = "componentType";
+ String COMPONENT_SUBTYPE = "componentSubtype";
+ String COMPONENT_NAME = "componentName";
+ String TEMPLATE_NAME = "template-name";
+ String RESOURCE_NAME = "resourceName";
+ }
- /**
- * @see org.teiid.rhq.plugin.Facet#getComponentType()
- * @since 1.0
- */
- @Override
- String getComponentType() {
- return ConnectionConstants.ComponentType.Resource.Model.TYPE;
- }
-
- /**
+ /**
+ * @see org.teiid.rhq.plugin.Facet#getComponentType()
+ * @since 1.0
+ */
+ @Override
+ String getComponentType() {
+ return ConnectionConstants.ComponentType.Resource.Model.TYPE;
+ }
+
+ /**
* The plugin container will call this method when your resource component
* has been scheduled to collect some measurements now. It is within this
* method that you actually talk to the managed resource and collect the
@@ -75,8 +89,8 @@
// actually need to collect
try {
Number value = new Integer(1); // dummy measurement value -
- // this should come from the
- // managed resource
+ // this should come from the
+ // managed resource
report.addData(new MeasurementDataNumeric(request, value
.doubleValue()));
} catch (Exception e) {
@@ -88,14 +102,17 @@
return;
}
- protected void setOperationArguments(String name, Configuration configuration,
- Map argumentMap) {
+ protected void setOperationArguments(String name,
+ Configuration configuration, Map argumentMap) {
- if (name.equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES)){
+ if (name
+ .equals(ConnectionConstants.ComponentType.Operation.GET_PROPERTIES)) {
String key = ConnectionConstants.IDENTIFIER;
argumentMap.put(key, getComponentIdentifier());
}
-
- }
+
+ }
+
+
}
\ No newline at end of file
Modified:
trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorDiscoveryComponent.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorDiscoveryComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/TranslatorDiscoveryComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -31,7 +31,6 @@
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedProperty;
import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.CollectionValueSupport;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.MetaValueFactory;
import org.rhq.core.domain.configuration.Configuration;
@@ -42,7 +41,6 @@
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
-import org.teiid.adminapi.impl.PropertyMetadata;
import org.teiid.rhq.plugin.util.PluginConstants;
import org.teiid.rhq.plugin.util.ProfileServiceUtil;
@@ -66,8 +64,6 @@
for (ManagedComponent translator : translators) {
- Map<String, ManagedProperty> managedPropertyMap = translator
- .getProperties();
String translatorKey = translator.getName();
String translatorName = ProfileServiceUtil.getSimpleValue(
translator, "name", String.class);
@@ -82,8 +78,7 @@
translatorName, // Resource Name
null, // Version
PluginConstants.ComponentType.Translator.DESCRIPTION, // Description
- discoveryContext.getDefaultPluginConfiguration(), // Plugin
- // Config
+ discoveryContext.getDefaultPluginConfiguration(), // Plugin config
null // Process info from a process scan
);
@@ -92,25 +87,34 @@
PropertyMap propMap = null;
c.put(list);
- for (ManagedProperty prop : managedPropertyMap.values()) {
- propMap = new PropertyMap("translatorMap");
- String name = prop.getName();
- if (name.equals("translator-property")) {
- getTranslatorValues(prop.getValue(), propMap, list);
- } else {
- propMap.put(new PropertySimple("name", name));
- propMap.put(new PropertySimple("value", ProfileServiceUtil
- .stringValue(prop.getValue())));
- propMap.put(new PropertySimple("description", prop
- .getDescription()));
- list.add(propMap);
- }
- }
+ // First get translator specific properties
+ ManagedProperty translatorProps = translator
+ .getProperty("translator-property");
+ getTranslatorValues(translatorProps.getValue(), propMap, list);
+ // Now get common properties
+ c.put(new PropertySimple("name", translatorName));
+ c.put(new PropertySimple("execution-factory-class",
+ ProfileServiceUtil.getSimpleValue(translator,
+ "execution-factory-class", String.class)));
+ c.put(new PropertySimple("immutable", ProfileServiceUtil
+ .getSimpleValue(translator, "immutable", Boolean.class)));
+ c.put(new PropertySimple("xa-capable", ProfileServiceUtil
+ .getSimpleValue(translator, "xa-capable", Boolean.class)));
+ c.put(new PropertySimple("exception-on-max-rows",
+ ProfileServiceUtil.getSimpleValue(translator,
+ "exception-on-max-rows", Boolean.class)));
+ c.put(new PropertySimple("max-result-rows", ProfileServiceUtil
+ .getSimpleValue(translator, "max-result-rows",
+ Integer.class)));
+ c.put(new PropertySimple("template-name", ProfileServiceUtil
+ .getSimpleValue(translator, "template-name",
+ String.class)));
+
detail.setPluginConfiguration(c);
// Add to return values
discoveredResources.add(detail);
- log.info("Discovered Teiid Translator: " + translatorName);
+ log.debug("Discovered Teiid Translator: " + translatorName);
}
return discoveredResources;
@@ -119,29 +123,22 @@
public static <T> void getTranslatorValues(MetaValue pValue,
PropertyMap map, PropertyList list) {
MetaType metaType = pValue.getMetaType();
- PropertyMetadata unwrappedvalue = null;
- if (metaType.isCollection()) {
- for (MetaValue value : ((CollectionValueSupport) pValue)
- .getElements()) {
- if (value.getMetaType().isComposite()) {
- map = new PropertyMap("translatorMap");
- unwrappedvalue = (PropertyMetadata) MetaValueFactory
- .getInstance().unwrap(value);
- map
- .put(new PropertySimple("name", unwrappedvalue
- .getName()));
- map.put(new PropertySimple("value", unwrappedvalue
- .getValue()));
- map
- .put(new PropertySimple("description",
- "Custom property"));
- list.add(map);
- } else {
- throw new IllegalStateException(pValue
- + " is not a Composite type");
- }
+ Map<String, T> unwrappedvalue = null;
+ if (metaType.isComposite()) {
+ unwrappedvalue = (Map<String, T>) MetaValueFactory
+ .getInstance().unwrap(pValue);
+
+ for (String key : unwrappedvalue.keySet()) {
+ map = new PropertyMap("translator-properties");
+ map.put(new PropertySimple("name", key));
+ map.put(new PropertySimple("value", unwrappedvalue.get(key)));
+ map.put(new PropertySimple("description", "Custom property"));
+ list.add(map);
}
+ } else {
+ throw new IllegalStateException(pValue + " is not a Composite type");
}
+
}
}
\ No newline at end of file
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-05-19 21:07:59
UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-05-19 23:20:03
UTC (rev 2145)
@@ -43,6 +43,7 @@
import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.ConfigurationUpdateStatus;
import org.rhq.core.domain.configuration.PropertyList;
import org.rhq.core.domain.configuration.PropertyMap;
import org.rhq.core.domain.configuration.PropertySimple;
@@ -51,6 +52,10 @@
import org.rhq.core.domain.measurement.MeasurementDataTrait;
import org.rhq.core.domain.measurement.MeasurementReport;
import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+import org.rhq.core.domain.resource.ResourceType;
+import org.rhq.core.pluginapi.configuration.ConfigurationFacet;
+import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
+import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.inventory.ResourceContext;
import org.teiid.rhq.admin.DQPManagementView;
import org.teiid.rhq.comm.ConnectionConstants;
@@ -218,6 +223,21 @@
return PluginConstants.ComponentType.VDB.NAME;
}
+ /**
+ * The plugin container will call this method when it has a new
+ * configuration for your managed resource. Your plugin will re-configure
+ * the managed resource in your own custom way, setting its configuration
+ * based on the new values of the given configuration.
+ *
+ * @see ConfigurationFacet#updateResourceConfiguration(ConfigurationUpdateReport)
+ */
+ public void updateResourceConfiguration(ConfigurationUpdateReport report) {
+ // this simulates the plugin taking the new configuration and
+ // reconfiguring the managed resource
+ resourceConfiguration = report.getConfiguration().deepCopy();
+ report.setStatus(ConfigurationUpdateStatus.SUCCESS);
+ }
+
@Override
public Configuration loadResourceConfiguration() {
@@ -251,7 +271,15 @@
return configuration;
}
+
+ @Override
+ public CreateResourceReport createResource(
+ CreateResourceReport createResourceReport) {
+ createContentBasedResource(createResourceReport);
+ return createResourceReport;
+ }
+
/**
* @param mcVdb
* @param configuration
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-05-19
21:07:59 UTC (rev 2144)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -239,7 +239,7 @@
list.add(map);
MetaType metaType = pValue.getMetaType();
if (metaType.isCollection()) {
- for (MetaValue value : ((CollectionValueSupport) pValue)
+ for (MetaValue value : ((CollectionValueSupport) pValue)
.getElements()) {
GenericValueSupport genValue = ((GenericValueSupport) value);
ManagedObject mo = (ManagedObject) genValue.getValue();
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyListAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyListAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyListAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A base class for PropertyList <-> ???MetaValue adapters.
+ *
+ */
+public abstract class AbstractPropertyListAdapter implements
PropertyAdapter<PropertyList, PropertyDefinitionList>
+{
+ public PropertyList convertToProperty(MetaValue metaValue, PropertyDefinitionList
propDefList)
+ {
+ PropertyList propList = new PropertyList(propDefList.getName());
+ populatePropertyFromMetaValue(propList, metaValue, propDefList);
+ return propList;
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyMapAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyMapAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertyMapAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A base class for PropertyMap <-> ???MetaValue adapters.
+ *
+ */
+public abstract class AbstractPropertyMapAdapter implements
PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ public PropertyMap convertToProperty(MetaValue metaValue, PropertyDefinitionMap
propDefMap)
+ {
+ PropertyMap propMap = new PropertyMap(propDefMap.getName());
+ populatePropertyFromMetaValue(propMap, metaValue, propDefMap);
+ return propMap;
+ }
+}
\ No newline at end of file
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertySimpleAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertySimpleAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/AbstractPropertySimpleAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A base class for {@link PropertySimple} <-> ???MetaValue adapters.
+ *
+ */
+public abstract class AbstractPropertySimpleAdapter implements
PropertyAdapter<PropertySimple, PropertyDefinitionSimple>
+{
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public PropertySimple convertToProperty(MetaValue metaValue, PropertyDefinitionSimple
propDefSimple)
+ {
+ PropertySimple propSimple = new PropertySimple(propDefSimple.getName(), null);
+ populatePropertyFromMetaValue(propSimple, metaValue, propDefSimple);
+ return propSimple;
+ }
+
+ public void populateMetaValueFromProperty(PropertySimple propSimple, MetaValue
metaValue,
+ PropertyDefinitionSimple propDefSimple)
+ {
+ if (metaValue == null)
+ throw new IllegalArgumentException("MetaValue to be populated is
null.");
+ String value;
+ if (propSimple == null || propSimple.getStringValue() == null)
+ {
+ // Value is null (i.e. prop is unset) - figure out what to use as a default
value.
+ String defaultValue = propDefSimple.getDefaultValue();
+ if (defaultValue != null)
+ {
+ log.debug("Simple property '" + propDefSimple.getName()
+ + "' has a null value - setting inner value of
corresponding ManagedProperty's MetaValue to plugin-specified default ('"
+ + defaultValue + "')...");
+ value = defaultValue;
+ }
+ else
+ {
+ if (metaValue.getMetaType().isPrimitive())
+ // If it's a primitive, don't mess with the MetaValue - just
let it keep whatever inner value it
+ // currently has.
+ return;
+ // It's a non-primitive - set its value to null. In most cases, this
should tell the managed resource
+ // to use its internal default.
+ log.debug("Simple property '" + propDefSimple.getName()
+ + "' has a null value - setting inner value of
corresponding ManagedProperty's MetaValue to null...");
+ value = null;
+ }
+ }
+ else
+ {
+ value = propSimple.getStringValue();
+ }
+ setInnerValue(value, metaValue, propDefSimple);
+ }
+
+ protected abstract void setInnerValue(String propSimpleValue, MetaValue metaValue,
PropertyDefinitionSimple propDefSimple);
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapter.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.rhq.core.domain.measurement.MeasurementDefinition;
+import org.rhq.core.domain.measurement.MeasurementReport;
+import org.rhq.core.domain.measurement.MeasurementScheduleRequest;
+
+import org.jboss.metatype.api.values.MetaValue;
+
+public interface MeasurementAdapter {
+ public void setMeasurementData(MeasurementReport report, MetaValue metaValue,
MeasurementScheduleRequest request,
+ MeasurementDefinition measurementDefinition);
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapterFactory.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapterFactory.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/MeasurementAdapterFactory.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.api;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.metatype.api.types.MetaType;
+
+public class MeasurementAdapterFactory
+{
+
+ private static final Log LOG = LogFactory.getLog(MeasurementAdapterFactory.class);
+
+ private static Map<String, String> customAdapters = new HashMap<String,
String>();
+
+ {
+ // Add customAdapters to the map
+ customAdapters.put("NoClasses", "NoClasses");
+ }
+
+ public static MeasurementAdapter getMeasurementPropertyAdapter(MetaType metaType)
+ {
+ MeasurementAdapter measurementAdapter = null;
+ if (metaType.isSimple())
+ {
+ // measurementAdapter = new SimpleMetaValueMeasurementAdapter();
+ }
+ else if (metaType.isGeneric())
+ {
+ measurementAdapter = null;
+ }
+ else if (metaType.isComposite())
+ {
+ measurementAdapter = null;
+ }
+ else if (metaType.isTable())
+ {
+ measurementAdapter = null;
+ }
+ else if (metaType.isCollection())
+ {
+ measurementAdapter = null;
+ }
+ else if (metaType.isArray())
+ {
+ measurementAdapter = null;
+ }
+
+ return measurementAdapter;
+ }
+
+ public static MeasurementAdapter getCustomMeasurementPropertyAdapter(String
measurementName)
+ {
+ MeasurementAdapter measurementAdapter = null;
+ String adapterClassName = customAdapters.get(measurementName);
+ if (adapterClassName != null && !adapterClassName.equals(""))
+ {
+ try
+ {
+ measurementAdapter =
(MeasurementAdapter)Class.forName(adapterClassName).newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ LOG.error("Cannot instantiate adapter class called " +
adapterClassName, e);
+ }
+ catch (IllegalAccessException e)
+ {
+ LOG.error("Cannot access adapter class called " +
adapterClassName, e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ LOG.error("Cannot find adapter class called " +
adapterClassName, e);
+ }
+ }
+ return measurementAdapter;
+ }
+}
Added: trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapter.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * An adapter that can convert back and forth between a specific type of {@link
MetaValue} and a specific type of {@link
+ * Property}.
+ *
+ * @author Mark Spritzler
+ * @author Ian Springer
+ */
+public interface PropertyAdapter<P extends Property, D extends PropertyDefinition>
+{
+ /**
+ * Given a {@link Property} and its {@link PropertyDefinition}, as well as a {@link
MetaValue}, populate that
+ * MetaValue so it corresponds to the Property. If the Property is a list or a map,
all descendant Property's should
+ * be added as descendants of the MetaValue.
+ *
+ * @param property the property to be copied
+ * @param metaValue the MetaValue to be populated; should not be null
+ * @param propertyDefinition the property's definition
+ */
+ public void populateMetaValueFromProperty(P property, MetaValue metaValue, D
propertyDefinition);
+
+ /**
+ * Given a {@link Property} and its {@link PropertyDefinition}, create and return a
corresponding {@link MetaValue}
+ * with the specified {@link MetaType}. If the Property is a list or a map, all
descendant Property's should be
+ * represented as descendants of the returned MetaValue. Generally this method can
simply create an empty MetaValue
+ * object and then delegate the population of the guts of the object to {@link
#populateMetaValueFromProperty(Property,
+ * MetaValue, PropertyDefinition)}.
+ *
+ * @param property the property to be converted
+ * @param propertyDefinition the property's definition
+ * @param metaType the type of MetaValue that should be created and
returned
+ * @return the MetaValue representation of the given Property
+ */
+ public MetaValue convertToMetaValue(P property, D propertyDefinition, MetaType
metaType);
+
+ /**
+ * Given a {@link Property} and its {@link PropertyDefinition}, as well as a {@link
MetaValue}, populate the
+ * Property so it corresponds to the MetaValue. If the MetaValue is a from of list or
map, all descendant
+ * MetaValue's should be added as descendants of the Property.
+ *
+ * @param property the property to be populated; should not be null
+ * @param metaValue the MetaValue to be copied
+ * @param propertyDefinition the property's definition
+ */
+ public void populatePropertyFromMetaValue(P property, MetaValue metaValue, D
propertyDefinition);
+
+ /**
+ * Given a {@link MetaValue}, create and return a corresponding {@link Property} with
the specified {@link
+ * PropertyDefinition}. If the MetaValue is a form of list or map, all descendant
MetaValue's should be represented
+ * as descendants of the returned Property. Generally this method can simply create
an empty Property object and
+ * then delegate the population of the guts of the object to {@link
#populatePropertyFromMetaValue(Property,
+ * MetaValue, PropertyDefinition)}.
+ *
+ * @param metaValue the metaValue to be converted
+ * @param propertyDefinition the definition of the property to be created and
returned
+ * @return the Property representation of the given MetaValue
+ */
+ public P convertToProperty(MetaValue metaValue, D propertyDefinition);
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapterFactory.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapterFactory.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/api/PropertyAdapterFactory.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.api;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.teiid.rhq.plugin.adapter.impl.PropertyListToArrayValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyListToCollectionValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyMapToCompositeValueSupportAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyMapToGenericValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyMapToMapCompositeValueSupportAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyMapToPropertiesValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertyMapToTableValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertySimpleToEnumValueAdapter;
+import org.teiid.rhq.plugin.adapter.impl.PropertySimpleToSimpleValueAdapter;
+
+import com.sun.istack.Nullable;
+
+/**
+ * @author Mark Spritzler
+ */
+public class PropertyAdapterFactory
+{
+ private static final Log LOG = LogFactory.getLog(PropertyAdapterFactory.class);
+
+ public static PropertyAdapter getPropertyAdapter(MetaValue metaValue)
+ {
+ if (metaValue == null)
+ {
+ LOG.debug("The MetaValue passed in is null.");
+ return null;
+ }
+ MetaType metaType = metaValue.getMetaType();
+ return getPropertyAdapter(metaType);
+ }
+
+ public static PropertyAdapter getPropertyAdapter(MetaType metaType)
+ {
+ PropertyAdapter propertyAdapter = null;
+ if (metaType.isSimple())
+ {
+ propertyAdapter = new PropertySimpleToSimpleValueAdapter();
+ }
+ else if (metaType.isGeneric())
+ {
+ propertyAdapter = new PropertyMapToGenericValueAdapter();
+ }
+ else if (metaType.isComposite())
+ {
+ if (metaType instanceof MapCompositeMetaType)
+ propertyAdapter = new PropertyMapToMapCompositeValueSupportAdapter();
+ else
+ propertyAdapter = new PropertyMapToCompositeValueSupportAdapter();
+ }
+ else if (metaType.isTable())
+ {
+ propertyAdapter = new PropertyMapToTableValueAdapter();
+ }
+ else if (metaType.isCollection())
+ {
+ propertyAdapter = new PropertyListToCollectionValueAdapter();
+ }
+ else if (metaType.isArray())
+ {
+ propertyAdapter = new PropertyListToArrayValueAdapter();
+ }
+ else if (metaType.isEnum())
+ {
+ propertyAdapter = new PropertySimpleToEnumValueAdapter();
+ }
+ else if (metaType instanceof PropertiesMetaType)
+ {
+ propertyAdapter = new PropertyMapToPropertiesValueAdapter();
+ }
+ else
+ {
+ LOG.warn("Unsupported MetaType: " + metaType);
+ }
+ return propertyAdapter;
+ }
+
+ @Nullable
+ public static PropertyAdapter getCustomPropertyAdapter(PropertySimple customProp)
+ {
+ if (customProp == null)
+ return null;
+ String adapterClassName = customProp.getStringValue();
+ PropertyAdapter propertyAdapter = null;
+ try
+ {
+ Class adapterClass = Class.forName(adapterClassName);
+ propertyAdapter = (PropertyAdapter)adapterClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ LOG.error("Unable to create custom adapter class for " + customProp
+ ".", e);
+ }
+ return propertyAdapter;
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/AbstractPropertyMapToCompositeValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/AbstractPropertyMapToCompositeValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/AbstractPropertyMapToCompositeValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,119 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.util.Set;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyMapAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertyMap} and a
{@link CompositeValue}.
+ * Subclasses exist for the two different implementations of
<code>CompositeValue</code>.
+ *
+ */
+public abstract class AbstractPropertyMapToCompositeValueAdapter extends
AbstractPropertyMapAdapter
+ implements PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public void populateMetaValueFromProperty(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ CompositeValue compositeValue = (CompositeValue)metaValue;
+ for (String mapMemberPropName : propMap.getMap().keySet())
+ {
+ Property mapMemberProp = propMap.get(mapMemberPropName);
+ PropertyDefinition mapMemberPropDef = propDefMap.get(mapMemberPropName);
+ MetaType mapMemberMetaType =
compositeValue.getMetaType().getType(mapMemberPropName);
+ if (mapMemberMetaType == null)
+ {
+ // this will occur when new map properties are added since they are not
present
+ // in the original metaValue which we are using
+ mapMemberMetaType = SimpleMetaType.STRING;
+ }
+ PropertyAdapter adapter =
PropertyAdapterFactory.getPropertyAdapter(mapMemberMetaType);
+ MetaValue mapMemberMetaValue = adapter.convertToMetaValue(mapMemberProp,
mapMemberPropDef, mapMemberMetaType);
+ putValue(compositeValue, mapMemberPropName, mapMemberMetaValue);
+ }
+ }
+
+ public MetaValue convertToMetaValue(PropertyMap propMap, PropertyDefinitionMap
propDefMap, MetaType metaType)
+ {
+ CompositeValue compositeValue = createCompositeValue(propDefMap, metaType);
+ populateMetaValueFromProperty(propMap, compositeValue, propDefMap);
+ return compositeValue;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ if (metaValue == null)
+ return;
+ CompositeValue compositeValue = (CompositeValue)metaValue;
+ Set<String> mapMemberPropNames = compositeValue.getMetaType().keySet();
+ // There won't be any keys when loading a Configuration for the first time.
+ for (String mapMemberPropName : mapMemberPropNames)
+ {
+ Property mapMemberProp = propMap.get(mapMemberPropName);
+ MetaValue mapMemberMetaValue = compositeValue.get(mapMemberPropName);
+ MetaType mapMemberMetaType =
compositeValue.getMetaType().getType(mapMemberPropName);
+ PropertyAdapter propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(mapMemberMetaType);
+ PropertyDefinition mapMemberPropDef = propDefMap.get(mapMemberPropName);
+ if (mapMemberProp == null)
+ {
+ if (mapMemberPropDef != null)
+ mapMemberProp = propertyAdapter.convertToProperty(mapMemberMetaValue,
mapMemberPropDef);
+ else
+ {
+ // If the member prop has no associated prop def, this is an
"open map".
+ if (!mapMemberMetaType.isSimple() &&
!mapMemberMetaType.isEnum())
+ {
+ log.debug("Map member prop [" + mapMemberMetaType +
"] is not a simple type - skipping...");
+ continue;
+ }
+ // Create a PropertySimple and populate it.
+ mapMemberProp = new PropertySimple(mapMemberPropName, null);
+ // NOTE: It's ok that the propDef is null -
PropertySimple*Adapter.populatePropertyFromMetaValue()
+ // doesn't use it for anything.
+ propertyAdapter.populatePropertyFromMetaValue(mapMemberProp,
mapMemberMetaValue, mapMemberPropDef);
+ }
+ propMap.put(mapMemberProp);
+ }
+ }
+ }
+
+ protected abstract void putValue(CompositeValue compositeValue, String key, MetaValue
value);
+
+ protected abstract CompositeValue createCompositeValue(PropertyDefinitionMap
propDefMap, MetaType metaType);
+}
\ No newline at end of file
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToArrayValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToArrayValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToArrayValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyListAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+
+/**
+ *
+ */
+public class PropertyListToArrayValueAdapter extends AbstractPropertyListAdapter
implements PropertyAdapter<PropertyList, PropertyDefinitionList>
+{
+ //@todo need to implement this like the other List to Collection, but not until there
is an actual property that needs this
+ public void populateMetaValueFromProperty(PropertyList property, MetaValue metaValue,
PropertyDefinitionList propertyDefinition)
+ {
+ PropertyDefinition memberDefinition = propertyDefinition.getMemberDefinition();
+ List<Property> properties = property.getList();
+ if (metaValue != null)
+ {
+ ArrayValueSupport valueSupport = (ArrayValueSupport)metaValue;
+ MetaType listMetaType = valueSupport.getMetaType().getElementType();
+ List<MetaValue> values = new
ArrayList<MetaValue>(properties.size());
+ for (Property propertyWithinList : properties)
+ {
+ MetaValue value = MetaValueFactory.getInstance().create(null);
+ PropertyAdapter<Property, PropertyDefinition> propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(listMetaType);
+ propertyAdapter.populateMetaValueFromProperty(propertyWithinList, value,
memberDefinition);
+ values.add(value);
+ }
+ valueSupport.setValue(values.toArray());
+ }
+ }
+
+ //@todo need to implement this like the other List to Collection, but not until there
is an actual property that needs this
+ public MetaValue convertToMetaValue(PropertyList property, PropertyDefinitionList
propertyDefinition, MetaType type)
+ {
+ return null;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyList property, MetaValue metaValue,
PropertyDefinitionList propertyDefinition)
+ {
+ PropertyDefinition memberDefinition = propertyDefinition.getMemberDefinition();
+ List<Property> properties = property.getList();
+
+ // Since we want to load the PropertyList with fresh values, we want it cleared
out
+ properties.clear();
+
+ if (metaValue != null)
+ {
+ ArrayValueSupport valueSupport = (ArrayValueSupport)metaValue;
+ MetaType listMetaType = valueSupport.getMetaType().getElementType();
+ MetaValue[] metaValues = (MetaValue[])valueSupport.getValue();
+ PropertyAdapter propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(listMetaType);
+ for (MetaValue value : metaValues)
+ {
+ Property propertyToAddToList = propertyAdapter.convertToProperty(value,
memberDefinition);
+ properties.add(propertyToAddToList);
+ }
+ }
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToCollectionValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToCollectionValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyListToCollectionValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+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.CollectionValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyListAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+
+/**
+ *
+ */
+public class PropertyListToCollectionValueAdapter extends AbstractPropertyListAdapter
implements PropertyAdapter<PropertyList, PropertyDefinitionList>
+{
+ private static final Log LOG =
LogFactory.getLog(PropertyListToCollectionValueAdapter.class);
+
+ public void populateMetaValueFromProperty(PropertyList property, MetaValue metaValue,
PropertyDefinitionList propertyDefinition)
+ {
+ PropertyDefinition listMemberPropDef = propertyDefinition.getMemberDefinition();
+ List<Property> listMemberProps = property.getList();
+ CollectionValueSupport collectionValue = (CollectionValueSupport)metaValue;
+ MetaType listMemberMetaType = collectionValue.getMetaType().getElementType();
+ MetaValue[] listMemberValues = new MetaValue[listMemberProps.size()];
+ PropertyAdapter propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(listMemberMetaType);
+ int memberIndex = 0;
+ for (Property listMemberProp : listMemberProps)
+ {
+ MetaValue listMemberValue =
propertyAdapter.convertToMetaValue(listMemberProp, listMemberPropDef,
listMemberMetaType);
+ listMemberValues[memberIndex++] = listMemberValue;
+ }
+ // Replace the existing elements with the new ones.
+ collectionValue.setElements(listMemberValues);
+ }
+
+ public MetaValue convertToMetaValue(PropertyList propertyList, PropertyDefinitionList
propertyListDefinition, MetaType metaType)
+ {
+ LOG.debug("GetMetaValue for property: " + propertyList.getName() +
" values: " + propertyList.getList().toString());
+ CollectionMetaType collectionMetaType = (CollectionMetaType)metaType;
+ MetaType memberMetaType = collectionMetaType.getElementType();
+ CollectionMetaType collectionType = new
CollectionMetaType(propertyListDefinition.getName(), memberMetaType);
+ CollectionValue collectionValue = new CollectionValueSupport(collectionType);
+ populateMetaValueFromProperty(propertyList, collectionValue,
propertyListDefinition);
+ return collectionValue;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyList propList, MetaValue metaValue,
PropertyDefinitionList propDefList)
+ {
+ PropertyDefinition memberPropDef = propDefList.getMemberDefinition();
+ if (propList != null)
+ {
+ // Since we want to load the PropertyList with fresh values, we want it
cleared out.
+ propList.getList().clear();
+ if (metaValue != null)
+ {
+ CollectionValue collectionValue = (CollectionValue)metaValue;
+ MetaType listMemberMetaType =
collectionValue.getMetaType().getElementType();
+ MetaValue[] listMemberValues = collectionValue.getElements();
+ PropertyAdapter propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(listMemberMetaType);
+ for (MetaValue listMemberValue : listMemberValues)
+ {
+ Property listMemberProp =
propertyAdapter.convertToProperty(listMemberValue, memberPropDef);
+ propList.add(listMemberProp);
+ }
+ }
+ }
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToCompositeValueSupportAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToCompositeValueSupportAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToCompositeValueSupportAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertyMap} and a
{@link CompositeValueSupport}.
+ * A <code>CompositeValueSupport</code> is a {@link CompositeValue}
implementation that contains items that may be of
+ * different types.
+ *
+ */
+public class PropertyMapToCompositeValueSupportAdapter extends
AbstractPropertyMapToCompositeValueAdapter
+ implements PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ protected void putValue(CompositeValue compositeValue, String key, MetaValue value)
+ {
+ CompositeValueSupport compositeValueSupport =
(CompositeValueSupport)compositeValue;
+ compositeValueSupport.set(key, value);
+ }
+
+ protected CompositeValue createCompositeValue(PropertyDefinitionMap propDefMap,
MetaType metaType)
+ {
+ MutableCompositeMetaType compositeMetaType;
+ if (metaType != null)
+ compositeMetaType = (MutableCompositeMetaType)metaType;
+ else
+ {
+ // TODO: See if this else block is actually necessary (I think it is needed
for creates).
+ String name = (propDefMap != null) ?
+ propDefMap.getName() : "CompositeMetaType";
+ String desc = (propDefMap != null && propDefMap.getDescription() !=
null) ?
+ propDefMap.getDescription() : "none";
+ compositeMetaType = new MutableCompositeMetaType(name, desc);
+ if (propDefMap != null)
+ {
+ for (PropertyDefinition mapMemberPropDef :
propDefMap.getPropertyDefinitions().values())
+ {
+ String mapMemberDesc = (propDefMap.getDescription() != null) ?
propDefMap.getDescription() : "none";
+ MetaType mapMemberMetaType =
ProfileServiceUtil.convertPropertyDefinitionToMetaType(mapMemberPropDef);
+ compositeMetaType.addItem(mapMemberPropDef.getName(), mapMemberDesc,
mapMemberMetaType);
+ }
+ }
+ }
+ return new CompositeValueSupport(compositeMetaType);
+ }
+}
\ No newline at end of file
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToGenericValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToGenericValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToGenericValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyMapAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+import org.teiid.rhq.plugin.util.ProfileServiceUtil;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertyMap} and a
{@link GenericValue}. The
+ * GenericValue's value is assumed to be a {@link ManagedObject}.
+ *
+ */
+public class PropertyMapToGenericValueAdapter extends AbstractPropertyMapAdapter
+ implements PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ public void populateMetaValueFromProperty(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ GenericValue genericValue = (GenericValue)metaValue;
+ if (!(genericValue.getValue() instanceof ManagedObject))
+ {
+ log.error("GenericValue's value [" + genericValue.getValue() +
"] is not a ManagedObject - not supported!");
+ return;
+ }
+ ManagedObject managedObject = (ManagedObject)genericValue.getValue();
+ for (String propName : propMap.getMap().keySet())
+ {
+ Property mapMemberProp = propMap.get(propName);
+ ManagedProperty managedProp = managedObject.getProperty(propName);
+ MetaType metaType = managedProp.getMetaType();
+ PropertyAdapter propertyAdapter =
PropertyAdapterFactory.getPropertyAdapter(metaType);
+ PropertyDefinition mapMemberPropDef = propDefMap.get(propName);
+ if (managedProp.getValue() == null)
+ {
+ MetaValue managedPropMetaValue =
propertyAdapter.convertToMetaValue(mapMemberProp, mapMemberPropDef, metaType);
+ managedProp.setValue(managedPropMetaValue);
+ }
+ else
+ {
+ MetaValue managedPropMetaValue = (MetaValue)managedProp.getValue();
+ propertyAdapter.populateMetaValueFromProperty(mapMemberProp,
managedPropMetaValue, mapMemberPropDef);
+ }
+ }
+ }
+
+ public MetaValue convertToMetaValue(PropertyMap propMap, PropertyDefinitionMap
propDefMap, MetaType metaType)
+ {
+ //GenericMetaType genericMetaType = (GenericMetaType)metaType;
+ ManagedObjectImpl managedObject = new ManagedObjectImpl(propDefMap.getName());
+ for (PropertyDefinition mapMemberPropDef :
propDefMap.getPropertyDefinitions().values())
+ {
+ ManagedPropertyImpl managedProp = new
ManagedPropertyImpl(mapMemberPropDef.getName());
+ MetaType managedPropMetaType =
ProfileServiceUtil.convertPropertyDefinitionToMetaType(mapMemberPropDef);
+ managedProp.setMetaType(managedPropMetaType);
+ managedProp.setManagedObject(managedObject);
+ managedObject.getProperties().put(managedProp.getName(), managedProp);
+ }
+ GenericValue genericValue = new GenericValueSupport(new
GenericMetaType(propDefMap.getName(),
+ propDefMap.getDescription()), managedObject);
+ populateMetaValueFromProperty(propMap, genericValue, propDefMap);
+ return genericValue;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ GenericValue genericValue = (GenericValue)metaValue;
+ ManagedObject managedObject = (ManagedObject)genericValue.getValue();
+ for (String propName : propDefMap.getPropertyDefinitions().keySet())
+ {
+ ManagedProperty managedProp = managedObject.getProperty(propName);
+ if (managedProp != null)
+ {
+ MetaType metaType = managedProp.getMetaType();
+ Object value;
+ if (metaType.isSimple())
+ {
+ SimpleValue simpleValue = (SimpleValue)managedProp.getValue();
+ value = simpleValue.getValue();
+ }
+ else if (metaType.isEnum())
+ {
+ EnumValue enumValue = (EnumValue)managedProp.getValue();
+ value = enumValue.getValue();
+ }
+ else
+ {
+ log.error("Nested ManagedProperty's value [" +
managedProp.getValue()
+ + "] is not a SimpleValue or EnumValue -
unsupported!");
+ continue;
+ }
+ propMap.put(new PropertySimple(propName, value));
+ }
+ }
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToMapCompositeValueSupportAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToMapCompositeValueSupportAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToMapCompositeValueSupportAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertyMap} and a
{@link
+ * MapCompositeValueSupport}. A <code>MapCompositeValueSupport</code> is a
{@link CompositeValue} implementation that
+ * contains items that are all of the same type; there is no predefined list of valid
keys, so it maps nicely to an
+ * "open" PropertyMap.
+ *
+ */
+public class PropertyMapToMapCompositeValueSupportAdapter extends
AbstractPropertyMapToCompositeValueAdapter implements PropertyAdapter<PropertyMap,
PropertyDefinitionMap>
+{
+ @Override
+ public void populateMetaValueFromProperty(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ MapCompositeValueSupport mapCompositeValueSupport =
(MapCompositeValueSupport)metaValue;
+ // First clear out all existing values from the MapCompositeValue.
+ for (String key : mapCompositeValueSupport.getMetaType().keySet())
+ {
+ mapCompositeValueSupport.remove(key);
+ }
+ // Now re-populate it with the values from the PropertyMap.
+ super.populateMetaValueFromProperty(propMap, metaValue, propDefMap);
+ }
+
+ protected void putValue(CompositeValue compositeValue, String key, MetaValue value)
+ {
+ MapCompositeValueSupport mapCompositeValueSupport =
(MapCompositeValueSupport)compositeValue;
+ mapCompositeValueSupport.put(key, value);
+ }
+
+ protected CompositeValue createCompositeValue(PropertyDefinitionMap propDefMap,
MetaType metaType)
+ {
+ MapCompositeMetaType mapCompositeMetaType = (MapCompositeMetaType)metaType;
+ MetaType mapMemberMetaType = mapCompositeMetaType.getValueType();
+ return new MapCompositeValueSupport(mapMemberMetaType);
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToPropertiesValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToPropertiesValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToPropertiesValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,86 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyMapAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertyMap} and a
{@link PropertiesMetaValue}. A
+ * <code>PropertiesMetaValue</code> extends java.util.Properties. Its
associated PropertiesMetaType may or may not
+ * define member property names; since the RHQ Configuration system assumes a
PropertyDefinitionMap either defines none
+ * of its member properties (i.e. an "open map") or defines all of them, we
just ignore the PropertiesMetaType and
+ * always map to an open map.
+ *
+ */
+public class PropertyMapToPropertiesValueAdapter extends AbstractPropertyMapAdapter
+ implements PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ public void populateMetaValueFromProperty(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ PropertiesMetaValue propertiesValue = (PropertiesMetaValue)metaValue;
+ for (String mapMemberPropName : propMap.getMap().keySet())
+ {
+ Property mapMemberProp = propMap.get(mapMemberPropName);
+ propertiesValue.setProperty(mapMemberProp.getName(),
((PropertySimple)mapMemberProp).getStringValue());
+ }
+ }
+
+ public MetaValue convertToMetaValue(PropertyMap propMap, PropertyDefinitionMap
propDefMap, MetaType metaType)
+ {
+ PropertiesMetaValue propertiesValue = new PropertiesMetaValue();
+ populateMetaValueFromProperty(propMap, propertiesValue, propDefMap);
+ return propertiesValue;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyMap propMap, MetaValue metaValue,
PropertyDefinitionMap propDefMap)
+ {
+ if (metaValue == null)
+ return;
+ PropertiesMetaValue propertiesValue = (PropertiesMetaValue)metaValue;
+ Set<String> mapMemberPropNames = new HashSet();
+ for (Object key : propertiesValue.keySet())
+ mapMemberPropNames.add((String)key);
+ // There won't be any keys when loading a Configuration for the first time.
+ for (String mapMemberPropName : mapMemberPropNames)
+ {
+ // We assume the PropertyMap is an "open map", since that's
what PropertiesMetaValue maps to.
+ PropertySimple mapMemberProp = propMap.getSimple(mapMemberPropName);
+ // Create a PropertySimple and populate it.
+ if (mapMemberProp == null)
+ {
+ mapMemberProp = new PropertySimple(mapMemberPropName,
propertiesValue.getProperty(mapMemberPropName));
+ propMap.put(mapMemberProp);
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToTableValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToTableValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertyMapToTableValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.api.values.TableValueSupport;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertyMapAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+
+/**
+ *
+ */
+public class PropertyMapToTableValueAdapter extends AbstractPropertyMapAdapter implements
PropertyAdapter<PropertyMap, PropertyDefinitionMap>
+{
+ public PropertyMap convertToProperty(MetaValue metaValue, PropertyDefinitionMap
propertyDefinition)
+ {
+ PropertyMap property = new PropertyMap();
+ populatePropertyFromMetaValue(property, metaValue, propertyDefinition);
+ return property;
+ }
+
+ //@todo need to implement this like the other Map to Composite, but not until there
is an actual property that needs this
+ public void populateMetaValueFromProperty(PropertyMap property, MetaValue metaValue,
PropertyDefinitionMap propertyDefinition)
+ {
+ if (metaValue != null)
+ {
+ TableValueSupport tableValueSupport = (TableValueSupport)metaValue;
+ Map<String, PropertyDefinition> map =
propertyDefinition.getPropertyDefinitions();
+ Map<String, Property> properties = property.getMap();
+ for (String key : map.keySet())
+ {
+ PropertyDefinition definition = map.get(key);
+ MetaValue[] getKey = new MetaValue[]{SimpleValueSupport.wrap(key)};
+ MetaValue value = tableValueSupport.get(getKey);
+ Property innerProperty = properties.get(key);
+ PropertyAdapter adapter =
PropertyAdapterFactory.getPropertyAdapter(value);
+ adapter.populateMetaValueFromProperty(innerProperty, value, definition);
+ }
+ }
+ }
+
+ //@todo need to implement this like the other Map to Composite, but not until there
is an actual property that needs this
+ public MetaValue convertToMetaValue(PropertyMap property, PropertyDefinitionMap
propertyDefinition, MetaType type)
+ {
+ return null;
+ }
+
+ public void populatePropertyFromMetaValue(PropertyMap property, MetaValue metaValue,
PropertyDefinitionMap propertyDefinition)
+ {
+ // Not important at this moment to implement as there sin't a need for this
mapping yet.
+ if (metaValue != null)
+ {
+ TableValueSupport valueSupport = (TableValueSupport)metaValue;
+ Collection<CompositeValue> values = valueSupport.values();
+ for (CompositeValue value : values)
+ {
+ CompositeValueSupport support = (CompositeValueSupport)value;
+ }
+ }
+ }
+}
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToEnumValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToEnumValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToEnumValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import org.jboss.metatype.api.types.EnumMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.EnumValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertySimpleAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertySimple} and
an {@link EnumValueSupport}.
+ *
+ */
+public class PropertySimpleToEnumValueAdapter extends AbstractPropertySimpleAdapter
implements PropertyAdapter<PropertySimple, PropertyDefinitionSimple>
+{
+ public void populatePropertyFromMetaValue(PropertySimple propSimple, MetaValue
metaValue, PropertyDefinitionSimple propDefSimple)
+ {
+ Object value = (metaValue != null) ? ((EnumValue)metaValue).getValue() : null;
+ propSimple.setValue(value);
+ }
+
+ public MetaValue convertToMetaValue(PropertySimple propSimple,
PropertyDefinitionSimple propDefSimple, MetaType metaType)
+ {
+ EnumValue enumValue = new EnumValueSupport((EnumMetaType)metaType,
propSimple.getStringValue());
+ populateMetaValueFromProperty(propSimple, enumValue, propDefSimple);
+ return enumValue;
+ }
+
+ protected void setInnerValue(String propSimpleValue, MetaValue metaValue,
PropertyDefinitionSimple propDefSimple)
+ {
+ EnumValueSupport enumValueSupport = (EnumValueSupport)metaValue;
+ enumValueSupport.setValue(propSimpleValue);
+ }
+}
\ No newline at end of file
Added:
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToSimpleValueAdapter.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToSimpleValueAdapter.java
(rev 0)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/adapter/impl/PropertySimpleToSimpleValueAdapter.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package org.teiid.rhq.plugin.adapter.impl;
+
+import java.io.Serializable;
+
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.teiid.rhq.plugin.adapter.api.AbstractPropertySimpleAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+
+/**
+ * This class provides code that maps back and forth between a {@link PropertySimple} and
a {@link SimpleValueSupport}.
+ *
+ */
+public class PropertySimpleToSimpleValueAdapter extends AbstractPropertySimpleAdapter
implements PropertyAdapter<PropertySimple, PropertyDefinitionSimple>
+{
+ public void populatePropertyFromMetaValue(PropertySimple propSimple, MetaValue
metaValue, PropertyDefinitionSimple propDefSimple)
+ {
+ Object value = (metaValue != null) ? ((SimpleValue)metaValue).getValue() : null;
+ propSimple.setValue(value);
+ }
+
+ public MetaValue convertToMetaValue(PropertySimple propSimple,
PropertyDefinitionSimple propDefSimple, MetaType metaType)
+ {
+ SimpleValue simpleValue = new SimpleValueSupport((SimpleMetaType)metaType,
null);
+ populateMetaValueFromProperty(propSimple, simpleValue, propDefSimple);
+ return simpleValue;
+ }
+
+ protected void setInnerValue(String propSimpleValue, MetaValue metaValue,
PropertyDefinitionSimple propDefSimple)
+ {
+ SimpleValueSupport simpleValueSupport = (SimpleValueSupport)metaValue;
+ if (propSimpleValue == null)
+ {
+ // A null value is the easiest case - just set the SimpleMetaValue's
inner value to null.
+ simpleValueSupport.setValue(null);
+ return;
+ }
+ // String value is non-null, so we can massage it into the proper type for the
SimpleMetaValue's inner value.
+ SimpleMetaType simpleMetaType = simpleValueSupport.getMetaType();
+ Serializable innerValue;
+ if (simpleMetaType.equals(SimpleMetaType.STRING) ||
simpleMetaType.equals(SimpleMetaType.NAMEDOBJECT))
+ innerValue = propSimpleValue;
+ else if (simpleMetaType.equals(SimpleMetaType.BOOLEAN) ||
simpleMetaType.equals(SimpleMetaType.BOOLEAN_PRIMITIVE))
+ innerValue = Boolean.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.BYTE) ||
simpleMetaType.equals(SimpleMetaType.BYTE_PRIMITIVE))
+ innerValue = Byte.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.CHARACTER) ||
simpleMetaType.equals(SimpleMetaType.CHARACTER_PRIMITIVE))
+ {
+ if (propSimpleValue.length() != 1)
+ throw new IllegalStateException("String value '" +
propSimpleValue + " cannot be converted to a character.");
+ innerValue = propSimpleValue.charAt(0);
+ }
+ else if (simpleMetaType.equals(SimpleMetaType.DOUBLE) ||
simpleMetaType.equals(SimpleMetaType.DOUBLE_PRIMITIVE))
+ innerValue = Double.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.FLOAT) ||
simpleMetaType.equals(SimpleMetaType.FLOAT_PRIMITIVE))
+ innerValue = Float.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.INTEGER) ||
simpleMetaType.equals(SimpleMetaType.INTEGER_PRIMITIVE))
+ innerValue = Integer.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.LONG) ||
simpleMetaType.equals(SimpleMetaType.LONG_PRIMITIVE))
+ innerValue = Long.valueOf(propSimpleValue);
+ else if (simpleMetaType.equals(SimpleMetaType.SHORT) ||
simpleMetaType.equals(SimpleMetaType.SHORT_PRIMITIVE))
+ innerValue = Short.valueOf(propSimpleValue);
+ else
+ throw new IllegalStateException("Unsupported MetaType: " +
simpleMetaType);
+ simpleValueSupport.setValue(innerValue);
+ }
+}
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java
===================================================================
---
trunk/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java 2010-05-19
21:07:59 UTC (rev 2144)
+++
trunk/console/src/main/java/org/teiid/rhq/plugin/util/ProfileServiceUtil.java 2010-05-19
23:20:03 UTC (rev 2145)
@@ -1,8 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library 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 library 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 library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package org.teiid.rhq.plugin.util;
import java.io.File;
+import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Set;
import javax.naming.InitialContext;
@@ -17,21 +45,104 @@
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedDeployment;
import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.types.SimpleMetaType;
import org.jboss.metatype.api.values.EnumValue;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
import org.jboss.profileservice.spi.ProfileService;
+import org.rhq.core.domain.configuration.Configuration;
+import org.rhq.core.domain.configuration.Property;
+import org.rhq.core.domain.configuration.PropertyMap;
+import org.rhq.core.domain.configuration.PropertySimple;
+import org.rhq.core.domain.configuration.definition.ConfigurationDefinition;
+import org.rhq.core.domain.configuration.definition.ConfigurationTemplate;
+import org.rhq.core.domain.configuration.definition.PropertyDefinition;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionList;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionMap;
+import org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
+import org.rhq.core.domain.configuration.definition.PropertySimpleType;
+import org.rhq.core.domain.resource.ResourceType;
+import org.teiid.rhq.plugin.TranslatorComponent;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapter;
+import org.teiid.rhq.plugin.adapter.api.PropertyAdapterFactory;
+import com.sun.istack.NotNull;
+import com.sun.istack.Nullable;
public class ProfileServiceUtil {
- protected final Log LOG = LogFactory.getLog(ProfileServiceUtil.class);
+ protected final static Log LOG = LogFactory
+ .getLog(ProfileServiceUtil.class);
private static ComponentType DQPTYPE = new ComponentType("teiid",
"dqp");
private static String DQPNAME =
"org.teiid.jboss.deployers.RuntimeEngineDeployer";
+ private static final Map<String, ComponentType> COMPONENT_TYPE_CACHE = new
HashMap<String, ComponentType>();
+ private static final Map<String, KnownDeploymentTypes> DEPLOYMENT_TYPE_CACHE = new
HashMap<String, KnownDeploymentTypes>();
+ private static final Map<String, Configuration> DEFAULT_PLUGIN_CONFIG_CACHE = new
HashMap<String, Configuration>();
+ protected static final String PLUGIN = "ProfileService";
+
+ public static ComponentType getComponentType(
+ @NotNull ResourceType resourceType) {
+ String resourceTypeName = resourceType.getName();
+ if (COMPONENT_TYPE_CACHE.containsKey(resourceTypeName))
+ return COMPONENT_TYPE_CACHE.get(resourceTypeName);
+ Configuration defaultPluginConfig = getDefaultPluginConfiguration(resourceType);
+ String type = defaultPluginConfig.getSimpleValue(
+ TranslatorComponent.Config.COMPONENT_TYPE, null);
+ if (type == null || type.equals(""))
+ throw new IllegalStateException(
+ "Required plugin configuration property '"
+ + TranslatorComponent.Config.COMPONENT_TYPE
+ + "' is not defined in default template.");
+ String subtype = defaultPluginConfig.getSimpleValue(
+ TranslatorComponent.Config.COMPONENT_SUBTYPE, null);
+ if (subtype == null || subtype.equals(""))
+ throw new IllegalStateException(
+ "Required plugin configuration property '"
+ + TranslatorComponent.Config.COMPONENT_SUBTYPE
+ + "' is not defined in default template.");
+ ComponentType componentType = new ComponentType(type, subtype);
+ COMPONENT_TYPE_CACHE.put(resourceTypeName, componentType);
+ return componentType;
+ }
+
+ private static Configuration getDefaultPluginConfiguration(
+ ResourceType resourceType) {
+ ConfigurationTemplate pluginConfigDefaultTemplate = resourceType
+ .getPluginConfigurationDefinition().getDefaultTemplate();
+ return (pluginConfigDefaultTemplate != null) ? pluginConfigDefaultTemplate
+ .createConfiguration()
+ : new Configuration();
+ }
+
/**
+ * @param name
+ * @param componentType
+ * @return
+ */
+ public static boolean isManagedComponent(ManagementView managementView,
+ String name, ComponentType componentType) {
+ boolean isDeployed = false;
+ if (name != null) {
+ try {
+ ManagedComponent component = getManagedComponent(componentType,
+ name);
+ if (component != null)
+ isDeployed = true;
+ } catch (Exception e) {
+ // Setting it to true to be safe than sorry, since there might
+ // be a component
+ // already deployed in the AS.
+ isDeployed = true;
+ }
+ }
+ return isDeployed;
+ }
+
+ /**
* Get the passed in {@link ManagedComponent}
*
* @return {@link ManagedComponent}
@@ -45,7 +156,7 @@
ManagementView mv = getManagementView(ps, true);
ManagedComponent mc = mv.getComponent(componentName, componentType);
-
+
return mc;
}
@@ -54,7 +165,8 @@
* type.
*
* @return Set of {@link ManagedComponent}s
- * @throws NamingException, Exception
+ * @throws NamingException
+ * , Exception
* @throws Exception
*/
public static Set<ManagedComponent> getManagedComponents(
@@ -71,7 +183,8 @@
* @param {@link ManagementView}
* @return
*/
- public static ManagementView getManagementView(ProfileService ps, boolean load) {
+ public static ManagementView getManagementView(ProfileService ps,
+ boolean load) {
ManagementView mv = ps.getViewManager();
if (load) {
mv.load();
@@ -96,7 +209,8 @@
/**
* @return {@link ProfileService}
- * @throws NamingException, Exception
+ * @throws NamingException
+ * , Exception
*/
public static ProfileService getProfileService() throws NamingException {
InitialContext ic = new InitialContext();
@@ -107,7 +221,8 @@
/**
* @return {@link File}
- * @throws NamingException, Exception
+ * @throws NamingException
+ * , Exception
*/
public static File getDeployDirectory() throws NamingException, Exception {
ProfileService ps = getProfileService();
@@ -141,51 +256,280 @@
File deployDir = warFile.getParentFile();
return deployDir;
}
-
- public static ManagedComponent getDQPManagementView() throws NamingException, Exception
{
-
+
+ public static ManagedComponent getDQPManagementView()
+ throws NamingException, Exception {
+
return getManagedComponent(DQPTYPE, DQPNAME);
}
-
+
public static String stringValue(MetaValue v1) throws Exception {
if (v1 != null) {
MetaType type = v1.getMetaType();
if (type instanceof SimpleMetaType) {
- SimpleValue simple = (SimpleValue)v1;
+ SimpleValue simple = (SimpleValue) v1;
return simple.getValue().toString();
}
throw new Exception("Failed to convert value to string value");
}
return null;
- }
-
+ }
+
public static Boolean booleanValue(MetaValue v1) throws Exception {
if (v1 != null) {
MetaType type = v1.getMetaType();
if (type instanceof SimpleMetaType) {
- SimpleValue simple = (SimpleValue)v1;
+ SimpleValue simple = (SimpleValue) v1;
return Boolean.valueOf(simple.getValue().toString());
}
throw new Exception("Failed to convert value to boolean value");
}
return null;
- }
+ }
+
+ public static <T> T getSimpleValue(ManagedComponent mc, String prop,
+ Class<T> expectedType) {
+ ManagedProperty mp = mc.getProperty(prop);
+ if (mp != null) {
+ MetaType metaType = mp.getMetaType();
+ if (metaType.isSimple()) {
+ SimpleValue simpleValue = (SimpleValue) mp.getValue();
+ return expectedType.cast((simpleValue != null) ? simpleValue
+ .getValue() : null);
+ } else if (metaType.isEnum()) {
+ EnumValue enumValue = (EnumValue) mp.getValue();
+ return expectedType.cast((enumValue != null) ? enumValue
+ .getValue() : null);
+ }
+ throw new IllegalStateException(prop + " is not a simple type");
+ }
+ return null;
+ }
+
+ public static Map<String, PropertySimple> getCustomProperties(
+ Configuration pluginConfig) {
+ Map<String, PropertySimple> customProperties = new LinkedHashMap<String,
PropertySimple>();
+ if (pluginConfig == null)
+ return customProperties;
+ PropertyMap customPropsMap = pluginConfig.getMap("custom-properties");
+ if (customPropsMap != null) {
+ Collection<Property> customProps = customPropsMap.getMap().values();
+ for (Property customProp : customProps) {
+ if (!(customProp instanceof PropertySimple)) {
+ LOG
+ .error("Custom property definitions in plugin configuration must be simple
properties - property "
+ + customProp + " is not - ignoring...");
+ continue;
+ }
+ customProperties.put(customProp.getName(),
+ (PropertySimple) customProp);
+ }
+ }
+ return customProperties;
+ }
+
+ public static Configuration convertManagedObjectToConfiguration(
+ Map<String, ManagedProperty> managedProperties,
+ Map<String, PropertySimple> customProps, ResourceType resourceType) {
+ Configuration config = new Configuration();
+ ConfigurationDefinition configDef = resourceType
+ .getResourceConfigurationDefinition();
+ Map<String, PropertyDefinition> propDefs = configDef
+ .getPropertyDefinitions();
+ Set<String> propNames = managedProperties.keySet();
+ for (String propName : propNames) {
+ PropertyDefinition propertyDefinition = propDefs.get(propName);
+ ManagedProperty managedProperty = managedProperties.get(propName);
+ if (propertyDefinition == null) {
+ if (!managedProperty.hasViewUse(ViewUse.STATISTIC))
+ LOG
+ .debug(resourceType
+ + " does not define a property corresponding to ManagedProperty
'"
+ + propName + "'.");
+ continue;
+ }
+ if (managedProperty == null) {
+ // This should never happen, but don't let it blow us up.
+ LOG.error("ManagedProperty '" + propName
+ + "' has a null value in the ManagedProperties Map.");
+ continue;
+ }
+ MetaValue metaValue = managedProperty.getValue();
+ if (managedProperty.isRemoved() || metaValue == null) {
+ // Don't even add a Property to the Configuration if the
+ // ManagedProperty is flagged as removed or has a
+ // null value.
+ continue;
+ }
+ PropertySimple customProp = customProps.get(propName);
+ PropertyAdapter<Property, PropertyDefinition> propertyAdapter =
PropertyAdapterFactory
+ .getCustomPropertyAdapter(customProp);
+ if (propertyAdapter == null)
+ propertyAdapter = PropertyAdapterFactory
+ .getPropertyAdapter(metaValue);
+ if (propertyAdapter == null) {
+ LOG
+ .error("Unable to find a PropertyAdapter for ManagedProperty '"
+ + propName
+ + "' with MetaType ["
+ + metaValue.getMetaType()
+ + "] for ResourceType '"
+ + resourceType.getName() + "'.");
+ continue;
+ }
+ Property property = propertyAdapter.convertToProperty(metaValue,
+ propertyDefinition);
+ config.put(property);
+ }
+ return config;
+ }
+
+ public static void convertConfigurationToManagedProperties(
+ Map<String, ManagedProperty> managedProperties,
+ Configuration configuration, ResourceType resourceType) {
+ ConfigurationDefinition configDefinition = resourceType
+ .getResourceConfigurationDefinition();
+ for (ManagedProperty managedProperty : managedProperties.values()) {
+ String propertyName = managedProperty.getName();
+ PropertyDefinition propertyDefinition = configDefinition
+ .get(propertyName);
+ if (propertyDefinition==null){
+ //The managed property is not defined in the configuration
+ continue;
+ }
+ populateManagedPropertyFromProperty(managedProperty,
+ propertyDefinition, configuration);
+ }
+ return;
+ }
+
+ private static void populateManagedPropertyFromProperty(ManagedProperty
managedProperty,
+ PropertyDefinition propertyDefinition, Configuration configuration) {
+ // If the ManagedProperty defines a default value, assume it's more
+ // definitive than any default value that may
+ // have been defined in the plugin descriptor, and update the
+ // PropertyDefinition to use that as its default
+ // value.
+ MetaValue defaultValue = managedProperty.getDefaultValue();
+ if (defaultValue != null)
+ updateDefaultValueOnPropertyDefinition(propertyDefinition,
+ defaultValue);
+ MetaValue metaValue = managedProperty.getValue();
+ PropertyAdapter propertyAdapter = null;
+ if (metaValue != null) {
+ LOG.trace("Populating existing MetaValue of type "
+ + metaValue.getMetaType() + " from RHQ property "
+ + propertyDefinition.getName() + " with definition " + propertyDefinition
+ + "...");
+ propertyAdapter = PropertyAdapterFactory
+ .getPropertyAdapter(metaValue);
+ propertyAdapter.populateMetaValueFromProperty(configuration.getSimple(propertyDefinition.getName()),
metaValue,
+ propertyDefinition);
+ } else {
+ MetaType metaType = managedProperty.getMetaType();
+ if (propertyAdapter == null)
+ propertyAdapter = PropertyAdapterFactory
+ .getPropertyAdapter(metaType);
+ LOG.trace("Converting property " + propertyDefinition.getName() + "
with definition "
+ + propertyDefinition + " to MetaValue of type " + metaType
+ + "...");
+ metaValue =
propertyAdapter.convertToMetaValue(configuration.getSimple(propertyDefinition.getName()),
+ propertyDefinition, metaType);
+ managedProperty.setValue(metaValue);
+ }
+ }
+
+ private static void updateDefaultValueOnPropertyDefinition(
+ PropertyDefinition propertyDefinition,
+ @NotNull MetaValue defaultValue) {
+ if (!(propertyDefinition instanceof PropertyDefinitionSimple)) {
+ LOG
+ .debug("Cannot update default value on non-simple property definition "
+ + propertyDefinition
+ + "(default value is "
+ + defaultValue + ").");
+ return;
+ }
+ MetaType metaType = defaultValue.getMetaType();
+ if (!metaType.isSimple() && !metaType.isEnum()) {
+ LOG.debug("Cannot update default value on " + propertyDefinition
+ + ", because default value's type (" + metaType
+ + ") is not simple or enum.");
+ return;
+ }
+ PropertyDefinitionSimple propertyDefinitionSimple = (PropertyDefinitionSimple)
propertyDefinition;
+ if (metaType.isSimple()) {
+ SimpleValue defaultSimpleValue = (SimpleValue) defaultValue;
+ Serializable value = defaultSimpleValue.getValue();
+ propertyDefinitionSimple.setDefaultValue((value != null) ? value
+ .toString() : null);
+ } else { // defaultValueMetaType.isEnum()
+ EnumValue defaultEnumValue = (EnumValue) defaultValue;
+ Serializable value = defaultEnumValue.getValue();
+ propertyDefinitionSimple.setDefaultValue((value != null) ? value
+ .toString() : null);
+ }
+ }
+
+ public static MetaType convertPropertyDefinitionToMetaType(
+ PropertyDefinition propDef) {
+ MetaType memberMetaType;
+ if (propDef instanceof PropertyDefinitionSimple) {
+ PropertySimpleType propSimpleType = ((PropertyDefinitionSimple) propDef)
+ .getType();
+ memberMetaType = convertPropertySimpleTypeToSimpleMetaType(propSimpleType);
+ } else if (propDef instanceof PropertyDefinitionList) {
+ // TODO (very low priority, since lists of lists are not going to be
+ // at all common)
+ memberMetaType = null;
+ } else if (propDef instanceof PropertyDefinitionMap) {
+ Map<String, PropertyDefinition> memberPropDefs = ((PropertyDefinitionMap)
propDef)
+ .getPropertyDefinitions();
+ if (memberPropDefs.isEmpty())
+ throw new IllegalStateException(
+ "PropertyDefinitionMap doesn't contain any member
PropertyDefinitions.");
+ // NOTE: We assume member prop defs are all of the same type, since
+ // for MapCompositeMetaTypes, they have to be.
+ PropertyDefinition mapMemberPropDef = memberPropDefs.values()
+ .iterator().next();
+ MetaType mapMemberMetaType = convertPropertyDefinitionToMetaType(mapMemberPropDef);
+ memberMetaType = new MapCompositeMetaType(mapMemberMetaType);
+ } else {
+ throw new IllegalStateException(
+ "List member PropertyDefinition has unknown type: "
+ + propDef.getClass().getName());
+ }
+ return memberMetaType;
+ }
- public static <T> T getSimpleValue(ManagedComponent mc, String prop,
Class<T> expectedType) {
- ManagedProperty mp = mc.getProperty(prop);
- if (mp != null) {
- MetaType metaType = mp.getMetaType();
- if (metaType.isSimple()) {
- SimpleValue simpleValue = (SimpleValue)mp.getValue();
- return expectedType.cast((simpleValue != null) ? simpleValue.getValue() :
null);
- }
- else if (metaType.isEnum()) {
- EnumValue enumValue = (EnumValue)mp.getValue();
- return expectedType.cast((enumValue != null) ? enumValue.getValue() : null);
- }
- throw new IllegalStateException(prop+ " is not a simple type");
- }
- return null;
- }
+ private static MetaType convertPropertySimpleTypeToSimpleMetaType(PropertySimpleType
memberSimpleType)
+ {
+ MetaType memberMetaType;
+ Class memberClass;
+ switch (memberSimpleType)
+ {
+ case BOOLEAN:
+ memberClass = Boolean.class;
+ break;
+ case INTEGER:
+ memberClass = Integer.class;
+ break;
+ case LONG:
+ memberClass = Long.class;
+ break;
+ case FLOAT:
+ memberClass = Float.class;
+ break;
+ case DOUBLE:
+ memberClass = Double.class;
+ break;
+ default:
+ memberClass = String.class;
+ break;
+ }
+ memberMetaType = SimpleMetaType.resolve(memberClass.getName());
+ return memberMetaType;
+ }
+
}
Modified: trunk/console/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-05-19 21:07:59 UTC (rev
2144)
+++ trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-05-19 23:20:03 UTC (rev
2145)
@@ -25,6 +25,40 @@
'>
<!ENTITY translatorConfiguration '
+
+ <c:list-property name="translatorList" description="Properties for
this translator"
+ readOnly="true">
+ <c:simple-property name="name" displayName="Name"
+ description="Name of the translator" />
+ <c:simple-property name="execution-factory-class"
displayName="execution-factory-class"
+ description="Connector Class" />
+ <c:simple-property name="capabilities-class"
displayName="capabilities-class"
+ description="The class to use to provide the Connector Capabilities"
/>
+ <c:simple-property name="override-capabilities-file"
displayName="override-capabilities-file"
+ description="Property file that defines the override capability
properties" />
+ <c:simple-property name="immutable" displayName="immutable"
+ description="Is Immutable, True if the source never changes."
type="boolean" default="false" />
+ <c:simple-property name="exception-on-max-rows"
displayName="exception-on-max-rows" type="boolean"
default="false" />
+ description="Indicates if an Exception should be thrown if the specified
value for Maximum Result Rows is exceeded; else no exception and no more than the maximum
will be returned" default="false" />
+ <c:simple-property name="max-result-rows"
displayName="max-result-rows"
+ description="Maximum Result Rows allowed" default="false"
/>
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
type="boolean" default="false" />
+ <c:list-property name="translatorList" description="Properties
for this translator"
+ readOnly="true">
+ <c:map-property name="translator-properties" >
+ <c:simple-property name="name" displayName="Name"
+ description="Name of this property" readOnly="true" />
+ <c:simple-property name="value" displayName="Value"
+ description="Value of this property" />
+ <c:simple-property name="description"
displayName="Description"
+ description="Description of this property" />
+ </c:map-property>
+ </c:list-property>
+
+'>
+
+<!ENTITY accessTranslatorConfiguration '
<resource-configuration>
<c:list-property name="translatorList" description="Properties for
this translator"
readOnly="true">
@@ -37,11 +71,9 @@
description="Description of this property" readOnly="true"
/>
</c:map-property>
</c:list-property>
- </resource-configuration>
+ </resource-configuration>
-
-'>
-
+'>
<!ENTITY datasourceAndConnectionFactoryOperations '
<operation name="flush" displayName="Flush"
@@ -1258,10 +1290,203 @@
</service>
<service name="Translators" description="Teiid Translators"
- class="TranslatorComponent"
discovery="TranslatorDiscoveryComponent">
+ class="TranslatorComponent"
discovery="TranslatorDiscoveryComponent"
+ createDeletePolicy="both" creationDataType="configuration">
- &translatorConfiguration;
+ <plugin-configuration>
+ <c:simple-property name="componentType" default="teiid"
+ readOnly="true" />
+ <c:simple-property name="componentSubtype"
+ default="translator" readOnly="true" />
+ <c:simple-property name="componentName" default="teiid"
+ readOnly="true" />
+ <c:simple-property name="template-name" default="translator"
+ readOnly="true" />
+ <c:simple-property name="resourceName" default="name">
+ <c:description>The name of the Resource configuration property
+ whose value should be used as the
+ Resource name when creating a new
+ Resource of this type.</c:description>
+ </c:simple-property>
+ </plugin-configuration>
+ <resource-configuration>
+ <c:simple-property name="name" displayName="Name"
+ description="Name of the translator" />
+ <c:simple-property name="execution-factory-class"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="immutable" displayName="immutable"
+ description="Is Immutable, True if the source never changes."
type="boolean"
+ default="false" />
+ <c:simple-property name="exception-on-max-rows"
+ displayName="exception-on-max-rows"
+ description="Indicates if an Exception should be thrown if the
+ specified value for Maximum Result Rows is exceeded; else no
+ exception and no more than the maximum will be returned"
+ type="boolean" default="false" defaultValue="false"
/>
+ <c:simple-property name="max-result-rows"
+ displayName="max-result-rows" description="Maximum Result Rows
allowed"
+ default="false" />
+ <c:simple-property name="xa-capable" displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="false" />
+ <c:list-property name="translatorList" readOnly="true"
required="false"
+ displayName="Translator Specific Properties" description="List of
translator specific properties">
+ <c:map-property name="translator-properties" >
+ <c:simple-property name="name" displayName="Name"
+ description="Name of this property" readOnly="true" />
+ <c:simple-property name="value" displayName="Value"
+ description="Value of this property" />
+ <c:simple-property name="description"
+ displayName="Description" description="Description of this
property" />
+ </c:map-property>
+ </c:list-property>
+ <c:simple-property name="template-name" default="translator"
+ readOnly="true" />
+
+ <c:template name="Access" description="Translator for
Access">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.access.AccessExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="DB2" description="Translator for DB2">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.db2.DB2ExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="Derby" description="Translator for
Derby">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.derby.DerbyExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="H2" description="Translator for H2">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.h2.H2ExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="HSQL" description="Translator for HSQL">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.hsql.HsqlExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="MySQL" description="Translator for
MySQL">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.mysql.MySQLExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="MySQL5" description="Translator for MySQL
5">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.mysql5.MySQL5ExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="Oracle" description="Translator for
Oracle">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.oracle.OracleExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="SQLServer" description="Translator for
SQLServer">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.oracle.SQLServerExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="Sybase" description="Translator for
Sybase">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.jdbc.sybase.SybaseExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-jdbc-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="LDAP" description="Translator for LDAP">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.ldap.LDAPExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-ldap-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="SalesForce" description="Translator for
SalesForce">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.salesforce.SalesForceExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-salesforce-${project.version}"
readOnly="true" />
+ </c:template>
+ <c:template name="XML" description="Translator for XML">
+ <c:simple-property name="execution-factory-class"
+ default="org.teiid.translator.xml.XMLExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-xml-${project.version}" readOnly="true"
/>
+ </c:template>
+ <c:template name="Loopback" description="Translator for
Loopback">
+ <c:simple-property name="execution-factory-class"
+ default=">org.teiid.translator.loopback.LoopbackExecutionFactory"
+ displayName="execution-factory-class" description="Connector
Class" />
+ <c:simple-property name="xa-capable"
displayName="xa-capable"
+ description="True, if this connector supports XA Transactions"
+ type="boolean" default="true" />
+ <c:simple-property name="template-name"
+ default="translator-loopback-${project.version}"
readOnly="true" />
+ </c:template>
+
+ </resource-configuration>
+
</service>
</server>