001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA 010 * is licensed to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.connector.store.jpa; 025 026 import java.util.Locale; 027 import java.util.UUID; 028 import javax.persistence.EntityManager; 029 import org.hibernate.ejb.Ejb3Configuration; 030 import org.jboss.dna.common.i18n.I18n; 031 import org.jboss.dna.common.util.CheckArg; 032 import org.jboss.dna.graph.ExecutionContext; 033 import org.jboss.dna.graph.request.processor.RequestProcessor; 034 035 /** 036 * A descriptor of a schema used by this connector. 037 * 038 * @see JpaSource.Models 039 * @see JpaSource.Models#addModel(Model) 040 * @see JpaSource#setModel(String) 041 * @see JpaSource#getModel() 042 * @author Randall Hauch 043 */ 044 public abstract class Model { 045 private final String name; 046 private final I18n description; 047 048 protected Model( String name, 049 I18n description ) { 050 CheckArg.isNotEmpty(name, "name"); 051 CheckArg.isNotNull(description, "description"); 052 this.name = name; 053 this.description = description; 054 } 055 056 public final String getName() { 057 return this.name; 058 } 059 060 /** 061 * Get the description of this model in the default locale. 062 * 063 * @return the description of this model; never null 064 */ 065 public String getDescription() { 066 return description.text(); 067 } 068 069 /** 070 * Get the description of this model in the supplied locale. 071 * 072 * @param locale the locale in which the description is to be returned 073 * @return the description of this model; never null 074 */ 075 public String getDescription( Locale locale ) { 076 return description.text(locale); 077 } 078 079 public abstract RequestProcessor createRequestProcessor( String sourceName, 080 ExecutionContext context, 081 EntityManager entityManager, 082 UUID rootNodeUuid, 083 String nameOfDefaultWorkspace, 084 String[] predefinedWorkspaceNames, 085 long largeValueMinimumSizeInBytes, 086 boolean creatingWorkspacesAllowed, 087 boolean comparessData, 088 boolean enforceReferentialIntegrity ); 089 090 /** 091 * Configure the entity class that will be used by JPA to store information in the database. 092 * 093 * @param configurator the Hibernate {@link Ejb3Configuration} component; never null 094 */ 095 public abstract void configure( Ejb3Configuration configurator ); 096 097 @Override 098 public final int hashCode() { 099 return this.name.hashCode(); 100 } 101 102 @Override 103 public final boolean equals( Object obj ) { 104 if (obj == this) return true; 105 if (obj instanceof Model) { 106 Model that = (Model)obj; 107 if (this.getName().equals(that.getName())) return true; 108 } 109 return false; 110 } 111 112 @Override 113 public final String toString() { 114 return name; 115 } 116 }