001: /*--
002:
003: Copyright (C) 2002-2005 Adrian Price.
004: All rights reserved.
005:
006: Redistribution and use in source and binary forms, with or without
007: modification, are permitted provided that the following conditions
008: are met:
009:
010: 1. Redistributions of source code must retain the above copyright
011: notice, this list of conditions, and the following disclaimer.
012:
013: 2. Redistributions in binary form must reproduce the above copyright
014: notice, this list of conditions, and the disclaimer that follows
015: these conditions in the documentation and/or other materials
016: provided with the distribution.
017:
018: 3. The names "OBE" and "Open Business Engine" must not be used to
019: endorse or promote products derived from this software without prior
020: written permission. For written permission, please contact
021: adrianprice@sourceforge.net.
022:
023: 4. Products derived from this software may not be called "OBE" or
024: "Open Business Engine", nor may "OBE" or "Open Business Engine"
025: appear in their name, without prior written permission from
026: Adrian Price (adrianprice@users.sourceforge.net).
027:
028: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
029: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
030: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
031: DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
032: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
033: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
034: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
035: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
036: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
037: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
038: POSSIBILITY OF SUCH DAMAGE.
039:
040: For more information on OBE, please see
041: <http://obe.sourceforge.net/>.
042:
043: */
044:
045: package org.obe.xpdl.model.data;
046:
047: import org.obe.util.AbstractEnum;
048: import org.obe.xpdl.XPDLNames;
049:
050: import java.util.HashMap;
051: import java.util.List;
052: import java.util.Map;
053:
054: /**
055: * Data type representing the basic workflow data types.
056: *
057: * @author Adrian Price
058: */
059: public final class BasicType extends AbstractEnum implements Type {
060: private static final long serialVersionUID = -7894443551993705284L;
061:
062: public static final BasicType STRING = new BasicType(
063: XPDLNames.STRING_KIND, STRING_TYPE);
064: public static final BasicType FLOAT = new BasicType(
065: XPDLNames.FLOAT_KIND, FLOAT_TYPE);
066: public static final BasicType INTEGER = new BasicType(
067: XPDLNames.INTEGER_KIND, INTEGER_TYPE);
068: /**
069: * @deprecated Use {@link ExternalReference} or @{@link SchemaType}.
070: */
071: public static final BasicType REFERENCE = new BasicType(
072: XPDLNames.REFERENCE_KIND, REFERENCE_TYPE);
073: public static final BasicType DATETIME = new BasicType(
074: XPDLNames.DATETIME_KIND, DATETIME_TYPE);
075: public static final BasicType BOOLEAN = new BasicType(
076: XPDLNames.BOOLEAN_KIND, BOOLEAN_TYPE);
077: public static final BasicType PERFORMER = new BasicType(
078: XPDLNames.PERFORMER_KIND, PERFORMER_TYPE);
079:
080: private static final BasicType[] _values = { STRING, FLOAT,
081: INTEGER, REFERENCE, DATETIME, BOOLEAN, PERFORMER };
082: private static final Map _tagMap = new HashMap();
083: public static final List VALUES = clinit(_values, _tagMap);
084:
085: // syntax: boolean ok = _assignable[to][from];
086: private static final boolean[][] _assignable = {
087: // string, float, integer, reference, datetime, boolean, performer
088: { true, true, true, false, true, true, true }, // string
089: { true, true, true, false, false, false, false }, // float
090: { true, true, true, false, true, false, false }, // integer
091: { false, false, false, true, false, false, false }, // reference
092: { true, false, true, false, true, false, false }, // datetime
093: { true, false, false, false, false, true, false }, // boolean
094: { true, false, false, false, false, false, true } // performer
095: };
096:
097: public static BasicType valueOf(int type) {
098: return _values[type];
099: }
100:
101: public static BasicType valueOf(String tag) {
102: BasicType basicType = (BasicType) _tagMap.get(tag);
103: if (basicType == null && tag != null)
104: throw new IllegalArgumentException(tag);
105: return basicType;
106: }
107:
108: /**
109: * Construct a new BasicType.
110: *
111: * @param name
112: * @param ordinal The int value
113: */
114: private BasicType(String name, int ordinal) {
115: super (name, ordinal);
116: }
117:
118: public Type getImpliedType() {
119: return this ;
120: }
121:
122: public boolean isAssignableFrom(Type fromType) {
123: fromType = fromType.getImpliedType();
124: if (fromType instanceof ExternalReference) {
125: // See whether the external reference refers to something we can
126: // convert to this BasicType.
127: Class valueType = DataTypes.classForType(fromType);
128: fromType = DataTypes.dataTypeForClass(valueType).getType();
129: }
130: if (fromType instanceof BasicType) {
131: BasicType basicType = (BasicType) fromType;
132: return _assignable[ordinal][basicType.ordinal];
133: }
134: return false;
135: }
136:
137: public List family() {
138: return VALUES;
139: }
140: }
|