KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > books > publisher > impl > dataretrieval > BookDependencies


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.impl.dataretrieval;
17
18 import org.outerx.daisy.x10Bookdeps.BookDependenciesDocument;
19 import org.apache.xmlbeans.XmlOptions;
20 import org.outerj.daisy.books.publisher.impl.VersionKey;
21
22 import java.util.HashSet JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.io.OutputStream JavaDoc;
25 import java.io.IOException JavaDoc;
26
27 public class BookDependencies {
28     private HashSet JavaDoc keys = new HashSet JavaDoc();
29
30     public void addDependency(VersionKey versionKey) {
31         keys.add(versionKey);
32     }
33
34     public void store(OutputStream JavaDoc os) throws IOException JavaDoc {
35         BookDependenciesDocument.BookDependencies.Dependency[] dependenciesXml = new BookDependenciesDocument.BookDependencies.Dependency[keys.size()];
36
37         Iterator JavaDoc keysIt = keys.iterator();
38         for (int i = 0; keysIt.hasNext(); i++) {
39             VersionKey key = (VersionKey)keysIt.next();
40             BookDependenciesDocument.BookDependencies.Dependency dependencyXml = BookDependenciesDocument.BookDependencies.Dependency.Factory.newInstance();
41             dependencyXml.setDocumentId(key.getDocumentId());
42             dependencyXml.setBranchId(key.getBranchId());
43             dependencyXml.setLanguageId(key.getLanguageId());
44             dependencyXml.setVersionId(key.getVersionId());
45             dependenciesXml[i] = dependencyXml;
46         }
47
48         BookDependenciesDocument bookDependenciesDocument = BookDependenciesDocument.Factory.newInstance();
49         bookDependenciesDocument.addNewBookDependencies().setDependencyArray(dependenciesXml);
50
51         XmlOptions xmlOptions = new XmlOptions();
52         xmlOptions.setSavePrettyPrint();
53         bookDependenciesDocument.save(os, xmlOptions);
54     }
55
56 }
57
Popular Tags