|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
SchemaImpl.java | 86.4% | 91.2% | 100% | 91% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.hivemind.schema.impl;
|
|
16 |
|
|
17 |
import java.util.ArrayList;
|
|
18 |
import java.util.Collections;
|
|
19 |
import java.util.Iterator;
|
|
20 |
import java.util.List;
|
|
21 |
|
|
22 |
import org.apache.hivemind.ApplicationRuntimeException;
|
|
23 |
import org.apache.hivemind.internal.Visibility;
|
|
24 |
import org.apache.hivemind.parse.BaseAnnotationHolder;
|
|
25 |
import org.apache.hivemind.schema.AttributeModel;
|
|
26 |
import org.apache.hivemind.schema.ElementModel;
|
|
27 |
import org.apache.hivemind.schema.Schema;
|
|
28 |
|
|
29 |
/**
|
|
30 |
* Implementation of {@link org.apache.hivemind.schema.Schema}.
|
|
31 |
*
|
|
32 |
* @author Howard Lewis Ship
|
|
33 |
*/
|
|
34 |
public class SchemaImpl extends BaseAnnotationHolder implements Schema |
|
35 |
{ |
|
36 |
private List _elementModels;
|
|
37 |
|
|
38 |
private List _shareableElementModels;
|
|
39 |
|
|
40 |
/** @since 1.1 */
|
|
41 |
private Visibility _visibility = Visibility.PUBLIC;
|
|
42 |
|
|
43 |
/** @since 1.1 */
|
|
44 |
private String _moduleId;
|
|
45 |
|
|
46 |
/** @since 1.1 */
|
|
47 |
private String _id;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* @since 1.1
|
|
51 |
*/
|
|
52 | 9 |
public String getModuleId()
|
53 |
{ |
|
54 | 9 |
return _moduleId;
|
55 |
} |
|
56 |
|
|
57 |
/**
|
|
58 |
* @since 1.1
|
|
59 |
*/
|
|
60 | 602 |
public String getId()
|
61 |
{ |
|
62 | 602 |
return _id;
|
63 |
} |
|
64 |
|
|
65 |
/**
|
|
66 |
* @since 1.1
|
|
67 |
*/
|
|
68 | 30 |
public Visibility getVisibility()
|
69 |
{ |
|
70 | 30 |
return _visibility;
|
71 |
} |
|
72 |
|
|
73 |
/** @since 1.1 */
|
|
74 | 355 |
public boolean visibleToModule(String moduleId) |
75 |
{ |
|
76 | 355 |
if (_visibility == Visibility.PUBLIC)
|
77 | 355 |
return true; |
78 |
|
|
79 | 0 |
return _moduleId.equals(moduleId);
|
80 |
} |
|
81 |
|
|
82 | 3375 |
public void addElementModel(ElementModel model) |
83 |
{ |
|
84 | 3375 |
if (_elementModels == null) |
85 | 1159 |
_elementModels = new ArrayList();
|
86 |
|
|
87 | 3375 |
_elementModels.add(model); |
88 | 3375 |
_shareableElementModels = null;
|
89 |
} |
|
90 |
|
|
91 | 1356 |
public List getElementModel()
|
92 |
{ |
|
93 | 1356 |
if (_shareableElementModels == null) |
94 | 802 |
_shareableElementModels = _elementModels == null ? Collections.EMPTY_LIST : Collections
|
95 |
.unmodifiableList(_elementModels); |
|
96 |
|
|
97 | 1356 |
return _shareableElementModels;
|
98 |
} |
|
99 |
|
|
100 | 1719 |
public boolean canInstancesBeKeyed() |
101 |
{ |
|
102 | 1719 |
boolean emptyModel = _elementModels == null || _elementModels.isEmpty(); |
103 |
|
|
104 | 1719 |
if (emptyModel)
|
105 | 0 |
return false; |
106 |
|
|
107 | 1719 |
for (Iterator i = _elementModels.iterator(); i.hasNext();)
|
108 |
{ |
|
109 | 1719 |
ElementModel model = (ElementModel) i.next(); |
110 |
|
|
111 | 1719 |
if (model.getKeyAttribute() == null) |
112 | 1509 |
return false; |
113 |
} |
|
114 |
|
|
115 | 210 |
return true; |
116 |
} |
|
117 |
|
|
118 |
/**
|
|
119 |
* Called by the {@link org.apache.hivemind.parse.DescriptorParser}to make sure that key
|
|
120 |
* attributes specified by the top-level elements actually are defined.
|
|
121 |
*/
|
|
122 | 1033 |
public void validateKeyAttributes() |
123 |
{ |
|
124 | 1033 |
if (_elementModels == null) |
125 | 0 |
return;
|
126 |
|
|
127 | 1033 |
for (Iterator i = _elementModels.iterator(); i.hasNext();)
|
128 |
{ |
|
129 | 1153 |
ElementModel em = (ElementModel) i.next(); |
130 |
|
|
131 | 1153 |
String key = em.getKeyAttribute(); |
132 |
|
|
133 | 1153 |
if (key == null) |
134 | 1046 |
continue;
|
135 |
|
|
136 | 107 |
AttributeModel keyAm = em.getAttributeModel(key); |
137 |
|
|
138 | 107 |
if (keyAm == null) |
139 | 1 |
throw new ApplicationRuntimeException("Key attribute \'" + key + "\' of element \'" |
140 |
+ em.getElementName() + "\' never declared.", em.getLocation(), null); |
|
141 |
} |
|
142 |
} |
|
143 |
|
|
144 |
/**
|
|
145 |
* @since 1.1
|
|
146 |
*/
|
|
147 | 1 |
public void setVisibility(Visibility visibility) |
148 |
{ |
|
149 | 1 |
_visibility = visibility; |
150 |
} |
|
151 |
|
|
152 |
/**
|
|
153 |
* @since 1.1
|
|
154 |
*/
|
|
155 | 290 |
public void setModuleId(String moduleId) |
156 |
{ |
|
157 | 290 |
_moduleId = moduleId; |
158 |
} |
|
159 |
|
|
160 |
/**
|
|
161 |
* @since 1.1
|
|
162 |
*/
|
|
163 | 290 |
public void setId(String id) |
164 |
{ |
|
165 | 290 |
_id = id; |
166 |
} |
|
167 |
|
|
168 |
} |
|