1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.objectledge.datatype;
29
30 import java.util.ArrayList;
31 import java.util.Hashtable;
32 import java.util.Iterator;
33 import java.util.List;
34 import java.util.Map;
35
36 import org.objectledge.datatype.xml.XMLSchemaDatatypeSetFactory;
37 import org.objectledge.xml.XMLGrammarCache;
38
39 /***
40 * The Datatype set manager component.
41 *
42 * @author <a href="mailto:dgajda@caltha.pl">Damian Gajda</a>
43 * @version $Id: DatatypeSetManager.java,v 1.5 2006/02/08 18:20:56 zwierzem Exp $
44 */
45 public class DatatypeSetManager
46 {
47 /*** the provided datatype sets. */
48 protected Map<String,DatatypeSet> datatypeSets = new Hashtable<String,DatatypeSet>();
49
50 /*** the datatype sets' factories. */
51 protected List<DatatypeSetFactory> factories = new ArrayList<DatatypeSetFactory>();
52
53 /***
54 * Creates an abstract datatype set manager.
55 *
56 * @param grammarCache XML grammar cache for retrieval of XML schema datatypes
57 */
58 public DatatypeSetManager(XMLGrammarCache grammarCache)
59 {
60
61 factories.add(new XMLSchemaDatatypeSetFactory(grammarCache));
62 }
63
64 /***
65 * Returns a named set of datatypes.
66 *
67 * @param name name of the datatype set
68 * @return the datatype set or null if the datatype set does not exist
69 * @throws DatatypeSetCreationException thrown when datatype set name is known but
70 * the set cannot be created.
71 */
72 public synchronized DatatypeSet getDatatypeSet(String name)
73 throws DatatypeSetCreationException
74 {
75 DatatypeSet set = (DatatypeSet) datatypeSets.get(name);
76 if(set == null)
77 {
78 for (Iterator iter = factories.iterator(); iter.hasNext();)
79 {
80 DatatypeSetFactory element = (DatatypeSetFactory) iter.next();
81 set = element.createDatatypeSet(name);
82 if(set != null)
83 {
84 break;
85 }
86 }
87 datatypeSets.put(name, set);
88 }
89 return set;
90 }
91
92 /***
93 * Set a parent - child relation between sets of datatypes. This relation is used to inherit
94 * datatypes between sets. Child datatype set inherits datatypes from parent one.
95 *
96 * @param child child datatype set
97 * @param parent parent datatype set
98 * @throws CircularDependencyException on dependency cycle creation
99 */
100 public synchronized void setParent(DatatypeSet child, DatatypeSet parent)
101 throws CircularDependencyException
102 {
103 DatatypeSet set = parent;
104 while(set != null && set != child)
105 {
106 set = ((AbstractDatatypeSet) set).getParent();
107 }
108 if(set == child)
109 {
110 throw new CircularDependencyException("datatype set '"+parent.getName()
111 +"' is a child of datatype set '"+child.getName()+"'");
112 }
113 ((AbstractDatatypeSet) child).setParent(parent);
114 }
115
116 /***
117 * Clears a parent - child relation on a child set of datatypes.
118 *
119 * @param child child datatype set
120 */
121 public void clearParent(DatatypeSet child)
122 {
123 ((AbstractDatatypeSet) child).setParent(null);
124 }
125
126
127
128
129
130
131 }