[jboss-cvs] JBossAS SVN: r59140 - in projects/microcontainer/trunk: . managed managed/src managed/src/etc managed/src/main managed/src/main/org managed/src/main/org/jboss managed/src/main/org/jboss/managed managed/src/main/org/jboss/managed/api managed/src/main/org/jboss/managed/mock managed/src/tests managed/src/tests/org managed/src/tests/org/jboss managed/src/tests/org/jboss/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Dec 19 08:02:14 EST 2006


Author: adrian at jboss.org
Date: 2006-12-19 08:02:07 -0500 (Tue, 19 Dec 2006)
New Revision: 59140

Added:
   projects/microcontainer/trunk/managed/
   projects/microcontainer/trunk/managed/.classpath
   projects/microcontainer/trunk/managed/.project
   projects/microcontainer/trunk/managed/build.bat
   projects/microcontainer/trunk/managed/build.sh
   projects/microcontainer/trunk/managed/build.xml
   projects/microcontainer/trunk/managed/src/
   projects/microcontainer/trunk/managed/src/etc/
   projects/microcontainer/trunk/managed/src/etc/default.mf
   projects/microcontainer/trunk/managed/src/main/
   projects/microcontainer/trunk/managed/src/main/org/
   projects/microcontainer/trunk/managed/src/main/org/jboss/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java
   projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/Test.java
   projects/microcontainer/trunk/managed/src/tests/
   projects/microcontainer/trunk/managed/src/tests/org/
   projects/microcontainer/trunk/managed/src/tests/org/jboss/
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/
   projects/microcontainer/trunk/managed/src/tests/org/jboss/test/empty
Log:
Start of managed project

Added: projects/microcontainer/trunk/managed/.classpath
===================================================================
--- projects/microcontainer/trunk/managed/.classpath	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/.classpath	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src/main"/>
+	<classpathentry kind="src" path="src/tests"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/common-core/lib/jboss-common-core.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-spi/lib/jboss-logging-spi.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/common-logging-log4j/lib/jboss-logging-log4j.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/test/lib/jboss-test.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/metatype"/>
+	<classpathentry kind="output" path="output/eclipse-classes"/>
+</classpath>

Added: projects/microcontainer/trunk/managed/.project
===================================================================
--- projects/microcontainer/trunk/managed/.project	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/.project	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>managed</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: projects/microcontainer/trunk/managed/build.bat
===================================================================
--- projects/microcontainer/trunk/managed/build.bat	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/build.bat	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,89 @@
+ at echo off
+REM  ======================================================================
+REM
+REM  This is the main entry point for the build system.
+REM
+REM  Users should be sure to execute this file rather than 'ant' to ensure
+REM  the correct version is being used with the correct configuration.
+REM
+REM  ======================================================================
+REM
+REM $Id: build.bat 31497 2005-05-24 16:47:10Z adrian $
+REM
+REM Authors:
+REM     Jason Dillon <jason at planet57.com>
+REM     Sacha Labourey <sacha.labourey at cogito-info.ch>
+REM
+
+REM ******************************************************
+REM Ignore the ANT_HOME variable: we want to use *our*
+REM ANT version and associated JARs.
+REM ******************************************************
+REM Ignore the users classpath, cause it might mess
+REM things up
+REM ******************************************************
+
+SETLOCAL
+
+set CLASSPATH=
+set ANT_HOME=
+set ANT_OPTS=-Djava.protocol.handler.pkgs=org.jboss.net.protocol -Dbuild.script=build.bat
+
+REM ******************************************************
+REM - "for" loops have been unrolled for compatibility
+REM   with some WIN32 systems.
+REM ******************************************************
+
+set NAMES=tools;tools\ant;tools\apache\ant
+set SUBFOLDERS=..;..\..;..\..\..;..\..\..\..
+
+REM ******************************************************
+REM ******************************************************
+
+SET EXECUTED=FALSE
+for %%i in (%NAMES%) do call :subLoop %%i %1 %2 %3 %4 %5 %6
+
+goto :EOF
+
+
+REM ******************************************************
+REM ********* Search for names in the subfolders *********
+REM ******************************************************
+
+:subLoop
+for %%j in (%SUBFOLDERS%) do call :testIfExists %%j\%1\bin\ant.bat %2 %3 %4 %5 %6 %7
+
+goto :EOF
+
+
+REM ******************************************************
+REM ************ Test if ANT Batch file exists ***********
+REM ******************************************************
+
+:testIfExists
+if exist %1 call :BatchFound %1 %2 %3 %4 %5 %6 %7 %8
+
+goto :EOF
+
+
+REM ******************************************************
+REM ************** Batch file has been found *************
+REM ******************************************************
+
+:BatchFound
+if (%EXECUTED%)==(FALSE) call :ExecuteBatch %1 %2 %3 %4 %5 %6 %7 %8
+set EXECUTED=TRUE
+
+goto :EOF
+
+REM ******************************************************
+REM ************* Execute Batch file only once ***********
+REM ******************************************************
+
+:ExecuteBatch
+echo Calling %1 %2 %3 %4 %5 %6 %7 %8
+call %1 %2 %3 %4 %5 %6 %7 %8
+
+:end
+
+if "%NOPAUSE%" == "" pause


