|
|||||||||||||||||||
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 | |||||||||||||||
RegistryAssemblyImpl.java | 100% | 100% | 100% | 100% |
|
1 |
// Copyright 2004 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.impl;
|
|
16 |
|
|
17 |
import java.util.ArrayList;
|
|
18 |
import java.util.HashMap;
|
|
19 |
import java.util.List;
|
|
20 |
import java.util.Map;
|
|
21 |
|
|
22 |
import org.apache.commons.logging.Log;
|
|
23 |
import org.apache.commons.logging.LogFactory;
|
|
24 |
import org.apache.hivemind.ClassResolver;
|
|
25 |
import org.apache.hivemind.ErrorHandler;
|
|
26 |
import org.apache.hivemind.HiveMind;
|
|
27 |
import org.apache.hivemind.Resource;
|
|
28 |
import org.apache.hivemind.parse.DescriptorParser;
|
|
29 |
import org.apache.hivemind.parse.ModuleDescriptor;
|
|
30 |
import org.apache.hivemind.schema.Schema;
|
|
31 |
|
|
32 |
/**
|
|
33 |
* Implementation of {@link org.apache.hivemind.impl.RegistryAssembly}.
|
|
34 |
*
|
|
35 |
* @author Howard Lewis Ship
|
|
36 |
*/
|
|
37 |
public class RegistryAssemblyImpl implements RegistryAssembly |
|
38 |
{ |
|
39 |
private static final Log LOG = LogFactory.getLog(RegistryAssemblyImpl.class); |
|
40 |
|
|
41 |
private List _runnables = new ArrayList(); |
|
42 |
private Map _schemas = new HashMap(); |
|
43 |
private List _queuedModules = new ArrayList(); |
|
44 |
private ErrorHandler _errorHandler;
|
|
45 |
|
|
46 | 102 |
public RegistryAssemblyImpl(ErrorHandler errorHandler)
|
47 |
{ |
|
48 | 102 |
_errorHandler = errorHandler; |
49 |
} |
|
50 |
|
|
51 |
private static class QueuedModule |
|
52 |
{ |
|
53 |
private Resource _resource;
|
|
54 |
private ClassResolver _resolver;
|
|
55 |
|
|
56 | 1 |
QueuedModule(Resource resource, ClassResolver resolver) |
57 |
{ |
|
58 | 1 |
_resource = resource; |
59 | 1 |
_resolver = resolver; |
60 |
} |
|
61 |
|
|
62 | 1 |
ModuleDescriptor parse(DescriptorParser parser) |
63 |
{ |
|
64 | 1 |
return parser.parse(_resource, _resolver);
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 | 214 |
public void addSchema(String schemaId, Schema schema) |
69 |
{ |
|
70 | 214 |
Schema existing = getSchema(schemaId); |
71 |
|
|
72 | 214 |
if (existing != null) |
73 |
{ |
|
74 | 1 |
_errorHandler.error( |
75 |
LOG, |
|
76 |
ImplMessages.duplicateSchema(schemaId, existing), |
|
77 |
schema.getLocation(), |
|
78 |
null);
|
|
79 | 1 |
return;
|
80 |
} |
|
81 |
|
|
82 | 213 |
_schemas.put(schemaId, schema); |
83 |
} |
|
84 |
|
|
85 | 555 |
public Schema getSchema(String schemaId)
|
86 |
{ |
|
87 | 555 |
return (Schema) _schemas.get(schemaId);
|
88 |
} |
|
89 |
|
|
90 | 53 |
public void addPostProcessor(Runnable postProcessor) |
91 |
{ |
|
92 | 53 |
_runnables.add(postProcessor); |
93 |
} |
|
94 |
|
|
95 |
/**
|
|
96 |
* Invokes {@link Runnable#run()} on each Runnable
|
|
97 |
* object previously stored using
|
|
98 |
* {@link #addPostProcessor(Runnable)}.
|
|
99 |
*/
|
|
100 | 97 |
public void performPostProcessing() |
101 |
{ |
|
102 | 97 |
int count = _runnables.size();
|
103 |
|
|
104 | 97 |
for (int i = 0; i < count; i++) |
105 |
{ |
|
106 | 50 |
Runnable r = (Runnable) _runnables.get(i); |
107 |
|
|
108 | 50 |
r.run(); |
109 |
} |
|
110 |
} |
|
111 |
|
|
112 | 1 |
public void enqueueModuleParse(Resource resource, ClassResolver resolver) |
113 |
{ |
|
114 | 1 |
QueuedModule qm = new QueuedModule(resource, resolver);
|
115 | 1 |
_queuedModules.add(qm); |
116 |
} |
|
117 |
|
|
118 |
/**
|
|
119 |
* Returns true if there are yet more queued models to be parsed.
|
|
120 |
*
|
|
121 |
*/
|
|
122 | 156 |
public boolean moreQueuedModules() |
123 |
{ |
|
124 | 156 |
return !_queuedModules.isEmpty();
|
125 |
} |
|
126 |
|
|
127 |
/**
|
|
128 |
* Parses the next enqueued module descripotor and returns it.
|
|
129 |
*/
|
|
130 | 1 |
public ModuleDescriptor parseNextQueued(DescriptorParser parser)
|
131 |
{ |
|
132 | 1 |
QueuedModule qm = (QueuedModule) _queuedModules.remove(0); |
133 |
|
|
134 | 1 |
return qm.parse(parser);
|
135 |
} |
|
136 |
} |
|
137 |
|
|