KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > repository > commonimpl > schema > CommonRepositorySchema


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.schema;
17
18 import org.outerj.daisy.repository.schema.*;
19 import org.outerj.daisy.repository.ValueType;
20 import org.outerj.daisy.repository.commonimpl.AuthenticatedUser;
21 import org.outerj.daisy.repository.commonimpl.CommonRepository;
22 import org.outerj.daisy.repository.RepositoryException;
23 import org.outerj.daisy.repository.LinkExtractorInfos;
24
25 import java.util.List JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Iterator JavaDoc;
28
29 public class CommonRepositorySchema {
30     private CommonRepository repository;
31     private SchemaStrategy schemaStrategy;
32     private List JavaDoc changeListeners = new ArrayList JavaDoc();
33     private RepositorySchemaCache cache;
34
35     public CommonRepositorySchema(SchemaStrategy schemaStrategy, CommonRepository repository, AuthenticatedUser systemUser) {
36         this.schemaStrategy = schemaStrategy;
37         this.cache = new RepositorySchemaCache(schemaStrategy, systemUser);
38         this.repository = repository;
39         addListener(cache);
40     }
41
42     public RepositorySchemaListener getCacheListener() {
43         return cache;
44     }
45
46     public RepositorySchemaCache getCache() {
47         return cache;
48     }
49
50     public DocumentType createDocumentType(String JavaDoc name, AuthenticatedUser user) {
51         return new DocumentTypeImpl(name, schemaStrategy, this, user);
52     }
53
54     public void deleteDocumentType(long documentTypeId, AuthenticatedUser user) throws RepositoryException {
55         schemaStrategy.deleteDocumentType(documentTypeId, user);
56     }
57
58     public FieldType createFieldType(String JavaDoc name, ValueType valueType, boolean multiValue, AuthenticatedUser user) {
59         return new FieldTypeImpl(name, valueType, multiValue, schemaStrategy, repository, user);
60     }
61
62     public void deleteFieldType(long fieldTypeId, AuthenticatedUser user) throws RepositoryException {
63         schemaStrategy.deleteFieldType(fieldTypeId, user);
64     }
65
66     public PartType createPartType(String JavaDoc name, String JavaDoc mimeTypes, AuthenticatedUser user) {
67         return new PartTypeImpl(name, mimeTypes, schemaStrategy, user);
68     }
69
70     public void deletePartType(long partTypeId, AuthenticatedUser user) throws RepositoryException {
71         schemaStrategy.deletePartType(partTypeId, user);
72     }
73
74     public DocumentTypes getAllDocumentTypes(boolean updateable, AuthenticatedUser user) throws RepositoryException {
75         if (updateable)
76             return new DocumentTypesImpl((DocumentTypeImpl[])schemaStrategy.getAllDocumentTypes(user).toArray(new DocumentTypeImpl[0]));
77         else
78             return cache.getAllDocumentTypes();
79     }
80
81     public FieldTypes getAllFieldTypes(boolean updateable, AuthenticatedUser user) throws RepositoryException {
82         if (updateable)
83             return new FieldTypesImpl((FieldTypeImpl[])schemaStrategy.getAllFieldTypes(user).toArray(new FieldTypeImpl[0]));
84         else
85             return cache.getAllFieldTypes();
86     }
87
88     public PartTypes getAllPartTypes(boolean updateable, AuthenticatedUser user) throws RepositoryException {
89         if (updateable)
90             return new PartTypesImpl((PartTypeImpl[])schemaStrategy.getAllPartTypes(user).toArray(new PartTypeImpl[0]));
91         else
92             return cache.getAllPartTypes();
93     }
94
95     public PartType getPartTypeById(long id, boolean updateable, AuthenticatedUser user) throws RepositoryException {
96         if (updateable)
97             return schemaStrategy.getPartTypeById(id, user);
98         else
99             return cache.getPartTypeById(id);
100     }
101
102     public PartType getPartTypeByName(String JavaDoc name, boolean updateable, AuthenticatedUser user) throws RepositoryException {
103         if (updateable)
104             return schemaStrategy.getPartTypeByName(name, user);
105         else
106             return cache.getPartTypeByName(name);
107     }
108
109     public FieldType getFieldTypeById(long id, boolean updateable, AuthenticatedUser user) throws RepositoryException {
110         if (updateable)
111             return schemaStrategy.getFieldTypeById(id, user);
112         else
113             return cache.getFieldTypeById(id);
114     }
115
116     public FieldType getFieldTypeByName(String JavaDoc name, boolean updateable, AuthenticatedUser user) throws RepositoryException {
117         if (updateable)
118             return schemaStrategy.getFieldTypeByName(name, user);
119         else
120             return cache.getFieldTypeByName(name);
121     }
122
123     public DocumentType getDocumentTypeById(long id, boolean updateable, AuthenticatedUser user) throws RepositoryException {
124         if (updateable)
125             return schemaStrategy.getDocumentTypeById(id, user);
126         else
127             return cache.getDocumentTypeById(id);
128     }
129
130     public DocumentType getDocumentTypeByName(String JavaDoc name, boolean updateable, AuthenticatedUser user) throws RepositoryException {
131         if (updateable)
132             return schemaStrategy.getDocumentTypeByName(name, user);
133         else
134             return cache.getDocumentTypeByName(name);
135     }
136
137     public LinkExtractorInfos getLinkExtractors(AuthenticatedUser user) throws RepositoryException {
138         return schemaStrategy.getLinkExtractors(user);
139     }
140
141     public void removeListener(RepositorySchemaListener listener) {
142         changeListeners.remove(listener);
143     }
144
145     public void addListener(RepositorySchemaListener listener) {
146         changeListeners.add(listener);
147     }
148
149     public void fireChangeEvent(RepositorySchemaEventType type, long id, long updateCount) {
150         Iterator JavaDoc listenerIt = changeListeners.iterator();
151         while (listenerIt.hasNext()) {
152             RepositorySchemaListener listener = (RepositorySchemaListener)listenerIt.next();
153             listener.modelChange(type, id, updateCount);
154         }
155     }
156
157     protected SchemaStrategy getSchemaStrategy() {
158         return schemaStrategy;
159     }
160 }
161
Popular Tags