Property changes on: projects/microcontainer/trunk/managed/build.bat
___________________________________________________________________
Name: svn:executable
   + 

Added: projects/microcontainer/trunk/managed/build.sh
===================================================================
--- projects/microcontainer/trunk/managed/build.sh	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/build.sh	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,172 @@
+#!/bin/sh
+### ====================================================================== ###
+##                                                                          ##
+##  This is the main entry point for the build system.                      ##
+##                                                                          ##
+##  Users should be sure to execute this file rather than 'ant' to ensure   ##
+##  the correct version is being used with the correct configuration.       ##
+##                                                                          ##
+### ====================================================================== ###
+
+# $Id: build.sh 31497 2005-05-24 16:47:10Z adrian $
+
+PROGNAME=`basename $0`
+DIRNAME=`dirname $0`
+GREP="grep"
+ROOT="/"
+
+# Ignore user's ANT_HOME if it is set
+ANT_HOME=""
+
+# the default search path for ant
+ANT_SEARCH_PATH="\
+    tools
+    tools/ant \
+    tools/apache/ant \
+    ant"
+
+# the default build file name
+ANT_BUILD_FILE="build.xml"
+
+# the default arguments
+ANT_OPTIONS="-find $ANT_BUILD_FILE"
+
+# Use the maximum available, or set MAX_FD != -1 to use that
+MAX_FD="maximum"
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false;
+darwin=false;
+case "`uname`" in
+    CYGWIN*)
+        cygwin=true
+        ;;
+
+    Darwin*)
+        darwin=true
+        ;;
+esac
+
+#
+# Helper to complain.
+#
+die() {
+    echo "${PROGNAME}: $*"
+    exit 1
+}
+
+#
+# Helper to complain.
+#
+warn() {
+    echo "${PROGNAME}: $*"
+}
+
+#
+# Helper to source a file if it exists.
+#
+maybe_source() {
+    for file in $*; do
+	if [ -f "$file" ]; then
+	    . $file
+	fi
+    done
+}
+
+search() {
+    search="$*"
+    for d in $search; do
+	ANT_HOME="`pwd`/$d"
+	ANT="$ANT_HOME/bin/ant"
+	if [ -x "$ANT" ]; then
+	    # found one
+	    echo $ANT_HOME
+	    break
+	fi
+    done
+}
+
+#
+# Main function.
+#
+main() {
+    # if there is a build config file. then source it
+    maybe_source "$DIRNAME/build.conf" "$HOME/.build.conf"
+
+    # Increase the maximum file descriptors if we can
+    if [ $cygwin = "false" ]; then
+	MAX_FD_LIMIT=`ulimit -H -n`
+	if [ $? -eq 0 ]; then
+	    if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ]; then
+		# use the system max
+		MAX_FD="$MAX_FD_LIMIT"
+	    fi
+
+	    ulimit -n $MAX_FD
+	    if [ $? -ne 0 ]; then
+		warn "Could not set maximum file descriptor limit: $MAX_FD"
+	    fi
+	else
+	    warn "Could not query system maximum file descriptor limit: $MAX_FD_LIMIT"
+	fi
+    fi
+
+    # try the search path
+    ANT_HOME=`search $ANT_SEARCH_PATH`
+
+    # try looking up to root
+    if [ "x$ANT_HOME" = "x" ]; then
+	target="build"
+	_cwd=`pwd`
+
+	while [ "x$ANT_HOME" = "x" ] && [ "$cwd" != "$ROOT" ]; do
+	    cd ..
+	    cwd=`pwd`
+	    ANT_HOME=`search $ANT_SEARCH_PATH`
+	done
+
+	# make sure we get back
+	cd $_cwd
+
+	if [ "$cwd" != "$ROOT" ]; then
+	    found="true"
+	fi
+
+	# complain if we did not find anything
+	if [ "$found" != "true" ]; then
+	    die "Could not locate Ant; check \$ANT or \$ANT_HOME."
+	fi
+    fi
+
+    # make sure we have one
+    ANT=$ANT_HOME/bin/ant
+    if [ ! -x "$ANT" ]; then
+	die "Ant file is not executable: $ANT"
+    fi
+
+    # need to specify planet57/buildmagic protocol handler package
+    ANT_OPTS="-Djava.protocol.handler.pkgs=org.jboss.net.protocol"
+
+    # setup some build properties
+    ANT_OPTS="$ANT_OPTS -Dbuild.script=$0"
+
+    # change to the directory where the script lives so users are not forced
+    # to be in the same directory as build.xml
+    cd $DIRNAME
+
+    # export some stuff for ant
+    export ANT ANT_HOME ANT_OPTS
+
+    # execute in debug mode, or simply execute
+    if [ "x$ANT_DEBUG" != "x" ]; then
+	/bin/sh -x $ANT $ANT_OPTIONS "$@"
+    else
+	exec $ANT $ANT_OPTIONS "$@"
+    fi
+}
+
+##
+## Bootstrap
+##
+
+main "$@"


