3

My goal is to take a XML and/or XSD file and dynamically create a Java object that contains costume annotations and load it into the JVM. A 3rd party library would then look for those objects containing that annotation and perform some function to it. example output of what the java object would look like is as follows

import org.optaplanner.core.api.domain.entity.PlanningEntity;
import org.optaplanner.core.api.domain.variable.PlanningVariable;

@PlanningEntity
public class NameAssignment extends ResourceAssignment{
    private String name;

   @PlanningVariable(valueRangeProviderRefs = { "PlannerCountRange" })    
   public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

The part i'm struggling with is generating the annotation fields @PlanningEntity and @PlanningVariable(valueRangeProviderRefs = { "PlannerCountRange" }) before, during or after the unmarshalling of the XML.

I've been trying to figure it out with JAXB, Dynamic JAXB, Dynamic JAXB, JavaAssist(for byte code manipulation), JCypher, and XJC(Just for compiling the classes). I even thought about dumping Java altogether and using Groovy. I'm starting to feel like I'm over complicating this and need some guidance. This is a "from scratch" project so I have zero constraints on how I implement it.

Any Help would be greatly appreciated.

Justin A
  • 364
  • 4
  • 14
  • 1
    If you're looking to build OptaPlanner domain objects at runtime, take a look at [the kjar technology](https://www.youtube.com/watch?v=t8Qu9J2D2aA) of OptaPlanner Workbench & Execution Server (also open source). – Geoffrey De Smet Jun 02 '16 at 11:10
  • 1
    @GeoffreyDeSmet - Thank you for the reply and all of your great work over the years with OptaPlanner. I am indeed wanting to build OptaPlanner domain objects at runtime. Your suggestion looks promising for future versions of my product. For now the product will run disconnected operations on a rich client without a web app or web service. I was waiting for your release update from this issue [XML file for domain configuration (as an alternative to domain class annotations) to externalize that configuration](https://issues.jboss.org/browse/PLANNER-151) – Justin A Jun 02 '16 at 18:53
  • That issue will allow to use a class *without optaplanner annotations* as a planning entity class, by configuring the annotations through an XML file. So basically like orm.xml for JPA annotations. It's currently not in the 7.0 roadmap (because of other issues that got prioritized over it). – Geoffrey De Smet Jun 03 '16 at 07:38
  • @JustinA - How would you use Groovy to solve this? – MD6380 Jun 08 '16 at 03:13

1 Answers1

0

With jaxb2-annotate-plugin you may inject any static annotations into generated code just provide binding.

Please look for answer Custom annotation with jaxb2-annotate-plugin and XJC tool for details and examples how to use it.

Hubbitus
  • 5,161
  • 3
  • 41
  • 47