001: /*
002: * Copyright 2006 Day Management AG, Switzerland. All rights reserved.
003: */
004: package javax.jcr.version;
005:
006: /**
007: * The possible actions specified by the <code>onParentVersion</code> attribute
008: * in a property definition within a node type definition.
009: * <p>
010: * This interface defines the following actions:
011: * <UL>
012: * <LI><code>COPY</code>
013: * <LI><code>VERSION</code>
014: * <LI><code>INITIALIZE</code>
015: * <LI><code>COMPUTE</code>
016: * <LI><code>IGNORE</code>
017: * <LI><code>ABORT</code>
018: * </UL>
019: * <p>
020: * Every item (node or property) in the repository has a status indicator that
021: * governs what happens to that item when its parent node is versioned. This
022: * status is defined by the <code>onParentVersion</code> attribute in
023: * the <code>PropertyDefinition</code> or <code>NodeDefinition</code> that applies to the
024: * item in question.
025: *
026: */
027: public final class OnParentVersionAction {
028:
029: /**
030: * The action constants.
031: */
032: public static final int COPY = 1;
033: public static final int VERSION = 2;
034: public static final int INITIALIZE = 3;
035: public static final int COMPUTE = 4;
036: public static final int IGNORE = 5;
037: public static final int ABORT = 6;
038:
039: /**
040: * The names of the defined on-version actions,
041: * as used in serialization.
042: */
043: public static final String ACTIONNAME_COPY = "COPY";
044: public static final String ACTIONNAME_VERSION = "VERSION";
045: public static final String ACTIONNAME_INITIALIZE = "INITIALIZE";
046: public static final String ACTIONNAME_COMPUTE = "COMPUTE";
047: public static final String ACTIONNAME_IGNORE = "IGNORE";
048: public static final String ACTIONNAME_ABORT = "ABORT";
049:
050: /**
051: * Returns the name of the specified <code>action</code>,
052: * as used in serialization.
053: * @param action the on-version action
054: * @return the name of the specified <code>action</code>
055: * @throws IllegalArgumentException if <code>action</code>
056: * is not a valid on-version action.
057: */
058: public static String nameFromValue(int action) {
059: switch (action) {
060: case COPY:
061: return ACTIONNAME_COPY;
062: case VERSION:
063: return ACTIONNAME_VERSION;
064: case INITIALIZE:
065: return ACTIONNAME_INITIALIZE;
066: case COMPUTE:
067: return ACTIONNAME_COMPUTE;
068: case IGNORE:
069: return ACTIONNAME_IGNORE;
070: case ABORT:
071: return ACTIONNAME_ABORT;
072: default:
073: throw new IllegalArgumentException(
074: "unknown on-version action: " + action);
075: }
076: }
077:
078: /**
079: * Returns the numeric constant value of the on-version action with the
080: * specified name.
081: * @param name the name of the on-version action
082: * @return the numeric constant value
083: * @throws IllegalArgumentException if <code>name</code>
084: * is not a valid on-version action name.
085: */
086: public static int valueFromName(String name) {
087: if (name.equals(ACTIONNAME_COPY)) {
088: return COPY;
089: } else if (name.equals(ACTIONNAME_VERSION)) {
090: return VERSION;
091: } else if (name.equals(ACTIONNAME_INITIALIZE)) {
092: return INITIALIZE;
093: } else if (name.equals(ACTIONNAME_COMPUTE)) {
094: return COMPUTE;
095: } else if (name.equals(ACTIONNAME_IGNORE)) {
096: return IGNORE;
097: } else if (name.equals(ACTIONNAME_ABORT)) {
098: return ABORT;
099: } else {
100: throw new IllegalArgumentException(
101: "unknown on-version action: " + name);
102: }
103: }
104:
105: /** private constructor to prevent instantiation */
106: private OnParentVersionAction() {
107: }
108: }
|