Ciao a tutti...

supponete che io abbia un file XML dove conservare le informazioni relative a un cluster.
Ovviamente sarà presente un nodo <hosts> che conterrà tanti nodi <host> e, a seguire, una serie di informazioni annidate in ciascun host.

Il codice che ho scritto è il seguente
codice:
    private ObjectFactory objfactory = new ObjectFactory();

    public void printAll() throws Exception {
        printInfo();
        printHosts();

        JAXBContext jc = JAXBContext.newInstance( "it.polito.dsd.sol3.jaxb" );
        

        //Elemento radice
        //HostsNode hostsXml = new HostsNode();
        //hostsXml.setMasterHost(hostsManager.getMasterHost().getName());
        HostsNode hostsXml = objfactory.createHostsNode();
        hostsXml.setMasterHost(hostsManager.getMasterHost().getName());
        
        //Scendo nel dettaglio di ogni host
        
        for (Host h:hostsManager.getHosts()){
        	HostNode hostXml =  objfactory.createHostNode();
        	//attributi dell'host
        	hostXml.setName(h.getName());
        	hostXml.setStatus(h.getStatus().toString());
        	if (h.isMaster()) 
        		hostXml.setType("master");
        	else
        		if (h.isServer()) hostXml.setType("server");
        		else hostXml.setType("client");
            
        	//Informazioni sull'host: Hardware Information
        	HardwareInformationsNode hi = objfactory.createHardwareInformationsNode();
        	  // si ricordi che questi dati possono anche essere non presenti
              if (h.getNumberOfProcessors() != -1) hi.setNumberOfProcessors(BigInteger.valueOf(h.getNumberOfProcessors()));
              if (h.getSwapSpace() != -1) hi.setSwapSpace(BigInteger.valueOf(h.getSwapSpace()));
         	  if (h.getPhysicalMemory() != -1) hi.setPhysicalMemory(BigInteger.valueOf(h.getPhysicalMemory()));
   			  if (!h.getOperatingSystem().equals(OperatingSystem.UNKNOWN)) hi.setOperatingSystem(h.getOperatingSystem().toString());
        	//Informazioni sull'host: Host Load
        	HostLoadNode hl = objfactory.createHostLoadNode();
        	  // si ricordi che questi dati possono anche essere non presenti
        	  if (h.getLoad() != null){
        	    hl.setCPUUtilization(BigInteger.valueOf(h.getLoad().CPUUtilization));
        	    hl.setNumberOfRunningJobs(BigInteger.valueOf(h.getLoad().numberOfRunningJobs));
        	    hl.setUsedPhysicalMemory(BigInteger.valueOf(h.getLoad().usedPhysicalMemory));
        	    hl.setUsedSwapSpace(BigInteger.valueOf(h.getLoad().usedSwapSpace));
        	  }
        	hostXml.setHardwareInformations(hi);
        	hostXml.setHostLoad(hl);     
         //devo solo collegare hostXml a hostsXml !!!!
          
        	
        }
        
       
        
        JAXBElement<HostsNode> hostsElement = (new ObjectFactory()).createHosts(hostsXml);
        
        Marshaller m = jc.createMarshaller();
        m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
        m.marshal( hostsElement, System.out );
        
    }
Non riesco a linkare all'intero dell'oggetto hostsXml i vari oggetti hostXml che mi sono creato. Sembra non esserci proprio un metodo atto a fare questo (diversamente ad esempio dall'oggetto hostXml, che ha un metodo per aggiungere al proprio interno il nodo hostLoad. Difatti io posso scrivere

hostXml.setHostLoad(hl).

Cosa sto sbagliando ? Sembra che il binding fatto da xjc non crei questo metodo.

Suggerimenti ?

Ciao e grazie!