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.observe.Observer;
034 import org.jboss.dna.graph.request.processor.RequestProcessor;
035
036 /**
037 * A descriptor of a schema used by this connector.
038 *
039 * @see JpaSource.Models
040 * @see JpaSource.Models#addModel(Model)
041 * @see JpaSource#setModel(String)
042 * @see JpaSource#getModel()
043 * @author Randall Hauch
044 */
045 public abstract class Model {
046 private final String name;
047 private final I18n description;
048
049 protected Model( String name,
050 I18n description ) {
051 CheckArg.isNotEmpty(name, "name");
052 CheckArg.isNotNull(description, "description");
053 this.name = name;
054 this.description = description;
055 }
056
057 public final String getName() {
058 return this.name;
059 }
060
061 /**
062 * Get the description of this model in the default locale.
063 *
064 * @return the description of this model; never null
065 */
066 public String getDescription() {
067 return description.text();
068 }
069
070 /**
071 * Get the description of this model in the supplied locale.
072 *
073 * @param locale the locale in which the description is to be returned
074 * @return the description of this model; never null
075 */
076 public String getDescription( Locale locale ) {
077 return description.text(locale);
078 }
079
080 public abstract RequestProcessor createRequestProcessor( String sourceName,
081 ExecutionContext context,
082 Observer observer,
083 EntityManager entityManager,
084 UUID rootNodeUuid,
085 String nameOfDefaultWorkspace,
086 String[] predefinedWorkspaceNames,
087 long largeValueMinimumSizeInBytes,
088 boolean creatingWorkspacesAllowed,
089 boolean comparessData,
090 boolean enforceReferentialIntegrity );
091
092 /**
093 * Configure the entity class that will be used by JPA to store information in the database.
094 *
095 * @param configurator the Hibernate {@link Ejb3Configuration} component; never null
096 */
097 public abstract void configure( Ejb3Configuration configurator );
098
099 @Override
100 public final int hashCode() {
101 return this.name.hashCode();
102 }
103
104 @Override
105 public final boolean equals( Object obj ) {
106 if (obj == this) return true;
107 if (obj instanceof Model) {
108 Model that = (Model)obj;
109 if (this.getName().equals(that.getName())) return true;
110 }
111 return false;
112 }
113
114 @Override
115 public final String toString() {
116 return name;
117 }
118 }