001 /* 002 * JBoss DNA (http://www.jboss.org/dna) 003 * See the COPYRIGHT.txt file distributed with this work for information 004 * regarding copyright ownership. Some portions may be licensed 005 * to Red Hat, Inc. under one or more contributor license agreements. 006 * See the AUTHORS.txt file in the distribution for a full listing of 007 * individual contributors. 008 * 009 * Unless otherwise indicated, all code in JBoss DNA is licensed 010 * to you under the terms of the GNU Lesser General Public License as 011 * published by the Free Software Foundation; either version 2.1 of 012 * the License, or (at your option) any later version. 013 * 014 * JBoss DNA is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 017 * Lesser General Public License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this software; if not, write to the Free 021 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 022 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 023 */ 024 package org.jboss.dna.jcr; 025 026 import org.jboss.dna.common.util.CheckArg; 027 import org.jboss.dna.graph.ExecutionContext; 028 import org.jboss.dna.graph.connector.RepositorySource; 029 import org.jboss.dna.graph.mimetype.MimeTypeDetector; 030 import org.jboss.dna.repository.Configurator; 031 import org.jboss.dna.repository.DnaConfiguration; 032 import org.jboss.dna.repository.DnaConfigurationException; 033 import org.jboss.dna.repository.Configurator.ChooseClass; 034 import org.jboss.dna.repository.Configurator.ConfigRepositoryDetails; 035 import org.jboss.dna.repository.Configurator.MimeTypeDetectorDetails; 036 import org.jboss.dna.repository.Configurator.RepositoryDetails; 037 038 /** 039 * A configuration builder for a {@link JcrEngine}. This class is an internal domain-specific language (DSL), 040 * and is designed to be used in a traditional way or in a method-chained manner: 041 * <pre> 042 * configuration.addRepository("Source1").usingClass(InMemoryRepositorySource.class).describedAs("description"); 043 * configuration.addMimeTypeDetector("detector") 044 * .usingClass(ExtensionBasedMimeTypeDetector.class) 045 * .describedAs("default detector"); 046 * configuration.addSequencer("MicrosoftDocs") 047 * .usingClass("org.jboss.dna.sequencer.msoffice.MSOfficeMetadataSequencer") 048 * .loadedFromClasspath() 049 * .named("Microsoft Document sequencer") 050 * .describedAs("Our primary sequencer for all .doc files") 051 * .sequencingFrom("/public//(*.(doc|xml|ppt)[*]/jcr:content[@jcr:data]") 052 * .andOutputtingTo("/documents/$1"); 053 * configuration.save(); 054 * </pre> 055 */ 056 public class JcrConfiguration 057 implements Configurator.Initializer<JcrConfiguration>, /*Configurator.SequencerConfigurator<JcrConfiguration>,*/ 058 Configurator.RepositoryConfigurator<JcrConfiguration>, Configurator.MimeDetectorConfigurator<JcrConfiguration>, 059 Configurator.Builder<JcrEngine> { 060 061 private final DnaConfiguration.Builder<JcrConfiguration> builder; 062 063 /** 064 * Create a new configuration for DNA. 065 */ 066 public JcrConfiguration() { 067 this(new ExecutionContext()); 068 } 069 070 /** 071 * Specify a new {@link ExecutionContext} that should be used for this DNA instance. 072 * 073 * @param context the new context, or null if a default-constructed execution context should be used 074 * @throws IllegalArgumentException if the supplied context reference is null 075 */ 076 public JcrConfiguration( ExecutionContext context ) { 077 this.builder = new DnaConfiguration.Builder<JcrConfiguration>(context, this); 078 } 079 080 /** 081 * Get the execution context used by this configurator. 082 * 083 * @return the execution context; never null 084 */ 085 public final ExecutionContext getExecutionContext() { 086 return builder.getExecutionContext(); 087 } 088 089 /** 090 * {@inheritDoc} 091 * 092 * @see org.jboss.dna.repository.Configurator.Initializer#withConfigurationRepository() 093 */ 094 public ChooseClass<RepositorySource, ConfigRepositoryDetails<JcrConfiguration>> withConfigurationRepository() { 095 return builder.withConfigurationRepository(); 096 } 097 098 // /** 099 // * {@inheritDoc} 100 // * 101 // * @see org.jboss.dna.repository.Configurator.SequencerConfigurator#addSequencer(java.lang.String) 102 // */ 103 // public ChooseClass<Sequencer, SequencerDetails<JcrConfiguration>> addSequencer( String id ) { 104 // CheckArg.isNotEmpty(id, "id"); 105 // return builder.addSequencer(id); 106 // } 107 108 /** 109 * {@inheritDoc} 110 * 111 * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(java.lang.String) 112 */ 113 public ChooseClass<RepositorySource, RepositoryDetails<JcrConfiguration>> addRepository( String id ) { 114 CheckArg.isNotEmpty(id, "id"); 115 return builder.addRepository(id); 116 } 117 118 /** 119 * {@inheritDoc} 120 * 121 * @see org.jboss.dna.repository.Configurator.RepositoryConfigurator#addRepository(org.jboss.dna.graph.connector.RepositorySource) 122 */ 123 public JcrConfiguration addRepository( RepositorySource source ) { 124 CheckArg.isNotNull(source, "source"); 125 CheckArg.isNotEmpty(source.getName(), "source.getName()"); 126 return builder.addRepository(source); 127 } 128 129 /** 130 * {@inheritDoc} 131 * 132 * @see org.jboss.dna.repository.Configurator.MimeDetectorConfigurator#addMimeTypeDetector(java.lang.String) 133 */ 134 public ChooseClass<MimeTypeDetector, MimeTypeDetectorDetails<JcrConfiguration>> addMimeTypeDetector( String id ) { 135 CheckArg.isNotEmpty(id, "id"); 136 return builder.addMimeTypeDetector(id); 137 } 138 139 /** 140 * Save any changes that have been made so far to the configuration. This method does nothing if no changes have been made. 141 * 142 * @return this configuration object for method chaining purposes; never null 143 */ 144 public JcrConfiguration save() { 145 return builder.save(); 146 } 147 148 /** 149 * {@inheritDoc} 150 * 151 * @see org.jboss.dna.repository.Configurator.Builder#build() 152 */ 153 public JcrEngine build() throws DnaConfigurationException { 154 save(); 155 return new JcrEngine(builder.buildDnaEngine()); 156 } 157 }