
/*
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.jcs.yajcache.file;

import org.apache.jcs.yajcache.annotate.*;

/**
 * Cache File Content Type.  A cache file represents the file persistence
 * format of a cache item.
 * Currently the content of a cache item can be persisted into an array of
 * bytes via either Java Serialization, or the XMLEncoder.
 *
 * @author Hanson Char
 */
@CopyRightApache
public enum CacheFileContentType {
    JAVA_SERIALIZATION,
    XML_ENCODER;

    /** Returns a single byte representing the content type. */
    public byte toByte() {
        switch(this) {
            case JAVA_SERIALIZATION:
                return 0;
            case XML_ENCODER:
                return 1;
            default:
                throw new IllegalStateException("Should never happen");
        }
    }
    /** 
     * Returns the corresponding CacheFileContentType enum instance 
     * from the given byte value. 
     */
    @NonNullable 
    public static CacheFileContentType fromByte(byte b) {
        switch(b) {
            case 0:
                return JAVA_SERIALIZATION;
            case 1:
                return XML_ENCODER;
            default:
                throw new IllegalArgumentException("Unsupported b="+b);
        }
    }
}

@@ -653,16 +653,96 @@
 .file;%0A%0A
+import java.io.Serializable;%0Aimport org.apache.commons.lang.SerializationUtils;%0A
 import o
@@ -768,16 +768,23 @@
 che.
+lang.
 annotat
-e
+ion
 .*;%0A
@@ -1053,16 +1053,19 @@
 har%0A */%0A
+// 
 @CopyRig
@@ -1073,16 +1073,72 @@
 tApache%0A
+// http://www.netbeans.org/issues/show_bug.cgi?id=53704%0A
 public e
@@ -1490,51 +1490,27 @@
 new 
-IllegalStateException(%22Should never happen%22
+AssertionError(this
 );%0A 
@@ -1653,21 +1653,8 @@
     
-@NonNullable 
 %0A   
@@ -1668,16 +1668,29 @@
  static 
+@NonNullable 
 CacheFil
@@ -1873,32 +1873,32 @@
        default:%0A
-
                 
@@ -1969,10 +1969,753 @@
 %7D%0A    %7D%0A
+    public byte%5B%5D serialize(Object obj) %7B%0A        switch(this) %7B%0A            case JAVA_SERIALIZATION:%0A                return SerializationUtils.serialize((Serializable)obj);%0A            case XML_ENCODER:%0A                return org.apache.jcs.yajcache.util.BeanUtils.inst.toXmlByteArray(obj);%0A            default:%0A                throw new AssertionError(this);%0A        %7D%0A    %7D%0A    public Object deserialize(byte%5B%5D ba) %7B%0A        switch(this) %7B%0A            case JAVA_SERIALIZATION:%0A                return SerializationUtils.deserialize(ba);%0A            case XML_ENCODER:%0A                return org.apache.jcs.yajcache.util.BeanUtils.inst.fromXmlByteArray(ba);%0A            default:%0A                throw new AssertionError(this);%0A        %7D%0A    %7D%0A
 %7D%0A

add serialize/deserialize