01: package org.drools.rule.builder.dialect.java;
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.List;
20:
21: import org.drools.commons.jci.stores.ResourceStore;
22: import org.drools.rule.PackageCompilationData;
23:
24: public class PackageStore implements ResourceStore {
25: private PackageCompilationData packageCompilationData;
26:
27: private List errors;
28:
29: public PackageStore() {
30: }
31:
32: public PackageStore(
33: final PackageCompilationData packageCompiationData,
34: final List errors) {
35: this .packageCompilationData = packageCompiationData;
36: this .errors = errors;
37: }
38:
39: public void setPackageCompilationData(
40: final PackageCompilationData packageCompiationData) {
41: this .packageCompilationData = packageCompiationData;
42: }
43:
44: public void write(final String resourceName, final byte[] clazzData) {
45: try {
46: this .packageCompilationData.write(resourceName, clazzData);
47: } catch (final Exception e) {
48: e.printStackTrace();
49: this .errors.add(new JavaDialectError(
50: "PackageStore was unable to write resourceName='"
51: + resourceName + "'"));
52: }
53: }
54:
55: public byte[] read(final String resourceName) {
56: byte[] clazz = null;
57: try {
58: clazz = this .packageCompilationData.read(resourceName);
59: } catch (final Exception e) {
60: this .errors.add(new JavaDialectError(
61: "PackageStore was unable to read resourceName='"
62: + resourceName + "'"));
63: }
64: return clazz;
65: }
66:
67: public void remove(final String resourceName) {
68: try {
69: this .packageCompilationData.remove(resourceName);
70: } catch (final Exception e) {
71: this .errors.add(new JavaDialectError(
72: "PackageStore was unable to remove resourceName='"
73: + resourceName + "'"));
74: }
75: }
76:
77: }
|