Property changes on: projects/microcontainer/trunk/managed/build.sh
___________________________________________________________________
Name: svn:executable
   + 

Added: projects/microcontainer/trunk/managed/build.xml
===================================================================
--- projects/microcontainer/trunk/managed/build.xml	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/build.xml	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,179 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+   <!ENTITY buildmagic SYSTEM "../tools/etc/buildmagic/buildmagic.ent">
+   <!ENTITY libraries SYSTEM "../thirdparty/libraries.ent">
+   <!ENTITY modules SYSTEM "../tools/etc/buildmagic/modules.ent">
+   <!ENTITY targets SYSTEM "../tools/etc/buildmagic/targets.ent">
+]>
+
+<!-- ====================================================================== -->
+<!--                                                                        -->
+<!--  JBoss, the OpenSource J2EE webOS                                      -->
+<!--                                                                        -->
+<!--  Distributable under LGPL license.                                     -->
+<!--  See terms of license at http://www.gnu.org.                           -->
+<!--                                                                        -->
+<!-- ====================================================================== -->
+
+<!-- $Id: build.xml 58705 2006-11-28 16:24:22Z adrian at jboss.org $ -->
+
+<project default="main" name="JBoss/Managed">
+
+  <!-- ================================================================== -->
+  <!-- Setup                                                              -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Include the common Buildmagic elements.
+     |
+     | This defines several different targets, properties and paths.
+     | It also sets up the basic extention tasks amoung other things.
+   -->
+
+  &buildmagic;
+
+  <!--
+     | Include the normal targets.
+   -->
+  &targets;
+
+  <!-- ================================================================== -->
+  <!-- Configuration                                                      -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Configure the build system.
+     |
+     | This target is invoked by the Buildmagic initialization logic and
+     | should contain module specific configuration elements.
+   -->
+
+  <target name="configure" unless="configure.disable">
+
+    <!-- =================== -->
+    <!-- Basic Configuration -->
+    <!-- =================== -->
+
+    <!-- Module name(s) & version -->
+    <property name="module.name" value="managed"/>
+    <property name="module.Name" value="JBoss Managed"/>
+    <property name="module.version" value="DEV"/>
+
+    <!-- ========= -->
+    <!-- Libraries -->
+    <!-- ========= -->
+
+    &libraries;
+
+    <!-- The combined library classpath -->
+    <path id="library.classpath">
+      <path refid="jboss/common.core.classpath"/>
+      <path refid="jboss/common.logging.spi.classpath"/>
+      <path refid="jboss/common.logging.log4j.classpath"/>
+    </path>
+
+    &modules;
+
+    <!-- The combined dependant module classpath -->
+    <path id="dependentmodule.classpath">
+      <path refid="jboss.metatype.classpath"/>
+    </path>
+
+   <!-- ============================= -->
+   <!-- Paths etc. for the retro task -->
+   <!-- ============================= -->
+   <property name="build.classes.retro" value="${module.output}/classes-retro"/>
+   <property name="build.lib.retro" value="${module.output}/lib14"/>
+   <path id="jbossretro.classpath">
+     <path refid="apache.ant.classpath"/>
+     <path refid="jboss.jbossretro.classpath"/>
+     <path refid="jboss/backport.concurrent.classpath"/>
+     <path refid="javassist.classpath"/>
+   </path>
+
+     
+    <!-- ===== -->
+    <!-- Tasks -->
+    <!-- ===== -->
+
+    <property name="jar.prefix" value="jboss-managed"/>
+    <property name="javac.target" value="1.5"/>
+    <property name="javac.source" value="1.5"/>
+
+    <call target="_default:task-init"/>
+
+  </target>
+
+  <!-- ================================================================== -->
+  <!-- Compile                                                            -->
+  <!-- ================================================================== -->
+
+  <!--
+     | Compile everything.
+     |
+     | This target should depend on other compile-* targets for each
+     | different type of compile that needs to be performed, short of
+     | documentation compiles.
+   -->
+
+  <target name="compile"
+	  description="Compile all source files."
+	  depends="_default:compile-classes,
+              _default:compile-etc,
+              retro"
+  />
+
+  <target name="retro">
+    <mkdir dir="${build.lib.retro}"/>
+    <taskdef name="retro" classname="org.jboss.ant.tasks.retro.Retro" classpathref="jbossretro.classpath"/>
+    <retro compilerclasspathref="jbossretro.classpath" destdir="${build.classes.retro}">
+      <classpath refid="jbossretro.classpath"/>
+      <classpath refid="library.classpath"/>
+      <classpath refid="dependentmodule.classpath"/>
+      <classpath>
+        <pathelement path="${build.classes}"/>
+      </classpath>
+      <src path="${build.classes}"/>
+    </retro>      
+  </target> 
+   
+  <!-- ================================================================== -->
+  <!-- Archives                                                           -->
+  <!-- ================================================================== -->
+
+  <!-- 
+     |  Build all jar files.
+    -->
+  <target name="module-jars" depends="init">
+    
+    <jar jarfile="${build.lib}/${jar.prefix}.jar" manifest="${build.etc}/default.mf">
+      <fileset dir="${build.classes}"/>
+    </jar>
+    <jar jarfile="${build.lib.retro}/${jar.prefix}14.jar" manifest="${build.etc}/default.mf">
+      <fileset dir="${build.classes.retro}"/>
+    </jar>
+    <!-- Minimal source bundle -->
+    <zip destfile="${build.lib}/${jar.prefix}-src.zip">
+      <fileset dir="${source.java}">
+        <include name="**"/>
+      </fileset>
+    </zip>
+  </target>
+   
+  <!-- ================================================================== -->
+  <!-- Test                                                               -->
+  <!-- ================================================================== -->
+
+  <target name="mock" depends="compile">
+    
+     <java classname="org.jboss.managed.mock.Test">
+        <classpath>
+           <pathelement location="${build.classes}"/>
+           <path refid="javac.classpath"/>
+           <path refid="apache.xerces.classpath"/>
+        </classpath>
+     </java>
+
+  </target>
+
+</project>

