01: /*
02: * Copyright 2004 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
21:
22: public class PublicationSpec {
23: private final String publicationTypeName;
24: private final String publicationOutputName;
25: private final String publicationOutputLabel;
26: private final Map<String, String> publicationProperties;
27:
28: public PublicationSpec(String publicationTypeName,
29: String publicationOutputName,
30: String publicationOutputLabel,
31: Map<String, String> properties) {
32: if (publicationTypeName == null)
33: throw new IllegalArgumentException(
34: "publicationTypeName param can not be null");
35: if (publicationOutputName == null)
36: throw new IllegalArgumentException(
37: "publicationOutputName param can not be null");
38: if (properties == null)
39: throw new IllegalArgumentException(
40: "properties param can not be null");
41:
42: this .publicationTypeName = publicationTypeName;
43: this .publicationOutputName = publicationOutputName;
44: this .publicationOutputLabel = publicationOutputLabel;
45: this .publicationProperties = properties;
46: }
47:
48: public String getPublicationTypeName() {
49: return publicationTypeName;
50: }
51:
52: public String getPublicationOutputName() {
53: return publicationOutputName;
54: }
55:
56: public String getPublicationOutputLabel() {
57: return publicationOutputLabel;
58: }
59:
60: public Map<String, String> getPublicationProperties() {
61: return publicationProperties;
62: }
63:
64: public PublicationSpecsDocument.PublicationSpecs.PublicationSpec getXml() {
65: PublicationSpecsDocument.PublicationSpecs.PublicationSpec pubSpecXml = PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Factory
66: .newInstance();
67: pubSpecXml.setName(publicationOutputName);
68: pubSpecXml.setLabel(publicationOutputLabel);
69: pubSpecXml.setType(publicationTypeName);
70:
71: Map.Entry[] entries = publicationProperties.entrySet().toArray(
72: new Map.Entry[publicationProperties.size()]);
73: PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry[] entriesXml = new PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry[entries.length];
74: for (int i = 0; i < entries.length; i++) {
75: entriesXml[i] = PublicationSpecsDocument.PublicationSpecs.PublicationSpec.Properties.Entry.Factory
76: .newInstance();
77: entriesXml[i].setKey((String) entries[i].getKey());
78: entriesXml[i]
79: .setStringValue((String) entries[i].getValue());
80: }
81:
82: pubSpecXml.addNewProperties().setEntryArray(entriesXml);
83:
84: return pubSpecXml;
85: }
86:
87: public static PublicationSpecsDocument getXml(
88: PublicationSpec[] specs) {
89: PublicationSpecsDocument.PublicationSpecs.PublicationSpec[] specsXml = new PublicationSpecsDocument.PublicationSpecs.PublicationSpec[specs.length];
90: for (int i = 0; i < specsXml.length; i++) {
91: specsXml[i] = specs[i].getXml();
92: }
93:
94: PublicationSpecsDocument doc = PublicationSpecsDocument.Factory
95: .newInstance();
96: doc.addNewPublicationSpecs().setPublicationSpecArray(specsXml);
97: return doc;
98: }
99: }
|