KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > commonimpl > variant > CommonVariantManager


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.repository.commonimpl.variant;
17
18 import org.outerj.daisy.repository.variant.*;
19 import org.outerj.daisy.repository.commonimpl.AuthenticatedUser;
20 import org.outerj.daisy.repository.RepositoryException;
21 import org.outerj.daisy.repository.RepositoryListener;
22
23 public class CommonVariantManager {
24     private VariantStrategy strategy;
25     private VariantCache cache;
26
27     public CommonVariantManager(VariantStrategy strategy, VariantCache cache) {
28         this.strategy = strategy;
29         this.cache = cache;
30     }
31
32     public RepositoryListener getCacheListener() {
33         return cache;
34     }
35
36     public Branch createBranch(String JavaDoc name, AuthenticatedUser user) {
37         return new BranchImpl(strategy, name, user);
38     }
39
40     public Branch getBranch(long id, boolean updateable, AuthenticatedUser user) throws RepositoryException {
41         if (!updateable)
42             return cache.getBranch(id);
43         return strategy.getBranch(id, user);
44     }
45
46     public Branch getBranchByName(String JavaDoc name, boolean updateable, AuthenticatedUser user) throws RepositoryException {
47         if (!updateable)
48             return cache.getBranchByName(name);
49         return strategy.getBranchByName(name, user);
50     }
51
52     public Branch getBranch(String JavaDoc branch, boolean updateable, AuthenticatedUser user) throws RepositoryException {
53         if (branch == null || branch.length() == 0)
54             throw new IllegalArgumentException JavaDoc("name: null or empty");
55
56         if (Character.isDigit(branch.charAt(0))) {
57             try {
58                 long id = Long.parseLong(branch);
59                 return getBranch(id, updateable, user);
60             } catch (NumberFormatException JavaDoc e) {
61                 throw new RepositoryException("Invalid branch name or ID: " + branch);
62             }
63         }
64         return getBranchByName(branch, updateable, user);
65     }
66
67     public Branches getAllBranches(boolean updateable, AuthenticatedUser user) throws RepositoryException {
68         if (!updateable)
69             return cache.getBranches();
70         return new BranchesImpl(strategy.getAllBranches(user));
71     }
72
73     public void deleteBranch(long id, AuthenticatedUser user) throws RepositoryException {
74         strategy.deleteBranch(id, user);
75     }
76
77     public Language createLanguage(String JavaDoc name, AuthenticatedUser user) {
78         return new LanguageImpl(strategy, name, user);
79     }
80
81     public Language getLanguage(long id, boolean updateable, AuthenticatedUser user) throws RepositoryException {
82         if (!updateable)
83             return cache.getLanguage(id);
84         return strategy.getLanguage(id, user);
85     }
86
87     public Language getLanguageByName(String JavaDoc name, boolean updateable, AuthenticatedUser user) throws RepositoryException {
88         if (!updateable)
89             return cache.getLanguageByName(name);
90         return strategy.getLanguageByName(name, user);
91     }
92
93     public Language getLanguage(String JavaDoc language, boolean updateable, AuthenticatedUser user) throws RepositoryException {
94         if (language == null || language.length() == 0)
95             throw new IllegalArgumentException JavaDoc("name: null or empty");
96
97         if (Character.isDigit(language.charAt(0))) {
98             try {
99                 long id = Long.parseLong(language);
100                 return getLanguage(id, updateable, user);
101             } catch (NumberFormatException JavaDoc e) {
102                 throw new RepositoryException("Invalid language name or ID: " + language);
103             }
104         }
105         return getLanguageByName(language, updateable, user);
106     }
107
108     public Languages getAllLanguages(boolean updateable, AuthenticatedUser user) throws RepositoryException {
109         if (!updateable)
110             return cache.getLanguages();
111         return new LanguagesImpl(strategy.getAllLanguages(user));
112     }
113
114     public void deleteLanguage(long id, AuthenticatedUser user) throws RepositoryException {
115         strategy.deleteLanguage(id, user);
116     }
117 }
118
Popular Tags