[jboss-cvs] JBossAS SVN: r85723 - in projects/jboss-man/tags: 2.1.0.CR4 and 21 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 11 03:26:36 EDT 2009
Author: scott.stark at jboss.org
Date: 2009-03-11 03:26:35 -0400 (Wed, 11 Mar 2009)
New Revision: 85723
Added:
projects/jboss-man/tags/2.1.0.CR4/
projects/jboss-man/tags/2.1.0.CR4/build/pom.xml
projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationMatcher.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/CompositeDataMetaValueBuilder.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/JmsDestinationTemplateInfo.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/PlatformMBeanUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java
projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/pom.xml
Removed:
projects/jboss-man/tags/2.1.0.CR4/build/pom.xml
projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java
projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java
projects/jboss-man/tags/2.1.0.CR4/pom.xml
Log:
[maven-release-plugin] copy for tag 2.1.0.CR4
Copied: projects/jboss-man/tags/2.1.0.CR4 (from rev 84388, projects/jboss-man/branches/Branch_2_1)
Deleted: projects/jboss-man/tags/2.1.0.CR4/build/pom.xml
===================================================================
--- projects/jboss-man/branches/Branch_2_1/build/pom.xml 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/build/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,54 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-man-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-man</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- <packaging>pom</packaging>
- <name>JBoss Managed Distribution</name>
- <url>http://www.jboss.org/jbossmc</url>
- <description>JBoss Managed Distribution Build</description>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <version>2.2-beta-2</version>
- <executions>
- <execution>
- <id>make-assembly</id>
- <phase>package</phase>
- <goals>
- <goal>attached</goal>
- </goals>
- <configuration>
- <finalName>jboss-man-${project.version}</finalName>
- <descriptors>
- <descriptor>src/assembly/dist.xml</descriptor>
- <descriptor>src/assembly/dist-with-deps.xml</descriptor>
- <descriptor>src/assembly/src.xml</descriptor>
- </descriptors>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-managed</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-metatype</artifactId>
- </dependency>
- </dependencies>
-
-</project>
Copied: projects/jboss-man/tags/2.1.0.CR4/build/pom.xml (from rev 85722, projects/jboss-man/branches/Branch_2_1/build/pom.xml)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/build/pom.xml (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/build/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,54 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-man-parent</artifactId>
+ <version>2.1.0.CR4</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-man</artifactId>
+ <version>2.1.0.CR4</version>
+ <packaging>pom</packaging>
+ <name>JBoss Managed Distribution</name>
+ <url>http://www.jboss.org/jbossmc</url>
+ <description>JBoss Managed Distribution Build</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.2-beta-2</version>
+ <executions>
+ <execution>
+ <id>make-assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attached</goal>
+ </goals>
+ <configuration>
+ <finalName>jboss-man-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/dist.xml</descriptor>
+ <descriptor>src/assembly/dist-with-deps.xml</descriptor>
+ <descriptor>src/assembly/src.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+ </dependencies>
+
+</project>
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/pom.xml 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,66 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-man-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>jboss-managed</artifactId>
- <packaging>jar</packaging>
- <name>JBoss Managed</name>
- <url>http://www.jboss.org/jbossmc</url>
- <description>JBoss Managed</description>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-assembly-plugin</artifactId>
- <configuration>
- <descriptors>
- <descriptor>src/assembly/api.xml</descriptor>
- <descriptor>src/assembly/plugins.xml</descriptor>
- </descriptors>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <!-- Do not add version information here, use ../pom.xml instead -->
- <dependencies>
- <!-- Global dependencies -->
- <dependency>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-metatype</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-mdr</artifactId>
- </dependency>
- <!-- Test dependencies -->
- <dependency>
- <groupId>sun-jaxb</groupId>
- <artifactId>jaxb-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-log4j</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test</groupId>
- <artifactId>jboss-test</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
\ No newline at end of file
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml (from rev 85722, projects/jboss-man/branches/Branch_2_1/managed/pom.xml)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,66 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-man-parent</artifactId>
+ <version>2.1.0.CR4</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-managed</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Managed</name>
+ <url>http://www.jboss.org/jbossmc</url>
+ <description>JBoss Managed</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <descriptors>
+ <descriptor>src/assembly/api.xml</descriptor>
+ <descriptor>src/assembly/plugins.xml</descriptor>
+ </descriptors>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- Do not add version information here, use ../pom.xml instead -->
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-mdr</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>sun-jaxb</groupId>
+ <artifactId>jaxb-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,66 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.api;
-
-import java.util.Map;
-
-import org.jboss.managed.api.ManagedProperty;
-
-/**
- * The exportable information for a DeploymentTemplate.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public interface DeploymentTemplateInfo
-{
- /**
- * The name of the DeploymentTemplate this info corresponds to
- * @return name of the deployment template
- */
- public String getName();
- /**
- * Information about the deployment template
- * @return Information about the deployment template
- */
- public String getDescription();
-
- /**
- * The name of the ManagedProperty in the Map<String, ManagedObject> map
- * obtained from the mainDeployer.getManagedObjects(VFSDeployment)
- * for the DeploymentTemplate this info is associated with.
- */
- public String getRootManagedPropertyName();
-
- /**
- * Get the template properties.
- * @return A name to property mapping of the properties that can be set
- * for use by the deployment template.
- */
- public Map<String, ManagedProperty> getProperties();
-
- /**
- *
- * @return
- */
- public DeploymentTemplateInfo copy();
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/DeploymentTemplateInfo.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.api;
+
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * The exportable information for a DeploymentTemplate.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface DeploymentTemplateInfo
+{
+ /**
+ * The name of the DeploymentTemplate this info corresponds to
+ * @return name of the deployment template
+ */
+ public String getName();
+ /**
+ * Information about the deployment template
+ * @return Information about the deployment template
+ */
+ public String getDescription();
+
+ /**
+ * The name of the ManagedProperty in the Map<String, ManagedObject> map
+ * obtained from the mainDeployer.getManagedObjects(VFSDeployment)
+ * for the DeploymentTemplate this info is associated with.
+ */
+ public String getRootManagedPropertyName();
+
+ /**
+ * Get the template properties.
+ * @return A name to property mapping of the properties that can be set
+ * for use by the deployment template.
+ */
+ public Map<String, ManagedProperty> getProperties();
+
+ /**
+ * Create a deep copy of the template info. This ensures any ManagedProperty
+ * objects returned in the copy do not share the same value references such
+ * that modification of the property value in the copy affects the original.
+ * @return a deep copy of the template info.
+ */
+ public DeploymentTemplateInfo copy();
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,99 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.api;
-
-import java.io.Serializable;
-
-/**
- * Fields.
- *
- * TODO the fields names should be annotation class names (where relevant)
- * when the annotations exist
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public interface Fields extends Serializable
-{
- /** The name field name */
- String NAME = "name";
-
- /** The mapped name field name */
- String MAPPED_NAME = "mappedName";
-
- /** The description field name */
- String DESCRIPTION = "description";
-
- /** The meta type field name */
- String META_TYPE = "metaType";
-
- /** The value */
- String VALUE = "value";
-
- /** The legal values */
- String LEGAL_VALUES = "legalValues";
-
- /** The minimum value */
- String MINIMUM_VALUE = "minValue";
-
- /** The maximum value */
- String MAXIMUM_VALUE = "maxValue";
-
- /** The mandatory */
- String MANDATORY = "mandatory";
-
- /** The PropertyInfo info for the ManagedObject attachment */
- String PROPERTY_INFO = "propertyInfo";
-
- /** The annotations associated with the property */
- String ANNOTATIONS = "annotations";
-
- /** The attachment */
- String ATTACHMENT = "attachment";
-
- /** The ViewUses */
- String VIEW_USE = "viewUse";
-
- /** The removed flag */
- String REMOVED = "removed";
-
- /** The modified flag */
- String MODIFIED = "modified";
-
- // TODO other standard fields here
-
- /**
- * Get a field with the given name
- *
- * @param name the name
- * @return the field value
- */
- Object getField(String name);
-
- /**
- * Set a field with the given name
- *
- * @param name the name
- * @param value the field value
- */
- void setField(String name, Object value);
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/Fields.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/Fields.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,105 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.api;
+
+import java.io.Serializable;
+
+/**
+ * Fields.
+ *
+ * TODO the fields names should be annotation class names (where relevant)
+ * when the annotations exist
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface Fields extends Serializable
+{
+ /** The name field name */
+ String NAME = "name";
+
+ /** The mapped name field name */
+ String MAPPED_NAME = "mappedName";
+
+ /** The description field name */
+ String DESCRIPTION = "description";
+
+ /** The meta type field name */
+ String META_TYPE = "metaType";
+
+ /** The value */
+ String VALUE = "value";
+
+ /** The legal values */
+ String LEGAL_VALUES = "legalValues";
+
+ /** The minimum value */
+ String MINIMUM_VALUE = "minValue";
+
+ /** The maximum value */
+ String MAXIMUM_VALUE = "maxValue";
+
+ /** The mandatory */
+ String MANDATORY = "mandatory";
+
+ /** The PropertyInfo info for the ManagedObject attachment */
+ String PROPERTY_INFO = "propertyInfo";
+
+ /** The annotations associated with the property */
+ String ANNOTATIONS = "annotations";
+
+ /** The attachment */
+ String ATTACHMENT = "attachment";
+
+ /** The ViewUses */
+ String VIEW_USE = "viewUse";
+
+ /** The removed flag */
+ String REMOVED = "removed";
+
+ /** The modified flag */
+ String MODIFIED = "modified";
+
+ // TODO other standard fields here
+
+ /**
+ * Get a field with the given name
+ *
+ * @param name the name
+ * @return the field value
+ */
+ Object getField(String name);
+
+ /**
+ * Set a field with the given name
+ *
+ * @param name the name
+ * @param value the field value
+ */
+ void setField(String name, Object value);
+
+ /**
+ * Create a copy of the fields.
+ * @return a copy of the fields.
+ */
+ Fields copy();
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,165 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.api;
-
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.managed.api.ManagedProperty;
-
-/**
- * A collection of ManagedComponent and structural information
- * about a deployment.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public interface ManagedDeployment
-{
- /** The phase of deployment */
- public enum DeploymentPhase {
- /** A deployment loaded during the server bootstrap phase */
- BOOTSTRAP,
- /** An mc/service deployment for a Deployer to be loaded after the BOOTSTRAP phase */
- DEPLOYER,
- /** Any deployment content to be loaded after the DEPLOYER phase */
- APPLICATION,
- /** Any unversioned deployment content to be loaded after the APPLICATION phase */
- APPLICATION_TRANSIENT
- };
-
- /**
- * Get the full name of the associated DeploymentUnit.
- * @return full name of the DeploymentUnit
- */
- public String getName();
- /**
- * Get the simple name (x.ear) for the deployment
- * @return simple name of the deployment
- */
- public String getSimpleName();
- /**
- * Get the phase this deployment is associated with
- * @return the phase
- */
- public DeploymentPhase getDeploymentPhase();
- /**
- * Add a deployment/module type
- * @param type
- * @return true if the type was added, false if it already exists
- */
- public boolean addType(String type);
- /**
- * Get the deployment/module types.
- * @return deployment types
- */
- public Set<String> getTypes();
- /**
- * Get the deployment/module types.
- * @param types
- */
- public void setTypes(Set<String> types);
-
- /**
- * Get the managed property names
- *
- * @return the property names
- */
- public Set<String> getPropertyNames();
- /**
- * Get a property
- *
- * @param name the name
- * @return the property
- */
- public ManagedProperty getProperty(String name);
-
- /**
- * Get the properties
- *
- * @return the properties
- */
- public Map<String, ManagedProperty> getProperties();
-
- /**
- * Get the managed object names
- *
- * @return the property names
- */
- public Set<String> getManagedObjectNames();
- public Map<String, ManagedObject> getManagedObjects();
- public ManagedObject getManagedObject(String name);
-
- /**
- *
- * @return the parent
- */
- public ManagedDeployment getParent();
-
- public ManagedComponent getComponent(String name);
-
- /**
- * Get the ManagedComponents for the deployment module.
- * @return ManagedComponents for the deployment module.
- */
- public Map<String, ManagedComponent> getComponents();
- /**
- * Get the nested deployment modules.
- * @return nested deployment modules.
- */
- public List<ManagedDeployment> getChildren();
-
- /**
- * Get the DeploymentTemplate names for components
- * that can be added to this deployment.
- * @return the template names
- */
- public Set<String> getComponentTemplateNames();
-
- /**
- * Add a component to this deployment
- * @param name the name
- * @param comp the component
- */
- public void addComponent(String name, ManagedComponent comp);
- /**
- *
- * @param name the name
- * @return true when it was removed
- */
- public boolean removeComponent(String name);
-
- /**
- * Get the DeploymentTemplate names for deployments
- * that can be added to this deployment.
- * @return the template names
- */
- public Set<String> getDeploymentTemplateNames();
- /**
- * Add a deployment
- * @param deplymentBaseName
- * @param info
- * @return the deployment
- */
- public ManagedDeployment addModule(String deplymentBaseName, DeploymentTemplateInfo info);
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java (from rev 84819, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedDeployment.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.api;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * A collection of ManagedComponent and structural information
+ * about a deployment.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedDeployment
+{
+ /** The phase of deployment
+ * @deprecated - no replacement, to be dropped
+ */
+ @Deprecated()
+ public enum DeploymentPhase {
+ /** A deployment loaded during the server bootstrap phase */
+ BOOTSTRAP,
+ /** An mc/service deployment for a Deployer to be loaded after the BOOTSTRAP phase */
+ DEPLOYER,
+ /** Any deployment content to be loaded after the DEPLOYER phase */
+ APPLICATION,
+ /** Any unversioned deployment content to be loaded after the APPLICATION phase */
+ APPLICATION_TRANSIENT
+ };
+
+ /**
+ * Get the full name of the associated DeploymentUnit.
+ * @return full name of the DeploymentUnit
+ */
+ public String getName();
+ /**
+ * Get the simple name (x.ear) for the deployment
+ * @return simple name of the deployment
+ */
+ public String getSimpleName();
+ /**
+ * Get the phase this deployment is associated with
+ * @return the phase
+ */
+ public DeploymentPhase getDeploymentPhase();
+ /**
+ * Add a deployment/module type
+ * @param type
+ * @return true if the type was added, false if it already exists
+ */
+ public boolean addType(String type);
+ /**
+ * Get the deployment/module types.
+ * @return deployment types
+ */
+ public Set<String> getTypes();
+ /**
+ * Get the deployment/module types.
+ * @param types
+ */
+ public void setTypes(Set<String> types);
+
+ /**
+ * Get the managed property names
+ *
+ * @return the property names
+ */
+ public Set<String> getPropertyNames();
+ /**
+ * Get a property
+ *
+ * @param name the name
+ * @return the property
+ */
+ public ManagedProperty getProperty(String name);
+
+ /**
+ * Get the properties
+ *
+ * @return the properties
+ */
+ public Map<String, ManagedProperty> getProperties();
+
+ /**
+ * Get the managed object names
+ *
+ * @return the property names
+ */
+ public Set<String> getManagedObjectNames();
+ public Map<String, ManagedObject> getManagedObjects();
+ public ManagedObject getManagedObject(String name);
+
+ /**
+ *
+ * @return the parent
+ */
+ public ManagedDeployment getParent();
+
+ public ManagedComponent getComponent(String name);
+
+ /**
+ * Get the ManagedComponents for the deployment module.
+ * @return ManagedComponents for the deployment module.
+ */
+ public Map<String, ManagedComponent> getComponents();
+ /**
+ * Get the nested deployment modules.
+ * @return nested deployment modules.
+ */
+ public List<ManagedDeployment> getChildren();
+
+ /**
+ * Get the DeploymentTemplate names for components
+ * that can be added to this deployment.
+ * @return the template names
+ */
+ public Set<String> getComponentTemplateNames();
+
+ /**
+ * Add a component to this deployment
+ * @param name the name
+ * @param comp the component
+ */
+ public void addComponent(String name, ManagedComponent comp);
+ /**
+ *
+ * @param name the name
+ * @return true when it was removed
+ */
+ public boolean removeComponent(String name);
+
+ /**
+ * Get the DeploymentTemplate names for deployments
+ * that can be added to this deployment.
+ * @return the template names
+ */
+ public Set<String> getDeploymentTemplateNames();
+ /**
+ * Add a deployment
+ * @param deplymentBaseName
+ * @param info
+ * @return the deployment
+ */
+ public ManagedDeployment addModule(String deplymentBaseName, DeploymentTemplateInfo info);
+
+ /**
+ * Get an attachment from the deployment.
+ *
+ * @see #setAttachment(String, Object)
+ *
+ * @param name the name
+ * @return the attachment
+ */
+ Object getAttachment(String name);
+
+ /**
+ * Get an attachment from the deployment,
+ * uses the expected type as both the name
+ * and to cast the resulting object.
+ *
+ * @param <T> the expected type
+ * @param expectedType the expected type
+ * @return the attachment
+ * @throws ClassCastException when the object is not of the expected type
+ */
+ <T> T getAttachment(Class<T> expectedType);
+
+ /**
+ * Set an attachment against the deployment. Attachments added to a deployment
+ * are serialized to external clients like admin tools, so the attachment
+ * type should be restricted to jdk types and commonly provided management
+ * related classes.
+ *
+ * @param name the name
+ * @param attachment the attachment, pass null to remove an attachment
+ * @throws IllegalArgumentException for a null name
+ */
+ void setAttachment(String name, Object attachment);
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,88 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.api;
-
-import java.io.Serializable;
-
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.MetaValue;
-
-/**
- * A representation of a managed operation.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public interface ManagedOperation extends Serializable
-{
- /**
- * The side-effect impact of invoking an operation
- */
- public enum Impact {
- /** There is not modification of the ManagedObject */
- ReadOnly,
- /** The impact may modify the ManagedObject */
- ReadWrite,
- /** The impact is to modify the ManagedObject */
- WriteOnly,
- /** The impact is not known */
- Unknown
- };
-
- /**
- * Get the operation description
- * @return the operation description
- */
- public String getDescription();
- /**
- * Get the name of the operation
- * @return the name of the operation
- */
- public String getName();
-
- /**
- * Get the impact of the operation
- * @return the side-effect type invoking the operation has.
- */
- public Impact getImpact();
-
- /**
- * The MetaType for the operation return value.
- * @return MetaType for the operation return value.
- */
- public MetaType getReturnType();
-
- /**
- * The parameter information for the operation arguments. An empty
- * signature array is returned if the operation takes no arguments.
- * @return parameter information for the operation arguments.
- */
- public ManagedParameter[] getParameters();
-
- /**
- * Invoke the operation given its parameter values.
- *
- * @param param the varags for the operation parameters.
- * @return the MetaValue for the result.
- */
- public MetaValue invoke(MetaValue... param);
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedOperation.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,94 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.api;
+
+import java.io.Serializable;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A representation of a managed operation.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public interface ManagedOperation extends Serializable
+{
+ /**
+ * The side-effect impact of invoking an operation
+ */
+ public enum Impact {
+ /** There is not modification of the ManagedObject */
+ ReadOnly,
+ /** The impact may modify the ManagedObject */
+ ReadWrite,
+ /** The impact is to modify the ManagedObject */
+ WriteOnly,
+ /** The impact is not known */
+ Unknown
+ };
+
+ /**
+ * Get the operation description
+ * @return the operation description
+ */
+ public String getDescription();
+ /**
+ * Get the name of the operation
+ * @return the name of the operation
+ */
+ public String getName();
+
+ /**
+ * Get the impact of the operation
+ * @return the side-effect type invoking the operation has.
+ */
+ public Impact getImpact();
+
+ /**
+ * The MetaType for the operation return value.
+ * @return MetaType for the operation return value.
+ */
+ public MetaType getReturnType();
+
+ /**
+ * The parameter information for the operation arguments. An empty
+ * signature array is returned if the operation takes no arguments.
+ * @return parameter information for the operation arguments.
+ */
+ public ManagedParameter[] getParameters();
+
+ /**
+ * Get the operation signature
+ * @return
+ */
+ public String[] getReflectionSignature();
+
+ /**
+ * Invoke the operation given its parameter values.
+ *
+ * @param param the varags for the operation parameters.
+ * @return the MetaValue for the result.
+ */
+ public MetaValue invoke(MetaValue... param);
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,239 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.api;
-
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.managed.api.annotation.ManagementObjectRef;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.MetaValue;
-
-/**
- * ManagedProperty.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision: 1.1 $
- */
-public interface ManagedProperty extends Serializable
-{
- /**
- * Get the managed object the property is associated with.
- *
- * @return the managed object
- */
- ManagedObject getManagedObject();
- void setManagedObject(ManagedObject managedObject);
-
- /**
- * Get the ManagedObject
- * @see {@linkplain ManagementObjectRef}
- * @return the ManagedObject the property references, null
- * if there is no reference or its unresolved.
- */
- ManagedObject getTargetManagedObject();
- void setTargetManagedObject(ManagedObject target);
-
- /**
- * Get the fields
- *
- * @return the fields
- */
- Fields getFields();
-
- /**
- * Get a field
- *
- * @param <T> the expected type
- * @param fieldName the field name
- * @param expected the expected type
- * @return the value
- */
- <T> T getField(String fieldName, Class<T> expected);
-
- /**
- * Set a field
- *
- * @param fieldName the field name
- * @param value the value
- */
- void setField(String fieldName, Serializable value);
-
- /**
- * Get the property's name
- *
- * @return the property's name
- */
- String getName();
-
- /**
- * Get the property's mapped name. This is an optional name
- * that allows for an external name to be mapped to an
- * internal one.
- *
- * @return the mapped name if it exists, null if there is no
- * mapped name.
- */
- String getMappedName();
-
- /**
- * Get the description
- *
- * @return the description
- */
- String getDescription();
-
- /**
- * Get the type
- *
- * @return the type
- */
- MetaType getMetaType();
-
- /**
- * Get the annotations associated with the property
- * @return the annotations associated with the property
- */
- Map<String, Annotation> getAnnotations();
-
- /**
- * Does the property have the annotation referenced by key.
- * @param key the key into {@link #getAnnotations()}
- * @return true if the annotation exists, false otherwise.
- */
- boolean hasAnnotation(String key);
-
- /**
- * See if the property has the indicated ViewUse among its
- * @ManagementProperty annotation uses.
- *
- * @param use - the ViewUse to check for
- * @return true if the ViewUse exists in the property uses, false otherwise
- */
- boolean hasViewUse(ViewUse use);
-
- /**
- * Get the value
- *
- * @return the value
- */
- MetaValue getValue();
-
- /**
- * Set the value
- *
- * @param value the value
- */
- void setValue(MetaValue value);
-
- /**
- * Get the legal values
- *
- * @return the legal values
- */
- Set<MetaValue> getLegalValues();
-
- /**
- * Get the minimum value
- *
- * @return the minimum value, a MetaValue implementing Comparable
- */
- Comparable<? extends MetaValue> getMinimumValue();
-
- /**
- * Get the maximum value
- *
- * @return the maximum value, a MetaValue implementing Comparable
- */
- Comparable<? extends MetaValue> getMaximumValue();
-
- /**
- * Check whether this is a valid value
- *
- * @param value the value
- * @return null for a valid value, an error message otherwise
- */
- String checkValidValue(MetaValue value);
-
- /**
- * Whether the property is mandatory
- *
- * @return true when mandatory
- */
- boolean isMandatory();
-
- /**
- * Whether the property has been edited/modified.
- *
- * @return true when modified
- */
- boolean isModified();
-
- /**
- * Whether the property has been marked as removed from its ManagedObject.
- * @return true is the property has been removed.
- */
- boolean isRemoved();
- /**
- * Set whether a property has been marked as removed from its ManagedObject.
- * @param flag - true is the property has been removed, false if not.
- */
- void setRemoved(boolean flag);
-
- /**
- * Get a transient attachment from the property.
- *
- * @see #setTransientAttachment(String, Object)
- *
- * @param name the name
- * @return the attachment
- */
- Object getTransientAttachment(String name);
-
- /**
- * Get an attachment from the property,
- * uses the expected type as both the name
- * and to cast the resulting object.
- *
- * @param <T> the expected type
- * @param expectedType the expected type
- * @return the attachment
- * @throws ClassCastException when the object is not of the expected type
- */
- <T> T getTransientAttachment(Class<T> expectedType);
-
- /**
- * Set an transient attachment against the property. A transient attachment
- * is one that will not be available to clients of the property, typically
- * admin tools. Such attachments are used by the server side where the
- * underlying metadata to which the property is
- *
- * @param name the name
- * @param attachment the attachment, pass null to remove an attachment
- * @throws IllegalArgumentException for a null name
- */
- void setTransientAttachment(String name, Object attachment);
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/ManagedProperty.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,247 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.api;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * ManagedProperty.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1.1 $
+ */
+public interface ManagedProperty extends Serializable
+{
+ /**
+ * Get the managed object the property is associated with.
+ *
+ * @return the managed object
+ */
+ ManagedObject getManagedObject();
+ void setManagedObject(ManagedObject managedObject);
+
+ /**
+ * Get the ManagedObject
+ * @see {@linkplain ManagementObjectRef}
+ * @return the ManagedObject the property references, null
+ * if there is no reference or its unresolved.
+ */
+ ManagedObject getTargetManagedObject();
+ void setTargetManagedObject(ManagedObject target);
+
+ /**
+ * Get the fields
+ *
+ * @return the fields
+ */
+ Fields getFields();
+
+ /**
+ * Create a copy of the managed property. This is a copy that whose fields
+ * are copies of the original property. Changes to the copies fields have
+ * not affect on the original.
+ * @return a copy of the managed property.
+ */
+ ManagedProperty copy();
+
+ /**
+ * Get a field
+ *
+ * @param <T> the expected type
+ * @param fieldName the field name
+ * @param expected the expected type
+ * @return the value
+ */
+ <T> T getField(String fieldName, Class<T> expected);
+
+ /**
+ * Set a field
+ *
+ * @param fieldName the field name
+ * @param value the value
+ */
+ void setField(String fieldName, Serializable value);
+
+ /**
+ * Get the property's name
+ *
+ * @return the property's name
+ */
+ String getName();
+
+ /**
+ * Get the property's mapped name. This is an optional name
+ * that allows for an external name to be mapped to an
+ * internal one.
+ *
+ * @return the mapped name if it exists, null if there is no
+ * mapped name.
+ */
+ String getMappedName();
+
+ /**
+ * Get the description
+ *
+ * @return the description
+ */
+ String getDescription();
+
+ /**
+ * Get the type
+ *
+ * @return the type
+ */
+ MetaType getMetaType();
+
+ /**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ Map<String, Annotation> getAnnotations();
+
+ /**
+ * Does the property have the annotation referenced by key.
+ * @param key the key into {@link #getAnnotations()}
+ * @return true if the annotation exists, false otherwise.
+ */
+ boolean hasAnnotation(String key);
+
+ /**
+ * See if the property has the indicated ViewUse among its
+ * @ManagementProperty annotation uses.
+ *
+ * @param use - the ViewUse to check for
+ * @return true if the ViewUse exists in the property uses, false otherwise
+ */
+ boolean hasViewUse(ViewUse use);
+
+ /**
+ * Get the value
+ *
+ * @return the value
+ */
+ MetaValue getValue();
+
+ /**
+ * Set the value
+ *
+ * @param value the value
+ */
+ void setValue(MetaValue value);
+
+ /**
+ * Get the legal values
+ *
+ * @return the legal values
+ */
+ Set<MetaValue> getLegalValues();
+
+ /**
+ * Get the minimum value
+ *
+ * @return the minimum value, a MetaValue implementing Comparable
+ */
+ Comparable<? extends MetaValue> getMinimumValue();
+
+ /**
+ * Get the maximum value
+ *
+ * @return the maximum value, a MetaValue implementing Comparable
+ */
+ Comparable<? extends MetaValue> getMaximumValue();
+
+ /**
+ * Check whether this is a valid value
+ *
+ * @param value the value
+ * @return null for a valid value, an error message otherwise
+ */
+ String checkValidValue(MetaValue value);
+
+ /**
+ * Whether the property is mandatory
+ *
+ * @return true when mandatory
+ */
+ boolean isMandatory();
+
+ /**
+ * Whether the property has been edited/modified.
+ *
+ * @return true when modified
+ */
+ boolean isModified();
+
+ /**
+ * Whether the property has been marked as removed from its ManagedObject.
+ * @return true is the property has been removed.
+ */
+ boolean isRemoved();
+ /**
+ * Set whether a property has been marked as removed from its ManagedObject.
+ * @param flag - true is the property has been removed, false if not.
+ */
+ void setRemoved(boolean flag);
+
+ /**
+ * Get a transient attachment from the property.
+ *
+ * @see #setTransientAttachment(String, Object)
+ *
+ * @param name the name
+ * @return the attachment
+ */
+ Object getTransientAttachment(String name);
+
+ /**
+ * Get an attachment from the property,
+ * uses the expected type as both the name
+ * and to cast the resulting object.
+ *
+ * @param <T> the expected type
+ * @param expectedType the expected type
+ * @return the attachment
+ * @throws ClassCastException when the object is not of the expected type
+ */
+ <T> T getTransientAttachment(Class<T> expectedType);
+
+ /**
+ * Set an transient attachment against the property. A transient attachment
+ * is one that will not be available to clients of the property, typically
+ * admin tools. Such attachments are used by the server side where the
+ * underlying metadata to which the property is
+ *
+ * @param name the name
+ * @param attachment the attachment, pass null to remove an attachment
+ * @throws IllegalArgumentException for a null name
+ */
+ void setTransientAttachment(String name, Object attachment);
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,92 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.api.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * ManagementObject annotation for describing ManagedObjects.
- * {@linkplain ManagedObject}
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at Inherited
- at Target({ElementType.TYPE})
- at Retention(RetentionPolicy.RUNTIME)
-public @interface ManagementObject
-{
- /** The name used for ManagementObjectRef resolution. Generally
- * this is taken from a property annotated with
- * {@linkplain ManagementObjectID}.
- */
- String name() default ManagementConstants.GENERATED;
- /**
- * A description for the managed object.
- */
- String description() default ManagementConstants.GENERATED;
- /** The name type used for ManagementObjectRef resolution. Generally
- * this is taken from a property annotated with
- * {@linkplain ManagementObjectID}.
- */
- String type() default AnnotationDefaults.EMPTY_STRING;
- /** The metadata attachment name for the ManagedObject */
- String attachmentName() default AnnotationDefaults.EMPTY_STRING;
- /** Is this a runtime extension of another ManagedObject. This
- * is used to tie together
- */
- boolean isRuntime() default false;
-
- /** The component type for MCs that are ManagedComponents */
- ManagementComponent componentType() default @ManagementComponent(type="", subtype="");
-
- /** What properties to include */
- ManagementProperties properties() default ManagementProperties.ALL;
-
- /**
- * A class level specification of the management properties. Depending on the
- * properties() value, this can either override or augment the ManagementProperty
- * annotations found on the bean fields/methods.
- * @return
- */
- ManagementProperty[] classProperties() default {};
-
- /** The exposed operations. If empty the operations will be obtained from
- * the annotated bean in a bean type specific way.
- */
- ManagementOperation[] operations() default {};
-
-/*
- // The class to use for the ManagedProperty implementation
- Class<? extends ManagedProperty> propertyFactory() default NULL_PROPERTY_FACTORY.class;
- // The class to use for the ManagedProperty Fields implementation
- Class<? extends Fields> fieldsFactory() default NULL_FIELDS_FACTORY.class;
- // The constraints, allowed values populator factory
- Class<? extends ManagedPropertyConstraintsPopulatorFactory> constraintsFactory()
- default NULL_CONSTRAINTS.class;
-*/
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObject.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,88 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * ManagementObject annotation for describing ManagedObjects.
+ * {@linkplain ManagedObject}
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Inherited
+ at Target({ElementType.TYPE})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementObject
+{
+ /** The name used for ManagementObjectRef resolution. Generally
+ * this is taken from a property annotated with
+ * {@linkplain ManagementObjectID}.
+ */
+ String name() default ManagementConstants.GENERATED;
+ /**
+ * A description for the managed object.
+ */
+ String description() default ManagementConstants.GENERATED;
+ /** The name type used for ManagementObjectRef resolution. Generally
+ * this is taken from a property annotated with
+ * {@linkplain ManagementObjectID}.
+ */
+ String type() default AnnotationDefaults.EMPTY_STRING;
+ /** The metadata attachment name for the ManagedObject */
+ String attachmentName() default AnnotationDefaults.EMPTY_STRING;
+ /** Is this a runtime extension of another ManagedObject. This
+ * is used to tie together runtime components with metadata
+ */
+ boolean isRuntime() default false;
+
+ /** The component type for MCs that are ManagedComponents */
+ ManagementComponent componentType() default @ManagementComponent(type="", subtype="");
+
+ /** What properties to include */
+ ManagementProperties properties() default ManagementProperties.ALL;
+
+ /**
+ * A class level specification of the management properties. Depending on the
+ * properties() value, this can either override or augment the ManagementProperty
+ * annotations found on the bean fields/methods.
+ * @return
+ */
+ ManagementProperty[] classProperties() default {};
+
+ /** The exposed operations. If empty the operations will be obtained from
+ * the annotated bean in a bean type specific way.
+ */
+ ManagementOperation[] operations() default {};
+
+ /**
+ * An interface to use for reflection when determining properties/operations
+ * of the managed object.
+ */
+ Class<?> targetInterface() default Object.class;
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,48 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.api.annotation;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * An annotation that identifies a ManagedObject key/type
- * qualifier source.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at Target({ElementType.TYPE, ElementType.METHOD})
- at Retention(RetentionPolicy.RUNTIME)
-public @interface ManagementObjectID
-{
- /** An explicit ManagedObject name. If empty, the name is
- * taken from the annotated property.
- */
- String name() default AnnotationDefaults.EMPTY_STRING;
- /** A qualifier for the name that provides a context to
- * identify the type or scope of the ManagedObject name.
- */
- String type() default AnnotationDefaults.EMPTY_STRING;
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java (from rev 84389, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/api/annotation/ManagementObjectID.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,58 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.api.annotation;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * An annotation that identifies a ManagedObject key/type
+ * qualifier source.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface ManagementObjectID
+{
+ /** An explicit ManagedObject name. If empty, the name is
+ * taken from the annotated property.
+ */
+ String name() default AnnotationDefaults.EMPTY_STRING;
+ /** A qualifier for the name that provides a context to
+ * identify the type or scope of the ManagedObject name.
+ */
+ String type() default AnnotationDefaults.EMPTY_STRING;
+ /**
+ * A fixed prefix to prepend to the annotated property value when
+ * name() is empty.
+ */
+ String prefix() default AnnotationDefaults.EMPTY_STRING;
+ /**
+ * A fixed suffix to append to the annotated property value when
+ * name() is empty.
+ */
+ String suffix() default AnnotationDefaults.EMPTY_STRING;
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,116 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins;
-
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.jboss.managed.api.DeploymentTemplateInfo;
-import org.jboss.managed.api.ManagedProperty;
-
-/**
- * A simple bean type of implementation of DeploymentTemplateInfo
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class BasicDeploymentTemplateInfo
- implements DeploymentTemplateInfo, Serializable
-{
- private static final long serialVersionUID = 1;
- /** The name the template is registered under with the profile service */
- private String name;
- /** The template description */
- private String description;
- /** The name of the ManagedProperty in the Map<String, ManagedObject> map
- * obtained from the mainDeployer.getManagedObjects(VFSDeployment)
- * for the DeploymentTemplate this info is associated with.
- */
- private String rootManagedPropertyName;
- /**
- * The template properties
- */
- private Map<String, ManagedProperty> properties;
-
- public BasicDeploymentTemplateInfo(String name, String description)
- {
- this(name, description, new HashMap<String, ManagedProperty>());
- }
- public BasicDeploymentTemplateInfo(String name, String description,
- Map<String, ManagedProperty> properties)
- {
- this.name = name;
- this.description = description;
- this.properties = properties;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getRootManagedPropertyName()
- {
- return rootManagedPropertyName;
- }
- public void setRootManagedPropertyName(String rootManagedPropertyName)
- {
- this.rootManagedPropertyName = rootManagedPropertyName;
- }
-
- public Map<String, ManagedProperty> getProperties()
- {
- return properties;
- }
- public void setProperties(Map<String, ManagedProperty> properties)
- {
- this.properties = properties;
- }
- public void addProperty(ManagedProperty property)
- {
- this.properties.put(property.getName(), property);
- }
-
-
- public DeploymentTemplateInfo copy()
- {
- return null;
- }
-
- public String toString()
- {
- StringBuilder tmp = new StringBuilder(super.toString());
- tmp.append('{');
- tmp.append(name);
- tmp.append(",description=");
- tmp.append(description);
- tmp.append(",properties=");
- tmp.append(properties);
- tmp.append('}');
- return tmp.toString();
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java (from rev 85281, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/BasicDeploymentTemplateInfo.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,129 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * A simple bean type of implementation of DeploymentTemplateInfo
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class BasicDeploymentTemplateInfo
+ implements DeploymentTemplateInfo, Serializable
+{
+ private static final long serialVersionUID = 1;
+ /** The name the template is registered under with the profile service */
+ private String name;
+ /** The template description */
+ private String description;
+ /** The name of the ManagedProperty in the Map<String, ManagedObject> map
+ * obtained from the mainDeployer.getManagedObjects(VFSDeployment)
+ * for the DeploymentTemplate this info is associated with.
+ */
+ private String rootManagedPropertyName;
+ /**
+ * The template properties
+ */
+ private Map<String, ManagedProperty> properties;
+
+ public BasicDeploymentTemplateInfo(String name, String description)
+ {
+ this(name, description, new HashMap<String, ManagedProperty>());
+ }
+ public BasicDeploymentTemplateInfo(String name, String description,
+ Map<String, ManagedProperty> properties)
+ {
+ this.name = name;
+ this.description = description;
+ this.properties = properties;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getRootManagedPropertyName()
+ {
+ return rootManagedPropertyName;
+ }
+ public void setRootManagedPropertyName(String rootManagedPropertyName)
+ {
+ this.rootManagedPropertyName = rootManagedPropertyName;
+ }
+
+ public Map<String, ManagedProperty> getProperties()
+ {
+ return properties;
+ }
+ public void setProperties(Map<String, ManagedProperty> properties)
+ {
+ this.properties = properties;
+ }
+ public void addProperty(ManagedProperty property)
+ {
+ this.properties.put(property.getName(), property);
+ }
+
+ public DeploymentTemplateInfo copy()
+ {
+ BasicDeploymentTemplateInfo copy = new BasicDeploymentTemplateInfo(name, description);
+ this.copy(copy);
+ return copy;
+ }
+
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder(super.toString());
+ tmp.append('{');
+ tmp.append(name);
+ tmp.append(",description=");
+ tmp.append(description);
+ tmp.append(",properties=");
+ tmp.append(properties);
+ tmp.append('}');
+ return tmp.toString();
+ }
+
+ protected void copy(BasicDeploymentTemplateInfo copy)
+ {
+ copy.setRootManagedPropertyName(rootManagedPropertyName);
+ Map<String, ManagedProperty> copyProps = new HashMap<String, ManagedProperty>();
+ for(ManagedProperty prop : properties.values())
+ {
+ ManagedProperty copyProp = prop.copy();
+ copyProps.put(copyProp.getName(), copyProp);
+ }
+ copy.setProperties(copyProps);
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,375 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * A default implementation of the Fields interface.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class DefaultFieldsImpl
- implements Fields
-{
- private static String END_MARKER = "__END_OF_FIELDS__";
-
- /** The serialVersionUID */
- private static final long serialVersionUID = 1;
-
- /** The fields */
- private HashMap<String, Object> fields = new HashMap<String, Object>();
-
- /**
- * Create a new DefaultFieldsImpl.
- */
- public DefaultFieldsImpl()
- {
- }
-
- /**
- * Create a new DefaultFieldsImpl.
- *
- * @param name the property name
- */
- public DefaultFieldsImpl(String name)
- {
- this.setName(name);
- }
-
- /**
- * Get the property name
- *
- * @return the name
- */
- public String getName()
- {
- return getField(NAME, String.class);
- }
-
- /**
- * Set the property name
- *
- * @param name the name
- */
- public void setName(String name)
- {
- setField(NAME, name);
- }
-
- /**
- * Get the description
- *
- * @return the description
- */
- public String getDescription()
- {
- return getField(DESCRIPTION, String.class);
- }
-
- /**
- * Set the description
- *
- * @param description the description
- */
- public void setDescription(String description)
- {
- setField(DESCRIPTION, description);
- }
-
- /**
- * Get the meta type
- *
- * @return the meta type
- */
- public MetaType getMetaType()
- {
- return getField(META_TYPE, MetaType.class);
- }
-
- /**
- * Set the meta type
- *
- * @param type the meta type
- */
- public void setMetaType(MetaType type)
- {
- setField(META_TYPE, type);
- }
-
- /**
- * Get the value
- *
- * @return the value
- */
- public MetaValue getValue()
- {
- return getField(VALUE, MetaValue.class);
- }
-
- /**
- * Set the value
- *
- * @param value the value
- */
- public void setValue(MetaValue value)
- {
- setField(VALUE, value);
- }
-
- /**
- * Get the view use
- * @return the view use field
- */
- public ViewUse[] getViewUse()
- {
- return getField(VIEW_USE, ViewUse[].class);
- }
- /**
- * Set the view use
- * @param use - the view use
- */
- public void setViewUse(ViewUse[] use)
- {
- setField(VIEW_USE, use);
- }
-
- /**
- * Get the legal values
- *
- * @return the values
- */
- @SuppressWarnings("unchecked")
- public Set<MetaValue> getLegalValues()
- {
- return getField(LEGAL_VALUES, Set.class);
- }
-
- /**
- * Set the legal values
- *
- * @param values the values
- */
- public void setLegalValues(Set<MetaValue> values)
- {
- setField(LEGAL_VALUES, (Serializable)values);
- }
-
- /**
- * Get the minimum value
- *
- * @return the minimum value
- */
- public Comparable<?> getMinimumValue()
- {
- return getField(MINIMUM_VALUE, Comparable.class);
- }
-
- /**
- * Set the minimum value
- *
- * @param value the value
- */
- public void setMinimumValue(Comparable<?> value)
- {
- setField(MINIMUM_VALUE, (Serializable)value);
- }
-
- /**
- * Get the maximum value
- *
- * @return the value
- */
- public Comparable<?> getMaximumValue()
- {
- return getField(MAXIMUM_VALUE, Comparable.class);
- }
-
- /**
- * Get the maximum value
- *
- * @param value the value
- */
- public void setMaximumValue(Comparable<?> value)
- {
- setField(MAXIMUM_VALUE, (Serializable)value);
- }
-
- /**
- * Get whether the property is mandatory
- *
- * @return true when mandaotry
- */
- public boolean isMandatory()
- {
- Boolean result = getField(MANDATORY, Boolean.class);
- if (result == null)
- return false;
- return result;
- }
-
- /**
- * Set the mandatory value
- *
- * @param flag true when mandatory
- */
- public void setMandatory(boolean flag)
- {
- if (flag)
- setField(MANDATORY, flag);
- else
- setField(MANDATORY, null);
- }
-
- /**
- * Get a field
- *
- * @param name the field name
- */
- public Object getField(String name)
- {
- return fields.get(name);
- }
-
- /**
- * Set a field
- *
- * @param name the field name
- * @param value the value
- */
- public void setField(String name, Object value)
- {
- fields.put(name, value);
- }
-
- /**
- * Get a field
- *
- * @param <T> the expected type
- * @param fieldName the field name
- * @param expected the expected type
- * @return the field value
- */
- @SuppressWarnings("unchecked")
- public <T> T getField(String fieldName, Class<T> expected)
- {
- if (fieldName == null)
- throw new IllegalArgumentException("Null field name");
- if (expected == null)
- throw new IllegalArgumentException("Null expected type");
-
- Object field = getField(fieldName);
-
- if (field == null)
- return null;
-
- if (expected.isInstance(field))
- return expected.cast(field);
-
- if (field instanceof SimpleValue)
- {
- SimpleValue value = (SimpleValue) field;
- Object result = value.getValue();
- if (result == null)
- return null;
- return expected.cast(result);
- }
-
- throw new IllegalStateException("Field " + fieldName + " with value " + field + " is a of the expected type: " + expected.getName());
- }
-
- /**
- * Display key fields like name, metaType and value
- */
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder(super.toString());
- //
- sb.append('(');
- sb.append(NAME);
- sb.append('=');
- sb.append(getName());
- sb.append(',');
- sb.append(META_TYPE);
- sb.append('=');
- sb.append(getMetaType());
- sb.append(',');
- sb.append(VALUE);
- sb.append('=');
- sb.append(getValue());
- sb.append(')');
- return sb.toString();
- }
-
- /**
- * Only write out the fields that should be usable by a remote client.
- * Excludes:
- * PROPERTY_INFO
- * ATTACHMENT
- *
- * @param out
- * @throws IOException
- */
- private void writeObject(java.io.ObjectOutputStream out)
- throws IOException
- {
- for (Map.Entry<String, Object> entry : fields.entrySet())
- {
- if(entry.getKey().equals(PROPERTY_INFO))
- continue;
- if(entry.getKey().equals(ATTACHMENT))
- continue;
- out.writeUTF(entry.getKey());
- out.writeObject(entry.getValue());
- }
- out.writeUTF(END_MARKER);
- }
- private void readObject(java.io.ObjectInputStream in)
- throws IOException, ClassNotFoundException
- {
- fields = new HashMap<String, Object>();
- String key;
- do
- {
- key = in.readUTF();
- if(key.equals(END_MARKER))
- key = null;
- else
- {
- Serializable value = (Serializable) in.readObject();
- fields.put(key, value);
- }
- } while(key != null);
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/DefaultFieldsImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,383 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * A default implementation of the Fields interface.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DefaultFieldsImpl
+ implements Fields
+{
+ private static String END_MARKER = "__END_OF_FIELDS__";
+
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1;
+
+ /** The fields */
+ private HashMap<String, Object> fields = new HashMap<String, Object>();
+
+ /**
+ * Create a new DefaultFieldsImpl.
+ */
+ public DefaultFieldsImpl()
+ {
+ }
+
+ /**
+ * Create a new DefaultFieldsImpl.
+ *
+ * @param name the property name
+ */
+ public DefaultFieldsImpl(String name)
+ {
+ this.setName(name);
+ }
+
+ /**
+ * Get the property name
+ *
+ * @return the name
+ */
+ public String getName()
+ {
+ return getField(NAME, String.class);
+ }
+
+ /**
+ * Set the property name
+ *
+ * @param name the name
+ */
+ public void setName(String name)
+ {
+ setField(NAME, name);
+ }
+
+ /**
+ * Get the description
+ *
+ * @return the description
+ */
+ public String getDescription()
+ {
+ return getField(DESCRIPTION, String.class);
+ }
+
+ /**
+ * Set the description
+ *
+ * @param description the description
+ */
+ public void setDescription(String description)
+ {
+ setField(DESCRIPTION, description);
+ }
+
+ /**
+ * Get the meta type
+ *
+ * @return the meta type
+ */
+ public MetaType getMetaType()
+ {
+ return getField(META_TYPE, MetaType.class);
+ }
+
+ /**
+ * Set the meta type
+ *
+ * @param type the meta type
+ */
+ public void setMetaType(MetaType type)
+ {
+ setField(META_TYPE, type);
+ }
+
+ /**
+ * Get the value
+ *
+ * @return the value
+ */
+ public MetaValue getValue()
+ {
+ return getField(VALUE, MetaValue.class);
+ }
+
+ /**
+ * Set the value
+ *
+ * @param value the value
+ */
+ public void setValue(MetaValue value)
+ {
+ setField(VALUE, value);
+ }
+
+ /**
+ * Get the view use
+ * @return the view use field
+ */
+ public ViewUse[] getViewUse()
+ {
+ return getField(VIEW_USE, ViewUse[].class);
+ }
+ /**
+ * Set the view use
+ * @param use - the view use
+ */
+ public void setViewUse(ViewUse[] use)
+ {
+ setField(VIEW_USE, use);
+ }
+
+ /**
+ * Get the legal values
+ *
+ * @return the values
+ */
+ @SuppressWarnings("unchecked")
+ public Set<MetaValue> getLegalValues()
+ {
+ return getField(LEGAL_VALUES, Set.class);
+ }
+
+ /**
+ * Set the legal values
+ *
+ * @param values the values
+ */
+ public void setLegalValues(Set<MetaValue> values)
+ {
+ setField(LEGAL_VALUES, (Serializable)values);
+ }
+
+ /**
+ * Get the minimum value
+ *
+ * @return the minimum value
+ */
+ public Comparable<?> getMinimumValue()
+ {
+ return getField(MINIMUM_VALUE, Comparable.class);
+ }
+
+ /**
+ * Set the minimum value
+ *
+ * @param value the value
+ */
+ public void setMinimumValue(Comparable<?> value)
+ {
+ setField(MINIMUM_VALUE, (Serializable)value);
+ }
+
+ /**
+ * Get the maximum value
+ *
+ * @return the value
+ */
+ public Comparable<?> getMaximumValue()
+ {
+ return getField(MAXIMUM_VALUE, Comparable.class);
+ }
+
+ /**
+ * Get the maximum value
+ *
+ * @param value the value
+ */
+ public void setMaximumValue(Comparable<?> value)
+ {
+ setField(MAXIMUM_VALUE, (Serializable)value);
+ }
+
+ /**
+ * Get whether the property is mandatory
+ *
+ * @return true when mandaotry
+ */
+ public boolean isMandatory()
+ {
+ Boolean result = getField(MANDATORY, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+
+ /**
+ * Set the mandatory value
+ *
+ * @param flag true when mandatory
+ */
+ public void setMandatory(boolean flag)
+ {
+ if (flag)
+ setField(MANDATORY, flag);
+ else
+ setField(MANDATORY, null);
+ }
+
+ /**
+ * Get a field
+ *
+ * @param name the field name
+ */
+ public Object getField(String name)
+ {
+ return fields.get(name);
+ }
+
+ /**
+ * Set a field
+ *
+ * @param name the field name
+ * @param value the value
+ */
+ public void setField(String name, Object value)
+ {
+ fields.put(name, value);
+ }
+
+ /**
+ * Get a field
+ *
+ * @param <T> the expected type
+ * @param fieldName the field name
+ * @param expected the expected type
+ * @return the field value
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getField(String fieldName, Class<T> expected)
+ {
+ if (fieldName == null)
+ throw new IllegalArgumentException("Null field name");
+ if (expected == null)
+ throw new IllegalArgumentException("Null expected type");
+
+ Object field = getField(fieldName);
+
+ if (field == null)
+ return null;
+
+ if (expected.isInstance(field))
+ return expected.cast(field);
+
+ if (field instanceof SimpleValue)
+ {
+ SimpleValue value = (SimpleValue) field;
+ Object result = value.getValue();
+ if (result == null)
+ return null;
+ return expected.cast(result);
+ }
+
+ throw new IllegalStateException("Field " + fieldName + " with value " + field + " is a of the expected type: " + expected.getName());
+ }
+
+ @SuppressWarnings("unchecked")
+ public Fields copy()
+ {
+ DefaultFieldsImpl copy = new DefaultFieldsImpl();
+ copy.fields = (HashMap<String, Object>) fields.clone();
+ return copy;
+ }
+
+ /**
+ * Display key fields like name, metaType and value
+ */
+ @Override
+ public String toString()
+ {
+ StringBuilder sb = new StringBuilder(super.toString());
+ //
+ sb.append('(');
+ sb.append(NAME);
+ sb.append('=');
+ sb.append(getName());
+ sb.append(',');
+ sb.append(META_TYPE);
+ sb.append('=');
+ sb.append(getMetaType());
+ sb.append(',');
+ sb.append(VALUE);
+ sb.append('=');
+ sb.append(getValue());
+ sb.append(')');
+ return sb.toString();
+ }
+
+ /**
+ * Only write out the fields that should be usable by a remote client.
+ * Excludes:
+ * PROPERTY_INFO
+ * ATTACHMENT
+ *
+ * @param out
+ * @throws IOException
+ */
+ private void writeObject(java.io.ObjectOutputStream out)
+ throws IOException
+ {
+ for (Map.Entry<String, Object> entry : fields.entrySet())
+ {
+ if(entry.getKey().equals(PROPERTY_INFO))
+ continue;
+ if(entry.getKey().equals(ATTACHMENT))
+ continue;
+ out.writeUTF(entry.getKey());
+ out.writeObject(entry.getValue());
+ }
+ out.writeUTF(END_MARKER);
+ }
+ private void readObject(java.io.ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ fields = new HashMap<String, Object>();
+ String key;
+ do
+ {
+ key = in.readUTF();
+ if(key.equals(END_MARKER))
+ key = null;
+ else
+ {
+ Serializable value = (Serializable) in.readObject();
+ fields.put(key, value);
+ }
+ } while(key != null);
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,211 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.managed.api.DeploymentTemplateInfo;
-import org.jboss.managed.api.ManagedComponent;
-import org.jboss.managed.api.ManagedDeployment;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-
-/**
- * A simple ManagedDeployment bean implementation
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class ManagedDeploymentImpl implements ManagedDeployment, Serializable
-{
- private static final long serialVersionUID = 1;
- /** The full deployment name */
- private String name;
- /** The simple deployment name */
- private String simpleName;
- /** The set of types assigned to the deployment */
- private Set<String> types;
- /** The profile service phase for the deployment */
- private DeploymentPhase phase;
- /** The parent deployment if any */
- private ManagedDeployment parent;
- /** The deployment ManagedObjects */
- private Map<String, ManagedObject> unitMOs;
- /** The flattened map of all ManagedObject properties */
- private Map<String, ManagedProperty> properties;
- /** The ManagedComponent wrappers for ManagedObjects marked as components */
- private Map<String, ManagedComponent> components = new HashMap<String, ManagedComponent>();
- /** The child deployemnts */
- private List<ManagedDeployment> children = new ArrayList<ManagedDeployment>();
-
- public ManagedDeploymentImpl(String name, String simpleName, DeploymentPhase phase,
- ManagedDeployment parent, Map<String, ManagedObject> unitMOs)
- {
- this.name = name;
- this.simpleName = simpleName;
- this.phase = phase;
- this.parent = parent;
- this.unitMOs = unitMOs;
- properties = new HashMap<String, ManagedProperty>();
- for(ManagedObject mo : unitMOs.values())
- {
- properties.putAll(mo.getProperties());
- }
- if(parent != null)
- {
- parent.getChildren().add(this);
- }
- }
-
- public String getName()
- {
- return name;
- }
- public String getSimpleName()
- {
- return simpleName;
- }
-
- public boolean addType(String type)
- {
- return types.add(type);
- }
- public Set<String> getTypes()
- {
- return types;
- }
- public void setTypes(Set<String> types)
- {
- this.types = types;
- }
-
- public DeploymentPhase getDeploymentPhase()
- {
- return phase;
- }
- public ManagedDeployment getParent()
- {
- return parent;
- }
-
- public Set<String> getComponentTemplateNames()
- {
- // TODO Auto-generated method stub
- return null;
- }
- public void addComponent(String name, ManagedComponent comp)
- {
- components.put(name, comp);
- }
- public ManagedComponent getComponent(String name)
- {
- return components.get(name);
- }
-
- public Map<String, ManagedComponent> getComponents()
- {
- return components;
- }
-
- public boolean removeComponent(String name)
- {
- ManagedComponent mc = components.remove(name);
- return mc != null;
- }
-
- public Set<String> getDeploymentTemplateNames()
- {
- // TODO Auto-generated method stub
- return null;
- }
- public List<ManagedDeployment> getChildren()
- {
- return children;
- }
-
- public ManagedDeployment addModule(String deplymentBaseName, DeploymentTemplateInfo info)
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- public Map<String, ManagedProperty> getProperties()
- {
- return properties;
- }
-
- public ManagedProperty getProperty(String name)
- {
- return properties.get(name);
- }
-
- public Set<String> getPropertyNames()
- {
- return properties.keySet();
- }
-
- public Set<String> getManagedObjectNames()
- {
- return unitMOs.keySet();
- }
- public Map<String, ManagedObject> getManagedObjects()
- {
- return unitMOs;
- }
- public ManagedObject getManagedObject(String name)
- {
- return unitMOs.get(name);
- }
-
- public String toString()
- {
- StringBuilder tmp = new StringBuilder(super.toString());
- tmp.append('{');
- tmp.append("name=");
- tmp.append(getName());
- tmp.append(", types=");
- tmp.append(types);
- tmp.append(", phase=");
- tmp.append(phase);
- tmp.append(", parent=");
- if( parent != null )
- {
- tmp.append("ManagedDeployment@");
- tmp.append(System.identityHashCode(parent));
- }
- else
- {
- tmp.append("null");
- }
- tmp.append(", components=");
- tmp.append(components);
- tmp.append(", children=");
- tmp.append(children);
- tmp.append('}');
- return tmp.toString();
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java (from rev 84819, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedDeploymentImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,237 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedDeployment;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+
+/**
+ * A simple ManagedDeployment bean implementation
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ManagedDeploymentImpl implements ManagedDeployment, Serializable
+{
+ private static final long serialVersionUID = 1;
+ /** The full deployment name */
+ private String name;
+ /** The simple deployment name */
+ private String simpleName;
+ /** The set of types assigned to the deployment */
+ private Set<String> types;
+ /** The profile service phase for the deployment */
+ private DeploymentPhase phase;
+ /** The parent deployment if any */
+ private ManagedDeployment parent;
+ /** The deployment ManagedObjects */
+ private Map<String, ManagedObject> unitMOs;
+ /** The flattened map of all ManagedObject properties */
+ private Map<String, ManagedProperty> properties;
+ /** The ManagedComponent wrappers for ManagedObjects marked as components */
+ private Map<String, ManagedComponent> components = new HashMap<String, ManagedComponent>();
+ /** The child deployemnts */
+ private List<ManagedDeployment> children = new ArrayList<ManagedDeployment>();
+ /** The attachments map */
+ private transient Map<String, Object> attachments;
+
+ public ManagedDeploymentImpl(String name, String simpleName, DeploymentPhase phase,
+ ManagedDeployment parent, Map<String, ManagedObject> unitMOs)
+ {
+ this.name = name;
+ this.simpleName = simpleName;
+ this.phase = phase;
+ this.parent = parent;
+ this.unitMOs = unitMOs;
+ properties = new HashMap<String, ManagedProperty>();
+ for(ManagedObject mo : unitMOs.values())
+ {
+ properties.putAll(mo.getProperties());
+ }
+ if(parent != null)
+ {
+ parent.getChildren().add(this);
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+ public String getSimpleName()
+ {
+ return simpleName;
+ }
+
+ public boolean addType(String type)
+ {
+ return types.add(type);
+ }
+ public Set<String> getTypes()
+ {
+ return types;
+ }
+ public void setTypes(Set<String> types)
+ {
+ this.types = types;
+ }
+
+ public DeploymentPhase getDeploymentPhase()
+ {
+ return phase;
+ }
+ public ManagedDeployment getParent()
+ {
+ return parent;
+ }
+
+ public Set<String> getComponentTemplateNames()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public void addComponent(String name, ManagedComponent comp)
+ {
+ components.put(name, comp);
+ }
+ public ManagedComponent getComponent(String name)
+ {
+ return components.get(name);
+ }
+
+ public Map<String, ManagedComponent> getComponents()
+ {
+ return components;
+ }
+
+ public boolean removeComponent(String name)
+ {
+ ManagedComponent mc = components.remove(name);
+ return mc != null;
+ }
+
+ public Set<String> getDeploymentTemplateNames()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public List<ManagedDeployment> getChildren()
+ {
+ return children;
+ }
+
+ public ManagedDeployment addModule(String deplymentBaseName, DeploymentTemplateInfo info)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<String, ManagedProperty> getProperties()
+ {
+ return properties;
+ }
+
+ public ManagedProperty getProperty(String name)
+ {
+ return properties.get(name);
+ }
+
+ public Set<String> getPropertyNames()
+ {
+ return properties.keySet();
+ }
+
+ public Set<String> getManagedObjectNames()
+ {
+ return unitMOs.keySet();
+ }
+ public Map<String, ManagedObject> getManagedObjects()
+ {
+ return unitMOs;
+ }
+ public ManagedObject getManagedObject(String name)
+ {
+ return unitMOs.get(name);
+ }
+
+ public <T> T getAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getAttachment(String name)
+ {
+ Object value = null;
+ if(attachments != null)
+ value = attachments.get(name);
+ return value;
+ }
+
+ public synchronized void setAttachment(String name, Object attachment)
+ {
+ if(attachments == null)
+ attachments = new HashMap<String, Object>();
+ attachments.put(name, attachment);
+ }
+
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder(super.toString());
+ tmp.append('{');
+ tmp.append("name=");
+ tmp.append(getName());
+ tmp.append(", types=");
+ tmp.append(types);
+ tmp.append(", phase=");
+ tmp.append(phase);
+ tmp.append(", parent=");
+ if( parent != null )
+ {
+ tmp.append("ManagedDeployment@");
+ tmp.append(System.identityHashCode(parent));
+ }
+ else
+ {
+ tmp.append("null");
+ }
+ tmp.append(", components=");
+ tmp.append(components);
+ tmp.append(", children=");
+ tmp.append(children);
+ tmp.append('}');
+ return tmp.toString();
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,135 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins;
-
-import org.jboss.managed.api.ManagedOperation;
-import org.jboss.managed.api.ManagedParameter;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.values.MetaValue;
-
-/**
- * A default implementation of ManagedOperation
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class ManagedOperationImpl implements ManagedOperation
-{
- private static final long serialVersionUID = 1;
- private String description;
- private Impact impact;
- private String name;
- private ManagedParameter[] parameters;
- private MetaType returnType;
-
-
- public ManagedOperationImpl(String name, String description)
- {
- this(description, name, Impact.Unknown, new ManagedParameter[0], SimpleMetaType.VOID);
- }
- public ManagedOperationImpl(String name, String description, Impact impact,
- ManagedParameter[] parameters, MetaType returnType)
- {
- super();
- this.description = description;
- this.impact = impact;
- this.name = name;
- this.parameters = parameters;
- this.returnType = returnType;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public void setDescription(String description)
- {
- this.description = description;
- }
-
- public Impact getImpact()
- {
- return impact;
- }
-
- public void setImpact(Impact impact)
- {
- this.impact = impact;
- }
-
- public String getName()
- {
- return name;
- }
-
- public void setName(String name)
- {
- this.name = name;
- }
-
- public ManagedParameter[] getParameters()
- {
- return parameters;
- }
-
- public void setParameters(ManagedParameter[] parameters)
- {
- this.parameters = parameters;
- }
-
- public MetaType getReturnType()
- {
- return returnType;
- }
-
- public void setReturnType(MetaType returnType)
- {
- this.returnType = returnType;
- }
-
- /**
- * This does not have a meaningful implementation because the target
- * is unknown. A runtime aspect that understand the context of this
- * operation needs to perform the invocation.
- */
- public MetaValue invoke(MetaValue... param)
- {
- return null;
- }
-
- public String toString()
- {
- StringBuilder tmp = new StringBuilder();
- tmp.append("ManagedOperation(name=");
- tmp.append(name);
- tmp.append(",description=");
- tmp.append(description);
- tmp.append(",impact=");
- tmp.append(impact);
- tmp.append(")");
-
- return tmp.toString();
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,148 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins;
+
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * A default implementation of ManagedOperation
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ManagedOperationImpl implements ManagedOperation
+{
+ private static final long serialVersionUID = 1;
+ private String description;
+ private Impact impact;
+ private String name;
+ private ManagedParameter[] parameters;
+ private MetaType returnType;
+
+
+ public ManagedOperationImpl(String name, String description)
+ {
+ this(description, name, Impact.Unknown, new ManagedParameter[0], SimpleMetaType.VOID);
+ }
+ public ManagedOperationImpl(String name, String description, Impact impact,
+ ManagedParameter[] parameters, MetaType returnType)
+ {
+ super();
+ this.description = description;
+ this.impact = impact;
+ this.name = name;
+ this.setParameters(parameters);
+ this.returnType = returnType;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public void setDescription(String description)
+ {
+ this.description = description;
+ }
+
+ public Impact getImpact()
+ {
+ return impact;
+ }
+
+ public void setImpact(Impact impact)
+ {
+ this.impact = impact;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public ManagedParameter[] getParameters()
+ {
+ return parameters;
+ }
+
+ public void setParameters(ManagedParameter[] parameters)
+ {
+ this.parameters = parameters;
+ if(this.parameters == null)
+ this.parameters = new ManagedParameter[0];
+ }
+
+ public MetaType getReturnType()
+ {
+ return returnType;
+ }
+
+ public void setReturnType(MetaType returnType)
+ {
+ this.returnType = returnType;
+ }
+
+
+ public String[] getReflectionSignature()
+ {
+ String[] signature = new String[parameters.length];
+ for(int i=0; i < parameters.length; i++)
+ {
+ signature[i] = parameters[i].getMetaType().getTypeName();
+ }
+ return signature;
+ }
+
+ /**
+ * This does not have a meaningful implementation because the target
+ * is unknown. A runtime aspect that understand the context of this
+ * operation needs to perform the invocation.
+ */
+ public MetaValue invoke(MetaValue... param)
+ {
+ return null;
+ }
+
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder();
+ tmp.append("ManagedOperation(name=");
+ tmp.append(name);
+ tmp.append(",description=");
+ tmp.append(description);
+ tmp.append(",impact=");
+ tmp.append(impact);
+ tmp.append(")");
+
+ return tmp.toString();
+ }
+
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationMatcher.java (from rev 84399, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationMatcher.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationMatcher.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedOperationMatcher.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins;
+
+import java.util.Set;
+
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.metatype.api.types.MetaType;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ManagedOperationMatcher
+{
+ public static ManagedOperation findOperation(Set<ManagedOperation> ops, String name,
+ MetaType... signature)
+ {
+ ManagedOperation match = null;
+ for(ManagedOperation op : ops)
+ {
+ if(op.getName().equals(name))
+ {
+ // Validate parameters
+ ManagedParameter[] params = op.getParameters();
+ if(params != null)
+ {
+ int paramLength = params.length;
+ int sigLength = signature.length;
+ if(paramLength != sigLength)
+ continue;
+
+ boolean sigMatches = true;
+ for(int n = 0; n < sigLength; n ++)
+ {
+ ManagedParameter mp = params[n];
+ MetaType mps = mp.getMetaType();
+ MetaType sig = signature[n];
+ if(mps.equals(sig) == false)
+ {
+ sigMatches = false;
+ break;
+ }
+ }
+ if(sigMatches)
+ {
+ // We have a match
+ match = op;
+ break;
+ }
+ }
+ else if(signature == null || signature.length == 0)
+ {
+ match = op;
+ break;
+ }
+ }
+ }
+ return match;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,577 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.plugins;
-
-import java.io.IOException;
-import java.io.InvalidObjectException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * ManagedProperty.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class ManagedPropertyImpl implements ManagedProperty
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 2;
- /* writeObject format:
- * - int version
- * - Fields fields
- * - ManagedObject managedObject
- * - ManagedObject targetManagedObject
- */
- private static final int VERSION1 = 1;
- /** The serialization version used by writeObject */
- private static final int STREAM_VERSION = VERSION1;
-
- /** The managed object */
- private ManagedObject managedObject;
- /** The managed object target for a ManagementObjectRef */
- private ManagedObject targetManagedObject;
-
- /** The fields */
- private Fields fields;
-
- /** The property name */
- private transient String name;
- /** The transient attachments map */
- private transient Map<String, Object> transientAttachments;
-
- /**
- * Create a new ManagedProperty that is not associated to
- * a ManagedObject.
- *
- * @param name the managed property name
- * @throws IllegalArgumentException for null fields or
- * missing Fields.NAME
- */
- public ManagedPropertyImpl(String name)
- {
- this(null, new DefaultFieldsImpl(name));
- }
-
- /**
- * Create a new ManagedProperty that is not associated to
- * a ManagedObject.
- *
- * @param fields the fields
- * @throws IllegalArgumentException for null fields or
- * missing Fields.NAME
- */
- public ManagedPropertyImpl(Fields fields)
- {
- this(null, fields);
- }
-
- /**
- * Create a new ManagedProperty.
- *
- * @param managedObject the managed object, may be null
- * @param fields the fields
- * @throws IllegalArgumentException for null fields or
- * missing Fields.NAME
- */
- public ManagedPropertyImpl(ManagedObject managedObject, Fields fields)
- {
- init(managedObject, fields);
- }
-
- public ManagedObject getManagedObject()
- {
- return managedObject;
- }
-
- /**
- * Set managed object
- *
- * @param managedObject the managed object
- */
- public void setManagedObject(ManagedObject managedObject)
- {
- this.managedObject = managedObject;
- }
-
- public ManagedObject getTargetManagedObject()
- {
- return targetManagedObject;
- }
-
- public void setTargetManagedObject(ManagedObject target)
- {
- this.targetManagedObject = target;
- }
-
- public Fields getFields()
- {
- return fields;
- }
-
- // TODO general reconstruction code for metatypes
- @SuppressWarnings("unchecked")
- public <T> T getField(String fieldName, Class<T> expected)
- {
- if (fieldName == null)
- throw new IllegalArgumentException("Null field name");
- if (expected == null)
- throw new IllegalArgumentException("Null expected type");
-
- Object field = getFields().getField(fieldName);
-
- if (field == null)
- return null;
-
- if (expected.isInstance(field))
- return expected.cast(field);
-
- if (field instanceof SimpleValue)
- {
- SimpleValue value = (SimpleValue) field;
- Object result = value.getValue();
- if (result == null)
- return null;
- return expected.cast(result);
- }
-
- throw new IllegalStateException("Field " + fieldName + " with value " + field + " is not of the expected type: " + expected.getName());
- }
-
- // TODO metaType stuff
- public void setField(String fieldName, Serializable value)
- {
- if (fieldName == null)
- throw new IllegalArgumentException("Null field name");
-
- getFields().setField(fieldName, value);
- }
-
- public String getName()
- {
- return name;
- }
-
- public String getMappedName()
- {
- return getField(Fields.MAPPED_NAME, String.class);
- }
-
- public String getDescription()
- {
- return getField(Fields.DESCRIPTION, String.class);
- }
-
- /**
- * Set the description
- *
- * @param description the description
- */
- public void setDescription(String description)
- {
- setField(Fields.DESCRIPTION, description);
- }
-
-
- /**
- * Get the annotations associated with the property
- * @return the annotations associated with the property
- */
- @SuppressWarnings("unchecked")
- public Map<String, Annotation> getAnnotations()
- {
- Object set = getField(Fields.ANNOTATIONS, Object.class);
- return (Map) set;
- }
-
- public void setAnnotations(Map<String, Annotation> annotations)
- {
- setField(Fields.ANNOTATIONS, (Serializable) annotations);
- }
-
-
- public boolean hasAnnotation(String key)
- {
- boolean hasAnnotation = false;
- // Look to the ManagementProperty annotation
- Map<String, Annotation> annotations = getAnnotations();
- if(annotations != null)
- {
- hasAnnotation = annotations.containsKey(key);
- }
- return hasAnnotation;
- }
-
- /**
- * See if the property has the indicated ViewUse among its
- * @ManagementProperty annotation or VIEW_USE field uses.
- *
- * @param use - the ViewUse to check for
- * @return true if the ViewUse exists in the property uses, false otherwise
- */
- public boolean hasViewUse(ViewUse use)
- {
- boolean hasViewUse = false;
- ViewUse[] uses = getViewUse();
- if(uses != null)
- {
- for(ViewUse vu : uses)
- {
- hasViewUse |= vu == use;
- }
- }
- return hasViewUse;
- }
-
- public MetaType getMetaType()
- {
- return getField(Fields.META_TYPE, MetaType.class);
- }
-
- /**
- * Set the meta type
- *
- * @param type the meta type
- */
- public void setMetaType(MetaType type)
- {
- setField(Fields.META_TYPE, type);
- }
-
- public MetaValue getValue()
- {
- return getField(Fields.VALUE, MetaValue.class);
- }
-
- public void setValue(MetaValue value)
- {
- setField(Fields.VALUE, value);
- }
-
- public ViewUse[] getViewUse()
- {
- ViewUse[] use = {};
- ViewUse[] useField = getField(Fields.VIEW_USE, ViewUse[].class);
- // Also look to the ManagementProperty annotation
- Map<String, Annotation> annotations = getAnnotations();
- if(annotations != null)
- {
- ManagementProperty mp = (ManagementProperty) annotations.get(ManagementProperty.class.getName());
- if(mp != null)
- {
- use = mp.use();
- if(useField != null && useField.length > 0)
- {
- HashSet<ViewUse> uses = new HashSet<ViewUse>();
- for(ViewUse vu : use)
- {
- uses.add(vu);
- }
- for(ViewUse vu : useField)
- {
- uses.add(vu);
- }
- use = new ViewUse[uses.size()];
- uses.toArray(use);
- }
- }
- }
- else if(useField != null)
- {
- use = useField;
- }
- return use;
- }
- public void setViewUse(ViewUse[] use)
- {
- setField(Fields.VIEW_USE, use);
- }
-
- @SuppressWarnings("unchecked")
- public Set<MetaValue> getLegalValues()
- {
- return getField(Fields.LEGAL_VALUES, Set.class);
- }
-
- /**
- * Set the legal values
- *
- * @param values the values
- */
- public void setLegalValues(Set<MetaValue> values)
- {
- setField(Fields.LEGAL_VALUES, (Serializable)values);
- }
-
- public Comparable<MetaValue> getMinimumValue()
- {
- return getField(Fields.MINIMUM_VALUE, Comparable.class);
- }
-
- /**
- * Set the minimum value
- *
- * @param value the value
- */
- public void setMinimumValue(Comparable<MetaValue> value)
- {
- setField(Fields.MINIMUM_VALUE, (Serializable)value);
- }
-
- public Comparable<MetaValue> getMaximumValue()
- {
- Comparable<MetaValue> field = getField(Fields.MAXIMUM_VALUE, Comparable.class);
- return field;
- }
-
- /**
- * Set the maximum value
- *
- * @param value the value
- */
- public void setMaximumValue(Comparable<MetaValue> value)
- {
- setField(Fields.MAXIMUM_VALUE, (Serializable)value);
- }
-
- public String checkValidValue(MetaValue value)
- {
- Comparable<MetaValue> min = getMinimumValue();
- if(min != null)
- {
- if(min.compareTo(value) > 0)
- return "min("+min+") > "+value;
- }
- Comparable<MetaValue> max = getMaximumValue();
- if(max != null)
- {
- if(max.compareTo(value) < 0)
- return "max("+max+") < "+value;
- }
- Set<MetaValue> legalValues = getLegalValues();
- if(legalValues != null && legalValues.size() > 0)
- {
- if(legalValues.contains(value) == false)
- return legalValues+" does not contain: "+value;
- }
- return null;
- }
-
- public boolean isMandatory()
- {
- Boolean result = getField(Fields.MANDATORY, Boolean.class);
- if (result == null)
- return false;
- return result;
- }
-
- public boolean isModified()
- {
- Boolean result = getField(Fields.MODIFIED, Boolean.class);
- if (result == null)
- return false;
- return result;
- }
- public void setModified(boolean flag)
- {
- if (flag)
- setField(Fields.MODIFIED, flag);
- else
- setField(Fields.MODIFIED, null);
- }
-
- /**
- * Set whether the field is mandatory
- *
- * @param flag true for mandatory
- */
- public void setMandatory(boolean flag)
- {
- if (flag)
- setField(Fields.MANDATORY, flag);
- else
- setField(Fields.MANDATORY, null);
- }
-
- public boolean isRemoved()
- {
- Boolean result = getField(Fields.REMOVED, Boolean.class);
- if (result == null)
- return false;
- return result;
- }
-
- /**
- * Set whether the property is removed
- *
- * @param flag true for removed
- */
- public void setRemoved(boolean flag)
- {
- if (flag)
- setField(Fields.REMOVED, flag);
- else
- setField(Fields.REMOVED, null);
- }
-
- public <T> T getTransientAttachment(Class<T> expectedType)
- {
- T tvalue = null;
- Object value = getTransientAttachment(expectedType.getName());
- if(value != null)
- tvalue = expectedType.cast(value);
- return tvalue;
- }
-
- public Object getTransientAttachment(String name)
- {
- Object value = null;
- if(transientAttachments != null)
- value = transientAttachments.get(name);
- return value;
- }
-
- public synchronized void setTransientAttachment(String name, Object attachment)
- {
- if(transientAttachments == null)
- transientAttachments = new HashMap<String, Object>();
- transientAttachments.put(name, attachment);
- }
-
- @Override
- public String toString()
- {
- StringBuilder tmp = new StringBuilder("ManagedProperty");
- tmp.append('{');
- tmp.append(name);
- if( getMappedName() != null )
- {
- tmp.append(',');
- tmp.append(getMappedName());
- }
- tmp.append(",metaType=");
- tmp.append(this.getMetaType());
- tmp.append('}');
- return tmp.toString();
- }
-
- @Override
- public int hashCode()
- {
- return name.hashCode();
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- return true;
- if (obj == null || obj instanceof ManagedProperty == false)
- return false;
-
- ManagedProperty other = (ManagedProperty) obj;
- return getName().equals(other.getName());
- }
-
- /**
- * Initialise a ManagedPropertyImpl.
- *
- * @param managedObject the managed object, may be null
- * @param fields the fields
- * @throws IllegalArgumentException for null fields or
- * missing Fields.NAME
- */
- private void init(ManagedObject managedObject, Fields fields)
- {
- if (fields == null)
- throw new IllegalArgumentException("Null fields");
-
- this.managedObject = managedObject;
- this.fields = fields;
-
- name = getField(Fields.NAME, String.class);
- if (name == null)
- throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
- }
-
- /**
- * Read from a stream
- *
- * @param in the stream
- * @throws IOException for IO problem
- * @throws ClassNotFoundException for a classloading problem
- */
- private void readObject(ObjectInputStream in)
- throws IOException, ClassNotFoundException
- {
- int version = in.readInt();
- if( version == VERSION1 )
- readVersion1(in);
- else
- throw new InvalidObjectException("Unknown version="+version);
- }
- /**
- * Write out the property fields
- * @param out
- * @throws IOException
- */
- private void writeObject(ObjectOutputStream out)
- throws IOException
- {
- out.writeInt(STREAM_VERSION);
- out.writeObject(fields);
- out.writeObject(managedObject);
- out.writeObject(targetManagedObject);
- }
-
- /**
- * The VERSION1 expected format:
- * - Fields fields
- * - ManagedObject managedObject
- */
- private void readVersion1(ObjectInputStream in)
- throws IOException, ClassNotFoundException
- {
- fields = (Fields) in.readObject();
- name = getField(Fields.NAME, String.class);
- if (name == null)
- throw new IOException("No " + Fields.NAME + " in fields");
- managedObject = (ManagedObject) in.readObject();
- targetManagedObject = (ManagedObject) in.readObject();
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/ManagedPropertyImpl.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,584 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.plugins;
+
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * ManagedProperty.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class ManagedPropertyImpl implements ManagedProperty
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 2;
+ /* writeObject format:
+ * - int version
+ * - Fields fields
+ * - ManagedObject managedObject
+ * - ManagedObject targetManagedObject
+ */
+ private static final int VERSION1 = 1;
+ /** The serialization version used by writeObject */
+ private static final int STREAM_VERSION = VERSION1;
+
+ /** The managed object */
+ private ManagedObject managedObject;
+ /** The managed object target for a ManagementObjectRef */
+ private ManagedObject targetManagedObject;
+
+ /** The fields */
+ private Fields fields;
+
+ /** The property name */
+ private transient String name;
+ /** The transient attachments map */
+ private transient Map<String, Object> transientAttachments;
+
+ /**
+ * Create a new ManagedProperty that is not associated to
+ * a ManagedObject.
+ *
+ * @param name the managed property name
+ * @throws IllegalArgumentException for null fields or
+ * missing Fields.NAME
+ */
+ public ManagedPropertyImpl(String name)
+ {
+ this(null, new DefaultFieldsImpl(name));
+ }
+
+ /**
+ * Create a new ManagedProperty that is not associated to
+ * a ManagedObject.
+ *
+ * @param fields the fields
+ * @throws IllegalArgumentException for null fields or
+ * missing Fields.NAME
+ */
+ public ManagedPropertyImpl(Fields fields)
+ {
+ this(null, fields);
+ }
+
+ /**
+ * Create a new ManagedProperty.
+ *
+ * @param managedObject the managed object, may be null
+ * @param fields the fields
+ * @throws IllegalArgumentException for null fields or
+ * missing Fields.NAME
+ */
+ public ManagedPropertyImpl(ManagedObject managedObject, Fields fields)
+ {
+ init(managedObject, fields);
+ }
+
+ public ManagedObject getManagedObject()
+ {
+ return managedObject;
+ }
+
+ /**
+ * Set managed object
+ *
+ * @param managedObject the managed object
+ */
+ public void setManagedObject(ManagedObject managedObject)
+ {
+ this.managedObject = managedObject;
+ }
+
+ public ManagedObject getTargetManagedObject()
+ {
+ return targetManagedObject;
+ }
+
+ public void setTargetManagedObject(ManagedObject target)
+ {
+ this.targetManagedObject = target;
+ }
+
+ public Fields getFields()
+ {
+ return fields;
+ }
+
+ // TODO general reconstruction code for metatypes
+ @SuppressWarnings("unchecked")
+ public <T> T getField(String fieldName, Class<T> expected)
+ {
+ if (fieldName == null)
+ throw new IllegalArgumentException("Null field name");
+ if (expected == null)
+ throw new IllegalArgumentException("Null expected type");
+
+ Object field = getFields().getField(fieldName);
+
+ if (field == null)
+ return null;
+
+ if (expected.isInstance(field))
+ return expected.cast(field);
+
+ if (field instanceof SimpleValue)
+ {
+ SimpleValue value = (SimpleValue) field;
+ Object result = value.getValue();
+ if (result == null)
+ return null;
+ return expected.cast(result);
+ }
+
+ throw new IllegalStateException("Field " + fieldName + " with value " + field + " is not of the expected type: " + expected.getName());
+ }
+
+ // TODO metaType stuff
+ public void setField(String fieldName, Serializable value)
+ {
+ if (fieldName == null)
+ throw new IllegalArgumentException("Null field name");
+
+ getFields().setField(fieldName, value);
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getMappedName()
+ {
+ return getField(Fields.MAPPED_NAME, String.class);
+ }
+
+ public String getDescription()
+ {
+ return getField(Fields.DESCRIPTION, String.class);
+ }
+
+ /**
+ * Set the description
+ *
+ * @param description the description
+ */
+ public void setDescription(String description)
+ {
+ setField(Fields.DESCRIPTION, description);
+ }
+
+
+ /**
+ * Get the annotations associated with the property
+ * @return the annotations associated with the property
+ */
+ @SuppressWarnings("unchecked")
+ public Map<String, Annotation> getAnnotations()
+ {
+ Object set = getField(Fields.ANNOTATIONS, Object.class);
+ return (Map) set;
+ }
+
+ public void setAnnotations(Map<String, Annotation> annotations)
+ {
+ setField(Fields.ANNOTATIONS, (Serializable) annotations);
+ }
+
+
+ public boolean hasAnnotation(String key)
+ {
+ boolean hasAnnotation = false;
+ // Look to the ManagementProperty annotation
+ Map<String, Annotation> annotations = getAnnotations();
+ if(annotations != null)
+ {
+ hasAnnotation = annotations.containsKey(key);
+ }
+ return hasAnnotation;
+ }
+
+ /**
+ * See if the property has the indicated ViewUse among its
+ * @ManagementProperty annotation or VIEW_USE field uses.
+ *
+ * @param use - the ViewUse to check for
+ * @return true if the ViewUse exists in the property uses, false otherwise
+ */
+ public boolean hasViewUse(ViewUse use)
+ {
+ boolean hasViewUse = false;
+ ViewUse[] uses = getViewUse();
+ if(uses != null)
+ {
+ for(ViewUse vu : uses)
+ {
+ hasViewUse |= vu == use;
+ }
+ }
+ return hasViewUse;
+ }
+
+ public MetaType getMetaType()
+ {
+ return getField(Fields.META_TYPE, MetaType.class);
+ }
+
+ /**
+ * Set the meta type
+ *
+ * @param type the meta type
+ */
+ public void setMetaType(MetaType type)
+ {
+ setField(Fields.META_TYPE, type);
+ }
+
+ public MetaValue getValue()
+ {
+ return getField(Fields.VALUE, MetaValue.class);
+ }
+
+ public void setValue(MetaValue value)
+ {
+ setField(Fields.VALUE, value);
+ }
+
+ public ViewUse[] getViewUse()
+ {
+ ViewUse[] use = {};
+ ViewUse[] useField = getField(Fields.VIEW_USE, ViewUse[].class);
+ // Also look to the ManagementProperty annotation
+ Map<String, Annotation> annotations = getAnnotations();
+ if(annotations != null)
+ {
+ ManagementProperty mp = (ManagementProperty) annotations.get(ManagementProperty.class.getName());
+ if(mp != null)
+ {
+ use = mp.use();
+ if(useField != null && useField.length > 0)
+ {
+ HashSet<ViewUse> uses = new HashSet<ViewUse>();
+ for(ViewUse vu : use)
+ {
+ uses.add(vu);
+ }
+ for(ViewUse vu : useField)
+ {
+ uses.add(vu);
+ }
+ use = new ViewUse[uses.size()];
+ uses.toArray(use);
+ }
+ }
+ }
+ else if(useField != null)
+ {
+ use = useField;
+ }
+ return use;
+ }
+ public void setViewUse(ViewUse[] use)
+ {
+ setField(Fields.VIEW_USE, use);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set<MetaValue> getLegalValues()
+ {
+ return getField(Fields.LEGAL_VALUES, Set.class);
+ }
+
+ /**
+ * Set the legal values
+ *
+ * @param values the values
+ */
+ public void setLegalValues(Set<MetaValue> values)
+ {
+ setField(Fields.LEGAL_VALUES, (Serializable)values);
+ }
+
+ public Comparable<MetaValue> getMinimumValue()
+ {
+ return getField(Fields.MINIMUM_VALUE, Comparable.class);
+ }
+
+ /**
+ * Set the minimum value
+ *
+ * @param value the value
+ */
+ public void setMinimumValue(Comparable<MetaValue> value)
+ {
+ setField(Fields.MINIMUM_VALUE, (Serializable)value);
+ }
+
+ public Comparable<MetaValue> getMaximumValue()
+ {
+ Comparable<MetaValue> field = getField(Fields.MAXIMUM_VALUE, Comparable.class);
+ return field;
+ }
+
+ /**
+ * Set the maximum value
+ *
+ * @param value the value
+ */
+ public void setMaximumValue(Comparable<MetaValue> value)
+ {
+ setField(Fields.MAXIMUM_VALUE, (Serializable)value);
+ }
+
+ public String checkValidValue(MetaValue value)
+ {
+ Comparable<MetaValue> min = getMinimumValue();
+ if(min != null)
+ {
+ if(min.compareTo(value) > 0)
+ return "min("+min+") > "+value;
+ }
+ Comparable<MetaValue> max = getMaximumValue();
+ if(max != null)
+ {
+ if(max.compareTo(value) < 0)
+ return "max("+max+") < "+value;
+ }
+ Set<MetaValue> legalValues = getLegalValues();
+ if(legalValues != null && legalValues.size() > 0)
+ {
+ if(legalValues.contains(value) == false)
+ return legalValues+" does not contain: "+value;
+ }
+ return null;
+ }
+
+ public boolean isMandatory()
+ {
+ Boolean result = getField(Fields.MANDATORY, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+
+ public boolean isModified()
+ {
+ Boolean result = getField(Fields.MODIFIED, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+ public void setModified(boolean flag)
+ {
+ if (flag)
+ setField(Fields.MODIFIED, flag);
+ else
+ setField(Fields.MODIFIED, null);
+ }
+
+ /**
+ * Set whether the field is mandatory
+ *
+ * @param flag true for mandatory
+ */
+ public void setMandatory(boolean flag)
+ {
+ if (flag)
+ setField(Fields.MANDATORY, flag);
+ else
+ setField(Fields.MANDATORY, null);
+ }
+
+ public boolean isRemoved()
+ {
+ Boolean result = getField(Fields.REMOVED, Boolean.class);
+ if (result == null)
+ return false;
+ return result;
+ }
+
+ /**
+ * Set whether the property is removed
+ *
+ * @param flag true for removed
+ */
+ public void setRemoved(boolean flag)
+ {
+ if (flag)
+ setField(Fields.REMOVED, flag);
+ else
+ setField(Fields.REMOVED, null);
+ }
+
+ public <T> T getTransientAttachment(Class<T> expectedType)
+ {
+ T tvalue = null;
+ Object value = getTransientAttachment(expectedType.getName());
+ if(value != null)
+ tvalue = expectedType.cast(value);
+ return tvalue;
+ }
+
+ public Object getTransientAttachment(String name)
+ {
+ Object value = null;
+ if(transientAttachments != null)
+ value = transientAttachments.get(name);
+ return value;
+ }
+
+ public synchronized void setTransientAttachment(String name, Object attachment)
+ {
+ if(transientAttachments == null)
+ transientAttachments = new HashMap<String, Object>();
+ transientAttachments.put(name, attachment);
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder tmp = new StringBuilder("ManagedProperty");
+ tmp.append('{');
+ tmp.append(name);
+ if( getMappedName() != null )
+ {
+ tmp.append(',');
+ tmp.append(getMappedName());
+ }
+ tmp.append(",metaType=");
+ tmp.append(this.getMetaType());
+ tmp.append('}');
+ return tmp.toString();
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof ManagedProperty == false)
+ return false;
+
+ ManagedProperty other = (ManagedProperty) obj;
+ return getName().equals(other.getName());
+ }
+
+ public ManagedProperty copy()
+ {
+ Fields fieldsCopy = fields.copy();
+ ManagedProperty mp = new ManagedPropertyImpl(fieldsCopy);
+ return mp;
+ }
+
+ /**
+ * Initialise a ManagedPropertyImpl.
+ *
+ * @param managedObject the managed object, may be null
+ * @param fields the fields
+ * @throws IllegalArgumentException for null fields or
+ * missing Fields.NAME
+ */
+ private void init(ManagedObject managedObject, Fields fields)
+ {
+ if (fields == null)
+ throw new IllegalArgumentException("Null fields");
+
+ this.managedObject = managedObject;
+ this.fields = fields;
+
+ name = getField(Fields.NAME, String.class);
+ if (name == null)
+ throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
+ }
+
+ /**
+ * Read from a stream
+ *
+ * @param in the stream
+ * @throws IOException for IO problem
+ * @throws ClassNotFoundException for a classloading problem
+ */
+ private void readObject(ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ int version = in.readInt();
+ if( version == VERSION1 )
+ readVersion1(in);
+ else
+ throw new InvalidObjectException("Unknown version="+version);
+ }
+ /**
+ * Write out the property fields
+ * @param out
+ * @throws IOException
+ */
+ private void writeObject(ObjectOutputStream out)
+ throws IOException
+ {
+ out.writeInt(STREAM_VERSION);
+ out.writeObject(fields);
+ out.writeObject(managedObject);
+ out.writeObject(targetManagedObject);
+ }
+
+ /**
+ * The VERSION1 expected format:
+ * - Fields fields
+ * - ManagedObject managedObject
+ */
+ private void readVersion1(ObjectInputStream in)
+ throws IOException, ClassNotFoundException
+ {
+ fields = (Fields) in.readObject();
+ name = getField(Fields.NAME, String.class);
+ if (name == null)
+ throw new IOException("No " + Fields.NAME + " in fields");
+ managedObject = (ManagedObject) in.readObject();
+ targetManagedObject = (ManagedObject) in.readObject();
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,966 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.managed.plugins.factory;
-
-import java.io.Serializable;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.config.spi.Configuration;
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedOperation;
-import org.jboss.managed.api.ManagedParameter;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.MutableManagedObject;
-import org.jboss.managed.api.ManagedOperation.Impact;
-import org.jboss.managed.api.annotation.AnnotationDefaults;
-import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
-import org.jboss.managed.api.annotation.FieldsFactory;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementConstants;
-import org.jboss.managed.api.annotation.ManagementDeployment;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementObjectRef;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementParameter;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ManagementPropertyFactory;
-import org.jboss.managed.api.annotation.ManagementRuntimeRef;
-import org.jboss.managed.api.annotation.RunStateProperty;
-import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.api.factory.ManagedObjectDefinition;
-import org.jboss.managed.plugins.DefaultFieldsImpl;
-import org.jboss.managed.plugins.ManagedObjectImpl;
-import org.jboss.managed.plugins.ManagedOperationImpl;
-import org.jboss.managed.plugins.ManagedParameterImpl;
-import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.managed.spi.factory.ManagedObjectBuilder;
-import org.jboss.managed.spi.factory.ManagedObjectPopulator;
-import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulator;
-import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
-import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metatype.api.annotations.MetaMapping;
-import org.jboss.metatype.api.annotations.MetaMappingFactory;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.GenericMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.MetaTypeFactory;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.spi.values.MetaMapper;
-import org.jboss.metatype.spi.values.MetaMapperFactory;
-import org.jboss.reflect.spi.AnnotatedInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.MethodInfo;
-import org.jboss.reflect.spi.ParameterInfo;
-import org.jboss.reflect.spi.TypeInfo;
-
-/**
- * The base ManagedObjectFactory implementation.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class AbstractManagedObjectFactory extends ManagedObjectFactory
- implements ManagedObjectBuilder
-{
- private static final Logger log = Logger.getLogger(AbstractManagedObjectFactory.class);
-
- /** The configuration */
- private static final Configuration configuration = PropertyConfigurationAccess.getConfiguration();
-
- /** The managed object meta type */
- public static final GenericMetaType MANAGED_OBJECT_META_TYPE = new GenericMetaType(ManagedObject.class.getName(), ManagedObject.class.getName());
-
- /** The meta type factory */
- private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
-
- /** The meta value factory */
- private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
- /** A default InstanceClassFactory used when there is no explicit ICF for a given class */
- private InstanceClassFactory<?> defaultInstanceFactory;
- /** A default ManagedObjectPopulator used when there is no explicit ManagedObjectBuilder for a given class */
- private ManagedObjectPopulator<?> defaultManagedObjectPopulator;
-
- /** The managed object builders */
- private Map<Class<?>, ManagedObjectBuilder> builders = new WeakHashMap<Class<?>, ManagedObjectBuilder>();
-
- /** The instance to class factories */
- private Map<Class<?>, InstanceClassFactory<?>> instanceFactories = new WeakHashMap<Class<?>, InstanceClassFactory<?>>();
-
- /**
- * Create a ManagedProperty by looking to the factory for ctor(Fields)
- * @param factory - the ManagedProperty implementation class
- * @param fields - the fields to pass to the ctor
- * @return the managed property if successful, null otherwise
- */
- public static ManagedProperty createManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
- {
- ManagedProperty property = null;
- try
- {
- Class<?>[] sig = {Fields.class};
- Constructor<? extends ManagedProperty> ctor = factory.getConstructor(sig);
- Object[] args = {fields};
- property = ctor.newInstance(args);
- }
- catch(Exception e)
- {
- log.debug("Failed to create ManagedProperty", e);
- }
- return property;
- }
-
- /**
- * Create an AbstractManagedObjectFactory that uses an AbstractInstanceClassFactory
- * as the defaultInstanceFactory and AbstractManagedObjectPopulator as the
- * defaultManagedObjectPopulator. The MetaTypeFactory, MetaValueFactory are
- * obtained from the respective getInstance() factory methods.
- */
- public AbstractManagedObjectFactory()
- {
- // Create an AbstractInstanceClassFactory as the default ICF
- DefaultInstanceClassFactory icf = new DefaultInstanceClassFactory();
- icf.setMof(this);
- defaultInstanceFactory = icf;
- // Create an AbstractManagedObjectPopulator as the default
- defaultManagedObjectPopulator = new AbstractManagedObjectPopulator<Serializable>(configuration, icf, instanceFactories);
- }
- /**
- * Create an AbstractManagedObjectFactory the given factories, supporting
- * information.
- *
- * @param metaTypeFactory
- * @param metaValueFactory
- * @param defaultInstanceFactory
- * @param defaultManagedObjectPopulator
- * @param builders
- * @param instanceFactories
- */
- public AbstractManagedObjectFactory(MetaTypeFactory metaTypeFactory,
- MetaValueFactory metaValueFactory,
- InstanceClassFactory<?> defaultInstanceFactory,
- ManagedObjectPopulator<?> defaultManagedObjectPopulator,
- Map<Class<?>, ManagedObjectBuilder> builders,
- Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
- {
- this.metaTypeFactory = metaTypeFactory;
- this.metaValueFactory = metaValueFactory;
- this.defaultInstanceFactory = defaultInstanceFactory;
- this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
- this.builders = builders;
- this.instanceFactories = instanceFactories;
- }
-
- /**
- * Add managed object definition.
- *
- * @param definition the MO definition
- */
- public void addManagedObjectDefinition(ManagedObjectDefinition definition)
- {
- if (definition == null || definition.isValid() == false)
- throw new IllegalArgumentException("Invalid MO definition: " + definition);
-
- setBuilder(definition.getType(), definition.getBuilder());
- }
-
- /**
- * Remove managed object definition.
- *
- * @param definition the MO definition
- */
- public void removeManagedObjectDefinition(ManagedObjectDefinition definition)
- {
- if (definition == null)
- return;
-
- setBuilder(definition.getType(), null);
- }
-
- /**
- * Get the configuration
- *
- * @return the configuration
- */
- public Configuration getConfiguration()
- {
- return configuration;
- }
-
-
- public MetaTypeFactory getMetaTypeFactory()
- {
- return metaTypeFactory;
- }
-
- public void setMetaTypeFactory(MetaTypeFactory metaTypeFactory)
- {
- this.metaTypeFactory = metaTypeFactory;
- }
-
- public MetaValueFactory getMetaValueFactory()
- {
- return metaValueFactory;
- }
-
- public void setMetaValueFactory(MetaValueFactory metaValueFactory)
- {
- this.metaValueFactory = metaValueFactory;
- }
-
- public Map<Class<?>, ManagedObjectBuilder> getBuilders()
- {
- return builders;
- }
-
- public void setBuilders(Map<Class<?>, ManagedObjectBuilder> builders)
- {
- this.builders = builders;
- }
-
- public Map<Class<?>, InstanceClassFactory<?>> getInstanceFactories()
- {
- return instanceFactories;
- }
-
- public void setInstanceFactories(
- Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
- {
- this.instanceFactories = instanceFactories;
- }
-
- /**
- * Get the default InstanceClassFactory
- * @return the current default InstanceClassFactory
- */
- public InstanceClassFactory<?> getDefaultInstanceFactory()
- {
- return defaultInstanceFactory;
- }
- /**
- * Set the default InstanceClassFactory. This is used when there is not
- * match an exact match by the {@linkplain #getInstanceClassFactory(Class)}
- * factory method.
- *
- * @param defaultInstanceFactory the default InstanceClassFactory to fall
- * back to. It may be null if no default should be used.
- */
- public void setDefaultInstanceFactory(
- InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
- {
- this.defaultInstanceFactory = defaultInstanceFactory;
- }
-
-
- public ManagedObjectPopulator<?> getDefaultManagedObjectPopulator()
- {
- return defaultManagedObjectPopulator;
- }
-
- /**
- * A default implementation of ManagedObjectPopulator that is used when
- * there is no ManagedObjectBuilder registered for a given type.
- * @see #getBuilder(Class)
- * @param defaultManagedObjectPopulator
- */
- public void setDefaultManagedObjectPopulator(
- ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator)
- {
- this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
- }
-
- @Override
- public <T> ManagedObject createManagedObject(Class<T> clazz, MetaData metaData)
- {
- if (clazz == null)
- throw new IllegalArgumentException("Null class");
-
- ManagedObject result = createSkeletonManagedObject(clazz, metaData);
- ManagedObjectPopulator<T> populator = getPopulator(clazz);
- populator.createObject(result, clazz, metaData);
-
- return result;
- }
-
- public ManagedObject initManagedObject(Object instance, Class<?> instanceType,
- MetaData metaData, String name, String nameType)
- {
- if (instance == null)
- throw new IllegalArgumentException("instance cannot be null");
-
- Class<?> clazz = instance.getClass();
- InstanceClassFactory icf = defaultInstanceFactory;
- if(instanceType != null && instanceType != clazz)
- icf = getInstanceClassFactory(instanceType, metaData);
- if(icf == defaultInstanceFactory)
- icf = getInstanceClassFactory(clazz, metaData);
-
- Class<Object> moClass;
- try
- {
- moClass = icf.getManagedObjectClass(instance);
- }
- catch(ClassNotFoundException e)
- {
- log.debug("Failed to load class for ManagedObject", e);
- return null;
- }
- if(moClass == null)
- {
- log.debug("ICF returned null class: "+instance);
- return null;
- }
-
- ManagedObject result = createSkeletonManagedObject(moClass, metaData);
- if (result == null)
- {
- log.debug("Null ManagedObject created for: "+moClass);
- return null;
- }
- log.debug("Created skeleton ManagedObject: "+result);
-
- if(result instanceof MutableManagedObject)
- {
- MutableManagedObject mmo = (MutableManagedObject) result;
- ManagedObjectPopulator<Object> populator = getPopulator(moClass);
- populator.populateManagedObject(mmo, instance, metaData);
- }
-
- return result;
- }
-
- @Override
- public void setBuilder(Class<?> clazz, ManagedObjectBuilder builder)
- {
- synchronized (builders)
- {
- if (builder == null)
- builders.remove(clazz);
- else
- builders.put(clazz, builder);
- }
- }
-
- @Override
- public <T> void setInstanceClassFactory(Class<T> clazz, InstanceClassFactory<T> factory)
- {
- synchronized (instanceFactories)
- {
- if (factory == null)
- {
- instanceFactories.remove(clazz);
- log.debug("Removed ICF for: "+clazz);
- }
- else
- {
- instanceFactories.put(clazz, factory);
- log.debug("Set ICF for: "+clazz+", to: "+factory);
- }
- }
- }
-
- /**
- * Create a skeleton managed object
- *
- * @param <T> the type
- * @param clazz the clazz
- * @return the skeleton managed object, null if clazz is not
- * marked as a ManagementObject.
- * {@linkplain ManagementObject}
- */
- protected <T> ManagedObject createSkeletonManagedObject(Class<T> clazz, MetaData metaData)
- {
- if (clazz == null)
- throw new IllegalArgumentException("Null class");
-
- ManagedObjectBuilder builder = getBuilder(clazz);
- return builder.buildManagedObject(clazz, metaData);
- }
-
- /**
- * The ManagedObjectBuilder.buildManagedObject implementation. This is based
- * on the org.jboss.managed.api.annotation.* package annotations.
- * @param clazz the attachment class
- * @param metaData - the optional metadata repository accessor used to query
- * for management annotation overrides/additions to the clazz
- * @return the ManagementObject if clazz is properly annotated, null if
- * it does not have a ManagementObject annotation on the class or metaData
- */
- @SuppressWarnings("unchecked")
- public ManagedObject buildManagedObject(Class<?> clazz, MetaData metaData)
- {
- boolean trace = log.isTraceEnabled();
- BeanInfo beanInfo = configuration.getBeanInfo(clazz);
- ClassInfo classInfo = beanInfo.getClassInfo();
-
- ManagementObject managementObject = getAnnotation(ManagementObject.class, classInfo, metaData);
- if( managementObject == null )
- {
- if (trace)
- log.trace("No ManagementObject annotation, skipping ManagedObject for class: "+clazz);
- // Skip the ManagedObject creation
- return null;
- }
-
- HashMap<String, Annotation> moAnnotations = new HashMap<String, Annotation>();
- moAnnotations.put(ManagementObject.class.getName(), managementObject);
- ManagementDeployment mnagementDeployment = getAnnotation(ManagementDeployment.class, classInfo, metaData);
- if(mnagementDeployment != null)
- moAnnotations.put(ManagementDeployment.class.getName(), mnagementDeployment);
- ManagementObjectID moID = getAnnotation(ManagementObjectID.class, classInfo, metaData);
- if (moID != null)
- moAnnotations.put(ManagementObjectID.class.getName(), moID);
-
- // Process the ManagementObject fields
- boolean isRuntime = managementObject.isRuntime();
- String name = classInfo.getName();
- String nameType = null;
- String attachmentName = classInfo.getName();
- Class<? extends Fields> moFieldsFactory = null;
- ConstraintsPopulatorFactory moCPF = null;
- Class<? extends ManagedPropertyConstraintsPopulatorFactory> moConstraintsFactory = null;
- Class<? extends ManagedProperty> moPropertyFactory = null;
- if (managementObject != null)
- {
- name = managementObject.name();
- if (name.length() == 0 || name.equals(ManagementConstants.GENERATED))
- name = classInfo.getName();
- nameType = managementObject.type();
- if (nameType.length() == 0)
- nameType = null;
- attachmentName = managementObject.attachmentName();
- if (attachmentName.length() == 0)
- attachmentName = classInfo.getName();
- // Check for a component specification
- ManagementComponent mc = managementObject.componentType();
- // Work around JBMDR-51 by checking type/subtype
- // if (mc.equals(AnnotationDefaults.COMP_TYPE) == false)
- if (mc.type().length() > 0 || mc.subtype().length() > 0)
- {
- log.debug("ManagedObject("+name+") is ManagedComponent type: "+mc);
- moAnnotations.put(ManagementComponent.class.getName(), mc);
- }
- // ManagementObject level default factory classes
- FieldsFactory ff = getAnnotation(FieldsFactory.class, classInfo, metaData);
- if(ff != null)
- moFieldsFactory = ff.value();
- moCPF = getAnnotation(ConstraintsPopulatorFactory.class, classInfo, metaData);
- if(moCPF != null)
- moConstraintsFactory = moCPF.value();
- ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, classInfo, metaData);
- if(mpf != null)
- moPropertyFactory = mpf.value();
- }
-
- if (trace)
- {
- log.trace("Building MangedObject(name="+name+",nameType="+nameType
- +",attachmentName="+attachmentName+",isRuntime="+isRuntime+")");
- }
-
- ManagementProperties propertyType = ManagementProperties.ALL;
- Set<String> classProperties = null;
- if (managementObject != null)
- {
- propertyType = managementObject.properties();
- if(propertyType == ManagementProperties.CLASS || propertyType == ManagementProperties.CLASS_AND_EXPLICIT)
- {
- classProperties = new HashSet<String>();
- for(ManagementProperty mp : managementObject.classProperties())
- {
- if(mp.name().length() > 0)
- classProperties.add(mp.name());
- if(mp.mappedName().length() > 0)
- classProperties.add(mp.mappedName());
- }
- }
- }
-
- // Build the ManagedProperties
- Set<ManagedProperty> properties = new HashSet<ManagedProperty>();
-
- Set<PropertyInfo> propertyInfos = beanInfo.getProperties();
- if (propertyInfos != null && propertyInfos.isEmpty() == false)
- {
- for (PropertyInfo propertyInfo : propertyInfos)
- {
- // Ignore the "class" property
- if ("class".equals(propertyInfo.getName()))
- continue;
-
- ManagementProperty managementProperty = getAnnotation(ManagementProperty.class, propertyInfo, metaData);
- ManagementObjectID id = getAnnotation(ManagementObjectID.class, propertyInfo, metaData);
- ManagementObjectRef ref = getAnnotation(ManagementObjectRef.class, propertyInfo, metaData);
- ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, propertyInfo, metaData);
- RunStateProperty rsp = getAnnotation(RunStateProperty.class, propertyInfo, metaData);
- HashMap<String, Annotation> propAnnotations = new HashMap<String, Annotation>();
- if (managementProperty != null)
- propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
- if (id != null)
- {
- propAnnotations.put(ManagementObjectID.class.getName(), id);
- // This overrides the MO nameType
- nameType = id.type();
- }
- if (ref != null)
- propAnnotations.put(ManagementObjectRef.class.getName(), ref);
- if (runtimeRef != null)
- propAnnotations.put(ManagementRuntimeRef.class.getName(), runtimeRef);
- if (rsp != null)
- propAnnotations.put(RunStateProperty.class.getName(), rsp);
-
- // Check whether this property should be included
- boolean includeProperty = false;
- switch(propertyType)
- {
- // Only if the property as a ManagementProperty
- case EXPLICIT:
- includeProperty = managementProperty != null &&
- (managementProperty.ignored() == false);
- break;
- // Only if the property is listed in the classProperties
- case CLASS:
- includeProperty = classProperties.contains(propertyInfo.getName());
- break;
- // Only if the property is listed in the classProperties
- case CLASS_AND_EXPLICIT:
- includeProperty = classProperties.contains(propertyInfo.getName())
- || (managementProperty != null && managementProperty.ignored() == false);
- break;
- // Any property that is not ignored
- case ALL:
- includeProperty = managementProperty == null
- || managementProperty.ignored() == false;
- break;
- }
-
- if (includeProperty)
- {
- Fields fields = null;
- Class<? extends Fields> factory = moFieldsFactory;
- FieldsFactory ff = getAnnotation(FieldsFactory.class, propertyInfo, metaData);
- if(ff != null)
- factory = ff.value();
- if (factory != null)
- {
- try
- {
- fields = factory.newInstance();
- }
- catch (Exception e)
- {
- log.debug("Failed to created Fields", e);
- }
- }
- if (fields == null)
- fields = new DefaultFieldsImpl();
-
- if( propertyInfo instanceof Serializable )
- {
- Serializable info = Serializable.class.cast(propertyInfo);
- fields.setField(Fields.PROPERTY_INFO, info);
- }
-
- String propertyName = propertyInfo.getName();
- if (managementProperty != null)
- propertyName = managementProperty.name();
- if( propertyName.length() == 0 )
- propertyName = propertyInfo.getName();
- fields.setField(Fields.NAME, propertyName);
-
- // This should probably always the the propertyInfo name?
- String mappedName = propertyInfo.getName();
- if (managementProperty != null)
- mappedName = managementProperty.mappedName();
- if( mappedName.length() == 0 )
- mappedName = propertyInfo.getName();
- fields.setField(Fields.MAPPED_NAME, mappedName);
-
- String description = ManagementConstants.GENERATED;
- if (managementProperty != null)
- description = managementProperty.description();
- if (description.equals(ManagementConstants.GENERATED))
- description = propertyName;
- fields.setField(Fields.DESCRIPTION, description);
-
- if (trace)
- {
- log.trace("Building MangedProperty(name="+propertyName
- +",mappedName="+mappedName
- +") ,annotations="+propAnnotations);
- }
-
- boolean mandatory = false;
- if (managementProperty != null)
- mandatory = managementProperty.mandatory();
- if (mandatory)
- fields.setField(Fields.MANDATORY, Boolean.TRUE);
-
- boolean managed = false;
- if (managementProperty != null)
- managed = managementProperty.managed();
-
- // The managed property type
- MetaType metaType = null;
- MetaMapper<?> metaMapper = null;
- MetaMapping metaMapping = getAnnotation(MetaMapping.class, propertyInfo, metaData);
- MetaMappingFactory metaMappingFactory = getAnnotation(MetaMappingFactory.class, propertyInfo, metaData);
- if(metaMappingFactory != null)
- {
- Class<? extends MetaMapperFactory<?>> mmfClass = metaMappingFactory.value();
- try
- {
- MetaMapperFactory<?> mmf = mmfClass.newInstance();
- String[] args = metaMappingFactory.args();
- if(args.length > 0)
- metaMapper = mmf.newInstance(args);
- else
- metaMapper = mmf.newInstance();
- }
- catch(Exception e)
- {
- log.debug("Failed to create MetaMapperFactory: "+metaMappingFactory, e);
- }
- }
- if(metaMapping != null)
- {
- // Use the mapping for the type
- Class<? extends MetaMapper<?>> mapperClass = metaMapping.value();
- try
- {
- metaMapper = mapperClass.newInstance();
- }
- catch(Exception e)
- {
- log.debug("Failed to create MetaMapper: "+metaMapping, e);
- }
- }
- if(metaMapper != null)
- metaType = metaMapper.getMetaType();
-
- // Determine meta type based on property type
- if(metaType == null)
- {
- if (managed)
- {
- TypeInfo typeInfo = propertyInfo.getType();
- if(typeInfo.isArray())
- metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
- else if (typeInfo.isCollection())
- metaType = new CollectionMetaType(typeInfo.getName(), MANAGED_OBJECT_META_TYPE);
- else
- metaType = MANAGED_OBJECT_META_TYPE;
- }
- else
- {
- metaType = metaTypeFactory.resolve(propertyInfo.getType());
- }
- }
- fields.setField(Fields.META_TYPE, metaType);
- // Property annotations
- if (propAnnotations.isEmpty() == false)
- fields.setField(Fields.ANNOTATIONS, propAnnotations);
-
- // Delegate others (legal values, min/max etc.) to the constraints factory
- try
- {
- Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = moConstraintsFactory;
- ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, propertyInfo, metaData);
- if(cpf != null)
- factoryClass = cpf.value();
- else
- cpf = moCPF;
- if(factoryClass != null)
- {
- ManagedPropertyConstraintsPopulatorFactory mpcpf = factoryClass.newInstance();
- ManagedPropertyConstraintsPopulator populator = mpcpf.newInstance(cpf.min(), cpf.max(), cpf.legalValues(), cpf.args());
- if (populator != null)
- populator.populateManagedProperty(clazz, propertyInfo, fields);
- }
- }
- catch(Exception e)
- {
- log.debug("Failed to populate constraints for: "+propertyInfo, e);
- }
-
- ManagedProperty property = null;
- Class<? extends ManagedProperty> mpClass = moPropertyFactory;
- ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, propertyInfo, metaData);
- if (mpf != null)
- mpClass = mpf.value();
- if (mpClass != null)
- property = getManagedProperty(mpClass, fields);
- // we should have write-through by default
- // use factory to change this default behavior
- if (property == null)
- property = createDefaultManagedProperty(fields);
- // Pass the MetaMapper as an attachment
- if(metaMapper != null)
- property.setTransientAttachment(MetaMapper.class.getName(), metaMapper);
- properties.add(property);
- }
- else if (trace)
- log.trace("Ignoring property: " + propertyInfo);
- }
- }
-
- /* TODO: Operations. In general the bean metadata does not contain
- operation information.
- */
- Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
-
- Set<MethodInfo> methodInfos = beanInfo.getMethods();
- if (methodInfos != null && methodInfos.isEmpty() == false)
- {
- for (MethodInfo methodInfo : methodInfos)
- {
- ManagementOperation managementOp = getAnnotation(ManagementOperation.class, methodInfo, metaData);
- if (managementOp == null)
- continue;
-
- ManagedOperation op = getManagedOperation(methodInfo, managementOp);
- operations.add(op);
- }
- }
-
- ManagedObjectImpl result = new ManagedObjectImpl(name, properties);
- result.setAnnotations(moAnnotations);
- if (nameType != null)
- result.setNameType(nameType);
- if (attachmentName != null)
- result.setAttachmentName(attachmentName);
- if (operations.size() > 0 )
- result.setOperations(operations);
- for (ManagedProperty property : properties)
- property.setManagedObject(result);
- return result;
- }
-
- /**
- * Create default MangedProperty instance.
- * Override this method for different default.
- *
- * @param fields the fields
- * @return new ManagedProperty instance
- */
- protected ManagedProperty createDefaultManagedProperty(Fields fields)
- {
- return new WritethroughManagedPropertyImpl(fields, metaValueFactory, this);
- }
-
- /**
- * Get the property name.
- *
- * @param property managed property
- * @return property name
- */
- protected String getPropertyName(ManagedProperty property)
- {
- // First look to the mapped name
- String name = property.getMappedName();
- if (name == null)
- property.getName();
- return name;
- }
-
- /**
- *
- * @param methodInfo
- * @param opAnnotation
- * @return the managed operation
- */
- protected ManagedOperation getManagedOperation(MethodInfo methodInfo, ManagementOperation opAnnotation)
- {
- String name = methodInfo.getName();
- String description = opAnnotation.description();
- Impact impact = opAnnotation.impact();
- ManagementParameter[] params = opAnnotation.params();
- ParameterInfo[] paramInfo = methodInfo.getParameters();
- TypeInfo returnInfo = methodInfo.getReturnType();
- MetaType returnType = metaTypeFactory.resolve(returnInfo);
- ArrayList<ManagedParameter> mparams = new ArrayList<ManagedParameter>();
- Class<? extends ManagedParameterConstraintsPopulatorFactory> opConstraintsFactor = opAnnotation.constraintsFactory();
-
- if( paramInfo != null )
- {
- for(int i = 0; i < paramInfo.length; i ++)
- {
- ParameterInfo pinfo = paramInfo[i];
- String pname = pinfo.getName();
- String pdescription = null;
- ManagementParameter mpa = null;
- // Look to ManagementParameter for info
- if (i < params.length)
- {
- mpa = params[i];
- if (mpa.name().equals(AnnotationDefaults.EMPTY_STRING) == false)
- pname = mpa.name();
- if (mpa.description().equals(AnnotationDefaults.EMPTY_STRING) == false)
- pdescription = mpa.description();
- }
- // Generate a name if there is none
- if (pname == null)
- pname = "arg#" + i;
- Fields fields = new DefaultFieldsImpl(pname);
- if (pdescription != null)
- fields.setField(Fields.DESCRIPTION, pdescription);
- MetaType metaType = metaTypeFactory.resolve(pinfo.getParameterType());
- fields.setField(Fields.META_TYPE, metaType);
- // Delegate others (legal values, min/max etc.) to the constraints factory
- try
- {
- Class<? extends ManagedParameterConstraintsPopulatorFactory> factoryClass = opConstraintsFactor;
- if (factoryClass == ManagementParameter.NULL_CONSTRAINTS.class)
- {
- if (mpa != null)
- factoryClass = mpa.constraintsFactory();
- }
- ManagedParameterConstraintsPopulatorFactory factory = factoryClass.newInstance();
- ManagedParameterConstraintsPopulator populator = factory.newInstance();
- if (populator != null)
- populator.populateManagedParameter(name, pinfo, fields);
- }
- catch(Exception e)
- {
- log.debug("Failed to populate constraints for: "+pinfo, e);
- }
-
- ManagedParameterImpl mp = new ManagedParameterImpl(fields);
- mparams.add(mp);
- }
- }
- ManagedParameter[] parameters = new ManagedParameter[mparams.size()];
- mparams.toArray(parameters);
-
- return new ManagedOperationImpl(name, description, impact, parameters, returnType);
- }
-
- /**
- * Get the builder for a class
- *
- * @param clazz the class
- * @return the builder
- */
- protected ManagedObjectBuilder getBuilder(Class<?> clazz)
- {
- synchronized (builders)
- {
- ManagedObjectBuilder builder = builders.get(clazz);
- if (builder != null)
- return builder;
- }
- return this;
- }
-
- /**
- * Get the instance factory for a class
- *
- * @param clazz the class
- * @return the InstanceClassFactory
- */
- @SuppressWarnings("unchecked")
- public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz,
- MetaData metaData)
- {
- InstanceClassFactory defaultFactory = defaultInstanceFactory;
- if(metaData != null)
- {
- InstanceClassFactory mdrFactory = metaData.getMetaData(InstanceClassFactory.class);
- if(mdrFactory != null)
- defaultFactory = mdrFactory;
- }
- InstanceClassFactory<X> factory = (InstanceClassFactory<X>)
- Utility.getInstanceClassFactory(clazz, instanceFactories,
- defaultFactory);
- return factory;
- }
-
- /**
- * Get the populator for a class
- *
- * @param clazz the class
- * @return the populator
- */
- @SuppressWarnings("unchecked")
- protected <X> ManagedObjectPopulator<X> getPopulator(Class<X> clazz)
- {
- ManagedObjectBuilder builder = getBuilder(clazz);
- if (builder instanceof ManagedObjectPopulator)
- return (ManagedObjectPopulator) builder;
- ManagedObjectPopulator<X> mop = (ManagedObjectPopulator<X>) defaultManagedObjectPopulator;
- return mop;
- }
-
- protected Collection<?> getAsCollection(Object value)
- {
- if( value.getClass().isArray() )
- return Arrays.asList(value);
- else if (value instanceof Collection)
- return Collection.class.cast(value);
- return null;
- }
-
- /**
- * Look for ctor(Fields)
- * @param factory - the ManagedProperty implementation class
- * @param fields - the fields to pass to the ctor
- * @return the managed property
- */
- protected ManagedProperty getManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
- {
- return createManagedProperty(factory, fields);
- }
-
- protected <X extends Annotation> X getAnnotation(Class<X> annotationType,
- AnnotatedInfo info, MetaData metaData)
- {
- X annotation = null;
- if(metaData != null)
- {
- annotation = metaData.getAnnotation(annotationType);
- if(annotation != null)
- log.trace("Loaded "+annotationType+" from MetaData");
- }
- if(annotation == null)
- annotation = info.getUnderlyingAnnotation(annotationType);
- return annotation;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,1049 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.managed.plugins.factory;
+
+import java.io.Serializable;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.spi.Configuration;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedParameter;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedObject;
+import org.jboss.managed.api.ManagedOperation.Impact;
+import org.jboss.managed.api.annotation.AnnotationDefaults;
+import org.jboss.managed.api.annotation.ConstraintsPopulatorFactory;
+import org.jboss.managed.api.annotation.FieldsFactory;
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementConstants;
+import org.jboss.managed.api.annotation.ManagementDeployment;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementObjectRef;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementParameter;
+import org.jboss.managed.api.annotation.ManagementProperties;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementPropertyFactory;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+import org.jboss.managed.api.annotation.RunStateProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.api.factory.ManagedObjectDefinition;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedOperationImpl;
+import org.jboss.managed.plugins.ManagedParameterImpl;
+import org.jboss.managed.plugins.WritethroughManagedPropertyImpl;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.managed.spi.factory.ManagedObjectBuilder;
+import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedParameterConstraintsPopulatorFactory;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulator;
+import org.jboss.managed.spi.factory.ManagedPropertyConstraintsPopulatorFactory;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.signature.FieldSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+import org.jboss.metadata.spi.signature.Signature;
+import org.jboss.metatype.api.annotations.MetaMapping;
+import org.jboss.metatype.api.annotations.MetaMappingFactory;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.metatype.spi.values.MetaMapperFactory;
+import org.jboss.reflect.spi.AnnotatedInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.MethodInfo;
+import org.jboss.reflect.spi.ParameterInfo;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * The base ManagedObjectFactory implementation.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractManagedObjectFactory extends ManagedObjectFactory
+ implements ManagedObjectBuilder
+{
+ private static final Logger log = Logger.getLogger(AbstractManagedObjectFactory.class);
+
+ /** The configuration */
+ private static final Configuration configuration = PropertyConfigurationAccess.getConfiguration();
+
+ /** The managed object meta type */
+ public static final GenericMetaType MANAGED_OBJECT_META_TYPE = new GenericMetaType(ManagedObject.class.getName(), ManagedObject.class.getName());
+
+ /** The meta type factory */
+ private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
+
+ /** The meta value factory */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ /** A default InstanceClassFactory used when there is no explicit ICF for a given class */
+ private InstanceClassFactory<?> defaultInstanceFactory;
+ /** A default ManagedObjectPopulator used when there is no explicit ManagedObjectBuilder for a given class */
+ private ManagedObjectPopulator<?> defaultManagedObjectPopulator;
+
+ /** The managed object builders */
+ private Map<Class<?>, ManagedObjectBuilder> builders = new WeakHashMap<Class<?>, ManagedObjectBuilder>();
+
+ /** The instance to class factories */
+ private Map<Class<?>, InstanceClassFactory<?>> instanceFactories = new WeakHashMap<Class<?>, InstanceClassFactory<?>>();
+
+ /**
+ * Create a ManagedProperty by looking to the factory for ctor(Fields)
+ * @param factory - the ManagedProperty implementation class
+ * @param fields - the fields to pass to the ctor
+ * @return the managed property if successful, null otherwise
+ */
+ public static ManagedProperty createManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
+ {
+ ManagedProperty property = null;
+ try
+ {
+ Class<?>[] sig = {Fields.class};
+ Constructor<? extends ManagedProperty> ctor = factory.getConstructor(sig);
+ Object[] args = {fields};
+ property = ctor.newInstance(args);
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create ManagedProperty", e);
+ }
+ return property;
+ }
+
+ /**
+ * Create an AbstractManagedObjectFactory that uses an AbstractInstanceClassFactory
+ * as the defaultInstanceFactory and AbstractManagedObjectPopulator as the
+ * defaultManagedObjectPopulator. The MetaTypeFactory, MetaValueFactory are
+ * obtained from the respective getInstance() factory methods.
+ */
+ public AbstractManagedObjectFactory()
+ {
+ // Create an AbstractInstanceClassFactory as the default ICF
+ DefaultInstanceClassFactory icf = new DefaultInstanceClassFactory();
+ icf.setMof(this);
+ defaultInstanceFactory = icf;
+ // Create an AbstractManagedObjectPopulator as the default
+ defaultManagedObjectPopulator = new AbstractManagedObjectPopulator<Serializable>(configuration, icf, instanceFactories);
+ }
+ /**
+ * Create an AbstractManagedObjectFactory the given factories, supporting
+ * information.
+ *
+ * @param metaTypeFactory
+ * @param metaValueFactory
+ * @param defaultInstanceFactory
+ * @param defaultManagedObjectPopulator
+ * @param builders
+ * @param instanceFactories
+ */
+ public AbstractManagedObjectFactory(MetaTypeFactory metaTypeFactory,
+ MetaValueFactory metaValueFactory,
+ InstanceClassFactory<?> defaultInstanceFactory,
+ ManagedObjectPopulator<?> defaultManagedObjectPopulator,
+ Map<Class<?>, ManagedObjectBuilder> builders,
+ Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
+ {
+ this.metaTypeFactory = metaTypeFactory;
+ this.metaValueFactory = metaValueFactory;
+ this.defaultInstanceFactory = defaultInstanceFactory;
+ this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
+ this.builders = builders;
+ this.instanceFactories = instanceFactories;
+ }
+
+ /**
+ * Add managed object definition.
+ *
+ * @param definition the MO definition
+ */
+ public void addManagedObjectDefinition(ManagedObjectDefinition definition)
+ {
+ if (definition == null || definition.isValid() == false)
+ throw new IllegalArgumentException("Invalid MO definition: " + definition);
+
+ setBuilder(definition.getType(), definition.getBuilder());
+ }
+
+ /**
+ * Remove managed object definition.
+ *
+ * @param definition the MO definition
+ */
+ public void removeManagedObjectDefinition(ManagedObjectDefinition definition)
+ {
+ if (definition == null)
+ return;
+
+ setBuilder(definition.getType(), null);
+ }
+
+ /**
+ * Get the configuration
+ *
+ * @return the configuration
+ */
+ public Configuration getConfiguration()
+ {
+ return configuration;
+ }
+
+
+ public MetaTypeFactory getMetaTypeFactory()
+ {
+ return metaTypeFactory;
+ }
+
+ public void setMetaTypeFactory(MetaTypeFactory metaTypeFactory)
+ {
+ this.metaTypeFactory = metaTypeFactory;
+ }
+
+ public MetaValueFactory getMetaValueFactory()
+ {
+ return metaValueFactory;
+ }
+
+ public void setMetaValueFactory(MetaValueFactory metaValueFactory)
+ {
+ this.metaValueFactory = metaValueFactory;
+ }
+
+ public Map<Class<?>, ManagedObjectBuilder> getBuilders()
+ {
+ return builders;
+ }
+
+ public void setBuilders(Map<Class<?>, ManagedObjectBuilder> builders)
+ {
+ this.builders = builders;
+ }
+
+ public Map<Class<?>, InstanceClassFactory<?>> getInstanceFactories()
+ {
+ return instanceFactories;
+ }
+
+ public void setInstanceFactories(
+ Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
+ {
+ this.instanceFactories = instanceFactories;
+ }
+
+ /**
+ * Get the default InstanceClassFactory
+ * @return the current default InstanceClassFactory
+ */
+ public InstanceClassFactory<?> getDefaultInstanceFactory()
+ {
+ return defaultInstanceFactory;
+ }
+ /**
+ * Set the default InstanceClassFactory. This is used when there is not
+ * match an exact match by the {@linkplain #getInstanceClassFactory(Class)}
+ * factory method.
+ *
+ * @param defaultInstanceFactory the default InstanceClassFactory to fall
+ * back to. It may be null if no default should be used.
+ */
+ public void setDefaultInstanceFactory(
+ InstanceClassFactory<? extends Serializable> defaultInstanceFactory)
+ {
+ this.defaultInstanceFactory = defaultInstanceFactory;
+ }
+
+
+ public ManagedObjectPopulator<?> getDefaultManagedObjectPopulator()
+ {
+ return defaultManagedObjectPopulator;
+ }
+
+ /**
+ * A default implementation of ManagedObjectPopulator that is used when
+ * there is no ManagedObjectBuilder registered for a given type.
+ * @see #getBuilder(Class)
+ * @param defaultManagedObjectPopulator
+ */
+ public void setDefaultManagedObjectPopulator(
+ ManagedObjectPopulator<? extends Serializable> defaultManagedObjectPopulator)
+ {
+ this.defaultManagedObjectPopulator = defaultManagedObjectPopulator;
+ }
+
+ @Override
+ public <T> ManagedObject createManagedObject(Class<T> clazz, MetaData metaData)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null class");
+
+ ManagedObject result = createSkeletonManagedObject(clazz, metaData);
+ ManagedObjectPopulator<T> populator = getPopulator(clazz);
+ populator.createObject(result, clazz, metaData);
+
+ return result;
+ }
+
+ public ManagedObject initManagedObject(Object instance, Class<?> instanceType,
+ MetaData metaData, String name, String nameType)
+ {
+ if (instance == null)
+ throw new IllegalArgumentException("instance cannot be null");
+
+ Class<?> clazz = instance.getClass();
+ InstanceClassFactory icf = defaultInstanceFactory;
+ if(instanceType != null && instanceType != clazz)
+ icf = getInstanceClassFactory(instanceType, metaData);
+ if(icf == defaultInstanceFactory)
+ icf = getInstanceClassFactory(clazz, metaData);
+
+ Class<Object> moClass;
+ try
+ {
+ moClass = icf.getManagedObjectClass(instance);
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.debug("Failed to load class for ManagedObject", e);
+ return null;
+ }
+ if(moClass == null)
+ {
+ log.debug("ICF returned null class: "+instance);
+ return null;
+ }
+
+ ManagedObject result = createSkeletonManagedObject(moClass, metaData);
+ if (result == null)
+ {
+ log.debug("Null ManagedObject created for: "+moClass);
+ return null;
+ }
+ log.debug("Created skeleton ManagedObject: "+result);
+
+ if(result instanceof MutableManagedObject)
+ {
+ MutableManagedObject mmo = (MutableManagedObject) result;
+ ManagedObjectPopulator<Object> populator = getPopulator(moClass);
+ populator.populateManagedObject(mmo, instance, metaData);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void setBuilder(Class<?> clazz, ManagedObjectBuilder builder)
+ {
+ synchronized (builders)
+ {
+ if (builder == null)
+ builders.remove(clazz);
+ else
+ builders.put(clazz, builder);
+ }
+ }
+
+ @Override
+ public <T> void setInstanceClassFactory(Class<T> clazz, InstanceClassFactory<T> factory)
+ {
+ synchronized (instanceFactories)
+ {
+ if (factory == null)
+ {
+ instanceFactories.remove(clazz);
+ log.debug("Removed ICF for: "+clazz);
+ }
+ else
+ {
+ instanceFactories.put(clazz, factory);
+ log.debug("Set ICF for: "+clazz+", to: "+factory);
+ }
+ }
+ }
+
+ /**
+ * Create a skeleton managed object
+ *
+ * @param <T> the type
+ * @param clazz the clazz
+ * @return the skeleton managed object, null if clazz is not
+ * marked as a ManagementObject.
+ * {@linkplain ManagementObject}
+ */
+ protected <T> ManagedObject createSkeletonManagedObject(Class<T> clazz, MetaData metaData)
+ {
+ if (clazz == null)
+ throw new IllegalArgumentException("Null class");
+
+ ManagedObjectBuilder builder = getBuilder(clazz);
+ return builder.buildManagedObject(clazz, metaData);
+ }
+
+ /**
+ * The ManagedObjectBuilder.buildManagedObject implementation. This is based
+ * on the org.jboss.managed.api.annotation.* package annotations.
+ * @param clazz the attachment class
+ * @param metaData - the optional metadata repository accessor used to query
+ * for management annotation overrides/additions to the clazz
+ * @return the ManagementObject if clazz is properly annotated, null if
+ * it does not have a ManagementObject annotation on the class or metaData.
+ * The BeanInfo used by this method is stored as a transient attachment
+ * under the BeanInfo.class.getName() ket.
+ */
+ @SuppressWarnings("unchecked")
+ public ManagedObject buildManagedObject(Class<?> clazz, MetaData metaData)
+ {
+ boolean trace = log.isTraceEnabled();
+ BeanInfo beanInfo = configuration.getBeanInfo(clazz);
+ ClassInfo classInfo = beanInfo.getClassInfo();
+
+ ManagementObject managementObject = getAnnotation(ManagementObject.class, classInfo, metaData);
+ if( managementObject == null )
+ {
+ if (trace)
+ log.trace("No ManagementObject annotation, skipping ManagedObject for class: "+clazz);
+ // Skip the ManagedObject creation
+ return null;
+ }
+
+ // If a targetInterface exists, rebuild the BeanInfo from that
+ Class<?> targetInterface = managementObject.targetInterface();
+ if(targetInterface != Object.class)
+ {
+ beanInfo = getBeanInfo(targetInterface);
+ classInfo = beanInfo.getClassInfo();
+ }
+ HashMap<String, Annotation> moAnnotations = new HashMap<String, Annotation>();
+ moAnnotations.put(ManagementObject.class.getName(), managementObject);
+ ManagementDeployment mnagementDeployment = getAnnotation(ManagementDeployment.class, classInfo, metaData);
+ if(mnagementDeployment != null)
+ moAnnotations.put(ManagementDeployment.class.getName(), mnagementDeployment);
+ ManagementObjectID moID = getAnnotation(ManagementObjectID.class, classInfo, metaData);
+ if (moID != null)
+ moAnnotations.put(ManagementObjectID.class.getName(), moID);
+
+ // Process the ManagementObject fields
+ boolean isRuntime = managementObject.isRuntime();
+ String name = classInfo.getName();
+ String nameType = null;
+ String attachmentName = classInfo.getName();
+ Class<? extends Fields> moFieldsFactory = null;
+ ConstraintsPopulatorFactory moCPF = null;
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> moConstraintsFactory = null;
+ Class<? extends ManagedProperty> moPropertyFactory = null;
+ if (managementObject != null)
+ {
+ name = managementObject.name();
+ if (name.length() == 0 || name.equals(ManagementConstants.GENERATED))
+ name = classInfo.getName();
+ nameType = managementObject.type();
+ if (nameType.length() == 0)
+ nameType = null;
+ attachmentName = managementObject.attachmentName();
+ if (attachmentName.length() == 0)
+ attachmentName = classInfo.getName();
+ // Check for a component specification
+ ManagementComponent mc = managementObject.componentType();
+ // Work around JBMDR-51 by checking type/subtype
+ // if (mc.equals(AnnotationDefaults.COMP_TYPE) == false)
+ if (mc.type().length() > 0 || mc.subtype().length() > 0)
+ {
+ log.debug("ManagedObject("+name+") is ManagedComponent type: "+mc);
+ moAnnotations.put(ManagementComponent.class.getName(), mc);
+ }
+ // ManagementObject level default factory classes
+ FieldsFactory ff = getAnnotation(FieldsFactory.class, classInfo, metaData);
+ if(ff != null)
+ moFieldsFactory = ff.value();
+ moCPF = getAnnotation(ConstraintsPopulatorFactory.class, classInfo, metaData);
+ if(moCPF != null)
+ moConstraintsFactory = moCPF.value();
+ ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, classInfo, metaData);
+ if(mpf != null)
+ moPropertyFactory = mpf.value();
+ }
+
+ if (trace)
+ {
+ log.trace("Building MangedObject(name="+name+",nameType="+nameType
+ +",attachmentName="+attachmentName+",isRuntime="+isRuntime+")");
+ }
+
+ ManagementProperties propertyType = ManagementProperties.ALL;
+ Set<String> classProperties = null;
+ if (managementObject != null)
+ {
+ propertyType = managementObject.properties();
+ if(propertyType == ManagementProperties.CLASS || propertyType == ManagementProperties.CLASS_AND_EXPLICIT)
+ {
+ classProperties = new HashSet<String>();
+ for(ManagementProperty mp : managementObject.classProperties())
+ {
+ if(mp.name().length() > 0)
+ classProperties.add(mp.name());
+ if(mp.mappedName().length() > 0)
+ classProperties.add(mp.mappedName());
+ }
+ }
+ }
+
+ // Build the ManagedProperties
+ Set<ManagedProperty> properties = new HashSet<ManagedProperty>();
+
+ Set<PropertyInfo> propertyInfos = beanInfo.getProperties();
+ if (propertyInfos != null && propertyInfos.isEmpty() == false)
+ {
+ for (PropertyInfo propertyInfo : propertyInfos)
+ {
+ // Ignore the "class" property
+ if ("class".equals(propertyInfo.getName()))
+ continue;
+
+ ManagementProperty managementProperty = getAnnotation(ManagementProperty.class, propertyInfo, metaData);
+ ManagementObjectID id = getAnnotation(ManagementObjectID.class, propertyInfo, metaData);
+ ManagementObjectRef ref = getAnnotation(ManagementObjectRef.class, propertyInfo, metaData);
+ ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, propertyInfo, metaData);
+ RunStateProperty rsp = getAnnotation(RunStateProperty.class, propertyInfo, metaData);
+ HashMap<String, Annotation> propAnnotations = new HashMap<String, Annotation>();
+ if (managementProperty != null)
+ propAnnotations.put(ManagementProperty.class.getName(), managementProperty);
+ if (id != null)
+ {
+ propAnnotations.put(ManagementObjectID.class.getName(), id);
+ // This overrides the MO nameType
+ nameType = id.type();
+ }
+ if (ref != null)
+ propAnnotations.put(ManagementObjectRef.class.getName(), ref);
+ if (runtimeRef != null)
+ propAnnotations.put(ManagementRuntimeRef.class.getName(), runtimeRef);
+ if (rsp != null)
+ propAnnotations.put(RunStateProperty.class.getName(), rsp);
+
+ // Check whether this property should be included
+ boolean includeProperty = false;
+ switch(propertyType)
+ {
+ // Only if the property as a ManagementProperty
+ case EXPLICIT:
+ includeProperty = managementProperty != null &&
+ (managementProperty.ignored() == false);
+ break;
+ // Only if the property is listed in the classProperties
+ case CLASS:
+ includeProperty = classProperties.contains(propertyInfo.getName());
+ break;
+ // Only if the property is listed in the classProperties
+ case CLASS_AND_EXPLICIT:
+ includeProperty = classProperties.contains(propertyInfo.getName())
+ || (managementProperty != null && managementProperty.ignored() == false);
+ break;
+ // Any property that is not ignored
+ case ALL:
+ includeProperty = managementProperty == null
+ || managementProperty.ignored() == false;
+ break;
+ }
+
+ if (includeProperty)
+ {
+ Fields fields = null;
+ Class<? extends Fields> factory = moFieldsFactory;
+ FieldsFactory ff = getAnnotation(FieldsFactory.class, propertyInfo, metaData);
+ if(ff != null)
+ factory = ff.value();
+ if (factory != null)
+ {
+ try
+ {
+ fields = factory.newInstance();
+ }
+ catch (Exception e)
+ {
+ log.debug("Failed to created Fields", e);
+ }
+ }
+ if (fields == null)
+ fields = new DefaultFieldsImpl();
+
+ if( propertyInfo instanceof Serializable )
+ {
+ Serializable info = Serializable.class.cast(propertyInfo);
+ fields.setField(Fields.PROPERTY_INFO, info);
+ }
+
+ String propertyName = propertyInfo.getName();
+ if (managementProperty != null)
+ propertyName = managementProperty.name();
+ if( propertyName.length() == 0 )
+ propertyName = propertyInfo.getName();
+ fields.setField(Fields.NAME, propertyName);
+
+ // This should probably always the the propertyInfo name?
+ String mappedName = propertyInfo.getName();
+ if (managementProperty != null)
+ mappedName = managementProperty.mappedName();
+ if( mappedName.length() == 0 )
+ mappedName = propertyInfo.getName();
+ fields.setField(Fields.MAPPED_NAME, mappedName);
+
+ String description = ManagementConstants.GENERATED;
+ if (managementProperty != null)
+ description = managementProperty.description();
+ if (description.equals(ManagementConstants.GENERATED))
+ description = propertyName;
+ fields.setField(Fields.DESCRIPTION, description);
+
+ if (trace)
+ {
+ log.trace("Building MangedProperty(name="+propertyName
+ +",mappedName="+mappedName
+ +") ,annotations="+propAnnotations);
+ }
+
+ boolean mandatory = false;
+ if (managementProperty != null)
+ mandatory = managementProperty.mandatory();
+ if (mandatory)
+ fields.setField(Fields.MANDATORY, Boolean.TRUE);
+
+ boolean managed = false;
+ if (managementProperty != null)
+ managed = managementProperty.managed();
+
+ // The managed property type
+ MetaType metaType = null;
+ MetaMapper<?> metaMapper = null;
+ MetaMapping metaMapping = getAnnotation(MetaMapping.class, propertyInfo, metaData);
+ MetaMappingFactory metaMappingFactory = getAnnotation(MetaMappingFactory.class, propertyInfo, metaData);
+ if(metaMappingFactory != null)
+ {
+ Class<? extends MetaMapperFactory<?>> mmfClass = metaMappingFactory.value();
+ try
+ {
+ MetaMapperFactory<?> mmf = mmfClass.newInstance();
+ String[] args = metaMappingFactory.args();
+ if(args.length > 0)
+ metaMapper = mmf.newInstance(args);
+ else
+ metaMapper = mmf.newInstance();
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create MetaMapperFactory: "+metaMappingFactory, e);
+ }
+ }
+ if(metaMapping != null)
+ {
+ // Use the mapping for the type
+ Class<? extends MetaMapper<?>> mapperClass = metaMapping.value();
+ try
+ {
+ metaMapper = mapperClass.newInstance();
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to create MetaMapper: "+metaMapping, e);
+ }
+ }
+ if(metaMapper != null)
+ metaType = metaMapper.getMetaType();
+
+ // Determine meta type based on property type
+ if(metaType == null)
+ {
+ if (managed)
+ {
+ TypeInfo typeInfo = propertyInfo.getType();
+ if(typeInfo.isArray())
+ metaType = new ArrayMetaType(1, MANAGED_OBJECT_META_TYPE);
+ else if (typeInfo.isCollection())
+ metaType = new CollectionMetaType(typeInfo.getName(), MANAGED_OBJECT_META_TYPE);
+ else
+ metaType = MANAGED_OBJECT_META_TYPE;
+ }
+ else
+ {
+ metaType = metaTypeFactory.resolve(propertyInfo.getType());
+ }
+ }
+ fields.setField(Fields.META_TYPE, metaType);
+ // Property annotations
+ if (propAnnotations.isEmpty() == false)
+ fields.setField(Fields.ANNOTATIONS, propAnnotations);
+
+ // Delegate others (legal values, min/max etc.) to the constraints factory
+ try
+ {
+ Class<? extends ManagedPropertyConstraintsPopulatorFactory> factoryClass = moConstraintsFactory;
+ ConstraintsPopulatorFactory cpf = getAnnotation(ConstraintsPopulatorFactory.class, propertyInfo, metaData);
+ if(cpf != null)
+ factoryClass = cpf.value();
+ else
+ cpf = moCPF;
+ if(factoryClass != null)
+ {
+ ManagedPropertyConstraintsPopulatorFactory mpcpf = factoryClass.newInstance();
+ ManagedPropertyConstraintsPopulator populator = mpcpf.newInstance(cpf.min(), cpf.max(), cpf.legalValues(), cpf.args());
+ if (populator != null)
+ populator.populateManagedProperty(clazz, propertyInfo, fields);
+ }
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to populate constraints for: "+propertyInfo, e);
+ }
+
+ ManagedProperty property = null;
+ Class<? extends ManagedProperty> mpClass = moPropertyFactory;
+ ManagementPropertyFactory mpf = getAnnotation(ManagementPropertyFactory.class, propertyInfo, metaData);
+ if (mpf != null)
+ mpClass = mpf.value();
+ if (mpClass != null)
+ property = getManagedProperty(mpClass, fields);
+ // we should have write-through by default
+ // use factory to change this default behavior
+ if (property == null)
+ property = createDefaultManagedProperty(fields);
+ // Pass the MetaMapper as an attachment
+ if(metaMapper != null)
+ property.setTransientAttachment(MetaMapper.class.getName(), metaMapper);
+ properties.add(property);
+ }
+ else if (trace)
+ log.trace("Ignoring property: " + propertyInfo);
+ }
+ }
+
+ /* TODO: Operations. In general the bean metadata does not contain
+ operation information.
+ */
+ Set<ManagedOperation> operations = new HashSet<ManagedOperation>();
+
+ Set<MethodInfo> methodInfos = beanInfo.getMethods();
+ if (methodInfos != null && methodInfos.isEmpty() == false)
+ {
+ for (MethodInfo methodInfo : methodInfos)
+ {
+ ManagementOperation managementOp = getAnnotation(ManagementOperation.class, methodInfo, metaData);
+ if (managementOp == null)
+ continue;
+
+ ManagedOperation op = getManagedOperation(methodInfo, managementOp);
+ operations.add(op);
+ }
+ }
+
+ ManagedObjectImpl result = new ManagedObjectImpl(name, properties);
+ result.setAnnotations(moAnnotations);
+ // Set the component name to name if this is a runtime MO with a name specified
+ if (isRuntime && name.equals(classInfo.getName()) == false)
+ result.setComponentName(name);
+ if (nameType != null)
+ result.setNameType(nameType);
+ if (attachmentName != null)
+ result.setAttachmentName(attachmentName);
+ if (operations.size() > 0 )
+ result.setOperations(operations);
+ for (ManagedProperty property : properties)
+ property.setManagedObject(result);
+ result.setTransientAttachment(BeanInfo.class.getName(), beanInfo);
+ return result;
+ }
+
+ /**
+ * Create default MangedProperty instance.
+ * Override this method for different default.
+ *
+ * @param fields the fields
+ * @return new ManagedProperty instance
+ */
+ protected ManagedProperty createDefaultManagedProperty(Fields fields)
+ {
+ return new WritethroughManagedPropertyImpl(fields, metaValueFactory, this);
+ }
+
+ /**
+ * Get the property name.
+ *
+ * @param property managed property
+ * @return property name
+ */
+ protected String getPropertyName(ManagedProperty property)
+ {
+ // First look to the mapped name
+ String name = property.getMappedName();
+ if (name == null)
+ property.getName();
+ return name;
+ }
+
+ /**
+ *
+ * @param methodInfo
+ * @param opAnnotation
+ * @return the managed operation
+ */
+ protected ManagedOperation getManagedOperation(MethodInfo methodInfo, ManagementOperation opAnnotation)
+ {
+ String name = methodInfo.getName();
+ String description = opAnnotation.description();
+ Impact impact = opAnnotation.impact();
+ ManagementParameter[] params = opAnnotation.params();
+ ParameterInfo[] paramInfo = methodInfo.getParameters();
+ TypeInfo returnInfo = methodInfo.getReturnType();
+ MetaType returnType = metaTypeFactory.resolve(returnInfo);
+ ArrayList<ManagedParameter> mparams = new ArrayList<ManagedParameter>();
+ Class<? extends ManagedParameterConstraintsPopulatorFactory> opConstraintsFactor = opAnnotation.constraintsFactory();
+
+ if( paramInfo != null )
+ {
+ for(int i = 0; i < paramInfo.length; i ++)
+ {
+ ParameterInfo pinfo = paramInfo[i];
+ String pname = pinfo.getName();
+ String pdescription = null;
+ ManagementParameter mpa = null;
+ // Look to ManagementParameter for info
+ if (i < params.length)
+ {
+ mpa = params[i];
+ if (mpa.name().equals(AnnotationDefaults.EMPTY_STRING) == false)
+ pname = mpa.name();
+ if (mpa.description().equals(AnnotationDefaults.EMPTY_STRING) == false)
+ pdescription = mpa.description();
+ }
+ // Generate a name if there is none
+ if (pname == null)
+ pname = "arg#" + i;
+ Fields fields = new DefaultFieldsImpl(pname);
+ if (pdescription != null)
+ fields.setField(Fields.DESCRIPTION, pdescription);
+ MetaType metaType = metaTypeFactory.resolve(pinfo.getParameterType());
+ fields.setField(Fields.META_TYPE, metaType);
+ // Delegate others (legal values, min/max etc.) to the constraints factory
+ try
+ {
+ Class<? extends ManagedParameterConstraintsPopulatorFactory> factoryClass = opConstraintsFactor;
+ if (factoryClass == ManagementParameter.NULL_CONSTRAINTS.class)
+ {
+ if (mpa != null)
+ factoryClass = mpa.constraintsFactory();
+ }
+ ManagedParameterConstraintsPopulatorFactory factory = factoryClass.newInstance();
+ ManagedParameterConstraintsPopulator populator = factory.newInstance();
+ if (populator != null)
+ populator.populateManagedParameter(name, pinfo, fields);
+ }
+ catch(Exception e)
+ {
+ log.debug("Failed to populate constraints for: "+pinfo, e);
+ }
+
+ ManagedParameterImpl mp = new ManagedParameterImpl(fields);
+ mparams.add(mp);
+ }
+ }
+ ManagedParameter[] parameters = new ManagedParameter[mparams.size()];
+ mparams.toArray(parameters);
+
+ return new ManagedOperationImpl(name, description, impact, parameters, returnType);
+ }
+
+ /**
+ * Get the builder for a class
+ *
+ * @param clazz the class
+ * @return the builder
+ */
+ protected ManagedObjectBuilder getBuilder(Class<?> clazz)
+ {
+ synchronized (builders)
+ {
+ ManagedObjectBuilder builder = builders.get(clazz);
+ if (builder != null)
+ return builder;
+ }
+ return this;
+ }
+
+ /**
+ * Get the instance factory for a class
+ *
+ * @param clazz the class
+ * @return the InstanceClassFactory
+ */
+ @SuppressWarnings("unchecked")
+ public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz,
+ MetaData metaData)
+ {
+ InstanceClassFactory defaultFactory = defaultInstanceFactory;
+ if(metaData != null)
+ {
+ InstanceClassFactory mdrFactory = metaData.getMetaData(InstanceClassFactory.class);
+ if(mdrFactory != null)
+ defaultFactory = mdrFactory;
+ }
+ InstanceClassFactory<X> factory = (InstanceClassFactory<X>)
+ Utility.getInstanceClassFactory(clazz, instanceFactories,
+ defaultFactory);
+ return factory;
+ }
+
+ /**
+ * Get the populator for a class
+ *
+ * @param clazz the class
+ * @return the populator
+ */
+ @SuppressWarnings("unchecked")
+ protected <X> ManagedObjectPopulator<X> getPopulator(Class<X> clazz)
+ {
+ ManagedObjectBuilder builder = getBuilder(clazz);
+ if (builder instanceof ManagedObjectPopulator)
+ return (ManagedObjectPopulator) builder;
+ ManagedObjectPopulator<X> mop = (ManagedObjectPopulator<X>) defaultManagedObjectPopulator;
+ return mop;
+ }
+
+ protected Collection<?> getAsCollection(Object value)
+ {
+ if( value.getClass().isArray() )
+ return Arrays.asList(value);
+ else if (value instanceof Collection)
+ return Collection.class.cast(value);
+ return null;
+ }
+
+ /**
+ * Look for ctor(Fields)
+ * @param factory - the ManagedProperty implementation class
+ * @param fields - the fields to pass to the ctor
+ * @return the managed property
+ */
+ protected ManagedProperty getManagedProperty(Class<? extends ManagedProperty> factory, Fields fields)
+ {
+ return createManagedProperty(factory, fields);
+ }
+
+ protected <X extends Annotation> X getAnnotation(Class<X> annotationType,
+ AnnotatedInfo info, MetaData metaData)
+ {
+ X annotation = null;
+ if(metaData != null)
+ {
+ annotation = metaData.getAnnotation(annotationType);
+ if(annotation == null && info instanceof MethodInfo)
+ {
+ MethodInfo mi = (MethodInfo) info;
+ Signature mis = Signature.getSignature(mi);
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if (annotation == null && info instanceof PropertyInfo)
+ {
+ PropertyInfo pi = (PropertyInfo) info;
+ if(pi.getGetter() != null)
+ {
+ Signature mis = new MethodSignature(pi.getGetter());
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if(annotation == null && pi.getSetter() != null)
+ {
+ Signature mis = new MethodSignature(pi.getSetter());
+ MetaData imetaData = metaData.getComponentMetaData(mis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ if(annotation == null && pi.getFieldInfo() != null)
+ {
+ Signature fis = new FieldSignature(pi.getFieldInfo());
+ MetaData imetaData = metaData.getComponentMetaData(fis);
+ if (imetaData != null)
+ annotation = imetaData.getAnnotation(annotationType);
+ }
+ }
+ if(annotation != null)
+ log.trace("Loaded "+annotationType+" from MetaData");
+ }
+ if(annotation == null)
+ annotation = info.getUnderlyingAnnotation(annotationType);
+ return annotation;
+ }
+
+ /**
+ * Build up a BeanInfo from the interface class and all interfaces it
+ * implements.
+ *
+ * @param iface - the interface for the managed object
+ * @return the full BeanInfo for the iface
+ */
+ protected BeanInfo getBeanInfo(Class<?> iface)
+ {
+ BeanInfo ifaceBI = configuration.getBeanInfo(iface);
+ Class<?>[] superIfaces = iface.getInterfaces();
+ if(superIfaces != null && superIfaces.length > 0)
+ {
+ // Combine all properties
+ Set<PropertyInfo> allProps = new HashSet<PropertyInfo>(ifaceBI.getProperties());
+ // Combine all operations
+ Set<MethodInfo> allMethods = new HashSet<MethodInfo>(ifaceBI.getMethods());
+ for(Class<?> superIface : superIfaces)
+ {
+ BeanInfo cBI = configuration.getBeanInfo(superIface);
+ Set<PropertyInfo> props = cBI.getProperties();
+ if(props != null)
+ allProps.addAll(props);
+ Set<MethodInfo> methods = cBI.getMethods();
+ if(methods != null)
+ allMethods.addAll(methods);
+ }
+
+ ifaceBI.setProperties(allProps);
+ ifaceBI.setMethods(allMethods);
+ }
+ return ifaceBI;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,258 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.factory;
-
-import java.lang.annotation.Annotation;
-import java.util.Map;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.config.spi.Configuration;
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.Fields;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.MutableManagedObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementRuntimeRef;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.managed.spi.factory.ManagedObjectPopulator;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * A default ManagedObjectPopulator implementation that relies on mc configuration
- * for obtaining BeanInfos for a class, and InstanceClassFactorys for
- * class, name and values from a value to be managed.
- *
- * @param <T> the type to populate
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class AbstractManagedObjectPopulator<T>
- implements ManagedObjectPopulator<T>
-{
- private static Logger log = Logger.getLogger(AbstractManagedObjectPopulator.class);
-
- /** The configuration */
- private Configuration configuration;
- private InstanceClassFactory<?> defaultInstanceFactory;
- /** The instance to class factories */
- private Map<Class<?>, InstanceClassFactory<?>> instanceFactories;
-
-
- public AbstractManagedObjectPopulator(Configuration configuration)
- {
- this(configuration, null, null);
- }
- public AbstractManagedObjectPopulator(
- Configuration configuration,
- InstanceClassFactory<?> defaultInstanceFactory,
- Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
- {
- super();
- this.configuration = configuration;
- this.defaultInstanceFactory = defaultInstanceFactory;
- this.instanceFactories = instanceFactories;
- }
-
- public Configuration getConfiguration()
- {
- return configuration;
- }
- public void setConfiguration(Configuration configuration)
- {
- this.configuration = configuration;
- }
-
- public InstanceClassFactory<?> getDefaultInstanceFactory()
- {
- return defaultInstanceFactory;
- }
- public void setDefaultInstanceFactory(InstanceClassFactory<?> defaultInstanceFactory)
- {
- this.defaultInstanceFactory = defaultInstanceFactory;
- }
-
- public Map<Class<?>, InstanceClassFactory<?>> getInstanceFactories()
- {
- return instanceFactories;
- }
- public void setInstanceFactories(Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
- {
- this.instanceFactories = instanceFactories;
- }
-
- public void createObject(ManagedObject managedObject, Class<T> clazz)
- {
- createObject(managedObject, clazz, null);
- }
- public void createObject(ManagedObject managedObject, Class<T> clazz, MetaData metaData)
- {
- if (managedObject == null)
- throw new IllegalArgumentException("Null managed object");
-
- if (managedObject instanceof MutableManagedObject == false)
- throw new IllegalStateException("Unable to create object " + managedObject.getClass().getName());
-
- MutableManagedObject managedObjectImpl = (MutableManagedObject) managedObject;
- T object = createUnderlyingObject(managedObjectImpl, clazz);
- populateManagedObject(managedObjectImpl, object, null);
- }
-
- public void populateManagedObject(MutableManagedObject managedObject, T object)
- {
- populateManagedObject(managedObject, object);
- }
- public void populateManagedObject(MutableManagedObject managedObject, T object,
- MetaData metaData)
- {
- managedObject.setAttachment(object);
- populateValues(managedObject, object, metaData);
- }
-
- /**
- * Get the instance factory for a class
- *
- * @param <T> the class to get an instance factory for
- * @param clazz the class
- * @return the InstanceClassFactory
- */
- @SuppressWarnings("unchecked")
- public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz, MetaData metaData)
- {
- InstanceClassFactory<X> factory = (InstanceClassFactory<X>)
- Utility.getInstanceClassFactory(clazz, instanceFactories,
- defaultInstanceFactory, metaData);
- return factory;
- }
-
- /**
- * Create the underlying object
- *
- * @param managedObject the managed object
- * @param clazz the class
- * @return the object
- */
- protected T createUnderlyingObject(MutableManagedObject managedObject, Class<T> clazz)
- {
- BeanInfo beanInfo = configuration.getBeanInfo(clazz);
- try
- {
- Object result = beanInfo.newInstance();
- return clazz.cast(result);
- }
- catch (Throwable t)
- {
- throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazz, t);
- }
- }
-
- /**
- * Populate the values
- *
- * @param managedObject the managed object
- * @param object the object
- */
- @SuppressWarnings("unchecked")
- protected void populateValues(MutableManagedObject managedObject, T object,
- MetaData metaData)
- {
- InstanceClassFactory icf = getInstanceClassFactory(object.getClass(), metaData);
- Class moClass;
- try
- {
- moClass = icf.getManagedObjectClass(object);
- }
- catch(ClassNotFoundException e)
- {
- throw new IllegalStateException(e);
- }
- BeanInfo beanInfo = configuration.getBeanInfo(moClass);
-
- Object componentName = null;
- Map<String, ManagedProperty> properties = managedObject.getProperties();
- if (properties != null && properties.size() > 0)
- {
- for (ManagedProperty property : properties.values())
- {
- MetaValue value = null;
- try
- {
- value = icf.getValue(beanInfo, property, metaData, object);
- }
- catch(Throwable t)
- {
- if(log.isTraceEnabled())
- log.trace("Failed to access value for property: "+property, t);
- }
-
- if (value != null)
- property.setField(Fields.VALUE, value);
- /* Need to look for a ManagementObjectID at the property level which
- defines the ManagedObject id name from the property value.
- */
- Map<String, Annotation> annotations = property.getAnnotations();
- if (annotations == null && metaData == null)
- continue;
-
- ManagementObjectID id = getAnnotation(ManagementObjectID.class, annotations, metaData);
- if (id != null)
- {
- if (value == null || value.getMetaType().isSimple() == false)
- {
- log.warn("Cannot create String name from non-Simple property: " + property + ", value=" + value);
- continue;
- }
- SimpleValue svalue = (SimpleValue) value;
- String name = "" + svalue.getValue();
- managedObject.setName(name);
- }
- ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, annotations, metaData);
- if (runtimeRef != null)
- {
- componentName = icf.getComponentName(beanInfo, property, object, value);
- if(componentName == null && defaultInstanceFactory != null)
- {
- InstanceClassFactory dicf = defaultInstanceFactory;
- componentName = dicf.getComponentName(beanInfo, property, object, value);
- }
- }
- }
- }
- if (componentName == null)
- componentName = icf.getComponentName(null, null, object, null);
- // set it, even if it's null
- managedObject.setComponentName(componentName);
- }
-
- private static <X extends Annotation> X getAnnotation(Class<X> clazz, Map<String, Annotation> annotations,
- MetaData metaData)
- {
- X annotation = null;
- if(metaData != null)
- annotation = metaData.getAnnotation(clazz);
- if(annotation == null && annotations != null)
- annotation = (X) annotations.get(clazz.getName());
- return annotation;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/AbstractManagedObjectPopulator.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,263 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.factory;
+
+import java.lang.annotation.Annotation;
+import java.util.Map;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.config.spi.Configuration;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.MutableManagedObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementRuntimeRef;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.managed.spi.factory.ManagedObjectPopulator;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * A default ManagedObjectPopulator implementation that relies on mc configuration
+ * for obtaining BeanInfos for a class, and InstanceClassFactorys for
+ * class, name and values from a value to be managed.
+ *
+ * @param <T> the type to populate
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractManagedObjectPopulator<T>
+ implements ManagedObjectPopulator<T>
+{
+ private static Logger log = Logger.getLogger(AbstractManagedObjectPopulator.class);
+
+ /** The configuration */
+ private Configuration configuration;
+ private InstanceClassFactory<?> defaultInstanceFactory;
+ /** The instance to class factories */
+ private Map<Class<?>, InstanceClassFactory<?>> instanceFactories;
+
+
+ public AbstractManagedObjectPopulator(Configuration configuration)
+ {
+ this(configuration, null, null);
+ }
+ public AbstractManagedObjectPopulator(
+ Configuration configuration,
+ InstanceClassFactory<?> defaultInstanceFactory,
+ Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
+ {
+ super();
+ this.configuration = configuration;
+ this.defaultInstanceFactory = defaultInstanceFactory;
+ this.instanceFactories = instanceFactories;
+ }
+
+ public Configuration getConfiguration()
+ {
+ return configuration;
+ }
+ public void setConfiguration(Configuration configuration)
+ {
+ this.configuration = configuration;
+ }
+
+ public InstanceClassFactory<?> getDefaultInstanceFactory()
+ {
+ return defaultInstanceFactory;
+ }
+ public void setDefaultInstanceFactory(InstanceClassFactory<?> defaultInstanceFactory)
+ {
+ this.defaultInstanceFactory = defaultInstanceFactory;
+ }
+
+ public Map<Class<?>, InstanceClassFactory<?>> getInstanceFactories()
+ {
+ return instanceFactories;
+ }
+ public void setInstanceFactories(Map<Class<?>, InstanceClassFactory<?>> instanceFactories)
+ {
+ this.instanceFactories = instanceFactories;
+ }
+
+ public void createObject(ManagedObject managedObject, Class<T> clazz)
+ {
+ createObject(managedObject, clazz, null);
+ }
+ public void createObject(ManagedObject managedObject, Class<T> clazz, MetaData metaData)
+ {
+ if (managedObject == null)
+ throw new IllegalArgumentException("Null managed object");
+
+ if (managedObject instanceof MutableManagedObject == false)
+ throw new IllegalStateException("Unable to create object " + managedObject.getClass().getName());
+
+ MutableManagedObject managedObjectImpl = (MutableManagedObject) managedObject;
+ T object = createUnderlyingObject(managedObjectImpl, clazz);
+ populateManagedObject(managedObjectImpl, object, null);
+ }
+
+ public void populateManagedObject(MutableManagedObject managedObject, T object)
+ {
+ populateManagedObject(managedObject, object);
+ }
+ public void populateManagedObject(MutableManagedObject managedObject, T object,
+ MetaData metaData)
+ {
+ managedObject.setAttachment(object);
+ populateValues(managedObject, object, metaData);
+ }
+
+ /**
+ * Get the instance factory for a class
+ *
+ * @param <T> the class to get an instance factory for
+ * @param clazz the class
+ * @return the InstanceClassFactory
+ */
+ @SuppressWarnings("unchecked")
+ public <X> InstanceClassFactory<X> getInstanceClassFactory(Class<X> clazz, MetaData metaData)
+ {
+ InstanceClassFactory<X> factory = (InstanceClassFactory<X>)
+ Utility.getInstanceClassFactory(clazz, instanceFactories,
+ defaultInstanceFactory, metaData);
+ return factory;
+ }
+
+ /**
+ * Create the underlying object
+ *
+ * @param managedObject the managed object
+ * @param clazz the class
+ * @return the object
+ */
+ protected T createUnderlyingObject(MutableManagedObject managedObject, Class<T> clazz)
+ {
+ BeanInfo beanInfo = configuration.getBeanInfo(clazz);
+ try
+ {
+ Object result = beanInfo.newInstance();
+ return clazz.cast(result);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Unable to create new object for " + managedObject + " clazz=" + clazz, t);
+ }
+ }
+
+ /**
+ * Populate the values
+ *
+ * @param managedObject the managed object
+ * @param object the object
+ */
+ @SuppressWarnings("unchecked")
+ protected void populateValues(MutableManagedObject managedObject, T object,
+ MetaData metaData)
+ {
+ InstanceClassFactory icf = getInstanceClassFactory(object.getClass(), metaData);
+ Class moClass;
+ try
+ {
+ moClass = icf.getManagedObjectClass(object);
+ }
+ catch(ClassNotFoundException e)
+ {
+ throw new IllegalStateException(e);
+ }
+
+ BeanInfo beanInfo = managedObject.getTransientAttachment(BeanInfo.class);
+ if(beanInfo == null)
+ beanInfo = configuration.getBeanInfo(moClass);
+
+ Object componentName = null;
+ Map<String, ManagedProperty> properties = managedObject.getProperties();
+ if (properties != null && properties.size() > 0)
+ {
+ for (ManagedProperty property : properties.values())
+ {
+ MetaValue value = null;
+ try
+ {
+ value = icf.getValue(beanInfo, property, metaData, object);
+ }
+ catch(Throwable t)
+ {
+ if(log.isTraceEnabled())
+ log.trace("Failed to access value for property: "+property, t);
+ }
+
+ if (value != null)
+ property.setField(Fields.VALUE, value);
+ /* Need to look for a ManagementObjectID at the property level which
+ defines the ManagedObject id name from the property value.
+ */
+ Map<String, Annotation> annotations = property.getAnnotations();
+ if (annotations == null && metaData == null)
+ continue;
+
+ ManagementObjectID id = getAnnotation(ManagementObjectID.class, annotations, metaData);
+ if (id != null)
+ {
+ if (value == null || value.getMetaType().isSimple() == false)
+ {
+ log.warn("Cannot create String name from non-Simple property: " + property + ", value=" + value);
+ continue;
+ }
+ SimpleValue svalue = (SimpleValue) value;
+ String name = id.prefix() + svalue.getValue() + id.suffix();
+ log.debug("Created name: "+name+" from property: "+property.getName());
+ managedObject.setName(name);
+ }
+ ManagementRuntimeRef runtimeRef = getAnnotation(ManagementRuntimeRef.class, annotations, metaData);
+ if (runtimeRef != null)
+ {
+ componentName = icf.getComponentName(beanInfo, property, object, value);
+ if(componentName == null && defaultInstanceFactory != null)
+ {
+ InstanceClassFactory dicf = defaultInstanceFactory;
+ componentName = dicf.getComponentName(beanInfo, property, object, value);
+ }
+ }
+ }
+ }
+ if (componentName == null)
+ componentName = icf.getComponentName(null, null, object, null);
+ // set it, even if it's null, but not if its already been set
+ if (managedObject.getComponentName() == null)
+ managedObject.setComponentName(componentName);
+ }
+
+ private static <X extends Annotation> X getAnnotation(Class<X> clazz, Map<String, Annotation> annotations,
+ MetaData metaData)
+ {
+ X annotation = null;
+ if(metaData != null)
+ annotation = metaData.getAnnotation(clazz);
+ if(annotation == null && annotations != null)
+ annotation = (X) annotations.get(clazz.getName());
+ return annotation;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,108 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.factory;
-
-import java.util.Map;
-
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metadata.spi.MetaData;
-
-/**
- * Common untility methods used by the factory plugins.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
-public class Utility
-{
- /**
- * Get the instance factory for a class
- *
- * @param clazz the class
- * @param instanceFactories - the registered mapping of classes to InstanceClassFactorys
- * @param defaultInstanceFactory - the default InstanceClassFactory to use
- * if no class match is found.
- * @return the InstanceClassFactory
- */
- @SuppressWarnings("unchecked")
- public static InstanceClassFactory getInstanceClassFactory(Class<?> clazz,
- Map<Class<?>, InstanceClassFactory<?>> instanceFactories,
- InstanceClassFactory defaultInstanceFactory)
- {
- return getInstanceClassFactory(clazz, instanceFactories, defaultInstanceFactory, null);
- }
- /**
- * Get the instance factory for a class
- *
- * @param clazz the class
- * @param instanceFactories - the registered mapping of classes to InstanceClassFactorys
- * @param defaultInstanceFactory - the default InstanceClassFactory to use
- * if no class match is found.
- * @param metaData - the possibly null metdata repository accessor. Its used to
- * query for an mdr InstanceClassFactory.class as an override to the defaultInstanceFactory
- * @return the InstanceClassFactory
- */
- @SuppressWarnings("unchecked")
- public static InstanceClassFactory getInstanceClassFactory(Class<?> clazz,
- Map<Class<?>, InstanceClassFactory<?>> instanceFactories,
- InstanceClassFactory defaultInstanceFactory, MetaData metaData)
- {
- InstanceClassFactory defaultFactory = defaultInstanceFactory;
- if(metaData != null)
- {
- InstanceClassFactory mdrFactory = metaData.getMetaData(InstanceClassFactory.class);
- if(mdrFactory != null)
- defaultFactory = mdrFactory;
- }
-
- synchronized (instanceFactories)
- {
- Class<?> c = clazz;
- InstanceClassFactory factory = instanceFactories.get(c);
- while(factory == null && c != null && c != Object.class)
- {
- // First check for interfaces
- Class<?>[] ifaces = c.getInterfaces();
- if(ifaces != null)
- {
- for(Class<?> i : ifaces)
- {
- factory = instanceFactories.get(i);
- if(factory != null)
- break;
- }
- }
- // Next look at superclasses
- if(factory == null)
- {
- c = c.getSuperclass();
- factory = instanceFactories.get(c);
- }
- }
- if (factory != null)
- return factory;
- }
- InstanceClassFactory factory = defaultFactory;
- return factory;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java (from rev 84389, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/factory/Utility.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.factory;
+
+import java.util.Map;
+
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metadata.spi.MetaData;
+
+/**
+ * Common utility methods used by the factory plugins.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class Utility
+{
+ /**
+ * Get the instance factory for a class
+ *
+ * @param clazz the class
+ * @param instanceFactories - the registered mapping of classes to InstanceClassFactorys
+ * @param defaultInstanceFactory - the default InstanceClassFactory to use
+ * if no class match is found.
+ * @return the InstanceClassFactory
+ */
+ @SuppressWarnings("unchecked")
+ public static InstanceClassFactory getInstanceClassFactory(Class<?> clazz,
+ Map<Class<?>, InstanceClassFactory<?>> instanceFactories,
+ InstanceClassFactory defaultInstanceFactory)
+ {
+ return getInstanceClassFactory(clazz, instanceFactories, defaultInstanceFactory, null);
+ }
+ /**
+ * Get the instance factory for a class
+ *
+ * @param clazz the class
+ * @param instanceFactories - the registered mapping of classes to InstanceClassFactorys
+ * @param defaultInstanceFactory - the default InstanceClassFactory to use
+ * if no class match is found.
+ * @param metaData - the possibly null metdata repository accessor. Its used to
+ * query for an mdr InstanceClassFactory.class as an override to the defaultInstanceFactory
+ * @return the InstanceClassFactory
+ */
+ @SuppressWarnings("unchecked")
+ public static InstanceClassFactory getInstanceClassFactory(Class<?> clazz,
+ Map<Class<?>, InstanceClassFactory<?>> instanceFactories,
+ InstanceClassFactory defaultInstanceFactory, MetaData metaData)
+ {
+ InstanceClassFactory defaultFactory = defaultInstanceFactory;
+ if(metaData != null)
+ {
+ InstanceClassFactory mdrFactory = metaData.getMetaData(InstanceClassFactory.class);
+ if(mdrFactory != null)
+ defaultFactory = mdrFactory;
+ }
+
+ synchronized (instanceFactories)
+ {
+ Class<?> c = clazz;
+ InstanceClassFactory factory = instanceFactories.get(c);
+ while(factory == null && c != null && c != Object.class)
+ {
+ // First check for interfaces
+ Class<?>[] ifaces = c.getInterfaces();
+ if(ifaces != null)
+ {
+ for(Class<?> i : ifaces)
+ {
+ factory = instanceFactories.get(i);
+ if(factory != null)
+ break;
+ }
+ }
+ // Next look at superclasses
+ if(factory == null)
+ {
+ c = c.getSuperclass();
+ factory = instanceFactories.get(c);
+ }
+ }
+ if (factory != null)
+ return factory;
+ }
+ InstanceClassFactory factory = defaultFactory;
+ return factory;
+ }
+
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx (from rev 84399, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx)
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ClassLoadingMXBean;
-import java.lang.management.ManagementFactory;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the ClassLoadingMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(name=ManagementFactory.CLASS_LOADING_MXBEAN_NAME,
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=ClassLoadingMXBean.class)
-public class ClassLoadingMXBeanMO implements ClassLoadingMXBean
-{
- @ManagementProperty(description="the number of currently loaded classes.")
- public int getLoadedClassCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the total number of classes loaded.")
- public long getTotalLoadedClassCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the total number of unloaded classes.")
- public long getUnloadedClassCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the verbose output flag for the class loading system.")
- public boolean isVerbose()
- {
- return false;
- }
-
- public void setVerbose(boolean value)
- {
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ClassLoadingMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the ClassLoadingMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(name=ManagementFactory.CLASS_LOADING_MXBEAN_NAME,
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=ClassLoadingMXBean.class)
+public class ClassLoadingMXBeanMO implements ClassLoadingMXBean
+{
+ @ManagementProperty(description="the number of currently loaded classes.")
+ public int getLoadedClassCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the total number of classes loaded.")
+ public long getTotalLoadedClassCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the total number of unloaded classes.")
+ public long getUnloadedClassCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the verbose output flag for the class loading system.")
+ public boolean isVerbose()
+ {
+ return false;
+ }
+
+ public void setVerbose(boolean value)
+ {
+ }
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/CompositeDataMetaValueBuilder.java (from rev 84828, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/CompositeDataMetaValueBuilder.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/CompositeDataMetaValueBuilder.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/CompositeDataMetaValueBuilder.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,91 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenType;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.spi.values.MetaValueBuilder;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class CompositeDataMetaValueBuilder implements MetaValueBuilder
+{
+ MetaValueFactory metaValueFactory;
+
+ public MetaValueFactory getMetaValueFactory()
+ {
+ return metaValueFactory;
+ }
+ public void setMetaValueFactory(MetaValueFactory metaValueFactory)
+ {
+ this.metaValueFactory = metaValueFactory;
+ }
+
+
+ public MetaValue buildMetaValue(MetaType metaType, Object object)
+ {
+ if((object instanceof CompositeData) == false)
+ return null;
+ CompositeData cd = (CompositeData) object;
+ CompositeType ct = cd.getCompositeType();
+ String[] itemNames = new String[ct.keySet().size()];
+ String[] itemDescriptions = new String[itemNames.length];
+ MetaValue[] itemValues = new MetaValue[itemNames.length];
+ MetaType[] itemTypes = new MetaType[itemNames.length];
+ ct.keySet().toArray(itemNames);
+ Object[] cdValues = cd.getAll(itemNames);
+ for(int n = 0; n < cdValues.length; n ++)
+ {
+ String itemName = itemNames[n];
+ Object ov = cdValues[n];
+ itemDescriptions[n] = ct.getDescription(itemName);
+ OpenType ot = ct.getType(itemName);
+ try
+ {
+ itemTypes[n] = ManagementFactoryUtils.getMetaType(ot);
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ MetaValue mv = metaValueFactory.create(ov, itemTypes[n]);
+ itemValues[n] = mv;
+ }
+
+ String typeName = ct.getTypeName();
+ String description = ct.getDescription();
+ CompositeMetaType cmt = new ImmutableCompositeMetaType(typeName, description, itemNames, itemDescriptions, itemTypes);
+ CompositeValueSupport cv = new CompositeValueSupport(cmt, itemNames, itemValues);
+ return cv;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,78 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.GarbageCollectorMXBean;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryManagerMXBean;
-import java.lang.management.RuntimeMXBean;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the RuntimeMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at ManagementObject(
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=GarbageCollectorMXBean.class)
-public class GarbageCollectorMXBeanMO implements GarbageCollectorMXBean
-{
-
- @ManagementProperty
- public long getCollectionCount()
- {
- return 0;
- }
-
- @ManagementProperty
- public long getCollectionTime()
- {
- return 0;
- }
-
- @ManagementProperty
- public String[] getMemoryPoolNames()
- {
- return null;
- }
-
- @ManagementProperty
- @ManagementObjectID(prefix=ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE)
- public String getName()
- {
- return null;
- }
-
- @ManagementProperty
- public boolean isValid()
- {
- return false;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/GarbageCollectorMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.RuntimeMXBean;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the RuntimeMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject(
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=GarbageCollectorMXBean.class)
+public class GarbageCollectorMXBeanMO implements GarbageCollectorMXBean
+{
+
+ @ManagementProperty
+ public long getCollectionCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty
+ public long getCollectionTime()
+ {
+ return 0;
+ }
+
+ @ManagementProperty
+ public String[] getMemoryPoolNames()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ @ManagementObjectID(prefix=ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE)
+ public String getName()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public boolean isValid()
+ {
+ return false;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,303 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ClassLoadingMXBean;
-import java.lang.management.GarbageCollectorMXBean;
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryMXBean;
-import java.lang.management.MemoryManagerMXBean;
-import java.lang.management.MemoryPoolMXBean;
-import java.lang.management.MemoryUsage;
-import java.lang.management.OperatingSystemMXBean;
-import java.lang.management.RuntimeMXBean;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
-import java.lang.reflect.AnnotatedElement;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-
-import javax.management.openmbean.ArrayType;
-import javax.management.openmbean.CompositeData;
-import javax.management.openmbean.CompositeDataSupport;
-import javax.management.openmbean.CompositeType;
-import javax.management.openmbean.OpenDataException;
-import javax.management.openmbean.OpenType;
-import javax.management.openmbean.SimpleType;
-
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
-import org.jboss.managed.plugins.factory.DefaultInstanceClassFactory;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.EnumMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * A utility class that created ManagedObjects for the jmx platform mbeans
- * returned by {@link java.lang.management.ManagementFactory}
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
-public class ManagementFactoryUtils
-{
- /**
- *
- * @param mof
- * @return
- */
- public static ManagedObject getClassLoadingMO(ManagedObjectFactory mof)
- {
- ClassLoadingMXBean mbean = ManagementFactory.getClassLoadingMXBean();
- ManagedObject mo = getMO(mbean, ClassLoadingMXBeanMO.class, mof);
- return mo;
- }
-
- public static ManagedObject getMemoryMXBean(ManagedObjectFactory mof)
- {
- MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
- ManagedObject mo = getMO(mbean, MemoryMXBeanMO.class, mof);
- return mo;
- }
-
- public static ManagedObject getOperatingSystemMXBean(ManagedObjectFactory mof)
- {
- OperatingSystemMXBean mbean = ManagementFactory.getOperatingSystemMXBean();
- ManagedObject mo = getMO(mbean, MemoryMXBeanMO.class, mof);
- return mo;
- }
-
- public static ManagedObject getThreadMXBean(ManagedObjectFactory mof)
- {
- ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
- ManagedObject mo = getMO(mbean, ThreadMXBeanMO.class, mof);
- return mo;
- }
-
- public static ManagedObject getRuntimeMXBean(ManagedObjectFactory mof)
- {
- RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
- ManagedObject mo = getMO(mbean, RuntimeMXBeanMO.class, mof);
- return mo;
- }
-
- public static List<ManagedObject> getMemoryManagerMXBeans(ManagedObjectFactory mof)
- {
- List<MemoryManagerMXBean> mbeans = ManagementFactory.getMemoryManagerMXBeans();
- ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
- for(MemoryManagerMXBean mbean : mbeans)
- {
- ManagedObject mo = getMO(mbean, MemoryManagerMXBeanMO.class, mof);
- mos.add(mo);
- }
- return mos;
- }
-
- public static List<ManagedObject> getGarbageCollectorMXBeans(ManagedObjectFactory mof)
- {
- List<GarbageCollectorMXBean> mbeans = ManagementFactory.getGarbageCollectorMXBeans();
- ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
- for(GarbageCollectorMXBean mbean : mbeans)
- {
- ManagedObject mo = getMO(mbean, GarbageCollectorMXBeanMO.class, mof);
- mos.add(mo);
- }
- return mos;
- }
-
- public static List<ManagedObject> getMemoryPoolMXBeans(ManagedObjectFactory mof)
- {
- List<MemoryPoolMXBean> mbeans = ManagementFactory.getMemoryPoolMXBeans();
- ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
- for(MemoryPoolMXBean mbean : mbeans)
- {
- ManagedObject mo = getMO(mbean, MemoryPoolMXBeanMO.class, mof);
- mos.add(mo);
- }
- return mos;
- }
-
- /**
- * Unwrap a CompositeValue for a MemoryUsage instance into the MemoryUsage.
- *
- * @param mv - the CompositeValue meta value
- * @return the corresponding MemoryUsage instance
- */
- public static MemoryUsage unwrapMemoryUsage(CompositeValue mv)
- {
- SimpleValue committedSV = SimpleValue.class.cast(mv.get("committed"));
- SimpleValue initSV = SimpleValue.class.cast(mv.get("init"));
- SimpleValue maxSV = SimpleValue.class.cast(mv.get("max"));
- SimpleValue usedSV = SimpleValue.class.cast(mv.get("used"));
- long committed = (Long) committedSV.getValue();
- long init = (Long) initSV.getValue();
- long max = (Long) maxSV.getValue();
- long used = (Long) usedSV.getValue();
- MemoryUsage mu = new MemoryUsage(init, used, committed, max);
- return mu;
- }
-
- public static <I> ManagedObject getMO(I mbean, final Class<? extends I> c, ManagedObjectFactory mof)
- {
- AnnotatedElement mbeanClass = c;
- AnnotatedElementMetaDataLoader retrieval = new AnnotatedElementMetaDataLoader(mbeanClass);
- MetaData metaData = new MetaDataRetrievalToMetaDataBridge(retrieval);
- ManagedObject mo = mof.initManagedObject(mbean, c, metaData, null, null);
- return mo;
- }
-
- public static ThreadInfo unwrapThreadInfo(CompositeValue mv)
- throws OpenDataException, ClassNotFoundException
- {
- CompositeData cd = (CompositeData) getOpenValue(mv);
- ThreadInfo ti = ThreadInfo.from(cd);
- return ti;
- }
-
- private static OpenType getOpenType(MetaType type) throws OpenDataException
- {
- OpenType openType = null;
- if(type instanceof SimpleMetaType)
- openType = getOpenType(SimpleMetaType.class.cast(type));
- else if(type instanceof CompositeMetaType)
- openType = getOpenType(CompositeMetaType.class.cast(type));
- else if(type instanceof ArrayMetaType)
- openType = getOpenType(ArrayMetaType.class.cast(type));
- else if(type instanceof EnumMetaType)
- openType = SimpleType.STRING;
- else
- throw new OpenDataException("Unhandled MetaType: "+type);
- return openType;
- }
-
- private static OpenType getOpenType(SimpleMetaType type)
- {
- OpenType openType = null;
- if(type == SimpleMetaType.BOOLEAN)
- openType = SimpleType.BOOLEAN;
- else if(type == SimpleMetaType.LONG)
- openType = SimpleType.LONG;
- else if(type == SimpleMetaType.INTEGER)
- openType = SimpleType.INTEGER;
- else if(type == SimpleMetaType.SHORT)
- openType = SimpleType.SHORT;
- else if(type == SimpleMetaType.STRING)
- openType = SimpleType.STRING;
- return openType;
- }
- private static ArrayType getOpenType(ArrayMetaType type) throws OpenDataException
- {
- int dimension = type.getDimension();
- OpenType elementType = getOpenType(type.getElementType());
- ArrayType openType = new ArrayType(dimension, elementType);
- return openType;
- }
- private static CompositeType getOpenType(CompositeMetaType type)
- throws OpenDataException
- {
- String[] items = new String[type.itemSet().size()];
- type.itemSet().toArray(items);
- String[] descriptions = new String[type.itemSet().size()];
- OpenType[] itemTypes = new OpenType[items.length];
- for(int n = 0; n < items.length; n ++)
- {
- String item = items[n];
- descriptions[n] = type.getDescription(item);
- MetaType mt = type.getType(item);
- itemTypes[n] = getOpenType(mt);
- }
-
- CompositeType ct = new CompositeType(type.getTypeName(),
- type.getDescription(), items, descriptions, itemTypes);
- return ct;
- }
-
- private static Object getOpenValue(MetaValue mv) throws OpenDataException
- {
- Object openValue = null;
- if(mv instanceof SimpleValue)
- {
- SimpleValue sv = SimpleValue.class.cast(mv);
- openValue = sv.getValue();
- }
- else if(mv instanceof CompositeValue)
- {
- CompositeValue cv = CompositeValue.class.cast(mv);
- HashMap<String, Object> itemsMap = new HashMap<String, Object>();
- CompositeMetaType cmt = cv.getMetaType();
- String[] items = new String[cmt.itemSet().size()];
- Object[] itemValues = new Object[items.length];
- cmt.itemSet().toArray(items);
- for(int n = 0; n < items.length; n ++)
- {
- String item = items[n];
- MetaValue itemMV = cv.get(item);
- Object itemValue = null;
- if(itemMV != null )
- itemValue = getOpenValue(itemMV);
- itemValues[n] = itemValue;
- }
-
- CompositeType ct = getOpenType(cmt);
- CompositeDataSupport cd = new CompositeDataSupport(ct, items, itemValues);
- openValue = cd;
- }
- else if(mv instanceof ArrayValue)
- {
- ArrayValue av = ArrayValue.class.cast(mv);
- if(av.getMetaType().isPrimitiveArray() || av.getMetaType().isSimple())
- openValue = av.getValue();
- else if(av.getMetaType().getElementType().isComposite())
- {
- CompositeData[] cd = new CompositeData[av.getLength()];
- for(int n = 0; n < av.getLength(); n ++)
- {
- cd[n] = (CompositeData) getOpenValue(CompositeValue.class.cast(av.getValue(n)));
- }
- openValue = cd;
- }
- }
- else if(mv instanceof EnumValue)
- {
- EnumValue ev = EnumValue.class.cast(mv);
- openValue = ev.getValue();
- }
- else
- {
- throw new OpenDataException("Unhandled MetaValue: "+mv);
- }
- return openValue;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ManagementFactoryUtils.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,428 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.GarbageCollectorMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryUsage;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.RuntimeMXBean;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.lang.reflect.AnnotatedElement;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.management.openmbean.ArrayType;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.SimpleType;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metadata.plugins.loader.reflection.AnnotatedElementMetaDataLoader;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.EnumMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * A utility class that created ManagedObjects for the jmx platform mbeans
+ * returned by {@link java.lang.management.ManagementFactory}
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ManagementFactoryUtils
+{
+ /**
+ * Return a Map of the platform mbean ManagedObjects. This does not include
+ * the MemoryManagerMXBeans, GarbageCollectorMXBeans or MemoryPoolMXBeans
+ * lists of ManagedObjects.
+ * @param mof - the ManagedObjectFactory to use
+ * @return Map of ManagedObjects for the platform mbeans keyed by the ManagedObject names
+ */
+ public static Map<String, ManagedObject> getPlatformMBeanMOs(ManagedObjectFactory mof)
+ {
+ HashMap<String, ManagedObject> mos = new HashMap<String, ManagedObject>();
+ ManagedObject classLoadingMO = getClassLoadingMO(mof);
+ mos.put(classLoadingMO.getName(), classLoadingMO);
+ ManagedObject memoryMXBean = getMemoryMXBean(mof);
+ mos.put(memoryMXBean.getName(), memoryMXBean);
+ ManagedObject operatingSystemMXBean = getOperatingSystemMXBean(mof);
+ mos.put(operatingSystemMXBean.getName(), operatingSystemMXBean);
+ ManagedObject threadMXBean = getThreadMXBean(mof);
+ mos.put(threadMXBean.getName(), threadMXBean);
+ ManagedObject runtimeMXBean = getRuntimeMXBean(mof);
+ mos.put(runtimeMXBean.getName(), runtimeMXBean);
+
+ return mos;
+ }
+
+ /**
+ * Build a ManagedObject for the ClassLoadingMXBean mean
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static ManagedObject getClassLoadingMO(ManagedObjectFactory mof)
+ {
+ ClassLoadingMXBean mbean = ManagementFactory.getClassLoadingMXBean();
+ ManagedObject mo = getMO(mbean, ClassLoadingMXBeanMO.class, mof);
+ return mo;
+ }
+
+ /**
+ * Build a ManagedObject for the MemoryMXBean mean
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static ManagedObject getMemoryMXBean(ManagedObjectFactory mof)
+ {
+ MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
+ ManagedObject mo = getMO(mbean, MemoryMXBeanMO.class, mof);
+ return mo;
+ }
+
+ /**
+ * Build a ManagedObject for the OperatingSystemMXBean mean
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static ManagedObject getOperatingSystemMXBean(ManagedObjectFactory mof)
+ {
+ OperatingSystemMXBean mbean = ManagementFactory.getOperatingSystemMXBean();
+ ManagedObject mo = getMO(mbean, OperatingSystemMXBeanMO.class, mof);
+ return mo;
+ }
+
+ /**
+ * Build a ManagedObject for the ThreadMXBean mean
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static ManagedObject getThreadMXBean(ManagedObjectFactory mof)
+ {
+ ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
+ ManagedObject mo = getMO(mbean, ThreadMXBeanMO.class, mof);
+ return mo;
+ }
+
+ /**
+ * Build a ManagedObject for the RuntimeMXBean mean
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static ManagedObject getRuntimeMXBean(ManagedObjectFactory mof)
+ {
+ RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
+ ManagedObject mo = getMO(mbean, RuntimeMXBeanMO.class, mof);
+ return mo;
+ }
+
+ /**
+ * Build a list of ManagedObject for the MemoryManagerMXBean means
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static List<ManagedObject> getMemoryManagerMXBeans(ManagedObjectFactory mof)
+ {
+ List<MemoryManagerMXBean> mbeans = ManagementFactory.getMemoryManagerMXBeans();
+ ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
+ for(MemoryManagerMXBean mbean : mbeans)
+ {
+ ManagedObject mo = getMO(mbean, MemoryManagerMXBeanMO.class, mof);
+ mos.add(mo);
+ }
+ return mos;
+ }
+
+ /**
+ * Build a list of ManagedObject for the GarbageCollectorMXBean means
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static List<ManagedObject> getGarbageCollectorMXBeans(ManagedObjectFactory mof)
+ {
+ List<GarbageCollectorMXBean> mbeans = ManagementFactory.getGarbageCollectorMXBeans();
+ ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
+ for(GarbageCollectorMXBean mbean : mbeans)
+ {
+ ManagedObject mo = getMO(mbean, GarbageCollectorMXBeanMO.class, mof);
+ mos.add(mo);
+ }
+ return mos;
+ }
+
+ /**
+ * Build a list of ManagedObject for the MemoryPoolMXBean means
+ * @param mof - the ManagedObjectFactory to use
+ * @return
+ */
+ public static List<ManagedObject> getMemoryPoolMXBeans(ManagedObjectFactory mof)
+ {
+ List<MemoryPoolMXBean> mbeans = ManagementFactory.getMemoryPoolMXBeans();
+ ArrayList<ManagedObject> mos = new ArrayList<ManagedObject>();
+ for(MemoryPoolMXBean mbean : mbeans)
+ {
+ ManagedObject mo = getMO(mbean, MemoryPoolMXBeanMO.class, mof);
+ mos.add(mo);
+ }
+ return mos;
+ }
+
+ /**
+ * Unwrap a CompositeValue for a MemoryUsage instance into the MemoryUsage.
+ *
+ * @param mv - the CompositeValue meta value
+ * @return the corresponding MemoryUsage instance
+ */
+ public static MemoryUsage unwrapMemoryUsage(CompositeValue mv)
+ {
+ SimpleValue committedSV = SimpleValue.class.cast(mv.get("committed"));
+ SimpleValue initSV = SimpleValue.class.cast(mv.get("init"));
+ SimpleValue maxSV = SimpleValue.class.cast(mv.get("max"));
+ SimpleValue usedSV = SimpleValue.class.cast(mv.get("used"));
+ long committed = (Long) committedSV.getValue();
+ long init = (Long) initSV.getValue();
+ long max = (Long) maxSV.getValue();
+ long used = (Long) usedSV.getValue();
+ MemoryUsage mu = new MemoryUsage(init, used, committed, max);
+ return mu;
+ }
+
+ public static <I> ManagedObject getMO(I mbean, final Class<? extends I> c, ManagedObjectFactory mof)
+ {
+ AnnotatedElement mbeanClass = c;
+ AnnotatedElementMetaDataLoader retrieval = new AnnotatedElementMetaDataLoader(mbeanClass);
+ MetaData metaData = new MetaDataRetrievalToMetaDataBridge(retrieval);
+ ManagedObject mo = mof.initManagedObject(mbean, c, metaData, null, null);
+ return mo;
+ }
+
+ public static ThreadInfo unwrapThreadInfo(CompositeValue mv)
+ throws OpenDataException, ClassNotFoundException
+ {
+ CompositeData cd = (CompositeData) getOpenValue(mv);
+ ThreadInfo ti = ThreadInfo.from(cd);
+ return ti;
+ }
+
+ static OpenType getOpenType(MetaType type) throws OpenDataException
+ {
+ OpenType openType = null;
+ if(type instanceof SimpleMetaType)
+ openType = getOpenType(SimpleMetaType.class.cast(type));
+ else if(type instanceof CompositeMetaType)
+ openType = getOpenType(CompositeMetaType.class.cast(type));
+ else if(type instanceof ArrayMetaType)
+ openType = getOpenType(ArrayMetaType.class.cast(type));
+ else if(type instanceof EnumMetaType)
+ openType = SimpleType.STRING;
+ else
+ throw new OpenDataException("Unhandled MetaType: "+type);
+ return openType;
+ }
+
+ static OpenType getOpenType(SimpleMetaType type)
+ {
+ OpenType openType = null;
+ if(type.equalsIgnorePrimitive(SimpleMetaType.BOOLEAN))
+ openType = SimpleType.BOOLEAN;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.BYTE))
+ openType = SimpleType.BYTE;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.CHARACTER))
+ openType = SimpleType.CHARACTER;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.LONG))
+ openType = SimpleType.LONG;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.INTEGER))
+ openType = SimpleType.INTEGER;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.SHORT))
+ openType = SimpleType.SHORT;
+ else if(type.equalsIgnorePrimitive(SimpleMetaType.STRING))
+ openType = SimpleType.STRING;
+ return openType;
+ }
+ static ArrayType getOpenType(ArrayMetaType type) throws OpenDataException
+ {
+ int dimension = type.getDimension();
+ OpenType elementType = getOpenType(type.getElementType());
+ ArrayType openType = new ArrayType(dimension, elementType);
+ return openType;
+ }
+ static CompositeType getOpenType(CompositeMetaType type)
+ throws OpenDataException
+ {
+ String[] items = new String[type.itemSet().size()];
+ type.itemSet().toArray(items);
+ String[] descriptions = new String[type.itemSet().size()];
+ OpenType[] itemTypes = new OpenType[items.length];
+ for(int n = 0; n < items.length; n ++)
+ {
+ String item = items[n];
+ descriptions[n] = type.getDescription(item);
+ MetaType mt = type.getType(item);
+ itemTypes[n] = getOpenType(mt);
+ }
+
+ CompositeType ct = new CompositeType(type.getTypeName(),
+ type.getDescription(), items, descriptions, itemTypes);
+ return ct;
+ }
+
+ static Object getOpenValue(MetaValue mv) throws OpenDataException
+ {
+ Object openValue = null;
+ if(mv instanceof SimpleValue)
+ {
+ SimpleValue sv = SimpleValue.class.cast(mv);
+ openValue = sv.getValue();
+ }
+ else if(mv instanceof CompositeValue)
+ {
+ CompositeValue cv = CompositeValue.class.cast(mv);
+ HashMap<String, Object> itemsMap = new HashMap<String, Object>();
+ CompositeMetaType cmt = cv.getMetaType();
+ String[] items = new String[cmt.itemSet().size()];
+ Object[] itemValues = new Object[items.length];
+ cmt.itemSet().toArray(items);
+ for(int n = 0; n < items.length; n ++)
+ {
+ String item = items[n];
+ MetaValue itemMV = cv.get(item);
+ Object itemValue = null;
+ if(itemMV != null )
+ itemValue = getOpenValue(itemMV);
+ itemValues[n] = itemValue;
+ }
+
+ CompositeType ct = getOpenType(cmt);
+ CompositeDataSupport cd = new CompositeDataSupport(ct, items, itemValues);
+ openValue = cd;
+ }
+ else if(mv instanceof ArrayValue)
+ {
+ ArrayValue av = ArrayValue.class.cast(mv);
+ if(av.getMetaType().isPrimitiveArray() || av.getMetaType().isSimple())
+ openValue = av.getValue();
+ else if(av.getMetaType().getElementType().isComposite())
+ {
+ CompositeData[] cd = new CompositeData[av.getLength()];
+ for(int n = 0; n < av.getLength(); n ++)
+ {
+ cd[n] = (CompositeData) getOpenValue(CompositeValue.class.cast(av.getValue(n)));
+ }
+ openValue = cd;
+ }
+ }
+ else if(mv instanceof EnumValue)
+ {
+ EnumValue ev = EnumValue.class.cast(mv);
+ openValue = ev.getValue();
+ }
+ else
+ {
+ throw new OpenDataException("Unhandled MetaValue: "+mv);
+ }
+ return openValue;
+ }
+
+ static MetaType getMetaType(OpenType type)
+ throws Exception
+ {
+ MetaType metaType = null;
+ if(type instanceof SimpleType)
+ metaType = getMetaType(SimpleType.class.cast(type));
+ else if(type instanceof CompositeType)
+ metaType = getMetaType(CompositeType.class.cast(type));
+ else if(type instanceof ArrayType)
+ metaType = getMetaType(ArrayType.class.cast(type));
+ else
+ throw new Exception("Unhandled OpenType: "+type);
+ return metaType;
+ }
+ static SimpleMetaType getMetaType(SimpleType type)
+ {
+ SimpleMetaType metaType = null;
+ if(type == SimpleType.BOOLEAN)
+ metaType = SimpleMetaType.BOOLEAN;
+ else if(type == SimpleType.BYTE)
+ metaType = SimpleMetaType.BYTE;
+ else if(type == SimpleType.CHARACTER)
+ metaType = SimpleMetaType.CHARACTER;
+ else if(type == SimpleType.LONG)
+ metaType = SimpleMetaType.LONG;
+ else if(type == SimpleType.INTEGER)
+ metaType = SimpleMetaType.INTEGER;
+ else if(type == SimpleType.SHORT)
+ metaType = SimpleMetaType.SHORT;
+ else if(type == SimpleType.STRING)
+ metaType = SimpleMetaType.STRING;
+ return metaType;
+ }
+ static ArrayMetaType getMetaType(ArrayType type)
+ throws Exception
+ {
+ int dimension = type.getDimension();
+ OpenType elementType = type.getElementOpenType();
+ MetaType elementMetaType = getMetaType(elementType);
+ ArrayMetaType metaType = new ArrayMetaType(dimension, elementMetaType);
+ return metaType;
+ }
+ static CompositeMetaType getMetaType(CompositeType type)
+ throws Exception
+ {
+ String[] itemNames = new String[type.keySet().size()];
+ String[] itemDescriptions = new String[itemNames.length];
+ MetaType[] itemTypes = new MetaType[itemNames.length];
+ type.keySet().toArray(itemNames);
+ for(int n = 0; n < itemNames.length; n ++)
+ {
+ String itemName = itemNames[n];
+ itemDescriptions[n] = type.getDescription(itemName);
+ OpenType ot = type.getType(itemName);
+ itemTypes[n] = getMetaType(ot);
+ }
+
+ String typeName = type.getTypeName();
+ String description = type.getDescription();
+ CompositeMetaType cmt = new ImmutableCompositeMetaType(typeName, description, itemNames, itemDescriptions, itemTypes);
+ return cmt;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryMXBean;
-import java.lang.management.MemoryUsage;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the MemoryMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(name=ManagementFactory.MEMORY_MXBEAN_NAME,
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=MemoryMXBean.class)
-public class MemoryMXBeanMO implements MemoryMXBean
-{
-
- @ManagementOperation(description="Runs the garbage collector")
- public void gc()
- {
- }
-
- @ManagementProperty(description="object representing the heap memory usage.")
- public MemoryUsage getHeapMemoryUsage()
- {
- return null;
- }
-
- @ManagementProperty(description="object representing the non-heap memory usage.")
- public MemoryUsage getNonHeapMemoryUsage()
- {
- return null;
- }
-
- @ManagementProperty(description="the approximate number objects for which finalization is pending.")
- public int getObjectPendingFinalizationCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the verbose output flag for the memory system.")
- public boolean isVerbose()
- {
- return false;
- }
-
- public void setVerbose(boolean value)
- {
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryUsage;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the MemoryMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(name=ManagementFactory.MEMORY_MXBEAN_NAME,
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=MemoryMXBean.class)
+public class MemoryMXBeanMO implements MemoryMXBean
+{
+
+ @ManagementOperation(description="Runs the garbage collector")
+ public void gc()
+ {
+ }
+
+ @ManagementProperty(description="object representing the heap memory usage.")
+ public MemoryUsage getHeapMemoryUsage()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="object representing the non-heap memory usage.")
+ public MemoryUsage getNonHeapMemoryUsage()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="the approximate number objects for which finalization is pending.")
+ public int getObjectPendingFinalizationCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the verbose output flag for the memory system.")
+ public boolean isVerbose()
+ {
+ return false;
+ }
+
+ public void setVerbose(boolean value)
+ {
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,64 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryManagerMXBean;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-
-/**
- * Stub class for the MemoryManagerMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=MemoryManagerMXBean.class)
-public class MemoryManagerMXBeanMO implements MemoryManagerMXBean
-{
-
- @ManagementProperty
- public String[] getMemoryPoolNames()
- {
- return null;
- }
-
- @ManagementProperty
- @ManagementObjectID(prefix=ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE)
- public String getName()
- {
- return null;
- }
-
- @ManagementProperty
- public boolean isValid()
- {
- return false;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryManagerMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,65 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryManagerMXBean;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+
+/**
+ * Stub class for the MemoryManagerMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=MemoryManagerMXBean.class)
+public class MemoryManagerMXBeanMO implements MemoryManagerMXBean
+{
+
+ @ManagementProperty
+ public String[] getMemoryPoolNames()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ @ManagementObjectID(prefix=ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE)
+ public String getName()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public boolean isValid()
+ {
+ return false;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,174 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.MemoryPoolMXBean;
-import java.lang.management.MemoryType;
-import java.lang.management.MemoryUsage;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementObjectID;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the MemoryPoolMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=MemoryPoolMXBean.class)
-public class MemoryPoolMXBeanMO implements MemoryPoolMXBean
-{
-
- @ManagementProperty
- public MemoryUsage getCollectionUsage()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @ManagementProperty
- public long getCollectionUsageThreshold()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @ManagementProperty
- public long getCollectionUsageThresholdCount()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @ManagementProperty
- public String[] getMemoryManagerNames()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @ManagementProperty
- @ManagementObjectID(prefix=ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE)
- public String getName()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @ManagementProperty
- public MemoryUsage getPeakUsage()
- {
- return null;
- }
-
- @ManagementProperty
- public MemoryType getType()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @ManagementProperty
- public MemoryUsage getUsage()
- {
- // TODO Auto-generated method stub
- return null;
- }
-
- @ManagementProperty
- public long getUsageThreshold()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @ManagementProperty
- public long getUsageThresholdCount()
- {
- // TODO Auto-generated method stub
- return 0;
- }
-
- @ManagementProperty
- public boolean isCollectionUsageThresholdExceeded()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @ManagementProperty
- public boolean isCollectionUsageThresholdSupported()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @ManagementProperty
- public boolean isUsageThresholdExceeded()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @ManagementProperty
- public boolean isUsageThresholdSupported()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @ManagementProperty
- public boolean isValid()
- {
- // TODO Auto-generated method stub
- return false;
- }
-
- @ManagementOperation
- public void resetPeakUsage()
- {
- // TODO Auto-generated method stub
-
- }
-
- @ManagementProperty
- public void setCollectionUsageThreshold(long threhsold)
- {
- // TODO Auto-generated method stub
-
- }
-
- @ManagementProperty
- public void setUsageThreshold(long threshold)
- {
- // TODO Auto-generated method stub
-
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/MemoryPoolMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryType;
+import java.lang.management.MemoryUsage;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the MemoryPoolMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=MemoryPoolMXBean.class)
+public class MemoryPoolMXBeanMO implements MemoryPoolMXBean
+{
+
+ @ManagementProperty
+ public MemoryUsage getCollectionUsage()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @ManagementProperty
+ public long getCollectionUsageThreshold()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @ManagementProperty
+ public long getCollectionUsageThresholdCount()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @ManagementProperty
+ public String[] getMemoryManagerNames()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @ManagementProperty
+ @ManagementObjectID(prefix=ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE)
+ public String getName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @ManagementProperty
+ public MemoryUsage getPeakUsage()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public MemoryType getType()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @ManagementProperty
+ public MemoryUsage getUsage()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @ManagementProperty
+ public long getUsageThreshold()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @ManagementProperty
+ public long getUsageThresholdCount()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @ManagementProperty
+ public boolean isCollectionUsageThresholdExceeded()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @ManagementProperty
+ public boolean isCollectionUsageThresholdSupported()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @ManagementProperty
+ public boolean isUsageThresholdExceeded()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @ManagementProperty
+ public boolean isUsageThresholdSupported()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @ManagementProperty
+ public boolean isValid()
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @ManagementOperation
+ public void resetPeakUsage()
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @ManagementProperty
+ public void setCollectionUsageThreshold(long threhsold)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @ManagementProperty
+ public void setUsageThreshold(long threshold)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,67 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.OperatingSystemMXBean;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the OperatingSystemMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(name=ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=OperatingSystemMXBean.class)
-public class OperatingSystemMXBeanMO implements OperatingSystemMXBean
-{
- @ManagementProperty(description="the operating system architecture.")
- public String getArch()
- {
- return null;
- }
-
- @ManagementProperty(description="the number of processors available to the virtual machine; never smaller than one.")
- public int getAvailableProcessors()
- {
- return 0;
- }
-
- @ManagementProperty(description="the operating system name.")
- public String getName()
- {
- return null;
- }
-
- @ManagementProperty(description="the operating system version.")
- public String getVersion()
- {
- return null;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/OperatingSystemMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.OperatingSystemMXBean;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the OperatingSystemMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(name=ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME,
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=OperatingSystemMXBean.class)
+public class OperatingSystemMXBeanMO implements OperatingSystemMXBean
+{
+ @ManagementProperty(description="the operating system architecture.")
+ public String getArch()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="the number of processors available to the virtual machine; never smaller than one.")
+ public int getAvailableProcessors()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the operating system name.")
+ public String getName()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="the operating system version.")
+ public String getVersion()
+ {
+ return null;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,141 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.RuntimeMXBean;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the RuntimeMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(name=ManagementFactory.RUNTIME_MXBEAN_NAME,
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=RuntimeMXBean.class)
-public class RuntimeMXBeanMO implements RuntimeMXBean
-{
- @ManagementProperty
- public String getBootClassPath()
- {
- return null;
- }
-
- @ManagementProperty
- public String getClassPath()
- {
- return null;
- }
-
- @ManagementProperty
- public List<String> getInputArguments()
- {
- return null;
- }
-
- @ManagementProperty
- public String getLibraryPath()
- {
- return null;
- }
-
- @ManagementProperty
- public String getManagementSpecVersion()
- {
- return null;
- }
-
- @ManagementProperty
- public String getName()
- {
- return null;
- }
-
- @ManagementProperty
- public String getSpecName()
- {
- return null;
- }
-
- @ManagementProperty
- public String getSpecVendor()
- {
- return null;
- }
-
- @ManagementProperty
- public String getSpecVersion()
- {
- return null;
- }
-
- @ManagementProperty
- public long getStartTime()
- {
- return 0;
- }
-
- @ManagementProperty
- public Map<String, String> getSystemProperties()
- {
- return null;
- }
-
- @ManagementProperty
- public long getUptime()
- {
- return 0;
- }
-
- @ManagementProperty
- public String getVmName()
- {
- return null;
- }
-
- @ManagementProperty
- public String getVmVendor()
- {
- return null;
- }
-
- @ManagementProperty
- public String getVmVersion()
- {
- return null;
- }
-
- @ManagementProperty
- public boolean isBootClassPathSupported()
- {
- return false;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/RuntimeMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.RuntimeMXBean;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the RuntimeMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(name=ManagementFactory.RUNTIME_MXBEAN_NAME,
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=RuntimeMXBean.class)
+public class RuntimeMXBeanMO implements RuntimeMXBean
+{
+ @ManagementProperty
+ public String getBootClassPath()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getClassPath()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public List<String> getInputArguments()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getLibraryPath()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getManagementSpecVersion()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getName()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getSpecName()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getSpecVendor()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getSpecVersion()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public long getStartTime()
+ {
+ return 0;
+ }
+
+ @ManagementProperty
+ public Map<String, String> getSystemProperties()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public long getUptime()
+ {
+ return 0;
+ }
+
+ @ManagementProperty
+ public String getVmName()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getVmVendor()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public String getVmVersion()
+ {
+ return null;
+ }
+
+ @ManagementProperty
+ public boolean isBootClassPathSupported()
+ {
+ return false;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java 2009-02-18 17:23:37 UTC (rev 84399)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,185 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.managed.plugins.jmx;
-
-import java.lang.management.ManagementFactory;
-import java.lang.management.ThreadInfo;
-import java.lang.management.ThreadMXBean;
-
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementOperation;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Stub class for the ThreadMXBean interface that is marked up with
- * management annotations.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(name=ManagementFactory.THREAD_MXBEAN_NAME,
- componentType=@ManagementComponent(type="MBean", subtype="Platform"),
- targetInterface=ThreadMXBean.class)
-public class ThreadMXBeanMO implements ThreadMXBean
-{
-
- @ManagementOperation(description="an array of IDs of the threads that are monitor deadlocked, if any; null otherwise.")
- public long[] findMonitorDeadlockedThreads()
- {
- return null;
- }
-
- @ManagementProperty(description="an array of long, each is a thread ID.")
- public long[] getAllThreadIds()
- {
- return null;
- }
-
- @ManagementProperty(description="the user-level CPU time for the current thread if CPU time measurement is enabled; -1 otherwise")
- public long getCurrentThreadCpuTime()
- {
- return 0;
- }
-
- @ManagementProperty(description="the total CPU time for the current thread if CPU time measurement is enabled; -1 otherwise")
- public long getCurrentThreadUserTime()
- {
- return 0;
- }
-
- @ManagementProperty(description="the current number of live daemon threads.")
- public int getDaemonThreadCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the peak live thread count.")
- public int getPeakThreadCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="the current number of live threads.")
- public int getThreadCount()
- {
- return 0;
- }
-
- @ManagementOperation(description="the total CPU time for a thread of the"
- + "specified ID if the thread of the specified ID exists, the thread is "
- + " alive, and CPU time measurement is enabled; -1</tt> otherwise.")
- public long getThreadCpuTime(long id)
- {
- return 0;
- }
-
- @ManagementOperation(description="a ThreadInfo object for the thread "
- + "of the given ID with no stack trace; null</tt> if the thread of the "
- + "given ID is not alive or it does not exist.")
- public ThreadInfo getThreadInfo(long id)
- {
- return null;
- }
-
- @ManagementOperation(description="an array of the ThreadInfo objects, "
- + "each containing information about a thread whose ID is in the "
- + "corresponding element of the input array of IDs.")
- public ThreadInfo[] getThreadInfo(long[] ids)
- {
- return null;
- }
-
- @ManagementOperation(description="a ThreadInfo of the thread of the given ID. "
- + "null if the thread of the given ID is not alive or it does not exist.")
- public ThreadInfo getThreadInfo(long id, int maxDepth)
- {
- return null;
- }
-
- @ManagementOperation(description="an array of the ThreadInfo objects, each "
- +"containing information about a thread whose ID is in the corresponding"
- +"element of the input array of IDs.")
- public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth)
- {
- return null;
- }
-
- @ManagementOperation(description="the user-level CPU time for a thread of the "
- +"specified ID if the thread of the specified ID exists, the thread is "
- +"alive, and CPU time measurement is enabled; -1</tt> otherwise.")
- public long getThreadUserTime(long id)
- {
- return 0;
- }
-
- @ManagementProperty(description="the total number of threads started.")
- public long getTotalStartedThreadCount()
- {
- return 0;
- }
-
- @ManagementProperty(description="true if the Java virtual machine supports "
- +"CPU time measurement for current thread; false</tt> otherwise.")
- public boolean isCurrentThreadCpuTimeSupported()
- {
- return false;
- }
-
- @ManagementProperty(description="true if thread contention monitoring is enabled; false</tt> otherwise.")
- public boolean isThreadContentionMonitoringEnabled()
- {
- return false;
- }
-
- @ManagementProperty(description="true if the Java virtual machine supports thread contention monitoring; false</tt> otherwise.")
- public boolean isThreadContentionMonitoringSupported()
- {
- return false;
- }
-
- @ManagementProperty(description="true if thread CPU time measurement is enabled; false</tt> otherwise.")
- public boolean isThreadCpuTimeEnabled()
- {
- return false;
- }
-
- @ManagementProperty(description="true if the Java virtual machine supports CPU time measurement for any thread;; false</tt> otherwise.")
- public boolean isThreadCpuTimeSupported()
- {
- return false;
- }
-
- @ManagementOperation(description="Resets the peak thread count to the current number of live threads.")
- public void resetPeakThreadCount()
- {
- }
-
- public void setThreadContentionMonitoringEnabled(boolean enable)
- {
- }
-
- public void setThreadCpuTimeEnabled(boolean enable)
- {
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/main/java/org/jboss/managed/plugins/jmx/ThreadMXBeanMO.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,186 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.managed.plugins.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Stub class for the ThreadMXBean interface that is marked up with
+ * management annotations.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(name=ManagementFactory.THREAD_MXBEAN_NAME,
+ isRuntime=true,
+ componentType=@ManagementComponent(type="MBean", subtype="Platform"),
+ targetInterface=ThreadMXBean.class)
+public class ThreadMXBeanMO implements ThreadMXBean
+{
+
+ @ManagementOperation(description="an array of IDs of the threads that are monitor deadlocked, if any; null otherwise.")
+ public long[] findMonitorDeadlockedThreads()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="an array of long, each is a thread ID.")
+ public long[] getAllThreadIds()
+ {
+ return null;
+ }
+
+ @ManagementProperty(description="the user-level CPU time for the current thread if CPU time measurement is enabled; -1 otherwise")
+ public long getCurrentThreadCpuTime()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the total CPU time for the current thread if CPU time measurement is enabled; -1 otherwise")
+ public long getCurrentThreadUserTime()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the current number of live daemon threads.")
+ public int getDaemonThreadCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the peak live thread count.")
+ public int getPeakThreadCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the current number of live threads.")
+ public int getThreadCount()
+ {
+ return 0;
+ }
+
+ @ManagementOperation(description="the total CPU time for a thread of the"
+ + "specified ID if the thread of the specified ID exists, the thread is "
+ + " alive, and CPU time measurement is enabled; -1</tt> otherwise.")
+ public long getThreadCpuTime(long id)
+ {
+ return 0;
+ }
+
+ @ManagementOperation(description="a ThreadInfo object for the thread "
+ + "of the given ID with no stack trace; null</tt> if the thread of the "
+ + "given ID is not alive or it does not exist.")
+ public ThreadInfo getThreadInfo(long id)
+ {
+ return null;
+ }
+
+ @ManagementOperation(description="an array of the ThreadInfo objects, "
+ + "each containing information about a thread whose ID is in the "
+ + "corresponding element of the input array of IDs.")
+ public ThreadInfo[] getThreadInfo(long[] ids)
+ {
+ return null;
+ }
+
+ @ManagementOperation(description="a ThreadInfo of the thread of the given ID. "
+ + "null if the thread of the given ID is not alive or it does not exist.")
+ public ThreadInfo getThreadInfo(long id, int maxDepth)
+ {
+ return null;
+ }
+
+ @ManagementOperation(description="an array of the ThreadInfo objects, each "
+ +"containing information about a thread whose ID is in the corresponding"
+ +"element of the input array of IDs.")
+ public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth)
+ {
+ return null;
+ }
+
+ @ManagementOperation(description="the user-level CPU time for a thread of the "
+ +"specified ID if the thread of the specified ID exists, the thread is "
+ +"alive, and CPU time measurement is enabled; -1</tt> otherwise.")
+ public long getThreadUserTime(long id)
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="the total number of threads started.")
+ public long getTotalStartedThreadCount()
+ {
+ return 0;
+ }
+
+ @ManagementProperty(description="true if the Java virtual machine supports "
+ +"CPU time measurement for current thread; false</tt> otherwise.")
+ public boolean isCurrentThreadCpuTimeSupported()
+ {
+ return false;
+ }
+
+ @ManagementProperty(description="true if thread contention monitoring is enabled; false</tt> otherwise.")
+ public boolean isThreadContentionMonitoringEnabled()
+ {
+ return false;
+ }
+
+ @ManagementProperty(description="true if the Java virtual machine supports thread contention monitoring; false</tt> otherwise.")
+ public boolean isThreadContentionMonitoringSupported()
+ {
+ return false;
+ }
+
+ @ManagementProperty(description="true if thread CPU time measurement is enabled; false</tt> otherwise.")
+ public boolean isThreadCpuTimeEnabled()
+ {
+ return false;
+ }
+
+ @ManagementProperty(description="true if the Java virtual machine supports CPU time measurement for any thread;; false</tt> otherwise.")
+ public boolean isThreadCpuTimeSupported()
+ {
+ return false;
+ }
+
+ @ManagementOperation(description="Resets the peak thread count to the current number of live threads.")
+ public void resetPeakThreadCount()
+ {
+ }
+
+ public void setThreadContentionMonitoringEnabled(boolean enable)
+ {
+ }
+
+ public void setThreadCpuTimeEnabled(boolean enable)
+ {
+ }
+
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/JmsDestinationTemplateInfo.java (from rev 85281, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/JmsDestinationTemplateInfo.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/JmsDestinationTemplateInfo.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/JmsDestinationTemplateInfo.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,128 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.annotation.factory.AnnotationProxy;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.plugins.BasicDeploymentTemplateInfo;
+import org.jboss.managed.plugins.DefaultFieldsImpl;
+import org.jboss.managed.plugins.ManagedObjectImpl;
+import org.jboss.managed.plugins.ManagedPropertyImpl;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.MetaValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JmsDestinationTemplateInfo extends BasicDeploymentTemplateInfo
+{
+ private static final long serialVersionUID = 1;
+ private String destinationType = "queue";
+
+ public JmsDestinationTemplateInfo(String name, String description, String destinationType)
+ {
+ super(name, description);
+ this.destinationType = destinationType;
+ super.setRootManagedPropertyName("services");
+
+ ManagedObjectImpl mo;
+ if("queue".equals(destinationType))
+ mo = new ManagedObjectImpl("org.jboss.jms.server.destination.QueueServiceMO");
+ else if("topic".equals(destinationType))
+ mo = new ManagedObjectImpl("org.jboss.jms.server.destination.TopicServiceMO");
+ else
+ throw new IllegalStateException("Unexpected destination type: " + destinationType);
+
+ addManagedProperty("name", "The destination name", true, false, SimpleMetaType.STRING, mo);
+ addManagedProperty("JNDIName", "The destination's JNDI name", false, true, SimpleMetaType.STRING, mo);
+ }
+
+
+ public String getDestinationType()
+ {
+ return destinationType;
+ }
+
+
+ @Override
+ public JmsDestinationTemplateInfo copy()
+ {
+ JmsDestinationTemplateInfo copy = new JmsDestinationTemplateInfo(getName(), getDescription(), destinationType);
+ super.copy(copy);
+ return copy;
+ }
+
+ private void addManagedProperty(String fieldName,
+ String fieldDescr,
+ boolean mandatory,
+ boolean isID,
+ MetaType metaType,
+ ManagedObjectImpl mo)
+ {
+
+ addManagedProperty(fieldName, fieldDescr, mandatory, isID, metaType, null, mo);
+ }
+
+ private void addManagedProperty(String fieldName,
+ String fieldDescr,
+ boolean mandatory,
+ boolean isID,
+ MetaType metaType,
+ MetaValue value,
+ ManagedObjectImpl mo)
+ {
+ DefaultFieldsImpl fields = new DefaultFieldsImpl();
+ fields.setDescription(fieldDescr);
+ fields.setMandatory(mandatory);
+ fields.setMetaType(metaType);
+ fields.setName(fieldName);
+ ManagedPropertyImpl mp = new ManagedPropertyImpl(mo, fields);
+ if(isID)
+ {
+ Map<String, Annotation> annotations = new HashMap<String, Annotation>();
+ Map<String, Object> idFields = Collections.emptyMap();
+ try
+ {
+ ManagementObjectID id = (ManagementObjectID) AnnotationProxy.createProxy(idFields, ManagementObjectID.class);
+ annotations.put(ManagementObjectID.class.getName(), id);
+ mp.setAnnotations(annotations);
+ }
+ catch(Exception e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+
+ super.addProperty(mp);
+ if(value != null)
+ mp.setValue(value);
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,122 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.managed.factory.support.beans;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
- at ManagementObject(properties = ManagementProperties.EXPLICIT)
- at XmlRootElement(name="bean")
- at XmlType(name="beanType", propOrder={"aliasMetaData", "related", "annotations", "classLoader", "constructor", "properties", "create", "start", "stop", "destroy", "depends", "demands", "supplies", "installs", "uninstalls", "installCallbacks", "uninstallCallbacks"})
-public class ABeanMetaData extends AFeatureMetaData
- implements IBeanMetaData, IBeanMetaDataFactory
-{
- private static final long serialVersionUID = 1;
- private String bean;
- private String name;
- /** The properties configuration Set<PropertyMetaData> */
- private Set<IPropertyMetaData> properties;
-
- public String getBean()
- {
- return bean;
- }
- public void setBean(String bean)
- {
- this.bean = bean;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String name)
- {
- this.name = name;
- }
-
- /**
- * Get a property
- *
- * @param name the name
- * @return the property name
- */
- public IPropertyMetaData getProperty(String name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
- if (properties != null && properties.size() > 0)
- {
- for (IPropertyMetaData prop : properties)
- {
- if (name.equals(prop.getName()))
- return prop;
- }
- }
- return null;
- }
-
- /**
- * Add a property
- *
- * @param property the property
- */
- public void addProperty(IPropertyMetaData property)
- {
- if (property == null)
- throw new IllegalArgumentException("Null property");
- if (properties == null)
- properties = new HashSet<IPropertyMetaData>();
- properties.add(property);
- }
-
- /**
- * Set the propertiess.
- *
- * @param properties Set<PropertyMetaData>
- */
- @ManagementProperty(managed=true)
- @XmlElement(name="property", type=APropertyMetaData.class)
- public void setProperties(Set<IPropertyMetaData> properties)
- {
- this.properties = properties;
- }
- public List<IBeanMetaData> getBeans()
- {
- ArrayList<IBeanMetaData> beans = new ArrayList<IBeanMetaData>();
- beans.add(this);
- return beans;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java (from rev 84399, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/ABeanMetaData.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,132 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.beans;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperties;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+ at ManagementObject(properties = ManagementProperties.EXPLICIT)
+ at XmlRootElement(name="bean")
+ at XmlType(name="beanType", propOrder={"aliasMetaData", "related", "annotations", "classLoader", "constructor", "properties", "create", "start", "stop", "destroy", "depends", "demands", "supplies", "installs", "uninstalls", "installCallbacks", "uninstallCallbacks"})
+public class ABeanMetaData extends AFeatureMetaData
+ implements IBeanMetaData, IBeanMetaDataFactory
+{
+ private static final long serialVersionUID = 1;
+ private String bean;
+ private String name;
+ /** The properties configuration Set<IPropertyMetaData> */
+ private Set<IPropertyMetaData> properties;
+
+ public String getBean()
+ {
+ return bean;
+ }
+ public void setBean(String bean)
+ {
+ this.bean = bean;
+ }
+ public String getName()
+ {
+ return name;
+ }
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ /**
+ * Get a property
+ *
+ * @param name the name
+ * @return the property name
+ */
+ public IPropertyMetaData getProperty(String name)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (properties != null && properties.size() > 0)
+ {
+ for (IPropertyMetaData prop : properties)
+ {
+ if (name.equals(prop.getName()))
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Add a property
+ *
+ * @param property the property
+ */
+ public void addProperty(IPropertyMetaData property)
+ {
+ if (property == null)
+ throw new IllegalArgumentException("Null property");
+ if (properties == null)
+ properties = new HashSet<IPropertyMetaData>();
+ properties.add(property);
+ }
+
+ public Set<IPropertyMetaData> getProperties()
+ {
+ return properties;
+ }
+
+ /**
+ * Set the propertiess.
+ *
+ * @param properties Set<PropertyMetaData>
+ */
+ @ManagementProperty(managed=true)
+ @XmlElement(name="property", type=APropertyMetaData.class)
+ public void setProperties(Set<IPropertyMetaData> properties)
+ {
+ this.properties = properties;
+ }
+ public List<IBeanMetaData> getBeans()
+ {
+ ArrayList<IBeanMetaData> beans = new ArrayList<IBeanMetaData>();
+ beans.add(this);
+ return beans;
+ }
+
+ public String toString()
+ {
+ return "ABeanMetaData("+bean+";"+name+")";
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,212 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.managed.factory.support.beans;
-
-import java.lang.annotation.Annotation;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.logging.Logger;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.annotation.ManagementObjectClass;
-import org.jboss.managed.api.annotation.ManagementProperty;
-import org.jboss.managed.api.annotation.ViewUse;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-
-/**
- * An InstanceClassFactory for BeanMetaData
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
-public class BeanMetaDataICF
- implements InstanceClassFactory<IBeanMetaData>
-{
- private static final Logger log = Logger.getLogger(BeanMetaDataICF.class);
- /** The meta value factory */
- private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
- private static HashMap<String, Object> beanMap = new HashMap<String, Object>();
-
- public MetaValueFactory getMetaValueFactory()
- {
- return metaValueFactory;
- }
- public void setMetaValueFactory(MetaValueFactory metaValueFactory)
- {
- this.metaValueFactory = metaValueFactory;
- }
-
- public static Object getBean(String name)
- {
- return beanMap.get(name);
- }
- public static void setBean(String name, Object bean)
- {
- beanMap.put(name, bean);
- }
-
- public Object locateBean(String beanName)
- {
- return beanMap.get(beanName);
- }
-
-
- public Class<IBeanMetaData> getType()
- {
- return IBeanMetaData.class;
- }
-
- public Object getComponentName(BeanInfo beanInfo, ManagedProperty property,
- IBeanMetaData attachment, MetaValue value)
- {
- return attachment.getName();
- }
-
- public Class<?> getManagedObjectClass(IBeanMetaData attachment)
- throws ClassNotFoundException
- {
- Class<?> mocClass = null;
-
- // Look for a ManagementObjectClass annotation
- Set<IAnnotationMetaData> annotations = attachment.getAnnotations();
- if(annotations != null)
- {
- for(IAnnotationMetaData amd : annotations)
- {
- Annotation ann = amd.getAnnotationInstance();
- if(ann instanceof ManagementObjectClass)
- {
- ManagementObjectClass moc = (ManagementObjectClass) ann;
- mocClass = moc.code();
- }
- }
- }
- // Use the bean from the metadata
- if(mocClass == null)
- {
- String beanClassName = attachment.getBean();
- if(beanClassName != null && beanClassName.length() > 0)
- {
- // TODO: TCL may not be correct
- ClassLoader loader = getClassLoader(attachment);
- mocClass = loader.loadClass(beanClassName);
- }
- }
- return mocClass;
- }
-
- public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property,
- MetaData metaData, IBeanMetaData attachment)
- {
- // Get the property from the bean
- // First look to the mapped name
- String name = property.getMappedName();
- if (name == null)
- property.getName();
- PropertyInfo propertyInfo = beanInfo.getProperty(name);
- Object bean = locateBean(attachment.getName());
- Object value = null;
- MetaValue mvalue = null;
-
- try
- {
- value = propertyInfo.get(bean);
- mvalue = metaValueFactory.create(value, propertyInfo.getType());
- }
- catch(Throwable e)
- {
- log.debug("Failed to get property value for bean: "+beanInfo.getName()
- +", property: "+propertyInfo.getName(), e);
- mvalue = metaValueFactory.create(null, propertyInfo.getType());
- return mvalue;
- }
-
- return mvalue;
- }
-
- public void setValue(BeanInfo beanInfo, ManagedProperty property,
- IBeanMetaData attachment, MetaValue value)
- {
- ClassLoader prevLoader = SecurityActions.getContextClassLoader();
- String beanName = attachment.getName();
- // First look to the mapped name
- String name = property.getMappedName();
- if (name == null)
- property.getName();
-
- // See if this is a RUNTIME property
- Map<String, Annotation> annotations = property.getAnnotations();
- boolean isRuntime = false;
- if(annotations != null)
- {
- ManagementProperty annotation = (ManagementProperty) annotations.get(ManagementProperty.class);
- if(annotation != null)
- {
- ViewUse[] uses = annotation.use();
- for(ViewUse use : uses)
- {
- if(use == ViewUse.RUNTIME)
- isRuntime = true;
- }
- }
- }
-
- try
- {
- ClassLoader loader = getClassLoader(attachment);
- // Set the mbean class loader as the TCL
- SecurityActions.setContextClassLoader(loader);
-
- PropertyInfo propertyInfo = beanInfo.getProperty(name);
- if(propertyInfo == null)
- throw new IllegalArgumentException("No matching property found: " + name + "/" + beanName);
-
- Object plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
- Object bean = locateBean(beanName);
- propertyInfo.set(bean, plainValue);
- }
- catch(Throwable e)
- {
- throw new IllegalStateException("Failed to set property value: "+name + "/" + beanName, e);
- }
- finally
- {
- SecurityActions.setContextClassLoader(prevLoader);
- }
- }
-
- protected ClassLoader getClassLoader(IBeanMetaData deployment)
- {
- ClassLoader loader = null;
- // TODO...
- // Fallback to TCL if there is no
- if(loader == null)
- loader = SecurityActions.getContextClassLoader();
- return loader;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java (from rev 84399, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/beans/BeanMetaDataICF.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,241 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.support.beans;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.logging.Logger;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectClass;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.annotation.ViewUse;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+
+/**
+ * An InstanceClassFactory for BeanMetaData
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class BeanMetaDataICF
+ implements InstanceClassFactory<IBeanMetaData>
+{
+ private static final Logger log = Logger.getLogger(BeanMetaDataICF.class);
+ /** The meta value factory */
+ private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ private static HashMap<String, Object> beanMap = new HashMap<String, Object>();
+ private InstanceClassFactory delegateICF;
+
+ public MetaValueFactory getMetaValueFactory()
+ {
+ return metaValueFactory;
+ }
+ public void setMetaValueFactory(MetaValueFactory metaValueFactory)
+ {
+ this.metaValueFactory = metaValueFactory;
+ }
+
+ public static Object getBean(String name)
+ {
+ return beanMap.get(name);
+ }
+ public static void setBean(String name, Object bean)
+ {
+ beanMap.put(name, bean);
+ }
+
+
+ public InstanceClassFactory getDelegateICF()
+ {
+ return delegateICF;
+ }
+ public void setDelegateICF(InstanceClassFactory delegateICF)
+ {
+ this.delegateICF = delegateICF;
+ }
+
+ public Object locateBean(String beanName)
+ {
+ return beanMap.get(beanName);
+ }
+
+
+ public Class<IBeanMetaData> getType()
+ {
+ return IBeanMetaData.class;
+ }
+
+ public Object getComponentName(BeanInfo beanInfo, ManagedProperty property,
+ IBeanMetaData attachment, MetaValue value)
+ {
+ return attachment.getName();
+ }
+
+ public Class<?> getManagedObjectClass(IBeanMetaData attachment)
+ throws ClassNotFoundException
+ {
+ Class<?> mocClass = null;
+
+ // Look for a ManagementObjectClass annotation
+ Set<IAnnotationMetaData> annotations = attachment.getAnnotations();
+ if(annotations != null)
+ {
+ for(IAnnotationMetaData amd : annotations)
+ {
+ Annotation ann = amd.getAnnotationInstance();
+ if(ann instanceof ManagementObjectClass)
+ {
+ ManagementObjectClass moc = (ManagementObjectClass) ann;
+ mocClass = moc.code();
+ }
+ }
+ }
+ // Use the bean from the metadata
+ if(mocClass == null)
+ {
+ String beanClassName = attachment.getBean();
+ if(beanClassName != null && beanClassName.length() > 0)
+ {
+ // TODO: TCL may not be correct
+ ClassLoader loader = getClassLoader(attachment);
+ mocClass = loader.loadClass(beanClassName);
+ // Make sure it has an ManagementObject annotation
+ ManagementObject moAnn = mocClass.getAnnotation(ManagementObject.class);
+ if(moAnn == null)
+ {
+ // Revert back to the BeanMetaData class
+ mocClass = attachment.getClass();
+ }
+ log.debug("Using bean class:, "+mocClass+" for bean: "+attachment);
+ }
+ }
+ return mocClass;
+ }
+
+ public MetaValue getValue(BeanInfo beanInfo, ManagedProperty property,
+ MetaData metaData, IBeanMetaData attachment)
+ {
+ // Get the property from the bean
+ // First look to the mapped name
+ String name = property.getMappedName();
+ if (name == null)
+ property.getName();
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+ Object bean = locateBean(attachment.getName());
+ Object value = null;
+ MetaValue mvalue = null;
+ if(propertyInfo.isReadable() == false)
+ {
+ if(log.isTraceEnabled())
+ log.trace("Skipping get of non-readable property: "+propertyInfo);
+ return null;
+ }
+
+ try
+ {
+ String getterClassName = propertyInfo.getGetter().getDeclaringClass().getName();
+ if(getterClassName.equals(attachment.getClass().getName()))
+ mvalue = delegateICF.getValue(beanInfo, property, metaData, attachment);
+ else
+ mvalue = delegateICF.getValue(beanInfo, property, metaData, bean);
+ }
+ catch(Throwable e)
+ {
+ log.debug("Failed to get property value for bean: "+beanInfo.getName()
+ +", property: "+propertyInfo.getName(), e);
+ mvalue = metaValueFactory.create(null, propertyInfo.getType());
+ return mvalue;
+ }
+
+ return mvalue;
+ }
+
+ public void setValue(BeanInfo beanInfo, ManagedProperty property,
+ IBeanMetaData attachment, MetaValue value)
+ {
+ ClassLoader prevLoader = SecurityActions.getContextClassLoader();
+ String beanName = attachment.getName();
+ // First look to the mapped name
+ String name = property.getMappedName();
+ if (name == null)
+ property.getName();
+
+ // See if this is a RUNTIME property
+ Map<String, Annotation> annotations = property.getAnnotations();
+ boolean isRuntime = false;
+ if(annotations != null)
+ {
+ ManagementProperty annotation = (ManagementProperty) annotations.get(ManagementProperty.class);
+ if(annotation != null)
+ {
+ ViewUse[] uses = annotation.use();
+ for(ViewUse use : uses)
+ {
+ if(use == ViewUse.RUNTIME)
+ isRuntime = true;
+ }
+ }
+ }
+
+ try
+ {
+ ClassLoader loader = getClassLoader(attachment);
+ // Set the mbean class loader as the TCL
+ SecurityActions.setContextClassLoader(loader);
+
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+ if(propertyInfo == null)
+ throw new IllegalArgumentException("No matching property found: " + name + "/" + beanName);
+
+ Object plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
+ Object bean = locateBean(beanName);
+ propertyInfo.set(bean, plainValue);
+ }
+ catch(Throwable e)
+ {
+ throw new IllegalStateException("Failed to set property value: "+name + "/" + beanName, e);
+ }
+ finally
+ {
+ SecurityActions.setContextClassLoader(prevLoader);
+ }
+ }
+
+ protected ClassLoader getClassLoader(IBeanMetaData deployment)
+ {
+ ClassLoader loader = null;
+ // TODO...
+ // Fallback to TCL if there is no
+ if(loader == null)
+ loader = SecurityActions.getContextClassLoader();
+ return loader;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,62 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.managed.factory.support.template;
-
-import java.io.Serializable;
-
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.annotation.ManagementProperties;
-import org.jboss.managed.api.annotation.ManagementProperty;
-
-/**
- * Test explicit properties.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
- at ManagementObject(properties=ManagementProperties.EXPLICIT)
-public class ManagementObjectExplicit implements Serializable
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -1L;
-
- /**
- * Get property 1
- *
- * @return null
- */
- @ManagementProperty(includeInTemplate=true)
- public String getProperty1()
- {
- return null;
- }
-
- /**
- * Get property 2
- *
- * @return null
- */
- public String getProperty2()
- {
- return null;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/support/template/ManagementObjectExplicit.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,67 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed.factory.support.template;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperties;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * Test explicit properties.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+ at ManagementObject(properties=ManagementProperties.EXPLICIT)
+public class ManagementObjectExplicit implements Serializable
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1L;
+ private String property1;
+
+ /**
+ * Get property 1
+ *
+ * @return null
+ */
+ @ManagementProperty(includeInTemplate=true)
+ public String getProperty1()
+ {
+ return property1;
+ }
+ public void setProperty1(String value)
+ {
+ this.property1 = value;
+ }
+
+ /**
+ * Get property 2
+ *
+ * @return null
+ */
+ public String getProperty2()
+ {
+ return null;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,491 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.test.managed.factory.test;
-
-import java.lang.annotation.Annotation;
-import java.math.BigDecimal;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.jboss.annotation.factory.AnnotationCreator;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.api.ManagedProperty;
-import org.jboss.managed.api.annotation.ManagementComponent;
-import org.jboss.managed.api.annotation.ManagementObject;
-import org.jboss.managed.api.factory.ManagedObjectFactory;
-import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
-import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
-import org.jboss.managed.plugins.factory.DefaultInstanceClassFactory;
-import org.jboss.managed.spi.factory.InstanceClassFactory;
-import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
-import org.jboss.metadata.spi.MetaData;
-import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.MapCompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
-import org.jboss.test.managed.factory.support.ManagementObjectChangedName;
-import org.jboss.test.managed.factory.support.ManagementPropertySimpleManaged;
-import org.jboss.test.managed.factory.support.Simple;
-import org.jboss.test.managed.factory.support.SimpleUnannotated;
-import org.jboss.test.managed.factory.support.amof.CustomName;
-import org.jboss.test.managed.factory.support.amof.ManagementObjectWithRuntimeRef;
-import org.jboss.test.managed.factory.support.amof.ManagementObjectWithRuntimeRefICF;
-import org.jboss.test.managed.factory.support.amof.TestICF;
-import org.jboss.test.managed.factory.support.amof.TestMOP;
-import org.jboss.test.managed.factory.support.amof.TestSimpleICF;
-import org.jboss.test.managed.factory.support.beans.ABeanMetaData;
-import org.jboss.test.managed.factory.support.beans.AKernelDeployment;
-import org.jboss.test.managed.factory.support.beans.BeanMetaDataICF;
-import org.jboss.test.managed.factory.support.beans.IBeanMetaData;
-import org.jboss.test.managed.factory.support.beans.IBeanMetaDataFactory;
-import org.jboss.test.managed.factory.support.deployment.JmsDestination;
-import org.jboss.test.managed.factory.support.deployment.JmsDestinationICF;
-import org.jboss.test.managed.factory.support.deployment.JmsDestinations;
-import org.jboss.test.managed.factory.support.deployment.QueueDestination;
-import org.jboss.test.managed.factory.support.deployment.SecurityDomain;
-import org.jboss.test.managed.factory.support.mcf.ConnectionFactoryProperty;
-import org.jboss.test.managed.factory.support.mcf.DBMSMetaData;
-import org.jboss.test.managed.factory.support.mcf.DataSourceConnectionPropertyMetaData;
-import org.jboss.test.managed.factory.support.mcf.LocalDSInstanceClassFactory;
-import org.jboss.test.managed.factory.support.mcf.LocalDataSourceDeploymentMetaData;
-import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentGroup;
-import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentMetaData;
-import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryPropertyMetaData;
-import org.jboss.test.managed.factory.support.mcf.NoTxConnectionFactoryDeploymentMetaData;
-import org.jboss.test.managed.factory.support.mcf.NoTxICF;
-import org.jboss.test.managed.factory.support.mcf.SecurityMetaData;
-
-/**
- * Test of behavior of the AbstractManagedObjectFactory
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class AbstractManagedObjectFactoryUnitTestCase extends AbstractManagedObjectFactoryTest
-{
- private ManagedObjectFactory testMOF;
-
- public static Test suite()
- {
- return new TestSuite(AbstractManagedObjectFactoryUnitTestCase.class);
- }
-
- public AbstractManagedObjectFactoryUnitTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Test overriding the AbstractManagedObjectFactory.defaultInstanceFactory
- */
- public void testDefaultInstanceFactory()
- {
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- mof.setDefaultInstanceFactory(new TestICF());
- TestSimpleICF icf = new TestSimpleICF();
- mof.setInstanceClassFactory(Simple.class, icf);
- testMOF = mof;
-
- BigDecimal bigDecimal = new BigDecimal(10);
- Simple simple = new Simple();
- simple.setBigDecimalValue(bigDecimal);
-
- ManagedObject managedObject = initManagedObject(simple);
- checkManagedObjectDefaults(Simple.class, managedObject);
- checkDefaultManagedProperties(managedObject, Simple.class);
-
- checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
- assertTrue("TestBigDecimalICF.isGetValueCalled", icf.isGetValueCalled());
-
- //
- managedObject = super.createManagedObject(ManagementPropertySimpleManaged.class);
- checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
- checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
- }
-
- /**
- * Test that the setDefaultManagedObjectPopulator overrides the MOF
- * default ManagedObjectPopulator
- */
- public void testDefaultManagedObjectPopulator()
- {
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- TestMOP mop = new TestMOP(mof.getConfiguration(), new TestSimpleICF(), mof.getInstanceFactories());
- mof.setDefaultManagedObjectPopulator(mop);
- testMOF = mof;
-
- BigDecimal bigDecimal = new BigDecimal(10);
- Simple simple = new Simple();
- simple.setBigDecimalValue(bigDecimal);
-
- ManagedObject managedObject = initManagedObject(simple);
- checkManagedObjectDefaults(Simple.class, managedObject);
- checkDefaultManagedProperties(managedObject, Simple.class);
- checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
- assertTrue("isPopulateManagedObjectCalled", mop.isPopulateManagedObjectCalled());
- //
- managedObject = createManagedObject(ManagementPropertySimpleManaged.class);
- checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
- checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
- assertTrue("isCreateObjectCalled", mop.isCreateObjectCalled());
-
- }
-
- public void testInstanceClassFactoryAddition()
- {
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- testMOF = mof;
-
- BeanMetaDataICF bicf = new BeanMetaDataICF();
- mof.addInstanceClassFactory(bicf);
- LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
- mof.addInstanceClassFactory(dsicf);
- NoTxICF nticf = new NoTxICF();
- mof.addInstanceClassFactory(nticf);
-
- InstanceClassFactory icf = mof.getInstanceClassFactory(IBeanMetaData.class);
- assertEquals("IBeanMetaData ICF", bicf, icf);
- icf = mof.getInstanceClassFactory(LocalDataSourceDeploymentMetaData.class);
- assertEquals("LocalDataSourceDeploymentMetaData ICF", dsicf, icf);
- icf = mof.getInstanceClassFactory(NoTxConnectionFactoryDeploymentMetaData.class);
- assertEquals("NoTxConnectionFactoryDeploymentMetaData ICF", nticf, icf);
- }
-
- /**
- * Test that the MetaData repository annotations override/augment the class
- * annotations.
- */
- public void testMetaDataRepositoryOverride()
- throws Exception
- {
- MemoryMetaDataLoader memory = new MemoryMetaDataLoader();
- String annotationExpr = "@org.jboss.managed.api.annotation.ManagementObject(name=\"testMetaDataRepositoryOverride\",componentType=@org.jboss.managed.api.annotation.ManagementComponent(type=\"MCBean\", subtype=\"MetaDataTest\"))";
- ManagementObject override = (ManagementObject) AnnotationCreator.createAnnotation(annotationExpr, ManagementObject.class);
- memory.addAnnotation(override);
- MetaData metaData = new MetaDataRetrievalToMetaDataBridge(memory);
-
- BigDecimal bigDecimal = new BigDecimal(10);
- SimpleUnannotated simple = new SimpleUnannotated();
- simple.setBigDecimalValue(bigDecimal);
-
- ManagedObjectFactory mof = getMOF();
- ManagedObject managedObject = mof.initManagedObject(simple, metaData);
- assertEquals("testMetaDataRepositoryOverride", managedObject.getName());
- Map<String, Annotation> moAnnotations = managedObject.getAnnotations();
- assertEquals("MO annotations == 2;", 2, moAnnotations.size());
- ManagementObject moAnn = (ManagementObject) moAnnotations.get(ManagementObject.class.getName());
- ManagementComponent componentType = moAnn.componentType();
- assertEquals("componentType.type", "MCBean", componentType.type());
- assertEquals("componentType.subtype", "MetaDataTest", componentType.subtype());
- checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
- checkDefaultManagedProperties(managedObject, SimpleUnannotated.class);
- }
-
- @SuppressWarnings("unchecked")
- public void testGenericValueUpdate()
- {
- super.enableTrace("org.jboss.managed");
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- mof.setInstanceClassFactory(JmsDestination.class, new JmsDestinationICF(mof));
- testMOF = mof;
-
- JmsDestinations destinations = new JmsDestinations();
- List<JmsDestination> queues = new ArrayList<JmsDestination>();
- QueueDestination q1 = new QueueDestination();
- q1.setJndiName("queues/Q1");
- q1.setDomain(new SecurityDomain("java:/jaas/JMS"));
- queues.add(q1);
- destinations.setDestinations(queues);
-
- ManagedObject managedObject = initManagedObject(destinations);
- checkManagedObjectDefaults(JmsDestinations.class, managedObject);
-
- ManagedProperty destinationsMP = managedObject.getProperty("destinations");
- assertNotNull(destinationsMP);
- CollectionValue destinationsValue = (CollectionValue) destinationsMP.getValue();
- assertNotNull(destinationsValue);
- assertEquals(1, destinationsValue.getSize());
- GenericValue q1GV = (GenericValue) destinationsValue.getElements()[0];
- assertNotNull(q1GV);
-
- ManagedObject q1MO = (ManagedObject) q1GV.getValue();
- assertNotNull(q1MO);
- ManagedProperty domain = q1MO.getProperty("domain");
- getLog().info(domain);
- GenericValue domainGV = (GenericValue) domain.getValue();
- assertNotNull(domainGV);
- ManagedObject domainMO = (ManagedObject) domainGV.getValue();
- assertNotNull(domainMO);
-
- ManagedProperty domainName = domainMO.getProperty("domain");
- assertEquals(SimpleValueSupport.wrap("java:/jaas/JMS"), domainName.getValue());
-
- ManagedObject domainUpdateMO = initManagedObject(new SecurityDomain("java:/jaas/JMS2"));
- DefaultInstanceClassFactory icf = new DefaultInstanceClassFactory(mof);
- GenericValue domainUpdateGV = icf.getManagedObjectValue(domain, domainUpdateMO);
- assertNotNull(domainUpdateGV.getValue());
- domain.setValue(domainUpdateGV);
- // Validate this has been written through
- assertEquals("java:/jaas/JMS2", q1.getDomain().getDomain());
- }
-
- /**
- * Test the transformer value of the ManagementRuntimeRef annotation when
- * there is a custom ICF
- */
- public void testTransformer()
- {
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- mof.setInstanceClassFactory(ManagementObjectWithRuntimeRef.class, new ManagementObjectWithRuntimeRefICF());
- testMOF = mof;
-
- ManagementObjectWithRuntimeRef mowref = new ManagementObjectWithRuntimeRef();
- mowref.setRefName(new CustomName("jboss:test=testTransformer"));
- ManagedObject managedObject = initManagedObject(mowref);
- createManagedObject(ManagementObjectChangedName.class);
- assertEquals("jboss:test=testTransformer", managedObject.getComponentName());
- }
-
- /**
- * Test the
- * @throws Exception
- */
- public void testMCFHierarchy()
- throws Exception
- {
- ManagedConnectionFactoryDeploymentGroup mcf = initMCFDG();
- ManagedObjectFactory mof = getMOF();
- ManagedObject mcfMO = mof.initManagedObject(mcf, "ManagedConnectionFactoryDeploymentGroup", null);
- ManagedProperty deployments = mcfMO.getProperty("deployments");
- Object dvalue = deployments.getValue();
- assertTrue(dvalue.getClass()+"", dvalue instanceof CollectionValue);
- CollectionValue cv = (CollectionValue) dvalue;
- assertEquals(1, cv.getSize());
- Object cv0 = cv.iterator().next();
- assertTrue(cv0 instanceof GenericValue);
- GenericValue gv0 = (GenericValue) cv0;
- assertTrue(gv0.getValue() instanceof ManagedObject);
- ManagedObject mo = (ManagedObject) gv0.getValue();
- assertEquals(LocalDataSourceDeploymentMetaData.class.getName(), mo.getAttachmentName());
- assertEquals(mcfMO, mo.getParent());
-
- // Validate the security-domain
- ManagedProperty secDomain = mo.getProperty("security-domain");
- assertNotNull("security-domain", secDomain);
- GenericValue sdGV = (GenericValue) secDomain.getValue();
- assertNotNull("security-domain.GV", sdGV);
- ManagedObject secDomainMO = (ManagedObject) sdGV.getValue();
-
- assertNotNull("security-domain.MO", secDomainMO);
- assertEquals(mo, secDomainMO.getParent());
- ManagedProperty domainName = secDomainMO.getProperty("domain");
- assertNotNull("security-domain.MO.domain", domainName);
- assertEquals(SimpleValueSupport.wrap("java:/jaas/SomeDomain"), domainName.getValue());
- }
-
- /**
- * Test the custom ConnectionFactoryProperty used for the config-property of
- * ManagedConnectionFactoryDeploymentMetaData
- * @throws Exception
- */
- public void testManagedConnectionFactoryPropertyMetaData()
- throws Exception
- {
- ManagedConnectionFactoryDeploymentGroup mcf = initMCFDG();
- ManagedObjectFactory mof = getMOF();
- LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
- mof.addInstanceClassFactory(dsicf);
- ManagedObject mcfMO = mof.initManagedObject(mcf, "ManagedConnectionFactoryDeploymentGroup", null);
- ManagedProperty deployments = mcfMO.getProperty("deployments");
- Object dvalue = deployments.getValue();
- assertTrue(dvalue.getClass()+"", dvalue instanceof CollectionValue);
- CollectionValue cv = (CollectionValue) dvalue;
- assertEquals(1, cv.getSize());
- Object cv0 = cv.iterator().next();
- assertTrue(cv0 instanceof GenericValue);
- GenericValue gv0 = (GenericValue) cv0;
- assertTrue(gv0.getValue() instanceof ManagedObject);
- ManagedObject mo = (ManagedObject) gv0.getValue();
- assertEquals(LocalDataSourceDeploymentMetaData.class.getName(), mo.getAttachmentName());
-
- ManagedProperty cpMP = mo.getProperty("config-property");
- assertNotNull("config-property", cpMP);
- assertTrue("config-property("+cpMP+") isa ConnectionFactoryProperty", cpMP instanceof ConnectionFactoryProperty);
- MetaType type = cpMP.getMetaType();
- assertTrue("config-property type("+type+") is MapCompositeMetaType", type instanceof MapCompositeMetaType);
- MetaValue value = cpMP.getValue();
- assertTrue("config-property("+value+") MapCompositeMetaType.isValue", value instanceof CompositeValue);
- CompositeValue cvalue = (CompositeValue) value;
- SimpleValue connectionPropertiesValue = (SimpleValue) cvalue.get("value");
- assertEquals("cp1-name=cp1-value\ncp2-name=cp2-value", connectionPropertiesValue.getValue().toString().trim());
- assertEquals(SimpleValueSupport.wrap("java.lang.String"), cvalue.get("type"));
- }
-
- public void testKernelDeployment()
- {
- AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
- mof.setInstanceClassFactory(IBeanMetaData.class, new BeanMetaDataICF());
- testMOF = mof;
-
- AKernelDeployment ad = new AKernelDeployment();
- ABeanMetaData bean1 = new ABeanMetaData();
- bean1.setBean(Simple.class.getName());
- bean1.setName("SimpleBean#1");
- ABeanMetaData bean2 = new ABeanMetaData();
- bean2.setBean(Simple.class.getName());
- bean2.setName("SimpleBean#2");
-
- Simple simple1 = new Simple();
- simple1.setBigDecimalValue(new BigDecimal(123456));
- Simple simple2 = new Simple();
- simple2.setBigDecimalValue(new BigDecimal(222222));
- BeanMetaDataICF.setBean("SimpleBean#1", simple1);
- BeanMetaDataICF.setBean("SimpleBean#2", simple2);
- List<IBeanMetaDataFactory> beanFactories = new ArrayList<IBeanMetaDataFactory>();
- beanFactories.add(bean1);
- beanFactories.add(bean2);
- ad.setBeanFactories(beanFactories);
-
- ManagedObject mo = mof.initManagedObject(ad, "KernelDeployment", null);
- ManagedProperty beanFactoriesMP = mo.getProperty("beanFactories");
- assertNotNull("beanFactories MP", beanFactoriesMP);
- Object beanFactoriesMPValue = beanFactoriesMP.getValue();
- getLog().debug("beanFactories MP value: "+beanFactoriesMPValue);
- assertTrue(beanFactoriesMPValue instanceof CollectionValue);
- CollectionValue cv = CollectionValue.class.cast(beanFactoriesMPValue);
- MetaValue[] cvs = cv.getElements();
-
- assertEquals(2, cv.getSize());
- MetaValue mv0 = cvs[0];
- assertTrue(mv0 instanceof GenericValue);
- GenericValue gv0 = GenericValue.class.cast(mv0);
- Object gv0Value = gv0.getValue();
- assertTrue(gv0Value instanceof ManagedObject);
- ManagedObject mo0 = ManagedObject.class.cast(gv0Value);
- ManagedProperty bigDecimalValueMP = mo0.getProperty("bigDecimalValue");
- assertNotNull(bigDecimalValueMP);
- assertEquals(SimpleValueSupport.wrap(new BigDecimal(123456)), bigDecimalValueMP.getValue());
- bigDecimalValueMP.setValue(SimpleValueSupport.wrap(new BigDecimal(987654)));
- assertEquals(new BigDecimal(987654), simple1.getBigDecimalValue());
-
- MetaValue mv1 = cvs[1];
- assertTrue(mv1 instanceof GenericValue);
- GenericValue gv1 = GenericValue.class.cast(mv1);
- Object gv1Value = gv1.getValue();
- assertTrue(gv1Value instanceof ManagedObject);
- ManagedObject mo1 = ManagedObject.class.cast(gv1Value);
- ManagedProperty bigDecimalValueMP2 = mo1.getProperty("bigDecimalValue");
- assertNotNull(bigDecimalValueMP2);
- assertEquals(SimpleValueSupport.wrap(new BigDecimal(222222)), bigDecimalValueMP2.getValue());
- bigDecimalValueMP2.setValue(SimpleValueSupport.wrap(new BigDecimal(12222221)));
- assertEquals(new BigDecimal(12222221), simple2.getBigDecimalValue());
-
- }
-
- /**
- * Override to allow test specific ManagedObjectFactory
- */
- @Override
- protected ManagedObjectFactory getMOF()
- {
- ManagedObjectFactory mof = testMOF;
- if (mof == null)
- mof = super.getMOF();
- return mof;
- }
-
- protected ManagedConnectionFactoryDeploymentGroup initMCFDG()
- throws Exception
- {
- ManagedConnectionFactoryDeploymentGroup mcfs = new ManagedConnectionFactoryDeploymentGroup();
- LocalDataSourceDeploymentMetaData lds = new LocalDataSourceDeploymentMetaData();
- lds.setBackgroundValidation(true);
- lds.setBackgroundValidationMillis(5000);
- lds.setBlockingTimeoutMilliSeconds(5000);
- lds.setCheckValidConnectionSQL("select something from somewhere");
- lds.setConnectionDefinition("conn def");
- lds.setConnectionUrl("jdbc:xyz:a=b");
- DataSourceConnectionPropertyMetaData cp1 = new DataSourceConnectionPropertyMetaData();
- cp1.setName("cp1-name");
- cp1.setValue("cp1-value");
- DataSourceConnectionPropertyMetaData cp2 = new DataSourceConnectionPropertyMetaData();
- cp2.setName("cp2-name");
- cp2.setValue("cp2-value");
- DataSourceConnectionPropertyMetaData[] cps = {
- cp1, cp2
- };
- lds.setDataSourceConnectionProperties(Arrays.asList(cps));
- List<ManagedConnectionFactoryPropertyMetaData> mcps = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
- ManagedConnectionFactoryPropertyMetaData mcp1 = new ManagedConnectionFactoryPropertyMetaData();
- mcp1.setName("mcp1-name");
- mcp1.setValue("mcp1-value");
- mcp1.setType("java.lang.String");
- mcps.add(mcp1);
- ManagedConnectionFactoryPropertyMetaData mcp2 = new ManagedConnectionFactoryPropertyMetaData();
- mcp2.setName("mcp2-name");
- mcp2.setValue("mcp2-value");
- mcp2.setType("java.lang.String");
- mcps.add(mcp2);
- lds.setManagedConnectionFactoryProperties(mcps);
- lds.setDriverClass("org.jboss.jdbc.SomeDriver");
- lds.setExceptionSorterClassName("org.jboss.jdbc.SomeExceptionSorter");
- String[] depends = {"jboss:service=Naming", "jboss:service=Hypersonic,database=localDB"};
- lds.setDependsNames(Arrays.asList(depends));
- lds.setIdleTimeoutMinutes(15);
- lds.setInterleaving(false);
- lds.setMaxSize(100);
- lds.setMinSize(1);
- DBMSMetaData md = new DBMSMetaData();
- md.setTypeMapping("Hypersonic SQL");
- lds.setDBMSMetaData(md);
- lds.setNewConnectionSQL("run this on a new conn");
- lds.setPassWord("password");
- lds.setPrefill(true);
- lds.setPreparedStatementCacheSize(50);
- lds.setQueryTimeout(30000);
- lds.setUserName("user");
- // Set a SecurityMetaData to validate its MO
- SecurityMetaData smd = new SecurityMetaData();
- smd.setDomain("java:/jaas/SomeDomain");
- lds.setSecurityMetaData(smd);
-
- ManagedConnectionFactoryDeploymentMetaData[] mds = {lds};
- mcfs.setDeployments(Arrays.asList(mds));
- mcfs.setUrl(new URL("file:/deploy/some-ds.xml"));
- return mcfs;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java (from rev 84399, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/AbstractManagedObjectFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,538 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.managed.factory.test;
+
+import java.lang.annotation.Annotation;
+import java.math.BigDecimal;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.annotation.factory.AnnotationCreator;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.AbstractInstanceClassFactory;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.managed.plugins.factory.DefaultInstanceClassFactory;
+import org.jboss.managed.spi.factory.InstanceClassFactory;
+import org.jboss.metadata.plugins.loader.memory.MemoryMetaDataLoader;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrievalToMetaDataBridge;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ManagementObjectChangedName;
+import org.jboss.test.managed.factory.support.ManagementPropertySimpleManaged;
+import org.jboss.test.managed.factory.support.Simple;
+import org.jboss.test.managed.factory.support.SimpleUnannotated;
+import org.jboss.test.managed.factory.support.amof.CustomName;
+import org.jboss.test.managed.factory.support.amof.ManagementObjectWithRuntimeRef;
+import org.jboss.test.managed.factory.support.amof.ManagementObjectWithRuntimeRefICF;
+import org.jboss.test.managed.factory.support.amof.TestICF;
+import org.jboss.test.managed.factory.support.amof.TestMOP;
+import org.jboss.test.managed.factory.support.amof.TestSimpleICF;
+import org.jboss.test.managed.factory.support.beans.ABeanMetaData;
+import org.jboss.test.managed.factory.support.beans.AKernelDeployment;
+import org.jboss.test.managed.factory.support.beans.APropertyMetaData;
+import org.jboss.test.managed.factory.support.beans.BeanMetaDataICF;
+import org.jboss.test.managed.factory.support.beans.IBeanMetaData;
+import org.jboss.test.managed.factory.support.beans.IBeanMetaDataFactory;
+import org.jboss.test.managed.factory.support.deployment.JmsDestination;
+import org.jboss.test.managed.factory.support.deployment.JmsDestinationICF;
+import org.jboss.test.managed.factory.support.deployment.JmsDestinations;
+import org.jboss.test.managed.factory.support.deployment.QueueDestination;
+import org.jboss.test.managed.factory.support.deployment.SecurityDomain;
+import org.jboss.test.managed.factory.support.mcf.ConnectionFactoryProperty;
+import org.jboss.test.managed.factory.support.mcf.DBMSMetaData;
+import org.jboss.test.managed.factory.support.mcf.DataSourceConnectionPropertyMetaData;
+import org.jboss.test.managed.factory.support.mcf.LocalDSInstanceClassFactory;
+import org.jboss.test.managed.factory.support.mcf.LocalDataSourceDeploymentMetaData;
+import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentGroup;
+import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryDeploymentMetaData;
+import org.jboss.test.managed.factory.support.mcf.ManagedConnectionFactoryPropertyMetaData;
+import org.jboss.test.managed.factory.support.mcf.NoTxConnectionFactoryDeploymentMetaData;
+import org.jboss.test.managed.factory.support.mcf.NoTxICF;
+import org.jboss.test.managed.factory.support.mcf.SecurityMetaData;
+
+/**
+ * Test of behavior of the AbstractManagedObjectFactory
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class AbstractManagedObjectFactoryUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+ private ManagedObjectFactory testMOF;
+
+ public static Test suite()
+ {
+ return new TestSuite(AbstractManagedObjectFactoryUnitTestCase.class);
+ }
+
+ public AbstractManagedObjectFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test overriding the AbstractManagedObjectFactory.defaultInstanceFactory
+ */
+ public void testDefaultInstanceFactory()
+ {
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ mof.setDefaultInstanceFactory(new TestICF());
+ TestSimpleICF icf = new TestSimpleICF();
+ mof.setInstanceClassFactory(Simple.class, icf);
+ testMOF = mof;
+
+ BigDecimal bigDecimal = new BigDecimal(10);
+ Simple simple = new Simple();
+ simple.setBigDecimalValue(bigDecimal);
+
+ ManagedObject managedObject = initManagedObject(simple);
+ checkManagedObjectDefaults(Simple.class, managedObject);
+ checkDefaultManagedProperties(managedObject, Simple.class);
+
+ checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
+ assertTrue("TestBigDecimalICF.isGetValueCalled", icf.isGetValueCalled());
+
+ //
+ managedObject = super.createManagedObject(ManagementPropertySimpleManaged.class);
+ checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
+ checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
+ }
+
+ /**
+ * Test that the setDefaultManagedObjectPopulator overrides the MOF
+ * default ManagedObjectPopulator
+ */
+ public void testDefaultManagedObjectPopulator()
+ {
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ TestMOP mop = new TestMOP(mof.getConfiguration(), new TestSimpleICF(), mof.getInstanceFactories());
+ mof.setDefaultManagedObjectPopulator(mop);
+ testMOF = mof;
+
+ BigDecimal bigDecimal = new BigDecimal(10);
+ Simple simple = new Simple();
+ simple.setBigDecimalValue(bigDecimal);
+
+ ManagedObject managedObject = initManagedObject(simple);
+ checkManagedObjectDefaults(Simple.class, managedObject);
+ checkDefaultManagedProperties(managedObject, Simple.class);
+ checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
+ assertTrue("isPopulateManagedObjectCalled", mop.isPopulateManagedObjectCalled());
+ //
+ managedObject = createManagedObject(ManagementPropertySimpleManaged.class);
+ checkManagedObjectDefaults(ManagementPropertySimpleManaged.class, managedObject);
+ checkDefaultManagedProperties(managedObject, ManagementPropertySimpleManaged.class);
+ assertTrue("isCreateObjectCalled", mop.isCreateObjectCalled());
+
+ }
+
+ public void testInstanceClassFactoryAddition()
+ {
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ testMOF = mof;
+
+ BeanMetaDataICF bicf = new BeanMetaDataICF();
+ mof.addInstanceClassFactory(bicf);
+ LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
+ mof.addInstanceClassFactory(dsicf);
+ NoTxICF nticf = new NoTxICF();
+ mof.addInstanceClassFactory(nticf);
+
+ InstanceClassFactory icf = mof.getInstanceClassFactory(IBeanMetaData.class);
+ assertEquals("IBeanMetaData ICF", bicf, icf);
+ icf = mof.getInstanceClassFactory(LocalDataSourceDeploymentMetaData.class);
+ assertEquals("LocalDataSourceDeploymentMetaData ICF", dsicf, icf);
+ icf = mof.getInstanceClassFactory(NoTxConnectionFactoryDeploymentMetaData.class);
+ assertEquals("NoTxConnectionFactoryDeploymentMetaData ICF", nticf, icf);
+ }
+
+ /**
+ * Test that the MetaData repository annotations override/augment the class
+ * annotations.
+ */
+ public void testMetaDataRepositoryOverride()
+ throws Exception
+ {
+ MemoryMetaDataLoader memory = new MemoryMetaDataLoader();
+ String annotationExpr = "@org.jboss.managed.api.annotation.ManagementObject(name=\"testMetaDataRepositoryOverride\",componentType=@org.jboss.managed.api.annotation.ManagementComponent(type=\"MCBean\", subtype=\"MetaDataTest\"))";
+ ManagementObject override = (ManagementObject) AnnotationCreator.createAnnotation(annotationExpr, ManagementObject.class);
+ memory.addAnnotation(override);
+ MetaData metaData = new MetaDataRetrievalToMetaDataBridge(memory);
+
+ BigDecimal bigDecimal = new BigDecimal(10);
+ SimpleUnannotated simple = new SimpleUnannotated();
+ simple.setBigDecimalValue(bigDecimal);
+
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject managedObject = mof.initManagedObject(simple, metaData);
+ assertEquals("testMetaDataRepositoryOverride", managedObject.getName());
+ Map<String, Annotation> moAnnotations = managedObject.getAnnotations();
+ assertEquals("MO annotations == 2;", 2, moAnnotations.size());
+ ManagementObject moAnn = (ManagementObject) moAnnotations.get(ManagementObject.class.getName());
+ ManagementComponent componentType = moAnn.componentType();
+ assertEquals("componentType.type", "MCBean", componentType.type());
+ assertEquals("componentType.subtype", "MetaDataTest", componentType.subtype());
+ checkPropertyDefaults(managedObject, "bigDecimalValue", BigDecimal.class, bigDecimal);
+ checkDefaultManagedProperties(managedObject, SimpleUnannotated.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testGenericValueUpdate()
+ {
+ super.enableTrace("org.jboss.managed");
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ mof.setInstanceClassFactory(JmsDestination.class, new JmsDestinationICF(mof));
+ testMOF = mof;
+
+ JmsDestinations destinations = new JmsDestinations();
+ List<JmsDestination> queues = new ArrayList<JmsDestination>();
+ QueueDestination q1 = new QueueDestination();
+ q1.setJndiName("queues/Q1");
+ q1.setDomain(new SecurityDomain("java:/jaas/JMS"));
+ queues.add(q1);
+ destinations.setDestinations(queues);
+
+ ManagedObject managedObject = initManagedObject(destinations);
+ checkManagedObjectDefaults(JmsDestinations.class, managedObject);
+
+ ManagedProperty destinationsMP = managedObject.getProperty("destinations");
+ assertNotNull(destinationsMP);
+ CollectionValue destinationsValue = (CollectionValue) destinationsMP.getValue();
+ assertNotNull(destinationsValue);
+ assertEquals(1, destinationsValue.getSize());
+ GenericValue q1GV = (GenericValue) destinationsValue.getElements()[0];
+ assertNotNull(q1GV);
+
+ ManagedObject q1MO = (ManagedObject) q1GV.getValue();
+ assertNotNull(q1MO);
+ ManagedProperty domain = q1MO.getProperty("domain");
+ getLog().info(domain);
+ GenericValue domainGV = (GenericValue) domain.getValue();
+ assertNotNull(domainGV);
+ ManagedObject domainMO = (ManagedObject) domainGV.getValue();
+ assertNotNull(domainMO);
+
+ ManagedProperty domainName = domainMO.getProperty("domain");
+ assertEquals(SimpleValueSupport.wrap("java:/jaas/JMS"), domainName.getValue());
+
+ ManagedObject domainUpdateMO = initManagedObject(new SecurityDomain("java:/jaas/JMS2"));
+ DefaultInstanceClassFactory icf = new DefaultInstanceClassFactory(mof);
+ GenericValue domainUpdateGV = icf.getManagedObjectValue(domain, domainUpdateMO);
+ assertNotNull(domainUpdateGV.getValue());
+ domain.setValue(domainUpdateGV);
+ // Validate this has been written through
+ assertEquals("java:/jaas/JMS2", q1.getDomain().getDomain());
+ }
+
+ /**
+ * Test the transformer value of the ManagementRuntimeRef annotation when
+ * there is a custom ICF
+ */
+ public void testTransformer()
+ {
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ mof.setInstanceClassFactory(ManagementObjectWithRuntimeRef.class, new ManagementObjectWithRuntimeRefICF());
+ testMOF = mof;
+
+ ManagementObjectWithRuntimeRef mowref = new ManagementObjectWithRuntimeRef();
+ mowref.setRefName(new CustomName("jboss:test=testTransformer"));
+ ManagedObject managedObject = initManagedObject(mowref);
+ createManagedObject(ManagementObjectChangedName.class);
+ assertEquals("jboss:test=testTransformer", managedObject.getComponentName());
+ }
+
+ /**
+ * Test the
+ * @throws Exception
+ */
+ public void testMCFHierarchy()
+ throws Exception
+ {
+ ManagedConnectionFactoryDeploymentGroup mcf = initMCFDG();
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mcfMO = mof.initManagedObject(mcf, "ManagedConnectionFactoryDeploymentGroup", null);
+ ManagedProperty deployments = mcfMO.getProperty("deployments");
+ Object dvalue = deployments.getValue();
+ assertTrue(dvalue.getClass()+"", dvalue instanceof CollectionValue);
+ CollectionValue cv = (CollectionValue) dvalue;
+ assertEquals(1, cv.getSize());
+ Object cv0 = cv.iterator().next();
+ assertTrue(cv0 instanceof GenericValue);
+ GenericValue gv0 = (GenericValue) cv0;
+ assertTrue(gv0.getValue() instanceof ManagedObject);
+ ManagedObject mo = (ManagedObject) gv0.getValue();
+ assertEquals(LocalDataSourceDeploymentMetaData.class.getName(), mo.getAttachmentName());
+ assertEquals(mcfMO, mo.getParent());
+
+ // Validate the security-domain
+ ManagedProperty secDomain = mo.getProperty("security-domain");
+ assertNotNull("security-domain", secDomain);
+ GenericValue sdGV = (GenericValue) secDomain.getValue();
+ assertNotNull("security-domain.GV", sdGV);
+ ManagedObject secDomainMO = (ManagedObject) sdGV.getValue();
+
+ assertNotNull("security-domain.MO", secDomainMO);
+ assertEquals(mo, secDomainMO.getParent());
+ ManagedProperty domainName = secDomainMO.getProperty("domain");
+ assertNotNull("security-domain.MO.domain", domainName);
+ assertEquals(SimpleValueSupport.wrap("java:/jaas/SomeDomain"), domainName.getValue());
+ }
+
+ /**
+ * Test the custom ConnectionFactoryProperty used for the config-property of
+ * ManagedConnectionFactoryDeploymentMetaData
+ * @throws Exception
+ */
+ public void testManagedConnectionFactoryPropertyMetaData()
+ throws Exception
+ {
+ ManagedConnectionFactoryDeploymentGroup mcf = initMCFDG();
+ ManagedObjectFactory mof = getMOF();
+ LocalDSInstanceClassFactory dsicf = new LocalDSInstanceClassFactory();
+ mof.addInstanceClassFactory(dsicf);
+ ManagedObject mcfMO = mof.initManagedObject(mcf, "ManagedConnectionFactoryDeploymentGroup", null);
+ ManagedProperty deployments = mcfMO.getProperty("deployments");
+ Object dvalue = deployments.getValue();
+ assertTrue(dvalue.getClass()+"", dvalue instanceof CollectionValue);
+ CollectionValue cv = (CollectionValue) dvalue;
+ assertEquals(1, cv.getSize());
+ Object cv0 = cv.iterator().next();
+ assertTrue(cv0 instanceof GenericValue);
+ GenericValue gv0 = (GenericValue) cv0;
+ assertTrue(gv0.getValue() instanceof ManagedObject);
+ ManagedObject mo = (ManagedObject) gv0.getValue();
+ assertEquals(LocalDataSourceDeploymentMetaData.class.getName(), mo.getAttachmentName());
+
+ ManagedProperty cpMP = mo.getProperty("config-property");
+ assertNotNull("config-property", cpMP);
+ assertTrue("config-property("+cpMP+") isa ConnectionFactoryProperty", cpMP instanceof ConnectionFactoryProperty);
+ MetaType type = cpMP.getMetaType();
+ assertTrue("config-property type("+type+") is MapCompositeMetaType", type instanceof MapCompositeMetaType);
+ MetaValue value = cpMP.getValue();
+ assertTrue("config-property("+value+") MapCompositeMetaType.isValue", value instanceof CompositeValue);
+ CompositeValue cvalue = (CompositeValue) value;
+ SimpleValue connectionPropertiesValue = (SimpleValue) cvalue.get("value");
+ assertEquals("cp1-name=cp1-value\ncp2-name=cp2-value", connectionPropertiesValue.getValue().toString().trim());
+ assertEquals(SimpleValueSupport.wrap("java.lang.String"), cvalue.get("type"));
+ }
+
+ public void testKernelDeployment()
+ {
+ AbstractManagedObjectFactory mof = new AbstractManagedObjectFactory();
+ BeanMetaDataICF icf = new BeanMetaDataICF();
+ icf.setDelegateICF(new DefaultInstanceClassFactory(mof));
+ mof.setInstanceClassFactory(IBeanMetaData.class, icf);
+ testMOF = mof;
+
+ AKernelDeployment ad = new AKernelDeployment();
+ ABeanMetaData bean1 = new ABeanMetaData();
+ bean1.setBean(Simple.class.getName());
+ bean1.setName("SimpleBean#1");
+ ABeanMetaData bean2 = new ABeanMetaData();
+ bean2.setBean(Simple.class.getName());
+ bean2.setName("SimpleBean#2");
+ ABeanMetaData bean3 = new ABeanMetaData();
+ bean3.setBean(SimpleUnannotated.class.getName());
+ bean3.setName("SimpleUnannotated#3");
+ APropertyMetaData bean3P1 = new APropertyMetaData();
+ bean3P1.setName("properties");
+ bean3P1.setDescription("The bean properties");
+ bean3P1.setPropertyType("java.util.Set<IPropertyMetaData>");
+ bean3.addProperty(bean3P1);
+
+ Simple simple1 = new Simple();
+ simple1.setBigDecimalValue(new BigDecimal(123456));
+ Simple simple2 = new Simple();
+ simple2.setBigDecimalValue(new BigDecimal(222222));
+ SimpleUnannotated simple3 = new SimpleUnannotated();
+ simple3.setBigDecimalValue(new BigDecimal(333333));
+ // Setup the bean name mappings
+ BeanMetaDataICF.setBean("SimpleBean#1", simple1);
+ BeanMetaDataICF.setBean("SimpleBean#2", simple2);
+ BeanMetaDataICF.setBean("SimpleUnannotated#3", simple3);
+ List<IBeanMetaDataFactory> beanFactories = new ArrayList<IBeanMetaDataFactory>();
+ beanFactories.add(bean1);
+ beanFactories.add(bean2);
+ beanFactories.add(bean3);
+ ad.setBeanFactories(beanFactories);
+
+ ManagedObject mo = mof.initManagedObject(ad, "KernelDeployment", null);
+ ManagedProperty beanFactoriesMP = mo.getProperty("beanFactories");
+ assertNotNull("beanFactories MP", beanFactoriesMP);
+ Object beanFactoriesMPValue = beanFactoriesMP.getValue();
+ getLog().debug("beanFactories MP value: "+beanFactoriesMPValue);
+ assertTrue(beanFactoriesMPValue instanceof CollectionValue);
+ // The beanFactories
+ CollectionValue cv = CollectionValue.class.cast(beanFactoriesMPValue);
+ MetaValue[] cvs = cv.getElements();
+
+
+ assertEquals(3, cv.getSize());
+ // ABeanMetaData ManagedObject for SimpleBean#1
+ MetaValue mv0 = cvs[0];
+ assertTrue(mv0 instanceof GenericValue);
+ GenericValue gv0 = GenericValue.class.cast(mv0);
+ Object gv0Value = gv0.getValue();
+ assertTrue(gv0Value instanceof ManagedObject);
+ ManagedObject mo0 = ManagedObject.class.cast(gv0Value);
+ assertEquals(bean1, mo0.getAttachment());
+ ManagedProperty bigDecimalValueMP = mo0.getProperty("bigDecimalValue");
+ assertNotNull(bigDecimalValueMP);
+ assertEquals(SimpleValueSupport.wrap(new BigDecimal(123456)), bigDecimalValueMP.getValue());
+ bigDecimalValueMP.setValue(SimpleValueSupport.wrap(new BigDecimal(987654)));
+ assertEquals(new BigDecimal(987654), simple1.getBigDecimalValue());
+
+ // ABeanMetaData ManagedObject for SimpleBean#2
+ MetaValue mv1 = cvs[1];
+ assertTrue(mv1 instanceof GenericValue);
+ GenericValue gv1 = GenericValue.class.cast(mv1);
+ Object gv1Value = gv1.getValue();
+ assertTrue(gv1Value instanceof ManagedObject);
+ ManagedObject mo1 = ManagedObject.class.cast(gv1Value);
+ ManagedProperty bigDecimalValueMP1 = mo1.getProperty("bigDecimalValue");
+ assertNotNull(bigDecimalValueMP1);
+ assertEquals(SimpleValueSupport.wrap(new BigDecimal(222222)), bigDecimalValueMP1.getValue());
+ bigDecimalValueMP1.setValue(SimpleValueSupport.wrap(new BigDecimal(12222221)));
+ assertEquals(new BigDecimal(12222221), simple2.getBigDecimalValue());
+
+ // ABeanMetaData ManagedObject for SimpleUnannotated#3
+ MetaValue mv2 = cvs[2];
+ assertTrue(mv2 instanceof GenericValue);
+ GenericValue gv2 = GenericValue.class.cast(mv2);
+ Object gv2Value = gv2.getValue();
+ assertTrue(gv2Value instanceof ManagedObject);
+ ManagedObject mo2 = ManagedObject.class.cast(gv2Value);
+ ManagedProperty properties = mo2.getProperty("properties");
+ assertNotNull(properties);
+ assertTrue(properties.getMetaType().isCollection());
+ CollectionMetaType amt = (CollectionMetaType) properties.getMetaType();
+ MetaType etype = amt.getElementType();
+ if (etype == AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE)
+ {
+ CollectionValue avalue = (CollectionValue) properties.getValue();
+ assertNotNull(avalue);
+ MetaValue[] elements = avalue.getElements();
+ for(int n = 0; n < avalue.getSize(); n ++)
+ {
+ GenericValue gv = (GenericValue) elements[n];
+ ManagedObject propMO = (ManagedObject) gv.getValue();
+ //...
+ }
+ }
+
+
+ }
+
+ /**
+ * Override to allow test specific ManagedObjectFactory
+ */
+ @Override
+ protected ManagedObjectFactory getMOF()
+ {
+ ManagedObjectFactory mof = testMOF;
+ if (mof == null)
+ mof = super.getMOF();
+ return mof;
+ }
+
+ protected ManagedConnectionFactoryDeploymentGroup initMCFDG()
+ throws Exception
+ {
+ ManagedConnectionFactoryDeploymentGroup mcfs = new ManagedConnectionFactoryDeploymentGroup();
+ LocalDataSourceDeploymentMetaData lds = new LocalDataSourceDeploymentMetaData();
+ lds.setBackgroundValidation(true);
+ lds.setBackgroundValidationMillis(5000);
+ lds.setBlockingTimeoutMilliSeconds(5000);
+ lds.setCheckValidConnectionSQL("select something from somewhere");
+ lds.setConnectionDefinition("conn def");
+ lds.setConnectionUrl("jdbc:xyz:a=b");
+ DataSourceConnectionPropertyMetaData cp1 = new DataSourceConnectionPropertyMetaData();
+ cp1.setName("cp1-name");
+ cp1.setValue("cp1-value");
+ DataSourceConnectionPropertyMetaData cp2 = new DataSourceConnectionPropertyMetaData();
+ cp2.setName("cp2-name");
+ cp2.setValue("cp2-value");
+ DataSourceConnectionPropertyMetaData[] cps = {
+ cp1, cp2
+ };
+ lds.setDataSourceConnectionProperties(Arrays.asList(cps));
+ List<ManagedConnectionFactoryPropertyMetaData> mcps = new ArrayList<ManagedConnectionFactoryPropertyMetaData>();
+ ManagedConnectionFactoryPropertyMetaData mcp1 = new ManagedConnectionFactoryPropertyMetaData();
+ mcp1.setName("mcp1-name");
+ mcp1.setValue("mcp1-value");
+ mcp1.setType("java.lang.String");
+ mcps.add(mcp1);
+ ManagedConnectionFactoryPropertyMetaData mcp2 = new ManagedConnectionFactoryPropertyMetaData();
+ mcp2.setName("mcp2-name");
+ mcp2.setValue("mcp2-value");
+ mcp2.setType("java.lang.String");
+ mcps.add(mcp2);
+ lds.setManagedConnectionFactoryProperties(mcps);
+ lds.setDriverClass("org.jboss.jdbc.SomeDriver");
+ lds.setExceptionSorterClassName("org.jboss.jdbc.SomeExceptionSorter");
+ String[] depends = {"jboss:service=Naming", "jboss:service=Hypersonic,database=localDB"};
+ lds.setDependsNames(Arrays.asList(depends));
+ lds.setIdleTimeoutMinutes(15);
+ lds.setInterleaving(false);
+ lds.setMaxSize(100);
+ lds.setMinSize(1);
+ DBMSMetaData md = new DBMSMetaData();
+ md.setTypeMapping("Hypersonic SQL");
+ lds.setDBMSMetaData(md);
+ lds.setNewConnectionSQL("run this on a new conn");
+ lds.setPassWord("password");
+ lds.setPrefill(true);
+ lds.setPreparedStatementCacheSize(50);
+ lds.setQueryTimeout(30000);
+ lds.setUserName("user");
+ // Set a SecurityMetaData to validate its MO
+ SecurityMetaData smd = new SecurityMetaData();
+ smd.setDomain("java:/jaas/SomeDomain");
+ lds.setSecurityMetaData(smd);
+
+ ManagedConnectionFactoryDeploymentMetaData[] mds = {lds};
+ mcfs.setDeployments(Arrays.asList(mds));
+ mcfs.setUrl(new URL("file:/deploy/some-ds.xml"));
+ return mcfs;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,87 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.managed.factory.test;
-
-import junit.framework.Test;
-
-import org.jboss.managed.api.DeploymentTemplateInfo;
-import org.jboss.managed.api.ManagedObject;
-import org.jboss.managed.plugins.factory.DeploymentTemplateInfoFactory;
-import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
-import org.jboss.test.managed.factory.support.template.ManagementObjectExplicit;
-
-
-/**
- * DeploymentTemplateInfo factory tests.
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class DeploymentTemplateInfoUnitTestCase extends AbstractManagedObjectFactoryTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(DeploymentTemplateInfoUnitTestCase.class);
- }
-
- /**
- * Create a new DeploymentTemplateInfoUnitTestCase.
- *
- * @param name the test name
- */
- public DeploymentTemplateInfoUnitTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Test Explicit properties included
- */
- public void testExplicit()
- {
- ManagedObject managedObject = createManagedObject(ManagementObjectExplicit.class);
- checkManagedObjectDefaults(ManagementObjectExplicit.class, managedObject);
- checkManagedProperties(managedObject, "property1");
- DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
- DeploymentTemplateInfo info = factory.createTemplateInfo(managedObject, "testExplicit", "testExplicit");
- log.info(info);
- assertEquals("testExplicit", info.getName());
- assertEquals("testExplicit", info.getDescription());
- assertTrue("property1 is in template info", info.getProperties().containsKey("property1"));
- }
- public void testReflectionOfExplicit()
- throws Exception
- {
- DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
- DeploymentTemplateInfo info = factory.createTemplateInfo(ManagementObjectExplicit.class, "testReflectionOfExplicit", "testReflectionOfExplicit");
- log.info(info);
- assertEquals("testReflectionOfExplicit", info.getName());
- assertEquals("testReflectionOfExplicit", info.getDescription());
- assertTrue("property1 is in template info", info.getProperties().containsKey("property1"));
- }
-
-}
\ No newline at end of file
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java (from rev 85281, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/DeploymentTemplateInfoUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,150 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed.factory.test;
+
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.plugins.factory.DeploymentTemplateInfoFactory;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.JmsDestinationTemplateInfo;
+import org.jboss.test.managed.factory.support.template.ManagementObjectExplicit;
+
+
+/**
+ * DeploymentTemplateInfo factory tests.
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DeploymentTemplateInfoUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(DeploymentTemplateInfoUnitTestCase.class);
+ }
+
+ /**
+ * Create a new DeploymentTemplateInfoUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public DeploymentTemplateInfoUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test Explicit properties included
+ */
+ public void testExplicit()
+ {
+ ManagedObject managedObject = createManagedObject(ManagementObjectExplicit.class);
+ checkManagedObjectDefaults(ManagementObjectExplicit.class, managedObject);
+ checkManagedProperties(managedObject, "property1");
+ DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
+ DeploymentTemplateInfo info = factory.createTemplateInfo(managedObject, "testExplicit", "testExplicit");
+ log.info(info);
+ assertEquals("testExplicit", info.getName());
+ assertEquals("testExplicit", info.getDescription());
+ assertTrue("property1 is in template info", info.getProperties().containsKey("property1"));
+ }
+ public void testReflectionOfExplicit()
+ throws Exception
+ {
+ DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
+ DeploymentTemplateInfo info = factory.createTemplateInfo(ManagementObjectExplicit.class, "testReflectionOfExplicit", "testReflectionOfExplicit");
+ log.info(info);
+ assertEquals("testReflectionOfExplicit", info.getName());
+ assertEquals("testReflectionOfExplicit", info.getDescription());
+ assertTrue("property1 is in template info", info.getProperties().containsKey("property1"));
+ }
+
+ public void testCopy()
+ {
+ ManagementObjectExplicit explicit = new ManagementObjectExplicit();
+ explicit.setProperty1("value1-orig");
+ ManagedObject managedObject = super.initManagedObject(explicit);
+
+ DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
+ DeploymentTemplateInfo info1 = factory.createTemplateInfo(managedObject, "testExplicit", "testExplicit");
+ log.info(info1);
+ assertEquals("testExplicit", info1.getName());
+ assertEquals("testExplicit", info1.getDescription());
+ assertTrue("property1 is in template info", info1.getProperties().containsKey("property1"));
+ ManagedProperty property1 = managedObject.getProperty("property1");
+
+ DeploymentTemplateInfo info1_1 = info1.copy();
+ log.info(info1);
+ assertEquals("testExplicit", info1.getName());
+ assertEquals("testExplicit", info1.getDescription());
+ assertTrue("property1 is in template info", info1.getProperties().containsKey("property1"));
+
+ Map<String, ManagedProperty> props1 = info1.getProperties();
+ ManagedProperty iproperty1 = props1.get("property1");
+ assertNotNull(iproperty1);
+ iproperty1.setValue(SimpleValueSupport.wrap("value1-copy"));
+
+ Map<String, ManagedProperty> props1_1 = info1_1.getProperties();
+ assertTrue("info1.props != info1_1.props", props1 != props1_1);
+ assertEquals("props size", props1.size(), props1_1.size());
+ ManagedProperty iproperty1_1 = props1_1.get("property1");
+ assertNotNull("info1.copy property1", iproperty1_1);
+ assertTrue("property1 != property1_1", iproperty1 != iproperty1_1);
+ assertTrue(property1.getFields() != iproperty1_1.getFields());
+ MetaValue value1 = iproperty1.getValue();
+ MetaValue value1_1 = iproperty1_1.getValue();
+ assertTrue(value1 != value1_1);
+ assertEquals("property1.value", SimpleValueSupport.wrap("value1-copy"), value1);
+ assertEquals("property1_1.value", SimpleValueSupport.wrap("value1-orig"), value1_1);
+ }
+
+ public void testSubclassCopy()
+ {
+ JmsDestinationTemplateInfo info = new JmsDestinationTemplateInfo("testSubclassCopy", "testSubclassCopy", "queue");
+ ManagedProperty jndiName = info.getProperties().get("JNDIName");
+ jndiName.setValue(SimpleValueSupport.wrap("testSubclassCopy"));
+ JmsDestinationTemplateInfo info2 = info.copy();
+ jndiName.setValue(SimpleValueSupport.wrap("testSubclassCopy-updated"));
+ ManagedProperty jndiName2 = info2.getProperties().get("JNDIName");
+ MetaValue value = jndiName.getValue();
+ MetaValue value2 = jndiName2.getValue();
+
+ assertTrue(info.getProperties() != info2.getProperties());
+ assertTrue(jndiName != jndiName2);
+ assertTrue(jndiName.getFields() != jndiName2.getFields());
+ assertTrue(value != value2);
+ assertEquals("jndiName", SimpleValueSupport.wrap("testSubclassCopy-updated"), jndiName.getValue());
+ assertEquals("jndiName2", SimpleValueSupport.wrap("testSubclassCopy"), value2);
+ }
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/PlatformMBeanUnitTestCase.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/factory/test/PlatformMBeanUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/PlatformMBeanUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/factory/test/PlatformMBeanUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,522 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed.factory.test;
+
+import java.lang.annotation.Annotation;
+import java.lang.management.ClassLoadingMXBean;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryUsage;
+import java.lang.management.OperatingSystemMXBean;
+import java.lang.management.RuntimeMXBean;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+
+import junit.framework.Test;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedOperation;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementComponent;
+import org.jboss.managed.api.annotation.ManagementOperation;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.ManagedOperationMatcher;
+import org.jboss.managed.plugins.jmx.CompositeDataMetaValueBuilder;
+import org.jboss.managed.plugins.jmx.ManagementFactoryUtils;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.test.managed.factory.AbstractManagedObjectFactoryTest;
+import org.jboss.test.managed.factory.support.ManagementObjectChangedName;
+import org.jboss.test.managed.factory.support.amof.CustomName;
+import org.jboss.test.managed.factory.support.amof.ManagementObjectWithRuntimeRef;
+
+/**
+ * Tests of creating ManagedObjects for the jvm platform mbeans
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1.1 $
+ */
+public class PlatformMBeanUnitTestCase extends AbstractManagedObjectFactoryTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(PlatformMBeanUnitTestCase.class);
+ }
+
+ /**
+ * Create a new ManagementObjectUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public PlatformMBeanUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the transformer value of the annotation
+ */
+ public void testClassLoadingMXBean()
+ {
+ super.enableTrace("org.jboss.managed.plugins.factory");
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mo = ManagementFactoryUtils.getClassLoadingMO(mof);
+ assertNotNull(mo);
+ assertEquals(ManagementFactory.CLASS_LOADING_MXBEAN_NAME, mo.getName());
+ validateComponentType(mo);
+ assertEquals(ManagementFactory.CLASS_LOADING_MXBEAN_NAME, mo.getComponentName());
+
+ Map<String, ManagedProperty> props = mo.getProperties();
+ assertNotNull(props);
+ // totalLoadedClassCount
+ ManagedProperty totalLoadedClassCount = props.get("totalLoadedClassCount");
+ assertNotNull(totalLoadedClassCount);
+ assertEquals(SimpleMetaType.LONG_PRIMITIVE, totalLoadedClassCount.getMetaType());
+ assertEquals("the total number of classes loaded.", totalLoadedClassCount.getDescription());
+ SimpleValue totalLoadedClassCountSV = SimpleValue.class.cast(totalLoadedClassCount.getValue());
+ assertNotNull(totalLoadedClassCountSV);
+ getLog().debug("totalLoadedClassCountSV"+totalLoadedClassCountSV);
+ SimpleValue sv1 = SimpleValueSupport.wrap(new Long(100));
+ assertTrue("> 100 classes loaded", sv1.compareTo(totalLoadedClassCountSV) < 0);
+ // loadedClassCount
+ ManagedProperty loadedClassCount = props.get("loadedClassCount");
+ assertNotNull(loadedClassCount);
+ assertEquals(SimpleMetaType.INTEGER_PRIMITIVE, loadedClassCount.getMetaType());
+ assertEquals("the number of currently loaded classes.", loadedClassCount.getDescription());
+ SimpleValue loadedClassCountSV = SimpleValue.class.cast(loadedClassCount.getValue());
+ assertNotNull(loadedClassCountSV);
+ getLog().debug("loadedClassCountSV"+loadedClassCountSV);
+ assertTrue("> 100 classes loaded", sv1.compareTo(loadedClassCountSV) < 0);
+ // unloadedClassCount
+ ManagedProperty unloadedClassCount = props.get("unloadedClassCount");
+ assertNotNull(unloadedClassCount);
+ assertEquals(SimpleMetaType.LONG_PRIMITIVE, unloadedClassCount.getMetaType());
+ assertEquals("the total number of unloaded classes.", unloadedClassCount.getDescription());
+ SimpleValue unloadedClassCountSV = SimpleValue.class.cast(unloadedClassCount.getValue());
+ assertNotNull(unloadedClassCountSV);
+ getLog().debug("unloadedClassCountSV"+unloadedClassCountSV);
+ // verbose
+ ManagedProperty verbose = props.get("verbose");
+ assertNotNull(verbose);
+ assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, verbose.getMetaType());
+ assertEquals("the verbose output flag for the class loading system.", verbose.getDescription());
+ SimpleValue verboseSV = SimpleValue.class.cast(verbose.getValue());
+ assertNotNull(verboseSV);
+ getLog().debug("verboseSV"+verboseSV);
+
+ }
+
+ public void testMemoryMXBean()
+ {
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mo = ManagementFactoryUtils.getMemoryMXBean(mof);
+ assertNotNull(mo);
+ assertEquals(ManagementFactory.MEMORY_MXBEAN_NAME, mo.getName());
+ validateComponentType(mo);
+
+ Map<String, ManagedProperty> props = mo.getProperties();
+ assertNotNull(props);
+
+ // heapMemoryUsage
+ ManagedProperty heapMemoryUsage = props.get("heapMemoryUsage");
+ assertNotNull(heapMemoryUsage);
+ assertEquals("object representing the heap memory usage.", heapMemoryUsage.getDescription());
+ CompositeValue heapMemoryUsageMV = CompositeValue.class.cast(heapMemoryUsage.getValue());
+ assertNotNull(heapMemoryUsageMV);
+ getLog().debug("heapMemoryUsageMV; "+heapMemoryUsageMV);
+ MemoryUsage heapMemoryUsageMU = ManagementFactoryUtils.unwrapMemoryUsage(heapMemoryUsageMV);
+ assertTrue(heapMemoryUsageMU.getInit() >= 0);
+ assertTrue(heapMemoryUsageMU.getUsed() >= 1000);
+ assertTrue(heapMemoryUsageMU.getMax() >= heapMemoryUsageMU.getCommitted());
+ assertTrue(heapMemoryUsageMU.getCommitted() >= heapMemoryUsageMU.getUsed());
+
+ // nonHeapMemoryUsage
+ ManagedProperty nonHeapMemoryUsage = props.get("nonHeapMemoryUsage");
+ assertNotNull(nonHeapMemoryUsage);
+ assertEquals("object representing the non-heap memory usage.", nonHeapMemoryUsage.getDescription());
+ CompositeValue nonHeapMemoryUsageMV = CompositeValue.class.cast(nonHeapMemoryUsage.getValue());
+ assertNotNull(nonHeapMemoryUsageMV);
+ getLog().debug("nonHeapMemoryUsageMV; "+nonHeapMemoryUsageMV);
+ MemoryUsage nonHeapMemoryUsageMU = ManagementFactoryUtils.unwrapMemoryUsage(nonHeapMemoryUsageMV);
+ assertTrue(nonHeapMemoryUsageMU.getInit() >= 0);
+ assertTrue(nonHeapMemoryUsageMU.getUsed() >= 1000);
+ assertTrue(nonHeapMemoryUsageMU.getMax() >= nonHeapMemoryUsageMU.getCommitted());
+ assertTrue(nonHeapMemoryUsageMU.getCommitted() >= nonHeapMemoryUsageMU.getUsed());
+ // objectPendingFinalizationCount
+ ManagedProperty objectPendingFinalizationCount = props.get("objectPendingFinalizationCount");
+ assertNotNull(objectPendingFinalizationCount);
+ assertEquals("the approximate number objects for which finalization is pending.", objectPendingFinalizationCount.getDescription());
+ MetaValue objectPendingFinalizationCountMV = objectPendingFinalizationCount.getValue();
+ assertNotNull(objectPendingFinalizationCountMV);
+ getLog().debug("objectPendingFinalizationCountMV; "+objectPendingFinalizationCountMV);
+
+ // verbose
+ ManagedProperty verbose = props.get("verbose");
+ assertNotNull(verbose);
+ assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, verbose.getMetaType());
+ assertEquals("the verbose output flag for the memory system.", verbose.getDescription());
+ SimpleValue verboseSV = SimpleValue.class.cast(verbose.getValue());
+ assertNotNull(verboseSV);
+ getLog().debug("verboseSV; "+verboseSV);
+
+ // The gc op
+ Set<ManagedOperation> ops = mo.getOperations();
+ assertNotNull(ops);
+ assertEquals("There is 1 op", 1, ops.size());
+ ManagedOperation gc = ops.iterator().next();
+ assertEquals("gc", gc.getName());
+ assertEquals("Runs the garbage collector", gc.getDescription());
+ gc.invoke(null);
+ }
+
+ public void testThreadMXBean()
+ throws Exception
+ {
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mo = ManagementFactoryUtils.getThreadMXBean(mof);
+ assertNotNull(mo);
+ assertEquals(ManagementFactory.THREAD_MXBEAN_NAME, mo.getName());
+ validateComponentType(mo);
+
+ ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
+ long threadID = Thread.currentThread().getId();
+ ThreadInfo threadInfo = mbean.getThreadInfo(threadID, 3);
+
+ // Test ThreadInfo MetaValue wrap/unwrap
+ MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+ CompositeDataMetaValueBuilder builder = new CompositeDataMetaValueBuilder();
+ builder.setMetaValueFactory(metaValueFactory);
+ metaValueFactory.setBuilder(CompositeData.class, builder);
+ metaValueFactory.setBuilder(CompositeDataSupport.class, builder);
+
+ MetaValue threadInfoMV = metaValueFactory.create(threadInfo);
+ log.debug("ThreadInfo.MV: "+threadInfoMV);
+ assertTrue(threadInfoMV instanceof CompositeValue);
+ CompositeValue tiCV = CompositeValue.class.cast(threadInfoMV);
+ ThreadInfo threadInfo2 = ManagementFactoryUtils.unwrapThreadInfo(tiCV);
+ assertEquals(threadInfo.getLockOwnerName(), threadInfo2.getLockOwnerName());
+ assertEquals(threadInfo.getThreadName(), threadInfo2.getThreadName());
+ assertEquals(threadInfo.isInNative(), threadInfo2.isInNative());
+ assertEquals(threadInfo.getBlockedCount(), threadInfo2.getBlockedCount());
+ assertEquals(threadInfo.getBlockedTime(), threadInfo2.getBlockedTime());
+ assertEquals(threadInfo.getLockOwnerId(), threadInfo2.getLockOwnerId());
+ assertEquals(threadInfo.getThreadId(), threadInfo2.getThreadId());
+ assertEquals(threadInfo.getThreadState(), threadInfo2.getThreadState());
+ assertEquals(threadInfo.getWaitedCount(), threadInfo2.getWaitedCount());
+ assertEquals(threadInfo.getWaitedTime(), threadInfo2.getWaitedTime());
+ StackTraceElement[] st = threadInfo.getStackTrace();
+ StackTraceElement[] st2 = threadInfo2.getStackTrace();
+ for(int n = 0; n < st.length; n ++)
+ {
+ assertEquals(st[n], st2[n]);
+ }
+
+ // Properties
+ ManagedProperty allThreadIds = mo.getProperty("allThreadIds");
+ assertNotNull(allThreadIds);
+ ManagedProperty currentThreadCpuTime = mo.getProperty("currentThreadCpuTime");
+ assertNotNull(currentThreadCpuTime);
+ long x = (Long) metaValueFactory.unwrap(currentThreadCpuTime.getValue());
+ assertTrue(x > 1000);
+ ManagedProperty currentThreadUserTime = mo.getProperty("currentThreadUserTime");
+ assertNotNull(currentThreadUserTime);
+ ManagedProperty daemonThreadCount = mo.getProperty("daemonThreadCount");
+ assertNotNull(daemonThreadCount);
+ x = (Integer) metaValueFactory.unwrap(daemonThreadCount.getValue());
+ assertEquals(mbean.getDaemonThreadCount(), x);
+ ManagedProperty peakThreadCount = mo.getProperty("peakThreadCount");
+ assertNotNull(peakThreadCount);
+ x = (Integer) metaValueFactory.unwrap(peakThreadCount.getValue());
+ assertEquals(mbean.getPeakThreadCount(), x);
+ ManagedProperty threadCount = mo.getProperty("threadCount");
+ assertNotNull(threadCount);
+ x = (Integer) metaValueFactory.unwrap(threadCount.getValue());
+ assertEquals(mbean.getThreadCount(), x);
+ ManagedProperty totalStartedThreadCount = mo.getProperty("totalStartedThreadCount");
+ assertNotNull(totalStartedThreadCount);
+ x = (Long) metaValueFactory.unwrap(totalStartedThreadCount.getValue());
+ assertEquals(mbean.getTotalStartedThreadCount(), x);
+ ManagedProperty currentThreadCpuTimeSupported = mo.getProperty("currentThreadCpuTimeSupported");
+ assertNotNull(currentThreadCpuTimeSupported);
+ boolean flag = (Boolean) metaValueFactory.unwrap(currentThreadCpuTimeSupported.getValue());
+ assertEquals(mbean.isCurrentThreadCpuTimeSupported(), flag);
+ ManagedProperty threadContentionMonitoringEnabled = mo.getProperty("threadContentionMonitoringEnabled");
+ assertNotNull(threadContentionMonitoringEnabled);
+ flag = (Boolean) metaValueFactory.unwrap(threadContentionMonitoringEnabled.getValue());
+ assertEquals(mbean.isThreadContentionMonitoringEnabled(), flag);
+ ManagedProperty threadContentionMonitoringSupported = mo.getProperty("threadContentionMonitoringSupported");
+ assertNotNull(threadContentionMonitoringSupported);
+ flag = (Boolean) metaValueFactory.unwrap(threadContentionMonitoringSupported.getValue());
+ assertEquals(mbean.isThreadContentionMonitoringSupported(), flag);
+ ManagedProperty threadCpuTimeEnabled = mo.getProperty("threadCpuTimeEnabled");
+ assertNotNull(threadCpuTimeEnabled);
+ flag = (Boolean) metaValueFactory.unwrap(threadCpuTimeEnabled.getValue());
+ assertEquals(mbean.isThreadCpuTimeEnabled(), flag);
+ ManagedProperty threadCpuTimeSupported = mo.getProperty("threadCpuTimeSupported");
+ assertNotNull(threadCpuTimeSupported);
+ flag = (Boolean) metaValueFactory.unwrap(threadCpuTimeSupported.getValue());
+ assertEquals(mbean.isThreadCpuTimeSupported(), flag);
+
+ // Ops
+ Set<ManagedOperation> ops = mo.getOperations();
+ log.debug(ops);
+
+ assertEquals("Ops count is 8", 8, ops.size());
+ ManagedOperation getThreadInfo = ManagedOperationMatcher.findOperation(ops,
+ "getThreadInfo", SimpleMetaType.LONG_PRIMITIVE, SimpleMetaType.INTEGER_PRIMITIVE);
+ assertNotNull("getThreadInfo", getThreadInfo);
+ log.debug(getThreadInfo);
+ String[] getThreadInfoSig = getThreadInfo.getReflectionSignature();
+ String[] getThreadInfoSigExpected = {"long", "int"};
+ assertEquals(Arrays.asList(getThreadInfoSigExpected), Arrays.asList(getThreadInfoSig));
+ ManagedOperation resetPeakThreadCount = ManagedOperationMatcher.findOperation(ops,
+ "resetPeakThreadCount");
+ assertNotNull("resetPeakThreadCount", resetPeakThreadCount);
+ assertEquals(0, resetPeakThreadCount.getReflectionSignature().length);
+
+ MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ ObjectName tname = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
+ MBeanInfo tinfo = server.getMBeanInfo(tname);
+ MBeanOperationInfo[] tops = tinfo.getOperations();
+ assertEquals(8, tops.length);
+ for(MBeanOperationInfo op : tops)
+ {
+ MBeanParameterInfo[] params = op.getSignature();
+ String sig = "";
+ if(params != null)
+ {
+ for(MBeanParameterInfo param : params)
+ {
+ if(sig.length() > 0)
+ sig += ",";
+ sig += param.getType();
+ }
+ }
+ log.debug(op.getName()+"("+sig+")");
+ }
+ Object[] params = {threadID};
+ String[] signature = {"long"};
+ Object result = server.invoke(tname, "getThreadInfo", params, signature);
+ threadInfo = mbean.getThreadInfo(threadID);
+ log.debug("getThreadInfo()-OpenType: "+result);
+ assertTrue(result instanceof CompositeDataSupport);
+ MetaValue resultMV = metaValueFactory.create(result);
+ assertTrue(resultMV instanceof CompositeValue);
+ CompositeValue resultCV = (CompositeValue) resultMV;
+ log.debug("getThreadInfo()-MetaType: "+resultCV);
+
+ ThreadInfo resultTI = ManagementFactoryUtils.unwrapThreadInfo(resultCV);
+ threadInfo2 = resultTI;
+ assertEquals(threadInfo.getLockOwnerName(), threadInfo2.getLockOwnerName());
+ assertEquals(threadInfo.getThreadName(), threadInfo2.getThreadName());
+ assertEquals(threadInfo.isInNative(), threadInfo2.isInNative());
+ assertEquals(threadInfo.getBlockedCount(), threadInfo2.getBlockedCount());
+ assertEquals(threadInfo.getBlockedTime(), threadInfo2.getBlockedTime());
+ assertEquals(threadInfo.getLockOwnerId(), threadInfo2.getLockOwnerId());
+ assertEquals(threadInfo.getThreadId(), threadInfo2.getThreadId());
+ assertEquals(threadInfo.getThreadState(), threadInfo2.getThreadState());
+ assertEquals(threadInfo.getWaitedCount(), threadInfo2.getWaitedCount());
+ assertEquals(threadInfo.getWaitedTime(), threadInfo2.getWaitedTime());
+ st = threadInfo.getStackTrace();
+ st2 = threadInfo2.getStackTrace();
+ for(int n = 0; n < st.length; n ++)
+ {
+ assertEquals(st[n], st2[n]);
+ }
+
+ }
+
+ public void testRuntimeMXBean()
+ {
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mo = ManagementFactoryUtils.getRuntimeMXBean(mof);
+ assertNotNull(mo);
+ assertEquals(ManagementFactory.RUNTIME_MXBEAN_NAME, mo.getName());
+ validateComponentType(mo);
+
+ RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
+ MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+
+ ManagedProperty bootClassPath = mo.getProperty("bootClassPath");
+ String x = (String) metaValueFactory.unwrap(bootClassPath.getValue());
+ assertEquals(mbean.getBootClassPath(), x);
+ ManagedProperty classPath = mo.getProperty("classPath");
+ x = (String) metaValueFactory.unwrap(classPath.getValue());
+ assertEquals(mbean.getClassPath(), x);
+ ManagedProperty libraryPath = mo.getProperty("libraryPath");
+ x = (String) metaValueFactory.unwrap(libraryPath.getValue());
+ assertEquals(mbean.getLibraryPath(), x);
+ ManagedProperty managementSpecVersion = mo.getProperty("managementSpecVersion");
+ x = (String) metaValueFactory.unwrap(managementSpecVersion.getValue());
+ assertEquals(mbean.getManagementSpecVersion(), x);
+ ManagedProperty specName = mo.getProperty("specName");
+ x = (String) metaValueFactory.unwrap(specName.getValue());
+ assertEquals(mbean.getSpecName(), x);
+ ManagedProperty specVendor = mo.getProperty("specVendor");
+ x = (String) metaValueFactory.unwrap(specVendor.getValue());
+ assertEquals(mbean.getSpecVendor(), x);
+ ManagedProperty specVersion = mo.getProperty("specVersion");
+ x = (String) metaValueFactory.unwrap(specVersion.getValue());
+ assertEquals(mbean.getSpecVersion(), x);
+ ManagedProperty vmName = mo.getProperty("vmName");
+ x = (String) metaValueFactory.unwrap(vmName.getValue());
+ assertEquals(mbean.getVmName(), x);
+ ManagedProperty vmVendor = mo.getProperty("vmVendor");
+ x = (String) metaValueFactory.unwrap(vmVendor.getValue());
+ assertEquals(mbean.getVmVendor(), x);
+ ManagedProperty vmVersion = mo.getProperty("vmVersion");
+ x = (String) metaValueFactory.unwrap(vmVersion.getValue());
+ assertEquals(mbean.getVmVersion(), x);
+ ManagedProperty startTime = mo.getProperty("startTime");
+ long time = (Long) metaValueFactory.unwrap(startTime.getValue());
+ assertEquals(mbean.getStartTime(), time);
+ ManagedProperty uptime = mo.getProperty("uptime");
+ time = (Long) metaValueFactory.unwrap(uptime.getValue());
+ ManagedProperty inputArguments = mo.getProperty("inputArguments");
+ List<String> ls = (List<String>) metaValueFactory.unwrap(inputArguments.getValue());
+ List<String> args = mbean.getInputArguments();
+ assertEquals(args, ls);
+ ManagedProperty systemProperties = mo.getProperty("systemProperties");
+ Map<String, String> map = (Map<String, String>) metaValueFactory.unwrap(systemProperties.getValue());
+ log.info("sun.io.unicode.encoding: "+map.get("sun.io.unicode.encoding"));
+ Map<String, String> sysProps = mbean.getSystemProperties();
+ for(String key : sysProps.keySet())
+ {
+ String p1 = sysProps.get(key);
+ String p2 = map.get(key);
+ // TODO: some properties are missing?
+ // assertEquals(key, p1, p2);
+ }
+ }
+ public void testOperatingSystemMXBean()
+ {
+ ManagedObjectFactory mof = getMOF();
+ ManagedObject mo = ManagementFactoryUtils.getOperatingSystemMXBean(mof);
+ assertNotNull(mo);
+ assertEquals(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME, mo.getName());
+ validateComponentType(mo);
+
+ ManagedProperty arch = mo.getProperty("arch");
+ assertNotNull(arch);
+ ManagedProperty availableProcessors = mo.getProperty("availableProcessors");
+ assertNotNull(availableProcessors);
+ SimpleValue procsSV = (SimpleValue) availableProcessors.getValue();
+ Integer procs = (Integer) procsSV.getValue();
+ assertTrue(procs.intValue() >= 1);
+ ManagedProperty version = mo.getProperty("version");
+ assertNotNull(version);
+ log.debug(version.getValue());
+ }
+ public void testMemoryManagerMXBeans()
+ {
+ ManagedObjectFactory mof = getMOF();
+ List<ManagedObject> mos = ManagementFactoryUtils.getMemoryManagerMXBeans(mof);
+ assertTrue(mos.size() > 0);
+ for(ManagedObject mo : mos)
+ {
+ ManagedProperty nameMP = mo.getProperty("name");
+ SimpleValue nameSV = SimpleValue.class.cast(nameMP.getValue());
+ String nameString = nameSV.getValue().toString();
+ String name = ManagementFactory.MEMORY_MANAGER_MXBEAN_DOMAIN_TYPE + nameString;
+ assertEquals(name, mo.getName());
+ validateComponentType(mo);
+ }
+ }
+ public void testMemoryPoolMXBeans()
+ {
+ ManagedObjectFactory mof = getMOF();
+ List<ManagedObject> mos = ManagementFactoryUtils.getMemoryPoolMXBeans(mof);
+ assertTrue(mos.size() > 0);
+ for(ManagedObject mo : mos)
+ {
+ ManagedProperty nameMP = mo.getProperty("name");
+ SimpleValue nameSV = SimpleValue.class.cast(nameMP.getValue());
+ String nameString = nameSV.getValue().toString();
+ String name = ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE + nameString;
+ assertEquals(name, mo.getName());
+ validateComponentType(mo);
+ }
+ }
+ public void testGarbageCollectorMXBeans()
+ {
+ ManagedObjectFactory mof = getMOF();
+ List<ManagedObject> mos = ManagementFactoryUtils.getGarbageCollectorMXBeans(mof);
+ assertTrue(mos.size() > 0);
+ for(ManagedObject mo : mos)
+ {
+ log.debug("GC.MO.props: "+mo.getPropertyNames());
+ ManagedProperty nameMP = mo.getProperty("name");
+ SimpleValue nameSV = SimpleValue.class.cast(nameMP.getValue());
+ String nameString = nameSV.getValue().toString();
+ String name = ManagementFactory.GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + nameString;
+ assertEquals(name, mo.getName());
+ validateComponentType(mo);
+ }
+ }
+
+ protected void validateComponentType(ManagedObject mo)
+ {
+ Map<String, Annotation> moAnns = mo.getAnnotations();
+ assertNotNull(moAnns);
+ ManagementComponent mc = (ManagementComponent) moAnns.get(ManagementComponent.class.getName());
+ assertNotNull(mc);
+ assertEquals("MBean", mc.type());
+ assertEquals("Platform", mc.subtype());
+ }
+
+ static class X
+ {
+ public int m0(int i)
+ {
+ return 0;
+ }
+ public Integer m1(Integer i)
+ {
+ return 0;
+ }
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,105 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.managed.mock;
-
-import java.io.Serializable;
-
-import org.jboss.managed.api.Fields;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-
-/**
- * DOMFields.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class MockDOMFields implements Fields
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 1L;
-
- /** The datasource element */
- private Element element;
-
- /** The element name */
- private String elementName;
-
- /**
- * Create a new DOMFields.
- *
- * @param element the data source element
- * @param elementName the element name
- */
- public MockDOMFields(Element element, String elementName)
- {
- this.element = element;
- this.elementName = elementName;
- }
-
- public Object getField(String name)
- {
- if (NAME.equals(name))
- return elementName;
- if (VALUE.equals(name))
- {
- NodeList nodes = element.getElementsByTagName(elementName);
- if (nodes.getLength() == 0)
- return null;
- else
- {
- Element element = (Element) nodes.item(0);
- return element.getTextContent();
- }
- }
- return null;
- }
-
- public void setField(String name, Object value)
- {
- if (VALUE.equals(name))
- {
- String string = (String) value;
- NodeList nodes = element.getElementsByTagName(elementName);
- Element childElement = null;
- if (nodes.getLength() == 0)
- {
- if (string == null || string.length() == 0)
- return;
- childElement = element.getOwnerDocument().createElement(elementName);
- element.appendChild(childElement);
- }
- else
- {
- childElement = (Element) nodes.item(0);
- if (string == null || string.length() == 0)
- {
- element.removeChild(childElement);
- return;
- }
- }
- childElement.setTextContent(string);
- return;
- }
- throw new UnsupportedOperationException("setField " + name);
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java (from rev 85266, projects/jboss-man/branches/Branch_2_1/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/managed/src/test/java/org/jboss/test/managed/mock/MockDOMFields.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,113 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.managed.mock;
+
+import java.io.Serializable;
+
+import org.jboss.managed.api.Fields;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * DOMFields.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockDOMFields implements Fields
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The datasource element */
+ private Element element;
+
+ /** The element name */
+ private String elementName;
+
+ /**
+ * Create a new DOMFields.
+ *
+ * @param element the data source element
+ * @param elementName the element name
+ */
+ public MockDOMFields(Element element, String elementName)
+ {
+ this.element = element;
+ this.elementName = elementName;
+ }
+
+ public Object getField(String name)
+ {
+ if (NAME.equals(name))
+ return elementName;
+ if (VALUE.equals(name))
+ {
+ NodeList nodes = element.getElementsByTagName(elementName);
+ if (nodes.getLength() == 0)
+ return null;
+ else
+ {
+ Element element = (Element) nodes.item(0);
+ return element.getTextContent();
+ }
+ }
+ return null;
+ }
+
+ public void setField(String name, Object value)
+ {
+ if (VALUE.equals(name))
+ {
+ String string = (String) value;
+ NodeList nodes = element.getElementsByTagName(elementName);
+ Element childElement = null;
+ if (nodes.getLength() == 0)
+ {
+ if (string == null || string.length() == 0)
+ return;
+ childElement = element.getOwnerDocument().createElement(elementName);
+ element.appendChild(childElement);
+ }
+ else
+ {
+ childElement = (Element) nodes.item(0);
+ if (string == null || string.length() == 0)
+ {
+ element.removeChild(childElement);
+ return;
+ }
+ }
+ childElement.setTextContent(string);
+ return;
+ }
+ throw new UnsupportedOperationException("setField " + name);
+ }
+
+ public Fields copy()
+ {
+ Element elementCopy = (Element) element.cloneNode(true);
+ MockDOMFields copy = new MockDOMFields(elementCopy, elementName);
+ return copy;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/pom.xml 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,74 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <parent>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-man-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- </parent>
- <modelVersion>4.0.0</modelVersion>
- <artifactId>jboss-metatype</artifactId>
- <packaging>jar</packaging>
- <name>JBoss Metatype</name>
- <url>http://www.jboss.org/jbossmc</url>
- <description>JBoss Metatype</description>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <testFailureIgnore>false</testFailureIgnore>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <!-- Do not add version information here, use ../pom.xml instead -->
- <dependencies>
- <!-- Global dependencies -->
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-reflect</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-spi</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-spi</artifactId>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- </dependency>
- <!-- Test dependencies -->
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-log4j</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.test</groupId>
- <artifactId>jboss-test</artifactId>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-managed</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml (from rev 85722, projects/jboss-man/branches/Branch_2_1/metatype/pom.xml)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,74 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-man-parent</artifactId>
+ <version>2.1.0.CR4</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jboss-metatype</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Metatype</name>
+ <url>http://www.jboss.org/jbossmc</url>
+ <description>JBoss Metatype</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <testFailureIgnore>false</testFailureIgnore>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <!-- Do not add version information here, use ../pom.xml instead -->
+ <dependencies>
+ <!-- Global dependencies -->
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </dependency>
+ <!-- Test dependencies -->
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,289 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.types;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectStreamField;
-
-/**
- * AbstractMetaType.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public abstract class AbstractMetaType implements MetaType
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 5786422588217893696L;
-
- /** The peristent fields */
- private static final ObjectStreamField[] serialPersistentFields =
- new ObjectStreamField[]
- {
- new ObjectStreamField("className", String.class),
- new ObjectStreamField("description", String.class),
- new ObjectStreamField("typeName", String.class)
- };
-
- /** The type's class name */
- private String className;
-
- // TODO internationalization
- /** The type's description */
- private String description;
-
- /** The type's name */
- private String typeName;
-
- /** Whether the class is an array */
- private transient boolean array = false;
-
- /**
- * Construct a new MetaType.<p>
- *
- * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
- * array of those classes.
- *
- * @param className the name of the class implementing the meta type,
- * cannot be null
- * @param typeName the name of the meta type, cannot be null
- * @param description the human readable description of the type, cannot
- * be null
- * @throws IllegalArgumentException for a null argument or a class is not an allowed class
- */
- protected AbstractMetaType(String className, String typeName, String description)
- {
- init(className, typeName, description);
- }
-
- /**
- * Construct a new MetaType.<p>
- *
- * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
- * array of those classes.
- *
- * @param className the name of the class implementing the meta type,
- * cannot be null
- * @param description the human readable description of the type, cannot
- * be null
- * @throws IllegalArgumentException for a null argument or a class is not an allowed class
- */
- protected AbstractMetaType(String className, String description)
- {
- init(className, className, description);
- }
-
- /**
- * Construct a new MetaType.
- *
- * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
- * array of those classes.
- *
- * @param className the name of the class implementing the meta type,
- * cannot be null
- * @throws IllegalArgumentException for a null argument or a class is not an allowed class
- */
- protected AbstractMetaType(String className)
- {
- init(className, className, className);
- }
-
- public String getClassName()
- {
- return className;
- }
-
- public String getTypeName()
- {
- return typeName;
- }
-
- public String getDescription()
- {
- return description;
- }
-
- public boolean isEnum()
- {
- return false;
- }
-
- public boolean isComposite()
- {
- return false;
- }
-
- public boolean isSimple()
- {
- return false;
- }
-
- public boolean isGeneric()
- {
- return false;
- }
-
- public boolean isTable()
- {
- return false;
- }
-
- public boolean isArray()
- {
- return array;
- }
-
- public boolean isCollection()
- {
- return false;
- }
-
- public abstract boolean isValue(Object obj);
-
- /**
- * Initialise the object
- *
- * @param className the name of the class implementing the meta type,
- * cannot be null or an empty
- * @param typeName the name of the meta type, cannot be null or an empty
- * string
- * @param description the human readable description of the type, cannot
- * be null or an empty string
- * @exception IllegalArgumentException for a null or empty argument or when class name is not allowed class
- */
- private void init(String className, String typeName, String description)
- {
- if (className == null || className.trim().equals(""))
- throw new IllegalArgumentException("null or empty class name");
- if (typeName == null || typeName.trim().equals(""))
- throw new IllegalArgumentException("null or empty type name");
- if (description == null || description.trim().equals(""))
- throw new IllegalArgumentException("null or empty description");
-
- if (isCollection() == false)
- {
- // Calculate the underlying class and whether this is an array
- String testClassName = getBaseClassName(className);
- if (testClassName == null)
- throw new IllegalArgumentException("Invalid array declaration (see the javadocs for java.lang.Class): " + className);
- if (testClassName.equals(className) == false)
- array = true;
-
- // Check the underlying class
- boolean ok = false;
- for (int i = 0; i < ALLOWED_CLASSNAMES.size(); i++)
- {
- if (testClassName.equals(ALLOWED_CLASSNAMES.get(i)))
- {
- ok = true;
- break;
- }
- }
- if (ok == false)
- {
- // Check for a primative array type
- int index = className.lastIndexOf('[');
- if (index == className.length()-2)
- ok = ArrayMetaType.isPrimitiveEncoding(className.substring(index+1));
- if (ok == false)
- throw new IllegalArgumentException("Not a MetaType allowed class name: " + className);
- }
- }
-
- // Looks ok
- this.className = className;
- this.typeName = typeName;
- this.description = description;
- }
-
- /**
- * Gets the base class name, either the passed class name
- * or the underlying class name if it is an array.<p>
- *
- * NOTE: The class is not check for validity.<p>
- *
- * Null is returned when the array declaration is invalid.
- *
- * @param className the string to test
- * @return the underlying class name or null
- */
- private static String getBaseClassName(String className)
- {
- final int length = className.length();
- final int last = length - 1;
- int i = 0;
-
- // Eat the array dimensions
- while (i < length && className.charAt(i) == '[')
- ++i;
-
- // It looks like an array
- if (i > 0)
- {
- // But is it valid
- char type = className.charAt(i);
- // Primitive array
- if (type == 'B' || type == 'C' || type == 'D' || type == 'F' ||
- type == 'I' || type == 'J' || type == 'S' || type == 'Z' || type == 'V')
- {
- if (i != last)
- return null;
- return className.substring(last, length);
- }
- // Object Array
- else if (className.charAt(i) != 'L' ||
- i >= last-1 ||
- className.charAt(last) != ';')
- return null;
-
- // Potentially valid array, class name might be rubbish
- return className.substring(i+1, last);
- }
-
- // Not an array
- return className;
- }
-
- /**
- * Read the object from a stream
- *
- * @param in the stream
- * @throws IOException
- * @throws ClassNotFoundException
- */
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- ObjectInputStream.GetField getField = in.readFields();
- String className = (String) getField.get("className", null);
- String typeName = (String) getField.get("typeName", null);
- String description = (String) getField.get("description", null);
- try
- {
- init(className, typeName, description);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unexpected error deserializing MetaType: " + className, e);
- }
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/AbstractMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,299 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.types;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamField;
+
+/**
+ * AbstractMetaType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractMetaType implements MetaType
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 5786422588217893696L;
+
+ /** The peristent fields */
+ private static final ObjectStreamField[] serialPersistentFields =
+ new ObjectStreamField[]
+ {
+ new ObjectStreamField("className", String.class),
+ new ObjectStreamField("description", String.class),
+ new ObjectStreamField("typeName", String.class)
+ };
+
+ /** The type's class name */
+ private String className;
+
+ // TODO internationalization
+ /** The type's description */
+ private String description;
+
+ /** The type's name */
+ private String typeName;
+
+ /** Whether the class is an array */
+ private transient boolean array = false;
+
+ /**
+ * Construct a new MetaType.<p>
+ *
+ * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
+ * array of those classes.
+ *
+ * @param className the name of the class implementing the meta type,
+ * cannot be null
+ * @param typeName the name of the meta type, cannot be null
+ * @param description the human readable description of the type, cannot
+ * be null
+ * @throws IllegalArgumentException for a null argument or a class is not an allowed class
+ */
+ protected AbstractMetaType(String className, String typeName, String description)
+ {
+ init(className, typeName, description);
+ }
+
+ /**
+ * Construct a new MetaType.<p>
+ *
+ * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
+ * array of those classes.
+ *
+ * @param className the name of the class implementing the meta type,
+ * cannot be null
+ * @param description the human readable description of the type, cannot
+ * be null
+ * @throws IllegalArgumentException for a null argument or a class is not an allowed class
+ */
+ protected AbstractMetaType(String className, String description)
+ {
+ init(className, className, description);
+ }
+
+ /**
+ * Construct a new MetaType.
+ *
+ * The class name must be in {@link #ALLOWED_CLASSNAMES} or an
+ * array of those classes.
+ *
+ * @param className the name of the class implementing the meta type,
+ * cannot be null
+ * @throws IllegalArgumentException for a null argument or a class is not an allowed class
+ */
+ protected AbstractMetaType(String className)
+ {
+ init(className, className, className);
+ }
+
+ public String getClassName()
+ {
+ return className;
+ }
+
+ public String getTypeName()
+ {
+ return typeName;
+ }
+
+ public String getDescription()
+ {
+ return description;
+ }
+
+ public boolean isEnum()
+ {
+ return false;
+ }
+
+ public boolean isComposite()
+ {
+ return false;
+ }
+
+ public boolean isSimple()
+ {
+ return false;
+ }
+
+ public boolean isPrimitive()
+ {
+ return false;
+ }
+
+ public boolean isGeneric()
+ {
+ return false;
+ }
+
+ public boolean isTable()
+ {
+ return false;
+ }
+
+ public boolean isArray()
+ {
+ return array;
+ }
+
+ public boolean isCollection()
+ {
+ return false;
+ }
+
+ public boolean isProperties()
+ {
+ return false;
+ }
+
+ public abstract boolean isValue(Object obj);
+
+ /**
+ * Initialise the object
+ *
+ * @param className the name of the class implementing the meta type,
+ * cannot be null or an empty
+ * @param typeName the name of the meta type, cannot be null or an empty
+ * string
+ * @param description the human readable description of the type, cannot
+ * be null or an empty string
+ * @exception IllegalArgumentException for a null or empty argument or when class name is not allowed class
+ */
+ private void init(String className, String typeName, String description)
+ {
+ if (className == null || className.trim().equals(""))
+ throw new IllegalArgumentException("null or empty class name");
+ if (typeName == null || typeName.trim().equals(""))
+ throw new IllegalArgumentException("null or empty type name");
+ if (description == null || description.trim().equals(""))
+ throw new IllegalArgumentException("null or empty description");
+
+ if (isCollection() == false)
+ {
+ // Calculate the underlying class and whether this is an array
+ String testClassName = getBaseClassName(className);
+ if (testClassName == null)
+ throw new IllegalArgumentException("Invalid array declaration (see the javadocs for java.lang.Class): " + className);
+ if (testClassName.equals(className) == false)
+ array = true;
+
+ // Check the underlying class
+ boolean ok = false;
+ for (int i = 0; i < ALLOWED_CLASSNAMES.size(); i++)
+ {
+ if (testClassName.equals(ALLOWED_CLASSNAMES.get(i)))
+ {
+ ok = true;
+ break;
+ }
+ }
+ if (ok == false)
+ {
+ // Check for a primative array type
+ int index = className.lastIndexOf('[');
+ if (index == className.length()-2)
+ ok = ArrayMetaType.isPrimitiveEncoding(className.substring(index+1));
+ if (ok == false)
+ throw new IllegalArgumentException("Not a MetaType allowed class name: " + className);
+ }
+ }
+
+ // Looks ok
+ this.className = className;
+ this.typeName = typeName;
+ this.description = description;
+ }
+
+ /**
+ * Gets the base class name, either the passed class name
+ * or the underlying class name if it is an array.<p>
+ *
+ * NOTE: The class is not check for validity.<p>
+ *
+ * Null is returned when the array declaration is invalid.
+ *
+ * @param className the string to test
+ * @return the underlying class name or null
+ */
+ private static String getBaseClassName(String className)
+ {
+ final int length = className.length();
+ final int last = length - 1;
+ int i = 0;
+
+ // Eat the array dimensions
+ while (i < length && className.charAt(i) == '[')
+ ++i;
+
+ // It looks like an array
+ if (i > 0)
+ {
+ // But is it valid
+ char type = className.charAt(i);
+ // Primitive array
+ if (type == 'B' || type == 'C' || type == 'D' || type == 'F' ||
+ type == 'I' || type == 'J' || type == 'S' || type == 'Z' || type == 'V')
+ {
+ if (i != last)
+ return null;
+ return className.substring(last, length);
+ }
+ // Object Array
+ else if (className.charAt(i) != 'L' ||
+ i >= last-1 ||
+ className.charAt(last) != ';')
+ return null;
+
+ // Potentially valid array, class name might be rubbish
+ return className.substring(i+1, last);
+ }
+
+ // Not an array
+ return className;
+ }
+
+ /**
+ * Read the object from a stream
+ *
+ * @param in the stream
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+ {
+ ObjectInputStream.GetField getField = in.readFields();
+ String className = (String) getField.get("className", null);
+ String typeName = (String) getField.get("typeName", null);
+ String description = (String) getField.get("description", null);
+ try
+ {
+ init(className, typeName, description);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unexpected error deserializing MetaType: " + className, e);
+ }
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,450 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.types;
-
-import org.jboss.metatype.api.values.ArrayValue;
-
-/**
- * ArrayMetaType.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ArrayMetaType extends AbstractMetaType
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = -2062790692152055156L;
-
- /** The number of dimensions in the array */
- private int dimension = 0;
-
- /** The element type for the array */
- private MetaType elementType;
-
- /** Is elementType a primative array */
- private boolean primitiveArray;
-
- /** Cached hash code */
- private transient int cachedHashCode = Integer.MIN_VALUE;
-
- /** Cached string representation */
- private transient String cachedToString = null;
-
- private static final int PRIMITIVE_WRAPPER_NAME_INDEX = 0;
- private static final int PRIMITIVE_TYPE_NAME_INDEX = 1;
- private static final int PRIMITIVE_TYPE_ENCODING_INDEX = 2;
- private static final int PRIMITIVE_OPEN_TYPE_INDEX = 3;
-
- private static final Object[][] PRIMITIVE_ARRAY_TYPES = {
- { Boolean.class.getName(), boolean.class.getName(), "Z", SimpleMetaType.BOOLEAN },
- { Character.class.getName(), char.class.getName(), "C", SimpleMetaType.CHARACTER },
- { Byte.class.getName(), byte.class.getName(), "B", SimpleMetaType.BYTE },
- { Short.class.getName(), short.class.getName(), "S", SimpleMetaType.SHORT },
- { Integer.class.getName(), int.class.getName(), "I", SimpleMetaType.INTEGER },
- { Long.class.getName(), long.class.getName(), "J", SimpleMetaType.LONG },
- { Float.class.getName(), float.class.getName(), "F", SimpleMetaType.FLOAT },
- { Double.class.getName(), double.class.getName(), "D", SimpleMetaType.DOUBLE }
- };
-
- /**
- * Is primitive key.
- *
- * @param primitiveKey the key to check
- * @return true if key is primitive
- */
- public static boolean isPrimitiveEncoding(final String primitiveKey)
- {
- for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
- {
- if (typeDescr[PRIMITIVE_TYPE_ENCODING_INDEX].equals(primitiveKey))
- {
- return true;
- }
- }
- return false;
- }
-
- /**
- * Get primitive meta type.
- *
- * @param primitiveTypeName primitive type name
- * @return primitive meta type or null if param is not primitive
- */
- public static SimpleMetaType getPrimitiveMetaType(String primitiveTypeName)
- {
- for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
- {
- if (primitiveTypeName.equals(typeDescr[PRIMITIVE_TYPE_NAME_INDEX]))
- return (SimpleMetaType) typeDescr[PRIMITIVE_OPEN_TYPE_INDEX];
- }
- return null;
- }
-
- /**
- * Get the char encoding string for the type name.
- *
- * @param typeName - the primitive wrapper type name
- * @return char encoding string.
- */
- public static String getPrimitiveEncoding(String typeName)
- {
- for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
- {
- if (typeName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
- return (String) typeDescr[PRIMITIVE_TYPE_ENCODING_INDEX];
- }
- return null;
- }
-
- /**
- * Get the char encoding string for the type name.
- *
- * @param typeName - the primitive wrapper type name
- * @return primitive type name string.
- */
- public static String getPrimitiveName(String typeName)
- {
- for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
- {
- if (typeName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
- return (String) typeDescr[PRIMITIVE_TYPE_NAME_INDEX];
- }
- return null;
- }
-
- /**
- * Get array meta type.
- *
- * @param elementType the element meta type
- * @return array meta type
- */
- public static ArrayMetaType getArrayType(MetaType elementType)
- {
- return new ArrayMetaType(1, elementType);
- }
-
- /**
- * Get primitive array meta type.
- *
- * @param arrayClass array class
- * @return array meta type
- */
- @SuppressWarnings("unchecked")
- public static ArrayMetaType getPrimitiveArrayType(Class<?> arrayClass)
- {
- if (!arrayClass.isArray())
- {
- throw new IllegalArgumentException("arrayClass must be an array");
- }
-
- int n = 1;
- Class<?> componentType = arrayClass.getComponentType();
- while (componentType.isArray())
- {
- n++;
- componentType = componentType.getComponentType();
- }
- String componentTypeName = componentType.getName();
-
- if (!componentType.isPrimitive())
- {
- throw new IllegalArgumentException(
- "component type of the array must be a primitive type");
- }
-
- SimpleMetaType simpleType = getPrimitiveMetaType(componentTypeName);
-
- // Build primitive array
- //
- ArrayMetaType at = new ArrayMetaType(simpleType, true);
- if (n > 1)
- at = new ArrayMetaType(n - 1, at);
- return at;
- }
-
- /**
- * Generate the class name
- *
- * @param dimension the dimension
- * @param elementType the element type
- * @param isPrimitive is this a primitive type
- * @return the class name
- */
- private static String genName(int dimension, MetaType elementType, boolean isPrimitive)
- {
- if (dimension < 1)
- throw new IllegalArgumentException("negative dimension");
- if (elementType == null)
- throw new IllegalArgumentException("null element type");
- if (elementType instanceof ArrayMetaType)
- throw new IllegalArgumentException("array type cannot be an element of an array type");
- StringBuilder buffer = new StringBuilder();
- for (int i=0; i < dimension; i++)
- buffer.append('[');
- if (isPrimitive)
- {
- buffer.append(getPrimitiveEncoding(elementType.getClassName()));
- }
- else
- {
- buffer.append('L');
- buffer.append(elementType.getClassName());
- buffer.append(';');
- }
- return buffer.toString();
- }
-
- /**
- * Generate the type name
- *
- * @param dimension the dimension
- * @param elementType the element type
- * @param isPrimitive is this a primitive type
- * @return the type name
- */
- private static String genType(int dimension, MetaType elementType, boolean isPrimitive)
- {
- if (dimension < 1)
- throw new IllegalArgumentException("negative dimension");
- if (elementType == null)
- throw new IllegalArgumentException("null element type");
- if (elementType instanceof ArrayMetaType)
- throw new IllegalArgumentException("array type cannot be an element of an array type");
- StringBuilder buffer = new StringBuilder();
- for (int i=0; i < dimension; i++)
- buffer.append('[');
- if (isPrimitive)
- {
- buffer.append(getPrimitiveEncoding(elementType.getClassName()));
- }
- else
- {
- buffer.append('L');
- buffer.append(elementType.getClassName());
- buffer.append(';');
- }
- return buffer.toString();
- }
-
- /**
- * Generate the description
- *
- * @param dimension the dimension
- * @param elementType the element type
- * @param isPrimitive is this a primitive type
- * @return the description
- */
- private static String genDesc(int dimension, MetaType elementType, boolean isPrimitive)
- {
- StringBuilder buffer = new StringBuilder();
- buffer.append(new Integer(dimension));
- buffer.append("-dimension array of ");
- if (isPrimitive)
- buffer.append(getPrimitiveName(elementType.getTypeName()));
- else
- buffer.append(elementType.getTypeName());
- return buffer.toString();
- }
-
- /**
- * Construct an ArrayMetaType.
- *
- * @param dimension the number of dimensions in the array
- * @param elementType the open type of the array elements
- * @throws IllegalArgumentException for a null argument or non-negative dimension or when meta type is an ArrayMetaType
- */
- public ArrayMetaType(int dimension, MetaType elementType)
- {
- super(genName(dimension, elementType, false),
- genType(dimension, elementType, false),
- genDesc(dimension, elementType, false));
- this.dimension = dimension;
- this.elementType = elementType;
- this.primitiveArray = false;
- }
-
- /**
- * Construct an ArrayMetaType.
- *
- * @param elementType the element type
- * @param primitiveArray is primitive array
- */
- public ArrayMetaType(SimpleMetaType elementType, boolean primitiveArray)
- {
- this(1, elementType, primitiveArray);
- }
-
- /**
- * Construct an ArrayMetaType.
- *
- * @param dimension the number of dimensions in the array
- * @param elementType the open type of the array elements
- * @param primitiveArray is primitive array
- * @throws IllegalArgumentException for a null argument or non-negative dimension or when meta type is an ArrayMetaType
- */
- public ArrayMetaType(int dimension, MetaType elementType, boolean primitiveArray)
- {
- super(genName(dimension, elementType, primitiveArray),
- genType(dimension, elementType, primitiveArray),
- genDesc(dimension, elementType, primitiveArray));
- this.dimension = dimension;
- this.elementType = elementType;
- this.primitiveArray = primitiveArray;
- }
-
- /**
- * Get the dimension of the array
- *
- * @return the dimension
- */
- public int getDimension()
- {
- return dimension;
- }
-
- /**
- * Get the meta type of the array elements
- *
- * @return the element type
- */
- public MetaType getElementType()
- {
- return elementType;
- }
-
- /**
- * Is primitive array.
- *
- * @return true for primitive array
- */
- public boolean isPrimitiveArray()
- {
- return primitiveArray;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public boolean isValue(Object obj)
- {
- if (obj == null)
- return false;
-
- Class clazz = obj.getClass();
- if (clazz.isArray() == false && (obj instanceof ArrayValue) == false)
- return false;
-
- if (elementType instanceof SimpleMetaType)
- return recursiveCheck((Object[]) obj, dimension);
-
- if (elementType instanceof TableMetaType || elementType instanceof CompositeMetaType)
- {
- // If this is an ArrayValue check its MetaType
- if (obj instanceof ArrayValue)
- {
- ArrayValue av = (ArrayValue) obj;
- return this.equals(av.getMetaType());
- }
- // Check the element classes
- Class thisClass;
- try
- {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- thisClass = Class.forName(getClassName(), false, loader);
- }
- catch (ClassNotFoundException e)
- {
- return false;
- }
- if (thisClass.isAssignableFrom(clazz) == false)
- return false;
- return recursiveCheck((Object[]) obj, dimension);
- }
- return false;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null || obj instanceof ArrayMetaType == false)
- return false;
- ArrayMetaType other = (ArrayMetaType) obj;
- return getDimension() == other.getDimension() && getElementType().equals(other.getElementType());
- }
-
- @Override
- public int hashCode()
- {
- if (cachedHashCode != Integer.MIN_VALUE)
- return cachedHashCode;
- cachedHashCode = getDimension() + getElementType().hashCode();
- return cachedHashCode;
- }
-
- @Override
- public String toString()
- {
- if (cachedToString != null)
- return cachedToString;
- StringBuilder buffer = new StringBuilder(ArrayMetaType.class.getSimpleName());
- buffer.append("{type=");
- buffer.append(getTypeName());
- buffer.append(" dims=");
- buffer.append(dimension);
- buffer.append(" elementType=");
- buffer.append(elementType);
- cachedToString = buffer.toString();
- return cachedToString;
- }
-
- /**
- * Recursively check array elements
- *
- * @param elements the elements
- * @param dimension the dimension
- * @return true if elements match, false otherwise
- */
- private boolean recursiveCheck(Object[] elements, int dimension)
- {
- // Reached the end
- if (dimension == 1)
- {
- // Check each element is the correct type
- for (int i = 0; i < elements.length; i++)
- {
- if (elements[i] != null && elementType.isValue(elements[i]) == false)
- return false;
- }
- }
- else
- {
- // Check the array element in this array element
- for (int i = 0; i < elements.length; i++)
- {
- if (recursiveCheck((Object[]) elements[i], dimension-1) == false)
- return false;
- }
- }
- return true;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/ArrayMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,454 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.types;
+
+import org.jboss.metatype.api.values.ArrayValue;
+
+/**
+ * ArrayMetaType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayMetaType extends AbstractMetaType
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -2062790692152055156L;
+
+ /** The number of dimensions in the array */
+ private int dimension = 0;
+
+ /** The element type for the array */
+ private MetaType elementType;
+
+ /** Is elementType a primative array */
+ private boolean primitiveArray;
+
+ /** Cached hash code */
+ private transient int cachedHashCode = Integer.MIN_VALUE;
+
+ /** Cached string representation */
+ private transient String cachedToString = null;
+
+ private static final int PRIMITIVE_WRAPPER_NAME_INDEX = 0;
+ private static final int PRIMITIVE_TYPE_NAME_INDEX = 1;
+ private static final int PRIMITIVE_TYPE_ENCODING_INDEX = 2;
+ private static final int PRIMITIVE_OPEN_TYPE_INDEX = 3;
+
+ private static final Object[][] PRIMITIVE_ARRAY_TYPES = {
+ { Boolean.class.getName(), boolean.class.getName(), "Z", SimpleMetaType.BOOLEAN },
+ { Character.class.getName(), char.class.getName(), "C", SimpleMetaType.CHARACTER },
+ { Byte.class.getName(), byte.class.getName(), "B", SimpleMetaType.BYTE },
+ { Short.class.getName(), short.class.getName(), "S", SimpleMetaType.SHORT },
+ { Integer.class.getName(), int.class.getName(), "I", SimpleMetaType.INTEGER },
+ { Long.class.getName(), long.class.getName(), "J", SimpleMetaType.LONG },
+ { Float.class.getName(), float.class.getName(), "F", SimpleMetaType.FLOAT },
+ { Double.class.getName(), double.class.getName(), "D", SimpleMetaType.DOUBLE }
+ };
+
+ /**
+ * Is primitive key.
+ *
+ * @param primitiveKey the key to check
+ * @return true if key is primitive
+ */
+ public static boolean isPrimitiveEncoding(final String primitiveKey)
+ {
+ for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
+ {
+ if (typeDescr[PRIMITIVE_TYPE_ENCODING_INDEX].equals(primitiveKey))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get primitive meta type.
+ *
+ * @param primitiveTypeName primitive type name
+ * @return primitive meta type or null if param is not primitive
+ */
+ public static SimpleMetaType getPrimitiveMetaType(String primitiveTypeName)
+ {
+ for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
+ {
+ if (primitiveTypeName.equals(typeDescr[PRIMITIVE_TYPE_NAME_INDEX]))
+ return (SimpleMetaType) typeDescr[PRIMITIVE_OPEN_TYPE_INDEX];
+ }
+ return null;
+ }
+
+ /**
+ * Get the char encoding string for the type name.
+ *
+ * @param typeName - the primitive wrapper type name
+ * @return char encoding string.
+ */
+ public static String getPrimitiveEncoding(String typeName)
+ {
+ for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
+ {
+ if (typeName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
+ return (String) typeDescr[PRIMITIVE_TYPE_ENCODING_INDEX];
+ else if(typeName.equals(typeDescr[PRIMITIVE_TYPE_NAME_INDEX]))
+ return (String) typeDescr[PRIMITIVE_TYPE_ENCODING_INDEX];
+ }
+ return null;
+ }
+
+ /**
+ * Get the char encoding string for the type name.
+ *
+ * @param typeName - the primitive wrapper type name
+ * @return primitive type name string.
+ */
+ public static String getPrimitiveName(String typeName)
+ {
+ for (Object[] typeDescr : PRIMITIVE_ARRAY_TYPES)
+ {
+ if (typeName.equals(typeDescr[PRIMITIVE_WRAPPER_NAME_INDEX]))
+ return (String) typeDescr[PRIMITIVE_TYPE_NAME_INDEX];
+ else if(typeName.equals(typeDescr[PRIMITIVE_TYPE_NAME_INDEX]))
+ return (String) typeDescr[PRIMITIVE_TYPE_NAME_INDEX];
+ }
+ return null;
+ }
+
+ /**
+ * Get array meta type.
+ *
+ * @param elementType the element meta type
+ * @return array meta type
+ */
+ public static ArrayMetaType getArrayType(MetaType elementType)
+ {
+ return new ArrayMetaType(1, elementType);
+ }
+
+ /**
+ * Get primitive array meta type.
+ *
+ * @param arrayClass array class
+ * @return array meta type
+ */
+ @SuppressWarnings("unchecked")
+ public static ArrayMetaType getPrimitiveArrayType(Class<?> arrayClass)
+ {
+ if (!arrayClass.isArray())
+ {
+ throw new IllegalArgumentException("arrayClass must be an array");
+ }
+
+ int n = 1;
+ Class<?> componentType = arrayClass.getComponentType();
+ while (componentType.isArray())
+ {
+ n++;
+ componentType = componentType.getComponentType();
+ }
+ String componentTypeName = componentType.getName();
+
+ if (!componentType.isPrimitive())
+ {
+ throw new IllegalArgumentException(
+ "component type of the array must be a primitive type");
+ }
+
+ SimpleMetaType simpleType = getPrimitiveMetaType(componentTypeName);
+
+ // Build primitive array
+ //
+ ArrayMetaType at = new ArrayMetaType(simpleType, true);
+ if (n > 1)
+ at = new ArrayMetaType(n - 1, at);
+ return at;
+ }
+
+ /**
+ * Generate the class name
+ *
+ * @param dimension the dimension
+ * @param elementType the element type
+ * @param isPrimitive is this a primitive type
+ * @return the class name
+ */
+ private static String genName(int dimension, MetaType elementType, boolean isPrimitive)
+ {
+ if (dimension < 1)
+ throw new IllegalArgumentException("negative dimension");
+ if (elementType == null)
+ throw new IllegalArgumentException("null element type");
+ if (elementType instanceof ArrayMetaType)
+ throw new IllegalArgumentException("array type cannot be an element of an array type");
+ StringBuilder buffer = new StringBuilder();
+ for (int i=0; i < dimension; i++)
+ buffer.append('[');
+ if (isPrimitive)
+ {
+ buffer.append(getPrimitiveEncoding(elementType.getClassName()));
+ }
+ else
+ {
+ buffer.append('L');
+ buffer.append(elementType.getClassName());
+ buffer.append(';');
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Generate the type name
+ *
+ * @param dimension the dimension
+ * @param elementType the element type
+ * @param isPrimitive is this a primitive type
+ * @return the type name
+ */
+ private static String genType(int dimension, MetaType elementType, boolean isPrimitive)
+ {
+ if (dimension < 1)
+ throw new IllegalArgumentException("negative dimension");
+ if (elementType == null)
+ throw new IllegalArgumentException("null element type");
+ if (elementType instanceof ArrayMetaType)
+ throw new IllegalArgumentException("array type cannot be an element of an array type");
+ StringBuilder buffer = new StringBuilder();
+ for (int i=0; i < dimension; i++)
+ buffer.append('[');
+ if (isPrimitive)
+ {
+ buffer.append(getPrimitiveEncoding(elementType.getClassName()));
+ }
+ else
+ {
+ buffer.append('L');
+ buffer.append(elementType.getClassName());
+ buffer.append(';');
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Generate the description
+ *
+ * @param dimension the dimension
+ * @param elementType the element type
+ * @param isPrimitive is this a primitive type
+ * @return the description
+ */
+ private static String genDesc(int dimension, MetaType elementType, boolean isPrimitive)
+ {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(new Integer(dimension));
+ buffer.append("-dimension array of ");
+ if (isPrimitive)
+ buffer.append(getPrimitiveName(elementType.getTypeName()));
+ else
+ buffer.append(elementType.getTypeName());
+ return buffer.toString();
+ }
+
+ /**
+ * Construct an ArrayMetaType.
+ *
+ * @param dimension the number of dimensions in the array
+ * @param elementType the open type of the array elements
+ * @throws IllegalArgumentException for a null argument or non-negative dimension or when meta type is an ArrayMetaType
+ */
+ public ArrayMetaType(int dimension, MetaType elementType)
+ {
+ super(genName(dimension, elementType, false),
+ genType(dimension, elementType, false),
+ genDesc(dimension, elementType, false));
+ this.dimension = dimension;
+ this.elementType = elementType;
+ this.primitiveArray = false;
+ }
+
+ /**
+ * Construct an ArrayMetaType.
+ *
+ * @param elementType the element type
+ * @param primitiveArray is primitive array
+ */
+ public ArrayMetaType(SimpleMetaType elementType, boolean primitiveArray)
+ {
+ this(1, elementType, primitiveArray);
+ }
+
+ /**
+ * Construct an ArrayMetaType.
+ *
+ * @param dimension the number of dimensions in the array
+ * @param elementType the open type of the array elements
+ * @param primitiveArray is primitive array
+ * @throws IllegalArgumentException for a null argument or non-negative dimension or when meta type is an ArrayMetaType
+ */
+ public ArrayMetaType(int dimension, MetaType elementType, boolean primitiveArray)
+ {
+ super(genName(dimension, elementType, primitiveArray),
+ genType(dimension, elementType, primitiveArray),
+ genDesc(dimension, elementType, primitiveArray));
+ this.dimension = dimension;
+ this.elementType = elementType;
+ this.primitiveArray = primitiveArray;
+ }
+
+ /**
+ * Get the dimension of the array
+ *
+ * @return the dimension
+ */
+ public int getDimension()
+ {
+ return dimension;
+ }
+
+ /**
+ * Get the meta type of the array elements
+ *
+ * @return the element type
+ */
+ public MetaType getElementType()
+ {
+ return elementType;
+ }
+
+ /**
+ * Is primitive array.
+ *
+ * @return true for primitive array
+ */
+ public boolean isPrimitiveArray()
+ {
+ return primitiveArray;
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean isValue(Object obj)
+ {
+ if (obj == null)
+ return false;
+
+ Class clazz = obj.getClass();
+ if (clazz.isArray() == false && (obj instanceof ArrayValue) == false)
+ return false;
+
+ if (elementType instanceof SimpleMetaType)
+ return recursiveCheck((Object[]) obj, dimension);
+
+ if (elementType instanceof TableMetaType || elementType instanceof CompositeMetaType)
+ {
+ // If this is an ArrayValue check its MetaType
+ if (obj instanceof ArrayValue)
+ {
+ ArrayValue av = (ArrayValue) obj;
+ return this.equals(av.getMetaType());
+ }
+ // Check the element classes
+ Class thisClass;
+ try
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ thisClass = Class.forName(getClassName(), false, loader);
+ }
+ catch (ClassNotFoundException e)
+ {
+ return false;
+ }
+ if (thisClass.isAssignableFrom(clazz) == false)
+ return false;
+ return recursiveCheck((Object[]) obj, dimension);
+ }
+ return false;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null || obj instanceof ArrayMetaType == false)
+ return false;
+ ArrayMetaType other = (ArrayMetaType) obj;
+ return getDimension() == other.getDimension() && getElementType().equals(other.getElementType());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if (cachedHashCode != Integer.MIN_VALUE)
+ return cachedHashCode;
+ cachedHashCode = getDimension() + getElementType().hashCode();
+ return cachedHashCode;
+ }
+
+ @Override
+ public String toString()
+ {
+ if (cachedToString != null)
+ return cachedToString;
+ StringBuilder buffer = new StringBuilder(ArrayMetaType.class.getSimpleName());
+ buffer.append("{type=");
+ buffer.append(getTypeName());
+ buffer.append(" dims=");
+ buffer.append(dimension);
+ buffer.append(" elementType=");
+ buffer.append(elementType);
+ cachedToString = buffer.toString();
+ return cachedToString;
+ }
+
+ /**
+ * Recursively check array elements
+ *
+ * @param elements the elements
+ * @param dimension the dimension
+ * @return true if elements match, false otherwise
+ */
+ private boolean recursiveCheck(Object[] elements, int dimension)
+ {
+ // Reached the end
+ if (dimension == 1)
+ {
+ // Check each element is the correct type
+ for (int i = 0; i < elements.length; i++)
+ {
+ if (elements[i] != null && elementType.isValue(elements[i]) == false)
+ return false;
+ }
+ }
+ else
+ {
+ // Check the array element in this array element
+ for (int i = 0; i < elements.length; i++)
+ {
+ if (recursiveCheck((Object[]) elements[i], dimension-1) == false)
+ return false;
+ }
+ }
+ return true;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,147 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.types;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * EnumMetaType.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class EnumMetaType extends AbstractMetaType
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 6786422588217893696L;
-
- /** The valid values */
- private List<String> validValues;
-
- /**
- * Create a new EnumMetaType.
- *
- * @param className the class name
- * @param validValues the valid values
- */
- public EnumMetaType(String className, List<String> validValues)
- {
- super(String.class.getName(), className, className);
- if (validValues == null)
- throw new IllegalArgumentException("Null valid values");
- this.validValues = validValues;
- }
- /**
- * Create a new EnumMetaType from the Enum values.
- *
- * @param validValues the valid Enum values
- */
- public EnumMetaType(Enum<?>[] validValues)
- {
- super(
- String.class.getName(),
- isValid(validValues) ? validValues[0].getClass().getName() : null,
- isValid(validValues) ? validValues[0].getClass().getName() : null
- );
- if (isValid(validValues) == false)
- throw new IllegalArgumentException("Null or empty valid values");
- ArrayList<String> values = new ArrayList<String>();
- for (Enum<?> e : validValues)
- values.add(e.name());
- this.validValues = values;
- }
-
- /**
- * Are enums valid.
- *
- * @param values the enums
- * @return true if not null and not empty
- */
- protected static boolean isValid(Enum<?>[] values)
- {
- return values != null && values.length > 0;
- }
-
- /**
- * Get the valid values
- *
- * @return the valid values
- */
- public List<String> getValidValues()
- {
- return Collections.unmodifiableList(validValues);
- }
-
- @Override
- public boolean isEnum()
- {
- return true;
- }
-
- /**
- * Validate that obj is a SimpleValue.STRING or EnumValue whose string
- * value is in the set of valid enum strings.
- * @return true if obj is a valid enum string for this type.
- */
- @Override
- public boolean isValue(Object obj)
- {
- if (obj == null || (obj instanceof SimpleValue == false && obj instanceof EnumValue == false))
- return false;
-
- String enumString = null;
- if(obj instanceof SimpleValue)
- {
- SimpleValue value = SimpleValue.class.cast(obj);
- if (SimpleMetaType.STRING == value.getMetaType() == false)
- return false;
- enumString = value.getValue().toString();
- }
- else
- {
- EnumValue value = EnumValue.class.cast(obj);
- enumString = value.getValue();
- }
- return validValues.contains(enumString);
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null || obj instanceof EnumMetaType == false)
- return false;
- EnumMetaType other = (EnumMetaType) obj;
- return getTypeName().equals(other.getTypeName()) && getValidValues().equals(other.getValidValues());
- }
-
- @Override
- public String toString()
- {
- return getTypeName() + "{" + validValues + "}";
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java (from rev 84399, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/EnumMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,148 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.types;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * EnumMetaType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class EnumMetaType extends AbstractMetaType
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 6786422588217893696L;
+
+ /** The valid values */
+ private List<String> validValues;
+
+ /**
+ * Create a new EnumMetaType.
+ *
+ * @param className the class name
+ * @param validValues the valid values
+ */
+ public EnumMetaType(String className, List<String> validValues)
+ {
+ super(String.class.getName(), className, className);
+ if (validValues == null)
+ throw new IllegalArgumentException("Null valid values");
+ this.validValues = validValues;
+ }
+ /**
+ * Create a new EnumMetaType from the Enum values.
+ *
+ * @param validValues the valid Enum values
+ */
+ public EnumMetaType(Enum<?>[] validValues)
+ {
+ super(
+ String.class.getName(),
+ isValid(validValues) ? validValues[0].getClass().getName() : null,
+ isValid(validValues) ? validValues[0].getClass().getName() : null
+ );
+ if (isValid(validValues) == false)
+ throw new IllegalArgumentException("Null or empty valid values");
+ ArrayList<String> values = new ArrayList<String>();
+ for (Enum<?> e : validValues)
+ values.add(e.name());
+ this.validValues = values;
+ }
+
+ /**
+ * Are enums valid.
+ *
+ * @param values the enums
+ * @return true if not null and not empty
+ */
+ protected static boolean isValid(Enum<?>[] values)
+ {
+ return values != null && values.length > 0;
+ }
+
+ /**
+ * Get the valid values
+ *
+ * @return the valid values
+ */
+ public List<String> getValidValues()
+ {
+ return Collections.unmodifiableList(validValues);
+ }
+
+ @Override
+ public boolean isEnum()
+ {
+ return true;
+ }
+
+ /**
+ * Validate that obj is a SimpleValue.STRING or EnumValue whose string
+ * value is in the set of valid enum strings.
+ * @return true if obj is a valid enum string for this type.
+ */
+ @Override
+ public boolean isValue(Object obj)
+ {
+ if (obj == null || (obj instanceof SimpleValue == false && obj instanceof EnumValue == false))
+ return false;
+
+ String enumString = null;
+ if(obj instanceof SimpleValue)
+ {
+ SimpleValue value = SimpleValue.class.cast(obj);
+ if (SimpleMetaType.STRING == value.getMetaType() == false)
+ return false;
+ enumString = value.getValue().toString();
+ }
+ else
+ {
+ EnumValue value = EnumValue.class.cast(obj);
+ enumString = value.getValue();
+ }
+ return validValues.contains(enumString);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null || obj instanceof EnumMetaType == false)
+ return false;
+ EnumMetaType other = (EnumMetaType) obj;
+ return getTypeName().equals(other.getTypeName()) && getValidValues().equals(other.getValidValues());
+ }
+
+ @Override
+ public String toString()
+ {
+ return getTypeName() + "{" + validValues + "}";
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,178 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.types;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.TableValue;
-
-/**
- * MetaType.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public interface MetaType extends Serializable
-{
- /**
- * The allowed classnames.<p>
- *
- * One of<br>
- * java.lang.Void<br>
- * java.lang.Boolean<br>
- * java.lang.Character<br>
- * java.lang.Byte<br>
- * java.lang.Short<br>
- * java.lang.Integer<br>
- * java.lang.Long<br>
- * java.lang.Float<br>
- * java.lang.Double<br>
- * java.lang.String<br>
- * java.lang.Date<br>
- * java.math.BigDecimal<br>
- * java.math.BigInteger<br>
- * java.util.Properties<br>
- * {@link Name}<br>
- * {@link SimpleValue}<br>
- * {@link EnumValue}<br>
- * {@link GenericValue}<br>
- * {@link ArrayValue}<br>
- * {@link CompositeValue}<br>
- * {@link TableValue}
- */
- List<String> ALLOWED_CLASSNAMES = Collections.unmodifiableList(Arrays.asList(new String[]
- {
- Void.class.getName(),
- Boolean.class.getName(),
- Character.class.getName(),
- Byte.class.getName(),
- Short.class.getName(),
- Integer.class.getName(),
- Long.class.getName(),
- Float.class.getName(),
- Double.class.getName(),
- String.class.getName(),
- Date.class.getName(),
- BigDecimal.class.getName(),
- BigInteger.class.getName(),
- Properties.class.getName(),
- Name.class.getName(),
- SimpleValue.class.getName(),
- EnumValue.class.getName(),
- GenericValue.class.getName(),
- ArrayValue.class.getName(),
- CompositeValue.class.getName(),
- TableValue.class.getName()
- }));
-
- /**
- * Retrieve the class name of the values of this meta
- * type. It is one of those listed in ALLOWED_CLASSNAMES or
- * a (multi-dimensional) array of one of those classes.
- *
- * @return the class name
- */
- String getClassName();
-
- /**
- * Retrieve the name of the meta type
- *
- * @return the type name
- */
- String getTypeName();
-
- /**
- * Retrieve the description of the type
- *
- * @return the description
- */
- String getDescription();
-
- /**
- * Retrieve whether the class name of the type is an array
- *
- * @return true when it is an array or false otherwise
- */
- boolean isArray();
-
- /**
- * Retrieve whether the class name of the type is a collection
- *
- * @return true when it is a collection or false otherwise
- */
- boolean isCollection();
-
- /**
- * Retrieve whether the class name of the type is an enum
- *
- * @return true when it is an enum or false otherwise
- */
- boolean isEnum();
-
- /**
- * Retrieve whether the class name of the type is simple
- *
- * @return true when it is simple or false otherwise
- */
- boolean isSimple();
-
- /**
- * Retrieve whether the class name of the type is generic
- *
- * @return true when it is generic or false otherwise
- */
- boolean isGeneric();
-
- /**
- * Retrieve whether the class name of the type is composite
- *
- * @return true when it is composite or false otherwise
- */
- boolean isComposite();
-
- /**
- * Retrieve whether the class name of the type is a table
- *
- * @return true when it is a table or false otherwise
- */
- boolean isTable();
-
- /**
- * Whether the passed value is one of those described by this meta type.
- *
- * @param obj the object to test
- * @return true when it is value for this meta type, false otherwise
- */
- boolean isValue(Object obj);
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/MetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,199 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.types;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.TableValue;
+
+/**
+ * MetaType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MetaType extends Serializable
+{
+ /**
+ * The allowed classnames.<p>
+ *
+ * One of<br>
+ * java.lang.Void<br>
+ * java.lang.Boolean<br>
+ * java.lang.Character<br>
+ * java.lang.Byte<br>
+ * java.lang.Short<br>
+ * java.lang.Integer<br>
+ * java.lang.Long<br>
+ * java.lang.Float<br>
+ * java.lang.Double<br>
+ * java.lang.String<br>
+ * java.lang.Date<br>
+ * java.math.BigDecimal<br>
+ * java.math.BigInteger<br>
+ * java.util.Properties<br>
+ * {@link Name}<br>
+ * {@link SimpleValue}<br>
+ * {@link EnumValue}<br>
+ * {@link GenericValue}<br>
+ * {@link ArrayValue}<br>
+ * {@link CompositeValue}<br>
+ * {@link TableValue}
+ */
+ List<String> ALLOWED_CLASSNAMES = Collections.unmodifiableList(Arrays.asList(new String[]
+ {
+ Void.class.getName(),
+ Boolean.class.getName(),
+ Character.class.getName(),
+ Byte.class.getName(),
+ Short.class.getName(),
+ Integer.class.getName(),
+ Long.class.getName(),
+ Float.class.getName(),
+ Double.class.getName(),
+ boolean.class.getName(),
+ char.class.getName(),
+ byte.class.getName(),
+ short.class.getName(),
+ int.class.getName(),
+ long.class.getName(),
+ float.class.getName(),
+ double.class.getName(),
+ String.class.getName(),
+ Date.class.getName(),
+ BigDecimal.class.getName(),
+ BigInteger.class.getName(),
+ Properties.class.getName(),
+ Name.class.getName(),
+ SimpleValue.class.getName(),
+ EnumValue.class.getName(),
+ GenericValue.class.getName(),
+ ArrayValue.class.getName(),
+ CompositeValue.class.getName(),
+ TableValue.class.getName()
+ }));
+
+ /**
+ * Retrieve the class name of the values of this meta
+ * type. It is one of those listed in ALLOWED_CLASSNAMES or
+ * a (multi-dimensional) array of one of those classes.
+ *
+ * @return the class name
+ */
+ String getClassName();
+
+ /**
+ * Retrieve the name of the meta type
+ *
+ * @return the type name
+ */
+ String getTypeName();
+
+ /**
+ * Retrieve the description of the type
+ *
+ * @return the description
+ */
+ String getDescription();
+
+ /**
+ * Retrieve whether the class name of the type is an array
+ *
+ * @return true when it is an array or false otherwise
+ */
+ boolean isArray();
+
+ /**
+ * Retrieve whether the class name of the type is a collection
+ *
+ * @return true when it is a collection or false otherwise
+ */
+ boolean isCollection();
+
+ /**
+ * Retrieve whether the class name of the type is an enum
+ *
+ * @return true when it is an enum or false otherwise
+ */
+ boolean isEnum();
+
+ /**
+ * Retrieve whether the class name of the type is simple
+ *
+ * @return true when it is simple or false otherwise
+ */
+ boolean isSimple();
+
+ /**
+ * Retrieve whether the class name of the type is a java primitive type.
+ * @return
+ */
+ boolean isPrimitive();
+
+ /**
+ * Retrieve whether the class name of the type is generic
+ *
+ * @return true when it is generic or false otherwise
+ */
+ boolean isGeneric();
+
+ /**
+ * Retrieve whether the class name of the type is composite
+ *
+ * @return true when it is composite or false otherwise
+ */
+ boolean isComposite();
+
+ /**
+ * Retrieve whether the class name of the type is a table
+ *
+ * @return true when it is a table or false otherwise
+ */
+ boolean isTable();
+
+ /**
+ * Return whether the type is a PropertiesMetaType type.
+ * @see PropertiesMetaType
+ * @return true if type is a PropertiesMetaType
+ */
+ boolean isProperties();
+
+ /**
+ * Whether the passed value is one of those described by this meta type.
+ *
+ * @param obj the object to test
+ * @return true when it is value for this meta type, false otherwise
+ */
+ boolean isValue(Object obj);
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,79 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.metatype.api.types;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import org.jboss.metatype.api.values.PropertiesMetaValue;
-
-
-/**
- * A MetaType for java.util.Properties
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
-public class PropertiesMetaType extends AbstractMetaType
-{
- private static final long serialVersionUID = 1;
- public static final PropertiesMetaType INSTANCE = new PropertiesMetaType();
- /** A mapping from known property names to description */
- private Map<String, String> propertyNameDescriptions = Collections.emptyMap();
-
- public PropertiesMetaType()
- {
- this(Properties.class.getName());
- }
- public PropertiesMetaType(String description)
- {
- super(Properties.class.getName(), description);
- }
- public PropertiesMetaType(String description, Map<String, String> propertyNameDescriptions)
- {
- super(Properties.class.getName(), description);
- this.propertyNameDescriptions = propertyNameDescriptions;
- }
-
- public void addProperty(String name, String description)
- {
- if(propertyNameDescriptions.size() == 0)
- propertyNameDescriptions = new HashMap<String,String>();
- propertyNameDescriptions.put(name, description);
- }
-
- public boolean isProperty(String name)
- {
- return propertyNameDescriptions.containsKey(name);
- }
- public String getDescription(String name)
- {
- return propertyNameDescriptions.get(name);
- }
- @Override
- public boolean isValue(Object obj)
- {
- return obj instanceof PropertiesMetaValue;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/PropertiesMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,85 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metatype.api.types;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+
+
+/**
+ * A MetaType for java.util.Properties
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesMetaType extends AbstractMetaType
+{
+ private static final long serialVersionUID = 1;
+ public static final PropertiesMetaType INSTANCE = new PropertiesMetaType();
+ /** A mapping from known property names to description */
+ private Map<String, String> propertyNameDescriptions = Collections.emptyMap();
+
+ public PropertiesMetaType()
+ {
+ this(Properties.class.getName());
+ }
+ public PropertiesMetaType(String description)
+ {
+ super(Properties.class.getName(), description);
+ }
+ public PropertiesMetaType(String description, Map<String, String> propertyNameDescriptions)
+ {
+ super(Properties.class.getName(), description);
+ this.propertyNameDescriptions = propertyNameDescriptions;
+ }
+
+ public void addProperty(String name, String description)
+ {
+ if(propertyNameDescriptions.size() == 0)
+ propertyNameDescriptions = new HashMap<String,String>();
+ propertyNameDescriptions.put(name, description);
+ }
+
+ public boolean isProperty(String name)
+ {
+ return propertyNameDescriptions.containsKey(name);
+ }
+ public String getDescription(String name)
+ {
+ return propertyNameDescriptions.get(name);
+ }
+
+ @Override
+ public boolean isProperties()
+ {
+ return true;
+ }
+ @Override
+ public boolean isValue(Object obj)
+ {
+ return obj instanceof PropertiesMetaValue;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,281 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.types;
-
-import java.io.ObjectStreamException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Comparator;
-import java.util.Date;
-
-import org.jboss.metatype.api.types.helpers.BigDecimalComparator;
-import org.jboss.metatype.api.types.helpers.BigIntegerComparator;
-import org.jboss.metatype.api.types.helpers.BooleanComparator;
-import org.jboss.metatype.api.types.helpers.ByteComparator;
-import org.jboss.metatype.api.types.helpers.CharacterComparator;
-import org.jboss.metatype.api.types.helpers.DateComparator;
-import org.jboss.metatype.api.types.helpers.DoubleComparator;
-import org.jboss.metatype.api.types.helpers.FloatComparator;
-import org.jboss.metatype.api.types.helpers.IntegerComparator;
-import org.jboss.metatype.api.types.helpers.LongComparator;
-import org.jboss.metatype.api.types.helpers.NamedComparator;
-import org.jboss.metatype.api.types.helpers.ShortComparator;
-import org.jboss.metatype.api.types.helpers.StringComparator;
-import org.jboss.metatype.api.values.SimpleValue;
-
-/**
- * SimpleMetaType.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleMetaType extends AbstractMetaType
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 6786422588217893696L;
-
- /** Cached hash code */
- private transient int cachedHashCode;
-
- /** Cached string representation */
- private transient String cachedToString;
-
- /** The simple type for java.math.BigDecimal */
- public static final SimpleMetaType BIGDECIMAL;
-
- /** The simple type for java.math.BigInteger */
- public static final SimpleMetaType BIGINTEGER;
-
- /** The simple type for java.lang.Boolean */
- public static final SimpleMetaType BOOLEAN;
-
- /** The simple type for java.lang.Byte */
- public static final SimpleMetaType BYTE;
-
- /** The simple type for java.lang.Character */
- public static final SimpleMetaType CHARACTER;
-
- /** The simple type for java.lang.Date */
- public static final SimpleMetaType DATE;
-
- /** The simple type for java.lang.Double */
- public static final SimpleMetaType DOUBLE;
-
- /** The simple type for java.lang.Float */
- public static final SimpleMetaType FLOAT;
-
- /** The simple type for java.lang.Integer */
- public static final SimpleMetaType INTEGER;
-
- /** The simple type for java.lang.Long */
- public static final SimpleMetaType LONG;
-
- /** The simple type for java.lang.Short */
- public static final SimpleMetaType SHORT;
-
- /** The simple type for java.lang.String */
- public static final SimpleMetaType STRING;
-
- /** The simple type for an object name */
- public static final SimpleMetaType NAMEDOBJECT;
-
- /** The simple type for java.lang.Void */
- public static final SimpleMetaType VOID;
-
- /** The comparator */
- private transient Comparator comparator;
-
- static
- {
- BIGDECIMAL = new SimpleMetaType(BigDecimal.class, BigDecimalComparator.INSTANCE);
- BIGINTEGER = new SimpleMetaType(BigInteger.class, BigIntegerComparator.INSTANCE);
- BOOLEAN = new SimpleMetaType(Boolean.class, BooleanComparator.INSTANCE);
- BYTE = new SimpleMetaType(Byte.class, ByteComparator.INSTANCE);
- CHARACTER = new SimpleMetaType(Character.class, CharacterComparator.INSTANCE);
- DATE = new SimpleMetaType(Date.class, DateComparator.INSTANCE);
- DOUBLE = new SimpleMetaType(Double.class, DoubleComparator.INSTANCE);
- FLOAT = new SimpleMetaType(Float.class, FloatComparator.INSTANCE);
- INTEGER = new SimpleMetaType(Integer.class, IntegerComparator.INSTANCE);
- LONG = new SimpleMetaType(Long.class, LongComparator.INSTANCE);
- SHORT = new SimpleMetaType(Short.class, ShortComparator.INSTANCE);
- STRING = new SimpleMetaType(String.class, StringComparator.INSTANCE);
- NAMEDOBJECT = new SimpleMetaType(Name.class, NamedComparator.INSTANCE);
- VOID = new SimpleMetaType(Void.class, null);
- }
-
- /**
- * Resolve a simple type
- *
- * @param className the class name of the simple type
- * @return the simple type
- * @throws IllegalArgumentException for a null className or if it is not a simple type
- */
- public static SimpleMetaType resolve(String className)
- {
- SimpleMetaType result = isSimpleType(className);
- if (result != null)
- return result;
- throw new IllegalArgumentException("Class is not a simple type: " + className);
- }
-
- /**
- * Return the simple type if the class name is a simple type
- * otherwise null.
- *
- * @param className the class name of the simple type
- * @return the simple type
- * @throws IllegalArgumentException for a null className
- */
- public static SimpleMetaType isSimpleType(String className)
- {
- if (className == null)
- throw new IllegalArgumentException("Null class name");
- if (className.equals(STRING.getClassName()))
- return STRING;
- if (className.equals(INTEGER.getClassName()) || className.equals(Integer.TYPE.getName()))
- return INTEGER;
- if (className.equals(BOOLEAN.getClassName()) || className.equals(Boolean.TYPE.getName()))
- return BOOLEAN;
- if (className.equals(LONG.getClassName()) || className.equals(Long.TYPE.getName()))
- return LONG;
- if (className.equals(BYTE.getClassName()) || className.equals(Byte.TYPE.getName()))
- return BYTE;
- if (className.equals(CHARACTER.getClassName()) || className.equals(Character.TYPE.getName()))
- return CHARACTER;
- if (className.equals(DOUBLE.getClassName()) || className.equals(Double.TYPE.getName()))
- return DOUBLE;
- if (className.equals(FLOAT.getClassName()) || className.equals(Float.TYPE.getName()))
- return FLOAT;
- if (className.equals(SHORT.getClassName()) || className.equals(Short.TYPE.getName()))
- return SHORT;
- if (className.equals(BIGDECIMAL.getClassName()))
- return BIGDECIMAL;
- if (className.equals(BIGINTEGER.getClassName()))
- return BIGINTEGER;
- if (className.equals(VOID.getClassName()) || className.equals(Void.TYPE.getName()))
- return VOID;
- if (className.equals(DATE.getClassName()))
- return DATE;
- if (className.equals(NAMEDOBJECT.getClassName()))
- return NAMEDOBJECT;
- return null;
- }
-
- /**
- * Construct an SimpleMetaType.<p>
- *
- * This constructor is used to construct the static simple meta types.
- *
- * @param className the name of the class implementing the type
- */
- private SimpleMetaType(String className)
- {
- super(className);
- cachedHashCode = getClassName().hashCode();
- StringBuilder buffer = new StringBuilder(SimpleMetaType.class.getSimpleName());
- buffer.append(":");
- buffer.append(getClassName());
- cachedToString = buffer.toString();
- }
-
- /**
- * Construct a simple meta type.
- *
- * @param clazz the class
- * @param comparator class's comparator
- */
- private <T> SimpleMetaType(Class<T> clazz, Comparator<T> comparator)
- {
- this(clazz.getName());
- this.comparator = comparator;
- }
-
- /**
- * Compare objects.
- *
- * @param first the first object
- * @param second the second object
- * @return compare result
- */
- @SuppressWarnings("unchecked")
- public int compare(Object first, Object second)
- {
- if (comparator == null)
- return 0;
-
- if (first == null || second == null)
- throw new IllegalArgumentException("Null objects to compare.");
-
- return comparator.compare(first, second);
- }
-
- @Override
- public boolean isSimple()
- {
- return true;
- }
-
- @Override
- public boolean isValue(Object obj)
- {
- if (obj == null || obj instanceof SimpleValue == false)
- return false;
-
- SimpleValue value = (SimpleValue) obj;
- return equals(value.getMetaType());
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (this == obj)
- return true;
- if (obj == null || obj instanceof SimpleMetaType == false)
- return false;
- SimpleMetaType other = (SimpleMetaType) obj;
- return getClassName().equals(other.getClassName());
- }
-
- @Override
- public int hashCode()
- {
- return cachedHashCode;
- }
-
- @Override
- public String toString()
- {
- return cachedToString;
- }
-
- /**
- * Resolve to the singletons
-
- * @return the singletons
- * @throws ObjectStreamException for a corrupted stream
- */
- private Object readResolve() throws ObjectStreamException
- {
- return resolve(getClassName());
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/types/SimpleMetaType.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,339 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.types;
+
+import java.io.ObjectStreamException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Comparator;
+import java.util.Date;
+
+import org.jboss.metatype.api.types.helpers.BigDecimalComparator;
+import org.jboss.metatype.api.types.helpers.BigIntegerComparator;
+import org.jboss.metatype.api.types.helpers.BooleanComparator;
+import org.jboss.metatype.api.types.helpers.ByteComparator;
+import org.jboss.metatype.api.types.helpers.CharacterComparator;
+import org.jboss.metatype.api.types.helpers.DateComparator;
+import org.jboss.metatype.api.types.helpers.DoubleComparator;
+import org.jboss.metatype.api.types.helpers.FloatComparator;
+import org.jboss.metatype.api.types.helpers.IntegerComparator;
+import org.jboss.metatype.api.types.helpers.LongComparator;
+import org.jboss.metatype.api.types.helpers.NamedComparator;
+import org.jboss.metatype.api.types.helpers.ShortComparator;
+import org.jboss.metatype.api.types.helpers.StringComparator;
+import org.jboss.metatype.api.values.SimpleValue;
+
+/**
+ * SimpleMetaType.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleMetaType extends AbstractMetaType
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 6786422588217893696L;
+
+ /** Cached hash code */
+ private transient int cachedHashCode;
+
+ /** Cached string representation */
+ private transient String cachedToString;
+
+ /** The simple type for java.math.BigDecimal */
+ public static final SimpleMetaType BIGDECIMAL;
+
+ /** The simple type for java.math.BigInteger */
+ public static final SimpleMetaType BIGINTEGER;
+
+ /** The simple type for java.lang.Boolean */
+ public static final SimpleMetaType BOOLEAN;
+ public static final SimpleMetaType BOOLEAN_PRIMITIVE;
+
+ /** The simple type for java.lang.Byte */
+ public static final SimpleMetaType BYTE;
+ public static final SimpleMetaType BYTE_PRIMITIVE;
+
+ /** The simple type for java.lang.Character */
+ public static final SimpleMetaType CHARACTER;
+ public static final SimpleMetaType CHARACTER_PRIMITIVE;
+
+ /** The simple type for java.lang.Date */
+ public static final SimpleMetaType DATE;
+
+ /** The simple type for java.lang.Double */
+ public static final SimpleMetaType DOUBLE;
+ public static final SimpleMetaType DOUBLE_PRIMITIVE;
+
+ /** The simple type for java.lang.Float */
+ public static final SimpleMetaType FLOAT;
+ public static final SimpleMetaType FLOAT_PRIMITIVE;
+
+ /** The simple type for java.lang.Integer */
+ public static final SimpleMetaType INTEGER;
+ public static final SimpleMetaType INTEGER_PRIMITIVE;
+
+ /** The simple type for java.lang.Long */
+ public static final SimpleMetaType LONG;
+ public static final SimpleMetaType LONG_PRIMITIVE;
+
+ /** The simple type for java.lang.Short */
+ public static final SimpleMetaType SHORT;
+ public static final SimpleMetaType SHORT_PRIMITIVE;
+
+ /** The simple type for java.lang.String */
+ public static final SimpleMetaType STRING;
+
+ /** The simple type for an object name */
+ public static final SimpleMetaType NAMEDOBJECT;
+
+ /** The simple type for java.lang.Void */
+ public static final SimpleMetaType VOID;
+
+ /** The comparator */
+ private transient Comparator comparator;
+ /** */
+ private transient char primitiveType;
+
+ static
+ {
+ BIGDECIMAL = new SimpleMetaType(BigDecimal.class, BigDecimalComparator.INSTANCE);
+ BIGINTEGER = new SimpleMetaType(BigInteger.class, BigIntegerComparator.INSTANCE);
+ BOOLEAN = new SimpleMetaType(Boolean.class, BooleanComparator.INSTANCE, 'Z');
+ BOOLEAN_PRIMITIVE = new SimpleMetaType(boolean.class, BooleanComparator.INSTANCE, 'Z');
+ BYTE = new SimpleMetaType(Byte.class, ByteComparator.INSTANCE, 'B');
+ BYTE_PRIMITIVE = new SimpleMetaType(byte.class, ByteComparator.INSTANCE, 'B');
+ CHARACTER = new SimpleMetaType(Character.class, CharacterComparator.INSTANCE, 'C');
+ CHARACTER_PRIMITIVE = new SimpleMetaType(char.class, CharacterComparator.INSTANCE, 'C');
+ DATE = new SimpleMetaType(Date.class, DateComparator.INSTANCE);
+ DOUBLE = new SimpleMetaType(Double.class, DoubleComparator.INSTANCE, 'D');
+ DOUBLE_PRIMITIVE = new SimpleMetaType(double.class, DoubleComparator.INSTANCE, 'D');
+ FLOAT = new SimpleMetaType(Float.class, FloatComparator.INSTANCE, 'F');
+ FLOAT_PRIMITIVE = new SimpleMetaType(float.class, FloatComparator.INSTANCE, 'F');
+ INTEGER = new SimpleMetaType(Integer.class, IntegerComparator.INSTANCE, 'I');
+ INTEGER_PRIMITIVE = new SimpleMetaType(int.class, IntegerComparator.INSTANCE, 'I');
+ LONG = new SimpleMetaType(Long.class, LongComparator.INSTANCE, 'J');
+ LONG_PRIMITIVE = new SimpleMetaType(long.class, LongComparator.INSTANCE, 'J');
+ SHORT = new SimpleMetaType(Short.class, ShortComparator.INSTANCE, 'S');
+ SHORT_PRIMITIVE = new SimpleMetaType(short.class, ShortComparator.INSTANCE, 'S');
+ STRING = new SimpleMetaType(String.class, StringComparator.INSTANCE);
+ NAMEDOBJECT = new SimpleMetaType(Name.class, NamedComparator.INSTANCE);
+ VOID = new SimpleMetaType(Void.class, null);
+ }
+
+ /**
+ * Resolve a simple type
+ *
+ * @param className the class name of the simple type
+ * @return the simple type
+ * @throws IllegalArgumentException for a null className or if it is not a simple type
+ */
+ public static SimpleMetaType resolve(String className)
+ {
+ SimpleMetaType result = isSimpleType(className);
+ if (result != null)
+ return result;
+ throw new IllegalArgumentException("Class is not a simple type: " + className);
+ }
+
+ /**
+ * Return the simple type if the class name is a simple type
+ * otherwise null.
+ *
+ * @param className the class name of the simple type
+ * @return the simple type
+ * @throws IllegalArgumentException for a null className
+ */
+ public static SimpleMetaType isSimpleType(String className)
+ {
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+ if (className.equals(STRING.getClassName()))
+ return STRING;
+ if (className.equals(INTEGER.getClassName()))
+ return INTEGER;
+ if (className.equals(Integer.TYPE.getName()))
+ return INTEGER_PRIMITIVE;
+ if (className.equals(BOOLEAN.getClassName()))
+ return BOOLEAN;
+ if (className.equals(Boolean.TYPE.getName()))
+ return BOOLEAN_PRIMITIVE;
+ if (className.equals(LONG.getClassName()))
+ return LONG;
+ if ( className.equals(Long.TYPE.getName()))
+ return LONG_PRIMITIVE;
+ if (className.equals(BYTE.getClassName()))
+ return BYTE;
+ if (className.equals(Byte.TYPE.getName()))
+ return BYTE_PRIMITIVE;
+ if (className.equals(CHARACTER.getClassName()))
+ return CHARACTER;
+ if (className.equals(Character.TYPE.getName()))
+ return CHARACTER_PRIMITIVE;
+ if (className.equals(DOUBLE.getClassName()))
+ return DOUBLE;
+ if (className.equals(Double.TYPE.getName()))
+ return DOUBLE_PRIMITIVE;
+ if (className.equals(FLOAT.getClassName()))
+ return FLOAT;
+ if(className.equals(Float.TYPE.getName()))
+ return FLOAT_PRIMITIVE;
+ if (className.equals(SHORT.getClassName()))
+ return SHORT;
+ if (className.equals(Short.TYPE.getName()))
+ return SHORT_PRIMITIVE;
+ if (className.equals(BIGDECIMAL.getClassName()))
+ return BIGDECIMAL;
+ if (className.equals(BIGINTEGER.getClassName()))
+ return BIGINTEGER;
+ if (className.equals(VOID.getClassName()) || className.equals(Void.TYPE.getName()))
+ return VOID;
+ if (className.equals(DATE.getClassName()))
+ return DATE;
+ if (className.equals(NAMEDOBJECT.getClassName()))
+ return NAMEDOBJECT;
+ return null;
+ }
+
+ /**
+ * Construct an SimpleMetaType.<p>
+ *
+ * This constructor is used to construct the static simple meta types.
+ *
+ * @param className the name of the class implementing the type
+ */
+ private SimpleMetaType(String className)
+ {
+ super(className);
+ cachedHashCode = getClassName().hashCode();
+ StringBuilder buffer = new StringBuilder(SimpleMetaType.class.getSimpleName());
+ buffer.append(":");
+ buffer.append(getClassName());
+ cachedToString = buffer.toString();
+ }
+
+ /**
+ * Construct a simple meta type.
+ *
+ * @param clazz the class
+ * @param comparator class's comparator
+ */
+ private <T> SimpleMetaType(Class<T> clazz, Comparator<T> comparator)
+ {
+ this(clazz, comparator, '\0');
+ }
+ private <T> SimpleMetaType(Class<T> clazz, Comparator<T> comparator, char primitiveType)
+ {
+ this(clazz.getName());
+ this.comparator = comparator;
+ this.primitiveType = primitiveType;
+ }
+
+ /**
+ * Compare objects.
+ *
+ * @param first the first object
+ * @param second the second object
+ * @return compare result
+ */
+ @SuppressWarnings("unchecked")
+ public int compare(Object first, Object second)
+ {
+ if (comparator == null)
+ return 0;
+
+ if (first == null || second == null)
+ throw new IllegalArgumentException("Null objects to compare.");
+
+ return comparator.compare(first, second);
+ }
+
+ @Override
+ public boolean isSimple()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isPrimitive()
+ {
+ return primitiveType != '\0'
+ && this.getTypeName().startsWith("java.lang") == false;
+ }
+
+ @Override
+ public boolean isValue(Object obj)
+ {
+ if (obj == null || obj instanceof SimpleValue == false)
+ return false;
+
+ SimpleValue value = (SimpleValue) obj;
+ return equals(value.getMetaType());
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ return true;
+ if (obj == null || obj instanceof SimpleMetaType == false)
+ return false;
+ SimpleMetaType other = (SimpleMetaType) obj;
+ return getClassName().equals(other.getClassName());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return cachedHashCode;
+ }
+
+ @Override
+ public String toString()
+ {
+ return cachedToString;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public boolean equalsIgnorePrimitive(Object obj)
+ {
+ if (obj == null || obj instanceof SimpleMetaType == false)
+ return false;
+ SimpleMetaType other = (SimpleMetaType) obj;
+ return this.primitiveType == other.primitiveType;
+ }
+
+ /**
+ * Resolve to the singletons
+
+ * @return the singletons
+ * @throws ObjectStreamException for a corrupted stream
+ */
+ private Object readResolve() throws ObjectStreamException
+ {
+ return resolve(getClassName());
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,149 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.metatype.api.values;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.MapCompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-
-/**
- * A CompositeValue for Map<String,MetaValue>
- *
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class MapCompositeValueSupport extends AbstractMetaValue implements CompositeValue
-{
- private static final long serialVersionUID = 1;
- private Map<String, MetaValue> map;
- private MapCompositeMetaType mapType;
-
- public MapCompositeValueSupport(MetaType valueType)
- {
- this(null, valueType);
- }
-
- public MapCompositeValueSupport(Map<String, MetaValue> map, MetaType valueType)
- {
- this.map = createMap();
- this.mapType = new MapCompositeMetaType(valueType);
- if(map != null)
- {
- for(Map.Entry<String, MetaValue> entry : map.entrySet())
- this.put(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * Create map instance.
- * Default is hash map.
- *
- * @return the map
- */
- protected Map<String, MetaValue> createMap()
- {
- return new HashMap<String, MetaValue>();
- }
-
- public boolean containsKey(String key)
- {
- return map.containsKey(key);
- }
-
- public boolean containsValue(MetaValue value)
- {
- return map.containsValue(value);
- }
-
- public MetaValue get(String key)
- {
- return map.get(key);
- }
-
- public void put(String key, MetaValue value)
- {
- if(mapType.containsItem(key) == false)
- mapType.addItem(key);
- map.put(key, value);
- }
-
- public MetaValue[] getAll(String[] keys)
- {
- List<MetaValue> values = new ArrayList<MetaValue>();
- if(keys != null)
- {
- for(String key : keys)
- {
- MetaValue value = map.get(key);
- values.add(value);
- }
- }
- MetaValue[] mvs = new MetaValue[values.size()];
- return values.toArray(mvs);
- }
-
- public CompositeMetaType getMetaType()
- {
- return mapType;
- }
-
- public Collection<MetaValue> values()
- {
- return map.values();
- }
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- return true;
-
- if (obj == null || obj instanceof MapCompositeValueSupport == false)
- return false;
-
- MapCompositeValueSupport other = (MapCompositeValueSupport) obj;
- if (mapType.equals(other.getMetaType()) == false)
- return false;
-
- Map<String, MetaValue> otherMap = other.map;
- if (map == null && otherMap == null)
- return true;
- if (map == null && otherMap != null)
- return false;
- return map.equals(otherMap);
- }
- @Override
- public int hashCode()
- {
- return map.hashCode();
- }
- @Override
- public String toString()
- {
- return mapType + ":" + map;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java (from rev 84841, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MapCompositeValueSupport.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metatype.api.values;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+
+/**
+ * A CompositeValue for Map<String,MetaValue>
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class MapCompositeValueSupport extends AbstractMetaValue implements CompositeValue
+{
+ private static final long serialVersionUID = 1;
+ private Map<String, MetaValue> map;
+ private MapCompositeMetaType mapType;
+
+ public MapCompositeValueSupport(MetaType valueType)
+ {
+ this(null, valueType);
+ }
+
+ public MapCompositeValueSupport(Map<String, MetaValue> map, MetaType valueType)
+ {
+ this.map = createMap();
+ this.mapType = new MapCompositeMetaType(valueType);
+ if(map != null)
+ {
+ for(Map.Entry<String, MetaValue> entry : map.entrySet())
+ this.put(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Create map instance.
+ * Default is hash map.
+ *
+ * @return the map
+ */
+ protected Map<String, MetaValue> createMap()
+ {
+ return new HashMap<String, MetaValue>();
+ }
+
+ public boolean containsKey(String key)
+ {
+ return map.containsKey(key);
+ }
+
+ public boolean containsValue(MetaValue value)
+ {
+ return map.containsValue(value);
+ }
+
+ public MetaValue get(String key)
+ {
+ return map.get(key);
+ }
+
+ public void put(String key, MetaValue value)
+ {
+ if(mapType.containsItem(key) == false)
+ mapType.addItem(key);
+ map.put(key, value);
+ }
+
+ public MetaValue remove(String key)
+ {
+ return map.remove(key);
+ }
+
+ public MetaValue[] getAll(String[] keys)
+ {
+ List<MetaValue> values = new ArrayList<MetaValue>();
+ if(keys != null)
+ {
+ for(String key : keys)
+ {
+ MetaValue value = map.get(key);
+ values.add(value);
+ }
+ }
+ MetaValue[] mvs = new MetaValue[values.size()];
+ return values.toArray(mvs);
+ }
+
+ public CompositeMetaType getMetaType()
+ {
+ return mapType;
+ }
+
+ public Collection<MetaValue> values()
+ {
+ return map.values();
+ }
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+
+ if (obj == null || obj instanceof MapCompositeValueSupport == false)
+ return false;
+
+ MapCompositeValueSupport other = (MapCompositeValueSupport) obj;
+ if (mapType.equals(other.getMetaType()) == false)
+ return false;
+
+ Map<String, MetaValue> otherMap = other.map;
+ if (map == null && otherMap == null)
+ return true;
+ if (map == null && otherMap != null)
+ return false;
+ return map.equals(otherMap);
+ }
+ @Override
+ public int hashCode()
+ {
+ return map.hashCode();
+ }
+ @Override
+ public String toString()
+ {
+ return mapType + ":" + map;
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,125 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.values;
-
-import java.lang.reflect.Type;
-
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
-import org.jboss.metatype.spi.values.MetaValueBuilder;
-import org.jboss.reflect.spi.TypeInfo;
-
-/**
- * MetaValueFactory.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @version $Revision: 1.1 $
- */
-public abstract class MetaValueFactory
-{
- /** The singleton builder */
- private static final MetaValueFactoryBuilder builder = new MetaValueFactoryBuilder();
-
- /**
- * Get the metatype factory
- *
- * @return the instance
- */
- public static final MetaValueFactory getInstance()
- {
- return builder.create();
- }
-
- /**
- * Create a meta value
- *
- * @param value the value
- * @return the meta value
- */
- public abstract MetaValue create(Object value);
-
- /**
- * Create a meta value
- *
- * @param value the value
- * @param type the type
- * @return the meta value
- */
- public abstract MetaValue create(Object value, Type type);
-
- /**
- * Create a meta value
- *
- * @param value the value
- * @param type the type
- * @return the meta value
- */
- public abstract MetaValue create(Object value, TypeInfo type);
-
- /**
- * Set a meta value builder.
- *
- * @param clazz the class
- * @param builder the builder
- */
- public abstract void setBuilder(Class<?> clazz, MetaValueBuilder<?> builder);
-
- /**
- * Set an instance factory.
- *
- * @param <T> exact instance type
- * @param clazz the class
- * @param factory the factory
- */
- public abstract <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory);
-
- /**
- * Unwrap meta value.
- * Supports simple and generic meta value.
- *
- * @param metaValue meta value
- * @return meta value's value
- */
- public abstract Object unwrap(MetaValue metaValue);
-
- /**
- * Unwrap meta value.
- * Supports simple and generic meta value.
- *
- * @param metaValue meta value
- * @param type the type
- * @return meta value's value
- */
- public abstract Object unwrap(MetaValue metaValue, Type type);
-
- /**
- * Unwrap meta value.
- * Supports simple and generic meta value.
- *
- * @param metaValue meta value
- * @param type the type
- * @return meta value's value
- */
- public abstract Object unwrap(MetaValue metaValue, TypeInfo type);
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java (from rev 84814, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/MetaValueFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,133 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.values;
+
+import java.lang.reflect.Type;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
+import org.jboss.metatype.spi.values.MetaValueBuilder;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * MetaValueFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class MetaValueFactory
+{
+ /** The singleton builder */
+ private static final MetaValueFactoryBuilder builder = new MetaValueFactoryBuilder();
+
+ /**
+ * Get the metatype factory
+ *
+ * @return the instance
+ */
+ public static final MetaValueFactory getInstance()
+ {
+ return builder.create();
+ }
+
+ /**
+ * Create a meta value
+ *
+ * @param value the value
+ * @return the meta value
+ */
+ public abstract MetaValue create(Object value);
+
+ /**
+ * Create a meta value
+ *
+ * @param value the value
+ * @param type the type
+ * @return the meta value
+ */
+ public abstract MetaValue create(Object value, Type type);
+
+ /**
+ * Create a meta value
+ *
+ * @param value the value
+ * @param type the type
+ * @return the meta value
+ */
+ public abstract MetaValue create(Object value, TypeInfo type);
+
+ /**
+ * Create a meta value given its MetaType
+ * @param value
+ * @param type the meta type
+ * @return the meta value
+ */
+ public abstract MetaValue create(Object value, MetaType type);
+
+ /**
+ * Set a meta value builder.
+ *
+ * @param clazz the class
+ * @param builder the builder
+ */
+ public abstract void setBuilder(Class<?> clazz, MetaValueBuilder<?> builder);
+
+ /**
+ * Set an instance factory.
+ *
+ * @param <T> exact instance type
+ * @param clazz the class
+ * @param factory the factory
+ */
+ public abstract <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory);
+
+ /**
+ * Unwrap meta value.
+ * Supports simple and generic meta value.
+ *
+ * @param metaValue meta value
+ * @return meta value's value
+ */
+ public abstract Object unwrap(MetaValue metaValue);
+
+ /**
+ * Unwrap meta value.
+ * Supports simple and generic meta value.
+ *
+ * @param metaValue meta value
+ * @param type the type
+ * @return meta value's value
+ */
+ public abstract Object unwrap(MetaValue metaValue, Type type);
+
+ /**
+ * Unwrap meta value.
+ * Supports simple and generic meta value.
+ *
+ * @param metaValue meta value
+ * @param type the type
+ * @return meta value's value
+ */
+ public abstract Object unwrap(MetaValue metaValue, TypeInfo type);
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,98 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.metatype.api.values;
-
-import java.util.Map;
-import java.util.Properties;
-
-import org.jboss.metatype.api.types.PropertiesMetaType;
-
-/**
- * A mapping from the jdk Properties to a MetaValue
- * @author Scott.Stark at jboss.org
- * @version $Revision:$
- */
-public class PropertiesMetaValue extends Properties
- implements MetaValue
-{
- private static final long serialVersionUID = 1;
- private PropertiesMetaType type;
-
- /**
- * Build a PropertiesMetaValue from a Properties by copying all key/value
- * pairs from props into the new PropertiesMetaValue.
- *
- * @param props - the Properties to copy
- * @return PropertiesMetaValue
- */
- public static PropertiesMetaValue wrap(Map<String,String> props)
- {
- PropertiesMetaValue value = new PropertiesMetaValue();
- value.putAll(props);
- return value;
- }
-
- /**
- * Creates an empty PropertiesMetaValue
- */
- public PropertiesMetaValue()
- {
- }
- /**
- * Create a PropertiesMetaValue with props as the defaults. If you want to
- * create a PropertiesMetaValue with only the key/value pairs of props use
- * {@link #wrap(Properties)}.
- *
- * @param props - default properties
- */
- public PropertiesMetaValue(Properties props)
- {
- this(props, PropertiesMetaType.INSTANCE);
- }
- /**
- * Create a PropertiesMetaValue with props as the defaults. If you want to
- * create a PropertiesMetaValue with only the key/value pairs of props use
- * {@link #wrap(Properties)}.
- *
- * @param props - default properties
- * @param type - the properties
- */
- public PropertiesMetaValue(Properties props, PropertiesMetaType type)
- {
- super(props);
- this.type = type;
- }
-
- public PropertiesMetaType getMetaType()
- {
- return type;
- }
-
- @Override
- public MetaValue clone()
- {
- PropertiesMetaValue clone = new PropertiesMetaValue();
- clone.putAll(this);
- return clone;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/PropertiesMetaValue.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metatype.api.values;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.jboss.metatype.api.types.PropertiesMetaType;
+
+/**
+ * A mapping from the jdk Properties to a MetaValue
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesMetaValue extends Properties
+ implements MetaValue
+{
+ private static final long serialVersionUID = 1;
+ private PropertiesMetaType type = PropertiesMetaType.INSTANCE;
+
+ /**
+ * Build a PropertiesMetaValue from a Properties by copying all key/value
+ * pairs from props into the new PropertiesMetaValue.
+ *
+ * @param props - the Properties to copy
+ * @return PropertiesMetaValue
+ */
+ public static PropertiesMetaValue wrap(Map<String,String> props)
+ {
+ PropertiesMetaValue value = new PropertiesMetaValue();
+ value.putAll(props);
+ return value;
+ }
+
+ /**
+ * Creates an empty PropertiesMetaValue
+ */
+ public PropertiesMetaValue()
+ {
+ }
+ /**
+ * Create a PropertiesMetaValue with props as the defaults. If you want to
+ * create a PropertiesMetaValue with only the key/value pairs of props use
+ * {@link #wrap(Properties)}.
+ *
+ * @param props - default properties
+ */
+ public PropertiesMetaValue(Properties props)
+ {
+ this(props, PropertiesMetaType.INSTANCE);
+ }
+ /**
+ * Create a PropertiesMetaValue with props as the defaults. If you want to
+ * create a PropertiesMetaValue with only the key/value pairs of props use
+ * {@link #wrap(Properties)}.
+ *
+ * @param props - default properties
+ * @param type - the properties
+ */
+ public PropertiesMetaValue(Properties props, PropertiesMetaType type)
+ {
+ super(props);
+ this.type = type;
+ }
+
+ public PropertiesMetaType getMetaType()
+ {
+ return type;
+ }
+
+ @Override
+ public MetaValue clone()
+ {
+ PropertiesMetaValue clone = new PropertiesMetaValue();
+ clone.putAll(this);
+ return clone;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,264 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.api.values;
-
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Date;
-
-import org.jboss.metatype.api.types.Name;
-import org.jboss.metatype.api.types.SimpleMetaType;
-
-/**
- * SimpleValue.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleValueSupport extends AbstractMetaValue implements SimpleValue
-{
- /** The serialVersionUID */
- private static final long serialVersionUID = 8473043036261557127L;
-
- /** The simple meta type */
- private SimpleMetaType metaType;
-
- /** The value */
- private Serializable value;
-
- /**
- * Wrap a simple object in simple value
- *
- * @param object the simple object
- * @return the simple value
- */
- public static SimpleValue wrap(Serializable object)
- {
- if (object == null)
- return null;
- String className = object.getClass().getName();
- SimpleMetaType metaType = SimpleMetaType.resolve(className);
- return new SimpleValueSupport(metaType, object);
- }
-
- /**
- * Create a new SimpleValueSupport.
- *
- * @param metaType the simple meta type
- * @param value the value
- * @throws IllegalArgumentException for a null simpleMetaType
- */
- public SimpleValueSupport(SimpleMetaType metaType, Serializable value)
- {
- if (metaType == null)
- throw new IllegalArgumentException("Null simple meta type");
- this.metaType = metaType;
- setValue(value);
- }
-
- public SimpleMetaType getMetaType()
- {
- return metaType;
- }
-
- /**
- * Get the value.
- *
- * @return the value.
- */
- public Serializable getValue()
- {
- return value;
- }
-
- /**
- * Set the value.
- *
- * @param value the value.
- */
- public void setValue(Serializable value)
- {
- this.value = value;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (obj == this)
- return true;
-
- if (obj == null || obj instanceof SimpleValue == false)
- return false;
-
- SimpleValue other = (SimpleValue) obj;
- if (metaType.equals(other.getMetaType()) == false)
- return false;
-
- Object otherValue = other.getValue();
- if (value == null && otherValue == null)
- return true;
- if (value == null && otherValue != null)
- return false;
- return value.equals(otherValue);
- }
-
- @Override
- public int hashCode()
- {
- if (value == null)
- return 0;
- return value.hashCode();
- }
-
- @Override
- public String toString()
- {
- return metaType + ":" + value;
- }
-
- public int compareTo(SimpleValue sv)
- {
- int compare = -1;
- if(getMetaType() == SimpleMetaType.BIGINTEGER && sv.getMetaType() == SimpleMetaType.BIGINTEGER)
- {
- BigInteger v1 = BigInteger.class.cast(value);
- BigInteger v2 = BigInteger.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.BIGDECIMAL && sv.getMetaType() == SimpleMetaType.BIGDECIMAL)
- {
- BigDecimal v1 = BigDecimal.class.cast(value);
- BigDecimal v2 = BigDecimal.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.BOOLEAN && sv.getMetaType() == SimpleMetaType.BOOLEAN)
- {
- Boolean v1 = Boolean.class.cast(value);
- Boolean v2 = Boolean.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.BYTE && sv.getMetaType() == SimpleMetaType.BYTE)
- {
- Byte v1 = Byte.class.cast(value);
- Byte v2 = Byte.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.CHARACTER && sv.getMetaType() == SimpleMetaType.CHARACTER)
- {
- Character v1 = Character.class.cast(value);
- Character v2 = Character.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.DATE && sv.getMetaType() == SimpleMetaType.DATE)
- {
- Date v1 = Date.class.cast(value);
- Date v2 = Date.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.DOUBLE && sv.getMetaType() == SimpleMetaType.DOUBLE)
- {
- Double v1 = Double.class.cast(value);
- Double v2 = Double.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.FLOAT && sv.getMetaType() == SimpleMetaType.FLOAT)
- {
- Float v1 = Float.class.cast(value);
- Float v2 = Float.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.INTEGER && sv.getMetaType() == SimpleMetaType.INTEGER)
- {
- Integer v1 = Integer.class.cast(value);
- Integer v2 = Integer.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.LONG && sv.getMetaType() == SimpleMetaType.LONG)
- {
- Long v1 = Long.class.cast(value);
- Long v2 = Long.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.SHORT && sv.getMetaType() == SimpleMetaType.SHORT)
- {
- Short v1 = Short.class.cast(value);
- Short v2 = Short.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.STRING && sv.getMetaType() == SimpleMetaType.STRING)
- {
- String v1 = String.class.cast(value);
- String v2 = String.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.NAMEDOBJECT && sv.getMetaType() == SimpleMetaType.NAMEDOBJECT)
- {
- Name v1 = Name.class.cast(value);
- Name v2 = Name.class.cast(sv.getValue());
- compare = v1.compareTo(v2);
- }
- else if(getMetaType() == SimpleMetaType.VOID && sv.getMetaType() == SimpleMetaType.VOID)
- {
- compare = 0;
- }
- else if(value instanceof Number && sv.getValue() instanceof Number)
- {
- // Compare two Numbers using the most precise type
- Number n0 = (Number) value;
- Number n1 = (Number) sv.getValue();
- if(n0 instanceof BigDecimal)
- {
- BigDecimal db0 = (BigDecimal) n0;
- BigDecimal db1 = new BigDecimal(n1.doubleValue());
- compare = db0.compareTo(db1);
- }
- else if(n1 instanceof BigDecimal)
- {
- BigDecimal db1 = (BigDecimal) n1;
- BigDecimal db0 = new BigDecimal(n0.doubleValue());
- compare = db0.compareTo(db1);
- }
- else if(n0 instanceof Float || n0 instanceof Double
- || n1 instanceof Float || n1 instanceof Double)
- {
- double d0 = n0.doubleValue();
- double d1 = n1.doubleValue();
- compare = Double.compare(d0, d1);
- }
- else
- {
- long l0 = n0.longValue();
- long l1 = n1.longValue();
- if(l0 < l1)
- compare = -1;
- else if(l0 > l1)
- compare = 1;
- else
- compare = 0;
- }
- }
-
- return compare;
- }
-
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/api/values/SimpleValueSupport.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,304 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.api.values;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import org.jboss.metatype.api.types.Name;
+import org.jboss.metatype.api.types.SimpleMetaType;
+
+/**
+ * SimpleValue.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleValueSupport extends AbstractMetaValue implements SimpleValue
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 8473043036261557127L;
+
+ /** The simple meta type */
+ private SimpleMetaType metaType;
+
+ /** The value */
+ private Serializable value;
+
+ /**
+ * Wrap a simple object in simple value
+ *
+ * @param object the simple object
+ * @return the simple value
+ */
+ public static SimpleValue wrap(Serializable object)
+ {
+ if (object == null)
+ return null;
+ String className = object.getClass().getName();
+ return wrap(object, className);
+ }
+ private static SimpleValue wrap(Serializable object, String className)
+ {
+ SimpleMetaType metaType = SimpleMetaType.resolve(className);
+ return new SimpleValueSupport(metaType, object);
+ }
+ public static SimpleValue wrap(boolean value)
+ {
+ return wrap(value, boolean.class.getName());
+ }
+ public static SimpleValue wrap(byte value)
+ {
+ return wrap(value, byte.class.getName());
+ }
+ public static SimpleValue wrap(char value)
+ {
+ return wrap(value, char.class.getName());
+ }
+ public static SimpleValue wrap(short value)
+ {
+ return wrap(value, short.class.getName());
+ }
+ public static SimpleValue wrap(int value)
+ {
+ return wrap(value, int.class.getName());
+ }
+ public static SimpleValue wrap(long value)
+ {
+ return wrap(value, long.class.getName());
+ }
+ public static SimpleValue wrap(float value)
+ {
+ return wrap(value, float.class.getName());
+ }
+ public static SimpleValue wrap(double value)
+ {
+ return wrap(value, double.class.getName());
+ }
+
+ /**
+ * Create a new SimpleValueSupport.
+ *
+ * @param metaType the simple meta type
+ * @param value the value
+ * @throws IllegalArgumentException for a null simpleMetaType
+ */
+ public SimpleValueSupport(SimpleMetaType metaType, Serializable value)
+ {
+ if (metaType == null)
+ throw new IllegalArgumentException("Null simple meta type");
+ this.metaType = metaType;
+ setValue(value);
+ }
+
+ public SimpleMetaType getMetaType()
+ {
+ return metaType;
+ }
+
+ /**
+ * Get the value.
+ *
+ * @return the value.
+ */
+ public Serializable getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Set the value.
+ *
+ * @param value the value.
+ */
+ public void setValue(Serializable value)
+ {
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+
+ if (obj == null || obj instanceof SimpleValue == false)
+ return false;
+
+ SimpleValue other = (SimpleValue) obj;
+ if (metaType.equals(other.getMetaType()) == false)
+ {
+ // Check equivalent types
+ if (metaType.equalsIgnorePrimitive(other.getMetaType()) == false)
+ return false;
+ }
+
+ Object otherValue = other.getValue();
+ if (value == null && otherValue == null)
+ return true;
+ if (value == null && otherValue != null)
+ return false;
+ return value.equals(otherValue);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if (value == null)
+ return 0;
+ return value.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return metaType + ":" + value;
+ }
+
+ public int compareTo(SimpleValue sv)
+ {
+ int compare = -1;
+ if(getMetaType() == SimpleMetaType.BIGINTEGER && sv.getMetaType() == SimpleMetaType.BIGINTEGER)
+ {
+ BigInteger v1 = BigInteger.class.cast(value);
+ BigInteger v2 = BigInteger.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.BIGDECIMAL && sv.getMetaType() == SimpleMetaType.BIGDECIMAL)
+ {
+ BigDecimal v1 = BigDecimal.class.cast(value);
+ BigDecimal v2 = BigDecimal.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.BOOLEAN && sv.getMetaType() == SimpleMetaType.BOOLEAN)
+ {
+ Boolean v1 = Boolean.class.cast(value);
+ Boolean v2 = Boolean.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.BYTE && sv.getMetaType() == SimpleMetaType.BYTE)
+ {
+ Byte v1 = Byte.class.cast(value);
+ Byte v2 = Byte.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.CHARACTER && sv.getMetaType() == SimpleMetaType.CHARACTER)
+ {
+ Character v1 = Character.class.cast(value);
+ Character v2 = Character.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.DATE && sv.getMetaType() == SimpleMetaType.DATE)
+ {
+ Date v1 = Date.class.cast(value);
+ Date v2 = Date.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.DOUBLE && sv.getMetaType() == SimpleMetaType.DOUBLE)
+ {
+ Double v1 = Double.class.cast(value);
+ Double v2 = Double.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.FLOAT && sv.getMetaType() == SimpleMetaType.FLOAT)
+ {
+ Float v1 = Float.class.cast(value);
+ Float v2 = Float.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.INTEGER && sv.getMetaType() == SimpleMetaType.INTEGER)
+ {
+ Integer v1 = Integer.class.cast(value);
+ Integer v2 = Integer.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.LONG && sv.getMetaType() == SimpleMetaType.LONG)
+ {
+ Long v1 = Long.class.cast(value);
+ Long v2 = Long.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.SHORT && sv.getMetaType() == SimpleMetaType.SHORT)
+ {
+ Short v1 = Short.class.cast(value);
+ Short v2 = Short.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.STRING && sv.getMetaType() == SimpleMetaType.STRING)
+ {
+ String v1 = String.class.cast(value);
+ String v2 = String.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.NAMEDOBJECT && sv.getMetaType() == SimpleMetaType.NAMEDOBJECT)
+ {
+ Name v1 = Name.class.cast(value);
+ Name v2 = Name.class.cast(sv.getValue());
+ compare = v1.compareTo(v2);
+ }
+ else if(getMetaType() == SimpleMetaType.VOID && sv.getMetaType() == SimpleMetaType.VOID)
+ {
+ compare = 0;
+ }
+ else if(value instanceof Number && sv.getValue() instanceof Number)
+ {
+ // Compare two Numbers using the most precise type
+ Number n0 = (Number) value;
+ Number n1 = (Number) sv.getValue();
+ if(n0 instanceof BigDecimal)
+ {
+ BigDecimal db0 = (BigDecimal) n0;
+ BigDecimal db1 = new BigDecimal(n1.doubleValue());
+ compare = db0.compareTo(db1);
+ }
+ else if(n1 instanceof BigDecimal)
+ {
+ BigDecimal db1 = (BigDecimal) n1;
+ BigDecimal db0 = new BigDecimal(n0.doubleValue());
+ compare = db0.compareTo(db1);
+ }
+ else if(n0 instanceof Float || n0 instanceof Double
+ || n1 instanceof Float || n1 instanceof Double)
+ {
+ double d0 = n0.doubleValue();
+ double d1 = n1.doubleValue();
+ compare = Double.compare(d0, d1);
+ }
+ else
+ {
+ long l0 = n0.longValue();
+ long l1 = n1.longValue();
+ if(l0 < l1)
+ compare = -1;
+ else if(l0 > l1)
+ compare = 1;
+ else
+ compare = 0;
+ }
+ }
+
+ return compare;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,450 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.plugins.types;
-
-import java.lang.ref.WeakReference;
-import java.lang.reflect.Type;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.ArrayList;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.WeakHashMap;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.config.plugins.property.PropertyConfiguration;
-import org.jboss.config.spi.Configuration;
-import org.jboss.metatype.api.annotations.CompositeKey;
-import org.jboss.metatype.api.annotations.CompositeValue;
-import org.jboss.metatype.api.annotations.Generic;
-import org.jboss.metatype.api.annotations.MetaTypeConstants;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.EnumMetaType;
-import org.jboss.metatype.api.types.GenericMetaType;
-import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
-import org.jboss.metatype.api.types.ImmutableTableMetaType;
-import org.jboss.metatype.api.types.MapCompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.MetaTypeFactory;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.types.TableMetaType;
-import org.jboss.metatype.spi.types.MetaTypeBuilder;
-import org.jboss.metatype.spi.values.MetaMapper;
-import org.jboss.reflect.spi.ArrayInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.EnumConstantInfo;
-import org.jboss.reflect.spi.EnumInfo;
-import org.jboss.reflect.spi.InterfaceInfo;
-import org.jboss.reflect.spi.TypeInfo;
-
-/**
- * DefaultMetaTypeFactory.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class DefaultMetaTypeFactory extends MetaTypeFactory
-{
- /** The map key */
- public static final String MAP_KEY = "key";
-
- /** The map value */
- public static final String MAP_VALUE = "value";
-
- /** Map index names */
- public static final String[] MAP_INDEX_NAMES = { MAP_KEY };
-
- /** Map item names */
- public static final String[] MAP_ITEM_NAMES = { MAP_KEY, MAP_VALUE };
-
- /** The configuration */
- private static Configuration configuration;
-
- static
- {
- configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
- {
- public Configuration run()
- {
- return new PropertyConfiguration();
- }
- });
- }
-
- /** The object type info */
- private TypeInfo objectTypeInfo = configuration.getTypeInfo(Object.class);
-
- /** The builders */
- private Map<Class<?>, WeakReference<MetaTypeBuilder>> builders = new WeakHashMap<Class<?>, WeakReference<MetaTypeBuilder>>();
-
- /**
- * Create a new DefaultMetaTypeFactory.
- */
- public DefaultMetaTypeFactory()
- {
- // Special types
- setBuilder(Class.class, ClassMetaTypeBuilder.INSTANCE);
- }
-
- @Override
- public MetaType resolve(Type type)
- {
- TypeInfo typeInfo = configuration.getTypeInfo(type);
- return resolve(typeInfo);
- }
-
- /**
- * Resolve the meta type
- *
- * @param typeInfo the type
- * @return the meta type
- */
- public MetaType resolve(TypeInfo typeInfo)
- {
- // Look for a cached value
- MetaType result = typeInfo.getAttachment(MetaType.class);
- if (result == null)
- {
- // Generate it
- result = generate(typeInfo);
-
- // Cache it
- typeInfo.setAttachment(MetaType.class.getName(), result);
- }
-
- // Return the result
- return result;
- }
-
- public void setBuilder(Class<?> clazz, MetaTypeBuilder builder)
- {
- synchronized (builders)
- {
- if (builder == null)
- builders.remove(clazz);
- builders.put(clazz, new WeakReference<MetaTypeBuilder>(builder));
- }
- }
-
- /**
- * Generate the metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- public MetaType generate(TypeInfo typeInfo)
- {
- MetaType result = isBuilder(typeInfo);
- if (result != null)
- return result;
-
- MetaMapper<?> mapper = MetaMapper.getMetaMapper(typeInfo);
- if (mapper != null)
- return mapper.getMetaType();
-
- result = isGeneric(typeInfo);
- if (result != null)
- return result;
-
- if (typeInfo.isEnum())
- return generateEnum((EnumInfo) typeInfo);
-
- ClassInfo annotationType = isAnnotation(typeInfo);
- if (annotationType != null)
- return generateAnnotation(annotationType);
-
- if (typeInfo.isArray())
- return generateArray((ArrayInfo) typeInfo);
-
- if (typeInfo.isCollection())
- return generateCollection((ClassInfo) typeInfo);
-
- if (typeInfo.isMap())
- {
- // See if this is a Map<String,?> type
- ClassInfo classInfo = (ClassInfo) typeInfo;
- TypeInfo[] types = classInfo.getActualTypeArguments();
- if (types != null)
- {
- TypeInfo keyType = types[0];
- TypeInfo valueType = types[1];
- if(keyType.getName().equals(String.class.getName()))
- {
- // Use MapCompositeMetaType
- MetaType valueMetaType = resolve(valueType);
- return new MapCompositeMetaType(valueMetaType);
- }
- }
- // Map java.util.Properties to MapCompositeMetaType(SimpleMetaType.STRING)
- else if(typeInfo.getName().equals(Properties.class.getName()))
- {
- return new MapCompositeMetaType(SimpleMetaType.STRING);
- }
- // No, return the general map type
- return generateMap(classInfo);
- }
-
- result = SimpleMetaType.isSimpleType(typeInfo.getName());
- if (result != null)
- return result;
-
- return generateBean((ClassInfo) typeInfo);
- }
-
- /**
- * Generate an enum metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- public EnumMetaType generateEnum(EnumInfo typeInfo)
- {
- EnumConstantInfo[] constants = typeInfo.getEnumConstants();
- List<String> validValues = new ArrayList<String>(constants.length);
- for (EnumConstantInfo constant : constants)
- validValues.add(constant.getName());
- return new EnumMetaType(typeInfo.getName(), validValues);
- }
-
- /**
- * Whether this type is an annotation
- *
- * @param typeInfo the type info
- * @return the annotation type info
- */
- public ClassInfo isAnnotation(TypeInfo typeInfo)
- {
- if (typeInfo.isAnnotation())
- return (ClassInfo) typeInfo;
-
- if (typeInfo instanceof ClassInfo)
- {
- ClassInfo classInfo = (ClassInfo) typeInfo;
- InterfaceInfo[] interfaces = classInfo.getInterfaces();
- if (interfaces != null)
- {
- for (int i = 0; i < interfaces.length; ++i)
- {
- if (interfaces[i].isAnnotation())
- return interfaces[i];
- }
- }
- }
-
- // Doesn't look like an annotation
- return null;
- }
-
- /**
- * Generate an annotation metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- public CompositeMetaType generateAnnotation(ClassInfo typeInfo)
- {
- return generateBean(typeInfo);
- }
-
- /**
- * Generate an array metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- @SuppressWarnings("unchecked")
- public ArrayMetaType generateArray(ArrayInfo typeInfo)
- {
- int dimension = 1;
- TypeInfo componentType = typeInfo.getComponentType();
- while (componentType.isArray())
- {
- ++dimension;
- componentType = ((ArrayInfo) componentType).getComponentType();
- }
- MetaType componentMetaType = resolve(componentType);
- return new ArrayMetaType(dimension, componentMetaType, componentType.isPrimitive());
- }
-
- /**
- * Generate a collection metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- @SuppressWarnings("unchecked")
- public CollectionMetaType generateCollection(ClassInfo typeInfo)
- {
- TypeInfo elementType = objectTypeInfo;
-
- TypeInfo[] types = typeInfo.getActualTypeArguments();
- if (types != null)
- elementType = types[0];
-
- MetaType elementMetaType = resolve(elementType);
- return new CollectionMetaType(typeInfo.getName(), elementMetaType);
- }
-
- /**
- * Generate a map metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- public TableMetaType generateMap(ClassInfo typeInfo)
- {
- TypeInfo keyType = objectTypeInfo;
- TypeInfo valueType = objectTypeInfo;
-
- TypeInfo[] types = typeInfo.getActualTypeArguments();
- if (types != null)
- {
- keyType = types[0];
- valueType = types[1];
- }
- return createMapType(keyType, valueType);
- }
-
- /**
- * Create a map type
- *
- * @param keyType the key type
- * @param valueType the value type
- * @return the map type
- */
- public TableMetaType createMapType(TypeInfo keyType, TypeInfo valueType)
- {
- String name = Map.class.getName();
- MetaType[] itemTypes = { resolve(keyType), resolve(valueType) };
- CompositeMetaType entryType = createMapEntryType(itemTypes);
- return new ImmutableTableMetaType(name, name, entryType, MAP_INDEX_NAMES);
- }
-
- /**
- * Create a map entry type
- *
- * @param itemTypes the item types
- * @return the map entry type
- */
- public static CompositeMetaType createMapEntryType(MetaType[] itemTypes)
- {
- String entryName = Map.Entry.class.getName();
- return new ImmutableCompositeMetaType(entryName, entryName, MAP_ITEM_NAMES, MAP_ITEM_NAMES, itemTypes);
- }
-
- /**
- * Generate a bean metatype
- *
- * @param typeInfo the type info
- * @return the metatype
- */
- public CompositeMetaType generateBean(ClassInfo typeInfo)
- {
- BeanInfo beanInfo = configuration.getBeanInfo(typeInfo);
- MutableCompositeMetaType result = new MutableCompositeMetaType(typeInfo.getName(), typeInfo.getName());
- typeInfo.setAttachment(MetaType.class.getName(), result);
-
- Set<String> keys = null;
- Set<PropertyInfo> properties = beanInfo.getProperties();
- if (properties != null && properties.size() > 0)
- {
- for (PropertyInfo property : properties)
- {
- // Do we ignore this property?
- CompositeValue compositeValue = property.getUnderlyingAnnotation(CompositeValue.class);
- if (compositeValue != null && compositeValue.ignore())
- continue;
-
- String name = property.getName();
- if ("class".equals(name) == false)
- {
- if (compositeValue != null)
- {
- String compositeValueName = compositeValue.name();
- if (MetaTypeConstants.DEFAULT.equals(compositeValueName) == false)
- name = compositeValueName;
- }
-
- TypeInfo itemTypeInfo = property.getType();
- MetaType metaType = resolve(itemTypeInfo);
- result.addItem(name, name, metaType);
- if (property.isAnnotationPresent(CompositeKey.class))
- {
- if (keys == null)
- keys = new LinkedHashSet<String>();
- keys.add(name);
- }
- }
- }
- }
- if (keys != null)
- result.setKeys(keys);
- result.freeze();
- return result;
- }
-
- /**
- * Check for builders
- *
- * @param typeInfo the type info
- * @return the meta type when it is special
- */
- @SuppressWarnings("deprecation")
- public MetaType isBuilder(TypeInfo typeInfo)
- {
- MetaTypeBuilder builder = null;
- synchronized (builders)
- {
- WeakReference<MetaTypeBuilder> weak = builders.get(typeInfo.getType());
- if (weak != null)
- builder = weak.get();
- }
- if (builder == null)
- return null;
- return builder.buildMetaType();
- }
-
- /**
- * Check for generic
- *
- * @param typeInfo the type info
- * @return the meta type when it is generic
- */
- public GenericMetaType isGeneric(TypeInfo typeInfo)
- {
- if (typeInfo instanceof ClassInfo == false)
- return null;
-
- ClassInfo classInfo = (ClassInfo) typeInfo;
- Generic generic = classInfo.getUnderlyingAnnotation(Generic.class);
- if (generic != null)
- return new GenericMetaType(typeInfo.getName(), typeInfo.getName());
- return null;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/DefaultMetaTypeFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,454 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.plugins.types;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Type;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.WeakHashMap;
+
+import javax.management.ObjectName;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.metatype.api.annotations.CompositeKey;
+import org.jboss.metatype.api.annotations.CompositeValue;
+import org.jboss.metatype.api.annotations.Generic;
+import org.jboss.metatype.api.annotations.MetaTypeConstants;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.EnumMetaType;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableTableMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.types.TableMetaType;
+import org.jboss.metatype.spi.types.MetaTypeBuilder;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.reflect.spi.ArrayInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.EnumConstantInfo;
+import org.jboss.reflect.spi.EnumInfo;
+import org.jboss.reflect.spi.InterfaceInfo;
+import org.jboss.reflect.spi.TypeInfo;
+
+/**
+ * DefaultMetaTypeFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DefaultMetaTypeFactory extends MetaTypeFactory
+{
+ /** The map key */
+ public static final String MAP_KEY = "key";
+
+ /** The map value */
+ public static final String MAP_VALUE = "value";
+
+ /** Map index names */
+ public static final String[] MAP_INDEX_NAMES = { MAP_KEY };
+
+ /** Map item names */
+ public static final String[] MAP_ITEM_NAMES = { MAP_KEY, MAP_VALUE };
+
+ /** The configuration */
+ private static Configuration configuration;
+
+ static
+ {
+ configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
+ {
+ public Configuration run()
+ {
+ return new PropertyConfiguration();
+ }
+ });
+ }
+
+ /** The object type info */
+ private TypeInfo objectTypeInfo = configuration.getTypeInfo(Object.class);
+
+ /** The builders */
+ private Map<Class<?>, WeakReference<MetaTypeBuilder>> builders = new WeakHashMap<Class<?>, WeakReference<MetaTypeBuilder>>();
+
+ /**
+ * Create a new DefaultMetaTypeFactory.
+ */
+ public DefaultMetaTypeFactory()
+ {
+ // Special types
+ setBuilder(Class.class, ClassMetaTypeBuilder.INSTANCE);
+ setBuilder(ObjectName.class, ObjectNameTypeBuilder.INSTANCE);
+ }
+
+ @Override
+ public MetaType resolve(Type type)
+ {
+ TypeInfo typeInfo = configuration.getTypeInfo(type);
+ return resolve(typeInfo);
+ }
+
+ /**
+ * Resolve the meta type
+ *
+ * @param typeInfo the type
+ * @return the meta type
+ */
+ public MetaType resolve(TypeInfo typeInfo)
+ {
+ // Look for a cached value
+ MetaType result = typeInfo.getAttachment(MetaType.class);
+ if (result == null)
+ {
+ // Generate it
+ result = generate(typeInfo);
+
+ // Cache it
+ typeInfo.setAttachment(MetaType.class.getName(), result);
+ }
+
+ // Return the result
+ return result;
+ }
+
+ public void setBuilder(Class<?> clazz, MetaTypeBuilder builder)
+ {
+ synchronized (builders)
+ {
+ if (builder == null)
+ builders.remove(clazz);
+ builders.put(clazz, new WeakReference<MetaTypeBuilder>(builder));
+ }
+ }
+
+ /**
+ * Generate the metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ public MetaType generate(TypeInfo typeInfo)
+ {
+ MetaType result = isBuilder(typeInfo);
+ if (result != null)
+ return result;
+
+ MetaMapper<?> mapper = MetaMapper.getMetaMapper(typeInfo);
+ if (mapper != null)
+ return mapper.getMetaType();
+
+ result = isGeneric(typeInfo);
+ if (result != null)
+ return result;
+
+ if (typeInfo.isEnum())
+ return generateEnum((EnumInfo) typeInfo);
+
+ ClassInfo annotationType = isAnnotation(typeInfo);
+ if (annotationType != null)
+ return generateAnnotation(annotationType);
+
+ if (typeInfo.isArray())
+ return generateArray((ArrayInfo) typeInfo);
+
+ if (typeInfo.isCollection())
+ return generateCollection((ClassInfo) typeInfo);
+
+ if (typeInfo.isMap())
+ {
+ // See if this is a Map<String,?> type
+ ClassInfo classInfo = (ClassInfo) typeInfo;
+ TypeInfo[] types = classInfo.getActualTypeArguments();
+ if (types != null)
+ {
+ TypeInfo keyType = types[0];
+ TypeInfo valueType = types[1];
+ if(keyType.getName().equals(String.class.getName()))
+ {
+ // Use MapCompositeMetaType
+ MetaType valueMetaType = resolve(valueType);
+ return new MapCompositeMetaType(valueMetaType);
+ }
+ }
+ // Map java.util.Properties to MapCompositeMetaType(SimpleMetaType.STRING)
+ else if(typeInfo.getName().equals(Properties.class.getName()))
+ {
+ return new MapCompositeMetaType(SimpleMetaType.STRING);
+ }
+ // No, return the general map type
+ return generateMap(classInfo);
+ }
+
+ result = SimpleMetaType.isSimpleType(typeInfo.getName());
+ if (result != null)
+ return result;
+
+ return generateBean((ClassInfo) typeInfo);
+ }
+
+ /**
+ * Generate an enum metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ public EnumMetaType generateEnum(EnumInfo typeInfo)
+ {
+ EnumConstantInfo[] constants = typeInfo.getEnumConstants();
+ List<String> validValues = new ArrayList<String>(constants.length);
+ for (EnumConstantInfo constant : constants)
+ validValues.add(constant.getName());
+ return new EnumMetaType(typeInfo.getName(), validValues);
+ }
+
+ /**
+ * Whether this type is an annotation
+ *
+ * @param typeInfo the type info
+ * @return the annotation type info
+ */
+ public ClassInfo isAnnotation(TypeInfo typeInfo)
+ {
+ if (typeInfo.isAnnotation())
+ return (ClassInfo) typeInfo;
+
+ if (typeInfo instanceof ClassInfo)
+ {
+ ClassInfo classInfo = (ClassInfo) typeInfo;
+ InterfaceInfo[] interfaces = classInfo.getInterfaces();
+ if (interfaces != null)
+ {
+ for (int i = 0; i < interfaces.length; ++i)
+ {
+ if (interfaces[i].isAnnotation())
+ return interfaces[i];
+ }
+ }
+ }
+
+ // Doesn't look like an annotation
+ return null;
+ }
+
+ /**
+ * Generate an annotation metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ public CompositeMetaType generateAnnotation(ClassInfo typeInfo)
+ {
+ return generateBean(typeInfo);
+ }
+
+ /**
+ * Generate an array metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ @SuppressWarnings("unchecked")
+ public ArrayMetaType generateArray(ArrayInfo typeInfo)
+ {
+ int dimension = 1;
+ TypeInfo componentType = typeInfo.getComponentType();
+ while (componentType.isArray())
+ {
+ ++dimension;
+ componentType = ((ArrayInfo) componentType).getComponentType();
+ }
+ MetaType componentMetaType = resolve(componentType);
+ boolean isPrimitive = componentType.isPrimitive();
+ return new ArrayMetaType(dimension, componentMetaType, isPrimitive);
+ }
+
+ /**
+ * Generate a collection metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ @SuppressWarnings("unchecked")
+ public CollectionMetaType generateCollection(ClassInfo typeInfo)
+ {
+ TypeInfo elementType = objectTypeInfo;
+
+ TypeInfo[] types = typeInfo.getActualTypeArguments();
+ if (types != null)
+ elementType = types[0];
+
+ MetaType elementMetaType = resolve(elementType);
+ return new CollectionMetaType(typeInfo.getName(), elementMetaType);
+ }
+
+ /**
+ * Generate a map metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ public TableMetaType generateMap(ClassInfo typeInfo)
+ {
+ TypeInfo keyType = objectTypeInfo;
+ TypeInfo valueType = objectTypeInfo;
+
+ TypeInfo[] types = typeInfo.getActualTypeArguments();
+ if (types != null)
+ {
+ keyType = types[0];
+ valueType = types[1];
+ }
+ return createMapType(keyType, valueType);
+ }
+
+ /**
+ * Create a map type
+ *
+ * @param keyType the key type
+ * @param valueType the value type
+ * @return the map type
+ */
+ public TableMetaType createMapType(TypeInfo keyType, TypeInfo valueType)
+ {
+ String name = Map.class.getName();
+ MetaType[] itemTypes = { resolve(keyType), resolve(valueType) };
+ CompositeMetaType entryType = createMapEntryType(itemTypes);
+ return new ImmutableTableMetaType(name, name, entryType, MAP_INDEX_NAMES);
+ }
+
+ /**
+ * Create a map entry type
+ *
+ * @param itemTypes the item types
+ * @return the map entry type
+ */
+ public static CompositeMetaType createMapEntryType(MetaType[] itemTypes)
+ {
+ String entryName = Map.Entry.class.getName();
+ return new ImmutableCompositeMetaType(entryName, entryName, MAP_ITEM_NAMES, MAP_ITEM_NAMES, itemTypes);
+ }
+
+ /**
+ * Generate a bean metatype
+ *
+ * @param typeInfo the type info
+ * @return the metatype
+ */
+ public CompositeMetaType generateBean(ClassInfo typeInfo)
+ {
+ BeanInfo beanInfo = configuration.getBeanInfo(typeInfo);
+ MutableCompositeMetaType result = new MutableCompositeMetaType(typeInfo.getName(), typeInfo.getName());
+ typeInfo.setAttachment(MetaType.class.getName(), result);
+
+ Set<String> keys = null;
+ Set<PropertyInfo> properties = beanInfo.getProperties();
+ if (properties != null && properties.size() > 0)
+ {
+ for (PropertyInfo property : properties)
+ {
+ // Do we ignore this property?
+ CompositeValue compositeValue = property.getUnderlyingAnnotation(CompositeValue.class);
+ if (compositeValue != null && compositeValue.ignore())
+ continue;
+
+ String name = property.getName();
+ if ("class".equals(name) == false)
+ {
+ if (compositeValue != null)
+ {
+ String compositeValueName = compositeValue.name();
+ if (MetaTypeConstants.DEFAULT.equals(compositeValueName) == false)
+ name = compositeValueName;
+ }
+
+ TypeInfo itemTypeInfo = property.getType();
+ MetaType metaType = resolve(itemTypeInfo);
+ result.addItem(name, name, metaType);
+ if (property.isAnnotationPresent(CompositeKey.class))
+ {
+ if (keys == null)
+ keys = new LinkedHashSet<String>();
+ keys.add(name);
+ }
+ }
+ }
+ }
+ if (keys != null)
+ result.setKeys(keys);
+ result.freeze();
+ return result;
+ }
+
+ /**
+ * Check for builders
+ *
+ * @param typeInfo the type info
+ * @return the meta type when it is special
+ */
+ @SuppressWarnings("deprecation")
+ public MetaType isBuilder(TypeInfo typeInfo)
+ {
+ MetaTypeBuilder builder = null;
+ synchronized (builders)
+ {
+ WeakReference<MetaTypeBuilder> weak = builders.get(typeInfo.getType());
+ if (weak != null)
+ builder = weak.get();
+ }
+ if (builder == null)
+ return null;
+ return builder.buildMetaType();
+ }
+
+ /**
+ * Check for generic
+ *
+ * @param typeInfo the type info
+ * @return the meta type when it is generic
+ */
+ public GenericMetaType isGeneric(TypeInfo typeInfo)
+ {
+ if (typeInfo instanceof ClassInfo == false)
+ return null;
+
+ ClassInfo classInfo = (ClassInfo) typeInfo;
+ Generic generic = classInfo.getUnderlyingAnnotation(Generic.class);
+ if (generic != null)
+ return new GenericMetaType(typeInfo.getName(), typeInfo.getName());
+ return null;
+ }
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java (from rev 85721, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/types/ObjectNameTypeBuilder.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metatype.plugins.types;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.spi.types.MetaTypeBuilder;
+
+/**
+ * A type builder for the javax.management.ObjectName type
+ *
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameTypeBuilder implements MetaTypeBuilder
+{
+ /** The singleton instance */
+ public static final ObjectNameTypeBuilder INSTANCE = new ObjectNameTypeBuilder();
+
+ /** The MetaType for Class */
+ public static final CompositeMetaType META_TYPE = new ImmutableCompositeMetaType(
+ ObjectName.class.getName(),
+ ObjectName.class.getName(),
+ new String[] { "domain", "keyPropertyList" },
+ new String[] { "The domain name", "The unordered set of keys and associated values" },
+ new MetaType[] { SimpleMetaType.STRING, PropertiesMetaType.INSTANCE }
+ );
+
+ public MetaType buildMetaType()
+ {
+ // TODO Auto-generated method stub
+ return META_TYPE;
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,161 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.plugins.values;
-
-import java.io.Serializable;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.util.UnreachableStatementException;
-
-/**
- * CompositeValueInvocationHandler.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- */
-public class CompositeValueInvocationHandler implements InvocationHandler, Serializable
-{
- private static final long serialVersionUID = 1;
-
- /** The MetaValueFactory */
- private static MetaValueFactory factory = MetaValueFactory.getInstance();
-
- /** A cache of methods to keys */
- private static final Map<Method, String> compositeDataKeyCache = Collections.synchronizedMap(new WeakHashMap<Method, String>());
-
- /** The composite value */
- private CompositeValue compositeValue;
-
- /**
- * Create a new CompositeValueInvocationHandler.
- *
- * @param compositeValue the composite value
- */
- public CompositeValueInvocationHandler(CompositeValue compositeValue)
- {
- if (compositeValue == null)
- throw new IllegalArgumentException("Null compositeValue");
- this.compositeValue = compositeValue;
- }
-
- /**
- * Get the compositeData.
- *
- * @return the compositeData.
- */
- public CompositeValue getCompositeValue()
- {
- return compositeValue;
- }
-
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- if (Object.class.equals(method.getDeclaringClass()))
- return handleObjectInvocation(method.getName(), args);
-
- // Map size
- if(method.getName().equals("size"))
- return compositeValue.values().size();
-
- MetaValue value = compositeValue.get(getCompositeDataKey(method));
- Type returnType = method.getGenericReturnType();
- return factory.unwrap(value, returnType);
- }
-
- private Object handleObjectInvocation(String name, Object[] args) throws Throwable
- {
- if ("equals".equals(name))
- {
- Object object = args[0];
- if (object == null || object instanceof Proxy == false)
- return false;
- InvocationHandler handler = Proxy.getInvocationHandler(object);
- if (handler == this)
- return true;
- if (handler == null || handler instanceof CompositeValueInvocationHandler == false)
- return false;
-
- CompositeValueInvocationHandler other = (CompositeValueInvocationHandler) handler;
- return getCompositeValue().equals(other.getCompositeValue());
- }
- else if ("hashCode".equals(name))
- return getCompositeValue().hashCode();
- else if ("toString".equals(name))
- return getCompositeValue().toString();
- throw new UnreachableStatementException();
- }
-
- /**
- * Get the key for a composite data getter method
- *
- * @param method the method
- * @return the key
- */
- public static String getCompositeDataKey(Method method)
- {
- String key = compositeDataKeyCache.get(method);
- if (key != null)
- return key;
-
- StringBuilder fieldName = null;
-
- Class<?> returnType = method.getReturnType();
- Class<?>[] paramTypes = method.getParameterTypes();
- if (Void.TYPE.equals(returnType) == false && paramTypes.length == 0)
- {
- String name = method.getName();
- if (name.startsWith("is") && name.length() > 2)
- {
- if (Boolean.TYPE.equals(returnType))
- {
- fieldName = new StringBuilder();
- fieldName.append(Character.toLowerCase(name.charAt(2)));
- if (name.length() > 3)
- fieldName.append(name.substring(3));
- }
- }
- else if (name.startsWith("get") && name.length() > 3)
- {
- fieldName = new StringBuilder();
- fieldName.append(Character.toLowerCase(name.charAt(3)));
- if (name.length() > 4)
- fieldName.append(name.substring(4));
- }
- }
-
- if (fieldName == null)
- return null;
-
- String result = fieldName.toString();
- compositeDataKeyCache.put(method, result);
- return result;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java (from rev 84841, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/CompositeValueInvocationHandler.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,303 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.plugins.values;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.WeakHashMap;
+import java.util.Map.Entry;
+
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.util.UnreachableStatementException;
+
+/**
+ * CompositeValueInvocationHandler.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class CompositeValueInvocationHandler implements InvocationHandler, Serializable
+{
+ private static final long serialVersionUID = 1;
+
+ /** The MetaValueFactory */
+ private static MetaValueFactory factory = MetaValueFactory.getInstance();
+
+ /** A cache of methods to keys */
+ private static final Map<Method, String> compositeDataKeyCache = Collections.synchronizedMap(new WeakHashMap<Method, String>());
+
+ /** The composite value */
+ private CompositeValue compositeValue;
+
+ /**
+ * Create a new CompositeValueInvocationHandler.
+ *
+ * @param compositeValue the composite value
+ */
+ public CompositeValueInvocationHandler(CompositeValue compositeValue)
+ {
+ if (compositeValue == null)
+ throw new IllegalArgumentException("Null compositeValue");
+ this.compositeValue = compositeValue;
+ }
+
+ /**
+ * Get the compositeData.
+ *
+ * @return the compositeData.
+ */
+ public CompositeValue getCompositeValue()
+ {
+ return compositeValue;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+ {
+ Class<?> declaringClass = method.getDeclaringClass();
+ if (Object.class.equals(declaringClass))
+ return handleObjectInvocation(method.getName(), args);
+
+ Type returnType = method.getGenericReturnType();
+ // size
+ if(method.getName().equals("size"))
+ return compositeValue.values().size();
+
+ MetaValue value = compositeValue.get(getCompositeDataKey(method));
+ return factory.unwrap(value, returnType);
+ }
+
+ private Object handleObjectInvocation(String name, Object[] args) throws Throwable
+ {
+ if ("equals".equals(name))
+ {
+ Object object = args[0];
+ if (object == null || object instanceof Proxy == false)
+ return false;
+ InvocationHandler handler = Proxy.getInvocationHandler(object);
+ if (handler == this)
+ return true;
+ if (handler == null || handler instanceof CompositeValueInvocationHandler == false)
+ return false;
+
+ CompositeValueInvocationHandler other = (CompositeValueInvocationHandler) handler;
+ return getCompositeValue().equals(other.getCompositeValue());
+ }
+ else if ("hashCode".equals(name))
+ return getCompositeValue().hashCode();
+ else if ("toString".equals(name))
+ return getCompositeValue().toString();
+ throw new UnreachableStatementException();
+ }
+
+ /**
+ * Get the key for a composite data getter method
+ *
+ * @param method the method
+ * @return the key
+ */
+ public static String getCompositeDataKey(Method method)
+ {
+ String key = compositeDataKeyCache.get(method);
+ if (key != null)
+ return key;
+
+ StringBuilder fieldName = null;
+
+ Class<?> returnType = method.getReturnType();
+ Class<?>[] paramTypes = method.getParameterTypes();
+ if (Void.TYPE.equals(returnType) == false && paramTypes.length == 0)
+ {
+ String name = method.getName();
+ if (name.startsWith("is") && name.length() > 2)
+ {
+ if (Boolean.TYPE.equals(returnType))
+ {
+ fieldName = new StringBuilder();
+ fieldName.append(Character.toLowerCase(name.charAt(2)));
+ if (name.length() > 3)
+ fieldName.append(name.substring(3));
+ }
+ }
+ else if (name.startsWith("get") && name.length() > 3)
+ {
+ fieldName = new StringBuilder();
+ fieldName.append(Character.toLowerCase(name.charAt(3)));
+ if (name.length() > 4)
+ fieldName.append(name.substring(4));
+ }
+ }
+
+ if (fieldName == null)
+ return null;
+
+ String result = fieldName.toString();
+ compositeDataKeyCache.put(method, result);
+ return result;
+ }
+
+ /*
+ static class MapCVProxy implements Map<String, Object>
+ {
+ private CompositeValue delegate;
+
+ MapCVProxy(CompositeValue delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public void clear()
+ {
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return delegate.containsKey(key.toString());
+ }
+
+ public boolean containsValue(Object value)
+ {
+ if ((value instanceof MetaValue) == false)
+ {
+ value = factory.create(value);
+ }
+ MetaValue mv = MetaValue.class.cast(value);
+ return delegate.containsValue(mv);
+ }
+
+ public Set<Entry<String, Object>> entrySet()
+ {
+ HashSet<Entry<String, MetaValue>> entrySet = new HashSet<Entry<String, MetaValue>>();
+ for(String key : delegate.getMetaType().itemSet())
+ {
+ MetaValue value = delegate.get(key);
+ Map.Entry<String, Object> entry = new MapCVProxyEntry(key, value);
+ entrySet.add(entry);
+ }
+ return entrySet;
+ }
+
+ public MetaValue get(Object key)
+ {
+ return delegate.get(key.toString());
+ }
+
+ public boolean isEmpty()
+ {
+ return delegate.values().size() == 0;
+ }
+
+ public Set<String> keySet()
+ {
+ return delegate.getMetaType().itemSet();
+ }
+
+ public MetaValue put(String key, MetaValue value)
+ {
+ MetaValue old = null;
+ if (delegate instanceof MapCompositeValueSupport)
+ {
+ MapCompositeValueSupport mcvs = (MapCompositeValueSupport) delegate;
+ old = mcvs.get(key);
+ if ((value instanceof MetaValue) == false)
+
+ mcvs.put(key, value);
+ }
+ return old;
+ }
+
+ public void putAll(Map<? extends String, ? extends Object> map)
+ {
+ if (delegate instanceof MapCompositeValueSupport)
+ {
+ MapCompositeValueSupport mcvs = (MapCompositeValueSupport) delegate;
+ for(String key : map.keySet())
+ {
+ Object mv = map.get(key);
+ if ((mv instanceof MetaValue) == false)
+ mv = factory.create(mv);
+ mcvs.put(key, (MetaValue) mv);
+ }
+ }
+ }
+
+ public Object remove(Object key)
+ {
+ if (delegate instanceof MapCompositeValueSupport)
+ {
+ MapCompositeValueSupport mcvs = (MapCompositeValueSupport) delegate;
+ return mcvs.remove(key.toString());
+ }
+ return null;
+ }
+
+ public int size()
+ {
+ return delegate.values().size();
+ }
+
+ public Collection<Object> values()
+ {
+ return delegate.values();
+ }
+
+ }
+ static class MapCVProxyEntry implements Entry<String, Object>
+ {
+ private String key;
+ private Object value;
+ MapCVProxyEntry(String key, Object value)
+ {
+ this.key = key;
+ this.value = value;
+ }
+ public String getKey()
+ {
+ return key;
+ }
+ public Object getValue()
+ {
+ return value;
+ }
+
+ public Object setValue(Object value)
+ {
+ Object old = value;
+ this.value = value;
+ return old;
+ }
+ }
+ */
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,1093 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2007, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metatype.plugins.values;
-
-import java.io.Serializable;
-import java.lang.ref.WeakReference;
-import java.lang.reflect.Array;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Proxy;
-import java.lang.reflect.Type;
-import java.lang.reflect.UndeclaredThrowableException;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.Stack;
-import java.util.WeakHashMap;
-import java.util.Map.Entry;
-
-import org.jboss.beans.info.spi.BeanInfo;
-import org.jboss.beans.info.spi.PropertyInfo;
-import org.jboss.config.plugins.property.PropertyConfiguration;
-import org.jboss.config.spi.Configuration;
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.CollectionMetaType;
-import org.jboss.metatype.api.types.CompositeMetaType;
-import org.jboss.metatype.api.types.EnumMetaType;
-import org.jboss.metatype.api.types.GenericMetaType;
-import org.jboss.metatype.api.types.MapCompositeMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.MetaTypeFactory;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.types.TableMetaType;
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.ArrayValueSupport;
-import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.CollectionValueSupport;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.CompositeValueSupport;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.EnumValueSupport;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.GenericValueSupport;
-import org.jboss.metatype.api.values.InstanceFactory;
-import org.jboss.metatype.api.values.MapCompositeValueSupport;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.MetaValueFactory;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.metatype.api.values.TableValue;
-import org.jboss.metatype.api.values.TableValueSupport;
-import org.jboss.metatype.plugins.types.DefaultMetaTypeFactory;
-import org.jboss.metatype.spi.values.MetaMapper;
-import org.jboss.metatype.spi.values.MetaValueBuilder;
-import org.jboss.reflect.plugins.introspection.ParameterizedClassInfo;
-import org.jboss.reflect.spi.ArrayInfo;
-import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.reflect.spi.TypeInfoFactory;
-
-/**
- * DefaultMetaValueFactory.
- *
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class DefaultMetaValueFactory extends MetaValueFactory
-{
- /** The metatype factory */
- private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
-
- /** The primitive default value map */
- private static final Map<Class<?>, Object> primitiveDefaultValueMap;
-
- static
- {
- primitiveDefaultValueMap = new HashMap<Class<?>, Object>();
- primitiveDefaultValueMap.put(byte.class, (byte)0);
- primitiveDefaultValueMap.put(boolean.class, false);
- primitiveDefaultValueMap.put(char.class, '0');
- primitiveDefaultValueMap.put(short.class, (short)0);
- primitiveDefaultValueMap.put(int.class, 0);
- primitiveDefaultValueMap.put(long.class, 0l);
- primitiveDefaultValueMap.put(float.class, (float)0);
- primitiveDefaultValueMap.put(double.class, (double)0);
- }
-
- /** The configuration */
- private static Configuration configuration;
-
- static
- {
- configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
- {
- public Configuration run()
- {
- return new PropertyConfiguration();
- }
- });
- }
-
- /** The thread local stack of objects mapped to meta values */
- private ThreadLocal<Stack<Map<Object, MetaValue>>> mappingStack = new ThreadLocal<Stack<Map<Object, MetaValue>>>()
- {
- protected Stack<Map<Object, MetaValue>> initialValue()
- {
- return new Stack<Map<Object, MetaValue>>();
- }
- };
-
- /** The builders */
- private Map<Class<?>, WeakReference<MetaValueBuilder<?>>> builders = new WeakHashMap<Class<?>, WeakReference<MetaValueBuilder<?>>>();
-
- /** The Object type info */
- private static final TypeInfo OBJECT_TYPE_INFO = configuration.getTypeInfo(Object.class);
-
- /** The instance factory builders */
- private Map<Class<?>, InstanceFactory<?>> instanceFactoryMap = new WeakHashMap<Class<?>, InstanceFactory<?>>();
-
- public DefaultMetaValueFactory()
- {
- // set default collection instance factories
- setInstanceFactory(List.class, ListInstanceFactory.INSTANCE);
- setInstanceFactory(Set.class, SetInstanceFactory.INSTANCE);
- setInstanceFactory(SortedSet.class, SortedSetInstanceFactory.INSTANCE);
- }
-
- public void setBuilder(Class<?> clazz, MetaValueBuilder<?> builder)
- {
- synchronized (builders)
- {
- if (builder == null)
- builders.remove(clazz);
- builders.put(clazz, new WeakReference<MetaValueBuilder<?>>(builder));
- }
- }
-
- public <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory)
- {
- synchronized(instanceFactoryMap)
- {
- if (factory == null)
- instanceFactoryMap.remove(clazz);
- else
- instanceFactoryMap.put(clazz, factory);
- }
- }
-
- /**
- * Create a simple value
- *
- * @param type the type
- * @param value the value
- * @return the simple value
- */
- public static SimpleValue createSimpleValue(SimpleMetaType type, Serializable value)
- {
- if (value == null)
- return null;
-
- return new SimpleValueSupport(type, value);
- }
-
- /**
- * Create an enum value
- *
- * @param <T> the enum type
- * @param type the type
- * @param value the value
- * @return the enum value
- */
- public static <T extends Enum<?>> EnumValue createEnumValue(EnumMetaType type, T value)
- {
- if (value == null)
- return null;
-
- return new EnumValueSupport(type, value.name());
- }
-
- /**
- * Create a generic value
- *
- * @param type the type
- * @param value the value
- * @param mapping the mapping
- * @return the generic value
- */
- public static GenericValue createGenericValue(GenericMetaType type, Object value, Map<Object, MetaValue> mapping)
- {
- if (value == null)
- return null;
-
- if (value instanceof Serializable == false)
- throw new IllegalArgumentException("Not serializable: " + value.getClass().getName());
-
- GenericValue result = new GenericValueSupport(type, (Serializable) value);
- mapping.put(value, result);
- return result;
- }
-
- /**
- * Create a collection value
- *
- * @param type the type
- * @param value the value
- * @param mapping the mapping
- * @return the generic value
- */
- public CollectionValue createCollectionValue(CollectionMetaType type, Object value, Map<Object, MetaValue> mapping)
- {
- if (value == null)
- return null;
-
- Collection<?> collection = (Collection<?>)value;
- MetaValue[] elements = new MetaValue[collection.size()];
- int i = 0;
- for(Object ce : collection)
- {
- // recalculate element info, since usually more deterministic
- TypeInfo typeInfo = configuration.getTypeInfo(ce.getClass());
- MetaType metaType = metaTypeFactory.resolve(typeInfo);
- elements[i++] = internalCreate(ce, typeInfo, metaType);
- }
- CollectionValue result = new CollectionValueSupport(type, elements);
- mapping.put(value, result);
- return result;
- }
-
- /**
- * Transform a primitive array into an Object[]. Converts
- * a primitive array like char[] to Object[].
- *
- * @param type - the primitive array class type info.
- * @param value - the primitive array instance.
- * @return object array
- */
- public static Object[] convertPrimativeArray(TypeInfo type, Object value)
- {
- if (value == null)
- return null;
-
- Object[] oa;
- if( type instanceof ArrayInfo )
- {
- // Get the Object form of the element
- ArrayInfo arrayInfo = ArrayInfo.class.cast(type);
- TypeInfo etype = arrayInfo.getComponentType();
- int size = Array.getLength(value);
- oa = new Object[size];
- for(int n = 0; n < size; n ++)
- {
- Object nvalue = Array.get(value, n);
- // Recursively convert nested array elements
- if (etype.isArray())
- {
- oa[n] = convertPrimativeArray(etype, nvalue);
- }
- oa[n] = nvalue;
- }
- }
- else
- {
- oa = (Object[]) value;
- }
-
- return oa;
- }
-
- /**
- * Map null to primitive.
- *
- * @param type the type info
- * @return default value
- */
- @SuppressWarnings("deprecation")
- public static Object mapNullToPrimitive(TypeInfo type)
- {
- return primitiveDefaultValueMap.get(type.getType());
- }
-
- /**
- * Transform a primitive array into an Object[]. Converts
- * a primitive array like char[] to Object[].
- *
- * @param value - the primitive array instance.
- * @return object array
- */
- public static Object[] convertPrimativeArray(Object value)
- {
- if (value == null)
- return null;
- return convertPrimativeArray(configuration.getTypeInfo(value.getClass()), value);
- }
-
- /**
- * Create an array value
- *
- * @param type the type
- * @param value the value
- * @param mapping the mapping
- * @return the composite value
- */
- @SuppressWarnings("unchecked")
- public ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object, MetaValue> mapping)
- {
- if (value == null)
- return null;
-
- ArrayValueSupport result = new ArrayValueSupport(type);
- mapping.put(value, result);
-
- Object[] array;
-
- MetaType elementType = type.getElementType();
- int dimension = type.getDimension();
-
- Object[] oldArray;
- Class<?> componentType;
- try
- {
- componentType = Class.forName(type.getClassName());
- }
- catch (Exception e)
- {
- throw new RuntimeException("Unable to determine component type for " + type, e);
- }
-
- ClassInfo classInfo = configuration.getClassInfo(value.getClass());
- if (classInfo.isArray())
- {
- // See if this is a primitive array
- ArrayInfo arrayInfo = ArrayInfo.class.cast(classInfo);
- TypeInfo compInfo = arrayInfo.getComponentType();
- while(compInfo instanceof ArrayInfo)
- {
- arrayInfo = ArrayInfo.class.cast(compInfo);
- compInfo = arrayInfo.getComponentType();
- }
- // Translate
- if (compInfo.isPrimitive())
- oldArray = convertPrimativeArray(classInfo, value);
- else
- oldArray = (Object[]) value;
- }
- else
- throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
-
- array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
- result.setValue(array);
- return result;
- }
-
- /**
- * Create an array
- *
- * @param elementType the element type
- * @param componentType the component type
- * @param dimension the dimension
- * @param oldArray the old array
- * @return the array
- */
- protected Object[] createArray(MetaType elementType, Class<?> componentType, int dimension, Object[] oldArray)
- {
- if (oldArray == null)
- return null;
-
- Object[] newArray = new Object[oldArray.length];
-
- if (dimension > 1)
- {
- Object[] nestedOld;
- for (int i = 0; i < oldArray.length; ++i)
- {
- if ( !(oldArray[i] instanceof Object[]) )
- nestedOld = convertPrimativeArray(oldArray[i]);
- else
- nestedOld = (Object[]) oldArray[i];
- Object[] result = createArray(elementType, componentType.getComponentType(), dimension-1, nestedOld);
- newArray[i] = result;
- }
- }
- else
- {
- for (int i = 0; i < oldArray.length; ++i)
- newArray[i] = internalCreate(oldArray[i], null, elementType);
- }
-
- return newArray;
- }
-
- /**
- * Create a composite value
- *
- * @param type the type
- * @param value the value
- * @param mapping the mapping
- * @return the composite value
- */
- @SuppressWarnings("unchecked")
- public CompositeValue createCompositeValue(CompositeMetaType type, Object value, Map<Object, MetaValue> mapping)
- {
- if (value == null)
- return null;
-
- // See if this is a Map<String,?> type
- if(type instanceof MapCompositeMetaType)
- {
- if((value instanceof Map) == false)
- throw new RuntimeException("Expected Map value for: " + type+", was: "+(value != null ? value.getClass() : "null"));
- Map<String,?> map = (Map) value;
- MapCompositeMetaType mapType = (MapCompositeMetaType) type;
- MetaType mapValueType = mapType.getValueType();
- MapCompositeValueSupport result = new MapCompositeValueSupport(mapValueType);
- for(Entry<String,?> entry : map.entrySet())
- {
- Object entryValue = entry.getValue();
- MetaValue entryMetaValue = internalCreate(entryValue, null, mapValueType);
- result.put(entry.getKey(), entryMetaValue);
- }
- mapping.put(value, result);
- return result;
- }
-
- CompositeValueSupport result = new CompositeValueSupport(type);
- mapping.put(value, result);
-
- BeanInfo beanInfo;
- try
- {
- ClassLoader cl = value.getClass().getClassLoader();
- if (cl == null)
- beanInfo = configuration.getBeanInfo(value.getClass());
- else
- beanInfo = configuration.getBeanInfo(type.getTypeName(), cl);
- }
- catch (Exception e)
- {
- throw new RuntimeException("Error retrieving BeanInfo for " + type, e);
- }
-
- for (String name : type.itemSet())
- {
- MetaType itemType = type.getType(name);
- Object itemValue = null;
- try
- {
- PropertyInfo property = beanInfo.getProperty(name);
- if (property.isReadable())
- itemValue = beanInfo.getProperty(value, name);
- }
- catch (RuntimeException e)
- {
- throw e;
- }
- catch (Error e)
- {
- throw e;
- }
- catch (Throwable t)
- {
- throw new RuntimeException("Error getting property: " + name + " for " + value.getClass(), t);
- }
-
- MetaValue item = internalCreate(itemValue, null, itemType);
- result.set(name, item);
- }
-
- return result;
- }
-
- /**
- * Create a table value
- *
- * @param type the type
- * @param value the value
- * @param mapping the mapping
- * @return the table value
- */
- @SuppressWarnings("unchecked")
- public TableValue createTableValue(TableMetaType type, Map value, Map<Object, MetaValue> mapping)
- {
- if (value == null)
- return null;
-
- TableValueSupport table = new TableValueSupport(type);
- mapping.put(value, table);
-
- CompositeMetaType entryType = type.getRowType();
- MetaType keyType = entryType.getType(DefaultMetaTypeFactory.MAP_KEY);
- MetaType valType = entryType.getType(DefaultMetaTypeFactory.MAP_VALUE);
-
- for (Iterator<Map.Entry> i = value.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = i.next();
- MetaValue key = internalCreate(entry.getKey(), null, keyType);
- MetaValue val = internalCreate(entry.getValue(), null, valType);
- CompositeValueSupport data = new CompositeValueSupport(entryType, DefaultMetaTypeFactory.MAP_ITEM_NAMES, new MetaValue[] { key, val });
- table.put(data);
- }
-
- return table;
- }
-
- @Override
- public MetaValue create(Object value)
- {
- return internalCreate(value, null, null);
- }
-
- @Override
- public MetaValue create(Object value, Type type)
- {
- TypeInfo typeInfo = configuration.getTypeInfo(type);
- return internalCreate(value, typeInfo, null);
- }
-
- @Override
- public MetaValue create(Object value, TypeInfo type)
- {
- return internalCreate(value, type, null);
- }
-
- @Override
- public Object unwrap(MetaValue metaValue)
- {
- return internalUnwrap(metaValue, null);
- }
-
- @Override
- public Object unwrap(MetaValue metaValue, Type type)
- {
- TypeInfo typeInfo = configuration.getTypeInfo(type);
- return internalUnwrap(metaValue, typeInfo);
- }
-
- @Override
- public Object unwrap(MetaValue metaValue, TypeInfo type)
- {
- return internalUnwrap(metaValue, type);
- }
-
- /**
- * Unwrap value from meta value.
- *
- * @param metaValue the meta value
- * @param type expected type info
- * @return unwrapped value
- */
- protected Object internalUnwrap(MetaValue metaValue, TypeInfo type)
- {
- if (metaValue == null)
- return null;
-
- MetaMapper<?> mapper = MetaMapper.getMetaMapper(type);
- if (mapper != null)
- return mapper.unwrapMetaValue(metaValue);
-
- MetaType metaType = metaValue.getMetaType();
-
- if (metaType.isSimple())
- {
- Serializable value = ((SimpleValue)metaValue).getValue();
- return getValue(metaType, type, value);
- }
- else if (metaType.isEnum())
- {
- String value = ((EnumValue)metaValue).getValue();
- return getValue(metaType, type, value);
- }
- else if (metaType.isGeneric())
- {
- Serializable value = ((GenericValue)metaValue).getValue();
- return getValue(metaType, type, value);
- }
- else if (metaType.isArray())
- {
- ArrayValue arrayValue = (ArrayValue)metaValue;
- if (type == null)
- type= getTypeInfo(metaType, arrayValue.getValue());
- Object array = newArrayInstance(type, arrayValue.getLength());
- for (int i = 0; i < Array.getLength(array); i++)
- {
- Object element = arrayValue.getValue(i);
- if (element instanceof MetaValue)
- element = unwrapMetaValue((MetaValue)element, type, array);
- else if (element != null && element.getClass().isArray())
- element = unwrapArray(array, element);
-
- Array.set(array, i, element);
- }
- return array;
- }
- else if (metaType.isComposite())
- {
- CompositeValue compositeValue = (CompositeValue)metaValue;
- return unwrapComposite(compositeValue, type);
- }
- else if (metaType.isCollection())
- {
- CollectionValue collectionValue = (CollectionValue)metaValue;
- return unwrapCollection(collectionValue, type);
- }
- else if (metaType.isTable())
- {
- TableValue tableValue = (TableValue)metaValue;
- return unwrapTable(tableValue, type);
- }
-
- throw new IllegalArgumentException("Unsupported meta value: " + metaValue);
- }
-
- /**
- * Do a simple check.
- * If current type param is null,
- * try getting type info from meta type
- * and value's classloader.
- *
- * @param type the type info
- * @param value tester value
- * @param metaType the meta type
- * @return type info
- */
- protected TypeInfo checkTypeInfo(TypeInfo type, Object value, MetaType metaType)
- {
- if (type == null && value != null)
- type = getTypeInfo(metaType, value);
- return type;
- }
-
- /**
- * Get the value.
- * Join type check and value conversion.
- *
- * @param metaType the meta type
- * @param typeInfo the type info
- * @param value the value
- * @return the converted value
- */
- protected Object getValue(MetaType metaType, TypeInfo typeInfo, Object value)
- {
- typeInfo = checkTypeInfo(typeInfo, value, metaType);
- return convertValue(value, typeInfo);
- }
-
- /**
- * Unwrap MetaValue.
- *
- * @param element the meta value
- * @param type parent type
- * @param array parent array
- * @return unwrapped value
- */
- protected Object unwrapMetaValue(MetaValue element, TypeInfo type, Object array)
- {
- TypeInfo elementType;
- if (type instanceof ClassInfo)
- elementType = ((ClassInfo)type).getComponentType();
- else
- elementType = getTypeInfo(element.getMetaType(), array);
- return unwrap(element, elementType);
- }
-
- /**
- * Unwrap array.
- * @param array parent array
- * @param element current array element
- * @return unwrapped array element
- */
- protected Object unwrapArray(Object array, Object element)
- {
- TypeInfo elementType = configuration.getTypeInfo(array.getClass().getComponentType());
- int subSize = Array.getLength(element);
- Object newElement = newArrayInstance(elementType, subSize);
- for(int i = 0; i < subSize; i++)
- {
- Object subElement = Array.get(element, i);
- if (subElement instanceof MetaValue)
- subElement = unwrapMetaValue((MetaValue)subElement, elementType, newElement);
- if (subElement != null && subElement.getClass().isArray())
- subElement = unwrapArray(newElement, subElement);
-
- Array.set(newElement, i, subElement);
- }
- return newElement;
- }
-
- /**
- * Unwrap composite.
- *
- * @param compositeValue the composite value
- * @param typeInfo expected type info
- * @return unwrapped value
- */
- @SuppressWarnings("deprecation")
- protected Object unwrapComposite(CompositeValue compositeValue, TypeInfo typeInfo)
- {
- CompositeMetaType compositeMetaType = compositeValue.getMetaType();
- String typeName = compositeMetaType.getTypeName();
- ClassLoader cl;
- if (typeInfo != null)
- cl = typeInfo.getType().getClassLoader();
- else
- cl = Thread.currentThread().getContextClassLoader();
-
- try
- {
- BeanInfo beanInfo = configuration.getBeanInfo(typeName, cl);
- ClassInfo classInfo = beanInfo.getClassInfo();
- if (classInfo.isInterface())
- {
- InvocationHandler handler = createCompositeValueInvocationHandler(compositeValue);
- Class<?> clazz = classInfo.getType();
- Class<?>[] interfaces = new Class[]{clazz};
- return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
- }
- Object bean = createNewInstance(beanInfo);
- for (String name : compositeMetaType.itemSet())
- {
- MetaValue itemValue = compositeValue.get(name);
- PropertyInfo propertyInfo = beanInfo.getProperty(name);
- Object value = unwrap(itemValue, propertyInfo.getType());
- propertyInfo.set(bean, value);
- }
- return bean;
- }
- catch (Throwable t)
- {
- throw new UndeclaredThrowableException(t);
- }
- }
-
- /**
- * Create composite invocation handler.
- *
- * @param compositeValue the composite value
- * @return composite invocation handler
- */
- protected InvocationHandler createCompositeValueInvocationHandler(CompositeValue compositeValue)
- {
- return new CompositeValueInvocationHandler(compositeValue);
- }
-
- /**
- * Unwrap collection meta value.
- *
- * @param collectionValue the collection value
- * @param type the type info
- * @return unwrapped collection
- */
- @SuppressWarnings("unchecked")
- protected Object unwrapCollection(CollectionValue collectionValue, TypeInfo type)
- {
- try
- {
- BeanInfo collectionInfo;
- // null is not instance of
- if (type instanceof ClassInfo)
- {
- collectionInfo = configuration.getBeanInfo(type);
- }
- else
- {
- MetaType metaType = collectionValue.getMetaType();
- collectionInfo = configuration.getBeanInfo(metaType.getTypeName(), Thread.currentThread().getContextClassLoader());
- }
- ClassInfo classInfo = collectionInfo.getClassInfo();
- Collection collection = (Collection)createNewInstance(collectionInfo);
-
- TypeInfo componentType = classInfo.getComponentType();
- boolean isObjectTypeInfo = OBJECT_TYPE_INFO.equals(componentType);
-
- for (MetaValue metaValue : collectionValue)
- {
- TypeInfo iterTypeInfo = isObjectTypeInfo ? getTypeInfo(metaValue.getMetaType(), null) : componentType;
- collection.add(unwrap(metaValue, iterTypeInfo));
- }
- return collection;
- }
- catch (Throwable t)
- {
- throw new UndeclaredThrowableException(t);
- }
- }
-
- /**
- * Unwrap table meta value.
- *
- * @param tableValue the table value
- * @param type the type info
- * @return unwrapped table (map)
- */
- @SuppressWarnings("deprecation")
- protected Object unwrapTable(TableValue tableValue, TypeInfo type)
- {
- if (type instanceof ParameterizedClassInfo)
- {
- ParameterizedClassInfo parameterizedType = (ParameterizedClassInfo)type;
- ClassInfo rawType = parameterizedType.getRawType();
- if (Map.class.isAssignableFrom(rawType.getType()))
- {
- TypeInfo keyType = parameterizedType.getActualTypeArguments()[0];
- TypeInfo valueType = parameterizedType.getActualTypeArguments()[1];
- return createMap(tableValue, keyType, valueType);
- }
- }
- throw new UnsupportedOperationException("Insufficient information to unwrap table: " + tableValue + ", " + type);
- }
-
- /**
- * Create a map
- *
- * @param tableValue the table value
- * @param keyType the key type
- * @param valueType the value type
- * @return the map
- */
- protected Map<?,?> createMap(TableValue tableValue, TypeInfo keyType, TypeInfo valueType)
- {
- if (tableValue == null)
- return null;
-
- Map<Object, Object> result = new HashMap<Object, Object>();
- Collection<CompositeValue> values = tableValue.values();
- for (CompositeValue entry : values)
- {
- Object key = unwrap(entry.get(DefaultMetaTypeFactory.MAP_KEY), keyType);
- Object val = unwrap(entry.get(DefaultMetaTypeFactory.MAP_VALUE), valueType);
- result.put(key, val);
- }
- return result;
- }
-
- /**
- * Create new instance.
- *
- * @param beanInfo the bean info
- * @return new instance
- * @throws Throwable for any error
- */
- @SuppressWarnings("deprecation")
- protected Object createNewInstance(BeanInfo beanInfo) throws Throwable
- {
- ClassInfo classInfo = beanInfo.getClassInfo();
- if (classInfo.isInterface())
- {
- InstanceFactory<?> instanceFactory = instanceFactoryMap.get(classInfo.getType());
- if (instanceFactory == null)
- throw new IllegalArgumentException("Cannot instantiate interface BeanInfo, missing InstanceFactory: " + classInfo);
-
- return instanceFactory.instantiate(beanInfo);
- }
- return beanInfo.newInstance();
- }
-
- /**
- * Get new array instance.
- *
- * @param typeInfo the type info
- * @param size the size
- * @return new array instance
- */
- protected Object newArrayInstance(TypeInfo typeInfo, int size)
- {
- if (typeInfo == null)
- throw new IllegalArgumentException("Null type info.");
-
- try
- {
- return typeInfo.newArrayInstance(size);
- }
- catch (Throwable t)
- {
- throw new UndeclaredThrowableException(t);
- }
- }
-
- /**
- * Get the class info from meta type.
- *
- * @param metaType the meta type
- * @param value the value which can provide classloader
- * @return type info
- */
- protected TypeInfo getTypeInfo(MetaType metaType, Object value)
- {
- if (metaType == null)
- throw new IllegalArgumentException("Null meta type, cannot determine class name.");
- if (value == null)
- throw new IllegalArgumentException("Null value, cannot determine classloader.");
-
- // get the classloader from the array we plan to fill
- ClassLoader cl = value.getClass().getClassLoader();
- return getTypeInfo(metaType, cl);
- }
-
- /**
- * Get the class info from meta type.
- *
- * @param metaType the meta type
- * @param cl the classloader
- * @return class info
- */
- protected TypeInfo getTypeInfo(MetaType metaType, ClassLoader cl)
- {
- if (cl == null)
- cl = Thread.currentThread().getContextClassLoader();
-
- try
- {
- TypeInfoFactory tif = configuration.getTypeInfoFactory();
- if (metaType.isArray())
- {
- ArrayMetaType arrayMetaType = (ArrayMetaType)metaType;
- MetaType elementMetaType = arrayMetaType.getElementType();
- String elementTypeName = elementMetaType.getTypeName();
- if (arrayMetaType.isPrimitiveArray())
- elementTypeName = ArrayMetaType.getPrimitiveName(elementTypeName);
- TypeInfo elementTypeInfo = tif.getTypeInfo(elementTypeName, cl);
- int dimension = arrayMetaType.getDimension() - 1; // minus 1, since we already use first in next line
- TypeInfo typeInfo = elementTypeInfo.getArrayType();
- while(dimension > 0)
- {
- typeInfo = typeInfo.getArrayType();
- dimension--;
- }
- return typeInfo;
- }
- return tif.getTypeInfo(metaType.getTypeName(), cl);
- }
- catch (ClassNotFoundException e)
- {
- throw new UndeclaredThrowableException(e);
- }
- }
-
- /**
- * Create a meta value from the object
- *
- * @param value the value
- * @param type the type
- * @param metaType the metaType
- * @return the meta value
- */
- @SuppressWarnings("unchecked")
- protected MetaValue internalCreate(Object value, TypeInfo type, MetaType metaType)
- {
- if (value == null)
- return null;
-
- if (type == null)
- type = configuration.getTypeInfo(value.getClass());
-
- value = convertValue(value, type);
-
- boolean start = false;
- if (metaType == null)
- {
- start = true;
- metaType = metaTypeFactory.resolve(type);
- }
-
- // For more complicated values we need to keep a mapping of objects to meta values
- // this avoids duplicate meta value construction and recursion
- Map<Object, MetaValue> mapping;
- if (start)
- {
- // This is the start of the mapping
- mapping = new HashMap<Object, MetaValue>();
- mappingStack.get().push(mapping);
- }
- else
- {
- // Check the existing mapping
- mapping = mappingStack.get().peek();
- MetaValue result = mapping.get(value);
- // Seen this before
- if (result != null)
- return result;
- }
-
- try
- {
- MetaValue result = isBuilder(metaType, type, value, mapping);
-
- if (result == null)
- {
- MetaMapper<Object> mapper = (MetaMapper) MetaMapper.getMetaMapper(type);
- if (mapper != null)
- result = mapper.createMetaValue(metaType, value);
- }
-
- if (result == null)
- {
- if (metaType.isSimple())
- result = createSimpleValue((SimpleMetaType) metaType, (Serializable) value);
- else if (metaType.isEnum())
- result = createEnumValue((EnumMetaType) metaType, (Enum<?>) value);
- else if (metaType.isArray())
- result = createArrayValue((ArrayMetaType) metaType, value, mapping);
- else if (metaType.isComposite())
- result = createCompositeValue((CompositeMetaType) metaType, value, mapping);
- else if (metaType.isTable())
- result = createTableValue((TableMetaType) metaType, (Map<?,?>) value, mapping);
- else if (metaType.isGeneric())
- result = createGenericValue((GenericMetaType) metaType, value, mapping);
- else if (metaType.isCollection())
- result = createCollectionValue((CollectionMetaType) metaType, value, mapping);
- else
- throw new IllegalStateException("Unknown metaType: " + metaType);
- }
- return result;
- }
- finally
- {
- // Remove the mapping from the stack
- if (start)
- mappingStack.get().pop();
- }
- }
-
- /**
- * Convert the value.
- *
- * @param value the value
- * @param typeInfo type info
- * @return converted value if type info not null
- * @throws UndeclaredThrowableException for any error
- */
- protected Object convertValue(Object value, TypeInfo typeInfo)
- {
- try
- {
- return typeInfo != null ? typeInfo.convertValue(value) : value;
- }
- catch (Throwable t)
- {
- throw new UndeclaredThrowableException(t);
- }
- }
-
- /**
- * Check for a builder
- *
- * @param metaType the meta type
- * @param type the type
- * @param value the value
- * @param mapping the mappings
- * @return the meta value
- */
- @SuppressWarnings({"unchecked", "deprecation"})
- protected MetaValue isBuilder(MetaType metaType, TypeInfo type, Object value, Map<Object, MetaValue> mapping)
- {
- MetaValueBuilder builder = null;
- synchronized (builders)
- {
- WeakReference<MetaValueBuilder<?>> weak = builders.get(type.getType());
- if (weak != null)
- builder = weak.get();
- }
- if (builder == null)
- return null;
- MetaValue result = builder.buildMetaValue(metaType, value);
- if (result != null)
- mapping.put(value, result);
-
- return result;
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java (from rev 85720, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/DefaultMetaValueFactory.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,1168 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metatype.plugins.values;
+
+import java.io.Serializable;
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.lang.reflect.UndeclaredThrowableException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.Stack;
+import java.util.WeakHashMap;
+import java.util.Map.Entry;
+
+import javax.management.ObjectName;
+
+import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.config.plugins.property.PropertyConfiguration;
+import org.jboss.config.spi.Configuration;
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.EnumMetaType;
+import org.jboss.metatype.api.types.GenericMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.MetaTypeFactory;
+import org.jboss.metatype.api.types.PropertiesMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.types.TableMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.ArrayValueSupport;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.EnumValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.GenericValueSupport;
+import org.jboss.metatype.api.values.InstanceFactory;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.metatype.api.values.TableValueSupport;
+import org.jboss.metatype.plugins.types.DefaultMetaTypeFactory;
+import org.jboss.metatype.spi.values.MetaMapper;
+import org.jboss.metatype.spi.values.MetaValueBuilder;
+import org.jboss.reflect.plugins.introspection.ParameterizedClassInfo;
+import org.jboss.reflect.spi.ArrayInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.reflect.spi.TypeInfoFactory;
+
+/**
+ * DefaultMetaValueFactory.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Scott.Stark at jboss.org
+ * @version $Revision$
+ */
+public class DefaultMetaValueFactory extends MetaValueFactory
+{
+ /** The metatype factory */
+ private MetaTypeFactory metaTypeFactory = MetaTypeFactory.getInstance();
+
+ /** The primitive default value map */
+ private static final Map<Class<?>, Object> primitiveDefaultValueMap;
+
+ static
+ {
+ primitiveDefaultValueMap = new HashMap<Class<?>, Object>();
+ primitiveDefaultValueMap.put(byte.class, (byte)0);
+ primitiveDefaultValueMap.put(boolean.class, false);
+ primitiveDefaultValueMap.put(char.class, '0');
+ primitiveDefaultValueMap.put(short.class, (short)0);
+ primitiveDefaultValueMap.put(int.class, 0);
+ primitiveDefaultValueMap.put(long.class, 0l);
+ primitiveDefaultValueMap.put(float.class, (float)0);
+ primitiveDefaultValueMap.put(double.class, (double)0);
+ }
+
+ /** The configuration */
+ private static Configuration configuration;
+
+ static
+ {
+ configuration = AccessController.doPrivileged(new PrivilegedAction<Configuration>()
+ {
+ public Configuration run()
+ {
+ return new PropertyConfiguration();
+ }
+ });
+ }
+
+ /** The thread local stack of objects mapped to meta values */
+ private ThreadLocal<Stack<Map<Object, MetaValue>>> mappingStack = new ThreadLocal<Stack<Map<Object, MetaValue>>>()
+ {
+ protected Stack<Map<Object, MetaValue>> initialValue()
+ {
+ return new Stack<Map<Object, MetaValue>>();
+ }
+ };
+
+ /** The builders */
+ private Map<Class<?>, WeakReference<MetaValueBuilder<?>>> builders = new WeakHashMap<Class<?>, WeakReference<MetaValueBuilder<?>>>();
+
+ /** The Object type info */
+ private static final TypeInfo OBJECT_TYPE_INFO = configuration.getTypeInfo(Object.class);
+
+ /** The instance factory builders */
+ private Map<Class<?>, InstanceFactory<?>> instanceFactoryMap = new WeakHashMap<Class<?>, InstanceFactory<?>>();
+
+ public DefaultMetaValueFactory()
+ {
+ // set default collection instance factories
+ setInstanceFactory(List.class, ListInstanceFactory.INSTANCE);
+ setInstanceFactory(Set.class, SetInstanceFactory.INSTANCE);
+ setInstanceFactory(SortedSet.class, SortedSetInstanceFactory.INSTANCE);
+ }
+
+ public void setBuilder(Class<?> clazz, MetaValueBuilder<?> builder)
+ {
+ synchronized (builders)
+ {
+ if (builder == null)
+ builders.remove(clazz);
+ builders.put(clazz, new WeakReference<MetaValueBuilder<?>>(builder));
+ }
+ }
+
+ public <T> void setInstanceFactory(Class<T> clazz, InstanceFactory<T> factory)
+ {
+ synchronized(instanceFactoryMap)
+ {
+ if (factory == null)
+ instanceFactoryMap.remove(clazz);
+ else
+ instanceFactoryMap.put(clazz, factory);
+ }
+ }
+
+ /**
+ * Create a simple value
+ *
+ * @param type the type
+ * @param value the value
+ * @return the simple value
+ */
+ public static SimpleValue createSimpleValue(SimpleMetaType type, Serializable value)
+ {
+ if (value == null)
+ return null;
+
+ return new SimpleValueSupport(type, value);
+ }
+
+ /**
+ * Create an enum value
+ *
+ * @param <T> the enum type
+ * @param type the type
+ * @param value the value
+ * @return the enum value
+ */
+ public static <T extends Enum<?>> EnumValue createEnumValue(EnumMetaType type, T value)
+ {
+ if (value == null)
+ return null;
+
+ return new EnumValueSupport(type, value.name());
+ }
+
+ /**
+ * Create a generic value
+ *
+ * @param type the type
+ * @param value the value
+ * @param mapping the mapping
+ * @return the generic value
+ */
+ public static GenericValue createGenericValue(GenericMetaType type, Object value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+
+ if (value instanceof Serializable == false)
+ throw new IllegalArgumentException("Not serializable: " + value.getClass().getName());
+
+ GenericValue result = new GenericValueSupport(type, (Serializable) value);
+ mapping.put(value, result);
+ return result;
+ }
+
+ /**
+ * Create a collection value
+ *
+ * @param type the type
+ * @param value the value
+ * @param mapping the mapping
+ * @return the generic value
+ */
+ public CollectionValue createCollectionValue(CollectionMetaType type, Object value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+
+ Collection<?> collection = (Collection<?>)value;
+ MetaValue[] elements = new MetaValue[collection.size()];
+ int i = 0;
+ for(Object ce : collection)
+ {
+ // recalculate element info, since usually more deterministic
+ TypeInfo typeInfo = configuration.getTypeInfo(ce.getClass());
+ MetaType metaType = metaTypeFactory.resolve(typeInfo);
+ elements[i++] = internalCreate(ce, typeInfo, metaType);
+ }
+ CollectionValue result = new CollectionValueSupport(type, elements);
+ mapping.put(value, result);
+ return result;
+ }
+
+ /**
+ * Transform a primitive array into an Object[]. Converts
+ * a primitive array like char[] to Object[].
+ *
+ * @param type - the primitive array class type info.
+ * @param value - the primitive array instance.
+ * @return object array
+ */
+ public static Object[] convertPrimativeArray(TypeInfo type, Object value)
+ {
+ if (value == null)
+ return null;
+
+ Object[] oa;
+ if( type instanceof ArrayInfo )
+ {
+ // Get the Object form of the element
+ ArrayInfo arrayInfo = ArrayInfo.class.cast(type);
+ TypeInfo etype = arrayInfo.getComponentType();
+ int size = Array.getLength(value);
+ oa = new Object[size];
+ for(int n = 0; n < size; n ++)
+ {
+ Object nvalue = Array.get(value, n);
+ // Recursively convert nested array elements
+ if (etype.isArray())
+ {
+ oa[n] = convertPrimativeArray(etype, nvalue);
+ }
+ oa[n] = nvalue;
+ }
+ }
+ else
+ {
+ oa = (Object[]) value;
+ }
+
+ return oa;
+ }
+
+ /**
+ * Map null to primitive.
+ *
+ * @param type the type info
+ * @return default value
+ */
+ @SuppressWarnings("deprecation")
+ public static Object mapNullToPrimitive(TypeInfo type)
+ {
+ return primitiveDefaultValueMap.get(type.getType());
+ }
+
+ /**
+ * Transform a primitive array into an Object[]. Converts
+ * a primitive array like char[] to Object[].
+ *
+ * @param value - the primitive array instance.
+ * @return object array
+ */
+ public static Object[] convertPrimativeArray(Object value)
+ {
+ if (value == null)
+ return null;
+ return convertPrimativeArray(configuration.getTypeInfo(value.getClass()), value);
+ }
+
+ /**
+ * Create an array value
+ *
+ * @param type the type
+ * @param value the value
+ * @param mapping the mapping
+ * @return the composite value
+ */
+ @SuppressWarnings("unchecked")
+ public ArrayValue createArrayValue(ArrayMetaType type, Object value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+
+ ArrayValueSupport result = new ArrayValueSupport(type);
+ mapping.put(value, result);
+
+ Object[] array;
+
+ MetaType elementType = type.getElementType();
+ int dimension = type.getDimension();
+
+ Object[] oldArray;
+ Class<?> componentType;
+ try
+ {
+ componentType = Class.forName(type.getClassName());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Unable to determine component type for " + type, e);
+ }
+
+ ClassInfo classInfo = configuration.getClassInfo(value.getClass());
+ if (classInfo.isArray())
+ {
+ // See if this is a primitive array
+ ArrayInfo arrayInfo = ArrayInfo.class.cast(classInfo);
+ TypeInfo compInfo = arrayInfo.getComponentType();
+ while(compInfo instanceof ArrayInfo)
+ {
+ arrayInfo = ArrayInfo.class.cast(compInfo);
+ compInfo = arrayInfo.getComponentType();
+ }
+ // Translate
+ if (compInfo.isPrimitive())
+ oldArray = convertPrimativeArray(classInfo, value);
+ else
+ oldArray = (Object[]) value;
+ }
+ else
+ throw new UnsupportedOperationException("Cannot construct array for " + value.getClass());
+
+ array = createArray(elementType, componentType.getComponentType(), dimension, oldArray);
+ result.setValue(array);
+ return result;
+ }
+
+ /**
+ * Create an array
+ *
+ * @param elementType the element type
+ * @param componentType the component type
+ * @param dimension the dimension
+ * @param oldArray the old array
+ * @return the array
+ */
+ protected Object[] createArray(MetaType elementType, Class<?> componentType, int dimension, Object[] oldArray)
+ {
+ if (oldArray == null)
+ return null;
+
+ Object[] newArray = new Object[oldArray.length];
+
+ if (dimension > 1)
+ {
+ Object[] nestedOld;
+ for (int i = 0; i < oldArray.length; ++i)
+ {
+ if ( !(oldArray[i] instanceof Object[]) )
+ nestedOld = convertPrimativeArray(oldArray[i]);
+ else
+ nestedOld = (Object[]) oldArray[i];
+ Object[] result = createArray(elementType, componentType.getComponentType(), dimension-1, nestedOld);
+ newArray[i] = result;
+ }
+ }
+ else
+ {
+ for (int i = 0; i < oldArray.length; ++i)
+ newArray[i] = internalCreate(oldArray[i], null, elementType);
+ }
+
+ return newArray;
+ }
+
+ /**
+ * Create a composite value
+ *
+ * @param type the type
+ * @param value the value
+ * @param mapping the mapping
+ * @return the composite value
+ */
+ @SuppressWarnings("unchecked")
+ public CompositeValue createCompositeValue(CompositeMetaType type, Object value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+
+ // See if this is a Map<String,?> type
+ if(type instanceof MapCompositeMetaType)
+ {
+ if((value instanceof Map) == false)
+ throw new RuntimeException("Expected Map value for: " + type+", was: "+(value != null ? value.getClass() : "null"));
+ Map<String,?> map = (Map) value;
+ MapCompositeMetaType mapType = (MapCompositeMetaType) type;
+ MetaType mapValueType = mapType.getValueType();
+ MapCompositeValueSupport result = new MapCompositeValueSupport(mapValueType);
+ for(Entry<String,?> entry : map.entrySet())
+ {
+ Object entryValue = entry.getValue();
+ MetaValue entryMetaValue = internalCreate(entryValue, null, mapValueType);
+ result.put(entry.getKey(), entryMetaValue);
+ }
+ mapping.put(value, result);
+ return result;
+ }
+
+ CompositeValueSupport result = new CompositeValueSupport(type);
+ mapping.put(value, result);
+
+ BeanInfo beanInfo;
+ try
+ {
+ ClassLoader cl = value.getClass().getClassLoader();
+ if (cl == null)
+ beanInfo = configuration.getBeanInfo(value.getClass());
+ else
+ beanInfo = configuration.getBeanInfo(type.getTypeName(), cl);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error retrieving BeanInfo for " + type, e);
+ }
+
+ for (String name : type.itemSet())
+ {
+ MetaType itemType = type.getType(name);
+ Object itemValue = null;
+ try
+ {
+ PropertyInfo property = beanInfo.getProperty(name);
+ if (property.isReadable())
+ itemValue = beanInfo.getProperty(value, name);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Error e)
+ {
+ throw e;
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Error getting property: " + name + " for " + value.getClass(), t);
+ }
+
+ MetaValue item = internalCreate(itemValue, null, itemType);
+ result.set(name, item);
+ }
+
+ return result;
+ }
+
+ /**
+ * Create a table value
+ *
+ * @param type the type
+ * @param value the value
+ * @param mapping the mapping
+ * @return the table value
+ */
+ @SuppressWarnings("unchecked")
+ public TableValue createTableValue(TableMetaType type, Map value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+
+ TableValueSupport table = new TableValueSupport(type);
+ mapping.put(value, table);
+
+ CompositeMetaType entryType = type.getRowType();
+ MetaType keyType = entryType.getType(DefaultMetaTypeFactory.MAP_KEY);
+ MetaType valType = entryType.getType(DefaultMetaTypeFactory.MAP_VALUE);
+
+ for (Iterator<Map.Entry> i = value.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = i.next();
+ MetaValue key = internalCreate(entry.getKey(), null, keyType);
+ MetaValue val = internalCreate(entry.getValue(), null, valType);
+ CompositeValueSupport data = new CompositeValueSupport(entryType, DefaultMetaTypeFactory.MAP_ITEM_NAMES, new MetaValue[] { key, val });
+ table.put(data);
+ }
+
+ return table;
+ }
+
+ @Override
+ public MetaValue create(Object value)
+ {
+ return internalCreate(value, null, null);
+ }
+
+ @Override
+ public MetaValue create(Object value, Type type)
+ {
+ TypeInfo typeInfo = configuration.getTypeInfo(type);
+ return internalCreate(value, typeInfo, null);
+ }
+
+ @Override
+ public MetaValue create(Object value, TypeInfo type)
+ {
+ return internalCreate(value, type, null);
+ }
+ @Override
+ public MetaValue create(Object value, MetaType type)
+ {
+ return internalCreate(value, null, type);
+ }
+
+ @Override
+ public Object unwrap(MetaValue metaValue)
+ {
+ return internalUnwrap(metaValue, null);
+ }
+
+ @Override
+ public Object unwrap(MetaValue metaValue, Type type)
+ {
+ TypeInfo typeInfo = configuration.getTypeInfo(type);
+ return internalUnwrap(metaValue, typeInfo);
+ }
+
+ @Override
+ public Object unwrap(MetaValue metaValue, TypeInfo type)
+ {
+ return internalUnwrap(metaValue, type);
+ }
+
+ /**
+ * Unwrap value from meta value.
+ *
+ * @param metaValue the meta value
+ * @param type expected type info
+ * @return unwrapped value
+ */
+ protected Object internalUnwrap(MetaValue metaValue, TypeInfo type)
+ {
+ if (metaValue == null)
+ return null;
+
+ MetaMapper<?> mapper = MetaMapper.getMetaMapper(type);
+ if (mapper != null)
+ return mapper.unwrapMetaValue(metaValue);
+
+ MetaType metaType = metaValue.getMetaType();
+
+ if (metaType.isSimple())
+ {
+ Serializable value = ((SimpleValue)metaValue).getValue();
+ return getValue(metaType, type, value);
+ }
+ else if (metaType.isEnum())
+ {
+ String value = ((EnumValue)metaValue).getValue();
+ return getValue(metaType, type, value);
+ }
+ else if (metaType.isGeneric())
+ {
+ Serializable value = ((GenericValue)metaValue).getValue();
+ return getValue(metaType, type, value);
+ }
+ else if (metaType.isArray())
+ {
+ ArrayValue arrayValue = (ArrayValue)metaValue;
+ if (type == null)
+ type= getTypeInfo(metaType, arrayValue.getValue());
+ Object array = newArrayInstance(type, arrayValue.getLength());
+ for (int i = 0; i < Array.getLength(array); i++)
+ {
+ Object element = arrayValue.getValue(i);
+ if (element instanceof MetaValue)
+ element = unwrapMetaValue((MetaValue)element, type, array);
+ else if (element != null && element.getClass().isArray())
+ element = unwrapArray(array, element);
+
+ Array.set(array, i, element);
+ }
+ return array;
+ }
+ else if (metaType.isComposite())
+ {
+ CompositeValue compositeValue = (CompositeValue)metaValue;
+ return unwrapComposite(compositeValue, type);
+ }
+ else if (metaType.isCollection())
+ {
+ CollectionValue collectionValue = (CollectionValue)metaValue;
+ return unwrapCollection(collectionValue, type);
+ }
+ else if (metaType.isTable())
+ {
+ TableValue tableValue = (TableValue)metaValue;
+ return unwrapTable(tableValue, type);
+ }
+
+ throw new IllegalArgumentException("Unsupported meta value: " + metaValue);
+ }
+
+ /**
+ * Do a simple check.
+ * If current type param is null,
+ * try getting type info from meta type
+ * and value's classloader.
+ *
+ * @param type the type info
+ * @param value tester value
+ * @param metaType the meta type
+ * @return type info
+ */
+ protected TypeInfo checkTypeInfo(TypeInfo type, Object value, MetaType metaType)
+ {
+ if (type == null && value != null)
+ type = getTypeInfo(metaType, value);
+ return type;
+ }
+
+ /**
+ * Get the value.
+ * Join type check and value conversion.
+ *
+ * @param metaType the meta type
+ * @param typeInfo the type info
+ * @param value the value
+ * @return the converted value
+ */
+ protected Object getValue(MetaType metaType, TypeInfo typeInfo, Object value)
+ {
+ typeInfo = checkTypeInfo(typeInfo, value, metaType);
+ return convertValue(value, typeInfo);
+ }
+
+ /**
+ * Unwrap MetaValue.
+ *
+ * @param element the meta value
+ * @param type parent type
+ * @param array parent array
+ * @return unwrapped value
+ */
+ protected Object unwrapMetaValue(MetaValue element, TypeInfo type, Object array)
+ {
+ TypeInfo elementType;
+ if (type instanceof ClassInfo)
+ elementType = ((ClassInfo)type).getComponentType();
+ else
+ elementType = getTypeInfo(element.getMetaType(), array);
+ return unwrap(element, elementType);
+ }
+
+ /**
+ * Unwrap array.
+ * @param array parent array
+ * @param element current array element
+ * @return unwrapped array element
+ */
+ protected Object unwrapArray(Object array, Object element)
+ {
+ TypeInfo elementType = configuration.getTypeInfo(array.getClass().getComponentType());
+ int subSize = Array.getLength(element);
+ Object newElement = newArrayInstance(elementType, subSize);
+ for(int i = 0; i < subSize; i++)
+ {
+ Object subElement = Array.get(element, i);
+ if (subElement instanceof MetaValue)
+ subElement = unwrapMetaValue((MetaValue)subElement, elementType, newElement);
+ if (subElement != null && subElement.getClass().isArray())
+ subElement = unwrapArray(newElement, subElement);
+
+ Array.set(newElement, i, subElement);
+ }
+ return newElement;
+ }
+
+ /**
+ * Unwrap composite.
+ *
+ * @param compositeValue the composite value
+ * @param typeInfo expected type info
+ * @return unwrapped value
+ */
+ @SuppressWarnings("deprecation")
+ protected Object unwrapComposite(CompositeValue compositeValue, TypeInfo typeInfo)
+ {
+ CompositeMetaType compositeMetaType = compositeValue.getMetaType();
+ String typeName = compositeMetaType.getTypeName();
+ ClassLoader cl;
+ if (typeInfo != null)
+ cl = typeInfo.getType().getClassLoader();
+ else
+ cl = Thread.currentThread().getContextClassLoader();
+
+ try
+ {
+ BeanInfo beanInfo = configuration.getBeanInfo(typeName, cl);
+ ClassInfo classInfo = beanInfo.getClassInfo();
+ Class<?> clazz = classInfo.getType();
+ if (classInfo.isInterface())
+ {
+ // Handle map specially
+ if (clazz.isAssignableFrom(Map.class))
+ return unwrapCompositeMap(compositeValue);
+
+ InvocationHandler handler = createCompositeValueInvocationHandler(compositeValue);
+ Class<?>[] interfaces = new Class[]{clazz};
+ return Proxy.newProxyInstance(clazz.getClassLoader(), interfaces, handler);
+ }
+ else if(clazz.isAssignableFrom(ObjectName.class))
+ {
+ // TODO: this should be handled more generically
+ MetaValue domain = compositeValue.get("domain");
+ String domainUnwrap = (String) unwrap(domain, String.class);
+ MetaValue keys = compositeValue.get("keyPropertyList");
+ Hashtable keysUnwrap = null;
+ if(keys instanceof PropertiesMetaValue)
+ keysUnwrap = (PropertiesMetaValue) keys;
+ ObjectName name = new ObjectName(domainUnwrap, keysUnwrap);
+ return name;
+ }
+
+ Object bean = createNewInstance(beanInfo);
+ for (String name : compositeMetaType.itemSet())
+ {
+ MetaValue itemValue = compositeValue.get(name);
+ PropertyInfo propertyInfo = beanInfo.getProperty(name);
+ Object value = unwrap(itemValue, propertyInfo.getType());
+ propertyInfo.set(bean, value);
+ }
+ return bean;
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+
+ protected Map unwrapCompositeMap(CompositeValue compositeValue)
+ {
+ HashMap map = new HashMap();
+ CompositeMetaType metaType = compositeValue.getMetaType();
+ for(String key : metaType.itemSet())
+ {
+ MetaValue mv = compositeValue.get(key);
+ Object value = unwrap(mv);
+ map.put(key, value);
+ }
+ return map;
+ }
+
+ /**
+ * Create composite invocation handler.
+ *
+ * @param compositeValue the composite value
+ * @return composite invocation handler
+ */
+ protected InvocationHandler createCompositeValueInvocationHandler(CompositeValue compositeValue)
+ {
+ return new CompositeValueInvocationHandler(compositeValue);
+ }
+
+ /**
+ * Unwrap collection meta value.
+ *
+ * @param collectionValue the collection value
+ * @param type the type info
+ * @return unwrapped collection
+ */
+ @SuppressWarnings("unchecked")
+ protected Object unwrapCollection(CollectionValue collectionValue, TypeInfo type)
+ {
+ try
+ {
+ BeanInfo collectionInfo;
+ // null is not instance of
+ if (type instanceof ClassInfo)
+ {
+ collectionInfo = configuration.getBeanInfo(type);
+ }
+ else
+ {
+ MetaType metaType = collectionValue.getMetaType();
+ collectionInfo = configuration.getBeanInfo(metaType.getTypeName(), Thread.currentThread().getContextClassLoader());
+ }
+ ClassInfo classInfo = collectionInfo.getClassInfo();
+ Collection collection = (Collection)createNewInstance(collectionInfo);
+
+ TypeInfo componentType = classInfo.getComponentType();
+ boolean isObjectTypeInfo = OBJECT_TYPE_INFO.equals(componentType);
+
+ for (MetaValue metaValue : collectionValue)
+ {
+ TypeInfo iterTypeInfo = isObjectTypeInfo ? getTypeInfo(metaValue.getMetaType(), null) : componentType;
+ collection.add(unwrap(metaValue, iterTypeInfo));
+ }
+ return collection;
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+
+ /**
+ * Unwrap table meta value.
+ *
+ * @param tableValue the table value
+ * @param type the type info
+ * @return unwrapped table (map)
+ */
+ @SuppressWarnings("deprecation")
+ protected Object unwrapTable(TableValue tableValue, TypeInfo type)
+ {
+ if (type instanceof ParameterizedClassInfo)
+ {
+ ParameterizedClassInfo parameterizedType = (ParameterizedClassInfo)type;
+ ClassInfo rawType = parameterizedType.getRawType();
+ if (Map.class.isAssignableFrom(rawType.getType()))
+ {
+ TypeInfo keyType = parameterizedType.getActualTypeArguments()[0];
+ TypeInfo valueType = parameterizedType.getActualTypeArguments()[1];
+ return createMap(tableValue, keyType, valueType);
+ }
+ }
+ throw new UnsupportedOperationException("Insufficient information to unwrap table: " + tableValue + ", " + type);
+ }
+
+ /**
+ * Create a map
+ *
+ * @param tableValue the table value
+ * @param keyType the key type
+ * @param valueType the value type
+ * @return the map
+ */
+ protected Map<?,?> createMap(TableValue tableValue, TypeInfo keyType, TypeInfo valueType)
+ {
+ if (tableValue == null)
+ return null;
+
+ Map<Object, Object> result = new HashMap<Object, Object>();
+ Collection<CompositeValue> values = tableValue.values();
+ for (CompositeValue entry : values)
+ {
+ Object key = unwrap(entry.get(DefaultMetaTypeFactory.MAP_KEY), keyType);
+ Object val = unwrap(entry.get(DefaultMetaTypeFactory.MAP_VALUE), valueType);
+ result.put(key, val);
+ }
+ return result;
+ }
+
+ /**
+ * Create a PropertiesMetaValue
+ * @param metaType
+ * @param value
+ * @param mapping
+ * @return
+ */
+ protected MetaValue createPropertiesValue(PropertiesMetaType metaType,
+ Object value, Map<Object, MetaValue> mapping)
+ {
+ if (value == null)
+ return null;
+ if((value instanceof Hashtable) == false)
+ throw new IllegalArgumentException("PropertiesMetaType requires a java.lang.Properties value, value.class: "+value.getClass());
+
+ Hashtable pvalue = (Hashtable) value;
+ PropertiesMetaValue pmv = new PropertiesMetaValue();
+ for(Object key : pvalue.keySet())
+ {
+ if ((key instanceof String) == false)
+ throw new IllegalArgumentException("key("+key+") is not a String");
+ String skey = (String) key;
+ Object ovalue = pvalue.get(skey);
+ if ((key instanceof String) == false)
+ throw new IllegalArgumentException("value for key("+key+") is not a String, value.class: "+ovalue.getClass());
+ String svalue = (String) ovalue;
+ pmv.setProperty(skey, svalue);
+ }
+ return pmv;
+ }
+
+ /**
+ * Create new instance.
+ *
+ * @param beanInfo the bean info
+ * @return new instance
+ * @throws Throwable for any error
+ */
+ @SuppressWarnings("deprecation")
+ protected Object createNewInstance(BeanInfo beanInfo) throws Throwable
+ {
+ ClassInfo classInfo = beanInfo.getClassInfo();
+ if (classInfo.isInterface())
+ {
+ InstanceFactory<?> instanceFactory = instanceFactoryMap.get(classInfo.getType());
+ if (instanceFactory == null)
+ throw new IllegalArgumentException("Cannot instantiate interface BeanInfo, missing InstanceFactory: " + classInfo);
+
+ return instanceFactory.instantiate(beanInfo);
+ }
+ return beanInfo.newInstance();
+ }
+
+ /**
+ * Get new array instance.
+ *
+ * @param typeInfo the type info
+ * @param size the size
+ * @return new array instance
+ */
+ protected Object newArrayInstance(TypeInfo typeInfo, int size)
+ {
+ if (typeInfo == null)
+ throw new IllegalArgumentException("Null type info.");
+
+ try
+ {
+ return typeInfo.newArrayInstance(size);
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+
+ /**
+ * Get the class info from meta type.
+ *
+ * @param metaType the meta type
+ * @param value the value which can provide classloader
+ * @return type info
+ */
+ protected TypeInfo getTypeInfo(MetaType metaType, Object value)
+ {
+ if (metaType == null)
+ throw new IllegalArgumentException("Null meta type, cannot determine class name.");
+ if (value == null)
+ throw new IllegalArgumentException("Null value, cannot determine classloader.");
+
+ // get the classloader from the array we plan to fill
+ ClassLoader cl = value.getClass().getClassLoader();
+ return getTypeInfo(metaType, cl);
+ }
+
+ /**
+ * Get the class info from meta type.
+ *
+ * @param metaType the meta type
+ * @param cl the classloader
+ * @return class info
+ */
+ protected TypeInfo getTypeInfo(MetaType metaType, ClassLoader cl)
+ {
+ if (cl == null)
+ cl = Thread.currentThread().getContextClassLoader();
+
+ try
+ {
+ TypeInfoFactory tif = configuration.getTypeInfoFactory();
+ if (metaType.isArray())
+ {
+ ArrayMetaType arrayMetaType = (ArrayMetaType)metaType;
+ MetaType elementMetaType = arrayMetaType.getElementType();
+ String elementTypeName = elementMetaType.getTypeName();
+ if (arrayMetaType.isPrimitiveArray())
+ elementTypeName = ArrayMetaType.getPrimitiveName(elementTypeName);
+ TypeInfo elementTypeInfo = tif.getTypeInfo(elementTypeName, cl);
+ int dimension = arrayMetaType.getDimension() - 1; // minus 1, since we already use first in next line
+ TypeInfo typeInfo = elementTypeInfo.getArrayType();
+ while(dimension > 0)
+ {
+ typeInfo = typeInfo.getArrayType();
+ dimension--;
+ }
+ return typeInfo;
+ }
+ return tif.getTypeInfo(metaType.getTypeName(), cl);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ }
+
+ /**
+ * Create a meta value from the object
+ *
+ * @param value the value
+ * @param type the type
+ * @param metaType the metaType
+ * @return the meta value
+ */
+ @SuppressWarnings("unchecked")
+ protected MetaValue internalCreate(Object value, TypeInfo type, MetaType metaType)
+ {
+ if (value == null)
+ return null;
+
+ if (type == null)
+ type = configuration.getTypeInfo(value.getClass());
+
+ value = convertValue(value, type);
+
+ boolean start = false;
+ if (metaType == null)
+ {
+ start = true;
+ metaType = metaTypeFactory.resolve(type);
+ }
+
+ // For more complicated values we need to keep a mapping of objects to meta values
+ // this avoids duplicate meta value construction and recursion
+ Map<Object, MetaValue> mapping;
+ if (start)
+ {
+ // This is the start of the mapping
+ mapping = new HashMap<Object, MetaValue>();
+ mappingStack.get().push(mapping);
+ }
+ else
+ {
+ // Check the existing mapping
+ mapping = mappingStack.get().peek();
+ MetaValue result = mapping.get(value);
+ // Seen this before
+ if (result != null)
+ return result;
+ }
+
+ try
+ {
+ MetaValue result = isBuilder(metaType, type, value, mapping);
+
+ if (result == null)
+ {
+ MetaMapper<Object> mapper = (MetaMapper) MetaMapper.getMetaMapper(type);
+ if (mapper != null)
+ result = mapper.createMetaValue(metaType, value);
+ }
+
+ if (result == null)
+ {
+ if (metaType.isSimple())
+ result = createSimpleValue((SimpleMetaType) metaType, (Serializable) value);
+ else if (metaType.isEnum())
+ result = createEnumValue((EnumMetaType) metaType, (Enum<?>) value);
+ else if (metaType.isArray())
+ result = createArrayValue((ArrayMetaType) metaType, value, mapping);
+ else if (metaType.isComposite())
+ result = createCompositeValue((CompositeMetaType) metaType, value, mapping);
+ else if (metaType.isTable())
+ result = createTableValue((TableMetaType) metaType, (Map<?,?>) value, mapping);
+ else if (metaType.isGeneric())
+ result = createGenericValue((GenericMetaType) metaType, value, mapping);
+ else if (metaType.isCollection())
+ result = createCollectionValue((CollectionMetaType) metaType, value, mapping);
+ else if (metaType.isProperties())
+ result = createPropertiesValue((PropertiesMetaType) metaType, value, mapping);
+ else
+ throw new IllegalStateException("Unknown metaType: " + metaType);
+ }
+ return result;
+ }
+ finally
+ {
+ // Remove the mapping from the stack
+ if (start)
+ mappingStack.get().pop();
+ }
+ }
+
+ /**
+ * Convert the value.
+ *
+ * @param value the value
+ * @param typeInfo type info
+ * @return converted value if type info not null
+ * @throws UndeclaredThrowableException for any error
+ */
+ protected Object convertValue(Object value, TypeInfo typeInfo)
+ {
+ try
+ {
+ return typeInfo != null ? typeInfo.convertValue(value) : value;
+ }
+ catch (Throwable t)
+ {
+ throw new UndeclaredThrowableException(t);
+ }
+ }
+
+ /**
+ * Check for a builder
+ *
+ * @param metaType the meta type
+ * @param type the type
+ * @param value the value
+ * @param mapping the mappings
+ * @return the meta value
+ */
+ @SuppressWarnings({"unchecked", "deprecation"})
+ protected MetaValue isBuilder(MetaType metaType, TypeInfo type, Object value, Map<Object, MetaValue> mapping)
+ {
+ MetaValueBuilder builder = null;
+ synchronized (builders)
+ {
+ WeakReference<MetaValueBuilder<?>> weak = builders.get(type.getType());
+ if (weak != null)
+ builder = weak.get();
+ }
+ if (builder == null)
+ return null;
+ MetaValue result = builder.buildMetaValue(metaType, value);
+ if (result != null)
+ mapping.put(value, result);
+
+ return result;
+ }
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java (from rev 85721, projects/jboss-man/branches/Branch_2_1/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/main/java/org/jboss/metatype/plugins/values/mappers/PropertiesCompositeObjectNameMetaMapper.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.metatype.plugins.values.mappers;
+
+import java.lang.reflect.Type;
+import java.util.Hashtable;
+
+import javax.management.ObjectName;
+
+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.PropertiesMetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.types.ObjectNameTypeBuilder;
+import org.jboss.metatype.spi.values.MetaMapper;
+
+/**
+ * A MetaMapper for ObjectName to CompositeValue using domain, keyPropertyList
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class PropertiesCompositeObjectNameMetaMapper extends MetaMapper<ObjectName>
+{
+
+ @Override
+ public MetaType getMetaType()
+ {
+ return ObjectNameTypeBuilder.META_TYPE;
+ }
+ @Override
+ public Type mapToType()
+ {
+ return ObjectName.class;
+ }
+
+ @Override
+ public MetaValue createMetaValue(MetaType metaType, ObjectName object)
+ {
+ String[] itemNames = {"domain", "keyPropertyList"};
+ PropertiesMetaValue keyValues = new PropertiesMetaValue();
+ for(Object key : object.getKeyPropertyList().keySet())
+ {
+ Object value = object.getKeyProperty((String)key);
+ keyValues.put(key, value);
+ }
+ MetaValue[] itemValues = {SimpleValueSupport.wrap(object.getDomain()), };
+ CompositeValueSupport mv = new CompositeValueSupport(ObjectNameTypeBuilder.META_TYPE,
+ itemNames, itemValues);
+ return mv;
+ }
+
+ @Override
+ public ObjectName unwrapMetaValue(MetaValue metaValue)
+ {
+ CompositeValue compositeValue = (CompositeValue) metaValue;
+ SimpleValue domain = (SimpleValue) compositeValue.get("domain");
+ String domainUnwrap = domain.toString();
+ MetaValue keys = compositeValue.get("keyPropertyList");
+ Hashtable keysUnwrap = null;
+ if(keys instanceof PropertiesMetaValue)
+ keysUnwrap = (PropertiesMetaValue) keys;
+ try
+ {
+ ObjectName name = new ObjectName(domainUnwrap, keysUnwrap);
+ return name;
+ }
+ catch(Exception e)
+ {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,142 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.metatype.types.factory.test;
-
-import org.jboss.metatype.api.types.ArrayMetaType;
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.test.metatype.types.factory.support.TestSimpleComposite;
-
-import junit.framework.Test;
-
-/**
- * ArrayMetaTypeFactoryUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ArrayMetaTypeFactoryUnitTestCase extends AbstractMetaTypeFactoryTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(ArrayMetaTypeFactoryUnitTestCase.class);
- }
-
- /**
- * Create a new ArrayMetaTypeFactoryUnitTestCase.
- *
- * @param name the test name
- */
- public ArrayMetaTypeFactoryUnitTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Test the correct meta type is generated for a simple array
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testSimpleArray() throws Exception
- {
- String[] array = new String[0];
- MetaType result = resolve(array.getClass());
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(1, SimpleMetaType.STRING);
- testArray(expected, actual);
- }
-
- @SuppressWarnings("unchecked")
- public void testCharArray()
- throws Exception
- {
- char[] array = {'H', 'e', 'l', 'l', 'o'};
- MetaType result = resolve(array.getClass());
-
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(1, SimpleMetaType.CHARACTER);
- testArray(expected, actual);
- }
- @SuppressWarnings("unchecked")
- public void testChar2DArray()
- throws Exception
- {
- char[][] array = {{'H', 'e', 'l', 'l', 'o'}};
- MetaType result = resolve(array.getClass());
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(2, SimpleMetaType.CHARACTER);
- testArray(expected, actual);
- }
-
- /**
- * Test the correct meta type is generated for a composite array
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testSimpleCompositeArray() throws Exception
- {
- TestSimpleComposite[] array = new TestSimpleComposite[0];
- MetaType result = resolve(array.getClass());
- MetaType composite = resolve(TestSimpleComposite.class);
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(1, composite);
- testArray(expected, actual);
- }
-
- /**
- * Test the correct meta type is generated for a multidimensional simple array
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testMultiSimpleArray() throws Exception
- {
- String[][] array = new String[0][0];
- MetaType result = resolve(array.getClass());
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(2, SimpleMetaType.STRING);
- testArray(expected, actual);
- }
-
- /**
- * Test the correct meta type is generated for a mutli dimensional composite array
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testMultiSimpleCompositeArray() throws Exception
- {
- TestSimpleComposite[][] array = new TestSimpleComposite[0][0];
- MetaType result = resolve(array.getClass());
- MetaType composite = resolve(TestSimpleComposite.class);
- ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
- ArrayMetaType expected = new ArrayMetaType(2, composite);
- testArray(expected, actual);
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/ArrayMetaTypeFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,156 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metatype.types.factory.test;
+
+import org.jboss.metatype.api.types.ArrayMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.test.metatype.types.factory.support.TestSimpleComposite;
+
+import junit.framework.Test;
+
+/**
+ * ArrayMetaTypeFactoryUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ArrayMetaTypeFactoryUnitTestCase extends AbstractMetaTypeFactoryTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(ArrayMetaTypeFactoryUnitTestCase.class);
+ }
+
+ /**
+ * Create a new ArrayMetaTypeFactoryUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public ArrayMetaTypeFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the correct meta type is generated for a simple array
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testSimpleArray() throws Exception
+ {
+ String[] array = new String[0];
+ MetaType result = resolve(array.getClass());
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(1, SimpleMetaType.STRING);
+ testArray(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testCharArray()
+ throws Exception
+ {
+ char[] array = {'H', 'e', 'l', 'l', 'o'};
+ MetaType result = resolve(array.getClass());
+
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(1, SimpleMetaType.CHARACTER_PRIMITIVE);
+ testArray(expected, actual);
+ }
+ public void testCharacterArray()
+ throws Exception
+ {
+ Character[] array = {Character.valueOf('H'),
+ Character.valueOf('e'),
+ Character.valueOf('l'),
+ Character.valueOf('l'),
+ Character.valueOf('o')};
+ MetaType result = resolve(array.getClass());
+
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(1, SimpleMetaType.CHARACTER);
+ testArray(expected, actual);
+ }
+ @SuppressWarnings("unchecked")
+ public void testChar2DArray()
+ throws Exception
+ {
+ char[][] array = {{'H', 'e', 'l', 'l', 'o'}};
+ MetaType result = resolve(array.getClass());
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(2, SimpleMetaType.CHARACTER_PRIMITIVE);
+ testArray(expected, actual);
+ }
+
+ /**
+ * Test the correct meta type is generated for a composite array
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testSimpleCompositeArray() throws Exception
+ {
+ TestSimpleComposite[] array = new TestSimpleComposite[0];
+ MetaType result = resolve(array.getClass());
+ MetaType composite = resolve(TestSimpleComposite.class);
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(1, composite);
+ testArray(expected, actual);
+ }
+
+ /**
+ * Test the correct meta type is generated for a multidimensional simple array
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testMultiSimpleArray() throws Exception
+ {
+ String[][] array = new String[0][0];
+ MetaType result = resolve(array.getClass());
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(2, SimpleMetaType.STRING);
+ testArray(expected, actual);
+ }
+
+ /**
+ * Test the correct meta type is generated for a mutli dimensional composite array
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testMultiSimpleCompositeArray() throws Exception
+ {
+ TestSimpleComposite[][] array = new TestSimpleComposite[0][0];
+ MetaType result = resolve(array.getClass());
+ MetaType composite = resolve(TestSimpleComposite.class);
+ ArrayMetaType actual = assertInstanceOf(result, ArrayMetaType.class);
+ ArrayMetaType expected = new ArrayMetaType(2, composite);
+ testArray(expected, actual);
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,126 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.metatype.types.factory.test;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Date;
-
-import junit.framework.Test;
-
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.SimpleMetaType;
-
-/**
- * SimpleMetaTypeFactoryUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleMetaTypeFactoryUnitTestCase extends AbstractMetaTypeFactoryTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(SimpleMetaTypeFactoryUnitTestCase.class);
- }
-
- /**
- * Create a new SimpleMetaTypeFactoryUnitTestCase.
- *
- * @param name the test name
- */
- public SimpleMetaTypeFactoryUnitTestCase(String name)
- {
- super(name);
- }
-
- SimpleMetaType[] expected = new SimpleMetaType[]
- {
- SimpleMetaType.BIGDECIMAL,
- SimpleMetaType.BIGINTEGER,
- SimpleMetaType.BOOLEAN,
- SimpleMetaType.BOOLEAN,
- SimpleMetaType.BYTE,
- SimpleMetaType.BYTE,
- SimpleMetaType.CHARACTER,
- SimpleMetaType.CHARACTER,
- SimpleMetaType.DATE,
- SimpleMetaType.DOUBLE,
- SimpleMetaType.DOUBLE,
- SimpleMetaType.FLOAT,
- SimpleMetaType.FLOAT,
- SimpleMetaType.INTEGER,
- SimpleMetaType.INTEGER,
- SimpleMetaType.LONG,
- SimpleMetaType.LONG,
- SimpleMetaType.SHORT,
- SimpleMetaType.SHORT,
- SimpleMetaType.STRING,
- SimpleMetaType.VOID
- };
-
- Class<?>[] classes = new Class<?>[]
- {
- BigDecimal.class,
- BigInteger.class,
- Boolean.class,
- Boolean.TYPE,
- Byte.class,
- Byte.TYPE,
- Character.class,
- Character.TYPE,
- Date.class,
- Double.class,
- Double.TYPE,
- Float.class,
- Float.TYPE,
- Integer.class,
- Integer.TYPE,
- Long.class,
- Long.TYPE,
- Short.class,
- Short.TYPE,
- String.class,
- Void.class
- };
-
- /**
- * Test the simple meta types are generated correctly
- *
- * @throws Exception for any problem
- */
- public void testSimpleTypes() throws Exception
- {
- for (int i = 0; i < expected.length; ++i)
- {
- String className = classes[i].getName();
- MetaType actual = resolve(classes[i]);
- getLog().debug("SimpleMetaType: " + className + " className=" + actual.getClassName() + " typeName=" + actual.getTypeName() + " description=" + actual.getDescription());
- assertEquals(expected[i], actual);
- }
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/factory/test/SimpleMetaTypeFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,126 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metatype.types.factory.test;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+
+/**
+ * SimpleMetaTypeFactoryUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleMetaTypeFactoryUnitTestCase extends AbstractMetaTypeFactoryTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(SimpleMetaTypeFactoryUnitTestCase.class);
+ }
+
+ /**
+ * Create a new SimpleMetaTypeFactoryUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public SimpleMetaTypeFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ SimpleMetaType[] expected = new SimpleMetaType[]
+ {
+ SimpleMetaType.BIGDECIMAL,
+ SimpleMetaType.BIGINTEGER,
+ SimpleMetaType.BOOLEAN,
+ SimpleMetaType.BOOLEAN_PRIMITIVE,
+ SimpleMetaType.BYTE,
+ SimpleMetaType.BYTE_PRIMITIVE,
+ SimpleMetaType.CHARACTER,
+ SimpleMetaType.CHARACTER_PRIMITIVE,
+ SimpleMetaType.DATE,
+ SimpleMetaType.DOUBLE,
+ SimpleMetaType.DOUBLE_PRIMITIVE,
+ SimpleMetaType.FLOAT,
+ SimpleMetaType.FLOAT_PRIMITIVE,
+ SimpleMetaType.INTEGER,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ SimpleMetaType.LONG,
+ SimpleMetaType.LONG_PRIMITIVE,
+ SimpleMetaType.SHORT,
+ SimpleMetaType.SHORT_PRIMITIVE,
+ SimpleMetaType.STRING,
+ SimpleMetaType.VOID
+ };
+
+ Class<?>[] classes = new Class<?>[]
+ {
+ BigDecimal.class,
+ BigInteger.class,
+ Boolean.class,
+ Boolean.TYPE,
+ Byte.class,
+ Byte.TYPE,
+ Character.class,
+ Character.TYPE,
+ Date.class,
+ Double.class,
+ Double.TYPE,
+ Float.class,
+ Float.TYPE,
+ Integer.class,
+ Integer.TYPE,
+ Long.class,
+ Long.TYPE,
+ Short.class,
+ Short.TYPE,
+ String.class,
+ Void.class
+ };
+
+ /**
+ * Test the simple meta types are generated correctly
+ *
+ * @throws Exception for any problem
+ */
+ public void testSimpleTypes() throws Exception
+ {
+ for (int i = 0; i < expected.length; ++i)
+ {
+ String className = classes[i].getName();
+ MetaType actual = resolve(classes[i]);
+ getLog().debug("SimpleMetaType: " + className + " className=" + actual.getClassName() + " typeName=" + actual.getTypeName() + " description=" + actual.getDescription());
+ assertEquals(expected[i], actual);
+ }
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,286 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.metatype.types.test;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Date;
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.Test;
-
-import org.jboss.metatype.api.types.MetaType;
-import org.jboss.metatype.api.types.Name;
-import org.jboss.metatype.api.values.ArrayValue;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.EnumValue;
-import org.jboss.metatype.api.values.GenericValue;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.TableValue;
-import org.jboss.test.metatype.AbstractMetaTypeTest;
-import org.jboss.test.metatype.types.support.MockMetaType;
-
-/**
- * MetaTypeUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class MetaTypeUnitTestCase extends AbstractMetaTypeTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(MetaTypeUnitTestCase.class);
- }
-
- /**
- * Create a new MetaTypeUnitTestCase.
- *
- * @param name the test name
- */
- public MetaTypeUnitTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Test the allowed classes
- *
- * @throws Exception for any problem
- */
- public void testAllowedClasses() throws Exception
- {
- List<String> allowedClassNames = MetaType.ALLOWED_CLASSNAMES;
- assertEquals(21, allowedClassNames.size());
- checkMetaType(allowedClassNames, Void.class);
- checkMetaType(allowedClassNames, Boolean.class);
- checkMetaType(allowedClassNames, Character.class);
- checkMetaType(allowedClassNames, Byte.class);
- checkMetaType(allowedClassNames, Short.class);
- checkMetaType(allowedClassNames, Integer.class);
- checkMetaType(allowedClassNames, Long.class);
- checkMetaType(allowedClassNames, Float.class);
- checkMetaType(allowedClassNames, Double.class);
- checkMetaType(allowedClassNames, String.class);
- checkMetaType(allowedClassNames, Date.class);
- checkMetaType(allowedClassNames, BigDecimal.class);
- checkMetaType(allowedClassNames, BigInteger.class);
- checkMetaType(allowedClassNames, Name.class);
- checkMetaType(allowedClassNames, SimpleValue.class);
- checkMetaType(allowedClassNames, EnumValue.class);
- checkMetaType(allowedClassNames, GenericValue.class);
- checkMetaType(allowedClassNames, ArrayValue.class);
- checkMetaType(allowedClassNames, CompositeValue.class);
- checkMetaType(allowedClassNames, TableValue.class);
- checkMetaType(allowedClassNames, Properties.class);
- }
-
- /**
- * Test the simple constructor
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testConstructorSimple() throws Exception
- {
- MetaType test = new MockMetaType("java.lang.Void", "type", "description");
- assertEquals("java.lang.Void", test.getClassName());
- assertEquals("type", test.getTypeName());
- assertEquals("description", test.getDescription());
- assertEquals(false, test.isArray());
- }
-
- /**
- * Test the array constructor
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testConstructorArray() throws Exception
- {
- MetaType test = new MockMetaType("[[Ljava.lang.Void;", "type", "description");
- assertEquals("[[Ljava.lang.Void;", test.getClassName());
- assertEquals("type", test.getTypeName());
- assertEquals("description", test.getDescription());
- assertEquals(true, test.isArray());
- }
-
- /**
- * Test the simple serialization
- *
- * @throws Exception for any problem
- */
- public void testSerializationSimple() throws Exception
- {
- testSerialization("java.lang.Void", "type", "description");
- }
-
- /**
- * Test the array serialization
- *
- * @throws Exception for any problem
- */
- public void testSerializationArray() throws Exception
- {
- testSerialization("[[Ljava.lang.Void;", "type", "description");
- }
-
- /**
- * Test the errors
- *
- * @throws Exception for any problem
- */
- @SuppressWarnings("unchecked")
- public void testErrors() throws Exception
- {
- try
- {
- new MockMetaType(null, "dummy", "dummy");
- fail("className cannot be null");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("", "dummy", "dummy");
- fail("className cannot be empty");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("java.lang.Void", null, "dummy");
- fail("typeName cannot be null");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("java.lang.Void", null, "dummy");
- fail("typeName cannot be empty");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("java.lang.Void", "dummy", null);
- fail("description cannot be null");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("java.lang.Void", "dummy", "");
- fail("description cannot be empty");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("java.lang.Class", "dummy", "dummy");
- fail("className must be a MetaType");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("[Ljava.lang.Void", "dummy", "dummy");
- fail("[Ljava.lang.Void is not a valid array");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("[L", "dummy", "dummy");
- fail("[L is not a valid array");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
-
- try
- {
- new MockMetaType("[Xjava.lang.Void;", "dummy", "dummy");
- fail("FAILS IN RI: [Xjava.lang.Void; is not a valid array");
- }
- catch (Throwable e)
- {
- checkThrowable(IllegalArgumentException.class, e);
- }
- }
-
- @SuppressWarnings("unchecked")
- private void testSerialization(String className, String type, String description) throws Exception
- {
- MetaType original = new MockMetaType(className, type, description);
- byte[] bytes = serialize(original);
- MetaType result = (MetaType) deserialize(bytes);
- assertEquals(original.getClassName(), result.getClassName());
- assertEquals(original.getTypeName(), result.getTypeName());
- assertEquals(original.getDescription(), result.getDescription());
- assertEquals(original.isArray(), result.isArray());
- }
-
- @SuppressWarnings("unchecked")
- private void checkMetaType(List names, Class clazz) throws Exception
- {
- String name = clazz.getName();
- assertTrue(name + " is a MetaType", names.contains(name));
-
- new MockMetaType(name, "dummy", "dummy");
-
- new MockMetaType("[L"+name+";", "dummy", "dummy");
-
- new MockMetaType("[[[[[L"+name+";", "dummy", "dummy");
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/MetaTypeUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,294 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metatype.types.test;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.List;
+import java.util.Properties;
+
+import junit.framework.Test;
+
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.Name;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.EnumValue;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.TableValue;
+import org.jboss.test.metatype.AbstractMetaTypeTest;
+import org.jboss.test.metatype.types.support.MockMetaType;
+
+/**
+ * MetaTypeUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MetaTypeUnitTestCase extends AbstractMetaTypeTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(MetaTypeUnitTestCase.class);
+ }
+
+ /**
+ * Create a new MetaTypeUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public MetaTypeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the allowed classes
+ *
+ * @throws Exception for any problem
+ */
+ public void testAllowedClasses() throws Exception
+ {
+ List<String> allowedClassNames = MetaType.ALLOWED_CLASSNAMES;
+ assertEquals(29, allowedClassNames.size());
+ checkMetaType(allowedClassNames, Void.class);
+ checkMetaType(allowedClassNames, Boolean.class);
+ checkMetaType(allowedClassNames, Character.class);
+ checkMetaType(allowedClassNames, Byte.class);
+ checkMetaType(allowedClassNames, Short.class);
+ checkMetaType(allowedClassNames, Integer.class);
+ checkMetaType(allowedClassNames, Long.class);
+ checkMetaType(allowedClassNames, Float.class);
+ checkMetaType(allowedClassNames, Double.class);
+ checkMetaType(allowedClassNames, String.class);
+ checkMetaType(allowedClassNames, Date.class);
+ checkMetaType(allowedClassNames, BigDecimal.class);
+ checkMetaType(allowedClassNames, BigInteger.class);
+ checkMetaType(allowedClassNames, Name.class);
+ checkMetaType(allowedClassNames, SimpleValue.class);
+ checkMetaType(allowedClassNames, EnumValue.class);
+ checkMetaType(allowedClassNames, GenericValue.class);
+ checkMetaType(allowedClassNames, ArrayValue.class);
+ checkMetaType(allowedClassNames, CompositeValue.class);
+ checkMetaType(allowedClassNames, TableValue.class);
+ checkMetaType(allowedClassNames, Properties.class);
+ checkMetaType(allowedClassNames, boolean.class);
+ checkMetaType(allowedClassNames, byte.class);
+ checkMetaType(allowedClassNames, char.class);
+ checkMetaType(allowedClassNames, float.class);
+ checkMetaType(allowedClassNames, double.class);
+ checkMetaType(allowedClassNames, int.class);
+ checkMetaType(allowedClassNames, long.class);
+ checkMetaType(allowedClassNames, short.class);
+ }
+
+ /**
+ * Test the simple constructor
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testConstructorSimple() throws Exception
+ {
+ MetaType test = new MockMetaType("java.lang.Void", "type", "description");
+ assertEquals("java.lang.Void", test.getClassName());
+ assertEquals("type", test.getTypeName());
+ assertEquals("description", test.getDescription());
+ assertEquals(false, test.isArray());
+ }
+
+ /**
+ * Test the array constructor
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testConstructorArray() throws Exception
+ {
+ MetaType test = new MockMetaType("[[Ljava.lang.Void;", "type", "description");
+ assertEquals("[[Ljava.lang.Void;", test.getClassName());
+ assertEquals("type", test.getTypeName());
+ assertEquals("description", test.getDescription());
+ assertEquals(true, test.isArray());
+ }
+
+ /**
+ * Test the simple serialization
+ *
+ * @throws Exception for any problem
+ */
+ public void testSerializationSimple() throws Exception
+ {
+ testSerialization("java.lang.Void", "type", "description");
+ }
+
+ /**
+ * Test the array serialization
+ *
+ * @throws Exception for any problem
+ */
+ public void testSerializationArray() throws Exception
+ {
+ testSerialization("[[Ljava.lang.Void;", "type", "description");
+ }
+
+ /**
+ * Test the errors
+ *
+ * @throws Exception for any problem
+ */
+ @SuppressWarnings("unchecked")
+ public void testErrors() throws Exception
+ {
+ try
+ {
+ new MockMetaType(null, "dummy", "dummy");
+ fail("className cannot be null");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("", "dummy", "dummy");
+ fail("className cannot be empty");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("java.lang.Void", null, "dummy");
+ fail("typeName cannot be null");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("java.lang.Void", null, "dummy");
+ fail("typeName cannot be empty");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("java.lang.Void", "dummy", null);
+ fail("description cannot be null");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("java.lang.Void", "dummy", "");
+ fail("description cannot be empty");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("java.lang.Class", "dummy", "dummy");
+ fail("className must be a MetaType");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("[Ljava.lang.Void", "dummy", "dummy");
+ fail("[Ljava.lang.Void is not a valid array");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("[L", "dummy", "dummy");
+ fail("[L is not a valid array");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+
+ try
+ {
+ new MockMetaType("[Xjava.lang.Void;", "dummy", "dummy");
+ fail("FAILS IN RI: [Xjava.lang.Void; is not a valid array");
+ }
+ catch (Throwable e)
+ {
+ checkThrowable(IllegalArgumentException.class, e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void testSerialization(String className, String type, String description) throws Exception
+ {
+ MetaType original = new MockMetaType(className, type, description);
+ byte[] bytes = serialize(original);
+ MetaType result = (MetaType) deserialize(bytes);
+ assertEquals(original.getClassName(), result.getClassName());
+ assertEquals(original.getTypeName(), result.getTypeName());
+ assertEquals(original.getDescription(), result.getDescription());
+ assertEquals(original.isArray(), result.isArray());
+ }
+
+ @SuppressWarnings("unchecked")
+ private void checkMetaType(List names, Class clazz) throws Exception
+ {
+ String name = clazz.getName();
+ assertTrue(name + " is a MetaType", names.contains(name));
+
+ new MockMetaType(name, "dummy", "dummy");
+
+ new MockMetaType("[L"+name+";", "dummy", "dummy");
+
+ new MockMetaType("[[[[[L"+name+";", "dummy", "dummy");
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,270 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.metatype.types.test;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Date;
-
-import junit.framework.Test;
-
-import org.jboss.metatype.api.types.Name;
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.metatype.plugins.types.StringName;
-import org.jboss.test.metatype.AbstractMetaTypeTest;
-
-/**
- * SimpleMetaTypeUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleMetaTypeUnitTestCase extends AbstractMetaTypeTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(SimpleMetaTypeUnitTestCase.class);
- }
-
- /**
- * Create a new SimpleMetaTypeUnitTestCase.
- *
- * @param name the test name
- */
- public SimpleMetaTypeUnitTestCase(String name)
- {
- super(name);
- }
-
- SimpleMetaType[] types = new SimpleMetaType[]
- {
- SimpleMetaType.BIGDECIMAL,
- SimpleMetaType.BIGINTEGER,
- SimpleMetaType.BOOLEAN,
- SimpleMetaType.BYTE,
- SimpleMetaType.CHARACTER,
- SimpleMetaType.DATE,
- SimpleMetaType.DOUBLE,
- SimpleMetaType.FLOAT,
- SimpleMetaType.INTEGER,
- SimpleMetaType.LONG,
- SimpleMetaType.SHORT,
- SimpleMetaType.STRING,
- SimpleMetaType.VOID,
- SimpleMetaType.NAMEDOBJECT
- };
-
- Class<?>[] classes = new Class[]
- {
- BigDecimal.class,
- BigInteger.class,
- Boolean.class,
- Byte.class,
- Character.class,
- Date.class,
- Double.class,
- Float.class,
- Integer.class,
- Long.class,
- Short.class,
- String.class,
- Void.class,
- Name.class
- };
-
- @SuppressWarnings("unchecked")
- SimpleValue[] values = new SimpleValue[]
- {
- new SimpleValueSupport(SimpleMetaType.BIGDECIMAL, new BigDecimal(1)),
- new SimpleValueSupport(SimpleMetaType.BIGINTEGER, BigInteger.ONE),
- new SimpleValueSupport(SimpleMetaType.BOOLEAN, new Boolean(false)),
- new SimpleValueSupport(SimpleMetaType.BYTE, new Byte(Byte.MAX_VALUE)),
- new SimpleValueSupport(SimpleMetaType.CHARACTER, new Character('a')),
- new SimpleValueSupport(SimpleMetaType.DATE, new Date(System.currentTimeMillis())),
- new SimpleValueSupport(SimpleMetaType.DOUBLE, new Double(1)),
- new SimpleValueSupport(SimpleMetaType.FLOAT, new Float(1)),
- new SimpleValueSupport(SimpleMetaType.INTEGER, new Integer(1)),
- new SimpleValueSupport(SimpleMetaType.LONG, new Long(1)),
- new SimpleValueSupport(SimpleMetaType.SHORT, new Short(Short.MAX_VALUE)),
- new SimpleValueSupport(SimpleMetaType.STRING, new String("hello")),
- new SimpleValueSupport(SimpleMetaType.VOID, null),
- new SimpleValueSupport(SimpleMetaType.NAMEDOBJECT, new StringName("objectref"))
- };
-
- @SuppressWarnings("unchecked")
- SimpleValue[] nullValues = new SimpleValue[]
- {
- new SimpleValueSupport(SimpleMetaType.BIGDECIMAL, null),
- new SimpleValueSupport(SimpleMetaType.BIGINTEGER, null),
- new SimpleValueSupport(SimpleMetaType.BOOLEAN, null),
- new SimpleValueSupport(SimpleMetaType.BYTE, null),
- new SimpleValueSupport(SimpleMetaType.CHARACTER, null),
- new SimpleValueSupport(SimpleMetaType.DATE, null),
- new SimpleValueSupport(SimpleMetaType.DOUBLE, null),
- new SimpleValueSupport(SimpleMetaType.FLOAT, null),
- new SimpleValueSupport(SimpleMetaType.INTEGER, null),
- new SimpleValueSupport(SimpleMetaType.LONG, null),
- new SimpleValueSupport(SimpleMetaType.SHORT, null),
- new SimpleValueSupport(SimpleMetaType.STRING, null),
- new SimpleValueSupport(SimpleMetaType.VOID, null),
- new SimpleValueSupport(SimpleMetaType.NAMEDOBJECT, null)
- };
-
- /**
- * Test the simple types
- *
- * @throws Exception for any problem
- */
- public void testSimpleTypes() throws Exception
- {
- for (int i = 0; i < types.length; i++)
- {
- String className = classes[i].getName();
- getLog().debug("SimpleMetaType: " + className + " className=" + types[i].getClassName() + " typeName=" + types[i].getTypeName() + " description=" + types[i].getDescription());
- assertEquals(className, types[i].getClassName());
- assertEquals(className, types[i].getTypeName());
- assertEquals(className, types[i].getDescription());
- }
- }
-
- /**
- * Test the equals
- *
- * @throws Exception for any problem
- */
- public void testEquals() throws Exception
- {
- for (int i = 0; i < types.length; i++)
- {
- for (int j = 0; j < types.length; j++)
- {
- boolean resultEquals = types[i].equals(types[j]);
- boolean resultReference = types[i] != types[j];
- getLog().debug("equals : " + types[i].getClassName() + " " + types[j] + " result=" + resultEquals);
- getLog().debug("equality: " + types[i].getClassName() + " " + types[j] + " result=" + resultReference);
- if (i == j)
- assertEquals("SimpleMetaTypes should be equal to itself " + classes[i], types[i], types[j]);
- else
- {
- assertNotSame("SimpleMetaTypes should be different under equality " + classes[i], types[i], types[j]);
- assertTrue("SimpleMetaTypes should be different under reference " + classes[i], types[i] != types[j]);
- }
- }
- }
- }
-
- /**
- * Test the isValue
- *
- * @throws Exception for any problem
- */
- public void testIsValue() throws Exception
- {
- for (int i = 0; i < types.length; ++i)
- {
- for (int j = 0; j < types.length; ++j)
- {
-
- // isValue makes no sense for Void
- if (values[i].getValue() == null)
- continue;
-
- boolean result = types[j].isValue(values[i]);
- getLog().debug("isValue: " + types[j].getClassName() + " value=" + values[i] + " result=" + result);
-
- if (i == j)
- {
- assertTrue(classes[i] + " should be a simple value of " + types[j], result);
- result = types[i].isValue(nullValues[j]);
- getLog().debug("isValue: " + types[i].getClassName() + " value=null value result=" + result);
- assertTrue(nullValues[j] + " should be a simple value of " + types[i], result);
- }
- else
- {
- assertFalse(classes[i] + " should NOT be a simple value of " + types[j], result);
- result = types[i].isValue(nullValues[j]);
- getLog().debug("isValue: " + types[i].getClassName() + " value=null value result=" + result);
- assertFalse(nullValues[j] + " should NOT be a simple value of " + types[i], result);
- }
- }
- }
- }
-
- /**
- * Test the hashCode
- *
- * @throws Exception for any problem
- */
- public void testHashCode() throws Exception
- {
- for (int i = 0; i < types.length; i++)
- {
- int classHashCode = classes[i].getName().hashCode();
- int typeHashCode = types[i].hashCode();
- getLog().debug("hashCode: " + types[i].getClassName() + " expected=" + classHashCode + " actual=" + typeHashCode);
- assertEquals(classHashCode, typeHashCode);
- }
- }
-
- /**
- * Test the toString
- *
- * @throws Exception for any problem
- */
- public void testToString() throws Exception
- {
- String smt = SimpleMetaType.class.getSimpleName();
- for (int i = 0; i < types.length; i++)
- {
- String className = classes[i].getName();
- String toString = types[i].toString();
- getLog().debug("toString: " + types[i].getClassName() + " value=" + toString);
- assertTrue("SimpleMetaType " + className + " should contain " + smt, toString.indexOf(smt) != -1);
- assertTrue("SimpleMetaType " + className + " should contain " + className, toString.indexOf(className) != -1);
- }
- }
-
- /**
- * Test the serialization
- *
- * @throws Exception for any problem
- */
- public void testSerialization() throws Exception
- {
- for (int i = 0; i < types.length; i++)
- {
- getLog().debug("serialization: " + types[i].getClassName() + " original=" + types[i]);
- byte[] bytes = serialize(types[i]);
- SimpleMetaType result = (SimpleMetaType) deserialize(bytes);
- getLog().debug("serialization: " + types[i].getClassName() + " result =" + types[i]);
-
- assertTrue("Should resolve to same object after serialization " + types[i], types[i] == result);
- }
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java (from rev 84826, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/types/test/SimpleMetaTypeUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,420 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metatype.types.test;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+
+import junit.framework.Test;
+
+import org.jboss.metatype.api.types.Name;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.types.StringName;
+import org.jboss.test.metatype.AbstractMetaTypeTest;
+
+/**
+ * SimpleMetaTypeUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleMetaTypeUnitTestCase extends AbstractMetaTypeTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(SimpleMetaTypeUnitTestCase.class);
+ }
+
+ /**
+ * Create a new SimpleMetaTypeUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public SimpleMetaTypeUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ SimpleMetaType[] types = new SimpleMetaType[]
+ {
+ SimpleMetaType.BIGDECIMAL,
+ SimpleMetaType.BIGINTEGER,
+ SimpleMetaType.BOOLEAN,
+ SimpleMetaType.BYTE,
+ SimpleMetaType.CHARACTER,
+ SimpleMetaType.DATE,
+ SimpleMetaType.DOUBLE,
+ SimpleMetaType.FLOAT,
+ SimpleMetaType.INTEGER,
+ SimpleMetaType.LONG,
+ SimpleMetaType.SHORT,
+ SimpleMetaType.STRING,
+ SimpleMetaType.VOID,
+ SimpleMetaType.NAMEDOBJECT
+ };
+
+ Class<?>[] classes = new Class[]
+ {
+ BigDecimal.class,
+ BigInteger.class,
+ Boolean.class,
+ Byte.class,
+ Character.class,
+ Date.class,
+ Double.class,
+ Float.class,
+ Integer.class,
+ Long.class,
+ Short.class,
+ String.class,
+ Void.class,
+ Name.class
+ };
+
+ @SuppressWarnings("unchecked")
+ SimpleValue[] values = new SimpleValue[]
+ {
+ new SimpleValueSupport(SimpleMetaType.BIGDECIMAL, new BigDecimal(1)),
+ new SimpleValueSupport(SimpleMetaType.BIGINTEGER, BigInteger.ONE),
+ new SimpleValueSupport(SimpleMetaType.BOOLEAN, new Boolean(false)),
+ new SimpleValueSupport(SimpleMetaType.BYTE, new Byte(Byte.MAX_VALUE)),
+ new SimpleValueSupport(SimpleMetaType.CHARACTER, new Character('a')),
+ new SimpleValueSupport(SimpleMetaType.DATE, new Date(System.currentTimeMillis())),
+ new SimpleValueSupport(SimpleMetaType.DOUBLE, new Double(1)),
+ new SimpleValueSupport(SimpleMetaType.FLOAT, new Float(1)),
+ new SimpleValueSupport(SimpleMetaType.INTEGER, new Integer(1)),
+ new SimpleValueSupport(SimpleMetaType.LONG, new Long(1)),
+ new SimpleValueSupport(SimpleMetaType.SHORT, new Short(Short.MAX_VALUE)),
+ new SimpleValueSupport(SimpleMetaType.STRING, new String("hello")),
+ new SimpleValueSupport(SimpleMetaType.VOID, null),
+ new SimpleValueSupport(SimpleMetaType.NAMEDOBJECT, new StringName("objectref"))
+ };
+
+ @SuppressWarnings("unchecked")
+ SimpleValue[] nullValues = new SimpleValue[]
+ {
+ new SimpleValueSupport(SimpleMetaType.BIGDECIMAL, null),
+ new SimpleValueSupport(SimpleMetaType.BIGINTEGER, null),
+ new SimpleValueSupport(SimpleMetaType.BOOLEAN, null),
+ new SimpleValueSupport(SimpleMetaType.BYTE, null),
+ new SimpleValueSupport(SimpleMetaType.CHARACTER, null),
+ new SimpleValueSupport(SimpleMetaType.DATE, null),
+ new SimpleValueSupport(SimpleMetaType.DOUBLE, null),
+ new SimpleValueSupport(SimpleMetaType.FLOAT, null),
+ new SimpleValueSupport(SimpleMetaType.INTEGER, null),
+ new SimpleValueSupport(SimpleMetaType.LONG, null),
+ new SimpleValueSupport(SimpleMetaType.SHORT, null),
+ new SimpleValueSupport(SimpleMetaType.STRING, null),
+ new SimpleValueSupport(SimpleMetaType.VOID, null),
+ new SimpleValueSupport(SimpleMetaType.NAMEDOBJECT, null)
+ };
+
+ /**
+ * Test the simple types
+ *
+ * @throws Exception for any problem
+ */
+ public void testSimpleTypes() throws Exception
+ {
+ for (int i = 0; i < types.length; i++)
+ {
+ String className = classes[i].getName();
+ getLog().debug("SimpleMetaType: " + className + " className=" + types[i].getClassName() + " typeName=" + types[i].getTypeName() + " description=" + types[i].getDescription());
+ assertEquals(className, types[i].getClassName());
+ assertEquals(className, types[i].getTypeName());
+ assertEquals(className, types[i].getDescription());
+ }
+ }
+
+ /**
+ * Test the equals
+ *
+ * @throws Exception for any problem
+ */
+ public void testEquals() throws Exception
+ {
+ for (int i = 0; i < types.length; i++)
+ {
+ for (int j = 0; j < types.length; j++)
+ {
+ boolean resultEquals = types[i].equals(types[j]);
+ boolean resultReference = types[i] != types[j];
+ getLog().debug("equals : " + types[i].getClassName() + " " + types[j] + " result=" + resultEquals);
+ getLog().debug("equality: " + types[i].getClassName() + " " + types[j] + " result=" + resultReference);
+ if (i == j)
+ assertEquals("SimpleMetaTypes should be equal to itself " + classes[i], types[i], types[j]);
+ else
+ {
+ assertNotSame("SimpleMetaTypes should be different under equality " + classes[i], types[i], types[j]);
+ assertTrue("SimpleMetaTypes should be different under reference " + classes[i], types[i] != types[j]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Test the isValue
+ *
+ * @throws Exception for any problem
+ */
+ public void testIsValue() throws Exception
+ {
+ for (int i = 0; i < types.length; ++i)
+ {
+ for (int j = 0; j < types.length; ++j)
+ {
+
+ // isValue makes no sense for Void
+ if (values[i].getValue() == null)
+ continue;
+
+ boolean result = types[j].isValue(values[i]);
+ getLog().debug("isValue: " + types[j].getClassName() + " value=" + values[i] + " result=" + result);
+
+ if (i == j)
+ {
+ assertTrue(classes[i] + " should be a simple value of " + types[j], result);
+ result = types[i].isValue(nullValues[j]);
+ getLog().debug("isValue: " + types[i].getClassName() + " value=null value result=" + result);
+ assertTrue(nullValues[j] + " should be a simple value of " + types[i], result);
+ }
+ else
+ {
+ assertFalse(classes[i] + " should NOT be a simple value of " + types[j], result);
+ result = types[i].isValue(nullValues[j]);
+ getLog().debug("isValue: " + types[i].getClassName() + " value=null value result=" + result);
+ assertFalse(nullValues[j] + " should NOT be a simple value of " + types[i], result);
+ }
+ }
+ }
+ }
+
+ /**
+ * Test the hashCode
+ *
+ * @throws Exception for any problem
+ */
+ public void testHashCode() throws Exception
+ {
+ for (int i = 0; i < types.length; i++)
+ {
+ int classHashCode = classes[i].getName().hashCode();
+ int typeHashCode = types[i].hashCode();
+ getLog().debug("hashCode: " + types[i].getClassName() + " expected=" + classHashCode + " actual=" + typeHashCode);
+ assertEquals(classHashCode, typeHashCode);
+ }
+ }
+
+ /**
+ * Test the toString
+ *
+ * @throws Exception for any problem
+ */
+ public void testToString() throws Exception
+ {
+ String smt = SimpleMetaType.class.getSimpleName();
+ for (int i = 0; i < types.length; i++)
+ {
+ String className = classes[i].getName();
+ String toString = types[i].toString();
+ getLog().debug("toString: " + types[i].getClassName() + " value=" + toString);
+ assertTrue("SimpleMetaType " + className + " should contain " + smt, toString.indexOf(smt) != -1);
+ assertTrue("SimpleMetaType " + className + " should contain " + className, toString.indexOf(className) != -1);
+ }
+ }
+
+ /**
+ * Test the serialization
+ *
+ * @throws Exception for any problem
+ */
+ public void testSerialization() throws Exception
+ {
+ for (int i = 0; i < types.length; i++)
+ {
+ getLog().debug("serialization: " + types[i].getClassName() + " original=" + types[i]);
+ byte[] bytes = serialize(types[i]);
+ SimpleMetaType result = (SimpleMetaType) deserialize(bytes);
+ getLog().debug("serialization: " + types[i].getClassName() + " result =" + types[i]);
+
+ assertTrue("Should resolve to same object after serialization " + types[i], types[i] == result);
+ }
+ }
+
+ public void testBytePrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.BYTE_PRIMITIVE, SimpleMetaType.isSimpleType(byte.class.getName()));
+ SimpleMetaType byteType = SimpleMetaType.resolve("byte");
+ assertNotNull(byteType);
+ assertEquals(SimpleMetaType.BYTE_PRIMITIVE, byteType);
+ assertTrue(byteType.isPrimitive());
+ Serializable one = (byte) 1;
+ log.debug("one.class: "+one.getClass());
+ SimpleValue byte1p = SimpleValueSupport.wrap((byte)1);
+ SimpleValue byte1p2 = SimpleValueSupport.wrap((byte)1);
+ assertEquals(SimpleMetaType.BYTE_PRIMITIVE, byte1p.getMetaType());
+ SimpleValue byte1 = SimpleValueSupport.wrap(one);
+ assertEquals(SimpleMetaType.BYTE, byte1.getMetaType());
+ assertEquals(byte1, byte1p);
+ assertEquals(byte1p, byte1p2);
+
+ SimpleValue byte2p = SimpleValueSupport.wrap((byte)2);
+ assertFalse(byte1p.equals(byte2p));
+ }
+ public void testShortPrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.SHORT_PRIMITIVE, SimpleMetaType.isSimpleType(short.class.getName()));
+ SimpleMetaType shortType = SimpleMetaType.resolve("short");
+ assertNotNull(shortType);
+ assertEquals(SimpleMetaType.SHORT_PRIMITIVE, shortType);
+ assertTrue(shortType.isPrimitive());
+ Serializable one = (short) 1;
+ log.debug("one.class: "+one.getClass());
+ SimpleValue short1p = SimpleValueSupport.wrap((short)1);
+ SimpleValue short1p2 = SimpleValueSupport.wrap((short)1);
+ assertEquals(SimpleMetaType.SHORT_PRIMITIVE, short1p.getMetaType());
+ SimpleValue short1 = SimpleValueSupport.wrap(one);
+ assertEquals(SimpleMetaType.SHORT, short1.getMetaType());
+ assertEquals(short1, short1p);
+ assertEquals(short1p, short1p2);
+
+ SimpleValue short2p = SimpleValueSupport.wrap((short)2);
+ assertFalse(short1p.equals(short2p));
+ }
+ public void testIntPrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.INTEGER_PRIMITIVE, SimpleMetaType.isSimpleType(int.class.getName()));
+ SimpleMetaType intType = SimpleMetaType.resolve("int");
+ assertNotNull(intType);
+ assertEquals(SimpleMetaType.INTEGER_PRIMITIVE, intType);
+ assertTrue(intType.isPrimitive());
+ Serializable one = (int) 1;
+ log.debug("one.class: "+one.getClass());
+ SimpleValue int1p = SimpleValueSupport.wrap((int)1);
+ SimpleValue int1p2 = SimpleValueSupport.wrap((int)1);
+ assertEquals(SimpleMetaType.INTEGER_PRIMITIVE, int1p.getMetaType());
+ SimpleValue int1 = SimpleValueSupport.wrap(one);
+ assertEquals(SimpleMetaType.INTEGER, int1.getMetaType());
+ assertEquals(int1, int1p);
+ assertEquals(int1p, int1p2);
+
+ SimpleValue int2p = SimpleValueSupport.wrap((int)2);
+ assertFalse(int1p.equals(int2p));
+ }
+ public void testLongPrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.LONG_PRIMITIVE, SimpleMetaType.isSimpleType(long.class.getName()));
+ SimpleMetaType longType = SimpleMetaType.resolve("long");
+ assertNotNull(longType);
+ assertEquals(SimpleMetaType.LONG_PRIMITIVE, longType);
+ assertTrue(longType.isPrimitive());
+ Serializable one = (long) 1;
+ log.debug("one.class: "+one.getClass());
+ SimpleValue long1p = SimpleValueSupport.wrap((long)1);
+ SimpleValue long1p2 = SimpleValueSupport.wrap((long)1);
+ assertEquals(SimpleMetaType.LONG_PRIMITIVE, long1p.getMetaType());
+ SimpleValue long1 = SimpleValueSupport.wrap(one);
+ assertEquals(SimpleMetaType.LONG, long1.getMetaType());
+ assertEquals(long1, long1p);
+ assertEquals(long1p, long1p2);
+
+ SimpleValue long2p = SimpleValueSupport.wrap((long)2);
+ assertFalse(long1p.equals(long2p));
+ }
+ public void testFloatPrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.FLOAT_PRIMITIVE, SimpleMetaType.isSimpleType(float.class.getName()));
+ SimpleMetaType floatType = SimpleMetaType.resolve("float");
+ assertNotNull(floatType);
+ assertTrue(SimpleMetaType.FLOAT_PRIMITIVE == floatType);
+ assertEquals(SimpleMetaType.FLOAT_PRIMITIVE, floatType);
+ assertTrue(floatType.isPrimitive());
+ Serializable pi = 3.14f;
+ log.debug("pi.class: "+pi.getClass());
+ SimpleValue float1p = SimpleValueSupport.wrap(3.14f);
+ SimpleValue float1p2 = SimpleValueSupport.wrap(3.14f);
+ assertEquals(SimpleMetaType.FLOAT_PRIMITIVE, float1p.getMetaType());
+ SimpleValue float1 = SimpleValueSupport.wrap(pi);
+ assertEquals(SimpleMetaType.FLOAT, float1.getMetaType());
+ assertEquals(float1, float1p);
+ assertEquals(float1p, float1p2);
+
+ SimpleValue float2p = SimpleValueSupport.wrap(3.24f);
+ assertFalse(float1p.equals(float2p));
+ }
+ public void testDoublePrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.DOUBLE_PRIMITIVE, SimpleMetaType.isSimpleType(double.class.getName()));
+ SimpleMetaType doubleType = SimpleMetaType.resolve("double");
+ assertNotNull(doubleType);
+ assertEquals(SimpleMetaType.DOUBLE_PRIMITIVE, doubleType);
+ assertTrue(doubleType.isPrimitive());
+ Serializable pi = 3.14;
+ log.debug("pi.class: "+pi.getClass());
+ SimpleValue double1p = SimpleValueSupport.wrap(3.14);
+ SimpleValue double1p2 = SimpleValueSupport.wrap(3.14);
+ assertEquals(SimpleMetaType.DOUBLE_PRIMITIVE, double1p.getMetaType());
+ SimpleValue double1 = SimpleValueSupport.wrap(pi);
+ assertEquals(SimpleMetaType.DOUBLE, double1.getMetaType());
+ assertEquals(double1, double1p);
+ assertEquals(double1p, double1p2);
+
+ SimpleValue double2p = SimpleValueSupport.wrap(3.24);
+ assertFalse(double1p.equals(double2p));
+ }
+ public void testBooleanPrimitives()
+ throws Exception
+ {
+ assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, SimpleMetaType.isSimpleType(boolean.class.getName()));
+ SimpleMetaType booleanType = SimpleMetaType.resolve("boolean");
+ assertNotNull(booleanType);
+ assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, booleanType);
+ assertTrue(booleanType.isPrimitive());
+ Serializable b = true;;
+ log.debug("b.class: "+b.getClass());
+ SimpleValue boolean1p = SimpleValueSupport.wrap(true);
+ SimpleValue boolean1p2 = SimpleValueSupport.wrap(true);
+ assertEquals(SimpleMetaType.BOOLEAN_PRIMITIVE, boolean1p.getMetaType());
+ SimpleValue boolean1 = SimpleValueSupport.wrap(b);
+ assertEquals(SimpleMetaType.BOOLEAN, boolean1.getMetaType());
+ assertEquals(boolean1, boolean1p);
+ assertEquals(boolean1p, boolean1p2);
+
+ SimpleValue boolean2p = SimpleValueSupport.wrap(false);
+ assertFalse(boolean1p.equals(boolean2p));
+ }
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java
===================================================================
--- projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,252 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.metatype.values.factory.test;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Type;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import junit.framework.Test;
-
-import org.jboss.metatype.api.types.SimpleMetaType;
-import org.jboss.metatype.api.values.CompositeValue;
-import org.jboss.metatype.api.values.CompositeValueSupport;
-import org.jboss.metatype.api.values.MapCompositeValueSupport;
-import org.jboss.metatype.api.values.MetaValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
-import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
-import org.jboss.test.metatype.types.support.MetaMappingUsage;
-import org.jboss.test.metatype.values.factory.support.AbstractPropertyMetaData;
-import org.jboss.test.metatype.values.factory.support.TestIgnoredCompositeItem;
-import org.jboss.test.metatype.values.factory.support.TestRecursiveComposite;
-import org.jboss.test.metatype.values.factory.support.TestRenamedCompositeItem;
-import org.jboss.test.metatype.values.factory.support.TestSimpleComposite;
-
-/**
- * CompositeValueFactoryUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class CompositeValueFactoryUnitTestCase extends AbstractMetaValueFactoryTest
-{
- /**
- * Create a testsuite for this test
- *
- * @return the testsuite
- */
- public static Test suite()
- {
- return suite(CompositeValueFactoryUnitTestCase.class);
- }
-
- /**
- * Create a new CompositeValueFactoryUnitTestCase.
- *
- * @param name the test name
- */
- public CompositeValueFactoryUnitTestCase(String name)
- {
- super(name);
- }
-
- /**
- * Test the correct value is generated for a simple composite
- *
- * @throws Exception for any problem
- */
- public void testSimpleComposite() throws Exception
- {
- MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestSimpleComposite.class.getName(), TestSimpleComposite.class.getName());
- compositeType.addItem("something", "something", SimpleMetaType.STRING);
- compositeType.freeze();
-
- String[] compositeNames = { "something" };
- CompositeValue expected = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Hello") });
-
- MetaValue result = createMetaValue(new TestSimpleComposite("Hello"));
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- /**
- * Test the correct value is generated for a recursive composite
- *
- * @throws Exception for any problem
- */
- public void testRecursiveComposite() throws Exception
- {
- MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestRecursiveComposite.class.getName(), TestRecursiveComposite.class.getName());
- compositeType.addItem("id", "id", SimpleMetaType.STRING);
- compositeType.addItem("other", "other", compositeType);
- Set<String> keys = Collections.singleton("id");
- compositeType.setKeys(keys);
- compositeType.freeze();
-
- CompositeValueSupport expected = new CompositeValueSupport(compositeType);
- expected.set("id", SimpleValueSupport.wrap("Hello"));
- expected.set("other", expected);
-
- TestRecursiveComposite object = new TestRecursiveComposite("Hello");
- object.setOther(object);
- MetaValue result = createMetaValue(object);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- public void testIgnoreItem() throws Exception
- {
- MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestIgnoredCompositeItem.class.getName(), TestIgnoredCompositeItem.class.getName());
- compositeType.addItem("id", "id", SimpleMetaType.STRING);
- Set<String> keys = Collections.singleton("id");
- compositeType.setKeys(keys);
- compositeType.freeze();
-
- CompositeValueSupport expected = new CompositeValueSupport(compositeType);
- expected.set("id", SimpleValueSupport.wrap("Hello"));
-
- TestIgnoredCompositeItem object = new TestIgnoredCompositeItem();
- object.setId("Hello");
- object.setIgnored("Ignored?");
- MetaValue result = createMetaValue(object);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- public void testRenameItem() throws Exception
- {
- MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestRenamedCompositeItem.class.getName(), TestRenamedCompositeItem.class.getName());
- compositeType.addItem("id", "id", SimpleMetaType.STRING);
- compositeType.addItem("renamed", "renamed", SimpleMetaType.STRING);
- Set<String> keys = Collections.singleton("id");
- compositeType.setKeys(keys);
- compositeType.freeze();
-
- CompositeValueSupport expected = new CompositeValueSupport(compositeType);
- expected.set("id", SimpleValueSupport.wrap("Hello"));
- expected.set("renamed", SimpleValueSupport.wrap("Renamed"));
-
- TestRenamedCompositeItem object = new TestRenamedCompositeItem();
- object.setId("Hello");
- object.setValue("Renamed");
- MetaValue result = createMetaValue(object);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- public HashMap<String, String> compositeSignature;
- /**
- * JBMICROCONT-238, Map<String,?> should map to a MapCompositeValueSupport(MetaValue<?>)
- * @throws Exception
- */
- public void testMapWithStringKeyComposite() throws Exception
- {
- Field field = getClass().getField("compositeSignature");
- Type mapSignature = field.getGenericType();
-
- Map<String, String> values = new HashMap<String, String>();
- values.put("key1", "value1");
- values.put("key2", "value2");
- values.put("key3", "value3");
- MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
- expected.put("key1", SimpleValueSupport.wrap("value1"));
- expected.put("key2", SimpleValueSupport.wrap("value2"));
- expected.put("key3", SimpleValueSupport.wrap("value3"));
- MetaValue result = createMetaValue(values, mapSignature);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
-
- }
- /**
- * JBMICROCONT-238, java.util.Properties should map to a MapCompositeValueSupport(MetaValue<String>)
- * @throws Exception
- */
- public void testPropertiesComposite()
- throws Exception
- {
- Type propertiesType = Properties.class;
-
- Properties values = new Properties();
- values.put("key1", "value1");
- values.put("key2", "value2");
- values.put("key3", "value3");
-
- MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
- expected.put("key1", SimpleValueSupport.wrap("value1"));
- expected.put("key2", SimpleValueSupport.wrap("value2"));
- expected.put("key3", SimpleValueSupport.wrap("value3"));
- MetaValue result = createMetaValue(values, propertiesType);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- /**
- * A test of the MetaMapping annotation controlling the MetaType of a Type
- */
- public void testMetaMappingComposite()
- throws Exception
- {
- Type type = MetaMappingUsage.class;
- MetaMappingUsage values = new MetaMappingUsage();
- values.setName("testMetaMappingComposite");
- values.setType("java.lang.String");
- values.setValue("testMetaMappingComposite-value");
-
- MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
- expected.put("name", SimpleValueSupport.wrap("testMetaMappingComposite"));
- expected.put("type", SimpleValueSupport.wrap("java.lang.String"));
- expected.put("value", SimpleValueSupport.wrap("testMetaMappingComposite-value"));
-
- MetaValue result = createMetaValue(values, type);
- CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
- getLog().debug("Composite Value: " + actual);
- assertEquals(expected, actual);
- }
-
- /**
- * JBMAN-50 DefaultMetaValueFactory.createCompositeValue Property is not
- * readable test.
- */
- public void testMutableCompositeMetaValue()
- throws Exception
- {
- AbstractPropertyMetaData apmd = new AbstractPropertyMetaData();
- MetaValue mv = createMetaValue(apmd);
- assertNotNull(mv);
- assertTrue(mv instanceof CompositeValue);
- CompositeValue cmv = CompositeValue.class.cast(mv);
- assertTrue("CV contains name", cmv.containsKey("name"));
- assertTrue("CV contains propertyTrim", cmv.containsKey("propertyTrim"));
- assertTrue("CV contains propertyReplace", cmv.containsKey("propertyReplace"));
- assertTrue("CV contains type", cmv.containsKey("type"));
- }
-}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java (from rev 84841, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/CompositeValueFactoryUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,278 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.metatype.values.factory.test;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.metatype.plugins.types.MutableCompositeMetaType;
+import org.jboss.test.metatype.types.support.MetaMappingUsage;
+import org.jboss.test.metatype.values.factory.support.AbstractPropertyMetaData;
+import org.jboss.test.metatype.values.factory.support.TestIgnoredCompositeItem;
+import org.jboss.test.metatype.values.factory.support.TestRecursiveComposite;
+import org.jboss.test.metatype.values.factory.support.TestRenamedCompositeItem;
+import org.jboss.test.metatype.values.factory.support.TestSimpleComposite;
+
+/**
+ * CompositeValueFactoryUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class CompositeValueFactoryUnitTestCase extends AbstractMetaValueFactoryTest
+{
+ /**
+ * Create a testsuite for this test
+ *
+ * @return the testsuite
+ */
+ public static Test suite()
+ {
+ return suite(CompositeValueFactoryUnitTestCase.class);
+ }
+
+ /**
+ * Create a new CompositeValueFactoryUnitTestCase.
+ *
+ * @param name the test name
+ */
+ public CompositeValueFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test the correct value is generated for a simple composite
+ *
+ * @throws Exception for any problem
+ */
+ public void testSimpleComposite() throws Exception
+ {
+ MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestSimpleComposite.class.getName(), TestSimpleComposite.class.getName());
+ compositeType.addItem("something", "something", SimpleMetaType.STRING);
+ compositeType.freeze();
+
+ String[] compositeNames = { "something" };
+ CompositeValue expected = new CompositeValueSupport(compositeType, compositeNames, new MetaValue[] { SimpleValueSupport.wrap("Hello") });
+
+ MetaValue result = createMetaValue(new TestSimpleComposite("Hello"));
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * Test the correct value is generated for a recursive composite
+ *
+ * @throws Exception for any problem
+ */
+ public void testRecursiveComposite() throws Exception
+ {
+ MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestRecursiveComposite.class.getName(), TestRecursiveComposite.class.getName());
+ compositeType.addItem("id", "id", SimpleMetaType.STRING);
+ compositeType.addItem("other", "other", compositeType);
+ Set<String> keys = Collections.singleton("id");
+ compositeType.setKeys(keys);
+ compositeType.freeze();
+
+ CompositeValueSupport expected = new CompositeValueSupport(compositeType);
+ expected.set("id", SimpleValueSupport.wrap("Hello"));
+ expected.set("other", expected);
+
+ TestRecursiveComposite object = new TestRecursiveComposite("Hello");
+ object.setOther(object);
+ MetaValue result = createMetaValue(object);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ public void testIgnoreItem() throws Exception
+ {
+ MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestIgnoredCompositeItem.class.getName(), TestIgnoredCompositeItem.class.getName());
+ compositeType.addItem("id", "id", SimpleMetaType.STRING);
+ Set<String> keys = Collections.singleton("id");
+ compositeType.setKeys(keys);
+ compositeType.freeze();
+
+ CompositeValueSupport expected = new CompositeValueSupport(compositeType);
+ expected.set("id", SimpleValueSupport.wrap("Hello"));
+
+ TestIgnoredCompositeItem object = new TestIgnoredCompositeItem();
+ object.setId("Hello");
+ object.setIgnored("Ignored?");
+ MetaValue result = createMetaValue(object);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ public void testRenameItem() throws Exception
+ {
+ MutableCompositeMetaType compositeType = new MutableCompositeMetaType(TestRenamedCompositeItem.class.getName(), TestRenamedCompositeItem.class.getName());
+ compositeType.addItem("id", "id", SimpleMetaType.STRING);
+ compositeType.addItem("renamed", "renamed", SimpleMetaType.STRING);
+ Set<String> keys = Collections.singleton("id");
+ compositeType.setKeys(keys);
+ compositeType.freeze();
+
+ CompositeValueSupport expected = new CompositeValueSupport(compositeType);
+ expected.set("id", SimpleValueSupport.wrap("Hello"));
+ expected.set("renamed", SimpleValueSupport.wrap("Renamed"));
+
+ TestRenamedCompositeItem object = new TestRenamedCompositeItem();
+ object.setId("Hello");
+ object.setValue("Renamed");
+ MetaValue result = createMetaValue(object);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ public HashMap<String, String> compositeSignature;
+ /**
+ * JBMICROCONT-238, Map<String,?> should map to a MapCompositeValueSupport(MetaValue<?>)
+ * @throws Exception
+ */
+ public void testMapWithStringKeyComposite() throws Exception
+ {
+ Field field = getClass().getField("compositeSignature");
+ Type mapSignature = field.getGenericType();
+
+ Map<String, String> values = new HashMap<String, String>();
+ values.put("key1", "value1");
+ values.put("key2", "value2");
+ values.put("key3", "value3");
+ MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ expected.put("key1", SimpleValueSupport.wrap("value1"));
+ expected.put("key2", SimpleValueSupport.wrap("value2"));
+ expected.put("key3", SimpleValueSupport.wrap("value3"));
+ MetaValue result = createMetaValue(values, mapSignature);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+
+ }
+ /**
+ * JBMICROCONT-238, java.util.Properties should map to a MapCompositeValueSupport(MetaValue<String>)
+ * @throws Exception
+ */
+ public void testPropertiesComposite()
+ throws Exception
+ {
+ Type propertiesType = Properties.class;
+
+ Properties values = new Properties();
+ values.put("key1", "value1");
+ values.put("key2", "value2");
+ values.put("key3", "value3");
+
+ MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ expected.put("key1", SimpleValueSupport.wrap("value1"));
+ expected.put("key2", SimpleValueSupport.wrap("value2"));
+ expected.put("key3", SimpleValueSupport.wrap("value3"));
+ MetaValue result = createMetaValue(values, propertiesType);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * A test of the MetaMapping annotation controlling the MetaType of a Type
+ */
+ public void testMetaMappingComposite()
+ throws Exception
+ {
+ Type type = MetaMappingUsage.class;
+ MetaMappingUsage values = new MetaMappingUsage();
+ values.setName("testMetaMappingComposite");
+ values.setType("java.lang.String");
+ values.setValue("testMetaMappingComposite-value");
+
+ MapCompositeValueSupport expected = new MapCompositeValueSupport(SimpleMetaType.STRING);
+ expected.put("name", SimpleValueSupport.wrap("testMetaMappingComposite"));
+ expected.put("type", SimpleValueSupport.wrap("java.lang.String"));
+ expected.put("value", SimpleValueSupport.wrap("testMetaMappingComposite-value"));
+
+ MetaValue result = createMetaValue(values, type);
+ CompositeValue actual = assertInstanceOf(result, CompositeValue.class);
+ getLog().debug("Composite Value: " + actual);
+ assertEquals(expected, actual);
+ }
+
+ /**
+ * JBMAN-50 DefaultMetaValueFactory.createCompositeValue Property is not
+ * readable test.
+ */
+ public void testMutableCompositeMetaValue()
+ throws Exception
+ {
+ AbstractPropertyMetaData apmd = new AbstractPropertyMetaData();
+ MetaValue mv = createMetaValue(apmd);
+ assertNotNull(mv);
+ assertTrue(mv instanceof CompositeValue);
+ CompositeValue cmv = CompositeValue.class.cast(mv);
+ assertTrue("CV contains name", cmv.containsKey("name"));
+ assertTrue("CV contains propertyTrim", cmv.containsKey("propertyTrim"));
+ assertTrue("CV contains propertyReplace", cmv.containsKey("propertyReplace"));
+ assertTrue("CV contains type", cmv.containsKey("type"));
+ }
+
+ /**
+ * JBMAN-61, validate proxy for MapCompositeValue unwrapping intercepts the
+ * Map.get(key) calls.
+ */
+ public void testMapCompositeValueProxy()
+ {
+ Properties props = System.getProperties();
+ log.debug(props);
+ // Convert to MetaValue
+ MetaValue propsMV = createMetaValue(props);
+ assertNotNull(propsMV);
+ assertTrue(propsMV instanceof CompositeValue);
+ // Unwrap to excercise the proxy via a Map interface
+ Map map = (Map) unwrapMetaValue(propsMV);
+ assertEquals(props.size(), map.size());
+ assertEquals(props.getProperty("java.runtime.name"), map.get("java.runtime.name"));
+ assertEquals(props.getProperty("java.library.path"), map.get("java.library.path"));
+ assertTrue("java.runtime.name", map.containsKey("java.runtime.name"));
+ assertTrue("java.runtime.name", map.containsValue(props.getProperty("java.runtime.name")));
+ assertFalse(map.isEmpty());
+ assertEquals(map.keySet(), props.keySet());
+ map.put("testMapCompositeValueProxy", "testMapCompositeValueProxy-value");
+ assertTrue("testMapCompositeValueProxy", map.containsKey("java.runtime.name"));
+ assertEquals("testMapCompositeValueProxy-value", map.get("testMapCompositeValueProxy"));
+ }
+}
Copied: projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java (from rev 85721, projects/jboss-man/branches/Branch_2_1/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/metatype/src/test/java/org/jboss/test/metatype/values/factory/test/ObjectNameUnitTestCase.java 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,96 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.metatype.values.factory.test;
+
+import java.util.Hashtable;
+
+import javax.management.ObjectName;
+
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.PropertiesMetaValue;
+
+/**
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class ObjectNameUnitTestCase extends AbstractMetaValueFactoryTest
+{
+
+ public ObjectNameUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Test ObjectName(String, Hashtable)
+ * @throws Exception
+ */
+ public void testObjectNameMVCreation()
+ throws Exception
+ {
+ Hashtable keys = new Hashtable();
+ keys.put("key1", "value1");
+ keys.put("key1", "value1");
+ ObjectName on = new ObjectName("testObjectNameMVCreation", keys);
+ MetaValue mv = super.createMetaValue(on);
+ log.debug(mv);
+ assertTrue("is a CompositeValue", mv instanceof CompositeValue);
+
+ CompositeValue cv = (CompositeValue) mv;
+ MetaValue domainMV = cv.get("domain");
+ assertNotNull(domainMV);
+ assertTrue("domain is a STRING", domainMV.getMetaType() == SimpleMetaType.STRING);
+ MetaValue keyPropertyList = cv.get("keyPropertyList");
+ assertNotNull(keyPropertyList);
+ assertTrue("keyPropertyList is a Properties", keyPropertyList instanceof PropertiesMetaValue);
+
+ ObjectName on2 = (ObjectName) super.unwrapMetaValue(mv);
+ assertEquals(on, on2);
+ }
+ /**
+ * Test ObjectName(String)
+ * @throws Exception
+ */
+ public void testObjectNameMVCreation2()
+ throws Exception
+ {
+ ObjectName on = new ObjectName("testObjectNameMVCreation2:key1=value1,key2=value2");
+ MetaValue mv = super.createMetaValue(on);
+ log.debug(mv);
+ assertTrue("is a CompositeValue", mv instanceof CompositeValue);
+
+ CompositeValue cv = (CompositeValue) mv;
+ MetaValue domainMV = cv.get("domain");
+ assertNotNull(domainMV);
+ assertTrue("domain is a STRING", domainMV.getMetaType() == SimpleMetaType.STRING);
+ MetaValue keyPropertyList = cv.get("keyPropertyList");
+ assertNotNull(keyPropertyList);
+ assertTrue("keyPropertyList is a Properties", keyPropertyList instanceof PropertiesMetaValue);
+
+ ObjectName on2 = (ObjectName) super.unwrapMetaValue(mv);
+ assertEquals(on, on2);
+ }
+
+
+}
Deleted: projects/jboss-man/tags/2.1.0.CR4/pom.xml
===================================================================
--- projects/jboss-man/branches/Branch_2_1/pom.xml 2009-02-18 15:53:39 UTC (rev 84388)
+++ projects/jboss-man/tags/2.1.0.CR4/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -1,250 +0,0 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-parent</artifactId>
- <version>4</version>
- </parent>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-man-parent</artifactId>
- <version>2.1.0-SNAPSHOT</version>
- <packaging>pom</packaging>
- <name>JBoss Managed Parent POM</name>
- <url>http://www.jboss.org/jbossmc</url>
- <description>JBoss Managed Parent POM</description>
- <scm>
- <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-man/branches/</connection>
- <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-man/branches/</developerConnection>
- <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/jboss-man/trunk/</url>
- </scm>
-
- <properties>
- <version.jboss.common.core>2.2.10.GA</version.jboss.common.core>
- <version.jboss.common.logging.spi>2.0.5.GA</version.jboss.common.logging.spi>
- <version.jboss.common.logging.log4j>2.0.5.GA</version.jboss.common.logging.log4j>
- <version.org.jboss.reflect>2.0.2.GA</version.org.jboss.reflect>
- <version.org.jboss.mdr>2.0.1.GA</version.org.jboss.mdr>
- <version.org.jboss.test>1.1.3.GA</version.org.jboss.test>
- <version.junit>4.4</version.junit>
- <version.sun.jaxb>2.1.4</version.sun.jaxb>
- <version.javassist>3.9.0.GA</version.javassist>
- </properties>
-
- <modules>
- <module>metatype</module>
- <module>managed</module>
- <module>build</module>
- </modules>
-
- <build>
- <outputDirectory>${microcontainer.outputDirectory}</outputDirectory>
- <testOutputDirectory>${microcontainer.testOutputDirectory}</testOutputDirectory>
- <finalName>${artifactId}</finalName>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.0.2</version>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- <showDeprecation>true</showDeprecation>
- <showWarnings>true</showWarnings>
- <optimize>true</optimize>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-release-plugin</artifactId>
- <version>2.0-beta-7</version>
- <configuration>
- <tagBase>https://svn.jboss.org/repos/jbossas/projects/jboss-man/tags</tagBase>
- <autoVersionSubmodules>true</autoVersionSubmodules>
- </configuration>
- </plugin>
- </plugins>
-
- <pluginManagement>
- <plugins>
- <plugin>
- <artifactId>maven-idea-plugin</artifactId>
- <configuration>
- <downloadSources>true</downloadSources>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.2</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <version>2.4.2</version>
- <configuration>
- <redirectTestOutputToFile>true</redirectTestOutputToFile>
- <includes>
- <include>org/jboss/test/**/*TestCase.java</include>
- </includes>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-
- <reporting>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-project-info-reports-plugin</artifactId>
- <reportSets>
- <reportSet>
- <reports>
- <report>dependencies</report>
- <report>issue-tracking</report>
- <report>license</report>
- <report>scm</report>
- </reports>
- </reportSet>
- </reportSets>
- </plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>findbugs-maven-plugin</artifactId>
- <version>1.0.0</version>
- </plugin>
- </plugins>
- </reporting>
- <dependencyManagement>
- <!-- The parent pom manages the inter-dependencies of the modules. -->
- <dependencies>
- <dependency>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-managed</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.man</groupId>
- <artifactId>jboss-metatype</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-common-core</artifactId>
- <version>${version.jboss.common.core}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-spi</artifactId>
- <version>${version.jboss.common.logging.spi}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.logging</groupId>
- <artifactId>jboss-logging-log4j</artifactId>
- <version>${version.jboss.common.logging.log4j}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-reflect</artifactId>
- <version>${version.org.jboss.reflect}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss</groupId>
- <artifactId>jboss-mdr</artifactId>
- <version>${version.org.jboss.mdr}</version>
- </dependency>
- <!-- test dependencies -->
- <dependency>
- <groupId>org.jboss.test</groupId>
- <artifactId>jboss-test</artifactId>
- <version>${version.org.jboss.test}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${version.junit}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>sun-jaxb</groupId>
- <artifactId>jaxb-api</artifactId>
- <version>${version.sun.jaxb}</version>
- </dependency>
- <dependency>
- <groupId>javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>${version.javassist}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
- <repositories>
- <repository>
- <id>repository.jboss.org</id>
- <name>JBoss Repository</name>
- <layout>default</layout>
- <url>http://repository.jboss.org/maven2/</url>
- <releases>
- <enabled>true</enabled>
- </releases>
- <snapshots>
- <enabled>false</enabled>
- </snapshots>
- </repository>
- <repository>
- <id>snapshots.jboss.org</id>
- <name>JBoss Snapshots Repository</name>
- <layout>default</layout>
- <url>http://snapshots.jboss.org/maven2/</url>
- <snapshots>
- <enabled>true</enabled>
- </snapshots>
- <releases>
- <enabled>false</enabled>
- </releases>
- </repository>
- </repositories>
-
- <profiles>
- <profile>
- <id>default</id>
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- <properties>
- <microcontainer.outputDirectory>target/classes</microcontainer.outputDirectory>
- <microcontainer.testOutputDirectory>target/tests-classes</microcontainer.testOutputDirectory>
- </properties>
- </profile>
- <profile>
- <id>eclipse</id>
- <build>
- <defaultGoal>process-test-resources</defaultGoal>
- <plugins>
- <plugin>
- <artifactId>maven-eclipse-plugin</artifactId>
- <executions>
- <execution>
- <id>eclipse</id>
- <phase>process-test-resources</phase>
- <goals>
- <goal>eclipse</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <downloadSources>true</downloadSources>
- <buildOutputDirectory>${microcontainer.outputDirectory}</buildOutputDirectory>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <properties>
- <microcontainer.outputDirectory>eclipse-target/classes</microcontainer.outputDirectory>
- <microcontainer.testOutputDirectory>eclipse-target/tests-classes</microcontainer.testOutputDirectory>
- </properties>
- </profile>
- </profiles>
-
-</project>
Copied: projects/jboss-man/tags/2.1.0.CR4/pom.xml (from rev 85722, projects/jboss-man/branches/Branch_2_1/pom.xml)
===================================================================
--- projects/jboss-man/tags/2.1.0.CR4/pom.xml (rev 0)
+++ projects/jboss-man/tags/2.1.0.CR4/pom.xml 2009-03-11 07:26:35 UTC (rev 85723)
@@ -0,0 +1,250 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>4</version>
+ </parent>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-man-parent</artifactId>
+ <version>2.1.0.CR4</version>
+ <packaging>pom</packaging>
+ <name>JBoss Managed Parent POM</name>
+ <url>http://www.jboss.org/jbossmc</url>
+ <description>JBoss Managed Parent POM</description>
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/jbossas/projects/jboss-man/tags/2.1.0.CR4</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-man/tags/2.1.0.CR4</developerConnection>
+ <url>scm:svn:https://svn.jboss.org/repos/jbossas/projects/jboss-man/tags/2.1.0.CR4</url>
+ </scm>
+
+ <properties>
+ <version.jboss.common.core>2.2.10.GA</version.jboss.common.core>
+ <version.jboss.common.logging.spi>2.0.5.GA</version.jboss.common.logging.spi>
+ <version.jboss.common.logging.log4j>2.0.5.GA</version.jboss.common.logging.log4j>
+ <version.org.jboss.reflect>2.0.2.GA</version.org.jboss.reflect>
+ <version.org.jboss.mdr>2.0.1.GA</version.org.jboss.mdr>
+ <version.org.jboss.test>1.1.3.GA</version.org.jboss.test>
+ <version.junit>4.4</version.junit>
+ <version.sun.jaxb>2.1.4</version.sun.jaxb>
+ <version.javassist>3.9.0.GA</version.javassist>
+ </properties>
+
+ <modules>
+ <module>metatype</module>
+ <module>managed</module>
+ <module>build</module>
+ </modules>
+
+ <build>
+ <outputDirectory>${microcontainer.outputDirectory}</outputDirectory>
+ <testOutputDirectory>${microcontainer.testOutputDirectory}</testOutputDirectory>
+ <finalName>${artifactId}</finalName>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ <showDeprecation>true</showDeprecation>
+ <showWarnings>true</showWarnings>
+ <optimize>true</optimize>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <version>2.0-beta-7</version>
+ <configuration>
+ <tagBase>https://svn.jboss.org/repos/jbossas/projects/jboss-man/tags</tagBase>
+ <autoVersionSubmodules>true</autoVersionSubmodules>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <artifactId>maven-idea-plugin</artifactId>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.2</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.4.2</version>
+ <configuration>
+ <redirectTestOutputToFile>true</redirectTestOutputToFile>
+ <includes>
+ <include>org/jboss/test/**/*TestCase.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <reporting>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-project-info-reports-plugin</artifactId>
+ <reportSets>
+ <reportSet>
+ <reports>
+ <report>dependencies</report>
+ <report>issue-tracking</report>
+ <report>license</report>
+ <report>scm</report>
+ </reports>
+ </reportSet>
+ </reportSets>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ </plugin>
+ </plugins>
+ </reporting>
+ <dependencyManagement>
+ <!-- The parent pom manages the inter-dependencies of the modules. -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <version>${version.jboss.common.core}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>${version.jboss.common.logging.spi}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <version>${version.jboss.common.logging.log4j}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-reflect</artifactId>
+ <version>${version.org.jboss.reflect}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-mdr</artifactId>
+ <version>${version.org.jboss.mdr}</version>
+ </dependency>
+ <!-- test dependencies -->
+ <dependency>
+ <groupId>org.jboss.test</groupId>
+ <artifactId>jboss-test</artifactId>
+ <version>${version.org.jboss.test}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${version.junit}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>sun-jaxb</groupId>
+ <artifactId>jaxb-api</artifactId>
+ <version>${version.sun.jaxb}</version>
+ </dependency>
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <version>${version.javassist}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <url>http://repository.jboss.org/maven2/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshots Repository</name>
+ <layout>default</layout>
+ <url>http://snapshots.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <properties>
+ <microcontainer.outputDirectory>target/classes</microcontainer.outputDirectory>
+ <microcontainer.testOutputDirectory>target/tests-classes</microcontainer.testOutputDirectory>
+ </properties>
+ </profile>
+ <profile>
+ <id>eclipse</id>
+ <build>
+ <defaultGoal>process-test-resources</defaultGoal>
+ <plugins>
+ <plugin>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>eclipse</id>
+ <phase>process-test-resources</phase>
+ <goals>
+ <goal>eclipse</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <downloadSources>true</downloadSources>
+ <buildOutputDirectory>${microcontainer.outputDirectory}</buildOutputDirectory>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <properties>
+ <microcontainer.outputDirectory>eclipse-target/classes</microcontainer.outputDirectory>
+ <microcontainer.testOutputDirectory>eclipse-target/tests-classes</microcontainer.testOutputDirectory>
+ </properties>
+ </profile>
+ </profiles>
+
+</project>
More information about the jboss-cvs-commits
mailing list