Added: projects/microcontainer/trunk/managed/src/etc/default.mf
===================================================================
--- projects/microcontainer/trunk/managed/src/etc/default.mf	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/etc/default.mf	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Created-By: @java.vm.version@ (@java.vm.vendor@)
+Specification-Title: @specification.title@
+Specification-Version: @specification.version@
+Specification-Vendor: @specification.vendor@
+Implementation-Title: @implementation.title@
+Implementation-URL: @implementation.url@
+Implementation-Version: @implementation.version@
+Implementation-Vendor: @implementation.vendor@
+Implementation-Vendor-Id: @implementation.vendor.id@

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/Fields.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,76 @@
+/*
+* 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>
+ * @version $Revision: 1.1 $
+ */
+public interface Fields extends Serializable
+{
+   /** The name field name */
+   String NAME = "name";
+
+   /** 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";
+   
+   // TODO other standard fields here
+   
+   /**
+    * Get a field with the given name
+    * 
+    * @param name the name
+    * @return the field value
+    */
+   Serializable getField(String name);
+   
+   /**
+    * Set a field with the given name
+    * 
+    * @param name the name
+    * @param value the field value
+    */
+   void setField(String name, Serializable value);
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedObject.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,114 @@
+/*
+* 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.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * ManagedObject.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ManagedObject implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = -2588364350006686542L;
+
+   /** The properties */
+   private Set<ManagedProperty> properties;
+   
+   /**
+    * Create a new ManagedObject
+    * 
+    * @param properties the properties 
+    */
+   public ManagedObject(Set<ManagedProperty> properties)
+   {
+      if (properties == null)
+         properties = Collections.emptySet();
+      this.properties = properties;
+   }
+   
+   // TODO identity, deployment info, scope, etc.
+   
+   /**
+    * Get the property names
+    * 
+    * @return the property names
+    */
+   public Set<String> getPropertyNames()
+   {
+      Set<String> result = new HashSet<String>(properties.size());
+      for (ManagedProperty property : properties)
+         result.add(property.getName());
+      return result;
+   }
+   
+   /**
+    * Get a property
+    * 
+    * @param name the name
+    * @return the property
+    */
+   public ManagedProperty getProperty(String name)
+   {
+      if (name == null)
+         throw new IllegalArgumentException("Null name");
+
+      for (ManagedProperty property : properties)
+      {
+         if (name.equals(property.getName()))
+            return property;
+      }
+      return null;
+   }
+   
+   /**
+    * Get the properties
+    * 
+    * @return the properties
+    */
+   public Set<ManagedProperty> getProperties()
+   {
+      return Collections.unmodifiableSet(properties);
+   }
+
+   /**
+    * Get the real properties
+    * 
+    * @return the properties
+    */
+   protected Set<ManagedProperty> getManagedProperties()
+   {
+      return properties;
+   }
+   
+   // TODO state, lifecycle, on-demand, etc.
+   
+   // TODO statistics
+   
+   // TODO listener api
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/api/ManagedProperty.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,297 @@
+/*
+* 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.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamField;
+import java.io.Serializable;
+import java.util.Set;
+
+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>
+ * @version $Revision: 1.1 $
+ */
+public class ManagedProperty implements Serializable
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 2268454772998030799L;
+   
+   /** The serialized form */
+   private static final ObjectStreamField[] serialPersistentFields =
+      new ObjectStreamField[]
+      {
+         new ObjectStreamField("fields", Fields.class),
+      };
+
+   /** The fields */
+   private Fields fields;
+
+   /** The property name */
+   private transient String name;
+   
+   /**
+    * Create a new ManagedProperty.
+    * 
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields
+    */
+   public ManagedProperty(Fields fields)
+   {
+      if (fields == null)
+         throw new IllegalArgumentException("Null fields");
+      this.fields = fields;
+      
+      name = getField(Fields.NAME, String.class);
+      if (name == null)
+         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
+   }
+   
+   /**
+    * Get the fields
+    * 
+    * @return the fields
+    */
+   public Fields getFields()
+   {
+      return fields;
+   }
+   
+   /**
+    * Get a field
+    *
+    * TODO general reconstruction code for metatypes
+    * @param <T> the expected type
+    * @param fieldName the field name
+    * @param expected the expected type
+    * @return the 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");
+      
+      Serializable 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  a of the expected type: " + expected.getName());
+   }
+   
+   /**
+    * Set a field
+    *
+    * TODO metaType stuff
+    * @param fieldName the field name
+    * @param value the value
+    */
+   public void setField(String fieldName, Serializable value)
+   {
+      if (fieldName == null)
+         throw new IllegalArgumentException("Null field name");
+      
+      getFields().setField(fieldName, value);
+   }
+   
+   /**
+    * Get the property's name
+    * 
+    * @return the property's name
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Get the description
+    * 
+    * @return the description
+    */
+   public String getDescription()
+   {
+      return getField(Fields.DESCRIPTION, String.class);
+   }
+
+   /**
+    * Get the type
+    * 
+    * @return the type
+    */
+   public MetaType getMetaType()
+   {
+      return getField(Fields.META_TYPE, MetaType.class);
+   }
+
+   /**
+    * Get the value
+    * 
+    * @return the value
+    */
+   public Object getValue()
+   {
+      return getField(Fields.VALUE, Object.class);
+   }
+
+   /**
+    * Set the value
+    * 
+    * @param value the value
+    */
+   public void setValue(Serializable value)
+   {
+      setField(Fields.VALUE, value);
+   }
+
+   /**
+    * Get the legal values
+    * 
+    * @return the legal values
+    */
+   @SuppressWarnings("unchecked")
+   public Set<MetaValue> getLegalValues()
+   {
+      return getField(Fields.LEGAL_VALUES, Set.class);
+   }
+
+   /**
+    * Get the minimum value
+    * 
+    * @return the minimum value
+    */
+   public MetaValue getMinimumValue()
+   {
+      return getField(Fields.MINIMUM_VALUE, MetaValue.class);
+   }
+
+   /**
+    * Get the miximum value
+    * 
+    * @return the maximum value
+    */
+   public MetaValue getMaximumValue()
+   {
+      return getField(Fields.MAXIMUM_VALUE, MetaValue.class);
+   }
+
+   /**
+    * Check whether this is a valid value
+    * 
+    * @param value the value
+    * @return null for a valid value, an error message otherwise
+    */
+   public String checkValidValue(Serializable value)
+   {
+      // TODO check min/max/etc.
+      return null;
+   }
+   
+   /**
+    * Whether the property is mandatory
+    * 
+    * @return true when mandatory
+    */
+   public boolean isMandatory()
+   {
+      Boolean result = getField(Fields.MANDATORY, Boolean.class);
+      if (result == null)
+         return false;
+      return result.booleanValue();
+   }
+
+   @Override
+   public String toString()
+   {
+      return "ManagedProperty{" + name + "}"; 
+   }
+
+   @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 name.equals(other.getName());
+   }
+   
+   /**
+    * Create a new ManagedProperty.
+    * 
+    * @param fields the fields
+    * @throws IllegalArgumentException for null fields
+    */
+   private void init(Fields fields)
+   {
+      if (fields == null)
+         throw new IllegalArgumentException("Null fields");
+      this.fields = fields;
+      
+      name = getField(Fields.NAME, String.class);
+      if (name == null)
+         throw new IllegalArgumentException("No " + Fields.NAME + " in fields");
+   }
+
+   private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
+   {
+      ObjectInputStream.GetField getField = in.readFields();
+      Fields fields = (Fields) getField.get("fields", null);
+      try
+      {
+         init(fields);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error deserializing managed property", e);
+      }
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDOMFields.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -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.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 Serializable 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, Serializable 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);
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/MockDataSourceManagedObject.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,88 @@
+/*
+* 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.mock;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.util.xml.DOMWriter;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * MockDataSourceManagedObject.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockDataSourceManagedObject extends ManagedObject
+{
+   /** The serialVersionUID */
+   private static final long serialVersionUID = 1L;
+
+   /** The document */
+   private Document document;
+   
+   /**
+    * Create a new MockDataSourceManagedObject.
+    */
+   public MockDataSourceManagedObject()
+   {
+      super(new HashSet<ManagedProperty>());
+      Element element;
+      try
+      {
+         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+         DocumentBuilder builder = factory.newDocumentBuilder();
+         DOMImplementation impl = builder.getDOMImplementation();
+         document = impl.createDocument(null, null, null);
+         
+         element = document.createElement("data-source");
+         document.appendChild(element);
+      }
+      catch (RuntimeException e)
+      {
+         throw e;
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Error creating dom", e);
+      }
+      
+      Set<ManagedProperty> properties = getManagedProperties();
+      properties.add(new ManagedProperty(new MockDOMFields(element, "jndi-name")));
+      properties.add(new ManagedProperty(new MockDOMFields(element, "connection-url")));
+      properties.add(new ManagedProperty(new MockDOMFields(element, "user")));
+      properties.add(new ManagedProperty(new MockDOMFields(element, "password")));
+   }
+   
+   public String prettyPrint()
+   {
+      return DOMWriter.printNode(document, true);
+   }
+}

