lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r417265 [2/6] - in /lucene/java/trunk/contrib/gdata-server: ./ lib/ src/java/ src/java/org/apache/lucene/gdata/server/ src/java/org/apache/lucene/gdata/server/registry/ src/java/org/apache/lucene/gdata/servlet/ src/java/org/apache/lucene/gd...
Date Mon, 26 Jun 2006 18:14:55 GMT
Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataService.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataService.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataService.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/GDataService.java Mon Jun 26 11:14:53 2006
@@ -1,275 +1,398 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.server;
+
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.data.ServerBaseEntry;
+import org.apache.lucene.gdata.data.ServerBaseFeed;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.storage.ResourceNotFoundException;
+import org.apache.lucene.gdata.storage.Storage;
+import org.apache.lucene.gdata.storage.StorageController;
+import org.apache.lucene.gdata.storage.StorageException;
+
+import com.google.gdata.data.BaseEntry;
+import com.google.gdata.data.BaseFeed;
+import com.google.gdata.data.DateTime;
+import com.google.gdata.data.Generator;
+import com.google.gdata.data.Link;
+import com.google.gdata.util.ParseException;
+
+/**
+ * default implementation of the {@link org.apache.lucene.gdata.server.Service}
+ * interface.
  * 
- * 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 
+ * @author Simon Willnauer
  * 
- *     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.lucene.gdata.server; 
- 
-import java.io.IOException; 
-import java.util.List; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
-import org.apache.lucene.gdata.server.registry.GDataServerRegistry; 
-import org.apache.lucene.gdata.storage.Storage; 
-import org.apache.lucene.gdata.storage.StorageException; 
-import org.apache.lucene.gdata.storage.StorageFactory; 
- 
-import com.google.gdata.data.BaseEntry; 
-import com.google.gdata.data.BaseFeed; 
-import com.google.gdata.data.DateTime; 
-import com.google.gdata.data.Generator; 
-import com.google.gdata.data.Link; 
-import com.google.gdata.util.ParseException; 
- 
-/** 
- * @author Simon Willnauer 
- *  
- */ 
-public class GDataService extends Service { 
-    private static final Log LOGGER = LogFactory.getLog(GDataService.class); 
- 
-    private Storage storage; 
- 
-    private GDataServerRegistry registry = GDataServerRegistry.getRegistry(); 
- 
-    private static final Generator generator; 
- 
-    private static final String generatorName = "Lucene GData-Server"; 
- 
-    private static final String generatorURI = "http://lucene.apache.org"; 
-    static { 
-        generator = new Generator(); 
-        generator.setName(generatorName); 
-        generator.setUri(generatorURI); 
-        generator.setVersion("0.1"); 
-    } 
- 
-    protected GDataService() throws ServiceException { 
-        try { 
-            this.storage = StorageFactory.getStorage(); 
-             
-        } catch (StorageException e) { 
-            LOGGER 
-                    .fatal( 
-                            "Can't get Storage Instance -- can't serve any requests", 
-                            e); 
-            ServiceException ex = new ServiceException( 
-                    "Can't get Storage instance" + e.getMessage(), e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.gdata.server.Service#createEntry(org.apache.lucene.gdata.server.GDataRequest, 
-     *      org.apache.lucene.gdata.server.GDataResponse) 
-     */ 
-    @Override 
-    public BaseEntry createEntry(GDataRequest request, GDataResponse response) 
-            throws ServiceException { 
- 
-        checkFeedIsRegisterd(request); 
-        if (LOGGER.isInfoEnabled()) 
-            LOGGER.info("create Entry for feedId: " + request.getFeedId()); 
-        BaseEntry entry = buildEntry(request); 
-        setUpdateTime(entry); 
-        try { 
- 
-            this.storage.storeEntry(entry, request.getFeedId()); 
-        } catch (Exception e) { 
-            ServiceException ex = new ServiceException("Could not store entry", 
-                    e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-        return entry; 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.gdata.server.Service#deleteEntry(org.apache.lucene.gdata.server.GDataRequest, 
-     *      org.apache.lucene.gdata.server.GDataResponse) 
-     */ 
-    @Override 
-    public BaseEntry deleteEntry(GDataRequest request, GDataResponse response) 
-            throws ServiceException { 
-        checkFeedIsRegisterd(request); 
-        String entryid = request.getEntryId(); 
-        String feedid = request.getFeedId(); 
-        try { 
-            this.storage.deleteEntry(entryid, feedid); 
-        } catch (Exception e) { 
-            ServiceException ex = new ServiceException( 
-                    "Could not delete entry", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-        return null; 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.gdata.server.Service#updateEntry(org.apache.lucene.gdata.server.GDataRequest, 
-     *      org.apache.lucene.gdata.server.GDataResponse) 
-     */ 
-    @Override 
-    public BaseEntry updateEntry(GDataRequest request, GDataResponse response) 
-            throws ServiceException { 
-        checkFeedIsRegisterd(request); 
- 
-        BaseEntry entry = buildEntry(request); 
-        String feedid = request.getFeedId(); 
-        if (LOGGER.isInfoEnabled()) 
-            LOGGER.info("update Entry" + entry.getId() + " for feedId: " 
-                    + feedid); 
-        setUpdateTime(entry); 
-        try { 
-            this.storage.updateEntry(entry, feedid); 
-        } catch (StorageException e) { 
-            ServiceException ex = new ServiceException( 
-                    "Could not update entry", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-        return entry; 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.gdata.server.Service#getFeed(org.apache.lucene.gdata.server.GDataRequest, 
-     *      org.apache.lucene.gdata.server.GDataResponse) 
-     */ 
-    @SuppressWarnings("unchecked") 
-    @Override 
-    public BaseFeed getFeed(GDataRequest request, GDataResponse response) 
-            throws ServiceException { 
-        checkFeedIsRegisterd(request); 
- 
-        try { 
-            // TODO remove when storing feeds is implemented just for 
-            // development 
-            BaseFeed feed = this.storage.getFeed(request.getFeedId(), request 
-                    .getStartIndex(), request.getItemsPerPage()); 
-            buildDynamicFeedElements(request, feed); 
-            List<BaseEntry> list = feed.getEntries(); 
-            addContextPath(list, request.getContextPath()); 
-            return feed; 
-        } catch (StorageException e) { 
-            ServiceException ex = new ServiceException("Could not get feed", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
- 
-    } 
- 
-    /* 
-     * build the dynamic elements like self link and next link 
-     */ 
-    private void buildDynamicFeedElements(final GDataRequest request, 
-            final BaseFeed feed) { 
-        feed.setGenerator(generator); 
-        feed.setItemsPerPage(request.getItemsPerPage()); 
-        feed.getLinks().add( 
-                buildLink(Link.Rel.SELF, Link.Type.ATOM, request.getSelfId())); 
-        // TODO add next link 
-    } 
- 
-    private Link buildLink(String rel, String type, String href) { 
-        Link retVal = new Link(); 
-        retVal.setHref(href); 
-        retVal.setRel(rel); 
-        retVal.setType(type); 
-        return retVal; 
-    } 
- 
-    /* 
-     * every entry has an ID which has to have a prefix. The prefix is the 
-     * context path of the requested feed. This will be used to request the 
-     * entry directly 
-     */ 
-    private void addContextPath(List<BaseEntry> list, final String contextPath) { 
-        for (BaseEntry entry : list) { 
-            addcontextPath(entry, contextPath); 
-        } 
-    } 
- 
-    @SuppressWarnings("unchecked") 
-    private BaseEntry addcontextPath(final BaseEntry entry, 
-            final String contextPath) { 
-        String id = contextPath + entry.getId(); 
-        entry.setId(id); 
-        Link self = new Link(); 
-        self.setRel("self"); 
-        self.setHref(id); 
-        self.setType("application/atom+xml"); 
-        entry.getLinks().add(self); 
-        return entry; 
-    } 
- 
-    private BaseEntry buildEntry(final GDataRequest request) 
-            throws ServiceException { 
-        try { 
-            return GDataEntityBuilder.buildEntry(request); 
- 
-        } catch (ParseException e) { 
-            ServiceException ex = new ServiceException( 
-                    "Could not parse entry from incoming request", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } catch (IOException e) { 
-            ServiceException ex = new ServiceException( 
-                    "Could not read or open input stream", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-    } 
- 
-    /* 
-     * checks whether the reqeuested feed is registered 
-     */ 
-    private void checkFeedIsRegisterd(final GDataRequest request) 
-            throws FeedNotFoundException { 
-        if (!this.registry.isFeedRegistered(request.getFeedId())) 
-            throw new FeedNotFoundException( 
-                    "Feed could not be found - is not registed - Feed ID:" 
-                            + request.getFeedId()); 
-        this.storage.setExtensionProfile(request.getExtensionProfile()); 
-    } 
- 
-    private BaseEntry setUpdateTime(final BaseEntry entry) { 
-        entry.setUpdated(DateTime.now()); 
-        return entry; 
-    } 
- 
-    /** 
-     * @see org.apache.lucene.gdata.server.Service#getSingleEntry(org.apache.lucene.gdata.server.GDataRequest, 
-     *      org.apache.lucene.gdata.server.GDataResponse) 
-     */ 
-    @Override 
-    public BaseEntry getSingleEntry(GDataRequest request, GDataResponse response) 
-            throws ServiceException { 
-        checkFeedIsRegisterd(request); 
- 
-        try { 
-            BaseEntry entry = this.storage.getEntry(request.getEntryId(), 
-                    request.getFeedId()); 
-            if(entry == null) 
-                return null; 
-            addcontextPath(entry, request.getContextPath()); 
-            return entry; 
-        } catch (StorageException e) { 
-            ServiceException ex = new ServiceException("Could not get feed", e); 
-            ex.setStackTrace(e.getStackTrace()); 
-            throw ex; 
-        } 
-    } 
- 
-} 
+ */
+public class GDataService implements Service {
+    private static final Log LOGGER = LogFactory.getLog(GDataService.class);
+
+    protected Storage storage;
+
+    protected GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+
+    private static final Generator generator;
+
+    private static final String generatorName = "Lucene GData-Server";
+
+    private static final String generatorURI = "http://lucene.apache.org";
+
+    private static final String XMLMIME = "application/atom+xml";
+    static {
+        generator = new Generator();
+        generator.setName(generatorName);
+        generator.setUri(generatorURI);
+        generator.setVersion("0.1");
+    }
+
+    protected GDataService() throws ServiceException {
+        try {
+            StorageController controller = GDataServerRegistry.getRegistry()
+                    .lookup(StorageController.class,
+                            ComponentType.STORAGECONTROLLER);
+            if (controller == null)
+                throw new StorageException(
+                        "StorageController is not registered");
+            this.storage = controller.getStorage();
+
+        } catch (StorageException e) {
+            LOGGER
+                    .fatal(
+                            "Can't get Storage Instance -- can't serve any requests",
+                            e);
+            ServiceException ex = new ServiceException(
+                    "Can't get Storage instance" + e.getMessage(), e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#createEntry(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.server.GDataResponse)
+     */
+
+    public BaseEntry createEntry(GDataRequest request, GDataResponse response)
+            throws ServiceException {
+
+        if (LOGGER.isInfoEnabled())
+            LOGGER.info("create Entry for feedId: " + request.getFeedId());
+
+        ServerBaseEntry entry = buildEntry(request, response);
+        entry.setFeedId(request.getFeedId());
+        entry.setServiceConfig(request.getConfigurator());
+        setTimeStamps(entry.getEntry());
+        BaseEntry retVal = null;
+        try {
+            retVal = this.storage.storeEntry(entry);
+        } catch (Exception e) {
+            response.setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            ServiceException ex = new ServiceException("Could not store entry",
+                    e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+        return retVal;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#deleteEntry(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.server.GDataResponse)
+     */
+
+    public BaseEntry deleteEntry(GDataRequest request, GDataResponse response)
+            throws ServiceException {
+
+        ServerBaseEntry entry = new ServerBaseEntry();
+        entry.setServiceConfig(request.getConfigurator());
+        entry.setFeedId(request.getFeedId());
+        entry.setId(request.getEntryId());
+        if (entry.getId() == null)
+            throw new ServiceException(
+                    "entry id is null -- can not delete null entry");
+        try {
+            this.storage.deleteEntry(entry);
+        } catch (ResourceNotFoundException e) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            ServiceException ex = new ServiceException(
+                    "Could not delete entry", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        } catch (Exception e) {
+            response.setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            ServiceException ex = new ServiceException(
+                    "Could not delete entry", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#updateEntry(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.server.GDataResponse)
+     */
+
+    public BaseEntry updateEntry(GDataRequest request, GDataResponse response)
+            throws ServiceException {
+
+        ServerBaseEntry entry = buildEntry(request, response);
+        entry.setFeedId(request.getFeedId());
+
+        entry.setServiceConfig(request.getConfigurator());
+        if (LOGGER.isInfoEnabled())
+            LOGGER.info("update Entry" + entry.getId() + " for feedId: "
+                    + request.getFeedId());
+        if (entry.getId() == null) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            throw new ServiceException("Entry id is null can not update entry");
+        }
+        if (!entry.getId().equals(request.getEntryId())) {
+            if (LOGGER.isInfoEnabled())
+                LOGGER
+                        .info("Entry id in the entry xml does not match the requested resource -- XML-ID:"
+                                + entry.getId()
+                                + "; Requested resource: "
+                                + request.getEntryId());
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            throw new ServiceException(
+                    "Entry id in the entry xml does not match the requested resource");
+        }
+        setTimeStamps(entry.getEntry());
+        BaseEntry retVal = null;
+        try {
+            retVal = this.storage.updateEntry(entry);
+        } catch (ResourceNotFoundException e) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            ServiceException ex = new ServiceException(
+                    "Could not update entry", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        } catch (StorageException e) {
+            response.setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            ServiceException ex = new ServiceException(
+                    "Could not update entry", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+        return retVal;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#getFeed(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.server.GDataResponse)
+     */
+    @SuppressWarnings("unchecked")
+    public BaseFeed getFeed(GDataRequest request, GDataResponse response)
+            throws ServiceException {
+
+        ServerBaseFeed feed = new ServerBaseFeed();
+        feed.setId(request.getFeedId());
+        feed.setStartIndex(request.getStartIndex());
+        feed.setItemsPerPage(request.getItemsPerPage());
+        feed.setServiceConfig(request.getConfigurator());
+        try {
+            BaseFeed retVal = this.storage.getFeed(feed);
+            dynamicElementFeedStragey(retVal, request);
+
+            return retVal;
+            /*
+             * resouce not found will be detected in Gdata request.
+             * the request queries the storage for the feed to get the serivce for the feed
+             */
+        } catch (StorageException e) {
+            response.setError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+            ServiceException ex = new ServiceException("Could not get feed", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+
+    }
+
+    private Link buildLink(String rel, String type, String href) {
+        Link retVal = new Link();
+        retVal.setHref(href);
+        retVal.setRel(rel);
+        retVal.setType(type);
+        return retVal;
+    }
+
+    private ServerBaseEntry buildEntry(final GDataRequest request,
+            final GDataResponse response) throws ServiceException {
+        try {
+            ServerBaseEntry entry = new ServerBaseEntry(GDataEntityBuilder
+                    .buildEntry(request));
+            return entry;
+
+        } catch (ParseException e) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            ServiceException ex = new ServiceException(
+                    "Could not parse entry from incoming request", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        } catch (IOException e) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            ServiceException ex = new ServiceException(
+                    "Could not read or open input stream", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+    }
+
+    private BaseEntry setTimeStamps(final BaseEntry entry) {
+        if (entry.getUpdated() == null)
+            entry.setUpdated(DateTime.now());
+        if (entry.getPublished() == null)
+            entry.setPublished(DateTime.now());
+        return entry;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#getSingleEntry(org.apache.lucene.gdata.server.GDataRequest,
+     *      org.apache.lucene.gdata.server.GDataResponse)
+     */
+
+    public BaseEntry getSingleEntry(GDataRequest request, GDataResponse response)
+            throws ServiceException {
+
+        try {
+            ServerBaseEntry entry = new ServerBaseEntry();
+            entry.setServiceConfig(request.getConfigurator());
+            entry.setFeedId(request.getFeedId());
+            entry.setId(request.getEntryId());
+            if(entry.getId() == null){
+                response.setError(HttpServletResponse.SC_BAD_REQUEST);
+                throw new ServiceException("entry is null can't get entry");
+            }
+                
+            BaseEntry retVal = null;
+            retVal = this.storage.getEntry(entry);
+            dynamicElementEntryStragey(retVal, request);
+            return retVal;
+        } catch (ResourceNotFoundException e) {
+            response.setError(HttpServletResponse.SC_BAD_REQUEST);
+            ServiceException ex = new ServiceException(
+                    "Could not get entry", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        } catch (StorageException e) {
+            ServiceException ex = new ServiceException("Could not get feed", e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+    }
+
+    /*
+     * adds all dynamic element to the entry
+     */
+    private void dynamicElementEntryStragey(final BaseEntry entry,
+            final GDataRequest request) {
+        setSelfLink(entry, request.getContextPath());
+    }
+
+    /*
+     * adds all dynamic element to the feed entries
+     */
+    @SuppressWarnings("unchecked")
+    private void dynamicElementFeedStragey(final BaseFeed feed,
+            final GDataRequest request) {
+        buildDynamicFeedElements(request, feed);
+        List<BaseEntry> entryList = feed.getEntries();
+        for (BaseEntry entry : entryList) {
+            String id = request.getContextPath() + entry.getId();
+            setSelfLink(entry, id);
+        }
+
+    }
+
+    /*
+     * The selfLink is build from a prefix and the entry id. The prefix is the
+     * context path of the requested feed. This will be used to request the
+     * entry directly
+     */@SuppressWarnings("unchecked")
+    private BaseEntry setSelfLink(final BaseEntry entry, String id) {
+        Link self = buildLink(Link.Rel.SELF, XMLMIME, id);
+        entry.getLinks().add(self);
+        return entry;
+    }
+
+    /*
+     * build the dynamic elements like self link and next link
+     */
+    private void buildDynamicFeedElements(final GDataRequest request,
+            final BaseFeed feed) {
+        feed.setGenerator(generator);
+        feed.setItemsPerPage(request.getItemsPerPage());
+        feed.setStartIndex(request.getStartIndex());
+        feed.setId(request.getContextPath());
+        feed.getLinks().add(
+                buildLink(Link.Rel.SELF, Link.Type.ATOM, request.getSelfId()));
+        feed.getLinks().add(
+                buildLink(Link.Rel.NEXT, XMLMIME, request.getNextId()));
+
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#close()
+     */
+    public void close() {
+        this.storage.close();
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#getFeedLastModified(java.lang.String)
+     */
+    public Date getFeedLastModified(final String feedId) throws ServiceException {
+        try {
+            return new Date(this.storage.getFeedLastModified(feedId));
+           
+        } catch (StorageException e) {
+            ServiceException ex = new ServiceException(
+                    "Could not get Last update for feed -- "+feedId, e);
+            ex.setStackTrace(e.getStackTrace());
+            throw ex;
+        }
+
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.Service#getEntryLastModified(java.lang.String, java.lang.String)
+     */
+    public Date getEntryLastModified(final String entryId,final String feedId) throws ServiceException {
+            try {
+                return new Date(this.storage.getEntryLastModified(entryId, feedId));
+                
+               
+                
+            } catch (StorageException e) {
+                ServiceException ex = new ServiceException(
+                        "Could not get Last update for entry  -- "+entryId, e);
+                ex.setStackTrace(e.getStackTrace());
+                throw ex;
+            }
+        
+    }
+
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/Service.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/Service.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/Service.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/Service.java Mon Jun 26 11:14:53 2006
@@ -16,6 +16,8 @@
  
 package org.apache.lucene.gdata.server; 
  
+import java.util.Date;
+
 import com.google.gdata.data.BaseEntry; 
 import com.google.gdata.data.BaseFeed; 
  
@@ -39,7 +41,7 @@
  *  
  *  
  */ 
-public abstract class Service { 
+public interface Service { 
  
     /** 
      * Service method to create an entry in an already created and existing 
@@ -133,6 +135,27 @@
     public abstract BaseEntry getSingleEntry(final GDataRequest request, final GDataResponse response) 
             throws ServiceException; 
      
+    /**
+     * will close the Service - service should not be used after this method has been called
+     */
+    public void close();
+
+    /**
+     * Retruns the date of the last modification for the given feed id
+     * @param feedId - the id of the feed 
+     * @return - the last modified date or the current date if the date can not be retrieved
+     * @throws ServiceException - if the storage can not be accessed
+     */
+    public abstract Date getFeedLastModified(String feedId)throws ServiceException;
+
+    /**
+     * Retruns the date of the last modification for the given entry id
+     * @param entryId - the id of the entry
+     * @param feedId  - the feed id this entry belongs to
+     * @return - the last modified date or the current date if the date can not be retrieved
+     * @throws ServiceException - if the storage can not be accessed 
+     */
+    public abstract Date getEntryLastModified(String entryId, String feedId)throws ServiceException;
      
  
  

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceException.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceException.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceException.java Mon Jun 26 11:14:53 2006
@@ -12,52 +12,59 @@
  * 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.lucene.gdata.server; 
- 
-/** 
- * @author Simon Willnauer 
+ */
+
+package org.apache.lucene.gdata.server;
+
+/**
+ * The ServiceException is used to encapsulate all {@link java.lang.Exception}
+ * throw by underlaying layers of the
+ * {@link org.apache.lucene.gdata.server.Service} layer.
  * 
- */ 
-public class ServiceException extends Exception { 
- 
-    /** 
-     *  
-     */ 
-    private static final long serialVersionUID = -7099825107871876584L; 
- 
-    /** 
-     *  
-     */ 
-    public ServiceException() { 
-        super(); 
-       
-    } 
- 
-    /** 
-     * @param arg0 
-     */ 
-    public ServiceException(String arg0) { 
-        super(arg0); 
-       
-    } 
- 
-    /** 
-     * @param arg0 
-     * @param arg1 
-     */ 
-    public ServiceException(String arg0, Throwable arg1) { 
-        super(arg0, arg1); 
-       
-    } 
- 
-    /** 
-     * @param arg0 
-     */ 
-    public ServiceException(Throwable arg0) { 
-        super(arg0); 
-       
-    } 
- 
-} 
+ * @author Simon Willnauer
+ * 
+ */
+public class ServiceException extends Exception {
+
+    /**
+     * 
+     */
+    private static final long serialVersionUID = -7099825107871876584L;
+
+    /**
+     * Constructs a new ServiceException
+     */
+    public ServiceException() {
+        super();
+
+    }
+
+    /**
+     * Constructs a new ServiceException
+     * @param arg0 - the exception message
+     */
+    public ServiceException(String arg0) {
+        super(arg0);
+
+    }
+
+    /**
+     * Constructs a new ServiceException
+     * @param arg0 - the exceptin message
+     * @param arg1 - the exception cause
+     */
+    public ServiceException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+
+    }
+
+    /**
+     * Constructs a new ServiceException
+     * @param arg0 - the exception cause
+     */
+    public ServiceException(Throwable arg0) {
+        super(arg0);
+
+    }
+
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceFactory.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceFactory.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceFactory.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/ServiceFactory.java Mon Jun 26 11:14:53 2006
@@ -1,57 +1,92 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.server;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.server.administration.AdminService;
+import org.apache.lucene.gdata.server.administration.GDataAdminService;
+import org.apache.lucene.gdata.server.registry.Component;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.ServerComponent;
+
+
+/**
+ * The {@link ServiceFactory} creates {@link Service} implementations to access
+ * the GData - Server components.
+ * This class should not be access directy. The class will be registered in the {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry}.
+ * Use {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry#lookup(Class, ComponentType)}
  * 
- * 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 
+ * @author Simon Willnauer
  * 
- *     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.lucene.gdata.server; 
- 
- 
-/** 
- * The {@link ServiceFactory} creates {@link Service} implementations to access 
- * the GData - Server components. 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class ServiceFactory { 
- 
-    private static ServiceFactory INSTANCE = null; 
- 
-    /** 
-     * @return - a Singleton Instance of the factory 
-     */ 
-    public static synchronized ServiceFactory getInstance() { 
-        if (INSTANCE == null) 
-            INSTANCE = new ServiceFactory(); 
-        return INSTANCE; 
- 
-    } 
- 
-    private ServiceFactory() { 
-        // private constructor --> singleton 
-    } 
- 
-    /** 
-     * Creates a {@link Service} implementation. 
-     *  
-     * @return a Service Implementation 
-     */ 
-    public Service getService() { 
-        try{ 
-        return new GDataService(); 
-        }catch (Exception e) { 
-            // 
-        } 
-        return null; 
-    } 
-} 
+ */
+@Component(componentType=ComponentType.SERVICEFACTORY)
+public class ServiceFactory implements ServerComponent {
+
+    private static final Log LOG = LogFactory.getLog(ServiceFactory.class);
+
+	
+
+	/**
+	 * public constructor to enable loading via the registry
+     * @see org.apache.lucene.gdata.server.registry.Component
+     * @see org.apache.lucene.gdata.server.registry.GDataServerRegistry
+	 */
+	public ServiceFactory() {
+		//
+	}
+
+	/**
+	 * Creates a {@link Service} instance.
+	 * 
+	 * @return a Service instance
+	 */
+	public Service getService() {
+		try{
+		return new GDataService();
+        }catch (Exception e) {
+            //
+        }
+        return null;
+	}
+    
+    /**
+     * Creates a {@link AdminService} instance
+     * @return a AdminService instance
+     */
+    public AdminService getAdminService(){
+        try {
+            return new GDataAdminService();
+        } catch (ServiceException e) {
+           LOG.warn("Factory method can not create GDataAdminService returning null-- "+e.getMessage(),e);
+        }
+        return null;
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ServerComponent#initialize()
+     */
+    public void initialize() {
+        //
+    }
+
+    /**
+     * @see org.apache.lucene.gdata.server.registry.ServerComponent#destroy()
+     */
+    public void destroy() {
+        //
+    }
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/DataBuilderException.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/DataBuilderException.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/DataBuilderException.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/DataBuilderException.java Mon Jun 26 11:14:53 2006
@@ -1,62 +0,0 @@
-/** 
- * Copyright 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.lucene.gdata.server.registry; 
- 
-/** 
- * @author Simon Willnauer 
- * 
- */ 
-public class DataBuilderException extends RuntimeException { 
- 
-    /** 
-     *  
-     */ 
-    private static final long serialVersionUID = -3802958802500735198L; 
- 
-    /** 
-     *  
-     */ 
-    public DataBuilderException() { 
-        super(); 
-        // TODO Auto-generated constructor stub 
-    } 
- 
-    /** 
-     * @param message 
-     */ 
-    public DataBuilderException(String message) { 
-        super(message); 
-        // TODO Auto-generated constructor stub 
-    } 
- 
-    /** 
-     * @param message 
-     * @param cause 
-     */ 
-    public DataBuilderException(String message, Throwable cause) { 
-        super(message, cause); 
-        // TODO Auto-generated constructor stub 
-    } 
- 
-    /** 
-     * @param cause 
-     */ 
-    public DataBuilderException(Throwable cause) { 
-        super(cause); 
-        // TODO Auto-generated constructor stub 
-    } 
- 
-} 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/FeedInstanceConfigurator.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/FeedInstanceConfigurator.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/FeedInstanceConfigurator.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/FeedInstanceConfigurator.java Mon Jun 26 11:14:53 2006
@@ -1,66 +0,0 @@
-/** 
- * Copyright 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.lucene.gdata.server.registry; 
- 
-/** 
- * @author Simon Willnauer 
- * 
- */ 
-public class FeedInstanceConfigurator { 
-    private Class feedType; 
-    private String feedId; 
-    private Class extensionProfileClass; 
-    /** 
-     * @return Returns the feedType. 
-     */ 
-    public Class getFeedType() { 
-        return this.feedType; 
-    } 
-    /** 
-     * @param feedType The feedType to set. 
-     */ 
-    public void setFeedType(Class feedType) { 
-        this.feedType = feedType; 
-    } 
-    /** 
-     * @return Returns the feedURL. 
-     */ 
-    public String getFeedId() { 
-        return this.feedId; 
-    } 
-    /** 
-     * @param feedURL The feedURL to set. 
-     */ 
-    public void setFeedId(String feedURL) { 
-        this.feedId = feedURL; 
-    } 
-     
-    /** 
-     * @return - the extension profile for this feed 
-     */ 
-    public Class getExtensionProfilClass(){ 
-        return this.extensionProfileClass; 
-    } 
-     
-    /** 
-     * @param extensionProfilClass 
-     */ 
-    public void setExtensionProfileClass(Class extensionProfilClass){ 
-        this.extensionProfileClass = extensionProfilClass; 
-    } 
-     
- 
-} 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/GDataServerRegistry.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/GDataServerRegistry.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/GDataServerRegistry.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/GDataServerRegistry.java Mon Jun 26 11:14:53 2006
@@ -1,154 +1,254 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.server.registry;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
  * 
- * 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 
+ * The GDataServerRegistry represents the registry component of the GData
+ * Server. All provided services and server components will be registered here.
+ * The Gdata Server serves RSS / ATOM feeds for defined services. Each service
+ * provides <i>n</i> feeds of a defined subclass of
+ * {@link com.google.gdata.data.BaseFeed}. Each feed contains <i>m</i> entries
+ * of a defined subclass of {@link com.google.gdata.data.BaseEntry}. To
+ * generate RSS / ATOM formates a class of the type
+ * {@link com.google.gdata.data.ExtensionProfile} is also defined for a service.
+ * <p>
+ * The entry,feed and the ExtensionProfile classes are defined in the
+ * gdata-config.xml and will be loaded when the server starts up.
+ * </p>
+ * <p>
+ * The components defined in the gdata-config.xml will also be loaded and
+ * instanciated at startup. If a component can not be loaded or an Exception
+ * occures the server will not start up. To cause of the exception or error will
+ * be logged to the standart server output.
+ * </p>
+ * <p>The GDataServerRegistry is a Singleton</p>
  * 
- *     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.lucene.gdata.server.registry; 
- 
-import java.util.HashMap; 
-import java.util.Map; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
-import org.apache.lucene.gdata.storage.StorageController; 
- 
-import com.google.gdata.data.ExtensionProfile; 
- 
-/** 
- *  
- * The FeedRegistry represents the registry component of the GData Server. All 
- * feed configurations will be registered here. Feed configurations contain 
- * several informationsa about GData feed like: 
- * <ol> 
- * <li>the feed id - where the feed can be accessed via http methodes</li> 
- * <li>the feed type - feed types are implementations of the abstract 
- * {@link com.google.gdata.data.BaseFeed}</li> 
- * </ol> 
- * The registry will be set up at start up of the server application and can be 
- * accessed from other components to get configurations according to incoming 
- * requests. 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class GDataServerRegistry { 
-    private static GDataServerRegistry INSTANCE; 
- 
-    private StorageController storageInstance; 
- 
-    private static final Log LOGGER = LogFactory 
-            .getLog(GDataServerRegistry.class); 
- 
-    private final Map<String, FeedInstanceConfigurator> feedTypMap = new HashMap<String, FeedInstanceConfigurator>(); 
- 
-    private GDataServerRegistry() { 
-        // private - singleton 
-    } 
- 
-    /** 
-     * @return a Sinleton registry instance 
-     */ 
-    public static synchronized GDataServerRegistry getRegistry() { 
-        if (INSTANCE == null) 
-            INSTANCE = new GDataServerRegistry(); 
-        return INSTANCE; 
-    } 
- 
-    /** 
-     * Registers a {@link FeedInstanceConfigurator} 
-     *  
-     * @param configurator - 
-     *            the configurator to register in the registry 
-     */ 
-    public void registerFeed(FeedInstanceConfigurator configurator) { 
-        if (configurator == null) { 
-            LOGGER.warn("Feedconfigurator is null -- skip registration"); 
-            return; 
-        } 
-        this.feedTypMap.put(configurator.getFeedId(), configurator); 
-    } 
- 
-    /** 
-     * Looks up the {@link FeedInstanceConfigurator} by the given feed id. 
-     *  
-     * @param feedId 
-     * @return - the {@link FeedInstanceConfigurator} or <code>null</code> if 
-     *         the no configuration for this feed has been registered 
-     */ 
-    public FeedInstanceConfigurator getFeedConfigurator(String feedId) { 
-        if (feedId == null) 
-            throw new IllegalArgumentException( 
-                    "Feed URL is null - must not be null to get registered feedtype"); 
-        return this.feedTypMap.get(feedId); 
-    } 
- 
-    protected void flushRegistry() { 
-        this.feedTypMap.clear(); 
-    } 
- 
-    /** 
-     * @param feedId - 
-     *            the id of the feed as the feed is registered 
-     * @return - <code>true</code> if and only if the feed is registered, 
-     *         otherwise <code>false</code>. 
-     */ 
-    public boolean isFeedRegistered(String feedId) { 
-        return this.feedTypMap.containsKey(feedId); 
- 
-    } 
- 
-    /** 
-     * @param storage 
-     */ 
-    public void registerStorage(StorageController storage) { 
-        if (this.storageInstance != null) 
-            throw new IllegalStateException( 
-                    "Storage already registered -- Instance of " 
-                            + this.storageInstance.getClass()); 
-        this.storageInstance = storage; 
-    } 
- 
-    /** 
-     * Destroys the registry and release all resources 
-     */ 
-    public void destroy() { 
-        flushRegistry(); 
-        this.storageInstance.destroy(); 
-        this.storageInstance = null; 
- 
-    } 
- 
-    /** 
-     * Creates the  {@link ExtensionProfile} for a registered feed 
-     * @param feedId - the feed id  
-     * @return - the extension profil for this feed of <code>null</code> if 
-     *         the feed is not registered or the extension profile could not be 
-     *         instanciated 
-     */ 
-    public ExtensionProfile getExtensionProfile(final String feedId) { 
-        FeedInstanceConfigurator configurator = this.feedTypMap.get(feedId); 
-        if (configurator == null) 
-            return null; 
-        Class clazz = configurator.getExtensionProfilClass(); 
-        try { 
-            return (ExtensionProfile) clazz.newInstance(); 
-        } catch (Exception e) { 
-            LOGGER 
-                    .error("Can not create instance of ExtensionProfil for class: " 
-                            + clazz + " -- feedId: " + feedId); 
- 
-        } 
-        return null; 
-    } 
- 
-} 
+ * @author Simon Willnauer
+ * 
+ */
+public class GDataServerRegistry {
+    private static GDataServerRegistry INSTANCE;
+
+    private static final Log LOGGER = LogFactory
+            .getLog(GDataServerRegistry.class);
+
+    private final Map<String, ProvidedService> serviceTypeMap = new HashMap<String, ProvidedService>();
+
+    private final Map<ComponentType, ComponentBean> componentMap = new HashMap<ComponentType, ComponentBean>(
+            10);
+
+    private GDataServerRegistry() {
+        // private - singleton
+    }
+
+    /**
+     * @return a Sinleton registry instance
+     */
+    public static synchronized GDataServerRegistry getRegistry() {
+        if (INSTANCE == null)
+            INSTANCE = new GDataServerRegistry();
+        return INSTANCE;
+    }
+
+    /**
+     * Registers a {@link ProvidedService}
+     * 
+     * @param configurator -
+     *            the configurator to register in the registry
+     */
+    public void registerService(ProvidedService configurator) {
+        if (configurator == null) {
+            LOGGER.warn("Feedconfigurator is null -- skip registration");
+            return;
+        }
+        this.serviceTypeMap.put(configurator.getName(), configurator);
+    }
+
+    /**
+     * Looks up the {@link ProvidedServiceConfig} by the given service name.
+     * 
+     * @param service
+     * @return - the {@link ProvidedServiceConfig} or <code>null</code> if the
+     *         no configuration for this service has been registered
+     */
+    public ProvidedService getProvidedService(String service) {
+        if (service == null)
+            throw new IllegalArgumentException(
+                    "Service is null - must not be null to get registered feedtype");
+        return this.serviceTypeMap.get(service);
+    }
+
+    protected void flushRegistry() {
+        this.serviceTypeMap.clear();
+        this.componentMap.clear();
+    }
+
+    /**
+     * @param service -
+     *            the name of the service
+     * @return - <code>true</code> if and only if the service is registered,
+     *         otherwise <code>false</code>.
+     */
+    public boolean isServiceRegistered(String service) {
+        return this.serviceTypeMap.containsKey(service);
+
+    }
+
+    /**
+     * Destroys the registry and release all resources
+     */
+    public void destroy() {
+        for (ComponentBean component : this.componentMap.values()) {
+            component.getObject().destroy();
+        }
+        flushRegistry();
+
+    }
+
+    /**
+     * This method is the main interface to the Component Lookup Service of the
+     * registry. Every GDATA - Server component like STORAGE or the INDEXER
+     * component will be accessible via this method. To get a Component from the
+     * lookup service specify the expected Class as an argument and the
+     * component type of the component to return. For a lookup of the
+     * STORAGECONTORLER the code looks like:
+     * <p>
+     * <code> registryInstance.lookup(StorageController.class,ComponentType.STORAGECONTROLLER);</code>
+     * </p>
+     * 
+     * @param <R>
+     *            the type of the expected return value
+     * @param clazz -
+     *            Class object of the expected return value
+     * @param compType -
+     *            The component type
+     * @return the registered component or <code>null</code> if the component
+     *         can not looked up.
+     */
+    @SuppressWarnings("unchecked")
+    public <R> R lookup(Class<R> clazz, ComponentType compType) {
+        ComponentBean bean = this.componentMap.get(compType);
+        if (bean == null)
+            return null;
+        if (bean.getSuperType().equals(clazz))
+            return (R) bean.getObject();
+        return null;
+    }
+
+    /**
+     * @param <E> 
+     * @param componentClass
+     * @throws RegistryException
+     */
+    @SuppressWarnings("unchecked")
+    public  <E extends ServerComponent> void  registerComponent(final Class<E> componentClass)
+            throws RegistryException {
+        
+        if (componentClass == null)
+            throw new IllegalArgumentException(
+                    "component class must not be null");
+  
+        if(!checkImplementsServerComponent(componentClass))
+            throw new RegistryException("can not register component. the given class does not implement ServerComponent interface -- "+componentClass.getName());
+        try {
+
+            Component annotation =  componentClass.getAnnotation(Component.class);
+            if (annotation == null)
+                throw new RegistryException(
+                        "can not register component. the given class is not a component -- "
+                                + componentClass.getName());
+            ComponentType type = annotation.componentType();
+            if (this.componentMap.containsKey(type))
+                throw new RegistryException("component already registered -- "
+                        + type.name());
+            Class superType = type.getClass().getField(type.name())
+                    .getAnnotation(SuperType.class).superType();
+            if (!checkSuperType(componentClass, superType))
+                throw new RegistryException("Considered Supertype <"
+                        + superType.getName() + "> is not a super type of <"
+                        + componentClass + ">");
+            ServerComponent comp = componentClass.newInstance();
+            comp.initialize();
+            ComponentBean bean = new ComponentBean(comp, superType);
+            
+            this.componentMap.put(type, bean);
+
+        } catch (Exception e) {
+            throw new RegistryException("Can not register component -- "
+                    + e.getMessage(), e);
+        }
+
+    }
+    
+    private static boolean checkImplementsServerComponent(Class type){
+        if(type == null)
+            return false;
+        if(type.equals(Object.class))
+            return false;
+        if(type.equals(ServerComponent.class))
+            return true;
+        Class[] compInterfaces = type.getInterfaces();
+        for (int i = 0; i < compInterfaces.length; i++) {
+           if(checkImplementsServerComponent(compInterfaces[i]))
+               return true;
+        }
+        return checkImplementsServerComponent(type.getSuperclass());
+        
+    }
+
+    private static boolean checkSuperType(Class type, Class consideredSuperType) {
+
+        if (type.equals(Object.class))
+            return false;
+        if (type.equals(consideredSuperType))
+            return true;
+        Class[] interfaces = type.getInterfaces();
+        for (int i = 0; i < interfaces.length; i++) {
+            if (interfaces[i].equals(consideredSuperType))
+                return true;
+        }
+        return checkSuperType(type.getSuperclass(), consideredSuperType);
+    }
+
+    private class ComponentBean {
+        private final Class superType;
+
+        private final ServerComponent object;
+
+        ComponentBean(final ServerComponent object, final Class superType) {
+            this.superType = superType;
+            this.object = object;
+        }
+
+        ServerComponent getObject() {
+            return this.object;
+        }
+
+        Class getSuperType() {
+            return this.superType;
+        }
+
+    }
+
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryBuilder.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryBuilder.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryBuilder.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryBuilder.java Mon Jun 26 11:14:53 2006
@@ -12,30 +12,59 @@
  * 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.lucene.gdata.server.registry; 
- 
-import com.google.gdata.data.ExtensionProfile; 
-import com.google.gdata.data.Feed; 
- 
-/** 
- * @author Simon Willnauer 
+ */
+package org.apache.lucene.gdata.server.registry;
+
+import java.io.IOException;
+
+import org.apache.commons.digester.Digester;
+import org.xml.sax.SAXException;
+
+/**
+ * Reads the configuration file and creates the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} singleton
+ * instance. All services and components will be instanciated and registered in
+ * the registry.
  * 
- */ 
-public class RegistryBuilder { 
- 
-    /** 
-     *  
-     */ 
-    public static void buildRegistry(){ 
-        // TODO Implement this!! -- just for develping purposes 
-        GDataServerRegistry reg = GDataServerRegistry.getRegistry(); 
-        FeedInstanceConfigurator configurator = new FeedInstanceConfigurator(); 
-        configurator.setFeedType(Feed.class); 
-        configurator.setFeedId("weblog"); 
-        configurator.setExtensionProfileClass(ExtensionProfile.class); 
-        reg.registerFeed(configurator); 
-         
-    } 
-     
-} 
+ * @author Simon Willnauer
+ * 
+ */
+class RegistryBuilder {
+
+    /**
+     * builds the {@link GDataServerRegistry} accessible via the
+     * {@link GDataServerRegistry#getRegistry()} method
+     * 
+     * @throws IOException -
+     *             if an IOException occures while reading the config file
+     * @throws SAXException -
+     *             if the config file can not be parsed
+     */
+    static void buildRegistry() throws IOException, SAXException {
+
+        buildFromConfiguration(new Digester(), GDataServerRegistry
+                .getRegistry());
+
+    }
+
+    private static void buildFromConfiguration(Digester digester,
+            GDataServerRegistry registry) throws IOException, SAXException {
+        
+        digester.setValidating(false);
+        digester.push(registry);
+        digester.addCallMethod("gdata/server-components/component",
+                "registerComponent", 0, new Class[] { Class.class });
+        digester.addObjectCreate("gdata/service", ProvidedServiceConfig.class);
+        digester.addSetProperties("gdata/service");
+        digester.addSetNext("gdata/service", "registerService");
+        digester.addBeanPropertySetter("gdata/service/feed-class", "feedType");
+        digester.addBeanPropertySetter("gdata/service/entry-class", "entryType");
+        digester.addBeanPropertySetter("gdata/service/extension-profile",
+                "extensionProfileClass");
+        digester.parse(RegistryBuilder.class
+                .getResourceAsStream("/gdata-config.xml"));
+    }
+
+   
+
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryContextListener.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryContextListener.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryContextListener.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/RegistryContextListener.java Mon Jun 26 11:14:53 2006
@@ -1,65 +1,80 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.server.registry;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This Listener creates the
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} when the
+ * context is loaded. The registry will be loaded before the
+ * {@link org.apache.lucene.gdata.servlet.RequestControllerServlet} is loaded.
+ * The Registry will be loaded and set up befor the REST interface is available.
+ * <p>
+ * This ContextListener has to be configured in the <code>web.xml</code>
+ * deployment descriptor.
+ * </p>
+ * <p>
+ * When the
+ * {@link javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)}
+ * method is called the registry will be destroyed using
+ * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry#destroy()}
+ * method.
  * 
- * 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 
+ * @author Simon Willnauer
  * 
- * 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.lucene.gdata.server.registry; 
- 
-import javax.servlet.ServletContextEvent; 
-import javax.servlet.ServletContextListener; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
- 
-/** 
- * This Listener creates the 
- * {@link org.apache.lucene.gdata.server.registry.GDataServerRegistry} when the 
- * context is loaded. The registry will be loaded before the 
- * {@link org.apache.lucene.gdata.servlet.RequestControllerServlet} is loaded. 
- * The Registry will be loaded and set up befor the REST interface is available. 
- * <p> 
- * This ContextListener has to be configured in the <code>web.xml</code> 
- * deployment descriptor.</p> 
- *  
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class RegistryContextListener implements ServletContextListener { 
-    private GDataServerRegistry serverRegistry; 
- 
-    private static final Log LOG = LogFactory 
-            .getLog(RegistryContextListener.class); 
- 
-   
- 
-    /** 
-     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent) 
-     */ 
-    public void contextInitialized(ServletContextEvent arg0) { 
-        LOG.info("RegistryContextListener has been loaded"); 
-        RegistryBuilder.buildRegistry(); 
-        this.serverRegistry = GDataServerRegistry.getRegistry(); 
-    } 
- 
-    /** 
-     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) 
-     */ 
-    public void contextDestroyed(ServletContextEvent arg0) { 
-        LOG.info("Destroying context"); 
-        this.serverRegistry.destroy(); 
- 
-    } 
- 
-} 
+ */
+public class RegistryContextListener implements ServletContextListener {
+    private GDataServerRegistry serverRegistry;
+
+    private static final Log LOG = LogFactory
+            .getLog(RegistryContextListener.class);
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
+     */
+    public void contextInitialized(ServletContextEvent arg0) {
+        LOG.info("RegistryContextListener has been loaded");
+
+        try {
+            RegistryBuilder.buildRegistry();
+            this.serverRegistry = GDataServerRegistry.getRegistry();
+        } catch (Exception e) {
+            this.serverRegistry.destroy();
+            LOG.error("can not register requiered components", e);
+            throw new RuntimeException("Can not register required components",
+                    e);
+        }
+     
+
+    }
+
+    /**
+     * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
+     */
+    public void contextDestroyed(ServletContextEvent arg0) {
+        LOG.info("Destroying context");
+        this.serverRegistry.destroy();
+
+    }
+
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/package.html
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/package.html?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/package.html (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/server/registry/package.html Mon Jun 26 11:14:53 2006
@@ -5,6 +5,6 @@
    <meta name="Author" content="Simon Willnauer"> 
 </head> 
 <body> 
-Internal registry - registering feeds and configurations 
+Internal registry - registering services and server components
 </body> 
 </html> 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/AbstractGdataServlet.java Mon Jun 26 11:14:53 2006
@@ -18,10 +18,15 @@
  
 import java.io.IOException; 
  
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletException; 
 import javax.servlet.http.HttpServlet; 
 import javax.servlet.http.HttpServletRequest; 
 import javax.servlet.http.HttpServletResponse; 
+
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+import org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory;
  
 /** 
  *  
@@ -42,7 +47,9 @@
  
     private static final String METHOD_POST = "POST"; 
  
-    private static final String METHOD_PUT = "PUT"; 
+    private static final String METHOD_PUT = "PUT";
+
+    protected static RequestHandlerFactory HANDLER_FACTORY = null; 
  
     /** 
      * This overwrites the protected <code>service</code> method to dispatch 
@@ -92,6 +99,17 @@
             super.service(arg0, arg1); 
         } 
  
+    }
+
+    /**
+     * 
+     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
+     */
+    public void init(ServletConfig arg0) throws ServletException {
+        HANDLER_FACTORY = GDataServerRegistry.getRegistry().lookup(RequestHandlerFactory.class,ComponentType.REQUESTHANDLERFACTORY);
+        if(HANDLER_FACTORY == null)
+            throw new ServletException("service not available");
+        
     } 
  
 } 

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/RequestControllerServlet.java Mon Jun 26 11:14:53 2006
@@ -1,122 +1,102 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.servlet;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.servlet.handler.GDataRequestHandler;
+
+/**
+ * Provides a clean basic interface for GDATA Client API and requests to the
+ * GDATA Server. This Servlet dispatches the incoming requests to defined GDATA
+ * request handlers. Each of the handler processes the incoming request and
+ * responds according to the requested action.
  * 
- * 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 
+ * @author Simon Willnauer
  * 
- *     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.lucene.gdata.servlet; 
- 
-import java.io.IOException; 
- 
-import javax.servlet.ServletConfig; 
-import javax.servlet.ServletException; 
-import javax.servlet.http.HttpServletRequest; 
-import javax.servlet.http.HttpServletResponse; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
-import org.apache.lucene.gdata.servlet.handler.DefaultRequestHandlerFactory; 
-import org.apache.lucene.gdata.servlet.handler.GDataRequestHandler; 
-import org.apache.lucene.gdata.servlet.handler.RequestHandlerFactory; 
- 
-/** 
- * Provides a clean basic interface for GDATA Client API and requests to the 
- * GDATA Server. This Servlet dispatches the incoming requests to defined GDATA 
- * request handlers. Each of the handler processes the incoming request and 
- * responds according to the requested action. 
- *  
- * @author Simon Willnauer 
- *  
- */ 
-public class RequestControllerServlet extends AbstractGdataServlet { 
-    private static RequestHandlerFactory HANDLER_FACTORY = null; 
-    private static final Log LOGGER = LogFactory.getLog(RequestControllerServlet.class); 
- 
-    /** 
-     * Version ID since this class implements 
-     *  
-     * @see java.io.Serializable 
-     */ 
-    private static final long serialVersionUID = 7540810742476175576L; 
- 
-    /** 
-     * @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest, 
-     *      javax.servlet.http.HttpServletResponse) 
-     */ 
-    @Override 
-    protected void doDelete(HttpServletRequest arg0, HttpServletResponse arg1) 
-            throws ServletException, IOException { 
-        GDataRequestHandler hanlder = HANDLER_FACTORY.getDeleteHandler(); 
-        if(LOGGER.isInfoEnabled()) 
-            LOGGER.info("Process DELETE request"); 
-         
-        hanlder.processRequest(arg0, arg1); 
-    } 
- 
-    /** 
-     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, 
-     *      javax.servlet.http.HttpServletResponse) 
-     */ 
-    @Override 
-    protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1) 
-            throws ServletException, IOException { 
-        GDataRequestHandler hanlder = HANDLER_FACTORY.getQueryHandler(); 
-        if(LOGGER.isInfoEnabled()) 
-            LOGGER.info("Process GET request"); 
-         
-        hanlder.processRequest(arg0, arg1); 
-    } 
- 
-    /** 
-     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, 
-     *      javax.servlet.http.HttpServletResponse) 
-     */ 
-    @Override 
-    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) 
-            throws ServletException, IOException { 
-        GDataRequestHandler hanlder = HANDLER_FACTORY.getInsertHandler(); 
-        if(LOGGER.isInfoEnabled()) 
-            LOGGER.info("Process POST request"); 
-        hanlder.processRequest(arg0, arg1); 
-    } 
- 
-    /** 
-     * @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest, 
-     *      javax.servlet.http.HttpServletResponse) 
-     */ 
-    @Override 
-    protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1) 
-            throws ServletException, IOException { 
-        GDataRequestHandler hanlder = HANDLER_FACTORY.getUpdateHandler(); 
-        if(LOGGER.isInfoEnabled()) 
-            LOGGER.info("Process PUT request"); 
-        hanlder.processRequest(arg0, arg1); 
-    } 
- 
-    /** 
-     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) 
-     */ 
-    @Override 
-    public void init(ServletConfig arg0)  { 
-        /* 
-         * The Factory implementation could be configured as an initial 
-         * parameter or by an external config file. 
-         *  
-         */ 
-        HANDLER_FACTORY = RequestHandlerFactory 
-                .getInstance(DefaultRequestHandlerFactory.class); 
-         
-    } 
-     
-   
-} 
+ */
+public class RequestControllerServlet extends AbstractGdataServlet {
+    private static final Log LOGGER = LogFactory.getLog(RequestControllerServlet.class);
+
+    /**
+     * Version ID since this class implements
+     * 
+     * @see java.io.Serializable
+     */
+    private static final long serialVersionUID = 7540810742476175576L;
+
+    /**
+     * @see javax.servlet.http.HttpServlet#doDelete(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+	protected void doDelete(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws ServletException, IOException {
+        GDataRequestHandler hanlder = HANDLER_FACTORY.getEntryDeleteHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process DELETE request");
+        
+        hanlder.processRequest(arg0, arg1);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+	protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws ServletException, IOException {
+        GDataRequestHandler hanlder = HANDLER_FACTORY.getFeedQueryHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process GET request");
+        hanlder.processRequest(arg0, arg1);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+	protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws ServletException, IOException {
+        GDataRequestHandler hanlder = HANDLER_FACTORY.getEntryInsertHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process POST request");
+        hanlder.processRequest(arg0, arg1);
+    }
+
+    /**
+     * @see javax.servlet.http.HttpServlet#doPut(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    @Override
+	protected void doPut(HttpServletRequest arg0, HttpServletResponse arg1)
+            throws ServletException, IOException {
+        GDataRequestHandler hanlder = HANDLER_FACTORY.getEntryUpdateHandler();
+        if(LOGGER.isInfoEnabled())
+            LOGGER.info("Process PUT request");
+        hanlder.processRequest(arg0, arg1);
+    }
+    
+  
+}

Modified: lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractGdataRequestHandler.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractGdataRequestHandler.java?rev=417265&r1=417264&r2=417265&view=diff
==============================================================================
--- lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractGdataRequestHandler.java (original)
+++ lucene/java/trunk/contrib/gdata-server/src/java/org/apache/lucene/gdata/servlet/handler/AbstractGdataRequestHandler.java Mon Jun 26 11:14:53 2006
@@ -1,96 +1,104 @@
-/** 
- * Copyright 2004 The Apache Software Foundation 
+/**
+ * Copyright 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.lucene.gdata.servlet.handler;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.lucene.gdata.server.GDataRequest;
+import org.apache.lucene.gdata.server.GDataRequestException;
+import org.apache.lucene.gdata.server.GDataResponse;
+import org.apache.lucene.gdata.server.Service;
+import org.apache.lucene.gdata.server.ServiceFactory;
+import org.apache.lucene.gdata.server.GDataRequest.GDataRequestType;
+import org.apache.lucene.gdata.server.registry.ComponentType;
+import org.apache.lucene.gdata.server.registry.GDataServerRegistry;
+
+/**
+ * @author Simon Willnauer
  * 
- * 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.lucene.gdata.servlet.handler; 
- 
-import java.io.IOException; 
- 
-import javax.servlet.ServletException; 
-import javax.servlet.http.HttpServletRequest; 
-import javax.servlet.http.HttpServletResponse; 
- 
-import org.apache.commons.logging.Log; 
-import org.apache.commons.logging.LogFactory; 
-import org.apache.lucene.gdata.server.GDataRequest; 
-import org.apache.lucene.gdata.server.GDataRequestException; 
-import org.apache.lucene.gdata.server.GDataResponse; 
-import org.apache.lucene.gdata.server.Service; 
-import org.apache.lucene.gdata.server.ServiceFactory; 
-import org.apache.lucene.gdata.server.GDataRequest.GDataRequestType; 
- 
-/** 
- * @author Simon Willnauer 
- *  
- */ 
-public abstract class AbstractGdataRequestHandler implements 
-        GDataRequestHandler { 
-    private final static Log LOG = LogFactory 
-            .getLog(AbstractGdataRequestHandler.class); 
- 
-     
-    protected GDataRequest feedRequest; 
-    protected GDataResponse feedResponse; 
- 
-    /** 
-     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest, 
-     *      javax.servlet.http.HttpServletResponse) 
-     */ 
-    public abstract void processRequest(HttpServletRequest request, 
-            HttpServletResponse response) throws ServletException, IOException; 
- 
-    protected void initializeRequestHandler(final HttpServletRequest request, final HttpServletResponse response, final GDataRequestType type) 
-            throws GDataRequestException { 
-        this.feedRequest = new GDataRequest(request, type); 
-        this.feedResponse = new GDataResponse(response); 
-        try {        
-            this.feedRequest.initializeRequest(); 
-        } catch (GDataRequestException e) { 
-            this.feedResponse.setError(HttpServletResponse.SC_NOT_FOUND); 
-            LOG.warn("Couldn't initialize FeedRequest - " + e.getMessage(), e); 
-            throw e; 
-        } 
-    } 
- 
-     
- 
-    protected void sendError() throws IOException { 
-        this.feedResponse.sendError(); 
-         
-    } 
- 
-    protected void setFeedResponseFormat() { 
-        this.feedResponse.setOutputFormat(this.feedRequest.getRequestedResponseFormat()); 
-    } 
- 
-    protected void setFeedResponseStatus(int status) { 
-        this.feedResponse.setResponseCode(status); 
-    } 
- 
-    protected void setError(int error) { 
-        this.feedResponse.setError(error); 
-    } 
- 
-    protected Service getService() throws ServletException { 
-        ServiceFactory serviceFactory = ServiceFactory.getInstance(); 
-        Service service = serviceFactory.getService(); 
-        if(service == null) 
-            throw new ServletException("Service not available");  
-        return service; 
-    } 
- 
-     
- 
-} 
+ */
+public abstract class AbstractGdataRequestHandler extends RequestAuthenticator implements
+        GDataRequestHandler {
+    private final static Log LOG = LogFactory
+            .getLog(AbstractGdataRequestHandler.class);
+
+    protected Service service;
+    protected GDataRequest feedRequest;
+    protected GDataResponse feedResponse;
+
+    /**
+     * @see org.apache.lucene.gdata.servlet.handler.GDataRequestHandler#processRequest(javax.servlet.http.HttpServletRequest,
+     *      javax.servlet.http.HttpServletResponse)
+     */
+    public abstract void processRequest(HttpServletRequest request,
+            HttpServletResponse response) throws ServletException, IOException;
+
+    protected void initializeRequestHandler(final HttpServletRequest request, final HttpServletResponse response, final GDataRequestType type)
+            throws GDataRequestException, ServletException {
+        this.feedRequest = new GDataRequest(request, type);
+        this.feedResponse = new GDataResponse(response);
+        getService();
+        try {       
+            this.feedRequest.initializeRequest();
+        } catch (GDataRequestException e) {
+            this.feedResponse.setError(HttpServletResponse.SC_NOT_FOUND);
+            LOG.warn("Couldn't initialize FeedRequest - " + e.getMessage(), e);
+            throw e;
+        }
+    }
+
+    
+
+    protected void sendError() throws IOException {
+        this.feedResponse.sendError();
+        
+    }
+
+	protected void setFeedResponseFormat() {
+		this.feedResponse.setOutputFormat(this.feedRequest.getRequestedResponseFormat());
+	}
+
+	protected void setFeedResponseStatus(int status) {
+		this.feedResponse.setResponseCode(status);
+	}
+
+	protected void setError(int error) {
+		this.feedResponse.setError(error);
+	}
+
+    private void getService() throws ServletException {
+        GDataServerRegistry registry = GDataServerRegistry.getRegistry();
+        ServiceFactory serviceFactory = registry.lookup(ServiceFactory.class,ComponentType.SERVICEFACTORY);
+        this.service = serviceFactory.getService();
+        if(this.service == null)
+            throw new ServletException("Service not available"); 
+        
+    }
+    
+    protected void closeService(){
+        this.service.close();
+    }
+
+
+
+}



Mime
View raw message