001: package org.drools.eclipse.flow.common.datatype.impl;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.HashMap;
020: import java.util.HashSet;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import org.drools.eclipse.flow.common.datatype.DataTypeRegistry;
025: import org.drools.ruleflow.common.datatype.DataTypeFactory;
026:
027: /**
028: * Default implementation of a datatype registry.
029: *
030: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
031: */
032: public class DataTypeRegistryImpl implements DataTypeRegistry {
033:
034: private Map dataTypes = new HashMap();
035:
036: public Set getDataTypes() {
037: return new HashSet(dataTypes.values());
038: }
039:
040: public void registerDataType(Class type,
041: DataTypeFactory dataTypeFactory, String name,
042: Class valueEditorClass, Class dataTypeEditorClass) {
043: if (dataTypeFactory == null) {
044: throw new NullPointerException(
045: "Data type factory may not be null");
046: }
047: if (name == null) {
048: throw new NullPointerException("Name may not be null");
049: }
050: if (valueEditorClass == null) {
051: throw new NullPointerException(
052: "valueEditorClass may not be null");
053: }
054: if (dataTypeEditorClass == null) {
055: throw new NullPointerException(
056: "dataTypeEditorClass may not be null");
057: }
058: dataTypes.put(type, new DataTypeInfo(type, dataTypeFactory,
059: name, valueEditorClass, dataTypeEditorClass));
060: }
061:
062: public IDataTypeInfo getDataTypeInfo(Class type) {
063: IDataTypeInfo dataTypeInfo = (IDataTypeInfo) dataTypes
064: .get(type);
065: if (dataTypeInfo == null) {
066: throw new IllegalArgumentException(
067: "Cannot find data type info with type " + type);
068: }
069: return dataTypeInfo;
070: }
071:
072: public class DataTypeInfo implements IDataTypeInfo {
073: private Class type;
074: private DataTypeFactory dataTypeFactory;
075: private String name;
076: private Class valueEditorClass;
077: private Class dataTypeEditorClass;
078:
079: private DataTypeInfo(Class type,
080: DataTypeFactory dataTypeFactory, String name,
081: Class valueEditorClass, Class dataTypeEditorClass) {
082: this .type = type;
083: this .dataTypeFactory = dataTypeFactory;
084: this .name = name;
085: this .valueEditorClass = valueEditorClass;
086: this .dataTypeEditorClass = dataTypeEditorClass;
087: }
088:
089: public Class getType() {
090: return type;
091: }
092:
093: public DataTypeFactory getDataTypeFactory() {
094: return dataTypeFactory;
095: }
096:
097: public String getName() {
098: return name;
099: }
100:
101: public Class getValueEditorClass() {
102: return valueEditorClass;
103: }
104:
105: public Class getDataTypeEditorClass() {
106: return dataTypeEditorClass;
107: }
108: }
109: }
|