01: package org.drools.brms.server.contenthandler;
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.io.IOException;
20: import java.io.StringReader;
21:
22: import org.drools.brms.client.modeldriven.brl.RuleModel;
23: import org.drools.brms.client.rpc.RuleAsset;
24: import org.drools.brms.server.builder.BRMSPackageBuilder;
25: import org.drools.brms.server.builder.ContentPackageAssembler;
26: import org.drools.brms.server.util.BRDRLPersistence;
27: import org.drools.brms.server.util.BRXMLPersistence;
28: import org.drools.compiler.DroolsParserException;
29: import org.drools.repository.AssetItem;
30: import org.drools.repository.PackageItem;
31:
32: import com.google.gwt.user.client.rpc.SerializableException;
33:
34: public class BRLContentHandler extends ContentHandler implements
35: IRuleAsset {
36:
37: public void retrieveAssetContent(RuleAsset asset, PackageItem pkg,
38: AssetItem item) throws SerializableException {
39: RuleModel model = BRXMLPersistence.getInstance().unmarshal(
40: item.getContent());
41:
42: asset.content = model;
43:
44: }
45:
46: public void storeAssetContent(RuleAsset asset, AssetItem repoAsset)
47: throws SerializableException {
48: RuleModel data = (RuleModel) asset.content;
49: if (data.name == null) {
50: data.name = repoAsset.getName();
51: }
52: repoAsset.updateContent(BRXMLPersistence.getInstance().marshal(
53: data));
54: }
55:
56: public void compile(BRMSPackageBuilder builder, AssetItem asset,
57: ContentPackageAssembler.ErrorLogger logger)
58: throws DroolsParserException, IOException {
59: builder.addPackageFromDrl(new StringReader(getSourceDRL(asset,
60: builder)));
61: }
62:
63: public void assembleDRL(BRMSPackageBuilder builder,
64: AssetItem asset, StringBuffer buf) {
65: String drl = getSourceDRL(asset, builder);
66: buf.append(drl);
67: }
68:
69: private String getSourceDRL(AssetItem asset,
70: BRMSPackageBuilder builder) {
71: RuleModel model = BRXMLPersistence.getInstance().unmarshal(
72: asset.getContent());
73: model.name = asset.getName();
74: String drl = BRDRLPersistence.getInstance().marshal(model);
75: if (builder.hasDSL() && model.hasDSLSentences()) {
76: drl = builder.getDSLExpander().expand(drl);
77: }
78: return drl;
79: }
80: }
|