KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > PublicationSpec


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.outerj.daisy.books.publisher;
17
18 import org.outerx.daisy.x10Bookpubspecs.PublicationSpecsDocument;
19
20 import java.util.Map JavaDoc;
21
22 public class PublicationSpec {
23     private final String JavaDoc publicationTypeName;
24     private final String JavaDoc publicationOutputName;
25     private final String JavaDoc publicationOutputLabel;
26     private final Map JavaDoc publicationProperties;
27
28     public PublicationSpec(String JavaDoc publicationTypeName, String JavaDoc publicationOutputName, String JavaDoc publicationOutputLabel, Map JavaDoc properties) {
29         if (publicationTypeName == null)
30             throw new IllegalArgumentException JavaDoc("publicationTypeName param can not be null");
31         if (publicationOutputName == null)
32             throw new IllegalArgumentException JavaDoc("publicationOutputName param can not be null");
33         if (properties == null)
34             throw new IllegalArgumentException JavaDoc("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 JavaDoc getPublicationTypeName() {
43         return publicationTypeName;
44     }
45
46     public String JavaDoc getPublicationOutputName() {
47         return publicationOutputName;
48     }
49
50     public String JavaDoc getPublicationOutputLabel() {
51         return publicationOutputLabel;
52     }
53
54     public Map JavaDoc 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 JavaDoc[] entries = (Map.Entry JavaDoc[])publicationProperties.entrySet().toArray(new Map.Entry JavaDoc[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 JavaDoc)entries[i].getKey());
70             entriesXml[i].setStringValue((String JavaDoc)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