portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rwat...@apache.org
Subject svn commit: r735948 [1/2] - in /portals/jetspeed-2/portal/branches/JPA_BRANCH: components/jetspeed-capability/ components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/ components/jetspeed-capability/src/main/java/org/apache/j...
Date Tue, 20 Jan 2009 06:54:51 GMT
Author: rwatler
Date: Mon Jan 19 22:54:50 2009
New Revision: 735948

URL: http://svn.apache.org/viewvc?rev=735948&view=rev
Log:
JPA Capabilities Component Integration
-------------------------------------------
- add JPA support for capabilities component
- simple addition of JPA_VERSION only schema changes required
- TODO: strip bean name specified component persistent objects since this will not really work in practice with either OJB/JPA.


Added:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManager.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManagerContext.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilityImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ClientImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/JetspeedCapabilities.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MediaTypeImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MimeTypeImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/persistence.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestOpenJPACapability.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/resources/jndi.properties
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/resources/jpa-capabilities.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/resources/log4j.properties
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/resources/openjpa-capabilities.xml
Modified:
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/pom.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/folder/jpa/FolderImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/LinkImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/PageImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-page-manager/src/main/java/org/apache/jetspeed/om/page/jpa/PageSecurityImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/AbstractProfilingRule.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-profiler/src/main/java/org/apache/jetspeed/profiler/rules/jpa/PrincipalRuleImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletentity/jpa/PortletEntityImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletpreferences/jpa/DatabasePreference.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/components/portletregistry/jpa/PortletRegistryImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/PortletApplicationDefinitionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-registry/src/main/java/org/apache/jetspeed/om/portlet/jpa/PortletDefinitionImpl.java
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/ddl-schema/phase1-schema.xml
    portals/jetspeed-2/portal/branches/JPA_BRANCH/jetspeed-portal-resources/src/main/resources/ddl/mssql/create-schema.sql

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/pom.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/pom.xml?rev=735948&r1=735947&r2=735948&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/pom.xml (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/pom.xml Mon Jan 19 22:54:50 2009
@@ -104,6 +104,48 @@
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>openjpa-maven-plugin</artifactId>
+        <version>1.0-alpha</version>
+        <executions>
+          <execution>
+            <id>org.apache.jetspeed.capabilities.jpa</id>
+            <phase>process-classes</phase>
+            <goals>
+              <goal>enhance</goal>
+            </goals>
+            <configuration>
+              <classes>${project.build.directory}/classes/org/apache/jetspeed/capabilities/jpa</classes>                   	  
+              <toolProperties>                      	 
+                <property>
+                  <name>addDefaultConstructor</name>
+                  <value>true</value>
+                </property>
+                <property>
+                  <name>enforcePropertyRestrictions</name>
+                  <value>true</value>
+                </property>
+              </toolProperties>
+            </configuration>
+          </execution>
+        </executions>
+        <dependencies>
+          <!-- rule objects implement Jetspeed APIs -->
+          <dependency>
+            <groupId>${pom.groupId}</groupId>
+            <artifactId>jetspeed-api</artifactId>
+            <version>${pom.version}</version>
+          </dependency>
+          <!-- force upgrade of JPA for plugin -->
+          <dependency>
+            <groupId>org.apache.openjpa</groupId>
+            <artifactId>openjpa-persistence-jdbc</artifactId>
+            <version>${openjpa.version}</version>
+            <scope>runtime</scope>
+          </dependency>
+        </dependencies>
+      </plugin>
     </plugins>
     <testResources>
       <testResource>
@@ -113,4 +155,4 @@
     </testResources>
   </build>
   
-</project>
\ No newline at end of file
+</project>

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java?rev=735948&r1=735947&r2=735948&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/impl/CapabilityMapImpl.java Mon Jan 19 22:54:50 2009
@@ -35,10 +35,9 @@
  * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
  * @version $Id$
  */
-class CapabilityMapImpl implements CapabilityMap
+public class CapabilityMapImpl implements CapabilityMap
 {
-    private static final Log log =
-        LogFactory.getLog(JetspeedCapabilities.class);
+    private static final Log log = LogFactory.getLog(CapabilityMapImpl.class);
     
     // Members
     private String useragent; // User agent for request

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManager.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManager.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManager.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManager.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.capabilities.jpa;
+
+import javax.persistence.EntityManager;
+
+/**
+ * CapabilitiesManager
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public interface CapabilitiesManager
+{
+    /**
+     * Return entity manager associated with current thread from
+     * registered context or default transactional entity manager
+     * created for this request.
+     * 
+     * @return entity manager.
+     */
+    public EntityManager getEntityManager();
+
+    /**
+     * Register capabilities manager context with current thread.
+     * 
+     * @param context capabilities manager context.
+     */
+    public void registerContext(Object context);
+
+    /**
+     * Get capabilities manager context registered with current thread.
+     * 
+     * @return capabilities manager context.
+     */
+    public Object getContext();
+
+    /**
+     * Unregister capabilities manager context with current thread.
+     * 
+     * @param context capabilities manager context.
+     */
+    public void unregisterContext(Object context);
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManagerContext.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManagerContext.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManagerContext.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilitiesManagerContext.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.capabilities.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+
+/**
+ * CapabilitiesManagerContext
+ * 
+ * Stateful object uses to hold JPA extended entity manager.
+ * 
+ * @author <a href="mailto:rwatler@apache.org">Randy Watler</a>
+ * @version $Id: $
+ */
+public class CapabilitiesManagerContext
+{
+    private EntityManager extendedEntityManager;
+    private CapabilitiesManager capabilitiesManager;
+
+    /**
+     * Set extended conversational entity manager instance for context.
+     * 
+     * @param entityManager injected entity manager.
+     */
+    @PersistenceContext (type=PersistenceContextType.EXTENDED, unitName="jetspeed-capabilities")
+    public void setExtendedEntityManager(EntityManager entityManager)
+    {
+        extendedEntityManager = entityManager;
+    }
+    
+    /**
+     * Get extended conversational entity manager instance for context.
+     * 
+     * @return entity manager.
+     */
+    public EntityManager getExtendedEntityManager()
+    {
+        return extendedEntityManager;
+    }
+    
+    /**
+     * Set capabilities manager associated with context.
+     * 
+     * @param capabilitiesManager
+     */
+    public void setCapabilitiesManager(CapabilitiesManager capabilitiesManager)
+    {
+        this.capabilitiesManager = capabilitiesManager;
+    }
+    
+    /**
+     * Initialize context by registering with capabilitiesManager on creating thread.
+     */
+    public void initialize()
+    {
+        capabilitiesManager.registerContext(this);
+    }
+
+    /**
+     * Terminate context by unregistering with capabilitiesManager on creating thread.
+     */
+    public void terminate()
+    {
+        capabilitiesManager.unregisterContext(this);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilityImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilityImpl.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilityImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/CapabilityImpl.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.capabilities.jpa;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.NamedQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.apache.jetspeed.capabilities.Capability;
+
+/**
+ * Capability implementation class.
+ *
+ * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
+ * @version $Id: CapabilityImpl.java 517719 2007-03-13 15:05:48Z ate $
+ */
+@Entity (name="Capability")
+@Table (name="CAPABILITY")
+@NamedQueries ({@NamedQuery(name="CAPABILITIES", query="select c from Capability c order by c.name asc"),
+                @NamedQuery(name="CAPABILITY", query="select c from Capability c where c.name = :name")})
+public class CapabilityImpl implements Capability
+{    
+    // Members
+    
+    @Id
+    @GeneratedValue (strategy=GenerationType.AUTO)
+    @Column (name="CAPABILITY_ID")
+    private int capabilityId;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @Basic
+    @Column (name="CAPABILITY")
+    private String name;
+
+    // Implementation
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.Capability#setCapabilityId(int)
+     */
+    public void setCapabilityId(int id)
+    {
+        this.capabilityId = id;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.Capability#getCapabilityId()
+     */
+    public int getCapabilityId()
+    {
+        return this.capabilityId;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.Capability#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.Capability#getName()
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+    
+    
+    /**
+     * Implements the hashCode calculation so two different objects with the content return the same hashcode....
+     */
+    public int hashCode()
+    {
+    	return name.hashCode();
+    }
+
+    /**
+     * Implements the equals operation so that 2 elements are equal if
+     * all their member values are equal.
+     *
+     *      
+     * @param object to compare this one with
+     * @return true if both objects represent the same (logical) content
+     */
+    public boolean equals(Object object)
+    {
+    	if (!(object instanceof Capability))
+    	{
+    		return false;
+    	}
+    	if (this == object)
+    		return true;
+//    	 Don't check the ID - id is only set through OJB so this would not recognize equality correctly 
+    	/*     	if (this.capabilityId != ((Capability)object).getCapabilityId())
+    		return false;
+    	 */
+    	String oName = ((Capability)object).getName();
+    	if (
+    			(oName == null) && (name == null)
+    			||
+    			(oName == name)
+    			||
+    			((oName != null) && (oName.equals(name)))
+    		)
+    		return true;
+    	return false;	
+    }
+
+    /**
+     * Get new persistent status.
+     * 
+     * @return whether object is new.
+     */
+    public boolean isNew()
+    {
+        return (capabilityId == 0);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ClientImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ClientImpl.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ClientImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/ClientImpl.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,380 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.capabilities.jpa;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinTable;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
+import javax.persistence.NamedQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.PostLoad;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.jetspeed.capabilities.Client;
+import org.apache.jetspeed.components.rdbms.jpa.JPAUtils;
+
+/**
+ * Simple implementation of the ClientRegistry interface.
+ *
+ * @author <a href="shesmer@raleigh.ibm.com">Stephan Hesmer</a>
+ * @author <a href="mailto:raphael@apache.org">Rapha\u00ebl Luta</a>
+ * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
+ * @version $Id: ClientImpl.java 516448 2007-03-09 16:25:47Z ate $
+ */
+@Entity (name="Client")
+@Table (name="CLIENT")
+@NamedQueries ({@NamedQuery(name="CLIENTS", query="select c from Client c order by c.name asc"),
+                @NamedQuery(name="CLIENTS_EVAL_ORDER", query="select c from Client c order by c.evalOrder asc"),
+                @NamedQuery(name="CLIENT", query="select c from Client c where c.name = :name")})
+public class ClientImpl implements Client, Serializable
+{
+    private static final long serialVersionUID = 7507742184696800108L;
+
+    // Members
+    
+    @Id
+    @GeneratedValue (strategy=GenerationType.AUTO)
+    @Column (name="CLIENT_ID")
+    private int clientId;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @Basic
+    @Column (name="USER_AGENT_PATTERN")
+    private String userAgentPattern;
+    @Basic
+    @Column (name="MANUFACTURER")
+    private String manufacturer;
+    @Basic
+    @Column (name="MODEL")
+    private String model;
+    @Basic
+    @Column (name="VERSION")
+    private String version;
+    @Basic
+    @Column (name="NAME")
+    private String name;
+    @ManyToMany (targetEntity=MimeTypeImpl.class, fetch=FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
+    @JoinTable (name="CLIENT_TO_MIMETYPE", joinColumns={@JoinColumn (name="CLIENT_ID", referencedColumnName="CLIENT_ID")}, inverseJoinColumns={@JoinColumn (name="MIMETYPE_ID", referencedColumnName="MIMETYPE_ID")})
+    private Collection mimetypes;
+    @ManyToMany (targetEntity=CapabilityImpl.class, fetch=FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
+    @JoinTable (name="CLIENT_TO_CAPABILITY", joinColumns={@JoinColumn (name="CLIENT_ID", referencedColumnName="CLIENT_ID")}, inverseJoinColumns={@JoinColumn (name="CAPABILITY_ID", referencedColumnName="CAPABILITY_ID")})
+    private Collection capabilities;
+    @Basic
+    @Column (name="PREFERRED_MIMETYPE_ID")
+    private int preferredMimeTypeId;
+    @Basic
+    @Column (name="EVAL_ORDER")
+    private int evalOrder;
+
+    @PostLoad
+    private void eagerFetchCollections()
+    {
+        if (mimetypes != null)
+        {
+            mimetypes.size();
+        }
+        if (capabilities != null)
+        {
+            capabilities.size();
+        }
+    }    
+
+    // Implementation
+    
+    public ClientImpl()
+    {
+        this.userAgentPattern = "";
+        this.manufacturer = "";
+        this.model = "";
+        this.version = "";
+    }
+
+    /**
+     * Implements the equals operation so that 2 elements are equal if
+     * all their member values are equal.
+     */
+    public boolean equals(Object object)
+    {
+        if (object == this)
+        	return true;
+
+        if (object == null)
+        {
+            return false;
+        }
+        
+        ClientImpl obj = (ClientImpl) object;
+
+        if (name != null)
+        {
+            if (!name.equals(obj.name))
+            {
+                return false;
+            }
+        } else
+        {
+            if (obj.name != null)
+            {
+                return false;
+            }
+        }
+     
+        if (userAgentPattern != null)
+        {
+            if (!userAgentPattern.equals(obj.userAgentPattern))
+            {
+                return false;
+            }
+        } else
+        {
+            if (obj.userAgentPattern != null)
+            {
+                return false;
+            }
+        }
+
+        if (manufacturer != null)
+        {
+            if (!manufacturer.equals(obj.manufacturer))
+            {
+                return false;
+            }
+        } else
+        {
+            if (obj.manufacturer != null)
+            {
+                return false;
+            }
+        }
+
+        if (model != null)
+        {
+            if (!model.equals(obj.model))
+            {
+                return false;
+            }
+        } else
+        {
+            if (obj.model != null)
+            {
+                return false;
+            }
+        }
+
+        if (version != null)
+        {
+            if (!version.equals(obj.version))
+            {
+                return false;
+            }
+        } else
+        {
+            if (obj.version != null)
+            {
+                return false;
+            }
+        }
+        if (mimetypes != null)
+        {
+        	if (!CollectionUtils.isEqualCollection(mimetypes, obj.mimetypes))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.mimetypes != null)
+            {
+                return false;
+            }
+        }
+
+         if (capabilities != null)
+        {
+	       if (!(CollectionUtils.isEqualCollection(capabilities,obj.capabilities )))
+	            return false;
+	    }
+        else
+        {
+            if (obj.capabilities != null)
+            {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public String getUserAgentPattern()
+    {
+        return userAgentPattern;
+    }
+
+    public void setUserAgentPattern(String userAgentPattern)
+    {
+        this.userAgentPattern = userAgentPattern;
+    }
+
+    public String getManufacturer()
+    {
+        return manufacturer;
+    }
+
+    public void setManufacturer(String name)
+    {
+        manufacturer = name;
+    }
+
+    public String getModel()
+    {
+        return model;
+    }
+
+    public void setModel(String name)
+    {
+        model = name;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion(String name)
+    {
+        version = name;
+    }
+
+    public Collection getMimetypes()
+    {
+        if(this.mimetypes == null)
+        {
+            this.mimetypes = JPAUtils.createList();
+        }
+        return mimetypes;
+    }
+
+    public void setMimetypes(Collection mimetypes)
+    {
+        getMimetypes().clear();
+        getMimetypes().addAll(mimetypes);
+    }
+
+    public Collection getCapabilities()
+    {
+        if(capabilities == null)
+        {
+            capabilities = JPAUtils.createList();
+        }
+        return capabilities;
+    }
+
+    public void setCapabilities(Collection capabilities)
+    {
+        getCapabilities().clear();
+        getCapabilities().addAll(capabilities);
+    }
+
+    /**
+     * Set Client ID -- Assigns the Client ID
+     * @param id
+     */
+    public void setClientId(int id)
+    {
+        this.clientId = id;
+    }
+
+    /**
+     * Get Client ID
+     * @return Client ID
+     */
+    public int getClientId()
+    {
+        return this.clientId;
+    }
+    /**
+     * @return
+     */
+    public String getName()
+    {
+        return name;
+    }
+
+    /**
+     * @param string
+     */
+    public void setName(String string)
+    {
+        name = string;
+    }
+
+    /**
+     * @return Preferred MimeType ID for Client
+     */
+    public int getPreferredMimeTypeId()
+    {
+        return this.preferredMimeTypeId;
+    }
+
+    /**
+     * Set preferred Mimetype ID for Client
+     * @param mimeTypeId MimeTypeId
+     */
+    public void setPreferredMimeTypeId(int mimeTypeId)
+    {
+        this.preferredMimeTypeId = mimeTypeId;
+    }
+
+    /**
+     * @return Returns the evalOrder.
+     */
+    public int getEvalOrder()
+    {
+        return evalOrder;
+    }
+    /**
+     * @param evalOrder The evalOrder to set.
+     */
+    public void setEvalOrder(int evalOrder)
+    {
+        this.evalOrder = evalOrder;
+    }
+
+    /**
+     * Get new persistent status.
+     * 
+     * @return whether object is new.
+     */
+    public boolean isNew()
+    {
+        return (clientId == 0);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/JetspeedCapabilities.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/JetspeedCapabilities.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/JetspeedCapabilities.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/JetspeedCapabilities.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,880 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.capabilities.jpa;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceContext;
+import javax.persistence.PersistenceContextType;
+import javax.persistence.Query;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.jetspeed.capabilities.Capabilities;
+import org.apache.jetspeed.capabilities.CapabilitiesException;
+import org.apache.jetspeed.capabilities.Capability;
+import org.apache.jetspeed.capabilities.CapabilityMap;
+import org.apache.jetspeed.capabilities.Client;
+import org.apache.jetspeed.capabilities.MediaType;
+import org.apache.jetspeed.capabilities.MimeType;
+import org.apache.jetspeed.capabilities.UnableToBuildCapabilityMapException;
+import org.apache.jetspeed.capabilities.impl.CapabilityMapImpl;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import org.springframework.stereotype.Repository;
+import org.springframework.transaction.annotation.Transactional;
+
+/**
+ * JetspeedCapabilities
+ *
+ * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
+ * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
+ * @version $Id: JetspeedCapabilities.java 517124 2007-03-12 08:10:25Z ate $
+ */
+@Repository
+public class JetspeedCapabilities implements Capabilities, BeanFactoryAware, CapabilitiesManager
+{
+    private static final Log log = LogFactory.getLog(JetspeedCapabilities.class);
+
+    public static final String DEFAULT_AGENT = "Mozilla/4.0";
+
+    public static final String AGENT_XML = "agentxml/1.0";
+
+    // Cache for the capability maps
+    Hashtable capabilityMapCache = new Hashtable();
+
+    /**
+     * added support for bean factory to create profile rules
+     */
+    private BeanFactory beanFactory;
+
+    /** named bean references */
+    private String clientBeanName; 
+    private String capabilityBeanName; 
+    private String mimeTypeBeanName; 
+    private String mediaTypeBeanName; 
+
+    private Class clientClass;
+    private Class capabilityClass;
+    private Class mimeTypeClass;
+    private Class mediaTypeClass;
+    
+    private EntityManager entityManager;
+    private ThreadLocal contexts;
+
+    /**
+     * Construct capabilities component with specified bean names to use
+     * to create new elements.
+     * 
+     * @param clientBeanName
+     * @param mediaTypeBeanName
+     * @param mimeTypeBeanName
+     * @param capabilityBeanName
+     */
+    public JetspeedCapabilities(String clientBeanName, String mediaTypeBeanName, String mimeTypeBeanName, String capabilityBeanName)
+    {
+        this.clientBeanName =  clientBeanName;
+        this.capabilityBeanName =  capabilityBeanName;
+        this.mimeTypeBeanName =  mimeTypeBeanName;
+        this.mediaTypeBeanName =  mediaTypeBeanName;
+        this.contexts = new ThreadLocal();        
+    }
+    
+    /**
+     * Inject shared entity manager from assembly; this entity
+     * manager is expected to honor existing entity manager
+     * context attached to current thread, (otherwise, a new
+     * temporary entity manager is created).
+     * 
+     * @param entityManager injected shared entity manager
+     */
+    @PersistenceContext (type=PersistenceContextType.TRANSACTION, unitName="jetspeed-capabilities")
+    public void setEntityManager(EntityManager entityManager) 
+    {
+        this.entityManager = entityManager;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#registerContext(java.lang.Object)
+     */
+    public void registerContext(Object context)
+    {
+        CapabilitiesManagerContext registeredContext = (CapabilitiesManagerContext)contexts.get();
+        if ((registeredContext == null) && (context instanceof CapabilitiesManagerContext))
+        {
+            contexts.set(context);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#getContext()
+     */
+    public Object getContext()
+    {
+        return (CapabilitiesManagerContext)contexts.get();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#unregisterContext(java.lang.Object)
+     */
+    public void unregisterContext(Object context)
+    {
+        CapabilitiesManagerContext registeredContext = (CapabilitiesManagerContext)contexts.get();
+        if (context == registeredContext)
+        {
+            contexts.remove();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.profiler.jpa.ProfilerManager#getEntityManager()
+     */
+    public EntityManager getEntityManager()
+    {
+        CapabilitiesManagerContext context = (CapabilitiesManagerContext)getContext();
+        return ((context != null) ? context.getExtendedEntityManager() : entityManager);
+    }    
+    
+    /*
+     * Method called automatically by Spring container upon initialization
+     * 
+     * @param beanFactory automatically provided by framework @throws
+     * BeansException
+     */
+    public void setBeanFactory(BeanFactory beanFactory) throws BeansException
+    {
+        this.beanFactory = beanFactory;
+    }
+
+    private Class getClientClass() throws ClassNotFoundException
+    {
+        if (clientClass == null)
+        {
+            clientClass = createClient(null).getClass();
+        }
+        return clientClass;
+    }
+
+    private Class getMimeTypeClass() throws ClassNotFoundException
+    {
+        if (mimeTypeClass == null)
+        {
+            mimeTypeClass = createMimeType(null).getClass();
+        }
+        return mimeTypeClass;
+    }
+    private Class getCapabilityClass()throws ClassNotFoundException
+    {
+        if (capabilityClass == null)
+        {
+            capabilityClass = createCapability(null).getClass();
+        }
+        return capabilityClass;
+    }
+
+    private Class getMediaTypeClass()throws ClassNotFoundException
+    {
+        if (mediaTypeClass == null)
+        {
+            mediaTypeClass = createMediaType(null).getClass();
+        }
+        return mediaTypeClass;
+    }
+    
+    /**
+     * @param userAgent Agent from the request
+     * @throws UnableToBuildCapabilityMapException
+     * @see org.apache.jetspeed.services.capability.CapabilityService#getCapabilityMap(java.lang.String)
+     */
+    public CapabilityMap getCapabilityMap(String userAgent) throws UnableToBuildCapabilityMapException
+    {        
+        CapabilityMap map = null;
+        boolean bClientFound = false;
+        String defaultAgent = null;
+        if (userAgent == null)
+        {
+            userAgent = DEFAULT_AGENT;
+        }
+
+        // Check the cache if we have already a capability map for
+        // the given Agent
+        map = (CapabilityMap) capabilityMapCache.get(userAgent);
+        if (map != null)
+        {
+            // Entry found
+            return map;
+        }
+
+        while (!bClientFound)
+        {
+            Client entry = findClient(userAgent);
+            if (entry == null)
+            {
+                if (userAgent.equals(DEFAULT_AGENT))
+                {
+                    log.error("CapabilityMap: Default agent not found in Client Registry !");
+
+                    // Stop searching -- event the default userAgent can't be found
+                    bClientFound = true;
+                }
+                else
+                {
+                    // Retry with the default Agent
+                    if (log.isDebugEnabled())
+                    {
+                        log.debug("CapabilityMap: useragent " + userAgent + "unknown, falling back to default");
+                    }
+
+                    // Use default Client
+                    defaultAgent = userAgent;
+                    userAgent = DEFAULT_AGENT;
+                }
+            }
+            else
+            {
+                // Found Client entry start populating the capability map.
+                map = new CapabilityMapImpl();
+
+                // Add client to CapabilityMap
+                map.setClient(entry);
+
+                // Add capabilities
+                Iterator capabilities = entry.getCapabilities().iterator();
+                while (capabilities.hasNext())
+                {
+                    map.addCapability((Capability) capabilities.next());
+                }
+
+                Collection mediatypes = getMediaTypesForMimeTypes(entry.getMimetypes().iterator());
+
+                // Add Mimetypes to map
+                Iterator mimetypes = entry.getMimetypes().iterator();
+                while (mimetypes.hasNext())
+                {
+                    map.addMimetype((MimeType) mimetypes.next());
+                }
+
+                Iterator media = mediatypes.iterator();
+                while (media.hasNext())
+                {
+                    map.addMediaType((MediaType) media.next());
+                }
+
+                //Set preferred Mimetype
+                MediaType mtEntry = getMediaTypeForMimeType(map.getPreferredType().getName());
+                map.setPreferredMediaType(mtEntry);
+
+                // Add map to cache
+                capabilityMapCache.put(userAgent, map);
+                if (defaultAgent != null)
+                {
+                    capabilityMapCache.put(defaultAgent, map);
+                }
+                return map;
+            }
+        }
+        
+        if (map != null)
+        {
+            return map;
+        }
+        throw new UnableToBuildCapabilityMapException("We were unable to build a capability map for the agent, " + userAgent + ". This might be an indiciation that the capability database has not been correctly initialized.");
+    }
+
+    /**
+     * Returns the client which matches the given useragent string.
+     *
+     * @param useragent     the useragent to match
+     * @return the found client or null if the user-agent does not match any
+     *  defined client
+     * @see org.apache.jetspeed.capabilities.CapabilityService#findClient(java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public Client findClient(String userAgent)
+    {
+        Client clientEntry = null;
+        Iterator clients = getClients();
+
+        if (log.isDebugEnabled())
+        {
+            log.debug("ClientRegistry: Looking for client with useragent :" + userAgent);
+        }
+
+        while (clients.hasNext())
+        {
+            Client client = (Client) clients.next();
+            if (client.getUserAgentPattern() != null)
+            {
+                try
+                {
+                    String exp = client.getUserAgentPattern();
+                    if (userAgent.matches(exp))
+                    {
+                        if (log.isDebugEnabled())
+                        {
+                            log.debug("Client: " + userAgent + " matches " + client.getUserAgentPattern());
+                        }
+                        return client;
+                    }
+                    else
+                    {
+                        if (log.isDebugEnabled())
+                        {
+                            log.debug("Client: " + userAgent + " does not match " + client.getUserAgentPattern());
+                        }
+                    }
+                }
+                catch (java.util.regex.PatternSyntaxException e)
+                {
+                    String message = "CapabilityServiceImpl: UserAgentPattern not valid : " + client.getUserAgentPattern() + " : " + e.getMessage();
+                    log.error(message, e);
+                }
+            }
+        }
+
+        return clientEntry;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.CapabilityService#getClients()
+     */
+    @Transactional (readOnly=true)
+    public Iterator getClients()
+    {
+        // query for all clients ordered by name
+        EntityManager entityManager = getEntityManager();
+        Query clientsQuery = entityManager.createNamedQuery("CLIENTS_EVAL_ORDER");
+        return clientsQuery.getResultList().iterator();
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaTypesForMimeTypes(java.util.Iterator)
+     */
+    @Transactional (readOnly=true)
+    public Collection getMediaTypesForMimeTypes(Iterator mimetypes)
+    {
+        // aggregate query for all media types with mime type names
+        EntityManager entityManager = getEntityManager();
+        Collection mediaTypes = new ArrayList();
+        while (mimetypes.hasNext())
+        {
+            // query for all media types with mime type name
+            Query mediaTypesWithMimeTypeQuery = entityManager.createNamedQuery("MEDIA_TYPES_WITH_MIME_TYPE");
+            String mimeTypeName = ((MimeType)mimetypes.next()).getName();
+            mediaTypesWithMimeTypeQuery.setParameter("mimeTypeName", mimeTypeName);
+            Iterator iter = mediaTypesWithMimeTypeQuery.getResultList().iterator();
+            while (iter.hasNext())
+            {
+                MediaType mediaType = (MediaType)iter.next();
+                if (!mediaTypes.contains(mediaType))
+                {
+                    mediaTypes.add(mediaType);
+                }
+            }
+        }
+        if (mediaTypes.isEmpty())
+        {
+            mediaTypes.add(getMediaType("html"));
+        }
+        return mediaTypes;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.CapabilityService#deleteCapabilityMapCache()
+     */
+    public void deleteCapabilityMapCache()
+    {
+        capabilityMapCache.clear();
+    }
+
+    /**
+     * getMediaTypeForMimeType
+     * @param mimeType to use for lookup
+     * @return MediaTypeEntry that matches the lookup in the MEDIATYPE_TO_MIMETYPE table
+     */
+    @Transactional (readOnly=true)
+    public MediaType getMediaTypeForMimeType(String mimeTypeName)
+    {               
+        // query for all media types with mime type name
+        EntityManager entityManager = getEntityManager();
+        Query mediaTypesWithMimeTypeQuery = entityManager.createNamedQuery("MEDIA_TYPES_WITH_MIME_TYPE");
+        mediaTypesWithMimeTypeQuery.setParameter("mimeTypeName", mimeTypeName);
+        Iterator iter = mediaTypesWithMimeTypeQuery.getResultList().iterator();
+        if (iter.hasNext())
+        {
+            return (MediaType) iter.next();
+        }
+        return null;
+    }
+
+    /**
+     * Obtain an iterator of all existing capabilities.
+     * @return Returns an iterator for all existing Capabilities of type <code>Capability</code>
+     */
+    @Transactional (readOnly=true)
+    public Iterator getCapabilities()
+    {
+        // query for all capabilities ordered by name
+        EntityManager entityManager = getEntityManager();
+        Query capabilitiesQuery = entityManager.createNamedQuery("CAPABILITIES");
+        return capabilitiesQuery.getResultList().iterator();
+    }
+    
+    /**
+     * Obtain an iterator of all existing mime types.
+     * @return Returns an iterator for all existing Mime Types of type <code>MimeType</code>
+     */
+    @Transactional (readOnly=true)
+    public Iterator getMimeTypes()
+    {
+        // query for all mime types ordered by name
+        EntityManager entityManager = getEntityManager();
+        Query mimeTypesQuery = entityManager.createNamedQuery("MIME_TYPES");
+        return mimeTypesQuery.getResultList().iterator();
+    }
+    
+    /**
+     * Obtain an iterator of all existing media types.
+     * @return Returns an iterator for all existing media types of type <code>MediaType</code>
+     */
+    @Transactional (readOnly=true)
+    public Iterator getMediaTypes()
+    {
+        // query for all media types ordered by name
+        EntityManager entityManager = getEntityManager();
+        Query mediaTypesQuery = entityManager.createNamedQuery("MEDIA_TYPES");
+        return mediaTypesQuery.getResultList().iterator();
+    }
+    
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#getMimeTypeBeanName()
+     */
+    public String getMimeTypeBeanName()
+    {
+        return mimeTypeBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#setMimeTypeBeanName(String)
+     */
+    public void setMimeTypeBeanName(String mimeTypeBeanName)
+    {
+        this.mimeTypeBeanName = mimeTypeBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#getClientBeanName()
+     */
+    public String getClientBeanName()
+    {
+        return clientBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#setClientBeanName(String)
+     */
+    public void setClientBeanName(String clientBeanName)
+    {
+        this.clientBeanName = clientBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#getMediaTypeBeanName()
+     */
+    public String getMediaTypeBeanName()
+    {
+        return mediaTypeBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#setMediaTypeBeanName(String)
+     */
+    public void setMediaTypeBeanName(String mediaTypeBeanName)
+    {
+        this.mediaTypeBeanName = mediaTypeBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#getCapabilityBeanName()
+     */
+    public String getCapabilityBeanName()
+    {
+        return capabilityBeanName;
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#setCapabilityBeanName(String)
+     */
+    public void setCapabilityBeanName(String capabilityBeanName)
+    {
+        this.capabilityBeanName = capabilityBeanName;
+    }
+    
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#createMimeType(String)
+     */
+    @Transactional (readOnly=true)
+    public MimeType createMimeType(String mimeType) throws ClassNotFoundException
+    {
+        MimeType mimeTypeobj = null;
+        if (mimeType != null)
+        {
+            //try to find it in space
+            mimeTypeobj = getMimeType(mimeType);
+            if (mimeTypeobj != null)
+            {
+                return mimeTypeobj;
+            }
+        }
+        try
+        {
+            mimeTypeobj = (MimeType) beanFactory.getBean(mimeTypeBeanName, MimeType.class);
+            mimeTypeobj.setName(mimeType);
+            return mimeTypeobj;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create capability instance for " + mimeTypeBeanName + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the " + mimeTypeBeanName + " mimeType bean.", e);
+        }
+    }
+    
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#createCapability(String)
+     */
+    @Transactional (readOnly=true)
+    public Capability createCapability(String capabilityName) throws ClassNotFoundException
+    {
+        Capability capability = null;
+        if (capabilityName != null)
+        {
+            //try to find it in space
+            capability = getCapability(capabilityName);
+            if (capability != null)
+            {
+                return capability;
+            }
+        }
+        try
+        {
+            capability = (Capability) beanFactory.getBean(capabilityBeanName, Capability.class);
+            capability.setName(capabilityName);
+            return capability;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create capability instance for " + capabilityBeanName + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the capability bean.", e);
+        }
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#createMediaType(String)
+     */
+    @Transactional (readOnly=true)
+    public MediaType createMediaType(String mediaTypeName) throws ClassNotFoundException
+    {
+        MediaType mediaType = null;
+        if (mediaTypeName != null)
+        {
+            //try to find it in space
+            mediaType = getMediaType(mediaTypeName);
+            if (mediaType != null)
+            {
+                return mediaType;
+            }
+        }
+        try
+        {
+            mediaType = (MediaType) beanFactory.getBean(mediaTypeBeanName, MediaType.class);
+            mediaType.setName(mediaTypeName);
+            return mediaType;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create mediaType instance for " + mediaTypeBeanName + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the mediaType bean.", e);
+        }
+    }
+
+    /* 
+     * @see org.apache.jetspeed.capabilities.Capabilities#createClient(String)
+     */
+    @Transactional (readOnly=true)
+    public Client createClient(String clientName) throws ClassNotFoundException
+    {
+        Client client = null;
+        if (clientName != null)
+        {
+            //try to find it in space
+            client = getClient(clientName);
+            if (client != null)
+            {
+                return client;
+            }
+        }
+        try
+        {
+            client = (Client) beanFactory.getBean(clientBeanName, Client.class);
+            client.setName(clientName);
+            return client;
+        }
+        catch (Exception e)
+        {
+            log.error("Failed to create client instance for " + clientBeanName + " error : " + e.getLocalizedMessage());
+            throw new ClassNotFoundException("Spring failed to create the client bean.", e);
+        }
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public MimeType getMimeType(String mimeType)
+    {
+        // query for media type by name
+        EntityManager entityManager = getEntityManager();
+        Query mimeTypeQuery = entityManager.createNamedQuery("MIME_TYPE");
+        mimeTypeQuery.setParameter("name", mimeType);
+        try
+        {
+            return (MimeType)mimeTypeQuery.getSingleResult();
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.capabilities.MimeTypeservice#getClientjava.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public Client getClient(String clientName)
+    {     
+        // query for client by name
+        EntityManager entityManager = getEntityManager();
+        Query clientQuery = entityManager.createNamedQuery("CLIENT");
+        clientQuery.setParameter("name", clientName);
+        try
+        {
+            return (Client)clientQuery.getSingleResult();
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return null;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.capabilities.MimeTypeservice#getCapability(java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public Capability getCapability(String capability)
+    {      
+        // query for capability by name
+        EntityManager entityManager = getEntityManager();
+        Query capabilityQuery = entityManager.createNamedQuery("CAPABILITY");
+        capabilityQuery.setParameter("name", capability);
+        try
+        {
+            return (Capability)capabilityQuery.getSingleResult();
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return null;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.capabilities.CapabilityService#getMediaType(java.lang.String)
+     */
+    @Transactional (readOnly=true)
+    public MediaType getMediaType(String mediaType)
+    {        
+        // query for media type by name
+        EntityManager entityManager = getEntityManager();
+        Query mediaTypeQuery = entityManager.createNamedQuery("MEDIA_TYPE");
+        mediaTypeQuery.setParameter("name", mediaType);
+        try
+        {
+            return (MediaType)mediaTypeQuery.getSingleResult();
+        }
+        catch (NoResultException nre)
+        {
+        }
+        return null;
+    }
+
+    /* 
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#storeMediaType(MediaType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void storeMediaType(MediaType mediaType) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), media type
+        if (!((MediaTypeImpl)mediaType).isNew())
+        {
+            mediaType = entityManager.merge(mediaType);
+        }
+        entityManager.persist(mediaType);
+        // explicitly flush entity manager after update
+        entityManager.flush();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#deleteMediaType(MediaType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void deleteMediaType(MediaType mediaType) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), media type
+        if (!((MediaTypeImpl)mediaType).isNew())
+        {
+            mediaType = entityManager.merge(mediaType);
+        }
+        entityManager.remove(mediaType);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+    
+    /* 
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#storeCapability(MediaType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void storeCapability(Capability capability) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), capability
+        if (!((CapabilityImpl)capability).isNew())
+        {
+            capability = entityManager.merge(capability);
+        }
+        entityManager.persist(capability);
+        // explicitly flush entity manager after update
+        entityManager.flush();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#deleteCapability(Capability)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void deleteCapability(Capability capability) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), capability
+        if (!((CapabilityImpl)capability).isNew())
+        {
+            capability = entityManager.merge(capability);
+        }
+        entityManager.remove(capability);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /* 
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#storeMimeType(MimeType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void storeMimeType(MimeType mimeType) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), mime type
+        if (!((MimeTypeImpl)mimeType).isNew())
+        {
+            mimeType = entityManager.merge(mimeType);
+        }
+        entityManager.persist(mimeType);
+        // explicitly flush entity manager after update
+        entityManager.flush();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#deleteMimeType(MimeType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void deleteMimeType(MimeType mimeType) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), mime type
+        if (!((MimeTypeImpl)mimeType).isNew())
+        {
+            mimeType = entityManager.merge(mimeType);
+        }
+        entityManager.remove(mimeType);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+
+    /* 
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#storeClient(MediaType)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void storeClient(Client client) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // update, (potentially detached), client
+        if (!((ClientImpl)client).isNew())
+        {
+            client = entityManager.merge(client);
+        }
+        entityManager.persist(client);
+        // explicitly flush entity manager after update
+        entityManager.flush();
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.jetspeed.capabilities.Capabilities#deleteClient(Client)
+     */
+    @Transactional (readOnly=false, rollbackFor=CapabilitiesException.class)
+    public void deleteClient(Client client) throws CapabilitiesException
+    {
+        EntityManager entityManager = getEntityManager();
+        // remove, (potentially detached), client
+        if (!((ClientImpl)client).isNew())
+        {
+            client = entityManager.merge(client);
+        }
+        entityManager.remove(client);
+        // explicitly flush entity manager after remove
+        entityManager.flush();
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MediaTypeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MediaTypeImpl.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MediaTypeImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MediaTypeImpl.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.capabilities.jpa;
+
+import java.util.Collection;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinTable;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToMany;
+import javax.persistence.NamedQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.PostLoad;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.jetspeed.capabilities.Capability;
+import org.apache.jetspeed.capabilities.MediaType;
+import org.apache.jetspeed.capabilities.MimeType;
+import org.apache.jetspeed.components.rdbms.jpa.JPAUtils;
+
+/**
+ * Default bean like implementation of MediaTypeEntry interface
+ * suitable for serializing with Castor
+ *
+ * @author <a href="mailto:raphael@apache.org">Rapha\u00ebl Luta</a>
+ * @version $Id: MediaTypeImpl.java 516448 2007-03-09 16:25:47Z ate $
+ */
+@Entity (name="MediaType")
+@Table (name="MEDIA_TYPE")
+@NamedQueries ({@NamedQuery(name="MEDIA_TYPES", query="select mt from MediaType mt order by mt.name asc"),
+                @NamedQuery(name="MEDIA_TYPE", query="select mt from MediaType mt where mt.name = :name"),
+                @NamedQuery(name="MEDIA_TYPES_WITH_MIME_TYPE", query="select mt from MediaType mt where :mimeTypeName member mt.mimetypes.name")})
+public class MediaTypeImpl implements MediaType
+{
+    // Members
+    
+    @Id
+    @GeneratedValue (strategy=GenerationType.AUTO)
+    @Column (name="MEDIATYPE_ID")
+    private int mediatypeId;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @Basic
+    @Column (name="CHARACTER_SET")
+    private String characterSet;    
+    @ManyToMany (targetEntity=CapabilityImpl.class, fetch=FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
+    @JoinTable (name="MEDIATYPE_TO_CAPABILITY", joinColumns={@JoinColumn (name="MEDIATYPE_ID", referencedColumnName="MEDIATYPE_ID")}, inverseJoinColumns={@JoinColumn (name="CAPABILITY_ID", referencedColumnName="CAPABILITY_ID")})
+    private Collection capabilities;
+    @ManyToMany (targetEntity=MimeTypeImpl.class, fetch=FetchType.LAZY, cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
+    @JoinTable (name="MEDIATYPE_TO_MIMETYPE", joinColumns={@JoinColumn (name="MEDIATYPE_ID", referencedColumnName="MEDIATYPE_ID")}, inverseJoinColumns={@JoinColumn (name="MIMETYPE_ID", referencedColumnName="MIMETYPE_ID")})
+    private Collection mimetypes;
+    @Basic
+    @Column (name="TITLE")
+    private String title;
+    @Basic
+    @Column (name="DESCRIPTION")
+    private String description;
+    @Basic
+    @Column (name="NAME")
+    private String name;
+
+    @PostLoad
+    private void eagerFetchCollections()
+    {
+        if (mimetypes != null)
+        {
+            mimetypes.size();
+        }
+        if (capabilities != null)
+        {
+            capabilities.size();
+        }
+    }    
+
+    // Implementation
+    
+    public MediaTypeImpl()
+    {        
+    }
+
+    public MediaTypeImpl(long id,
+                              String name,
+                              int _hidden,
+                              String mimeType,
+                              String title,
+                              String description,
+                              String image,
+                               String role)
+    {
+         this.mimetypes.add(mimeType);
+    }
+
+    /**
+     * Implements the equals operation so that 2 elements are equal if
+     * all their member values are equal.
+     */
+    public boolean equals(Object object)
+    {
+        if (this == object)
+        	return true;
+        if (object==null)
+            return false;
+        
+        MediaTypeImpl obj = (MediaTypeImpl)object;
+
+
+        if (this.name!=null)
+        {
+            if (!name.equals(obj.name))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.name!=null)
+            {
+                return false;
+            }
+        }
+
+        if (this.description!=null)
+        {
+            if (!description.equals(obj.description))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.description!=null)
+            {
+                return false;
+            }
+        }
+
+        if (characterSet!=null)
+        {
+            if (!characterSet.equals(obj.characterSet))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.characterSet!=null)
+            {
+                return false;
+            }
+        }
+
+
+        if (this.title!=null)
+        {
+            if (!title.equals(obj.title))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.title!=null)
+            {
+                return false;
+            }
+        }
+
+
+        if (mimetypes != null)
+        {
+        	if (!CollectionUtils.isEqualCollection(mimetypes, obj.mimetypes))
+            {
+                return false;
+            }
+        }
+        else
+        {
+            if (obj.mimetypes != null)
+            {
+                return false;
+            }
+        }
+
+         if (capabilities != null)
+        {
+	       if (!(CollectionUtils.isEqualCollection(capabilities,obj.capabilities )))
+	            return false;
+	    }
+        else
+        {
+            if (obj.capabilities != null)
+            {
+                return false;
+            }
+        }
+
+        return true;
+}
+    
+ 
+    /** @return the character set associated with this MediaType */
+    public String getCharacterSet()
+    {
+        return this.characterSet;
+    }
+
+    /** Sets the character set associated with this MediaType */
+    public void setCharacterSet( String charSet)
+    {
+        this.characterSet = charSet;
+    }
+
+    
+    public Collection getCapabilities()
+    {
+        if (capabilities == null)
+        {
+            capabilities = JPAUtils.createList();
+        }
+        return capabilities;
+    }
+
+    public void setCapabilities(Collection capabilities)
+    {
+        getCapabilities().clear();
+        getCapabilities().addAll(capabilities);
+    }
+    
+    
+    public Collection getMimetypes()
+    {
+        if (mimetypes == null)
+        {
+            mimetypes = JPAUtils.createList();
+        }
+        return mimetypes;
+    }
+    
+    public void setMimetypes(Collection mimetypes)
+    {
+        getMimetypes().clear();
+        getMimetypes().addAll(mimetypes);
+    }
+
+    public void addMimetype(MimeType mimeType)
+    {
+        if (!getMimetypes().contains(mimeType.getName()))
+        {
+            getMimetypes().add(mimeType);
+        }
+    }
+
+    public void addCapability(Capability capability)
+    {
+        if (!getCapabilities().contains(capability.getName()))
+        {
+            getCapabilities().add(capability);
+        }
+    }
+
+    public void removeMimetype(String name)
+    {
+        getMimetypes().remove(name);
+    }
+    
+    /**
+     * Set MediaType ID -- Assigns ID
+     * @param id
+     */
+    public void setMediatypeId(int id)
+    {
+        this.mediatypeId = id;
+    }
+
+    /**
+     * Get MediaType ID -- Return ID
+     * @return MediaTypeID
+     */
+    public int getMediatypeId()
+    {
+        return this.mediatypeId;
+    }
+    
+    /**
+      * Set name ob MediaTypeEntry
+      */
+     public void setName(String name)
+     {
+         this.name = name;
+     }
+  
+     /**
+      * Get name ob MediaTypeEntry
+      */
+ 
+     public String getName()
+     {
+         return this.name;
+     }
+     
+     public String getTitle()
+     {
+         return this.title;
+     }
+
+     public void setTitle(String title)
+     {
+         this.title = title;
+     }
+     
+     public String getDescription()
+     {
+         return this.description;
+     }
+
+
+    public void setDescription(String desc)
+    {
+        this.description = desc;
+    }
+
+    /**
+     * Get new persistent status.
+     * 
+     * @return whether object is new.
+     */
+    public boolean isNew()
+    {
+        return (mediatypeId == 0);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MimeTypeImpl.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MimeTypeImpl.java?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MimeTypeImpl.java (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/java/org/apache/jetspeed/capabilities/jpa/MimeTypeImpl.java Mon Jan 19 22:54:50 2009
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jetspeed.capabilities.jpa;
+
+import javax.persistence.Basic;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.NamedQuery;
+import javax.persistence.NamedQueries;
+import javax.persistence.Table;
+import javax.persistence.Version;
+
+import org.apache.jetspeed.capabilities.MimeType;
+
+/**
+ * Mimetype implementation class.
+ *
+ * @author <a href="mailto:roger.ruttimann@earthlink.net">Roger Ruttimann</a>
+ * @version $Id: MimeTypeImpl.java 517719 2007-03-13 15:05:48Z ate $
+ */
+@Entity (name="MimeType")
+@Table (name="MIMETYPE")
+@NamedQueries ({@NamedQuery(name="MIME_TYPES", query="select mt from MimeType mt order by mt.name asc"),
+                @NamedQuery(name="MIME_TYPE", query="select mt from MimeType mt where mt.name = :name")})
+public class MimeTypeImpl implements MimeType
+{
+    // Members
+    
+    @Id
+    @GeneratedValue (strategy=GenerationType.AUTO)
+    @Column (name="MIMETYPE_ID")
+    private int mimeTypeId;
+    @Version
+    @Column (name="JPA_VERSION")
+    private int jpaVersion;
+    @Basic
+    @Column (name="NAME")
+    private String name;
+    
+    // Implementation
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.MimeType#setMimetypeId(int)
+     */
+    public void setMimetypeId(int id)
+    {
+        this.mimeTypeId = id;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.MimeType#getMimetypeId()
+     */
+    public int getMimetypeId()
+    {
+        return this.mimeTypeId;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.MimeType#setName(java.lang.String)
+     */
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.om.registry.MimeType#getName()
+     */
+    public String getName()
+    {
+        return this.name;
+    }
+
+    /**
+     * Implements the hashCode calculation so two different objects with the content return the same hashcode....
+     */
+    public int hashCode()
+    {
+    	return name.hashCode();
+    }
+    /**
+     * Implements the equals operation so that 2 elements are equal if
+     * all their member values are equal.
+     *
+     *      
+     * @param object to compare this one with
+     * @return true if both objects represent the same (logical) content
+     */
+    public boolean equals(Object object)
+    {
+    	if (!(object instanceof MimeType))
+    	{
+    		return false;
+    	}
+    	if (this == object)
+    		return true;
+// Don't check the ID - id is only set through OJB so this would not recognize equality correctly 
+/*    	if (mimeTypeId != ((MimeType)object).getMimetypeId())
+    		return false;
+*/
+    	String oName = ((MimeType)object).getName();
+    	if (
+    			(oName == null) && (name == null)
+    			||
+    			(oName == name)
+    			||
+    			((oName != null) && (oName.equals(name)))
+    		)
+    		return true;
+    	return false;	
+    }
+
+    /**
+     * Get new persistent status.
+     * 
+     * @return whether object is new.
+     */
+    public boolean isNew()
+    {
+        return (mimeTypeId == 0);
+    }
+}

Added: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/persistence.xml?rev=735948&view=auto
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/persistence.xml (added)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/main/resources/META-INF/persistence.xml Mon Jan 19 22:54:50 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+
+    <persistence-unit name="jetspeed-capabilities" transaction-type="JTA">
+
+        <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+
+        <jta-data-source>jetspeed-xa</jta-data-source>
+        <non-jta-data-source>jetspeed</non-jta-data-source>
+
+        <class>org.apache.jetspeed.capabilities.jpa.CapabilityImpl</class>
+        <class>org.apache.jetspeed.capabilities.jpa.ClientImpl</class>
+        <class>org.apache.jetspeed.capabilities.jpa.MediaTypeImpl</class>
+        <class>org.apache.jetspeed.capabilities.jpa.MimeTypeImpl</class>
+
+        <exclude-unlisted-classes>true</exclude-unlisted-classes>
+
+    </persistence-unit>
+
+</persistence>

Modified: portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java?rev=735948&r1=735947&r2=735948&view=diff
==============================================================================
--- portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java (original)
+++ portals/jetspeed-2/portal/branches/JPA_BRANCH/components/jetspeed-capability/src/test/java/org/apache/jetspeed/capabilities/TestCapability.java Mon Jan 19 22:54:50 2009
@@ -24,43 +24,52 @@
 
 import junit.framework.Test;
 
-import org.apache.jetspeed.components.test.AbstractSpringTestCase;
+import org.apache.jetspeed.components.util.jpa.JPADatasourceEnabledSpringTestCase;
 import org.apache.jetspeed.serializer.JetspeedSerializer;
 
-
 /**
  * Test Capability Service
  * 
  * @author <a href="roger.ruttimann@earthlink.net">Roger Ruttimann</a>
  * @version $Id$
  */
-public class TestCapability extends AbstractSpringTestCase
+public class TestCapability extends JPADatasourceEnabledSpringTestCase
 {
+    // Members
+    
     private Capabilities capabilities = null;
 
+    // Implementation
+    
     /**
-     * Start the tests.
+     * Define ordered test case test methods.
      * 
-     * @param args
-     *            the arguments. Not used
+     * @return test suite
      */
-    public static void main(String args[])
+    public static Test suite()
     {
-        junit.awtui.TestRunner.main(new String[]
-        { TestCapability.class.getName() });
+        return createFixturedTestSuite(TestCapability.class, "firstTestSetup", "lastTestTeardown");
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.components.util.jpa.JPADatasourceEnabledSpringTestCase#setUp()
+     */
     protected void setUp() throws Exception
     {
         super.setUp();
         capabilities = (Capabilities) scm.getComponent("capabilities");
     }
-
-    public static Test suite()
+    
+    /* (non-Javadoc)
+     * @see org.apache.jetspeed.components.test.AbstractSpringTestCase#getConfigurations()
+     */
+    protected String[] getConfigurations()
     {
-        return createFixturedTestSuite(TestCapability.class, "firstTestSetup", "lastTestTeardown");
+        return new String[] { "capabilities.xml", "transaction.xml", "serializer.xml" };
     }
 
+    // Test Implementation
+    
     public void firstTestSetup() throws Exception
     {
         System.out.println("firstTestSetup");
@@ -76,13 +85,9 @@
         serializer.deleteData();
     }
     
-    /**
-     * Tests categories
-     * 
-     * @throws Exception
-     */
     public void testCapability() throws Exception
     {
+        System.out.println("testCapability");
         assertNotNull("capabilities component is null", capabilities);
         int lastOrder = 0;
         Iterator caps = capabilities.getClients();
@@ -167,7 +172,6 @@
         assertNotNull("getCapabilityMap is null", cm);
         assertTrue("Ericsson", cm.getClient().getName().equals("sonyericsson"));
         capabilityMapReport(cm);        
-        
     }
 
     private void capabilityMapReport(CapabilityMap cm)
@@ -239,6 +243,7 @@
     
     public void testNewMimeType() throws Exception
     {
+        System.out.println("testNewMimeType");
     	MimeType mimeType = null;
     	Iterator _it = null;
     	HashMap _hash = getMimeTypes(0);
@@ -277,19 +282,14 @@
     	existingObject = capabilities.getMimeType("TEST MIME TYPE");
         assertNotNull("creating and saving new mimetype didn't store object",existingObject);
         
-        
         capabilities.deleteMimeType(mimeType);
     	existingObject = capabilities.getMimeType("TEST MIME TYPE");
         assertNull("creating new mimetype delete from storage didn't work",existingObject);
-        
     }
 
-
-    
-    
-    
     public void testNewCapability() throws Exception
     {
+        System.out.println("testNewCapability");
     	Capability capability = null;
     	Iterator _it = null;
        	HashMap _hash = getCapabilities(0);
@@ -328,17 +328,14 @@
     	existingObject = capabilities.getCapability("TEST CAPABILITY TYPE");
         assertNotNull("creating and saving new capability didn't store object",existingObject);
         
-        
         capabilities.deleteCapability(capability);
     	existingObject = capabilities.getCapability("TEST CAPABILITY TYPE");
         assertNull("creating new capability delete from storage didn't work",existingObject);
-        
     }
 
-    
-    
     public void testNewMediaType() throws Exception
     {
+        System.out.println("testNewMediaType");
     	MediaType mediaType = null;
     	Iterator _it = capabilities.getMediaTypes();
     	HashMap _hash = new HashMap();
@@ -381,8 +378,6 @@
         HashMap someCapabilities  = getCapabilities(numCapabilities);
         HashMap someMimeTypes  = getMimeTypes(numMimeTypes);
         
-        
-        
         // create a new one:
         mediaType = capabilities.createMediaType(name);
         assertNotNull("creating new mediatype returns null", mediaType);
@@ -394,8 +389,7 @@
     	existingObject = capabilities.getMediaType(name);
         assertNull("creating new mediaType already in existing capabilities",existingObject);
         
-        
-// set object fields               
+        // set object fields               
         mediaType.setCharacterSet(utf);
         mediaType.setTitle(title);
         mediaType.setDescription(description);
@@ -410,8 +404,6 @@
         assertTrue("number of Mimetypes added (" + added + ") not the same as expected ("+numMimeTypes+")",(added==numMimeTypes));
         
         // setting links:
-        
-        
         ArrayList set = new ArrayList(someCapabilities.values());
         mediaType.setCapabilities(set);
         assertTrue("number of Capabilities added (" + set.size() + ") not the same as expected ("+numCapabilities+")",(set.size()==numCapabilities));
@@ -423,17 +415,11 @@
         capabilities.deleteMediaType(mediaType);
     	existingObject = capabilities.getMediaType(name);
         assertNull("creating new mediaType delete from storage didn't work",existingObject);
- 
-        
-        
-        
-        
     }
 
-    
-    
     public void testNewClient() throws Exception
     {
+        System.out.println("testNewClient");
     	Client client = null;
     	Iterator _it = capabilities.getClients();
     	HashMap _hash = new HashMap();
@@ -457,15 +443,12 @@
     	Client existingObject = (Client)_hash.get(existingKey);
         assertNotNull("Couldn't identify existing object to run test",existingObject);
 
-    	
     	// "create" existing one
     	client = capabilities.createClient(existingKey);
         assertNotNull("creating 'existing' client returns null", client);
         assertTrue("creating 'existing' client didn't return existing object", (client.equals(existingObject)));
-
         
         // setting fields
-        
         String name  = "TEST CLIENT";
         int numCapabilities = 3;
         int numMimeTypes = 4;
@@ -488,24 +471,20 @@
         String manufacturer = "Test Manufacturer";
         String model = "XYZ";
         
-// set object fields               
+        // set object fields               
         client.setUserAgentPattern(userAgentPattern);
         client.setManufacturer(manufacturer);
         client.setModel(model);
 
         ArrayList set = new ArrayList(someCapabilities.values());
         client.setCapabilities(set);
-        assertTrue("number of Capabilities added (" + set.size() + ") not the same as expected ("+numCapabilities+")",(set.size()==numCapabilities));
+        assertTrue("number of Capabilities added (" + client.getCapabilities().size() + ") not the same as expected ("+numCapabilities+")",(client.getCapabilities().size()==numCapabilities));
         
         set = new ArrayList(someMimeTypes.values());
-        client.setCapabilities(set);
-        assertTrue("number of MimeTypes added (" + set.size() + ") not the same as expected ("+numCapabilities+")",(set.size()==numMimeTypes));
+        client.setMimetypes(set);
+        assertTrue("number of MimeTypes added (" + client.getMimetypes().size() + ") not the same as expected ("+numMimeTypes+")",(client.getMimetypes().size()==numMimeTypes));
 
-        
         // setting links:
-        
-        
-        
         capabilities.storeClient(client);
     	existingObject = capabilities.getClient(name);
         assertNotNull("creating and saving new client didn't store object",existingObject);
@@ -513,36 +492,23 @@
         capabilities.deleteClient(client);
     	existingObject = capabilities.getClient(name);
         assertNull("creating new client delete from storage didn't work",existingObject);
- 
-        
-        
-        
-        
     }
-
-    
     
     public void testCapabilityRepeat() throws Exception
     {
+        System.out.println("testCapabilityRepeat");
     	capabilities.deleteCapabilityMapCache();
         testCapability();
     }
 
-    
-    protected String[] getConfigurations()
-    {
-        return new String[] 
-        { "capabilities.xml", "transaction.xml", "serializer.xml" };
-    }
-
-    protected String[] getBootConfigurations()
-    {
-        return new String[]
-        { "boot/datasource.xml"};
-    }
-
-    protected String getBeanDefinitionFilterCategories()
+    /**
+     * Start the tests.
+     * 
+     * @param args
+     *            the arguments. Not used
+     */
+    public static void main(String args[])
     {
-        return "default,jdbcDS";
+        junit.awtui.TestRunner.main(new String[]{TestCapability.class.getName()});
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org


Mime
View raw message