Author: andreas
Date: Fri Feb 6 02:27:10 2009
New Revision: 741380
URL: http://svn.apache.org/viewvc?rev=741380&view=rev
Log:
Springify Lenya core components.
Modified:
lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilder.java
lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentUtil.java
lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/PublicationUtil.java
lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/metadata/MetaDataCache.java
lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java
lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java
lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml
Modified: lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilder.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilder.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilder.java (original)
+++ lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilder.java Fri Feb 6 02:27:10 2009
@@ -25,11 +25,6 @@
public interface DocumentFactoryBuilder {
/**
- * The Avalon service role.
- */
- String ROLE = DocumentFactoryBuilder.class.getName();
-
- /**
* Creates a new document factory.
* @param session The session.
* @return A document identity map.
Modified: lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentUtil.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentUtil.java (original)
+++ lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/DocumentUtil.java Fri Feb 6 02:27:10 2009
@@ -17,9 +17,9 @@
*/
package org.apache.lenya.cms.publication;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.environment.Request;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.repository.RepositoryUtil;
import org.apache.lenya.cms.repository.Session;
@@ -40,24 +40,14 @@
*/
public static final DocumentFactory createDocumentFactory(ServiceManager manager,
Session session) {
- DocumentFactoryBuilder builder = getBuilder(manager);
+ DocumentFactoryBuilder builder = (DocumentFactoryBuilder) WebAppContextUtils
+ .getCurrentWebApplicationContext().getBean(DocumentFactoryBuilder.class.getName());
return builder.createDocumentFactory(session);
}
- protected static DocumentFactoryBuilder getBuilder(ServiceManager manager) {
- if (DocumentUtil.builder == null) {
- try {
- DocumentUtil.builder = (DocumentFactoryBuilder) manager.lookup(DocumentFactoryBuilder.ROLE);
- } catch (ServiceException e) {
- throw new RuntimeException(e);
- }
- }
- return DocumentUtil.builder;
- }
-
/**
- * Returns a document factory for the session which is attached to the
- * request. If no session exists, it is created.
+ * Returns a document factory for the session which is attached to the request. If no session
+ * exists, it is created.
* @param manager The service manager.
* @param request The request.
* @return A document factory.
@@ -73,8 +63,7 @@
}
/**
- * Returns the currently requested document or <code>null</code> if no
- * document is requested.
+ * Returns the currently requested document or <code>null</code> if no document is requested.
* @param manager The service manager.
* @param request The request.
* @return A document.
Modified: lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/PublicationUtil.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/PublicationUtil.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/PublicationUtil.java (original)
+++ lenya/trunk/org.apache.lenya.core.api/src/main/java/org/apache/lenya/cms/publication/PublicationUtil.java Fri Feb 6 02:27:10 2009
@@ -74,6 +74,7 @@
* @param webappUrl The URL within the web application (without context prefix)
* @return A publication
* @throws PublicationException when something went wrong
+ * @deprecated
*/
public static Publication getPublicationFromUrl(ServiceManager manager,
DocumentFactory factory, String webappUrl) throws PublicationException {
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/metadata/MetaDataCache.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/metadata/MetaDataCache.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/metadata/MetaDataCache.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/metadata/MetaDataCache.java Fri Feb 6 02:27:10 2009
@@ -17,23 +17,17 @@
*/
package org.apache.lenya.cms.metadata;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
import org.apache.excalibur.store.impl.MRUMemoryStore;
-import org.apache.lenya.cms.publication.Document;
/**
* Cache for meta data.
*/
-public class MetaDataCache implements ThreadSafe, Serviceable, Component {
+public class MetaDataCache {
public static final String ROLE = MetaDataCache.class.getName();
protected static final String STORE_ROLE = MetaDataCache.ROLE + "Store";
private MRUMemoryStore store;
- protected ServiceManager manager;
/**
* Get a meta data object from the cache.
@@ -68,18 +62,11 @@
protected MRUMemoryStore getStore() {
if (this.store == null) {
synchronized (this) {
- try {
- this.store = (MRUMemoryStore) this.manager.lookup(STORE_ROLE);
- } catch (ServiceException e) {
- throw new RuntimeException(e);
- }
+ this.store = (MRUMemoryStore) WebAppContextUtils.getCurrentWebApplicationContext()
+ .getBean(STORE_ROLE);
}
}
return this.store;
}
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
- }
-
}
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryBuilderImpl.java Fri Feb 6 02:27:10 2009
@@ -17,27 +17,52 @@
*/
package org.apache.lenya.cms.publication;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.util.AbstractLogEnabled;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.metadata.MetaDataCache;
import org.apache.lenya.cms.repository.Session;
/**
* Document factory builder implementation.
*/
-public class DocumentFactoryBuilderImpl extends AbstractLogEnabled implements ThreadSafe,
- DocumentFactoryBuilder, Serviceable {
+public class DocumentFactoryBuilderImpl extends AbstractLogEnabled implements
+ DocumentFactoryBuilder {
+
+ private PublicationManager pubManager;
+ private MetaDataCache metaDataCache;
+ private SourceResolver sourceResolver;
public DocumentFactory createDocumentFactory(Session session) {
- return new DocumentFactoryImpl(session, this.manager, getLogger());
+ DocumentFactoryImpl factory = new DocumentFactoryImpl(session, getLogger());
+ factory.setMetaDataCache(getMetaDataCache());
+ factory.setPublicationManager(getPublicationManager());
+ factory.setSourceResolver(getSourceResolver());
+ return factory;
+ }
+
+ protected void setPublicationManager(PublicationManager pubManager) {
+ this.pubManager = pubManager;
+ }
+
+ protected PublicationManager getPublicationManager() {
+ return this.pubManager;
+ }
+
+ protected MetaDataCache getMetaDataCache() {
+ return metaDataCache;
+ }
+
+ public void setMetaDataCache(MetaDataCache metaDataCache) {
+ this.metaDataCache = metaDataCache;
}
-
- protected ServiceManager manager;
- public void service(ServiceManager manager) throws ServiceException {
- this.manager = manager;
+ public SourceResolver getSourceResolver() {
+ return sourceResolver;
}
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ this.sourceResolver = sourceResolver;
+ }
+
+
}
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentFactoryImpl.java Fri Feb 6 02:27:10 2009
@@ -25,6 +25,8 @@
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.commons.logging.Log;
+import org.apache.excalibur.source.SourceResolver;
+import org.apache.lenya.cms.metadata.MetaDataCache;
import org.apache.lenya.cms.repository.RepositoryException;
import org.apache.lenya.cms.repository.RepositoryItem;
import org.apache.lenya.cms.repository.Session;
@@ -39,7 +41,8 @@
public class DocumentFactoryImpl extends AbstractLogEnabled implements DocumentFactory {
private Session session;
- protected ServiceManager manager;
+ private MetaDataCache metaDataCache;
+ private SourceResolver sourceResolver;
/**
* @return The session.
@@ -51,12 +54,10 @@
/**
* Ctor.
* @param session The session to use.
- * @param manager The service manager.
* @param logger The logger to use.
*/
- public DocumentFactoryImpl(Session session, ServiceManager manager, Log logger) {
+ public DocumentFactoryImpl(Session session, Log logger) {
this.session = session;
- this.manager = manager;
}
/**
@@ -179,7 +180,7 @@
*/
public boolean isDocument(String webappUrl) throws DocumentBuildException {
Assert.notNull("webapp URL", webappUrl);
- PublicationManager pubMgr = getPubManager();
+ PublicationManager pubMgr = getPublicationManager();
try {
URLInformation info = new URLInformation(webappUrl);
String pubId = info.getPublicationId();
@@ -236,8 +237,8 @@
protected DocumentLocator getLocator(String webappUrl) {
DocumentLocator locator;
try {
- Publication publication = PublicationUtil.getPublicationFromUrl(this.manager, this,
- webappUrl);
+ URLInformation info = new URLInformation(webappUrl);
+ Publication publication = getPublication(info.getPublicationId());
DocumentBuilder builder = publication.getDocumentBuilder();
locator = builder.getLocator(this, webappUrl);
@@ -298,7 +299,10 @@
*/
protected DocumentImpl createDocument(DocumentFactory map, DocumentIdentifier identifier,
int revision, DocumentBuilder builder) throws DocumentBuildException {
- return new DocumentImpl(this.manager, map, identifier, revision, getLogger());
+ DocumentImpl doc = new DocumentImpl(map, identifier, revision, getLogger());
+ doc.setMetaDataCache(getMetaDataCache());
+ doc.setSourceResolver(getSourceResolver());
+ return doc;
}
public Document get(DocumentIdentifier identifier) throws DocumentBuildException {
@@ -326,28 +330,41 @@
}
public Publication getPublication(String id) throws PublicationException {
- return getPubManager().getPublication(this, id);
+ return getPublicationManager().getPublication(this, id);
}
public Publication[] getPublications() {
- return getPubManager().getPublications(this);
+ return getPublicationManager().getPublications(this);
}
- private static PublicationManager pubManager;
+ private PublicationManager pubManager;
- protected PublicationManager getPubManager() {
- if (pubManager == null) {
- try {
- pubManager = (PublicationManager) this.manager.lookup(PublicationManager.ROLE);
- } catch (ServiceException e) {
- throw new RuntimeException(e);
- }
- }
- return pubManager;
+ protected void setPublicationManager(PublicationManager pubManager) {
+ this.pubManager = pubManager;
+ }
+
+ protected PublicationManager getPublicationManager() {
+ return this.pubManager;
}
public boolean existsPublication(String id) {
- return Arrays.asList(getPubManager().getPublicationIds()).contains(id);
+ return Arrays.asList(getPublicationManager().getPublicationIds()).contains(id);
+ }
+
+ protected MetaDataCache getMetaDataCache() {
+ return metaDataCache;
+ }
+
+ public void setMetaDataCache(MetaDataCache metaDataCache) {
+ this.metaDataCache = metaDataCache;
+ }
+
+ public SourceResolver getSourceResolver() {
+ return sourceResolver;
+ }
+
+ public void setSourceResolver(SourceResolver sourceResolver) {
+ this.sourceResolver = sourceResolver;
}
}
\ No newline at end of file
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/java/org/apache/lenya/cms/publication/DocumentImpl.java Fri Feb 6 02:27:10 2009
@@ -25,12 +25,11 @@
import java.util.Date;
import java.util.List;
-import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceSelector;
+import org.apache.cocoon.spring.configurator.WebAppContextUtils;
import org.apache.cocoon.util.AbstractLogEnabled;
import org.apache.commons.logging.Log;
+import org.apache.excalibur.source.SourceResolver;
import org.apache.lenya.cms.cocoon.source.SourceUtil;
import org.apache.lenya.cms.metadata.MetaData;
import org.apache.lenya.cms.metadata.MetaDataCache;
@@ -54,7 +53,6 @@
private DocumentIdentifier identifier;
private DocumentFactory factory;
- protected ServiceManager manager;
private int revision = -1;
/**
@@ -97,7 +95,7 @@
* @param revision The revision number or -1 if the latest revision should be used.
* @param _logger a logger
*/
- protected DocumentImpl(ServiceManager manager, DocumentFactory map,
+ protected DocumentImpl(DocumentFactory map,
DocumentIdentifier identifier, int revision, Log logger) {
if (getLogger().isDebugEnabled()) {
@@ -110,7 +108,6 @@
throw new IllegalArgumentException("The UUID must not be null!");
}
- this.manager = manager;
this.identifier = identifier;
this.factory = map;
this.revision = revision;
@@ -422,6 +419,7 @@
private ResourceType resourceType;
private MetaDataCache metaDataCache;
+ private SourceResolver resolver;
/**
* Convenience method to read the document's resource type from the meta-data.
@@ -429,18 +427,17 @@
*/
public ResourceType getResourceType() throws DocumentException {
if (this.resourceType == null) {
- ServiceSelector selector = null;
+ String name;
try {
- String name = getMetaData(METADATA_NAMESPACE).getFirstValue(METADATA_RESOURCE_TYPE);
- if (name == null) {
- throw new DocumentException("No resource type defined for document [" + this
- + "]!");
- }
- selector = (ServiceSelector) this.manager.lookup(ResourceType.ROLE + "Selector");
- this.resourceType = (ResourceType) selector.select(name);
- } catch (Exception e) {
+ name = getMetaData(METADATA_NAMESPACE).getFirstValue(METADATA_RESOURCE_TYPE);
+ } catch (MetaDataException e) {
throw new DocumentException(e);
}
+ if (name == null) {
+ throw new DocumentException("No resource type defined for document [" + this
+ + "]!");
+ }
+ this.resourceType = (ResourceType) WebAppContextUtils.getCurrentWebApplicationContext().getBean(ResourceType.class.getName() + "/" + name);
}
return this.resourceType;
}
@@ -458,13 +455,6 @@
}
protected MetaDataCache getMetaDataCache() {
- if (this.metaDataCache == null) {
- try {
- this.metaDataCache = (MetaDataCache) this.manager.lookup(MetaDataCache.ROLE);
- } catch (ServiceException e) {
- throw new RuntimeException(e);
- }
- }
return this.metaDataCache;
}
@@ -522,7 +512,7 @@
public boolean existsAreaVersion(String area) {
String sourceUri = getSourceURI(getPublication(), area, getUUID(), getLanguage());
try {
- return SourceUtil.exists(sourceUri, this.manager);
+ return SourceUtil.exists(sourceUri, this.resolver);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -706,4 +696,16 @@
return this.revision;
}
+ public void setMetaDataCache(MetaDataCache metaDataCache) {
+ this.metaDataCache = metaDataCache;
+ }
+
+ public SourceResolver getSourceResolver() {
+ return resolver;
+ }
+
+ public void setSourceResolver(SourceResolver resolver) {
+ this.resolver = resolver;
+ }
+
}
\ No newline at end of file
Modified: lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml
URL: http://svn.apache.org/viewvc/lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml?rev=741380&r1=741379&r2=741380&view=diff
==============================================================================
--- lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml (original)
+++ lenya/trunk/org.apache.lenya.core.impl/src/main/resources/META-INF/cocoon/spring/lenya-core-impl-components.xml Fri Feb 6 02:27:10 2009
@@ -25,8 +25,16 @@
<property name="uuidGenerator" ref="org.apache.lenya.cms.repository.UUIDGenerator"/>
<property name="sharedItemStore" ref="org.apache.lenya.cms.repository.SharedItemStore"/>
</bean>
+ <bean name="org.apache.lenya.cms.publication.PublicationManager"
+ class="org.apache.lenya.cms.publication.PublicationManagerImpl"/>
+ <bean name="org.apache.lenya.cms.metadata.MetaDataCache"
+ class="org.apache.lenya.cms.metadata.MetaDataCache"/>
<bean name="org.apache.lenya.cms.publication.DocumentFactoryBuilder"
- class="org.apache.lenya.cms.publication.DocumentFactoryBuilderImpl"/>
+ class="org.apache.lenya.cms.publication.DocumentFactoryBuilderImpl">
+ <property name="publicationManager" ref="org.apache.lenya.cms.publication.PublicationManager"/>
+ <property name="metaDataCache" ref="org.apache.lenya.cms.metadata.MetaDataCache"/>
+ <property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
+ </bean>
<bean name="org.apache.lenya.cms.module.ModuleManager"
class="org.apache.lenya.cms.module.ModuleManagerImpl"/>
<bean name="org.apache.lenya.cms.repository.SharedItemStore"
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.