Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java')
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java115
1 files changed, 115 insertions, 0 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java
new file mode 100644
index 0000000000..97b9f47aac
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/orm/AbstractOrmXmlDefinition.java
@@ -0,0 +1,115 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 Oracle. All rights reserved.
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0, which accompanies this distribution
+ * and is available at http://www.eclipse.org/legal/epl-v10.html.
+ *
+ * Contributors:
+ * Oracle - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.jpa.core.internal.context.orm;
+
+import java.util.ArrayList;
+
+import org.eclipse.jpt.common.utility.internal.Tools;
+import org.eclipse.jpt.jpa.core.context.orm.OrmAttributeMappingDefinition;
+import org.eclipse.jpt.jpa.core.context.orm.OrmTypeMappingDefinition;
+import org.eclipse.jpt.jpa.core.context.orm.OrmXmlContextNodeFactory;
+import org.eclipse.jpt.jpa.core.context.orm.OrmXmlDefinition;
+import org.eclipse.jpt.jpa.core.context.orm.UnsupportedOrmAttributeMappingDefinition;
+
+/**
+ * All the state in the definition should be "static"
+ * (i.e. unchanging once it is initialized).
+ */
+public abstract class AbstractOrmXmlDefinition
+ implements OrmXmlDefinition
+{
+ protected final OrmXmlContextNodeFactory factory;
+
+ protected ArrayList<OrmTypeMappingDefinition> typeMappingDefinitions;
+
+ protected ArrayList<OrmAttributeMappingDefinition> attributeMappingDefinitions;
+
+
+ /**
+ * zero-argument constructor
+ */
+ protected AbstractOrmXmlDefinition() {
+ super();
+ this.factory = this.buildContextNodeFactory();
+ }
+
+
+ // ********** factory **********
+
+ protected abstract OrmXmlContextNodeFactory buildContextNodeFactory();
+
+ public OrmXmlContextNodeFactory getContextNodeFactory() {
+ return this.factory;
+ }
+
+
+ // ********** type mapping definitions **********
+
+ public OrmTypeMappingDefinition getTypeMappingDefinition(String mappingKey) {
+ for (OrmTypeMappingDefinition definition : this.getTypeMappingDefinitions()) {
+ if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) {
+ return definition;
+ }
+ }
+ throw new IllegalArgumentException("Illegal type mapping key: " + mappingKey); //$NON-NLS-1$
+ }
+
+ /**
+ * Return a list of mapping definitions to use for types in
+ * <code>orm.xml</code> mapping files.
+ * The order is unimportant.
+ */
+ protected synchronized ArrayList<OrmTypeMappingDefinition> getTypeMappingDefinitions() {
+ if (this.typeMappingDefinitions == null) {
+ this.typeMappingDefinitions = this.buildTypeMappingDefinitions();
+ }
+ return this.typeMappingDefinitions;
+ }
+
+ protected ArrayList<OrmTypeMappingDefinition> buildTypeMappingDefinitions() {
+ ArrayList<OrmTypeMappingDefinition> definitions = new ArrayList<OrmTypeMappingDefinition>();
+ this.addTypeMappingDefinitionsTo(definitions);
+ return definitions;
+ }
+
+ protected abstract void addTypeMappingDefinitionsTo(ArrayList<OrmTypeMappingDefinition> definitions);
+
+
+ // ********** attribute mapping definitions **********
+
+ public OrmAttributeMappingDefinition getAttributeMappingDefinition(String mappingKey) {
+ for (OrmAttributeMappingDefinition definition : this.getAttributeMappingDefinitions()) {
+ if (Tools.valuesAreEqual(definition.getKey(), mappingKey)) {
+ return definition;
+ }
+ }
+ return UnsupportedOrmAttributeMappingDefinition.instance();
+ }
+
+ /**
+ * Return a list of mapping definitions to use for attributes in
+ * <code>orm.xml</code> mapping files.
+ * The order is unimportant.
+ */
+ protected synchronized ArrayList<OrmAttributeMappingDefinition> getAttributeMappingDefinitions() {
+ if (this.attributeMappingDefinitions == null) {
+ this.attributeMappingDefinitions = this.buildAttributeMappingDefinitions();
+ }
+ return this.attributeMappingDefinitions;
+ }
+
+ protected ArrayList<OrmAttributeMappingDefinition> buildAttributeMappingDefinitions() {
+ ArrayList<OrmAttributeMappingDefinition> definitions = new ArrayList<OrmAttributeMappingDefinition>();
+ this.addAttributeMappingDefinitionsTo(definitions);
+ return definitions;
+ }
+
+ protected abstract void addAttributeMappingDefinitionsTo(ArrayList<OrmAttributeMappingDefinition> definitions);
+}

Back to the top