Property changes on: . ___________________________________________________________________ Modified: svn:ignore - derby.log target *.iws *.ipr *.iml .* jcoverage* junit*.properties + derby.log target *.iws *.ipr *.iml .* jcoverage* junit*.properties target-eclipse Index: src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/EnumCollectionConverterImpl.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/EnumCollectionConverterImpl.java (revision 0) +++ src/main/java/org/apache/jackrabbit/ocm/manager/collectionconverter/impl/EnumCollectionConverterImpl.java (revision 0) @@ -0,0 +1,181 @@ +/* + * 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.jackrabbit.ocm.manager.collectionconverter.impl; + + +import java.util.Iterator; +import java.util.Map; + +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.Value; +import javax.jcr.ValueFactory; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.ocm.exception.JcrMappingException; +import org.apache.jackrabbit.ocm.exception.ObjectContentManagerException; +import org.apache.jackrabbit.ocm.manager.atomictypeconverter.AtomicTypeConverter; +import org.apache.jackrabbit.ocm.manager.atomictypeconverter.impl.UndefinedTypeConverterImpl; +import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableCollection; +import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableObjectsUtil; +import org.apache.jackrabbit.ocm.manager.collectionconverter.ManageableObjects; +import org.apache.jackrabbit.ocm.manager.enumconverter.EnumTypeConverter; +import org.apache.jackrabbit.ocm.manager.objectconverter.ObjectConverter; +import org.apache.jackrabbit.ocm.mapper.Mapper; +import org.apache.jackrabbit.ocm.mapper.model.CollectionDescriptor; +import org.apache.jackrabbit.ocm.reflection.ReflectionUtils; + +/** + * Collection Mapping/convertion implementation used for enum collections + * + * This collection mapping strategy maps a collection into a JCR multi value property + * + * @author Christophe Lombart + * @author Alexandru Popescu + * @author Boni Gopalan + */ +public class EnumCollectionConverterImpl extends AbstractCollectionConverterImpl { + + private EnumTypeConverter enumConverter = new EnumTypeConverter(); + /** + * Constructor + * + * @param atomicTypeConverters + * @param objectConverter + * @param mapper + */ + public EnumCollectionConverterImpl( Map atomicTypeConverters, + ObjectConverter objectConverter, + Mapper mapper) { + super(atomicTypeConverters, objectConverter, mapper); + } + + /** + * + * @see AbstractCollectionConverterImpl#doInsertCollection(Session, Node, CollectionDescriptor, ManageableCollection) + */ + protected void doInsertCollection(Session session, + Node parentNode, + CollectionDescriptor collectionDescriptor, + ManageableObjects objects) throws RepositoryException { + try { + if (objects == null) { + return; + } + + String jcrName = getCollectionJcrName(collectionDescriptor); + Value[] values = new Value[objects.getSize()]; + ValueFactory valueFactory = session.getValueFactory(); + Iterator collectionIterator = objects.getIterator(); + for (int i = 0; i < objects.getSize(); i++) { + Object fieldValue = collectionIterator.next(); + values[i] = enumConverter.getValue(valueFactory, fieldValue); + } + + parentNode.setProperty(jcrName, values); + } + catch(ValueFormatException vfe) { + throw new ObjectContentManagerException("Cannot insert collection field : " + + collectionDescriptor.getFieldName() + + " of class " + + collectionDescriptor.getClassDescriptor().getClassName(), vfe); + } + } + + /** + * + * @see AbstractCollectionConverterImpl#doUpdateCollection(Session, Node, CollectionDescriptor, ManageableCollection) + */ + protected void doUpdateCollection(Session session, + Node parentNode, + CollectionDescriptor collectionDescriptor, + ManageableObjects objects) throws RepositoryException { + String jcrName = getCollectionJcrName(collectionDescriptor); + + // Delete existing values + if (parentNode.hasProperty(jcrName)) { + parentNode.setProperty(jcrName, (Value[]) null); + } + + if (objects == null) { + return; + } + + + // Add all collection element into an Value array + Value[] values = new Value[objects.getSize()]; + ValueFactory valueFactory = session.getValueFactory(); + int i = 0; + for (Iterator collectionIterator = objects.getIterator(); collectionIterator.hasNext(); i++) { + Object fieldValue = collectionIterator.next(); + values[i] = enumConverter.getValue(valueFactory, fieldValue); + } + + parentNode.setProperty(jcrName, values); + } + + /** + * @see AbstractCollectionConverterImpl#doGetCollection(Session, Node, CollectionDescriptor, Class) + */ + protected ManageableObjects doGetCollection(Session session, + Node parentNode, + CollectionDescriptor collectionDescriptor, + Class collectionFieldClass) throws RepositoryException { + try { + String jcrName = getCollectionJcrName(collectionDescriptor); + if (!parentNode.hasProperty(jcrName)) { + return null; + } + Property property = parentNode.getProperty(jcrName); + Value[] values = property.getValues(); + if (values == null || values.length <= 0){ + return null; + } + + ManageableObjects objects = ManageableObjectsUtil.getManageableObjects(collectionFieldClass); + for (int i = 0; i < values.length; i++) { + ((ManageableCollection) objects).addObject(enumConverter.getObject(values[i])); + } + + return objects; + } + catch(ValueFormatException vfe) { + throw new ObjectContentManagerException("Cannot get the collection field : " + + collectionDescriptor.getFieldName() + + "for class " + collectionDescriptor.getClassDescriptor().getClassName(), + vfe); + } + } + + /** + * @see AbstractCollectionConverterImpl#doIsNull(Session, Node, CollectionDescriptor, Class) + */ + protected boolean doIsNull(Session session, + Node parentNode, + CollectionDescriptor collectionDescriptor, + Class collectionFieldClass) throws RepositoryException { + String jcrName = getCollectionJcrName(collectionDescriptor); + + if (!parentNode.hasProperty(jcrName)) { + return true; + } + return false; + } +} \ No newline at end of file Index: src/main/java/org/apache/jackrabbit/ocm/manager/enumconverter/EnumTypeConverter.java =================================================================== --- src/main/java/org/apache/jackrabbit/ocm/manager/enumconverter/EnumTypeConverter.java (revision 0) +++ src/main/java/org/apache/jackrabbit/ocm/manager/enumconverter/EnumTypeConverter.java (revision 0) @@ -0,0 +1,82 @@ +/* +* Copyright © BioImagene Inc. 2005-2008 All right reserved. + +* The copyright to the computer program(s) herein is the property of Bioimagene Inc. +* The program(s) may be used and/or copied only with the written permission +* of Bioimagene or in accordance with the terms and conditions stipulated in the +* agreement/contract under which the program(s) have been supplied. +*/ +package org.apache.jackrabbit.ocm.manager.enumconverter; + +import org.apache.commons.lang.StringUtils; + +import org.apache.jackrabbit.ocm.manager.atomictypeconverter.AtomicTypeConverter; + +import java.io.InvalidClassException; + +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFactory; +import javax.jcr.ValueFormatException; + + +/** +* +* SimpleEnumerationTypeConverter class. +* +* This converter can map type Enum (java.lang.Enum) to JCR properties and back. +* +* @author Boni Gopalan +*/ +public class EnumTypeConverter implements AtomicTypeConverter { + + public Object getObject(Value value) { + try { + String propertyValue = value.getString(); + String[] enumerationDef = StringUtils.split(propertyValue, ':'); + String enumerationClass = enumerationDef[0]; + String enumerationValue = enumerationDef[1]; + Enum[] enumerations = (Enum[]) Class.forName(enumerationClass) + .getEnumConstants(); + int size = enumerations.length; + + for (int i = 0; i < size; i++) { + if (enumerations[i].name().equals(enumerationValue)) { + return enumerations[i]; + } + } + + throw new RuntimeException(new InvalidClassException(enumerationClass + + " Does not contain an enumeration " + enumerationValue)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Value getValue(ValueFactory valueFactory, Object object) { + if (object == null) { + return null; + } + + if (!(object instanceof Enum)) { + throw new RuntimeException(new InvalidClassException(EnumTypeConverter.class.getSimpleName() + + " Can only convert simple Enumerations")); + } + + String value; + Enum anEnum = (Enum) (object); + value = anEnum.getDeclaringClass().getName() + ":" + anEnum.name(); + + return valueFactory.createValue(value); + } + + public String getXPathQueryValue(ValueFactory valueFactory, Object object) { + Value value = getValue(valueFactory, object); + + try { + return "'" + value.getString() + "'"; + } catch (Exception e) { + throw new RuntimeException(e.fillInStackTrace()); + } + } +} Index: src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java (revision 704127) +++ src/test/java/org/apache/jackrabbit/ocm/AnnotationTestBase.java (working copy) @@ -53,6 +53,7 @@ import org.apache.jackrabbit.ocm.testmodel.collection.Element; import org.apache.jackrabbit.ocm.testmodel.collection.Main; import org.apache.jackrabbit.ocm.testmodel.collection.Person; +import org.apache.jackrabbit.ocm.testmodel.enumeration.Odyssey; import org.apache.jackrabbit.ocm.testmodel.inheritance.Ancestor; import org.apache.jackrabbit.ocm.testmodel.inheritance.AnotherDescendant; import org.apache.jackrabbit.ocm.testmodel.inheritance.Descendant; @@ -172,6 +173,7 @@ classes.add(SimpleAnnotedClass.class); classes.add(SimpleInterface.class); classes.add(Person.class); + classes.add(Odyssey.class); Mapper mapper = new AnnotationMapperImpl(classes); ocm = new ObjectContentManagerImpl(session, mapper); Index: src/test/java/org/apache/jackrabbit/ocm/DigesterTestBase.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/DigesterTestBase.java (revision 704127) +++ src/test/java/org/apache/jackrabbit/ocm/DigesterTestBase.java (working copy) @@ -58,7 +58,9 @@ "./src/test/test-config/jcrmapping-inheritance.xml", "./src/test/test-config/jcrmapping-jcrnodetypes.xml", "./src/test/test-config/jcrmapping-uuid.xml", - "./src/test/test-config/jcrmapping-complex-collections.xml"}; + "./src/test/test-config/jcrmapping-complex-collections.xml", + "./src/test/test-config/jcrmapping-Enum.xml" + }; session = RepositoryUtil.login(repository, "superuser", "superuser"); ocm = new ObjectContentManagerImpl(session, files); Index: src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/AnnotationSimpleEnumerationTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/AnnotationSimpleEnumerationTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/AnnotationSimpleEnumerationTest.java (revision 0) @@ -0,0 +1,74 @@ +/* + * 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.jackrabbit.ocm.manager.enumeration; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.ocm.AnnotationTestBase; +import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup; +import org.apache.jackrabbit.ocm.DigesterTestBase; +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.apache.jackrabbit.ocm.testmodel.A; +import org.apache.jackrabbit.ocm.testmodel.B; +import org.apache.jackrabbit.ocm.testmodel.C; +import org.apache.jackrabbit.ocm.testmodel.Discriminator; +import org.apache.jackrabbit.ocm.testmodel.enumeration.Odyssey; +import org.apache.jackrabbit.ocm.testmodel.enumeration.Planet; + +/** + * Test Simple Enumeration mappings + * + * @author Boni Gopalan + */ +public class AnnotationSimpleEnumerationTest extends AnnotationTestBase +{ + private final static Log logger = LogFactory.getLog(AnnotationSimpleEnumerationTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public AnnotationSimpleEnumerationTest(String testName) throws Exception + { + super(testName); + } + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new RepositoryLifecycleTestSetup( + new TestSuite(AnnotationSimpleEnumerationTest.class)); + } + + public void testMapSimpleEnumeration() + { + try { + new SimpleEnumerationTestBase(getObjectContentManager()).testMapSimpleEnumeration(); + } catch (Throwable e) { + e.printStackTrace(); + fail("Tests resulted in exception"); + } + } + +} Index: src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/DigesterSimpleEnumerationTest.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/DigesterSimpleEnumerationTest.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/DigesterSimpleEnumerationTest.java (revision 0) @@ -0,0 +1,64 @@ +/* + * 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.jackrabbit.ocm.manager.enumeration; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.runner.TestCaseClassLoader; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.ocm.DigesterTestBase; +import org.apache.jackrabbit.ocm.RepositoryLifecycleTestSetup; + +/** + * Test Persisting and retrieving Enum values. + * + * @author Boni Gopalan + */ +public class DigesterSimpleEnumerationTest extends DigesterTestBase +{ + private final static Log log = LogFactory.getLog(DigesterSimpleEnumerationTest.class); + + /** + *

Defines the test case name for junit.

+ * @param testName The test case name. + */ + public DigesterSimpleEnumerationTest(String testName) throws Exception + { + super(testName); + } + + public static Test suite() + { + // All methods starting with "test" will be executed in the test suite. + return new RepositoryLifecycleTestSetup( + new TestSuite(DigesterSimpleEnumerationTest.class)); + } + + public void testMapSimpleEnumeration() + { + try { + new SimpleEnumerationTestBase(getObjectContentManager()).testMapSimpleEnumeration(); + } catch (Throwable e) { + e.printStackTrace(); + fail("Tests resulted in exception"); + } + } + +} Index: src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/SimpleEnumerationTestBase.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/SimpleEnumerationTestBase.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/manager/enumeration/SimpleEnumerationTestBase.java (revision 0) @@ -0,0 +1,94 @@ +/* + * 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.jackrabbit.ocm.manager.enumeration; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.jackrabbit.ocm.manager.ObjectContentManager; +import org.apache.jackrabbit.ocm.testmodel.enumeration.Odyssey; +import org.apache.jackrabbit.ocm.testmodel.enumeration.Planet; + +/** + * Test Simple Enumeration mappings + * + * @author Boni Gopalan + */ +public class SimpleEnumerationTestBase extends TestCase +{ + private final static Log logger = LogFactory.getLog(SimpleEnumerationTestBase.class); + ObjectContentManager ocm; + public SimpleEnumerationTestBase(ObjectContentManager ocm){ + this.ocm = ocm; + } + + public void testMapSimpleEnumeration() + { + try + { + // -------------------------------------------------------------------------------- + // Create and store an object graph in the repository + // -------------------------------------------------------------------------------- + Odyssey odyssey = new Odyssey(); + odyssey.setPath("/odesseyToMars"); + odyssey.setGoingTo(Planet.MARS); + odyssey.setStartingFrom(Planet.EARTH); + odyssey.setStops(getStops()); + ocm.insert(odyssey); + Odyssey fbOdessey = (Odyssey)ocm.getObject("/odesseyToMars"); + assertTrue("Fetched back Enum did not match the saved data", fbOdessey.getGoingTo() == Planet.MARS); + assertTrue("Fetched back Enum did not match the saved data", fbOdessey.getStartingFrom() == Planet.EARTH); + assertTrue("Fetched back Enum did not match the saved Enum Collection Size", fbOdessey.getStops().size() == odyssey.getStops().size()); + List stops = getStops(); + List fbStops = fbOdessey.getStops(); + for (Planet aStop : stops){ + assertContains("Fetched back list did not contain :" + aStop.toString(), aStop, fbStops); + logger.info("Contains Enum : " + aStop.toString()); + } + } + catch (Exception e) + { + e.printStackTrace(); + fail("Exception occurs during the unit test : " + e); + } + + } + + private static void assertContains(String message, Planet value, List aList){ + for (Enum anObject : aList){ + if (anObject == null){ + if (value == null) return; + continue; + } + if (anObject.equals(value)) return; + } + fail(message); + } + + private List getStops(){ + List stops = new ArrayList(); + stops.add(Planet.MARS); + stops.add(Planet.MERCURY); + stops.add(Planet.JUPITER); + return stops; + } + +} Index: src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Odyssey.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Odyssey.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Odyssey.java (revision 0) @@ -0,0 +1,161 @@ +package org.apache.jackrabbit.ocm.testmodel.enumeration; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.apache.jackrabbit.ocm.manager.collectionconverter.impl.EnumCollectionConverterImpl; +import org.apache.jackrabbit.ocm.manager.enumconverter.EnumTypeConverter; +import org.apache.jackrabbit.ocm.mapper.impl.annotation.Field; +import org.apache.jackrabbit.ocm.mapper.impl.annotation.Node; + +@Node +public class Odyssey { + @Field(path=true) + private String path = null; + @Field(converter=EnumTypeConverter.class) + private Planet startingFrom; + @Field(converter=EnumTypeConverter.class) + private Planet goingTo; + public Odyssey(){ + startingFrom = Planet.EARTH; + goingTo = Planet.PLUTO; + stops = new ArrayList(); + } + @org.apache.jackrabbit.ocm.mapper.impl.annotation.Collection(collectionConverter=EnumCollectionConverterImpl.class) + private java.util.List stops; + + public void add(int index, Planet element) { + stops.add(index, element); + } + + public boolean add(Planet e) { + return stops.add(e); + } + + public boolean addAll(Collection c) { + return stops.addAll(c); + } + + public boolean addAll(int index, Collection c) { + return stops.addAll(index, c); + } + + public void clear() { + stops.clear(); + } + + public boolean contains(Object o) { + return stops.contains(o); + } + + public boolean containsAll(Collection c) { + return stops.containsAll(c); + } + + public boolean equals(Object o) { + return stops.equals(o); + } + + public Planet get(int index) { + return stops.get(index); + } + + public int hashCode() { + return stops.hashCode(); + } + + public int indexOf(Object o) { + return stops.indexOf(o); + } + + public boolean isEmpty() { + return stops.isEmpty(); + } + + public Iterator iterator() { + return stops.iterator(); + } + + public int lastIndexOf(Object o) { + return stops.lastIndexOf(o); + } + + public ListIterator listIterator() { + return stops.listIterator(); + } + + public ListIterator listIterator(int index) { + return stops.listIterator(index); + } + + public Planet remove(int index) { + return stops.remove(index); + } + + public boolean remove(Object o) { + return stops.remove(o); + } + + public boolean removeAll(Collection c) { + return stops.removeAll(c); + } + + public boolean retainAll(Collection c) { + return stops.retainAll(c); + } + + public Planet set(int index, Planet element) { + return stops.set(index, element); + } + + public int size() { + return stops.size(); + } + + public List subList(int fromIndex, int toIndex) { + return stops.subList(fromIndex, toIndex); + } + + public Object[] toArray() { + return stops.toArray(); + } + + public T[] toArray(T[] a) { + return stops.toArray(a); + } + + public java.util.List getStops() { + return stops; + } + + public void setStops(java.util.List stops) { + this.stops = stops; + } + + public Planet getStartingFrom() { + return startingFrom; + } + + public void setStartingFrom(Planet startingFrom) { + this.startingFrom = startingFrom; + } + + public Planet getGoingTo() { + return goingTo; + } + + public void setGoingTo(Planet goingTo) { + this.goingTo = goingTo; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } +} Index: src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Planet.java =================================================================== --- src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Planet.java (revision 0) +++ src/test/java/org/apache/jackrabbit/ocm/testmodel/enumeration/Planet.java (revision 0) @@ -0,0 +1,32 @@ +package org.apache.jackrabbit.ocm.testmodel.enumeration; + +public enum Planet { + MERCURY (3.303e+23, 2.4397e6), + VENUS (4.869e+24, 6.0518e6), + EARTH (5.976e+24, 6.37814e6), + MARS (6.421e+23, 3.3972e6), + JUPITER (1.9e+27, 7.1492e7), + SATURN (5.688e+26, 6.0268e7), + URANUS (8.686e+25, 2.5559e7), + NEPTUNE (1.024e+26, 2.4746e7), + PLUTO (1.27e+22, 1.137e6); + + private final double mass; // in kilograms + private final double radius; // in meters + Planet(double mass, double radius) { + this.mass = mass; + this.radius = radius; + } + public double mass() { return mass; } + public double radius() { return radius; } + + // universal gravitational constant (m3 kg-1 s-2) + public static final double G = 6.67300E-11; + + public double surfaceGravity() { + return G * mass / (radius * radius); + } + public double surfaceWeight(double otherMass) { + return otherMass * surfaceGravity(); + } +} Index: src/test/test-config/jcrmapping-Enum.xml =================================================================== --- src/test/test-config/jcrmapping-Enum.xml (revision 0) +++ src/test/test-config/jcrmapping-Enum.xml (revision 0) @@ -0,0 +1,33 @@ + + + + + + + + + + + +