<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
I think it's a good idea to wrap enums in an object, but changing spec on the generated code (for enhancement) needs to wait till future version 0.7 or 0.8. Plz add an issue on github.
In the meantime, others can chime in for feedback.
-eugene
I just referenced this thread, hope that's ok:
https://github.com/eed3si9n/scalaxb/issues/107
Cheers,
Viktor
[ERROR] /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/scala/dfk/ka/services/CrmService.scala:50:
error: type mismatch;
[INFO] found : Product with Serializable with dfk.ka.generated.ActivityStatus
[INFO] required: dfk.ka.generated.ApplicationStatus
[INFO] status = status))
[INFO] ^
[ERROR] /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/scala/dfk/ka/services/CrmService.scala:86:
error: type mismatch;
[INFO] found : Product with Serializable with
dfk.ka.generated.ApplicationStatus
[INFO] required: dfk.ka.generated.ActivityStatus
[INFO] status = status(activity.status.get),
[INFO] ^
[ERROR] two errors found
The reason is that one of them looks like:
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" }
while the other
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" }
and with the order changed the names of the case objects are also
changed so the ones ending with Value are not the ones ending with
Value on my local machine.
I'll encapsulate them in different packages for now so there's now
rush, but just wanted to share :)
Thanks,
Viktor
I am curious why your build server (jenkins?) is generating sources
inconsistently. I thought these files are returned in alphabetical
order if you're using sbt-scalaxb.
-eugene
I'll see if I can dig something up…
In the meantime, I realized I don't know how to do the package mapping:
I'm using Maven and I see here
http://martiell.github.com/scalaxb/maven/generate-mojo.html#packageName
that there is a Mojo field packageNames that is a Map[String, String].
However, that would mean something like:
<configuration>
<packageNames>
<http://mydomain/myservice>my.service.package.name</http://mydomain/myservice>
</packageNames>
<xsdDirectory>${basedir}/src/main/webapp/static/services/schema/
</xsdDirectory>
</configuration>
which isn't even valid xml. Is there some other way to specify the
mapping or is it possible to escape in any way?
Thanks,
Viktor
The same goes for the package mapping.
-eugene
[INFO] --- scalaxb-maven-plugin:0.6.2:generate (scalaxb) @ dfkka ---
[INFO] Running in process: scalaxb -d
/Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb -p
dfk.ka.generated
/Users/viktor/dev/projects/dfkka/src/main/webapp/static/services/schema/crm/ActivitiesCreatedOrUpdated.xsd
/Users/viktor/dev/projects/dfkka/src/main/webapp/static/services/schema/crm/ApplicationsCreatedOrUpdated.xsd
/Users/viktor/dev/projects/dfkka/src/main/webapp/static/services/schema/FetchInvoiceData.xsd
/Users/viktor/dev/projects/dfkka/src/main/webapp/static/services/schema/MarkOrderInvoiced.xsd
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/MarkOrderInvoiced.scala.
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/FetchInvoiceData.scala.
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/ApplicationsCreatedOrUpdated.scala.
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/ActivitiesCreatedOrUpdated.scala.
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/ActivitiesCreatedOrUpdated_xmlprotocol.scala.
generated /Users/viktor/dev/projects/dfkka/target/generated-sources/scalaxb/scalaxb.scala.
and from my build server:
[INFO] --- scalaxb-maven-plugin:0.6.2:generate (scalaxb) @ dfkka ---
[INFO] Running in process: scalaxb -d
"/usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb$"
-p dfk.ka.generated
"/usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/webapp/static/services/schema/FetchInvoiceData.xsd$"
"/usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/webapp/static/services/schema/MarkOrderInvoiced.xsd$"
"/usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/webapp/static/services/schema/crm/ApplicationsCreatedOrUpdated.xsd$"
"/usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/src/main/webapp/static/services/schema/crm/ActivitiesCreatedOrUpdated.xsd$"
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/ActivitiesCreatedOrUpdated.scala.
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/ApplicationsCreatedOrUpdated.scala.
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/MarkOrderInvoiced.scala.
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/FetchInvoiceData.scala.
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/FetchInvoiceData_xmlprotocol.scala.
generated /usr/share/java/webapps/jenkins/home/jobs/DFK_KA_verify/workspace/target/generated-sources/scalaxb/scalaxb.scala.
so it looks like it's my local machine that doesn't do it alphabetically…
Thanks,
Viktor
<packageNames>
<ActivitiesCreatedOrUpdated>dfk.ka.generated.crm.activities</ActivitiesCreatedOrUpdated>
<ApplitacionsCreatedOrUpdated>dfk.ka.generated.crm.activities</ApplitacionsCreatedOrUpdated>
</packageNames>
but I got:
Error: Unknown argument
'-pActivitiesCreatedOrUpdated=dfk.ka.generated.crm.activities'
There should be a colon there right? Should I open a ticket and put on Martin?
Thanks,
Viktor
alphabetical processing - https://github.com/eed3si9n/scalaxb/issues/110
mojo mappings - https://github.com/eed3si9n/scalaxb/issues/111
Thanks,
Viktor
I didn't expect that. Which version of the maven plugin are you using?
Martin
The missing colon in -p: is fixed is 0.6.6-SNAPSHOT, but you'll still
have the same problem that you can't use URLs as XML element names. :(
Martin
Thanks,
Viktor
Thanks for reporting these.
I've deployed a new snapshot scalaxb-maven-plugin (0.6.6-SNAPSHOT).
I think it should fix these, but I've only done some unit testing, no
new integration tests.
There's an example of the mojo mapping here:
https://github.com/eed3si9n/scalaxb/blob/master/mvn-scalaxb/src/test/resources/org/scalaxb/maven/packageNames.xml
I'll try to add some more tests and update docs this weekend.
If you get a chance to try the snapshot before then, please let me
know if it fixes the issues for you.
Cheers,
Martin.
I did a quick try just now and I got some problems, but I might misuse
the combination of
<packageName> and <packageNames>
With this mapping:
<packageName>dfk.ka.generated</packageName>
<packageNames>
<packageName>
<uri>http://www.kgm.se/df100/service</uri>
<package>se.kgm.df100</package>
</packageName>
</packageNames>
I got this:
package dfk.ka.generated
case class Activity(uniplyId: BigInt,
product: dfk.ka.generated.ProductType,
startDate: javax.xml.datatype.XMLGregorianCalendar,
endDate: javax.xml.datatype.XMLGregorianCalendar,
location: String,
city: String,
status: dfk.ka.generated.ActivityStatus,
internal: Boolean)
case class ActivitiesCreatedOrUpdated(Activity: se.kgm.df100.Activity*)
which doesn't compile. So it seems it used the package from
<packageName> in the top of the file but later used the correct
package defined in the mappings. For me it would be excellent if it
was possible to have the <packageName> as a fallback for unqualified
namespaces or unspecified mappings and then be able to "override" with
the packageNames mappings.
Should I remove the packageName-tag if I am to use <packageNames>?
Thanks,
Viktor
I quickly answer myself: it didn't help. There was still the default
package name of "generated" in the top of the file:
// Generated by <a href="http://scalaxb.org/">scalaxb</a>.
package generated
case class Activity(uniplyId: BigInt,
product: generated.ProductType,
startDate: javax.xml.datatype.XMLGregorianCalendar,
endDate: javax.xml.datatype.XMLGregorianCalendar,
location: String,
city: String,
status: generated.ActivityStatus,
internal: Boolean)
case class ActivitiesCreatedOrUpdated(Activity: se.kgm.df100.Activity*)
Thanks,
Viktor
I think it's fine to use packageName and packageNames together.
The protocol code will end up in the package specified by packageName,
and the case classes in the packages specified by the packageNames map
(but defaulting to the packageName if unspecified).
There's an integration test with exactly this setup, the pom:
https://github.com/eed3si9n/scalaxb/blob/master/mvn-scalaxb/src/it/itp04-packages/pom.xml
... and the files expected to be generated:
https://github.com/eed3si9n/scalaxb/blob/master/mvn-scalaxb/src/test/java/org/scalaxb/maven/it/ITP04Packages.java
Martin
On Fri, Nov 11, 2011 at 3:20 PM, eugene yokota <eed3...@gmail.com> wrote:
> What you described should be the intended behavior.
But the code I posted doesn't compile. The case class is defined as
"generated.Activity" but used as "se.kgm.df100.Activity"…
> Do you have the schema or wsld available somewhere I can test?
I'll try to compose a small self-contained reproducable example and get back…
Cheers,
Viktor
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://www.hedefalk.se/test"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://www.hedefalk.se/test">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.hedefalk.se/test"
targetNameSpace="http://www.hedefalk.se/test">
<xsd:element name="WsdlTestElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="switch" type="WsdlSwitch" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="WsdlSwitch">
<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="On" />
<xsd:enumeration value="Off" />
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
<wsdl:portType name="service">
</wsdl:portType>
<wsdl:binding name="serviceSoap11" type="tns:service">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
</wsdl:binding>
<wsdl:service name="serviceService">
<wsdl:port binding="tns:serviceSoap11" name="serviceSoap11">
<soap:address location="http://hedefalk.se:80/ws/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
and this mapping:
<packageName>
dfk.ka.generated
</packageName>
<packageNames>
<packageName>
<uri>http://www.hedefalk.se/test</uri>
<package>se.hedefalk.test</package>
</packageName>
</packageNames>
gives the following code:
// Generated by <a href="http://scalaxb.org/">scalaxb</a>.
package se.hedefalk.test
case class WsdlTestElement(switch: dfk.ka.generated.WsdlSwitch)
trait WsdlSwitch
object WsdlSwitch {
def fromString(value: String): WsdlSwitch = value match {
case "On" => OnValue
case "Off" => OffValue
}
}
case object OnValue extends WsdlSwitch { override def toString = "On" }
case object OffValue extends WsdlSwitch { override def toString = "Off" }
trait Service {
}
which doesn't compile since the package names of declaration and usage differ.
If instead I only use an xsd with kindof the same schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.hedefalk.se/test"
targetNameSpace="http://www.hedefalk.se/test">
<xsd:element name="TestXsdElement">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="switch" type="XsdSwitch"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="XsdSwitch">
<xsd:restriction base="xsd:normalizedString">
<xsd:enumeration value="On"/>
<xsd:enumeration value="Off"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
I get
// Generated by <a href="http://scalaxb.org/">scalaxb</a>.
package dfk.ka.generated
case class TestXsdElement(switch: dfk.ka.generated.XsdSwitch)
trait XsdSwitch
object XsdSwitch {
def fromString(value: String): XsdSwitch = value match {
case "On" => On
case "Off" => Off
}
}
case object On extends XsdSwitch { override def toString = "On" }
case object Off extends XsdSwitch { override def toString = "Off" }
which haven't been mapped at all.
Maybe I'm misunderstanding how this should be used…?
Thanks,
Viktor
So I figured I would just build myself from source:
> sbt "project app" "+ publish-local"
It worked fine, but it publishes to .ivy2… Is there a quick way to
make sbt publish to my local mvn repo so I don't have to do manual
installs? I kindof remember there was before, but I can't find the
resource…
Thanks,
Viktor
On Mon, Nov 21, 2011 at 2:32 AM, Viktor Hedefalk <hede...@gmail.com> wrote:
> Excellent!
>
> Thanks a lot,
> Viktor
>
> Den 21 nov 2011 02:01 skrev "eugene yokota" <eed3...@gmail.com>:
>>
>> This has been identified as [#117] and I fixed it in 0.6.7-SNAPSHOT.
>> I tried your sample, and it generated compilable code.
>> -eugene
>> [#117]: https://github.com/eed3si9n/scalaxb/issues/117
But I got test errors:
<error message="Unresolved compilation problems:
The type scala.collection.Seq cannot be resolved. It is indirectly
referenced from required .class files
The import scala cannot be resolved
JavaConversions cannot be resolved
" type="java.lang.Error">java.lang.Error: Unresolved compilation problems:
The type scala.collection.Seq cannot be resolved. It is indirectly
referenced from required .class files
The import scala cannot be resolved
JavaConversions cannot be resolved
…
Any tips?
Thanks,
Viktor
Is the project open in an IDE? Perhaps it's spitting out broken class
files, so doing a clean might fix things…
But for now, I'd suggest using the 0.6.6 release of mvn-scalaxb with
scalaxb 0.6.7-SNAPSHOT, like this:
<plugin>
<groupId>org.scalaxb</groupId>
<artifactId>scalaxb-maven-plugin</artifactId>
<version>0.6.6</version>
<configuration>
...
</configuration>
<executions>
<execution>
<id>scalaxb</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.scalaxb</groupId>
<artifactId>scalaxb_2.9.1</artifactId>
<version>0.6.7-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
Martin
> Is the project open in an IDE? Perhaps it's spitting out broken class
> files, so doing a clean might fix things…
So I tried with just mvn clean install -s settings.xml, but it didn't help…
> But for now, I'd suggest using the 0.6.6 release of mvn-scalaxb with
> scalaxb 0.6.7-SNAPSHOT, like this:
>
> <dependencies>
> <dependency>
> <groupId>org.scalaxb</groupId>
> <artifactId>scalaxb_2.9.1</artifactId>
> <version>0.6.7-SNAPSHOT</version>
> </dependency>
> </dependencies>
> </plugin>
>
Ah, I didn't know I could do that which was just what I wanted I guess. Thanks!
/Viktor