You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2005/12/02 10:52:07 UTC

svn commit: r351654 - in /lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon: ./ ConfigurableElementSet.java RepositoryFactory.java RepositoryFactoryImpl.java

Author: andreas
Date: Fri Dec  2 01:52:03 2005
New Revision: 351654

URL: http://svn.apache.org/viewcvs?rev=351654&view=rev
Log:
Repo layer: added Avalon-based RepositoryFactory

Added:
    lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/
    lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/ConfigurableElementSet.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactory.java
    lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/ConfigurableElementSet.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/ConfigurableElementSet.java?rev=351654&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/ConfigurableElementSet.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/ConfigurableElementSet.java Fri Dec  2 01:52:03 2005
@@ -0,0 +1,65 @@
+/*
+ * Copyright  1999-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.lenya.cms.repo.avalon;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.lenya.cms.repo.metadata.Element;
+import org.apache.lenya.cms.repo.metadata.ElementSet;
+import org.apache.lenya.cms.repo.metadata.impl.ElementImpl;
+
+/**
+ * Avalon-based element set.
+ */
+public class ConfigurableElementSet extends AbstractLogEnabled implements ElementSet, Configurable {
+
+    private String namespaceUri;
+    private Map elements = new HashMap();
+
+    protected String getNamespaceURI() {
+        return this.namespaceUri;
+    }
+
+    public void configure(Configuration config) throws ConfigurationException {
+
+        this.namespaceUri = config.getAttribute("namespace");
+
+        Configuration[] attributeConfigs = config.getChildren("attribute");
+        for (int i = 0; i < attributeConfigs.length; i++) {
+            String name = attributeConfigs[i].getAttribute("name");
+            boolean isMultiple = attributeConfigs[i].getAttributeAsBoolean("multiple", false);
+            this.elements.put(name, new ElementImpl(name, isMultiple));
+        }
+
+    }
+
+    public Element[] getElements() {
+        Collection values = this.elements.values();
+        return (Element[]) values.toArray(new Element[values.size()]);
+    }
+
+    public Element getElement(String name) {
+        return (Element) this.elements.get(name);
+    }
+
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactory.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactory.java?rev=351654&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactory.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactory.java Fri Dec  2 01:52:03 2005
@@ -0,0 +1,38 @@
+/*
+ * Copyright  1999-2005 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.lenya.cms.repo.avalon;
+
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+
+/**
+ * Avalon-based repository factory.
+ */
+public interface RepositoryFactory {
+    
+    /**
+     * The Avalon role.
+     */
+    String ROLE = RepositoryFactory.class.getName();
+
+    /**
+     * @return The repository.
+     * @throws RepositoryException if an error occurs.
+     */
+    public Repository getRepository() throws RepositoryException;
+    
+}

Added: lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java
URL: http://svn.apache.org/viewcvs/lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java?rev=351654&view=auto
==============================================================================
--- lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java (added)
+++ lenya/trunk/src/java/org/apache/lenya/cms/repo/avalon/RepositoryFactoryImpl.java Fri Dec  2 01:52:03 2005
@@ -0,0 +1,61 @@
+/*
+ * Copyright  1999-2005 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.lenya.cms.repo.avalon;
+
+import java.util.Map;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.context.Context;
+import org.apache.avalon.framework.context.ContextException;
+import org.apache.avalon.framework.context.Contextualizable;
+import org.apache.avalon.framework.thread.ThreadSafe;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.lenya.cms.repo.Repository;
+import org.apache.lenya.cms.repo.RepositoryException;
+import org.apache.lenya.cms.repo.RepositoryManager;
+
+/**
+ * Repository factory implementation.
+ */
+public class RepositoryFactoryImpl implements RepositoryFactory, Contextualizable, Configurable,
+        ThreadSafe {
+
+    public void contextualize(Context context) throws ContextException {
+        this.context = context;
+    }
+
+    public void configure(Configuration config) throws ConfigurationException {
+        this.factoryClassName = config.getChild("repository-factory").getAttribute("class");
+    }
+
+    private String factoryClassName;
+    private Repository repository;
+    private Context context;
+
+    public Repository getRepository() throws RepositoryException {
+        if (this.repository == null) {
+            Map objectModel = ContextHelper.getObjectModel(this.context);
+            String webappPath = ObjectModelHelper.getContext(objectModel).getRealPath("/");
+            this.repository = RepositoryManager.getRepository(webappPath, this.factoryClassName);
+        }
+        return this.repository;
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@lenya.apache.org
For additional commands, e-mail: commits-help@lenya.apache.org