Google Groups

restriction with enumeration -> case objects flat on package…


Viktor Hedefalk Oct 31, 2011 7:01 AM
Posted in group: scalaxb
From the enumeration :

<xsd:simpleType name="ActivityStatus">
        <xsd:restriction base="xsd:normalizedString">
            <xsd:enumeration value="Planned" />
            <xsd:enumeration value="Cancelled" />
            <xsd:enumeration value="Completed" />
        </xsd:restriction>
    </xsd:simpleType>


I get this in generated code:

trait ActivityStatus

object ActivityStatus {
  def fromString(value: String): ActivityStatus = value match {
    case "Planned" => PlannedValue
    case "Cancelled" => CancelledValue
    case "Completed" => CompletedValue

  }
}

case object PlannedValue extends ActivityStatus { override def
toString = "Planned" }
case object CancelledValue extends ActivityStatus { override def
toString = "Cancelled" }
case object CompletedValue extends ActivityStatus { override def
toString = "Completed" }


I'm curious if it would be possible to wrap the case objects inside
the companion object? Thing is I have another kind of status with the
same names in another type (that just happened to have the same values
now). That one got different names in generated code though:

case object Planned extends ApplicationStatus { override def toString
= "Planned" }
case object Cancelled extends ApplicationStatus { override def
toString = "Cancelled" }
case object Completed extends ApplicationStatus { override def
toString = "Completed" }

I could of course manually put them in different packages, but for ME
it would feel natural if the case objects where wrapped inside the
companion of the specific type of which they belong… But maybe I'm not
seeing the whole picture…?

Thanks,
Viktor