/* * Hibernate, Relational Persistence for Idiomatic Java * * License: GNU Lesser General Public License (LGPL), version 2.1 or later. * See the lgpl.txt file in the root directory or . */ package org.hibernate.boot.model.source.internal.hbm; import org.hibernate.AssertionFailure; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmMapType; import org.hibernate.boot.model.source.spi.AttributeSourceContainer; import org.hibernate.boot.model.source.spi.PluralAttributeIndexSource; import org.hibernate.boot.model.source.spi.PluralAttributeNature; import org.hibernate.boot.model.source.spi.Sortable; import org.hibernate.internal.util.StringHelper; public class PluralAttributeSourceMapImpl extends AbstractPluralAttributeSourceImpl implements IndexedPluralAttributeSource, Sortable { private final PluralAttributeIndexSource indexSource; private final String xmlNodeName; private final JaxbHbmMapType jaxbMap; public PluralAttributeSourceMapImpl( MappingDocument sourceMappingDocument, JaxbHbmMapType jaxbMap, AttributeSourceContainer container) { super( sourceMappingDocument, jaxbMap, container ); this.jaxbMap = jaxbMap; this.xmlNodeName = jaxbMap.getNode(); if ( jaxbMap.getMapKey() != null ) { this.indexSource = new PluralAttributeMapKeySourceBasicImpl( sourceMappingDocument, jaxbMap.getMapKey() ); } else if ( jaxbMap.getIndex() != null ) { this.indexSource = new PluralAttributeMapKeySourceBasicImpl( sourceMappingDocument, jaxbMap.getIndex() ); } else if ( jaxbMap.getCompositeMapKey() != null ) { this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( sourceMappingDocument, this, jaxbMap.getCompositeMapKey() ); } else if ( jaxbMap.getCompositeIndex() != null ) { this.indexSource = new PluralAttributeMapKeySourceEmbeddedImpl( sourceMappingDocument, this, jaxbMap.getCompositeIndex() ); } else if ( jaxbMap.getMapKeyManyToMany() != null ) { this.indexSource = new PluralAttributeMapKeyManyToManySourceImpl( sourceMappingDocument, this, jaxbMap.getMapKeyManyToMany() ); } else if ( jaxbMap.getIndexManyToMany() != null ) { this.indexSource = new PluralAttributeMapKeyManyToManySourceImpl( sourceMappingDocument, this, jaxbMap.getIndexManyToMany() ); } else if ( jaxbMap.getIndexManyToAny() != null ) { this.indexSource = new PluralAttributeMapKeyManyToAnySourceImpl( sourceMappingDocument, this, jaxbMap.getIndexManyToAny() ); } else { throw new AssertionFailure( "No map key found" ); } } @Override public PluralAttributeIndexSource getIndexSource() { return indexSource; } @Override public boolean isSorted() { String comparatorName = getComparatorName(); return StringHelper.isNotEmpty( comparatorName ) && !comparatorName.equals( "unsorted" ); } @Override public String getComparatorName() { return jaxbMap.getSort(); } @Override public PluralAttributeNature getNature() { return PluralAttributeNature.MAP; } @Override public XmlElementMetadata getSourceType() { return XmlElementMetadata.MAP; } @Override public String getXmlNodeName() { return xmlNodeName; } }