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.util.HashMap;
20: import java.util.Map;
21:
22: import org.drools.brms.client.common.AssetFormats;
23: import org.drools.brms.client.rpc.RuleAsset;
24: import org.drools.repository.AssetItem;
25: import org.drools.repository.PackageItem;
26:
27: import com.google.gwt.user.client.rpc.SerializableException;
28:
29: /**
30: * All content handlers must implement this, and be registered in content_types.properties
31: * @author Michael Neale
32: *
33: */
34: public abstract class ContentHandler {
35:
36: static Map handlers;
37:
38: static {
39: handlers = new HashMap() {
40: {
41: put(AssetFormats.BUSINESS_RULE, new BRLContentHandler());
42: put(AssetFormats.DSL_TEMPLATE_RULE,
43: new DSLRuleContentHandler());
44: put(AssetFormats.DRL, new DRLFileContentHandler());
45: put(AssetFormats.DSL, new DSLDefinitionContentHandler());
46: put(AssetFormats.FUNCTION, new FunctionContentHandler());
47: put(AssetFormats.MODEL, new ModelContentHandler());
48: put(AssetFormats.DECISION_SPREADSHEET_XLS,
49: new DecisionTableXLSHandler());
50: put(AssetFormats.RULE_FLOW_RF, new RuleFlowHandler());
51: put(AssetFormats.ENUMERATION,
52: new EnumerationContentHandler());
53: }
54: };
55: }
56:
57: /**
58: * When loading asset content.
59: * @param asset The target.
60: * @param item The source.
61: * @throws SerializableException
62: */
63: public abstract void retrieveAssetContent(RuleAsset asset,
64: PackageItem pkg, AssetItem item)
65: throws SerializableException;
66:
67: /**
68: * For storing the asset content back into the repo node (any changes).
69: * @param asset
70: * @param repoAsset
71: * @throws SerializableException
72: */
73: public abstract void storeAssetContent(RuleAsset asset,
74: AssetItem repoAsset) throws SerializableException;
75:
76: public static ContentHandler getHandler(String format) {
77: ContentHandler h = (ContentHandler) handlers.get(format);
78: if (h == null)
79: throw new IllegalArgumentException(
80: "Unable to handle the content type: " + format);
81: return h;
82: }
83:
84: /**
85: * @return true if the current content type is for a rule asset.
86: * If it is a rule asset, then it can be assembled into a package.
87: * If its not, then it is there, nominally to support compiling or
88: * validation/testing of the package (eg a model, or a dsl file).
89: */
90: public boolean isRuleAsset() {
91: return this instanceof IRuleAsset;
92: }
93:
94: }
|