Added: projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/Test.java
===================================================================
--- projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/Test.java	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/main/org/jboss/managed/mock/Test.java	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1,59 @@
+/*
+* 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.mock;
+
+/**
+ * Test.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class Test
+{
+   public static void main(String[] args) throws Exception
+   {
+      MockDataSourceManagedObject mo = new MockDataSourceManagedObject();
+
+      System.out.println("MockDataSourceManagedObject, available propertes...\n");
+      System.out.println(mo.getPropertyNames());
+
+      System.out.println("\nInitial MetaData...\n");
+      System.out.println(mo.prettyPrint());
+      
+      System.out.println("\nAdding jndi-name...\n");
+      mo.getProperty("jndi-name").setValue("DefaultDS");
+      System.out.println(mo.prettyPrint());
+
+      System.out.println("\nAdding user and password...\n");
+      mo.getProperty("user").setValue("Scott");
+      mo.getProperty("password").setValue("Tiger");
+      System.out.println(mo.prettyPrint());
+
+      System.out.println("\nChanging jndi-name...\n");
+      mo.getProperty("jndi-name").setValue("ChangedDS");
+      System.out.println(mo.prettyPrint());
+
+      System.out.println("\nRemoving jndi-name...\n");
+      mo.getProperty("jndi-name").setValue(null);
+      System.out.println(mo.prettyPrint());
+   }
+}

Added: projects/microcontainer/trunk/managed/src/tests/org/jboss/test/empty
===================================================================
--- projects/microcontainer/trunk/managed/src/tests/org/jboss/test/empty	2006-12-19 13:01:12 UTC (rev 59139)
+++ projects/microcontainer/trunk/managed/src/tests/org/jboss/test/empty	2006-12-19 13:02:07 UTC (rev 59140)
@@ -0,0 +1 @@
+empty
\ No newline at end of file




More information about the jboss-cvs-commits mailing list