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.repository.commonimpl;
17:
18: import org.outerj.daisy.repository.AvailableVariants;
19: import org.outerj.daisy.repository.AvailableVariant;
20: import org.outerj.daisy.repository.RepositoryException;
21: import org.outerx.daisy.x10.AvailableVariantsDocument;
22: import org.outerx.daisy.x10.AvailableVariantDocument;
23:
24: public class AvailableVariantsImpl implements AvailableVariants {
25: private final AvailableVariant[] availableVariants;
26:
27: public AvailableVariantsImpl(AvailableVariant[] availableVariants) {
28: this .availableVariants = availableVariants;
29: }
30:
31: public AvailableVariant[] getArray() {
32: return availableVariants;
33: }
34:
35: public int size() {
36: return availableVariants.length;
37: }
38:
39: public boolean hasVariant(long branchId, long languageId) {
40: for (int i = 0; i < availableVariants.length; i++) {
41: if (availableVariants[i].getBranchId() == branchId
42: && availableVariants[i].getLanguageId() == languageId) {
43: return true;
44: }
45: }
46: return false;
47: }
48:
49: public AvailableVariantsDocument getXml() {
50: try {
51: return getXml(false);
52: } catch (RepositoryException e) {
53: // getXml only throws an exception if includeVariantNames is true
54: throw new RuntimeException(e);
55: }
56: }
57:
58: public AvailableVariantsDocument getXml(boolean includeVariantNames)
59: throws RepositoryException {
60: AvailableVariantDocument.AvailableVariant[] availableVariantXml = new AvailableVariantDocument.AvailableVariant[availableVariants.length];
61: for (int i = 0; i < availableVariants.length; i++) {
62: availableVariantXml[i] = availableVariants[i].getXml(
63: includeVariantNames).getAvailableVariant();
64: }
65:
66: AvailableVariantsDocument document = AvailableVariantsDocument.Factory
67: .newInstance();
68: AvailableVariantsDocument.AvailableVariants availableVariantsXml = document
69: .addNewAvailableVariants();
70: availableVariantsXml
71: .setAvailableVariantArray(availableVariantXml);
72: return document;
73: }
74: }
|