1 16 package org.outerj.daisy.books.publisher; 17 18 import org.outerx.daisy.x10Bookpubspecs.PublicationSpecsDocument; 19 20 import java.util.Map ; 21 22 public class PublicationSpec { 23 private final String publicationTypeName; 24 private final String publicationOutputName; 25 private final String publicationOutputLabel; 26 private final Map publicationProperties; 27 28 public PublicationSpec(String publicationTypeName, String publicationOutputName, String publicationOutputLabel, Map properties) { 29 if (publicationTypeName == null) 30 throw new IllegalArgumentException ("publicationTypeName param can not be null"); 31 if (publicationOutputName == null) 32 throw new IllegalArgumentException ("publicationOutputName param can not be null"); 33 if (properties == null) 34 throw new IllegalArgumentException ("properties param can not be null"); 35 36 this.publicationTypeName = publicationTypeName; 37 this.publicationOutputName = publicationOutputName; 38 this.publicationOutputLabel = publicationOutputLabel; 39 this.publicationProperties = properties; 40 } 41 42 public String getPublicationTypeName() { 43 return publicationTypeName; 44 } 45 46 public String getPublicationOutputName() { 47 return publicationOutputName; 48 } 49 50 public String getPublicationOutputLabel() { 51 return publicationOutputLabel; 52 } 53 54 public Map getPublicationProperties() { 55 return publicationProperties; 56 } 57 58 public PublicationSpecsDocument.PublicationSpecs.PublicationSpec getXml() { 59 PublicationSpecsDocument.PublicationSpecs.PublicationSpec pubSpecXml = PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Factory.newInstance(); 60 pubSpecXml.setName(publicationOutputName); 61 pubSpecXml.setLabel(publicationOutputLabel); 62 pubSpecXml.setType(publicationTypeName); 63 64 Map.Entry [] entries = (Map.Entry [])publicationProperties.entrySet().toArray(new Map.Entry [publicationProperties.size()]); 65 PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry[] entriesXml = 66 new PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry[entries.length]; 67 for (int i = 0; i < entries.length; i++) { 68 entriesXml[i] = PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry.Factory.newInstance(); 69 entriesXml[i].setKey((String )entries[i].getKey()); 70 entriesXml[i].setStringValue((String )entries[i].getValue()); 71 } 72 73 pubSpecXml.addNewProperties().setEntryArray(entriesXml); 74 75 return pubSpecXml; 76 } 77 78 public static PublicationSpecsDocument getXml(PublicationSpec[] specs) { 79 PublicationSpecsDocument.PublicationSpecs.PublicationSpec[] specsXml = new PublicationSpecsDocument.PublicationSpecs.PublicationSpec[specs.length]; 80 for (int i = 0; i < specsXml.length; i++) { 81 specsXml[i] = specs[i].getXml(); 82 } 83 84 PublicationSpecsDocument doc = PublicationSpecsDocument.Factory.newInstance(); 85 doc.addNewPublicationSpecs().setPublicationSpecArray(specsXml); 86 return doc; 87 } 88 } 89 | Popular Tags |