01: package org.drools.brms.server.contenthandler;
02:
03: /*
04: * Copyright 2007 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:
23: import org.drools.brms.client.rpc.BuilderResult;
24: import org.drools.brms.server.util.DataEnumLoader;
25: import org.drools.repository.AssetItem;
26:
27: public class EnumerationContentHandler extends PlainTextContentHandler
28: implements IValidating {
29:
30: public BuilderResult[] validateAsset(AssetItem asset) {
31:
32: String content = asset.getContent();
33: DataEnumLoader loader = new DataEnumLoader(content);
34: if (!loader.hasErrors()) {
35: return new BuilderResult[0];
36: } else {
37: List<BuilderResult> errors = new ArrayList<BuilderResult>();
38: List errs = loader.getErrors();
39:
40: for (Iterator iter = errs.iterator(); iter.hasNext();) {
41:
42: BuilderResult result = new BuilderResult();
43: result.assetName = asset.getName();
44: result.assetFormat = asset.getFormat();
45: result.uuid = asset.getUUID();
46: result.message = (String) iter.next();
47: errors.add(result);
48: }
49:
50: return errors.toArray(new BuilderResult[errors.size()]);
51: }
52: }
53:
54: }
|