01: package org.drools.brms.server.util;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.ArrayList;
20: import java.util.Iterator;
21: import java.util.List;
22: import java.util.jar.JarInputStream;
23:
24: import org.drools.brms.client.common.AssetFormats;
25: import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
26: import org.drools.brms.server.builder.BRMSPackageBuilder;
27: import org.drools.brms.server.rules.SuggestionCompletionLoader;
28: import org.drools.lang.dsl.DSLMappingFile;
29: import org.drools.repository.AssetItem;
30: import org.drools.repository.PackageItem;
31:
32: /**
33: * This decorates the suggestion completion loader with BRMS specific stuff.
34: *
35: * @author Michael Neale
36: */
37: public class BRMSSuggestionCompletionLoader extends
38: SuggestionCompletionLoader {
39:
40: public SuggestionCompletionEngine getSuggestionEngine(
41: PackageItem pkg) {
42: return super .getSuggestionEngine(pkg.getHeader(), getJars(pkg),
43: getDSLMappingFiles(pkg), getDataEnums(pkg));
44: }
45:
46: private List<String> getDataEnums(PackageItem pkg) {
47: Iterator it = pkg
48: .listAssetsByFormat(new String[] { AssetFormats.ENUMERATION });
49: List<String> list = new ArrayList<String>();
50: while (it.hasNext()) {
51: AssetItem item = (AssetItem) it.next();
52: list.add(item.getContent());
53: }
54: return list;
55: }
56:
57: private List<DSLMappingFile> getDSLMappingFiles(PackageItem pkg) {
58: return BRMSPackageBuilder.getDSLMappingFiles(pkg,
59: new BRMSPackageBuilder.DSLErrorEvent() {
60: public void recordError(AssetItem asset,
61: String message) {
62: errors.add(asset.getName() + " : " + message);
63: }
64: });
65: }
66:
67: private List<JarInputStream> getJars(PackageItem pkg) {
68: return BRMSPackageBuilder.getJars(pkg);
69: }
70:
71: }
|