<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2012, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file 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.
  -->

  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  targetNamespace="urn:jboss:jboss-jpa:1.0"     
  xmlns="urn:jboss:jboss-jpa:1.0"
  elementFormDefault="unqualified" 
  attributeFormDefault="unqualified" 
  version="1.0">

  <!-- jboss-jpa may be in a jboss-all.xml deployment descriptor to choose between 
       deep/shallow extended persistence inheritance.
  -->  
  
  <!-- example of using shallow inheritance 
      <jboss>
       <jboss-jpa xmlns="http://www.jboss.com/xml/ns/javaee">
       <extended-persistence inheritance="SHALLOW"/>
       </jboss-jpa>
      </jboss>
  -->
  
  <!-- example of using deep inheritance 
      <jboss>
       <jboss-jpa xmlns="http://www.jboss.com/xml/ns/javaee">
       <extended-persistence inheritance="DEEP"/>
       </jboss-jpa>
      </jboss>
  -->
  
  <!-- Root element -->  
  
  <xs:element name="jboss-jpa" type="jboss-jpa-type"/>
  <xs:complexType name="jboss-jpa-type">
    <xs:all>
      <xs:element name="extended-persistence" type="extended-persistence-type" minOccurs="0" maxOccurs="1"/>
    </xs:all>
  </xs:complexType>

  <xs:complexType name="extended-persistence-type">
    <xs:attribute name="inheritance" type="extended-persistence-inheritance-type" default="DEEP" use="optional">
      <xs:annotation>
          <xs:documentation>
            <![CDATA[[
              Controls how JPA extended persistence context (XPC) inheritance is performed.  
              XPC inheritance only occurs between stateful session beans used within the same EJB3 thread.
              This might be a stateful bean that injects other stateful beans (directly or via JNDI lookup).
              
              With DEEP extended persistence inheritance, the extended persistence context is always shared at 
              the top most stateful bean level.  Even if the top level bean does not have an extended persistence 
              context, sub-beans (siblings) will share the extended persistence context (requiring fewer copies of 
              entities to be loaded).
              
              With SHALLOW extended persistence inheritance, the extended persistence context is only shared between 
              a stateful bean and its parent bean.  This means that sibling stateful beans with the same parent bean, 
              will have isolated persistence contexts (assuming the parent bean doesn't have an extended persistence 
              context).
             ]]>
          </xs:documentation>
      </xs:annotation>
    </xs:attribute>
  </xs:complexType>

  <xs:simpleType name="extended-persistence-inheritance-type">
    <xs:restriction base="xs:token">
      <xs:enumeration value="DEEP" />
      <xs:enumeration value="SHALLOW" />
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

