Author: chris.laprun(a)jboss.com
Date: 2009-07-01 12:12:36 -0400 (Wed, 01 Jul 2009)
New Revision: 13511
Added:
modules/jems/
modules/jems/trunk/
modules/jems/trunk/build/
modules/jems/trunk/build/licences/
modules/jems/trunk/build/licences/JBossEULA.txt
modules/jems/trunk/build/misc/
modules/jems/trunk/build/misc/codeguide.html
modules/jems/trunk/build/pom.xml
modules/jems/trunk/jems/
modules/jems/trunk/jems/pom.xml
modules/jems/trunk/jems/src/
modules/jems/trunk/jems/src/main/
modules/jems/trunk/jems/src/main/java/
modules/jems/trunk/jems/src/main/java/org/
modules/jems/trunk/jems/src/main/java/org/jboss/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JMX.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDI.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDIBinder.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/AbstractJBossService.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JBossServiceModelMBean.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JMXConstants.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifeCycleAdapter.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifecycleInvoker.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjection.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjector.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvoker.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvokerMBean.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ContextObject.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/DialectFactory.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/HibernateProvider.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProvider.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProviderMBean.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JMXTreeCacheProvider.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/MagicString.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ObjectContextualizer.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/OracleStringUserType.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/QNameUserType.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/StringWrapperUserType.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/TreeCacheProvider.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/ClassicService.java
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/POJOService.java
modules/jems/trunk/jems/src/main/resources/
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/META-INF/
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/META-INF/jboss-service.xml
modules/jems/trunk/pom.xml
Log:
First import of mavenized JEMS support module. Note that pojo-service.sar is not currently
built.
Added: modules/jems/trunk/build/licences/JBossEULA.txt
===================================================================
--- modules/jems/trunk/build/licences/JBossEULA.txt (rev 0)
+++ modules/jems/trunk/build/licences/JBossEULA.txt 2009-07-01 16:12:36 UTC (rev 13511)
@@ -0,0 +1,106 @@
+LICENSE AGREEMENT
+JBOSS(r)
+
+This License Agreement governs the use of the Software Packages and any updates to the
Software
+Packages, regardless of the delivery mechanism. Each Software Package is a collective
work
+under U.S. Copyright Law. Subject to the following terms, Red Hat, Inc. ("Red
Hat") grants to
+the user ("Client") a license to the applicable collective work(s) pursuant to
the
+GNU Lesser General Public License v. 2.1 except for the following Software Packages:
+(a) JBoss Portal Forums and JBoss Transactions JTS, each of which is licensed pursuant to
the
+GNU General Public License v.2;
+
+(b) JBoss Rules, which is licensed pursuant to the Apache License v.2.0;
+
+(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is
licensed under the
+(open source) Sleepycat License (if Client does not wish to use the open source version
of this database,
+it may purchase a license from Sleepycat Software);
+
+and (d) the BPEL extension for JBoss jBPM, which is licensed under the Common Public
License v.1,
+and, pursuant to the OASIS BPEL4WS standard, requires parties wishing to redistribute to
enter various
+royalty-free patent licenses.
+
+Each of the foregoing licenses is available at
http://www.opensource.org/licenses/index.php.
+
+1. The Software. "Software Packages" refer to the various software modules
that are created and made available
+for distribution by the
JBoss.org open source community at
http://www.jboss.org. Each
of the Software Packages
+may be comprised of hundreds of software components. The end user license agreement for
each component is located in
+the component's source code. With the exception of certain image files identified in
Section 2 below,
+the license terms for the components permit Client to copy, modify, and redistribute the
component,
+in both source code and binary code forms. This agreement does not limit Client's
rights under,
+or grant Client rights that supersede, the license terms of any particular component.
+
+2. Intellectual Property Rights. The Software Packages are owned by Red Hat and others
and are protected under copyright
+and other laws. Title to the Software Packages and any component, or to any copy,
modification, or merged portion shall
+remain with the aforementioned, subject to the applicable license. The "JBoss"
trademark, "Red Hat" trademark, the
+individual Software Package trademarks, and the "Shadowman" logo are registered
trademarks of Red Hat and its affiliates
+in the U.S. and other countries. This agreement permits Client to distribute unmodified
copies of the Software Packages
+using the Red Hat trademarks that Red Hat has inserted in the Software Packages on the
condition that Client follows Red Hat's
+trademark guidelines for those trademarks located at
http://www.redhat.com/about/corporate/trademark/. Client must abide by
+these trademark guidelines when distributing the Software Packages, regardless of whether
the Software Packages have been modified.
+If Client modifies the Software Packages, then Client must replace all Red Hat trademarks
and logos identified at
+http://www.jboss.com/company/logos, unless a separate agreement with Red Hat is executed
or other permission granted.
+Merely deleting the files containing the Red Hat trademarks may corrupt the Software
Packages.
+
+3. Limited Warranty. Except as specifically stated in this Paragraph 3 or a license for
a particular
+component, to the maximum extent permitted under applicable law, the Software Packages
and the
+components are provided and licensed "as is" without warranty of any kind,
expressed or implied,
+including the implied warranties of merchantability, non-infringement or fitness for a
particular purpose.
+Red Hat warrants that the media on which Software Packages may be furnished will be free
from defects in
+materials and manufacture under normal use for a period of 30 days from the date of
delivery to Client.
+Red Hat does not warrant that the functions contained in the Software Packages will meet
Client's requirements
+or that the operation of the Software Packages will be entirely error free or appear
precisely as described
+in the accompanying documentation. This warranty extends only to the party that purchases
the Services
+pertaining to the Software Packages from Red Hat or a Red Hat authorized distributor.
+
+4. Limitation of Remedies and Liability. To the maximum extent permitted by applicable
law, the remedies
+described below are accepted by Client as its only remedies. Red Hat's entire
liability, and Client's
+exclusive remedies, shall be: If the Software media is defective, Client may return it
within 30 days of
+delivery along with a copy of Client's payment receipt and Red Hat, at its option,
will replace it or
+refund the money paid by Client for the Software. To the maximum extent permitted by
applicable law,
+Red Hat or any Red Hat authorized dealer will not be liable to Client for any incidental
or consequential
+damages, including lost profits or lost savings arising out of the use or inability to
use the Software,
+even if Red Hat or such dealer has been advised of the possibility of such damages. In
no event shall
+Red Hat's liability under this agreement exceed the amount that Client paid to Red
Hat under this
+Agreement during the twelve months preceding the action.
+
+5. Export Control. As required by U.S. law, Client represents and warrants that it:
+(a) understands that the Software Packages are subject to export controls under the
+U.S. Commerce Department's Export Administration Regulations ("EAR");
+
+(b) is not located in a prohibited destination country under the EAR or U.S. sanctions
regulations
+(currently Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria);
+
+(c) will not export, re-export, or transfer the Software Packages to any prohibited
destination, entity,
+or individual without the necessary export license(s) or authorizations(s) from the U.S.
Government;
+
+(d) will not use or transfer the Software Packages for use in any sensitive nuclear,
chemical or
+biological weapons, or missile technology end-uses unless authorized by the U.S.
Government by
+regulation or specific license;
+
+(e) understands and agrees that if it is in the United States and exports or transfers
the Software
+Packages to eligible end users, it will, as required by EAR Section 740.17(e), submit
semi-annual
+reports to the Commerce Department's Bureau of Industry & Security (BIS), which
include the name and
+address (including country) of each transferee;
+
+and (f) understands that countries other than the United States may restrict the import,
use, or
+export of encryption products and that it shall be solely responsible for compliance with
any such
+import, use, or export restrictions.
+
+6. Third Party Programs. Red Hat may distribute third party software programs with the
Software Packages
+that are not part of the Software Packages and which Client must install separately.
These third party
+programs are subject to their own license terms. The license terms either accompany the
programs or
+can be viewed at
http://www.redhat.com/licenses/. If Client does not agree to abide by
the applicable
+license terms for such programs, then Client may not install them. If Client wishes to
install the programs
+on more than one system or transfer the programs to another party, then Client must
contact the licensor
+of the programs.
+
+7. General. If any provision of this agreement is held to be unenforceable, that shall
not affect the
+enforceability of the remaining provisions. This License Agreement shall be governed by
the laws of the
+State of North Carolina and of the United States, without regard to any conflict of laws
provisions,
+except that the United Nations Convention on the International Sale of Goods shall not
apply.
+
+Copyright 2006 Red Hat, Inc. All rights reserved.
+"JBoss" and the JBoss logo are registered trademarks of Red Hat, Inc.
+All other trademarks are the property of their respective owners.
+
+ Page 1 of 1 18 October 2006
Added: modules/jems/trunk/build/misc/codeguide.html
===================================================================
--- modules/jems/trunk/build/misc/codeguide.html (rev 0)
+++ modules/jems/trunk/build/misc/codeguide.html 2009-07-01 16:12:36 UTC (rev 13511)
@@ -0,0 +1,133 @@
+<html>
+
+<head>
+<style type="text/css">
+pre { border-style:solid; border-width:thin; padding:5px; background-color:#EEEEFF;}
+span.bad { text-decoration:line-through; }
+span.important { font-weight:bold; color:red; }
+</style>
+</head>
+
+<body>
+
+<h2>Coding Conventions</h2>
+
+<h3>Some more general guidelines</h3>
+<ul>
+<li>Fully qualified imports should be used, rather than importing
x.y.*.</li>
+<li>Use newlines for opening braces, so that the top and bottom braces can be
visually matched.</li>
+<li>Aid visual separation of logical steps by introducing newlines and appropriate
comments above them.</li>
+</ul>
+
+
+<h3>A class that conforms to JBoss coding guidelines</h3>
+
+<pre>
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, Red Hat Middleware, LLC, 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 x;
+
+// <span class="important">Explicit imports</span>
+import a.b.C1; // <span class="important">good</span>
+import a.b.C2;
+import a.b.C3;
+
+// <span class="important">Do not write</span>
+<span class="bad">import a.b.*;</span> // <span
class="important">bad</span>
+
+// <span class="important">DO NOT USE "TAB" TO INDENT CODE USE
*3* SPACES FOR PORTABILITY AMONG EDITORS</span>
+
+/**
+ * A description of this class.
+ *
+ * @see SomeRelatedClass.
+ *
+ * @version <tt>$Revision: 7755 $</tt>
+ * @author <a href="mailto:{email}">{full
name}</a>
+ */
+public class X
+ extends Y
+ implements Z
+{
+ public void startService() throws Exception
+ {
+ // Use the newline for the opening bracket so we can match top
+ // and bottom bracket visually
+
+ Class cls = Class.forName(dataSourceClass);
+ vendorSource = (XADataSource)cls.newInstance();
+
+ // Jump a line between logically distinct <span
class="important">steps</span> and add<
+ // line of comment to it
+ cls = vendorSource.getClass();
+
+ // Comment lines <span class="important">always</span> start
with an uppercase
+ // except if it is the second line
+ if(properties != null)
+ {
+
+ try
+ {
+ }
+ catch (IOException ioe)
+ {
+ }
+ for (Iterator i = props.entrySet().iterator(); i.hasNext();)
+ {
+
+ // Get the name and value for the attributes
+ Map.Entry entry = (Map.Entry) i.next();
+ String attributeName = (String) entry.getKey();
+ String attributeValue = (String) entry.getValue();
+
+ // Print the debug message
+ log.debug("Setting attribute '" + attributeName + "'
to '" + attributeValue + "'");
+
+ // get the attribute
+ Method setAttribute =
+ cls.getMethod("set" + attributeName, new Class[] { String.class
});
+
+ // And set the value
+ setAttribute.invoke(vendorSource, new Object[] { attributeValue });
+ }
+ }
+
+ <span class="bad">// this is a <span
class="important">bad</span> comment line because it starts with a
lower case</span>
+ vendorSource.getXAConnection().close();
+
+ // Bind in JNDI
+ bind(new InitialContext(), "java:/"+getPoolName(),
+ new Reference(vendorSource.getClass().getName(),
+ getClass().getName(), null));
+
+ // Block must always be delimited explicitely
+ if (0 == 0)
+ <span class="important">{</span>
+ System.out.println(true);
+ <span class="important">}</span>
+
+ }
+}
+</pre>
+</body>
+</html>
Property changes on: modules/jems/trunk/build/misc/codeguide.html
___________________________________________________________________
Name: svn:executable
+ *
Added: modules/jems/trunk/build/pom.xml
===================================================================
--- modules/jems/trunk/build/pom.xml (rev 0)
+++ modules/jems/trunk/build/pom.xml 2009-07-01 16:12:36 UTC (rev 13511)
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<!--
+ This pom functions as a default configuration. The subproject
+ poms each inherit configuration from this one.
+
+ When adding version information for an artifact please do the following
+ - add a version property for the specific version
+ - add a dependency in the dependencyManagement section which refers to
+ the property
+-->
+<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.portal</groupId>
+ <artifactId>jboss-portal-parent</artifactId>
+ <version>1.0.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.portal.jems</groupId>
+ <artifactId>module-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>JBoss Portal JEMS Support Parent</name>
+ <description>JBoss Portal JEMS Support</description>
+
+
+ <!--JBoss reporitories to be able to grab jboss-portal-parent pom-->
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <
url>http://repository.jboss.org/maven2/</url>
+ <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>
+
+
+ <!--Sample additional plugin repository. This one is not needed if you don't
use maven-antrun-extended-plugin
+ (used in module-c)-->
+ <pluginRepositories>
+ <pluginRepository>
+ <
id>java.net maven repository</id>
+ <
url>http://download.java.net/maven/2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+
+
+</project>
Added: modules/jems/trunk/jems/pom.xml
===================================================================
--- modules/jems/trunk/jems/pom.xml (rev 0)
+++ modules/jems/trunk/jems/pom.xml 2009-07-01 16:12:36 UTC (rev 13511)
@@ -0,0 +1,111 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<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.portal.jems</groupId>
+ <artifactId>module-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>jems</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Portal JEMS Support</name>
+
+ <properties>
+ <version.jbossas>4.2.3.GA</version.jbossas>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.portal.common</groupId>
+ <artifactId>common-common</artifactId>
+ <version>1.2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>apache-log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.15</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jbosscache</artifactId>
+ <version>3.3.1.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss</artifactId>
+ <version>${version.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-common</artifactId>
+ <version>${version.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-system</artifactId>
+ <version>${version.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jboss-jmx</artifactId>
+ <version>${version.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss</groupId>
+ <artifactId>jbossha</artifactId>
+ <version>${version.jbossas}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.cache</groupId>
+ <artifactId>jbosscache-core</artifactId>
+ <version>1.4.1.SP3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.beanshell</groupId>
+ <artifactId>bsh</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JMX.java
===================================================================
--- modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JMX.java
(rev 0)
+++ modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JMX.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,215 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2009, Red Hat Middleware, LLC, 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.portal.jems.as;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.mx.util.ObjectNameConverter;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import java.util.Comparator;
+import java.util.Hashtable;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 13310 $
+ */
+public final class JMX
+{
+
+ private static final Logger log = Logger.getLogger(JMX.class);
+
+ public static ObjectName extend(ObjectName name, Properties keyProperties)
+ {
+ try
+ {
+ Hashtable table = name.getKeyPropertyList();
+ table.putAll(keyProperties);
+ return ObjectNameConverter.convert(name.getDomain(), table);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ log.error("", e);
+ throw new RuntimeException();
+ }
+ }
+
+ /** ObjectName comparator based on canonical name lexicography. */
+ public static Comparator OBJECT_NAME_COMPARATOR = new Comparator()
+ {
+ public int compare(Object o1, Object o2)
+ {
+ ObjectName n1 = (ObjectName)o1;
+ ObjectName n2 = (ObjectName)o2;
+ return n1.getCanonicalName().compareTo(n2.getCanonicalName());
+ }
+ };
+
+ public static void safeUnregister(MBeanServer server, ObjectName name)
+ {
+ if (server != null)
+ {
+ if (name != null)
+ {
+ try
+ {
+ server.unregisterMBean(name);
+ }
+ catch (InstanceNotFoundException e)
+ {
+ log.error("MBean " + name + " nto here");
+ }
+ catch (MBeanRegistrationException e)
+ {
+ log.error("MBean threw an exception during unregistration",
e.getTargetException());
+ }
+ }
+ else
+ {
+ log.error("Cannot unregister a null MBean");
+ }
+ }
+ else
+ {
+ log.error("Cannot unregister with a null MBeanServer");
+ }
+ }
+
+ /**
+ * Retrieves the MBeanProxy associated with the given class and name from the
specified MBeanServer.
+ *
+ * @param expectedClass the expected class of the MBean's proxy
+ * @param name the MBean's ObjectName
+ * @param server the MBeanServer from which to retrieve the MBeanProxy
+ * @return a MBeanProxy for the specified MBean if it exists
+ * @throws RuntimeException if the MBean couldn't be retrieved
+ */
+ public static <T> T getMBeanProxy(Class<T> expectedClass, ObjectName name,
MBeanServer server)
+ {
+ try
+ {
+ return expectedClass.cast(MBeanProxy.get(expectedClass, name, server));
+ }
+ catch (Exception e)
+ {
+ String message = "Couldn't retrieve '" +
name.getCanonicalName() + "' MBean with class " + expectedClass.getName();
+ log.error(message, e);
+ throw new RuntimeException(message, e);
+ }
+ }
+
+ /**
+ * Retrieves the MBeanProxy associated with the given class and name from the JBoss
microkernel as returned by
+ * <code>MBeanServerLocator.locateJBoss()</code>.
+ *
+ * @param expectedClass the expected class of the MBean's proxy
+ * @param name a String representation of the MBean's ObjectName
+ * @return a MBeanProxy for the specified MBean if it exists
+ * @throws IllegalArgumentException if the given name is not a valid ObjectName
+ * @throws RuntimeException if the MBean couldn't be retrieved
+ * @see #getMBeanProxy(Class, javax.management.ObjectName,
javax.management.MBeanServer)
+ * @since 2.4
+ */
+ public static <T> T getMBeanProxy(Class<T> expectedClass, String name)
+ {
+ ObjectName objecName = createObjectName(name);
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ return getMBeanProxy(expectedClass, objecName, server);
+ }
+
+ private static ObjectName createObjectName(String name)
+ {
+ ObjectName objecName;
+ try
+ {
+ objecName = new ObjectName(name);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new IllegalArgumentException("'" + name + "' is not
a valid ObjectName");
+ }
+ return objecName;
+ }
+
+ /**
+ * Checks whether the JBoss MBeanServer knows about an MBean with the specified name
without having to retrieve a
+ * proxy to it.
+ *
+ * @param name a String representation of the MBean object name which registration
status we're interested in
+ * @return <code>true</code> if the server knows of an MBean with the
specified name, <code>false</code> otherwise.
+ */
+ public static boolean isRegistered(String name)
+ {
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ return server.isRegistered(createObjectName(name));
+ }
+
+ public static boolean addNotificationListener(
+ MBeanServer server,
+ ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ {
+ try
+ {
+ server.addNotificationListener(name, listener, filter, handback);
+ return true;
+ }
+ catch (InstanceNotFoundException e)
+ {
+ return false;
+ }
+ }
+
+ public static boolean removeNotificationListener(
+ MBeanServer server,
+ ObjectName name,
+ NotificationListener listener)
+ {
+ try
+ {
+ server.removeNotificationListener(name, listener);
+ return true;
+ }
+ catch (InstanceNotFoundException e)
+ {
+ log.error("Cannot remove notification listener", e);
+ return false;
+ }
+ catch (ListenerNotFoundException e)
+ {
+ log.error("Cannot remove notification listener", e);
+ return false;
+ }
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JMX.java
___________________________________________________________________
Name: svn:executable
+ *
Added: modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDI.java
===================================================================
--- modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDI.java
(rev 0)
+++ modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDI.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,106 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as;
+
+import org.jboss.util.naming.NonSerializableFactory;
+
+import javax.naming.CompositeName;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+/**
+ * Various JNDI stuff.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class JNDI
+{
+
+ /**
+ * Encapsulate JNDI binding operation into one single class, hidding non usefull JNDI
complexity. It has been
+ * designed to fit with service life cycle.
+ * <p/>
+ * <code>
+ * <p/>
+ * private String jndiName; private JNDI.Binding jndiBinding;
+ * <p/>
+ * public void startService() throws Exception { ... if (this.jndiName != null) {
jndiBinding = new
+ * JNDI.Binding(jndiName, this); jndiBinding.bind(); } ... }
+ * <p/>
+ * public void stopService() throws Exception { ... if (jndiBinding != null) {
jndiBinding.unbind(); jndiBinding =
+ * null; } ... } </code>
+ */
+ public static class Binding
+ {
+
+ /** . */
+ private final String jndiName;
+
+ /** . */
+ private String unbindJNDIName;
+
+ /** . */
+ private Object o;
+
+ public Binding(String jndiName, Object o)
+ {
+ if (jndiName == null)
+ {
+ throw new IllegalArgumentException("No JNDI name provided");
+ }
+ if (o == null)
+ {
+ throw new IllegalArgumentException("No object to bind for JNDI name
" + jndiName);
+ }
+ this.jndiName = jndiName;
+ this.o = o;
+ }
+
+ /**
+ * Attempt to perform binding.
+ *
+ * @throws NamingException on failure
+ */
+ public void bind() throws NamingException
+ {
+ NonSerializableFactory.rebind(new CompositeName(jndiName), o, true);
+ unbindJNDIName = jndiName;
+ }
+
+ /** Unbinds in a safe manner. */
+ public void unbind()
+ {
+ if (unbindJNDIName != null)
+ {
+ try
+ {
+ NonSerializableFactory.unbind(unbindJNDIName);
+ }
+ catch (NameNotFoundException ignore)
+ {
+ }
+ }
+ }
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDI.java
___________________________________________________________________
Name: svn:executable
+ *
Added: modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDIBinder.java
===================================================================
--- modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDIBinder.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/JNDIBinder.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,95 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * A service that binds an injected service to the JNDI registry.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class JNDIBinder extends AbstractJBossService
+{
+
+ /** The jndi name. */
+ private String jndiName;
+
+ /** The injected service that will be bound. */
+ private Object targetObject;
+
+ /** The jndi binding object. */
+ private JNDI.Binding jndiBinding;
+
+ public String getJNDIName()
+ {
+ return jndiName;
+ }
+
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public Object getTargetObject()
+ {
+ return targetObject;
+ }
+
+ public void setTargetObject(Object targetObject)
+ {
+ this.targetObject = targetObject;
+ }
+
+ protected void createService() throws Exception
+ {
+ if (jndiName == null)
+ {
+ throw new IllegalStateException("No jndi name provided");
+ }
+ }
+
+ protected void startService() throws Exception
+ {
+ if (targetObject == null)
+ {
+ throw new IllegalStateException("No target object to bind");
+ }
+
+ //
+ log.debug("About to bind service" + targetObject + " to JNDI with
name " + jndiName);
+ jndiBinding = new JNDI.Binding(jndiName, this);
+ jndiBinding.bind();
+ log.debug("Service" + targetObject + " bound to JNDI with name
" + jndiName);
+ }
+
+ protected void stopService() throws Exception
+ {
+ if (jndiBinding != null)
+ {
+ jndiBinding.unbind();
+ jndiBinding = null;
+ }
+ }
+}
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/AbstractJBossService.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/AbstractJBossService.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/AbstractJBossService.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,85 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import org.jboss.logging.Logger;
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * JBoss service integration helper.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class AbstractJBossService extends ServiceMBeanSupport
+{
+
+ public AbstractJBossService()
+ {
+ }
+
+ public AbstractJBossService(final Class type)
+ {
+ super(type);
+ }
+
+ public AbstractJBossService(final String category)
+ {
+ super(category);
+ }
+
+ public AbstractJBossService(final Logger log)
+ {
+ super(log);
+ }
+
+ public final int getState()
+ {
+ return super.getState();
+ }
+
+ public final String getStateString()
+ {
+ return super.getStateString();
+ }
+
+ public final void create() throws Exception
+ {
+ super.create();
+ }
+
+ public final void start() throws Exception
+ {
+ super.start();
+ }
+
+ public final void stop()
+ {
+ super.stop();
+ }
+
+ public final void destroy()
+ {
+ super.destroy();
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/AbstractJBossService.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JBossServiceModelMBean.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JBossServiceModelMBean.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JBossServiceModelMBean.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,543 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.interceptor.AbstractInterceptor;
+import org.jboss.mx.interceptor.Interceptor;
+import org.jboss.mx.modelmbean.ModelMBeanInvoker;
+import org.jboss.mx.server.Invocation;
+import org.jboss.mx.server.InvocationContext;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.portal.common.mx.JavaBeanModelMBeanBuilder;
+import org.jboss.portal.common.util.Tools;
+import org.jboss.system.ServiceMBeanSupport;
+import org.w3c.dom.Element;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.modelmbean.InvalidTargetObjectTypeException;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class JBossServiceModelMBean extends ModelMBeanInvoker
+{
+
+ // Attributes ----------------------------------------------------
+
+ static
+ {
+ try
+ {
+ serviceMixinInfo = JavaBeanModelMBeanBuilder.build(ServiceMixin.class,
Object.class);
+ }
+ catch (Exception e)
+ {
+ throw new Error(e);
+ }
+ }
+
+ /** . */
+ private static final ModelMBeanInfo serviceMixinInfo;
+
+ /** . */
+ private static final Logger log = Logger.getLogger(JBossServiceModelMBean.class);
+
+ /** . */
+ public static final String PORTAL_KERNEL_NO_PROXIES =
"portal.kernel.no_proxies";
+
+ // Constructors --------------------------------------------------
+
+ /** . */
+ private final boolean replaceProxies;
+
+ /** . */
+ private final ServiceMixin serviceMixin;
+
+ /** . */
+ private final POJOInjector injector;
+
+ /** . */
+ private final boolean createExists;
+
+ /** . */
+ private final boolean startExists;
+
+ /** . */
+ private final boolean stopExists;
+
+ /** . */
+ private final boolean destroyExists;
+
+ /** . */
+ private final boolean getStateExists;
+
+ /** . */
+ private final boolean getStateStringExists;
+
+ /** . */
+ private final boolean getManagedResourceExists;
+
+ public JBossServiceModelMBean(Object resource) throws MBeanException
+ {
+ this(resource, null, null);
+ }
+
+ public JBossServiceModelMBean(Object resource, Element config, String version) throws
MBeanException
+ {
+ try
+ {
+ setManagedResource(resource, "ObjectReference");
+
+ //
+ boolean pojo = !(resource instanceof ServiceMBeanSupport);
+
+ // Build
+ ModelMBeanInfo info = JavaBeanModelMBeanBuilder.build(resource.getClass(), pojo
? Object.class : ServiceMBeanSupport.class);
+
+ //
+ this.replaceProxies =
"true".equals(System.getProperty(PORTAL_KERNEL_NO_PROXIES, "true"));
+ this.injector = new POJOInjector();
+ this.serviceMixin = new ServiceMixin(resource);
+
+ //
+ List mmois = Tools.toList(info.getOperations());
+ List mmais = Tools.toList(info.getAttributes());
+
+ //
+ boolean createExists = false;
+ boolean startExists = false;
+ boolean stopExists = false;
+ boolean destroyExists = false;
+ boolean getStateExists = false;
+ boolean getStateStringExists = false;
+ boolean getManagedResourceExists = false;
+
+ //
+ for (int i = 0; i < mmois.size(); i++)
+ {
+ ModelMBeanOperationInfo mmoi = (ModelMBeanOperationInfo)mmois.get(i);
+ if (mmoi.getSignature().length == 0)
+ {
+ if (mmoi.getName().equals("create"))
+ {
+ createExists = true;
+ }
+ else if (mmoi.getName().equals("start"))
+ {
+ startExists = true;
+ }
+ else if (mmoi.getName().equals("stop"))
+ {
+ stopExists = true;
+ }
+ else if (mmoi.getName().equals("destroy"))
+ {
+ destroyExists = true;
+ }
+ else if (mmoi.getName().equals("getState"))
+ {
+ getStateExists = true;
+ }
+ else if (mmoi.getName().equals("getStateString"))
+ {
+ getStateStringExists = true;
+ }
+ else if (mmoi.getName().equals("getManagedResource"))
+ {
+ getManagedResourceExists = true;
+ }
+ }
+ }
+
+ //
+ this.createExists = createExists;
+ this.startExists = startExists;
+ this.stopExists = stopExists;
+ this.destroyExists = destroyExists;
+ this.getStateExists = getStateExists;
+ this.getStateStringExists = getStateStringExists;
+ this.getManagedResourceExists = getManagedResourceExists;
+
+ //
+ if (!createExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("create"));
+ }
+ if (!startExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("start"));
+ }
+ if (!stopExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("stop"));
+ }
+ if (!destroyExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("destroy"));
+ }
+ if (!getStateExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("getState"));
+ mmais.add(serviceMixinInfo.getAttribute("State"));
+ }
+ if (!getStateStringExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("getStateString"));
+ mmais.add(serviceMixinInfo.getAttribute("StateString"));
+ }
+ if (!getManagedResourceExists)
+ {
+ mmois.add(serviceMixinInfo.getOperation("getManagedResource"));
+ mmais.add(serviceMixinInfo.getAttribute("ManagedResource"));
+ }
+
+ //
+ info = new ModelMBeanInfoSupport(
+ info.getClassName(),
+ info.getDescription(),
+ (ModelMBeanAttributeInfo[])mmais.toArray(new
ModelMBeanAttributeInfo[mmais.size()]),
+ (ModelMBeanConstructorInfo[])info.getConstructors(),
+ (ModelMBeanOperationInfo[])mmois.toArray(new
ModelMBeanOperationInfo[mmois.size()]),
+ (ModelMBeanNotificationInfo[])info.getNotifications());
+
+ //
+ setModelMBeanInfo(info);
+ }
+ catch (InstanceNotFoundException e)
+ {
+ throw new MBeanException(e);
+ }
+ catch (InvalidTargetObjectTypeException e)
+ {
+ throw new MBeanException(e, "Unsupported resource type: " +
resourceType);
+ }
+ catch (Exception e)
+ {
+ throw new MBeanException(e);
+ }
+ }
+
+ // ModelMBean implementation -------------------------------------
+
+ public boolean isSupportedResourceType(Object resource, String resourceType)
+ {
+ return "ObjectReference".equals(resourceType);
+ }
+
+ public MBeanInfo getMBeanInfo()
+ {
+ return info;
+ }
+
+ //
+
+ protected void initDispatchers()
+ {
+ super.initDispatchers();
+
+ //
+ for (Iterator i = attributeContextMap.values().iterator(); i.hasNext();)
+ {
+ InvocationContext ctx = (InvocationContext)i.next();
+ if ("State".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return new Integer(serviceMixin.getState());
+ }
+ });
+ }
+ else if ("StateString".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return serviceMixin.getStateString();
+ }
+ });
+ }
+ else if ("ManagedResource".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return serviceMixin.getManagedResource();
+ }
+ });
+ }
+ else if (replaceProxies)
+ {
+ // Retrieve original dispatcher
+ final Interceptor dispatcher = ctx.getDispatcher();
+
+ //
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ if (InvocationContext.OP_SETATTRIBUTE.equals(invocation.getType()))
+ {
+ Object value = invocation.getArgs()[0];
+ if (value != null && Proxy.isProxyClass(value.getClass()))
+ {
+ Object handler = Proxy.getInvocationHandler(value);
+ if (handler instanceof MBeanProxyExt)
+ {
+ MBeanProxyExt pojoHandler = (MBeanProxyExt)handler;
+ POJOInjection injection = new POJOInjection(pojoHandler,
dispatcher, invocation);
+ injector.addInjection(injection);
+ }
+ else
+ {
+ dispatcher.invoke(invocation);
+ }
+ }
+ else
+ {
+ dispatcher.invoke(invocation);
+ }
+
+ //
+ return null;
+ }
+ else
+ {
+ return dispatcher.invoke(invocation);
+ }
+ }
+ });
+ }
+ }
+
+ //
+ for (Iterator i = operationContextMap.values().iterator(); i.hasNext();)
+ {
+ InvocationContext ctx = (InvocationContext)i.next();
+ if ("create".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ serviceMixin.create();
+ return null;
+ }
+ });
+ }
+ else if ("start".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ serviceMixin.start();
+ return null;
+ }
+ });
+ }
+ else if ("stop".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ serviceMixin.stop();
+ return null;
+ }
+ });
+ }
+ else if ("destroy".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ serviceMixin.destroy();
+ return null;
+ }
+ });
+ }
+ else if ("getState".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return new Integer(serviceMixin.getState());
+ }
+ });
+ }
+ else if ("getStateString".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return serviceMixin.getStateString();
+ }
+ });
+ }
+ else if ("getManagedResource".equals(ctx.getName()))
+ {
+ ctx.setDispatcher(new AbstractInterceptor()
+ {
+ public Object invoke(Invocation invocation) throws Throwable
+ {
+ return serviceMixin.getManagedResource();
+ }
+ });
+ }
+ }
+ }
+
+ private static class ServiceMixin extends ServiceMBeanSupport
+ {
+
+ /** . */
+ private final Object resource;
+
+ public ServiceMixin(Object resource)
+ {
+ this.resource = resource;
+ }
+
+ protected void createService() throws Exception
+ {
+ execute("create");
+ }
+
+ protected void startService() throws Exception
+ {
+ execute("start");
+ }
+
+ protected void stopService() throws Exception
+ {
+ execute("stop");
+ }
+
+ protected void destroyService() throws Exception
+ {
+ execute("destroy");
+ }
+
+ public Object getManagedResource()
+ {
+ return resource;
+ }
+
+ private void execute(String lifecycle) throws Exception
+ {
+ Method m = null;
+ try
+ {
+ m = resource.getClass().getMethod(lifecycle, new Class[0]);
+ }
+ catch (NoSuchMethodException ignore)
+ {
+ }
+
+ //
+ if (m != null)
+ {
+ try
+ {
+ m.invoke(resource, new Object[0]);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new Error(e);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable t = e.getTargetException();
+ if (t instanceof Exception)
+ {
+ throw (Exception)t;
+ }
+ else if (t instanceof Error)
+ {
+ throw (Error)t;
+ }
+ else
+ {
+ throw new Error(t);
+ }
+ }
+ }
+ }
+ }
+
+ // MBeanRegistration implementation
*********************************************************************************
+
+
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
+ {
+ name = super.preRegister(server, name);
+
+ //
+ server.addNotificationListener(JMXConstants.MBEAN_SERVER_DELEGATE, injector, null,
null);
+
+ //
+ return name;
+ }
+
+ public void postRegister(Boolean done)
+ {
+ super.postRegister(done);
+ }
+
+ public void preDeregister() throws Exception
+ {
+ getServer().removeNotificationListener(JMXConstants.MBEAN_SERVER_DELEGATE,
injector);
+
+ //
+ super.preDeregister();
+ }
+
+ public void postDeregister()
+ {
+ super.postDeregister();
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JBossServiceModelMBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JMXConstants.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JMXConstants.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/JMXConstants.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import org.jboss.mx.util.ObjectNameFactory;
+
+import javax.management.ObjectName;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public interface JMXConstants
+{
+ /** The name of the server delegate. */
+ ObjectName MBEAN_SERVER_DELEGATE =
ObjectNameFactory.create("JMImplementation:type=MBeanServerDelegate");
+}
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifeCycleAdapter.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifeCycleAdapter.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifeCycleAdapter.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,238 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import org.apache.log4j.Logger;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanProxyCreationException;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.portal.jems.as.JMX;
+import org.jboss.system.ServiceController;
+import org.jboss.system.ServiceControllerMBean;
+import org.jboss.system.ServiceMBean;
+
+import javax.management.AttributeChangeNotification;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerNotification;
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Adapts JBoss lifecycle event handling and multiplex event from different sources into
one source.
+ * <p/>
+ * It requires an MBeanServer and a ServiceController plugged into the MBeanServer.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class LifeCycleAdapter
+{
+
+ /** The name of the server delegate. */
+ private static final ObjectName MBEAN_SERVER_DELEGATE =
ObjectNameFactory.create("JMImplementation:type=MBeanServerDelegate");
+
+ /** The logger. */
+ protected Logger log;
+
+ /** The service controller name. */
+ protected ServiceControllerMBean controller;
+
+ /** The server. */
+ protected MBeanServer server;
+
+ /** The delegated listener. */
+ private Listener listener;
+
+ /** The watched mbeans. */
+ private Set watched;
+
+ /** Create the rule for the given server. */
+ public LifeCycleAdapter(MBeanServer server)
+ {
+ try
+ {
+ this.log = Logger.getLogger(getClass());
+ this.controller =
(ServiceControllerMBean)MBeanProxy.get(ServiceControllerMBean.class,
ServiceController.OBJECT_NAME, server);
+ this.server = server;
+ this.listener = new Listener();
+ this.watched = Collections.synchronizedSet(new HashSet());
+ }
+ catch (MBeanProxyCreationException ignored)
+ {
+ }
+ }
+
+ /**
+ * Start the adapter.
+ *
+ * @throws IllegalStateException if the service controller is missing
+ */
+ public void start() throws IllegalStateException
+ {
+ JMX.addNotificationListener(server, MBEAN_SERVER_DELEGATE, listener, listener,
null);
+ if (!JMX.addNotificationListener(server, ServiceControllerMBean.OBJECT_NAME,
listener, listener, null))
+ {
+ throw new IllegalStateException("The service controller is not
here");
+ }
+ }
+
+ /** Stop the adapter */
+ public void stop()
+ {
+ JMX.removeNotificationListener(server, ServiceControllerMBean.OBJECT_NAME,
listener);
+ JMX.removeNotificationListener(server, MBEAN_SERVER_DELEGATE, listener);
+ server = null;
+ watched.clear();
+ }
+
+ public void addStateListener(ObjectName name)
+ {
+ try
+ {
+ server.addNotificationListener(name, listener, listener, name);
+ watched.add(name);
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot become a listener of " + name, e);
+ }
+ }
+
+ public void removeStateListener(ObjectName name)
+ {
+ try
+ {
+ server.removeNotificationListener(name, listener);
+ watched.remove(name);
+ }
+ catch (Exception ignored)
+ {
+ }
+ }
+
+// protected void registered(ObjectName name)
+// {
+// }
+//
+// protected void unregistered(ObjectName name)
+// {
+// }
+
+ protected void created(ObjectName name)
+ {
+ }
+
+ protected void starting(ObjectName name)
+ {
+ }
+
+ protected void started(ObjectName name)
+ {
+ }
+
+ protected void stopping(ObjectName name)
+ {
+ }
+
+ protected void stopped(ObjectName name)
+ {
+ }
+
+ protected void destroyed(ObjectName name)
+ {
+ }
+
+ private class Listener implements NotificationListener, NotificationFilter
+ {
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 4049015398272819164L;
+
+ public boolean isNotificationEnabled(Notification notification)
+ {
+ return true;
+ }
+
+ public void handleNotification(Notification notification, Object handback)
+ {
+ String type = notification.getType();
+ if (type == MBeanServerNotification.REGISTRATION_NOTIFICATION)
+ {
+ MBeanServerNotification msn = (MBeanServerNotification)notification;
+ ObjectName name = msn.getMBeanName();
+ // registered(name);
+ }
+ else if (type == MBeanServerNotification.UNREGISTRATION_NOTIFICATION)
+ {
+ MBeanServerNotification msn = (MBeanServerNotification)notification;
+ ObjectName name = msn.getMBeanName();
+ // unregistered(name);
+ }
+ else if (type == AttributeChangeNotification.ATTRIBUTE_CHANGE)
+ {
+ AttributeChangeNotification acn = (AttributeChangeNotification)notification;
+ ObjectName name = (ObjectName)handback;
+ if ("State".equals(acn.getAttributeName()))
+ {
+ int state = ((Integer)acn.getNewValue()).intValue();
+ switch (state)
+ {
+ case ServiceMBean.STARTING:
+ starting(name);
+ break;
+ case ServiceMBean.STARTED:
+ started(name);
+ break;
+ case ServiceMBean.STOPPING:
+ stopping(name);
+ break;
+ case ServiceMBean.STOPPED:
+ stopped(name);
+ break;
+ default:
+ }
+ }
+ }
+ else if (type == ServiceMBean.CREATE_EVENT)
+ {
+ ObjectName name = (ObjectName)notification.getUserData();
+ if (watched.contains(name))
+ {
+ created(name);
+ }
+ }
+ else if (type == ServiceMBean.DESTROY_EVENT)
+ {
+ ObjectName name = (ObjectName)notification.getUserData();
+ if (watched.contains(name))
+ {
+ destroyed(name);
+ }
+ }
+ }
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifeCycleAdapter.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifecycleInvoker.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifecycleInvoker.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifecycleInvoker.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+
+/**
+ * A jmx method invoker based on the lifecycle.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class LifecycleInvoker extends AbstractJBossService
+{
+
+ /** . */
+ private ObjectName target;
+
+ /** . */
+ private String onCreate;
+
+ /** . */
+ private String onStart;
+
+ /** . */
+ private String onStop;
+
+ /** . */
+ private String onDestroy;
+
+ public ObjectName getTarget()
+ {
+ return target;
+ }
+
+ public void setTarget(ObjectName target)
+ {
+ this.target = target;
+ }
+
+ public String getOnCreate()
+ {
+ return onCreate;
+ }
+
+ public void setOnCreate(String onCreate)
+ {
+ this.onCreate = onCreate;
+ }
+
+ public String getOnStart()
+ {
+ return onStart;
+ }
+
+ public void setOnStart(String onStart)
+ {
+ this.onStart = onStart;
+ }
+
+ public String getOnStop()
+ {
+ return onStop;
+ }
+
+ public void setOnStop(String onStop)
+ {
+ this.onStop = onStop;
+ }
+
+ public String getOnDestroy()
+ {
+ return onDestroy;
+ }
+
+ public void setOnDestroy(String onDestroy)
+ {
+ this.onDestroy = onDestroy;
+ }
+
+ private void invoke(String methodName)
+ {
+ try
+ {
+ log.debug("About to invoke " + methodName + " on mbean " +
target);
+ server.invoke(target, methodName, new Object[0], new String[0]);
+ }
+ catch (InstanceNotFoundException e)
+ {
+ log.debug("The mbean " + target + " does not exist and " +
methodName + " cannot be invoked");
+ }
+ catch (MBeanException e)
+ {
+ Throwable t = e.getCause();
+ log.error("The mbean " + target + " threw an exception during the
invocation of the method " + methodName, t);
+ }
+ catch (ReflectionException e)
+ {
+ log.error("The mbean " + target + " invocation of method " +
methodName, e);
+ }
+ }
+
+ protected void createService() throws Exception
+ {
+ if (onCreate != null)
+ {
+ invoke(onCreate);
+ }
+ }
+
+ protected void startService() throws Exception
+ {
+ if (onStart != null)
+ {
+ invoke(onStart);
+ }
+ }
+
+ protected void stopService() throws Exception
+ {
+ if (onStop != null)
+ {
+ invoke(onStop);
+ }
+ }
+
+ protected void destroyService() throws Exception
+ {
+ if (onDestroy != null)
+ {
+ invoke(onDestroy);
+ }
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/LifecycleInvoker.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjection.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjection.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjection.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,130 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import org.jboss.mx.interceptor.Interceptor;
+import org.jboss.mx.server.Invocation;
+import org.jboss.mx.server.registry.MBeanEntry;
+import org.jboss.mx.util.MBeanProxyExt;
+
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class POJOInjection
+{
+
+ /** The dispatcher. */
+ private final Interceptor dispatcher;
+
+ /** The setter invocation. */
+ private final Invocation setter;
+
+ /** The mbean server. */
+ private final MBeanServer server;
+
+ /** The pojo object name. */
+ private final ObjectName pojoName;
+
+ /** The injection status. */
+ private boolean injected;
+
+ public POJOInjection(MBeanProxyExt pojoHandler, Interceptor dispatcher, Invocation
setter)
+ {
+ this.dispatcher = dispatcher;
+ this.setter = setter;
+ this.server = pojoHandler.getMBeanProxyMBeanServer();
+ this.pojoName = pojoHandler.getMBeanProxyObjectName();
+ this.injected = false;
+ }
+
+ public ObjectName getPOJOName()
+ {
+ return pojoName;
+ }
+
+ public synchronized void resolve()
+ {
+ if (!injected)
+ {
+ if (server.isRegistered(pojoName))
+ {
+ try
+ {
+ // Get the mbean entry
+ MBeanEntry entry = (MBeanEntry)server.invoke(new
ObjectName("JMImplementation:type=MBeanRegistry"), "get", new
Object[]{pojoName}, new String[]{ObjectName.class.getName()});
+
+ //
+ if (entry != null)
+ {
+ // Get the managed resource (aka the service)
+ Object pojo = entry.getInvoker().getResource();
+
+ // Replace the proxy by the service
+ setter.getArgs()[0] = pojo;
+
+ // Dispatch the invocation finally
+ dispatcher.invoke(setter);
+
+ //
+ this.injected = true;
+ }
+ }
+ catch (InstanceNotFoundException ignore)
+ {
+ // It means that between the registration check and the get
+ // the service was removed
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ else
+ {
+ if (!server.isRegistered(pojoName))
+ {
+ try
+ {
+ // Replace the proxy by the service
+ setter.getArgs()[0] = null;
+
+ // Dispatch the invocation finally
+ dispatcher.invoke(setter);
+
+ //
+ this.injected = false;
+ }
+ catch (Throwable e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjector.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjector.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/as/system/POJOInjector.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.as.system;
+
+import javax.management.MBeanServerNotification;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class POJOInjector implements NotificationListener
+{
+
+ /** . */
+ private final Map injections;
+
+ public POJOInjector()
+ {
+ this.injections = new HashMap();
+ }
+
+ public void addInjection(POJOInjection injection)
+ {
+ injections.put(injection.getPOJOName(), injection);
+
+ //
+ injection.resolve();
+ }
+
+ public void handleNotification(Notification notification, Object object)
+ {
+ String type = notification.getType();
+ if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(type) ||
MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type))
+ {
+ MBeanServerNotification msn = (MBeanServerNotification)notification;
+ ObjectName name = msn.getMBeanName();
+ POJOInjection injection = (POJOInjection)injections.get(name);
+ if (injection != null)
+ {
+ injection.resolve();
+ }
+ }
+ }
+}
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvoker.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvoker.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvoker.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,245 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.ha;
+
+import org.jboss.ha.singleton.HASingletonSupport;
+import org.jboss.invocation.Invocation;
+import org.jboss.naming.Util;
+
+import javax.management.ObjectName;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import java.lang.reflect.Method;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class HASingletonInvoker extends HASingletonSupport implements
HASingletonInvokerMBean
+{
+ /** The proxy factory. */
+ private ObjectName proxyFactory;
+
+ /** The cached proxy. */
+ private Proxy proxy;
+
+ /** Where is bound the ha proxy. */
+ private String jndiName;
+
+ /** The callback service which this service depends on. */
+ private Callback callback;
+
+ /** The JNDI properties. */
+ private Properties jndiProperties;
+
+ /** How many time we retry on fail over. */
+ private int maxRetries;
+
+ /** How long we wait before trying a jndi lookup during fail over. */
+ private long retryWaitingTimeMS;
+
+ public long getRetryWaitingTimeMS()
+ {
+ return retryWaitingTimeMS;
+ }
+
+ public void setRetryWaitingTimeMS(long retryWaitingTimeMS)
+ {
+ this.retryWaitingTimeMS = retryWaitingTimeMS;
+ }
+
+ public int getMaxRetries()
+ {
+ return maxRetries;
+ }
+
+ public void setMaxRetries(int maxRetries)
+ {
+ this.maxRetries = maxRetries;
+ }
+
+ public Properties getJNDIProperties()
+ {
+ return jndiProperties;
+ }
+
+ public void setJNDIProperties(Properties jndiProperties)
+ {
+ this.jndiProperties = jndiProperties;
+ }
+
+ public ObjectName getProxyFactory()
+ {
+ return proxyFactory;
+ }
+
+ public void setProxyFactory(ObjectName proxyFactory)
+ {
+ this.proxyFactory = proxyFactory;
+ }
+
+ public Callback getCallback()
+ {
+ return callback;
+ }
+
+ public void setCallback(Callback callback)
+ {
+ this.callback = callback;
+ }
+
+ public String getJNDIName()
+ {
+ return jndiName;
+ }
+
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ public Proxy lookupProxy()
+ {
+ if (proxy == null)
+ {
+ try
+ {
+ InitialContext ctx = new InitialContext(jndiProperties);
+ proxy = (Proxy)ctx.lookup(jndiName);
+ }
+ catch (NamingException e)
+ {
+ log.error("Proxy " + jndiName + " not bound");
+ }
+ }
+ return proxy;
+ }
+
+ public Object invoke(String methodName, Class[] types, Object[] args) throws
Exception
+ {
+ int retries = maxRetries;
+ while (retries-- > 0)
+ {
+ try
+ {
+ Proxy proxy = lookupProxy();
+ return proxy.invoke(methodName, types, args);
+ }
+ catch (Throwable t)
+ {
+ if (!(t instanceof Error))
+ {
+ proxy = null;
+ if (retries > 0)
+ {
+ log.error("Cannot invoke proxy will retry " + retries +
" times", t);
+ try
+ {
+ log.debug("Sleeping for " + retryWaitingTimeMS + "
before trying to fail over");
+ Thread.sleep(retryWaitingTimeMS);
+ }
+ catch (InterruptedException ignore)
+ {
+ // Get out of the loop
+ retries = 0;
+ }
+ }
+ else
+ {
+ log.error("Cannot invoke proxy will no more retry", t);
+ }
+ }
+ else
+ {
+ throw (Error)t;
+ }
+ }
+ }
+ // Todo : throw exception
+ return null;
+ }
+
+ protected void startService() throws Exception
+ {
+ callback.setInvoker(this);
+
+ //
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+ super.stopService();
+
+ //
+ callback.setInvoker(null);
+ }
+
+ public void startSingleton()
+ {
+ String name = callback.getDisplayName();
+
+ //
+ try
+ {
+
+ // Start the service.
+ log.debug("Starting singleton " + name);
+ callback.startSingleton();
+ log.debug("Singleton " + name + " started");
+
+ //
+ log.debug("Binding singleton proxy " + name);
+ Object proxy = server.getAttribute(proxyFactory, "Proxy");
+ Util.bind(new InitialContext(), jndiName, proxy);
+ log.debug("Singleton proxy " + name + " bound");
+ }
+ catch (Exception e)
+ {
+ log.error("Not able to start singleton " + name + " bound",
e);
+ }
+ }
+
+ public void stopSingleton()
+ {
+ // Stop the singleton
+ if (callback != null)
+ {
+ //
+ String name = callback.getDisplayName();
+
+ //
+ log.debug("Stopping singleton proxy " + name);
+ callback.stopSingleton();
+ log.debug("Singleton " + name + " stopped");
+ }
+ }
+
+ public Object invoke(Invocation mi) throws Exception
+ {
+ Method m = mi.getMethod();
+ Object[] args = mi.getArguments();
+ return callback.invoke(m.getName(), m.getParameterTypes(), args);
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvoker.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvokerMBean.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvokerMBean.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvokerMBean.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,112 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.ha;
+
+import org.jboss.ha.singleton.HASingletonMBean;
+
+import javax.management.ObjectName;
+import java.util.Properties;
+
+/**
+ * The ha singleton invoker service extends the ha singleton service and adds the
capability to invoke the singleton
+ * service from the cluster.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public interface HASingletonInvokerMBean extends HASingletonMBean
+{
+
+ /** Get the callback of the invoker. */
+ HASingletonInvoker.Callback getCallback();
+
+ /** @see #getCallback() */
+ void setCallback(HASingletonInvoker.Callback callback);
+
+ /** Return the JNDI name under which the proxy is bound. */
+ String getJNDIName();
+
+ /** @see #getJNDIName() */
+ void setJNDIName(String jndiName);
+
+ /** Return the name of the proxy factory to use. */
+ ObjectName getProxyFactory();
+
+ /** @see #getProxyFactory() */
+ void setProxyFactory(ObjectName proxyFactory);
+
+ /** Return the JNDI configuration to lookup the proxy. */
+ Properties getJNDIProperties();
+
+ /** @see #getJNDIProperties() */
+ void setJNDIProperties(Properties jndiProperties);
+
+ /** Return the max number of retries when an invocation is done. */
+ int getMaxRetries();
+
+ /** @see #getMaxRetries() */
+ void setMaxRetries(int maxRetries);
+
+ /** Return the time that the thread will sleep before looking up a proxy during fail
over. */
+ long getRetryWaitingTimeMS();
+
+ /** @see #getRetryWaitingTimeMS() */
+ void setRetryWaitingTimeMS(long retryWaitingTimeMS);
+
+ /** Return the proxy, if it is cached then it will return the cached proxy otherwise
it will perform a JNDI lookup. */
+ HASingletonInvoker.Proxy lookupProxy();
+
+ /**
+ * Invoke the service through the invoker. When the service proxy throws an exception
the invoker waits for a
+ * specific duration and then perform a new lookup for a certain amount of time.
+ */
+ Object invoke(String methodName, Class[] types, Object[] args) throws Exception;
+
+ /** Contract layer that defines the interactions between the service and the ha
invoker. */
+ interface Callback
+ {
+ /**
+ * Set the invoker on the client, if the invoker is not null then the invoker is
available otherwise if it is null
+ * then the invoker is not available.
+ */
+ void setInvoker(HASingletonInvoker invoker);
+
+ /** Start the singleton. */
+ void startSingleton();
+
+ /** Stop the singleton. */
+ void stopSingleton();
+
+ /** Invocation callback */
+ Object invoke(String methodName, Class[] types, Object[] args) throws Exception;
+
+ /** Provide a simple display name for logging purpose. */
+ String getDisplayName();
+ }
+
+ /** The proxy interface bound in JNDI. */
+ interface Proxy
+ {
+ Object invoke(String methodName, Class[] types, Object[] args) throws Exception;
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/ha/HASingletonInvokerMBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ByteArrayBlob.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,161 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.jboss.portal.common.io.IOTools;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.sql.Blob;
+import java.sql.SQLException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public final class ByteArrayBlob implements Blob
+{
+
+ /** . */
+ byte[] _bytes;
+
+ public ByteArrayBlob(InputStream in) throws IOException
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ IOTools.copy(in, out);
+ _bytes = out.toByteArray();
+ }
+
+ public ByteArrayBlob(ByteArrayBlob that)
+ {
+ _bytes = that.getBytes(0, that._bytes.length);
+ }
+
+ public ByteArrayBlob(byte[] _bytes)
+ {
+ this._bytes = _bytes;
+ }
+
+ public ByteArrayBlob(Blob blob) throws SQLException
+ {
+ _bytes = blob.getBytes(1, (int)blob.length());
+ }
+
+ public long length()
+ {
+ return _bytes.length;
+ }
+
+ public byte[] getBytes(long pos, int length)
+ {
+ byte[] bytes = new byte[length];
+ // Why are we passing in 'pos'? It results in AOOBE.
+ //System.arraycopy(_bytes, (int)pos, bytes, 0, length);
+ System.arraycopy(_bytes, 0, bytes, 0, length);
+ return bytes;
+ }
+
+ public InputStream getBinaryStream()
+ {
+ return new ByteArrayInputStream(_bytes);
+ }
+
+ /*
+ * For JDK 1.6
+ * @see java.sql.Blob#getBinaryStream()
+ */
+ public InputStream getBinaryStream(long pos, long length)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * For JDK 1.6
+ * @see java.sql.Blob#free()
+ */
+ public void free()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int setBytes(long pos, byte[] bytes)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public int setBytes(long pos, byte[] bytes, int offset, int len)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public OutputStream setBinaryStream(long pos)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public long position(byte pattern[], long start)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public long position(Blob pattern, long start)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void truncate(long len)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public static ByteArrayBlob get(Blob blob) throws IOException, SQLException
+ {
+ if (blob instanceof ByteArrayBlob)
+ {
+ return (ByteArrayBlob)blob;
+ }
+ else
+ {
+ InputStream binaryStream = blob.getBinaryStream();
+ return new ByteArrayBlob(binaryStream);
+ }
+ }
+
+ public static ByteArrayBlob create(Blob blob) throws IOException, SQLException
+ {
+ if (blob instanceof ByteArrayBlob)
+ {
+ return new ByteArrayBlob((ByteArrayBlob)blob);
+ }
+ else
+ {
+ InputStream binaryStream = blob.getBinaryStream();
+ return new ByteArrayBlob(binaryStream);
+ }
+ }
+
+
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,165 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+
+import java.io.Serializable;
+import java.sql.Blob;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class CacheableBlobUserType implements UserType
+{
+
+ /** . */
+ private static final int[] SQL_TYPES = {Types.BLOB};
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+ public Class returnedClass()
+ {
+ return Blob.class;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException
+ {
+ if (x == y)
+ {
+ return true;
+ }
+ if (x != null && y != null)
+ {
+ try
+ {
+ ByteArrayBlob _x = ByteArrayBlob.get((Blob)x);
+ ByteArrayBlob _y = ByteArrayBlob.get((Blob)y);
+ return java.util.Arrays.equals(_x._bytes, _y._bytes);
+ }
+ catch (Exception e)
+ {
+ throw new HibernateException(e);
+ }
+ }
+ return false;
+ }
+
+ public int hashCode(Object object) throws HibernateException
+ {
+ return object.hashCode();
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
HibernateException, SQLException
+ {
+ Blob blob = rs.getBlob(names[0]);
+ return rs.wasNull() ? null : new ByteArrayBlob(blob);
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index) throws
HibernateException, SQLException
+ {
+ if (value == null)
+ {
+ st.setNull(index, Types.BLOB);
+ }
+ else
+ {
+ st.setBlob(index, (Blob)value);
+ }
+// if (value==null) {
+// st.setNull(index, Types.BLOB);
+// }
+// else {
+//
+// if (value instanceof SerializableBlob) {
+// value = ( (SerializableBlob) value ).getWrappedBlob();
+// }
+//
+// final boolean useInputStream =
session.getFactory().getDialect().useInputStreamToInsertBlob() &&
+// (value instanceof BlobImpl);
+//
+// if ( useInputStream ) {
+// BlobImpl blob = (BlobImpl) value;
+// st.setBinaryStream( index, blob.getBinaryStream(), (int) blob.length() );
+// }
+// else {
+// st.setBlob(index, (Blob) value);
+// }
+//
+// }
+ }
+
+ public Object deepCopy(Object value) throws HibernateException
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ try
+ {
+ return ByteArrayBlob.create((Blob)value);
+ }
+ catch (Exception e)
+ {
+ throw new HibernateException(e);
+ }
+ }
+
+ public boolean isMutable()
+ {
+ return true;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException
+ {
+ if (value == null)
+ {
+ return null;
+ }
+ return ((ByteArrayBlob)value)._bytes;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
+ {
+ if (cached == null)
+ {
+ return null;
+ }
+ return new ByteArrayBlob((byte[])cached);
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException
+ {
+ return original;
+ }
+
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/CacheableBlobUserType.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ContextObject.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ContextObject.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ContextObject.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+/**
+ * The contract interface for an object to obtain a context.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public interface ContextObject
+{
+ void setContext(Object context);
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ContextObject.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/DialectFactory.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/DialectFactory.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/DialectFactory.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,119 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.HibernateException;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Ripped off hibernate 3.1 that is not in 3.0. A factory for generating Dialect
instances.
+ *
+ * @author Steve Ebersole
+ * @version $Revision: 11473 $
+ */
+public class DialectFactory
+{
+
+
+ private DialectFactory()
+ {
+ }
+
+ /**
+ * Determine the appropriate Dialect to use given the database product name and major
version.
+ *
+ * @param databaseName The name of the database product (obtained from
metadata).
+ * @param databaseMajorVersion The major version of the database product (obtained
from metadata).
+ * @return An appropriate dialect instance.
+ */
+ public static String determineDialect(String databaseName, int databaseMajorVersion)
+ {
+ if (databaseName == null)
+ {
+ throw new HibernateException("Hibernate Dialect must be explicitly
set");
+ }
+
+ DatabaseDialectMapper mapper = (DatabaseDialectMapper)MAPPERS.get(databaseName);
+ if (mapper == null)
+ {
+ throw new HibernateException("Hibernate Dialect must be explicitly set for
database: " + databaseName);
+ }
+
+ return mapper.getDialectClass(databaseMajorVersion);
+ }
+
+ /**
+ * For a given database product name, instances of DatabaseDialectMapper know which
Dialect to use for different
+ * versions.
+ */
+ public static interface DatabaseDialectMapper
+ {
+ public String getDialectClass(int majorVersion);
+ }
+
+ /** A simple DatabaseDialectMapper for dialects which are independent of the
underlying database product version. */
+ public static class VersionInsensitiveMapper implements DatabaseDialectMapper
+ {
+ private String dialectClassName;
+
+ public VersionInsensitiveMapper(String dialectClassName)
+ {
+ this.dialectClassName = dialectClassName;
+ }
+
+ public String getDialectClass(int majorVersion)
+ {
+ return dialectClassName;
+ }
+ }
+
+ private static final Map MAPPERS = new HashMap();
+
+ static
+ {
+ // TODO : this is the stuff it'd be nice to move to a properties file or some
other easily user-editable place
+ MAPPERS.put("HSQL Database Engine", new
VersionInsensitiveMapper("org.hibernate.dialect.HSQLDialect"));
+ MAPPERS.put("DB2/NT", new
VersionInsensitiveMapper("org.hibernate.dialect.DB2Dialect"));
+ MAPPERS.put("MySQL", new
VersionInsensitiveMapper("org.hibernate.dialect.MySQLDialect"));
+ MAPPERS.put("PostgreSQL", new
VersionInsensitiveMapper("org.hibernate.dialect.PostgreSQLDialect"));
+ MAPPERS.put("Microsoft SQL Server Database", new
VersionInsensitiveMapper("org.hibernate.dialect.SQLServerDialect"));
+ MAPPERS.put("Microsoft SQL Server", new
VersionInsensitiveMapper("org.hibernate.dialect.SQLServerDialect"));
+ MAPPERS.put("Sybase SQL Server", new
VersionInsensitiveMapper("org.hibernate.dialect.SybaseDialect"));
+ MAPPERS.put("Informix Dynamic Server", new
VersionInsensitiveMapper("org.hibernate.dialect.InformixDialect"));
+
+ MAPPERS.put(
+ "Oracle",
+ new DatabaseDialectMapper()
+ {
+ public String getDialectClass(int majorVersion)
+ {
+ return majorVersion > 8
+ ? "org.hibernate.dialect.Oracle9Dialect"
+ : "org.hibernate.dialect.OracleDialect";
+ }
+ }
+ );
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/DialectFactory.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/HibernateProvider.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/HibernateProvider.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/HibernateProvider.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public interface HibernateProvider
+{
+ Configuration getConfig();
+
+ SessionFactory getSessionFactory();
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/HibernateProvider.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProvider.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProvider.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProvider.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.jboss.cache.TreeCache;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import javax.management.ObjectName;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class JBossTreeCacheProvider extends AbstractJBossService implements
TreeCacheProvider, JBossTreeCacheProviderMBean
+{
+
+ private ObjectName cacheName;
+
+ public ObjectName getCacheName()
+ {
+ return cacheName;
+ }
+
+ public void setCacheName(ObjectName cacheName)
+ {
+ this.cacheName = cacheName;
+ }
+
+ public TreeCache getTreeCache()
+ {
+ try
+ {
+ return (TreeCache)server.getAttribute(cacheName, "Instance");
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot get cache instance", e);
+ return null;
+ }
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProvider.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProviderMBean.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProviderMBean.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProviderMBean.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.jboss.cache.TreeCache;
+
+import javax.management.ObjectName;
+
+/**
+ */
+public interface JBossTreeCacheProviderMBean
+{
+
+ public ObjectName getCacheName();
+
+ public void setCacheName(ObjectName cacheName);
+
+ public TreeCache getTreeCache();
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JBossTreeCacheProviderMBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JMXTreeCacheProvider.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JMXTreeCacheProvider.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JMXTreeCacheProvider.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,101 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.apache.log4j.Logger;
+import org.hibernate.cache.Cache;
+import org.hibernate.cache.CacheException;
+import org.hibernate.cache.CacheProvider;
+import org.hibernate.cache.OptimisticTreeCache;
+import org.hibernate.cache.TreeCache;
+import org.jboss.mx.util.MBeanProxy;
+import org.jboss.mx.util.MBeanServerLocator;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.util.Properties;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 9317 $
+ */
+public class JMXTreeCacheProvider implements CacheProvider
+{
+
+ /** Our logger. */
+ private static final Logger log = Logger.getLogger(JMXTreeCacheProvider.class);
+
+ public boolean isMinimalPutsEnabledByDefault()
+ {
+ return true;
+ }
+
+ public Cache buildCache(String regionName, Properties properties) throws
CacheException
+ {
+ try
+ {
+ String objectNameAsString =
properties.getProperty("hibernate.cache.object_name");
+ log.debug("Uses tree cache provider with object name " +
objectNameAsString);
+
+ //
+ ObjectName providerName = ObjectName.getInstance(objectNameAsString);
+
+ //
+ MBeanServer server = MBeanServerLocator.locateJBoss();
+ TreeCacheProvider provider =
(TreeCacheProvider)MBeanProxy.get(TreeCacheProvider.class, providerName, server);
+ org.jboss.cache.TreeCache cache = provider.getTreeCache();
+
+ //Select the proper type of hibernate cache to be used
+ Cache hibernateCache = null;
+ if(cache.getNodeLockingScheme().equalsIgnoreCase("OPTIMISTIC"))
+ {
+ log.debug("Selecting Optimistic Cache");
+ hibernateCache = new OptimisticTreeCache(cache, regionName);
+ }
+ else
+ {
+ log.debug("Selecting regular Tree Cache");
+ hibernateCache = new TreeCache(cache, regionName,
cache.getTransactionManager());
+ }
+
+ return hibernateCache;
+ }
+ catch (Exception e)
+ {
+ throw new CacheException(e);
+ }
+ }
+
+ public long nextTimestamp()
+ {
+ return System.currentTimeMillis() / 100;
+ }
+
+ public void start(Properties properties) throws CacheException
+ {
+ }
+
+ public void stop()
+ {
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/JMXTreeCacheProvider.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/MagicString.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/MagicString.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/MagicString.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,123 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * An hibernate custom type that handles the fact that oracle stores an empty string as
null. That types changes the
+ * semantic of string with the fact that a returned null string is equals to an empty
string.
+ * <p/>
+ * I did not found a good name for that class so I choosed MagicString but it has nothing
magic.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class MagicString implements UserType, Serializable
+{
+
+ private static final int[] TYPES = {Types.VARCHAR};
+
+ public int[] sqlTypes()
+ {
+ return TYPES;
+ }
+
+ public Class returnedClass()
+ {
+ return String.class;
+ }
+
+ public boolean equals(Object x, Object y)
+ {
+ if (x == y)
+ {
+ return true;
+ }
+ if (x == null)
+ {
+ return ((String)y).length() == 0;
+ }
+ else if (y == null)
+ {
+ return ((String)x).length() == 0;
+ }
+ return x.equals(y);
+ }
+
+ public Object deepCopy(Object value)
+ {
+ return value;
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws
HibernateException, SQLException
+ {
+ String value = (String)Hibernate.STRING.nullSafeGet(resultSet, names[0]);
+ if (value != null)
+ {
+ return value;
+ }
+ else
+ {
+ return "";
+ }
+ }
+
+ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws
HibernateException, SQLException
+ {
+ Hibernate.STRING.nullSafeSet(statement, value, index);
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
+ {
+ return cached;
+ }
+
+ public Serializable disassemble(Object value)
+ {
+ return (Serializable)value;
+ }
+
+ public int hashCode(Object object) throws HibernateException
+ {
+ return object.hashCode();
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException
+ {
+ return original;
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/MagicString.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ObjectContextualizer.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ObjectContextualizer.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ObjectContextualizer.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,65 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.SessionFactory;
+import org.hibernate.event.EventListeners;
+import org.hibernate.event.PostLoadEvent;
+import org.hibernate.event.PostLoadEventListener;
+import org.hibernate.impl.SessionFactoryImpl;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class ObjectContextualizer
+{
+
+ public Object context;
+
+ public ObjectContextualizer(Object context)
+ {
+ this.context = context;
+ }
+
+ public void attach(SessionFactory sessionFactory)
+ {
+ EventListeners listeners =
((SessionFactoryImpl)sessionFactory).getEventListeners();
+ PostLoadEventListener[] lels1 = listeners.getPostLoadEventListeners();
+ PostLoadEventListener[] lels2 = new PostLoadEventListener[lels1.length + 1];
+ System.arraycopy(lels1, 0, lels2, 1, lels1.length);
+ lels2[0] = new PostLoadEventListener()
+ {
+ public void onPostLoad(PostLoadEvent postLoadEvent)
+ {
+ Object entity = postLoadEvent.getEntity();
+ if (entity instanceof ContextObject)
+ {
+ ContextObject object = (ContextObject)entity;
+ object.setContext(context);
+ }
+ }
+ };
+ listeners.setPostLoadEventListeners(lels2);
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/ObjectContextualizer.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/OracleStringUserType.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/OracleStringUserType.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/OracleStringUserType.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,133 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.Oracle9Dialect;
+import org.hibernate.dialect.OracleDialect;
+import org.hibernate.usertype.UserType;
+
+/**
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class OracleStringUserType implements UserType
+{
+
+ private static final int[] SQL_TYPES = {Types.VARCHAR};
+
+ private static final String EMPTY_STRING = "__EMPTY_STRING__";
+
+ public Object assemble(Serializable arg0, Object arg1) throws HibernateException
+ {
+ return arg0;
+ }
+
+ public Object deepCopy(Object value) throws HibernateException
+ {
+ return value;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException
+ {
+ return (Serializable)value;
+ }
+
+ public boolean equals(Object arg0, Object arg1) throws HibernateException
+ {
+ if (arg0 == arg1)
+ {
+ return true;
+ }
+ if ((arg0 == null) || (arg1 == null))
+ {
+ return false;
+ }
+ return arg0.equals(arg1);
+ }
+
+ public int hashCode(Object arg0) throws HibernateException
+ {
+ return arg0.hashCode();
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws
HibernateException, SQLException
+ {
+ String dbValue = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
+
+ if (dbValue == null)
+ {
+ return null;
+ }
+ else if (dbValue.equals(EMPTY_STRING))
+ {
+ return "";
+ }
+ else
+ {
+ return dbValue;
+ }
+ }
+
+ public void nullSafeSet(PreparedStatement st, Object value, int index) throws
HibernateException, SQLException
+ {
+ if (value.equals(""))
+ {
+ Hibernate.STRING.nullSafeSet(st, EMPTY_STRING, index);
+ }
+ else
+ {
+ Hibernate.STRING.nullSafeSet(st, value, index);
+ }
+ }
+
+ public Object replace(Object arg0, Object arg1, Object arg2) throws
HibernateException
+ {
+ return arg0;
+ }
+
+ public Class returnedClass()
+ {
+ return String.class;
+ }
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+}
+
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/QNameUserType.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/QNameUserType.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/QNameUserType.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,138 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.Hibernate;
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * An hibernate user type to persist the
<code>javax.xml.namespace.QName</code> class on two database columns.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class QNameUserType implements UserType
+{
+
+ /** . */
+ private static final int[] SQL_TYPES = {Hibernate.STRING.sqlType()};
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+ public Class returnedClass()
+ {
+ return QName.class;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException
+ {
+ if (x == y)
+ {
+ return true;
+ }
+ else if (x == null || y == null)
+ {
+ return false;
+ }
+ else
+ {
+ return x.equals(y);
+ }
+ }
+
+ public int hashCode(Object x) throws HibernateException
+ {
+ return x.hashCode();
+ }
+
+ public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws
HibernateException, SQLException
+ {
+ // Test nullity
+ String value = resultSet.getString(names[0]);
+ if (resultSet.wasNull())
+ {
+ return null;
+ }
+
+ //
+ int pos = value.indexOf(':');
+ if (pos == -1)
+ {
+ return new QName(value);
+ }
+ else
+ {
+ String namespaceURI = value.substring(0, pos);
+ String localPart = value.substring(pos + 1);
+ return new QName(namespaceURI, localPart);
+ }
+ }
+
+ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws
HibernateException, SQLException
+ {
+ if (value == null)
+ {
+ statement.setNull(index, SQL_TYPES[0]);
+ }
+ else
+ {
+ QName qname = (QName)value;
+ statement.setString(index, qname.getNamespaceURI() + ":" +
qname.getLocalPart());
+ }
+ }
+
+ public Object deepCopy(Object value) throws HibernateException
+ {
+ return value;
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException
+ {
+ return (QName)value;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
+ {
+ return cached;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException
+ {
+ return original;
+ }
+}
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,449 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import bsh.EvalError;
+import bsh.Interpreter;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.exception.SQLGrammarException;
+import org.hibernate.metadata.ClassMetadata;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.tool.hbm2ddl.SchemaUpdate;
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.net.URLTools;
+import org.jboss.portal.common.util.CLResourceLoader;
+import org.jboss.portal.common.util.LoaderResource;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * Configures and binds the hibernate session factory.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:boleslaw.dawidowicz@jboss.com">Boleslaw
Dawidowicz</a>
+ * @version $Revision: 12426 $
+ */
+public class SessionFactoryBinder extends AbstractJBossService implements
HibernateProvider
+{
+
+ /** doCheck result - schema ok */
+ private static final int RESULT_NONE = 0;
+
+ /** doCheck result - schema need updates */
+ private static final int RESULT_UPDATE = 1;
+
+ /** doCheck result - schema not exist */
+ private static final int RESULT_CREATE = 2;
+
+ /** . */
+ private String configLocation;
+
+ /** . */
+ private String setupLocation;
+
+ /** If true checks the schema existence on start and create it if necessary. */
+ private boolean doChecking;
+
+ /** The session factory. */
+ private SessionFactory sessionFactory;
+
+ /** Where we configure hibernate. */
+ private URL configURL;
+
+ /** . */
+ private LoaderResource setupResource;
+
+ /** The hibernate configuration object. */
+ protected Configuration config;
+
+ /**
+ *
+ */
+ private String dialectName;
+
+ /**
+ *
+ */
+ protected String jndiName;
+
+ public boolean getDoChecking()
+ {
+ return doChecking;
+ }
+
+ public void setDoChecking(boolean doChecking)
+ {
+ this.doChecking = doChecking;
+ }
+
+ public String getConfigLocation()
+ {
+ return configLocation;
+ }
+
+ public void setConfigLocation(String configLocation)
+ {
+ this.configLocation = configLocation;
+ }
+
+ public String getSetupLocation()
+ {
+ return setupLocation;
+ }
+
+ public void setSetupLocation(String setupLocation)
+ {
+ this.setupLocation = setupLocation;
+ }
+
+ public URL getConfigURL()
+ {
+ return configURL;
+ }
+
+ public LoaderResource getSetupResource()
+ {
+ return setupResource;
+ }
+
+ public Configuration getConfig()
+ {
+ return config;
+ }
+
+ public SessionFactory getSessionFactory()
+ {
+ return sessionFactory;
+ }
+
+ public String getDialectName()
+ {
+ return dialectName;
+ }
+
+ public String getJNDIName()
+ {
+ return jndiName;
+ }
+
+ public void setJNDIName(String jndiName)
+ {
+ this.jndiName = jndiName;
+ }
+
+ /** During this step the hibernate configuration is created. */
+ protected void createService() throws Exception
+ {
+ // Setup URLs
+ if (configLocation == null)
+ {
+ throw new Exception("The config location is null");
+ }
+ configURL =
Thread.currentThread().getContextClassLoader().getResource(configLocation);
+ if (configURL == null)
+ {
+ throw new Exception("The config " + configLocation + " does not
exist");
+ }
+ if (!URLTools.exists(configURL))
+ {
+ throw new Exception("The config " + configURL + " does not
exist");
+ }
+
+ //
+ if (setupLocation != null)
+ {
+ setupResource = new CLResourceLoader().getResource(setupLocation);
+ }
+
+ // Perform configuration
+ config = new Configuration();
+ config.configure(configURL);
+
+ // Force transaction manager lookup class and JTA env
+ setPropertyIfAbsent("transaction.auto_close_session", "true");
+ setPropertyIfAbsent("transaction.flush_before_completion",
"true");
+ setPropertyIfAbsent("hibernate.transaction.flush_before_completion",
"true");
+ setPropertyIfAbsent("hibernate.transaction.factory_class",
"org.hibernate.transaction.JTATransactionFactory");
+ setPropertyIfAbsent("hibernate.transaction.manager_lookup_class",
"org.hibernate.transaction.JBossTransactionManagerLookup");
+
+ // Set JNDI name if present and absent
+ if (jndiName != null)
+ {
+ setPropertyIfAbsent("hibernate.session_factory_name", jndiName);
+ }
+ }
+
+ private void setPropertyIfAbsent(String name, String value)
+ {
+ if (config.getProperty(name) == null)
+ {
+ config.setProperty(name, value);
+ }
+ }
+
+ /** During this step the session factory is created and the content creation is
triggered. */
+ protected void startService() throws Exception
+ {
+ // Detect the dialect if necessary
+ dialectName = config.getProperty(Environment.DIALECT);
+ if (dialectName == null)
+ {
+ String dataSourceJNDI = config.getProperty(Environment.DATASOURCE);
+ log.debug("Detecting dialect with datasource " + dataSourceJNDI +
" ...");
+ DataSource ds = (DataSource)new InitialContext().lookup(dataSourceJNDI);
+ Connection conn = null;
+ try
+ {
+ conn = ds.getConnection();
+ DatabaseMetaData meta = conn.getMetaData();
+ String databaseName = meta.getDatabaseProductName();
+ int databaseMajorVersion = getDatabaseMajorVersion(meta);
+ dialectName = DialectFactory.determineDialect(databaseName,
databaseMajorVersion);
+ config.setProperty(Environment.DIALECT, dialectName);
+ log.debug("Detected dialect " + dialectName + ", database is
(" + databaseName + "," + databaseMajorVersion + ")");
+ }
+ finally
+ {
+ IOTools.safeClose(conn);
+ }
+ }
+ log.debug("Using dialect " + dialectName);
+ if ("org.hibernate.dialect.HSQLDialect".equals(dialectName))
+ {
+ log.warn("You are using the file based HSQL database, this is not
recommended on a production environment and will not work properly on a clustered
environment.");
+ }
+
+ //
+ createSessionFactory();
+
+ if (doChecking)
+ {
+ //check the schema
+ int check = doCheck();
+ switch (check)
+ {
+ case RESULT_NONE:
+ break;
+ case RESULT_UPDATE:
+ updateSchema();
+ break;
+ case RESULT_CREATE:
+ createSchema();
+ createContent();
+ break;
+ }
+ }
+ }
+
+ /** During this step the session factory is destroyed. */
+ protected void stopService() throws Exception
+ {
+ destroySessionFactory();
+ }
+
+ /** During this step the hibernate config is unreferenced. */
+ protected void destroyService() throws Exception
+ {
+ config = null;
+ }
+
+ public int doCheck()
+ {
+ Session session = null;
+ int numOfChecks = 0;
+ int bad = 0;
+ try
+ {
+ session = sessionFactory.openSession();
+ Collection values = sessionFactory.getAllClassMetadata().values();
+ numOfChecks = values.size();
+ for (Iterator i = values.iterator(); i.hasNext();)
+ {
+ ClassMetadata cmd = (ClassMetadata)i.next();
+ Query query = session.createQuery("from " + cmd.getEntityName());
+ query.setFirstResult(0);
+ query.setMaxResults(0);
+ try
+ {
+ query.list();
+ }
+ catch (SQLGrammarException e)
+ {
+ // We consider that exception means that the schema does not exist
+ bad++;
+ }
+ }
+ }
+ finally
+ {
+ IOTools.safeClose(session);
+ }
+ // There was no sql grammar exception - schema is ok!
+ if (bad == 0)
+ {
+ log.debug("The schema was checked as valid");
+ //do nothing
+ return RESULT_NONE;
+ }
+ // There is no existing valid schema;
+ else if (bad == numOfChecks)
+ {
+ log.debug("The schema was checked as not exists");
+ // Totaly invalid schema
+ return RESULT_CREATE;
+ }
+ // Schema is partialy corrupted
+ else if (bad < numOfChecks)
+ {
+ // Schema needs updates;
+ log.debug("The schema was checked as need updates");
+ return RESULT_UPDATE;
+ }
+
+ // If here something gone wrong...
+ log.debug("The schema was checked as need to be created");
+ return RESULT_CREATE;
+ }
+
+
+ public void createSchema()
+ {
+ log.debug("Creating database schema");
+ try
+ {
+ SchemaExport export = new SchemaExport(config);
+ export.create(false, true);
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot create schema", e);
+ }
+ }
+
+ public void destroySchema()
+ {
+ log.debug("Destroying database schema");
+ try
+ {
+ SchemaExport export = new SchemaExport(config);
+ export.drop(false, true);
+ }
+ catch (Exception e)
+ {
+ log.error("Cannot destroy schema", e);
+ }
+ }
+
+ public void createContent()
+ {
+ if (setupResource != null)
+ {
+ if (setupResource.exists())
+ {
+ try
+ {
+ log.info("Creating database content");
+ String script = setupResource.asString("UTF-8");
+
+ // Create an interpreter and configures it
+ Interpreter interpreter = new Interpreter();
+
interpreter.setClassLoader(Thread.currentThread().getContextClassLoader());
+ interpreter.setOut(System.out);
+ interpreter.set("SessionFactory", sessionFactory);
+ interpreter.eval(script);
+ }
+ catch (EvalError e)
+ {
+ log.error("Error in the bsh script", e);
+ }
+ catch (IllegalStateException e)
+ {
+ log.error("Cannot load setup script", e);
+ }
+ }
+ else
+ {
+ log.warn("There is a setup URL but the not valid " +
setupResource);
+ }
+ }
+ }
+
+ public void updateSchema()
+ {
+ log.debug("Updating database schema");
+ SchemaUpdate update = new SchemaUpdate(config);
+ update.execute(false, true);
+ }
+
+ /** Create the session factory. */
+ protected void createSessionFactory() throws Exception
+ {
+ sessionFactory = config.buildSessionFactory();
+ }
+
+ /** Close the session factory if it is not null. */
+ protected void destroySessionFactory()
+ {
+ if (sessionFactory != null)
+ {
+ sessionFactory.close();
+ sessionFactory = null;
+ }
+ else
+ {
+ log.debug("No session factory to close");
+ }
+ }
+
+ private int getDatabaseMajorVersion(DatabaseMetaData meta)
+ {
+ try
+ {
+ Method gdbmvMethod =
DatabaseMetaData.class.getMethod("getDatabaseMajorVersion", null);
+ return ((Integer)gdbmvMethod.invoke(meta, null)).intValue();
+ }
+ catch (NoSuchMethodException nsme)
+ {
+ return 0;
+ }
+ catch (Throwable t)
+ {
+ log.debug("could not get database version from JDBC metadata");
+ return 0;
+ }
+ }
+
+}
+
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/StringWrapperUserType.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/StringWrapperUserType.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/StringWrapperUserType.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,137 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.hibernate.HibernateException;
+import org.hibernate.usertype.UserType;
+
+import java.io.Serializable;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public abstract class StringWrapperUserType implements UserType, Serializable
+{
+
+ private static final int[] SQL_TYPES = {Types.VARCHAR};
+
+ public Object fromNull()
+ {
+ return null;
+ }
+
+ public String toNull()
+ {
+ return null;
+ }
+
+ public abstract Object fromString(String name);
+
+ public abstract String toString(Object value);
+
+ public int[] sqlTypes()
+ {
+ return SQL_TYPES;
+ }
+
+ public boolean equals(Object x, Object y) throws HibernateException
+ {
+ if (x == y)
+ {
+ return true;
+ }
+ else if (x == null || y == null)
+ {
+ return false;
+ }
+ else
+ {
+ return x.equals(y);
+ }
+ }
+
+ public int hashCode(Object x) throws HibernateException
+ {
+ return x.hashCode();
+ }
+
+ public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner) throws
HibernateException, SQLException
+ {
+ String string = resultSet.getString(names[0]);
+
+ //
+ if (resultSet.wasNull())
+ {
+ return fromNull();
+ }
+ else
+ {
+ return fromString(string);
+ }
+ }
+
+ public void nullSafeSet(PreparedStatement statement, Object value, int index) throws
HibernateException, SQLException
+ {
+ String string = value == null ? toNull() : toString(value);
+
+ //
+ if (string == null)
+ {
+ statement.setNull(index, Types.VARCHAR);
+ }
+ else
+ {
+ statement.setString(index, string);
+ }
+ }
+
+ public Object deepCopy(Object value) throws HibernateException
+ {
+ return value;
+ }
+
+ public boolean isMutable()
+ {
+ return false;
+ }
+
+ public Serializable disassemble(Object value) throws HibernateException
+ {
+ return (Serializable)value;
+ }
+
+ public Object assemble(Serializable cached, Object owner) throws HibernateException
+ {
+ return cached;
+ }
+
+ public Object replace(Object original, Object target, Object owner) throws
HibernateException
+ {
+ return original;
+ }
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/StringWrapperUserType.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/TreeCacheProvider.java
===================================================================
---
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/TreeCacheProvider.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/TreeCacheProvider.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,37 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.jems.hibernate;
+
+import org.jboss.cache.TreeCache;
+
+/**
+ * Provide a tree cache. <code>org.jboss.cache.TreeCache</code> is a concrete
class and cannot be proxy injected. This
+ * interface enable injection and gives a way to the dependant to retrieve the cache.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public interface TreeCacheProvider
+{
+ TreeCache getTreeCache();
+}
Property changes on:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/jems/hibernate/TreeCacheProvider.java
___________________________________________________________________
Name: svn:executable
+ *
Added:
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/ClassicService.java
===================================================================
--- modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/ClassicService.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/ClassicService.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.test.jems;
+
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class ClassicService extends AbstractJBossService
+{
+
+ /** . */
+ private String string;
+
+ protected void createService()
+ {
+ System.out.println("create callback");
+ }
+
+ protected void startService()
+ {
+ System.out.println("start callback");
+ }
+
+ protected void stopService()
+ {
+ System.out.println("stop callback");
+ }
+
+ protected void destroyService()
+ {
+ System.out.println("destroy callback");
+ }
+
+ public void operation()
+ {
+ System.out.println("operation called");
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+}
Added: modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/POJOService.java
===================================================================
--- modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/POJOService.java
(rev 0)
+++
modules/jems/trunk/jems/src/main/java/org/jboss/portal/test/jems/POJOService.java 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.portal.test.jems;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ */
+public class POJOService
+{
+
+ /** . */
+ private String string;
+
+ public void create()
+ {
+ System.out.println("create callback");
+ }
+
+ public void start()
+ {
+ System.out.println("start callback");
+ }
+
+ public void stop()
+ {
+ System.out.println("stop callback");
+ }
+
+ public void destroy()
+ {
+ System.out.println("destroy callback");
+ }
+
+ public void operation()
+ {
+ System.out.println("operation called");
+ }
+
+ public String getString()
+ {
+ return string;
+ }
+
+ public void setString(String string)
+ {
+ this.string = string;
+ }
+}
Added:
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/META-INF/jboss-service.xml
===================================================================
---
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/META-INF/jboss-service.xml
(rev 0)
+++
modules/jems/trunk/jems/src/main/resources/pojo-service-sar/META-INF/jboss-service.xml 2009-07-01
16:12:36 UTC (rev 13511)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2006, Red Hat Middleware, LLC, 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<server>
+
+ <!-- -->
+ <mbean
+ code="org.jboss.portal.test.jems.POJOService"
+ name="portal.test:service=POJO"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+
+ <!-- -->
+ <mbean
+ code="org.jboss.portal.test.jems.ClassicService"
+ name="portal.test:service=Classic"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+</server>
Added: modules/jems/trunk/pom.xml
===================================================================
--- modules/jems/trunk/pom.xml (rev 0)
+++ modules/jems/trunk/pom.xml 2009-07-01 16:12:36 UTC (rev 13511)
@@ -0,0 +1,35 @@
+<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>
+ <groupId>org.jboss.portal.jems</groupId>
+ <artifactId>module-aggregator</artifactId>
+ <packaging>pom</packaging>
+ <name>JBoss Portal JEMS support</name>
+ <version>1.0.0-SNAPSHOT</version>
+ <
url>http://www.jboss.org/jbossportal</url>
+
+ <dependencies/>
+
+ <!--Repository definition needed to deploy artifacts into JBoss maven
repositories-->
+ <distributionManagement>
+ <repository>
+ <!--Copy the distribution jar file to a local checkout of the maven
repository
+ - This variable can be set in $MAVEN_HOME/conf/settings.xml-->
+ <id>repository.jboss.org</id>
+ <url>file://${jboss.repository.root}</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <
url>dav:https://snapshots.jboss.org/maven2</url>
+ <uniqueVersion>true</uniqueVersion>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <modules>
+ <module>build</module>
+ <module>jems</module>
+ </modules>
+
+
+</project>
\ No newline at end of file