/*******************************************************************************
 * Copyright (c) 2010 Nicolas Roduit.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Nicolas Roduit - initial API and implementation
 ******************************************************************************/
package org.weasis.imageio.codec.internal;

import javax.imageio.ImageIO;

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.weasis.core.api.image.util.JAIUtil;

import com.sun.media.imageioimpl.common.ImageioUtil;
import com.sun.media.imageioimpl.plugins.bmp.BMPImageReaderSpi;
import com.sun.media.imageioimpl.plugins.bmp.BMPImageWriterSpi;
import com.sun.media.imageioimpl.plugins.gif.GIFImageWriterSpi;
import com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageReaderSpi;
import com.sun.media.imageioimpl.plugins.jpeg.CLibJPEGImageWriterSpi;
import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderCodecLibSpi;
import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReaderSpi;
import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterCodecLibSpi;
import com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageWriterSpi;
import com.sun.media.imageioimpl.plugins.png.CLibPNGImageReaderSpi;
import com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriterSpi;
import com.sun.media.imageioimpl.plugins.pnm.PNMImageWriterSpi;
import com.sun.media.imageioimpl.plugins.raw.RawImageReaderSpi;
import com.sun.media.imageioimpl.plugins.raw.RawImageWriterSpi;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageReaderSpi;
import com.sun.media.imageioimpl.plugins.tiff.TIFFImageWriterSpi;
import com.sun.media.imageioimpl.plugins.wbmp.WBMPImageReaderSpi;
import com.sun.media.imageioimpl.plugins.wbmp.WBMPImageWriterSpi;
import com.sun.media.imageioimpl.stream.ChannelImageInputStreamSpi;
import com.sun.media.imageioimpl.stream.ChannelImageOutputStreamSpi;
import com.sun.media.jai.imageioimpl.ImageReadWriteSpi;

public class Activator implements BundleActivator {

    @Override
    public void start(final BundleContext bundleContext) throws Exception {
        // Do not use cache. Images must be download locally before reading them.
        ImageIO.setUseCache(false);

        // SPI Issue Resolution
        // Register imageio SPI with the classloader of this bundle
        // and unregister imageio SPI if imageio.jar is also in the jre/lib/ext folder

        Class[] jaiCodecs = { ChannelImageInputStreamSpi.class, ChannelImageOutputStreamSpi.class,
            CLibJPEGImageReaderSpi.class, CLibPNGImageReaderSpi.class, J2KImageReaderSpi.class,
            J2KImageReaderCodecLibSpi.class, WBMPImageReaderSpi.class, BMPImageReaderSpi.class, RawImageReaderSpi.class,
            TIFFImageReaderSpi.class, CLibJPEGImageWriterSpi.class, CLibPNGImageWriterSpi.class,
            J2KImageWriterSpi.class, J2KImageWriterCodecLibSpi.class, WBMPImageWriterSpi.class, BMPImageWriterSpi.class,
            GIFImageWriterSpi.class, PNMImageWriterSpi.class, RawImageWriterSpi.class, TIFFImageWriterSpi.class };

        for (Class c : jaiCodecs) {
            ImageioUtil.registerServiceProvider(c);
        }
        // TODO Should be in properties?
        // Unregister sun native jpeg codec
        // ImageioUtil.unRegisterServiceProvider(registry, CLibJPEGImageReaderSpi.class);

        // Register the ImageRead and ImageWrite operation for JAI
        new ImageReadWriteSpi().updateRegistry(JAIUtil.getOperationRegistry());
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {

        Class[] jaiCodecs = { ChannelImageInputStreamSpi.class, ChannelImageOutputStreamSpi.class,
            CLibJPEGImageReaderSpi.class, CLibPNGImageReaderSpi.class, J2KImageReaderSpi.class,
            J2KImageReaderCodecLibSpi.class, WBMPImageReaderSpi.class, BMPImageReaderSpi.class, RawImageReaderSpi.class,
            TIFFImageReaderSpi.class, CLibJPEGImageWriterSpi.class, CLibPNGImageWriterSpi.class,
            J2KImageWriterSpi.class, J2KImageWriterCodecLibSpi.class, WBMPImageWriterSpi.class, BMPImageWriterSpi.class,
            GIFImageWriterSpi.class, PNMImageWriterSpi.class, RawImageWriterSpi.class, TIFFImageWriterSpi.class };

        for (Class c : jaiCodecs) {
            ImageioUtil.unRegisterServiceProvider(c);
        }

    }

}

@@ -1526,32 +1526,96 @@
 ImageWriterSpi;%0A
+import com.sun.media.imageioimpl.plugins.pnm.PNMImageReaderSpi;%0A
 import com.sun.m
@@ -1654,32 +1654,32 @@
 ImageWriterSpi;%0A
-
 import com.sun.m
@@ -2981,35 +2981,35 @@
 eaderSpi.class, 
-Raw
+PNM
 ImageReaderSpi.c
@@ -3017,32 +3017,57 @@
 ass,%0A           
+ RawImageReaderSpi.class,
  TIFFImageReader
@@ -3098,32 +3098,44 @@
 WriterSpi.class,
+%0A           
  CLibPNGImageWri
@@ -3143,36 +3143,24 @@
 erSpi.class,
-%0A           
  J2KImageWri
@@ -3197,32 +3197,44 @@
 decLibSpi.class,
+%0A           
  WBMPImageWriter
@@ -3264,36 +3264,24 @@
 erSpi.class,
-%0A           
  GIFImageWri
@@ -3310,32 +3310,44 @@
 WriterSpi.class,
+%0A           
  RawImageWriterS
@@ -4184,27 +4184,27 @@
 rSpi.class, 
-Raw
+PNM
 ImageReaderS
@@ -4224,16 +4224,41 @@
         
+ RawImageReaderSpi.class,
  TIFFIma
@@ -4297,32 +4297,44 @@
 WriterSpi.class,
+%0A           
  CLibPNGImageWri
@@ -4342,36 +4342,24 @@
 erSpi.class,
-%0A           
  J2KImageWri
@@ -4396,32 +4396,44 @@
 decLibSpi.class,
+%0A           
  WBMPImageWriter
@@ -4467,28 +4467,16 @@
 i.class,
-%0A           
  GIFImag
@@ -4517,16 +4517,28 @@
 i.class,
+%0A           
  RawImag

Add missing PNMImageReader