Author: alexsmirnov
Date: 2010-01-28 20:31:27 -0500 (Thu, 28 Jan 2010)
New Revision: 16380
Added:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ModelValidator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/StandardSources.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ValidatorImpl.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMakerModule.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
Log:
https://jira.jboss.org/jira/browse/RF-8288 all but template compiler converted to
dependency injection
Added:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
(rev 0)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -0,0 +1,45 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public interface FileManager {
+
+ public File getFile(String path) throws FileNotFoundException;
+
+ public Iterable<File> getFiles();
+
+ public File createFile(String path, long lastModified) throws IOException;
+
+ public abstract Iterable<File> getFolders();
+
+}
Property changes on:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/FileManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -33,6 +33,8 @@
import org.richfaces.cdk.xmlconfig.XmlModule;
import java.io.File;
+import java.nio.charset.Charset;
+import java.util.Locale;
import java.util.Map;
import javax.annotation.Nullable;
@@ -57,9 +59,14 @@
private Injector injector;
- private Map<StandardOutputFolders, File> outputFolders;
+ private Locale locale = Locale.getDefault();
+
+ private Charset charset = Charset.defaultCharset();
+
+ private Map<StandardOutputFolders, FileManager> outputFolders =
Maps.newHashMap();
- private Map<StandardSources, Iterable<File>> sources;
+ private Map<StandardSources,FileManager> sources = Maps.newHashMap();
+
public void setLoader(CdkClassLoader loader) {
this.loader = loader;
@@ -69,10 +76,14 @@
this.log = log;
}
- public void setOutputFolders(Map<StandardOutputFolders, File> outputFolders) {
- this.outputFolders = outputFolders;
+ public void addOutputFolder(StandardOutputFolders type, File outputFolder) {
+ this.outputFolders.put(type, new OutputFileManager(outputFolder));
}
+ public void addSources(StandardSources type, Iterable<File> files,
Iterable<File> folders){
+ this.sources.put(type, new SourceFileManager(files, folders));
+ }
+
public void init(){
checkNotNull(loader, "classLoader");
injector = Guice.createInjector(new CdkConfigurationModule(),new AptModule(),new
ModelModule(),
@@ -90,11 +101,13 @@
protected void configure() {
bind(CdkClassLoader.class).toInstance(loader);
bind(Logger.class).toInstance(log);
- for (Map.Entry<StandardOutputFolders, File> entry :
outputFolders.entrySet()) {
- bind(File.class).annotatedWith(new
OutputFolderImpl(entry.getKey())).toInstance(entry.getValue());
+ bind(Locale.class).toInstance(locale);
+ bind(Charset.class).toInstance(charset);
+ for (Map.Entry<StandardOutputFolders, FileManager> entry :
outputFolders.entrySet()) {
+ bind(FileManager.class).annotatedWith(new
OutputFolderImpl(entry.getKey())).toInstance(entry.getValue());
}
- for (Map.Entry<StandardSources, Iterable<File>> entry :
sources.entrySet()) {
- bind(new TypeLiteral<Iterable<File>>(){}).annotatedWith(new
SourceImpl(entry.getKey())).toInstance(entry.getValue());
+ for (Map.Entry<StandardSources, FileManager> entry :
sources.entrySet()) {
+ bind(FileManager.class).annotatedWith(new
SourceImpl(entry.getKey())).toInstance(entry.getValue());
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -82,7 +82,7 @@
builder.build();
}
- getValidator().verify(library);
+ getValidator().verify();
generate();
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ModelValidator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ModelValidator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ModelValidator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -23,7 +23,6 @@
package org.richfaces.cdk;
-import org.richfaces.cdk.model.ComponentLibrary;
/**
* <p class="changed_added_4_0">Interface for CDK library model
verifier.</p>
@@ -38,5 +37,5 @@
* @param library
* @throws CdkException
*/
- public void verify(ComponentLibrary library) throws CdkException;
+ public void verify() throws CdkException;
}
Added:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
(rev 0)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -0,0 +1,128 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.Collections;
+
+import org.richfaces.cdk.model.ComponentLibrary;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class OutputFileManager implements FileManager {
+
+ private final Iterable<File> folders;
+ private final File folder;
+
+ public OutputFileManager(File folder) {
+ this.folder = folder;
+ this.folders = Collections.singleton(folder);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#createFile(java.lang.String)
+ */
+ @Override
+ public File createFile(String path, long lastModified) throws IOException {
+ if (null == path) {
+ throw new NullPointerException();
+ }
+
+
+ if (null == folder) {
+ throw new FileNotFoundException("No output folder set for file " +
path);
+ }
+
+ if (folder.exists() && !folder.isDirectory()) {
+ throw new IOException("Output folder " + folder + " not is
directory.");
+ }
+
+ // Strip leading '/'
+ if (path.startsWith(File.separator)) {
+ path = path.substring(1);
+ }
+
+ File outputFile = new File(folder, path);
+
+ if (outputFile.exists()) {
+ if (lastModified > 0 && outputFile.lastModified() >
lastModified) {
+ return null;
+ } else {
+ outputFile.delete();
+ }
+ }
+
+ // Create file folder.
+ outputFile.getParentFile().mkdirs();
+ outputFile.createNewFile();
+
+ return outputFile;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#getFile(java.lang.String)
+ */
+ @Override
+ public File getFile(String path) throws FileNotFoundException {
+ File file = new File(folder, path);
+ if (file.exists()) {
+ return file;
+ }
+ throw new FileNotFoundException(path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#getFiles()
+ */
+ @Override
+ public Iterable<File> getFiles() {
+ // TODO - list all files in folder.
+ return Collections.emptySet();
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @return the folders
+ */
+ @Override
+ public Iterable<File> getFolders() {
+ return this.folders;
+ }
+
+}
Property changes on:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/OutputFileManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
(rev 0)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -0,0 +1,103 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class SourceFileManager implements FileManager {
+
+ private final Iterable<File> sources;
+ private final Iterable<File> folders;
+
+ public SourceFileManager(Iterable<File> sources, Iterable<File> folders)
{
+ this.sources = sources;
+ this.folders = folders;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#createFile(java.lang.String)
+ */
+ @Override
+ public File createFile(String path, long lastModified) throws IOException {
+ throw new UnsupportedOperationException("Cannot create file in source
folder");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#getFile(java.lang.String)
+ */
+ @Override
+ public File getFile(String path) throws FileNotFoundException {
+ if (null != folders) {
+ for (File folder : folders) {
+ if (folder.exists() && folder.isDirectory()) {
+ File configFile = new File(folder, path);
+ if (configFile.exists()) {
+ return configFile;
+ }
+ }
+ }
+ }
+ if(null != sources){
+ for (File file : sources) {
+ if(file.getAbsolutePath().endsWith(path)){
+ return file;
+ }
+ }
+ }
+ throw new FileNotFoundException(path);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.FileManager#getFiles()
+ */
+ @Override
+ public Iterable<File> getFiles() {
+ return sources;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the folders
+ */
+ @Override
+ public Iterable<File> getFolders() {
+ return this.folders;
+ }
+
+}
Property changes on:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/SourceFileManager.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/StandardSources.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/StandardSources.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/StandardSources.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -30,7 +30,7 @@
* @author asmirnov(a)exadel.com
*/
public enum StandardSources implements SourceType {
- JAVA_SOURCES, FACES_CONFIGS, RENDERER_TEMPLATES;
+ JAVA_SOURCES, FACES_CONFIGS,
RENDERER_TEMPLATES,JAVA_SOURCE_FOLDERS,FACES_CONFIG_FOLDERS,TEMPLATE_FOLDERS;
@Override
public String getName() {
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ValidatorImpl.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ValidatorImpl.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/ValidatorImpl.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -50,7 +50,6 @@
@Inject
public ValidatorImpl(ComponentLibrary library, NamingConventions namingConventions)
{
this.library = library;
- // TODO Auto-generated constructor stub
this.namingConventions = namingConventions;
}
/*
@@ -58,9 +57,9 @@
* @see
org.richfaces.cdk.ValidatorModel#verify(org.richfaces.cdk.model.ComponentLibrary)
*/
@Override
- public void verify(ComponentLibrary library) throws CdkException {
+ public void verify() throws CdkException {
verifyRenderers();
- verifyComponents(library);
+ verifyComponents();
// After all, merge all similar elements.
compact(library.getComponents());
@@ -82,8 +81,7 @@
}
}
- protected void verifyComponents(ComponentLibrary library) throws CdkException {
- NamingConventions namingConventions = getNamingConventions();
+ protected void verifyComponents() throws CdkException {
for (ComponentModel component : library.getComponents()) {
@@ -101,10 +99,6 @@
}
}
- private NamingConventions getNamingConventions() throws CdkException {
- return namingConventions;
- }
-
protected void compact(Collection<?> collection) {
// if (collection instanceof ModelCollection) {
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkAnnotationProcessor.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -25,18 +25,20 @@
import java.lang.annotation.Annotation;
+import javax.inject.Inject;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkProcessingException;
-import org.richfaces.cdk.CdkWorker;
+import org.richfaces.cdk.xmlconfig.FragmentParser;
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public interface CdkAnnotationProcessor extends CdkWorker {
+public interface CdkAnnotationProcessor {
+
/**
* <p class="changed_added_4_0"></p>
* @param element
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -28,20 +28,17 @@
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.RoundEnvironment;
+import javax.inject.Inject;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkProcessingException;
-import org.richfaces.cdk.CdkWorker;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.ModelValidator;
-import org.richfaces.cdk.OutputType;
-import org.richfaces.cdk.StandardOutputs;
-import org.richfaces.cdk.StandardSources;
+import org.richfaces.cdk.model.ComponentLibrary;
-import com.google.common.collect.ImmutableList;
-
/**
* <p class="changed_added_4_0">
* Base class for all CDK Annotation processors. That class provides access to current
CDK context and utility methods
@@ -51,70 +48,61 @@
* @author asmirnov(a)exadel.com
*
*/
-public class CdkProcessor extends AbstractProcessor implements CdkWorker {
+public class CdkProcessor extends AbstractProcessor {
private static final Set<String> ANY_ANNOTATION =
Collections.singleton("*");
+
+ @Inject
+ private Logger log;
- private static final ImmutableList<? extends Class<? extends
CdkAnnotationProcessor>> PROCESSORS = ImmutableList
- .of(ComponentProcessor.class,
- FacesComponentProcessor.class,
- BehaviorProcessor.class,
- ValidatorProcessor.class,
- ConverterProcessor.class);
+ @Inject
+ private Iterable<CdkAnnotationProcessor> processors;
- /**
- * <p class="changed_added_4_0">
- * CDK context.
- * </p>
- */
- private CdkContext context;
+ @Inject
+ private Iterable<ModelBuilder> builders;
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param context
- * current CDK context
- * @throws CdkException
- */
- @Override
- public void init(CdkContext context) throws CdkException {
- this.context = context;
- }
+ @Inject
+ private Iterable<CdkWriter> generators;
+
+ @Inject
+ private SourceUtils sourceUtils;
+
+ @Inject
+ private ModelValidator validator;
+
+
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
roundEnv) {
- SourceUtils sourceUtils = new SourceUtils(this.processingEnv, roundEnv);
- sourceUtils.init(getContext());
- getContext().setWorker(SourceUtils.class, sourceUtils);
+ sourceUtils.setup(this.processingEnv, roundEnv);
if (!roundEnv.processingOver()) {
// Process annotations.
- for (Class<? extends CdkAnnotationProcessor> process : PROCESSORS) {
+ for (CdkAnnotationProcessor process : processors) {
processAnnotation(process);
}
// parse non-java sources
- getContext().getBuilderFor(StandardSources.FACES_CONFIGS).build();
- getContext().getBuilderFor(StandardSources.RENDERER_TEMPLATES).build();
-
getContext().getWorker(ModelValidator.class).verify(getContext().getLibrary());
- } else if (!getContext().getErrors().iterator().hasNext()) {
+ for (ModelBuilder builder : builders) {
+ builder.build();
+ }
+ validator.verify();
+ } else if (0 == log.getErrorCount()) {
// processing over, generate files.
- for (OutputType type : StandardOutputs.values()) {
- getContext().getGeneratorFor(type).render();
+ for (CdkWriter generator : generators) {
+ generator.render();
}
}
- getContext().setWorker(SourceUtils.class, null);
+ sourceUtils.release();
return false;
}
- protected void processAnnotation(Class<? extends CdkAnnotationProcessor>
processor) {
- CdkAnnotationProcessor cdkAnnotationProcessor =
getContext().getWorker(processor);
- Set<? extends TypeElement> annotatedWith =
getContext().getWorker(SourceUtils.class)
- .getClassesAnnotatedWith(cdkAnnotationProcessor.getProcessedAnnotation());
+ protected void processAnnotation(CdkAnnotationProcessor processor) {
+ Set<? extends TypeElement> annotatedWith = sourceUtils
+ .getClassesAnnotatedWith(processor.getProcessedAnnotation());
for (TypeElement typeElement : annotatedWith) {
try {
- cdkAnnotationProcessor.process(typeElement);
+ processor.process(typeElement);
} catch (CdkProcessingException e) {
sendError(typeElement, e);
}
@@ -124,19 +112,8 @@
protected void sendError(TypeElement componentElement, CdkProcessingException e) {
// rise error and continue.
processingEnv.getMessager().printMessage(javax.tools.Diagnostic.Kind.ERROR,
e.getMessage(), componentElement);
- getContext().sendError(e);
}
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the context
- */
- protected CdkContext getContext() {
- return context;
- }
-
@Override
public Set<String> getSupportedAnnotationTypes() {
return ANY_ANNOTATION;
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -27,7 +27,6 @@
import java.lang.annotation.Annotation;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.annotation.processing.SupportedAnnotationTypes;
@@ -79,6 +78,7 @@
*/
@SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
Component.NAME})
public class ComponentProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
+
public void process(TypeElement componentElement) {
ComponentLibrary library = getLibrary();
// Process class-level annotations.
@@ -102,9 +102,6 @@
return explicitType;
}
- private NamingConventions getNamingConventions() {
- return getContext().getWorker(NamingConventions.class);
- }
private void setComponentProperties(TypeElement componentElement, ComponentModel
component)
@@ -124,7 +121,7 @@
}
private void processFacets(TypeElement componentElement, ComponentModel component) {
- SourceUtils sourceUtils = getContext().getWorker(SourceUtils.class);
+ SourceUtils sourceUtils = getSourceUtils();
Set<BeanProperty> properties =
sourceUtils.getBeanPropertiesAnnotatedWith(Facet.class, componentElement);
// TODO - encapsulate attribute builder into utility class.
@@ -176,7 +173,7 @@
component.setFamily(family.value());
} else {
// static final COMPONENT_FAMILY string constant.
- Object value =
getContext().getWorker(SourceUtils.class).getConstant(componentElement,
"COMPONENT_FAMILY");
+ Object value = getSourceUtils().getConstant(componentElement,
"COMPONENT_FAMILY");
if (null != value) {
component.setFamily(value.toString());
}
@@ -240,7 +237,7 @@
}
}
- SourceUtils sourceUtils = getContext().getWorker(SourceUtils.class);
+ SourceUtils sourceUtils = getSourceUtils();
sourceUtils.visitSupertypes(componentElement.asType(), new SuperTypeVisitor() {
@Override
@@ -342,10 +339,6 @@
}
- private Map<String, Property> parseProperties(String attributesConfig) {
- return
getContext().getWorker(FragmentParser.class).parseProperties(CdkEntityResolver.URN_ATTRIBUTES
+attributesConfig+".xml");
- }
-
private void setBehaviorEvent(Property attribute, EventName eventName) {
if (null != eventName) {
org.richfaces.cdk.model.EventName event = new
org.richfaces.cdk.model.EventName();
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -1,20 +1,60 @@
package org.richfaces.cdk.apt;
+import java.util.Map;
+
+import javax.inject.Inject;
import javax.lang.model.element.TypeElement;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkWorker;
+import org.richfaces.cdk.NamingConventions;
import org.richfaces.cdk.annotations.DisplayName;
import org.richfaces.cdk.annotations.Icon;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.DescriptionGroup;
+import org.richfaces.cdk.model.Property;
+import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
+import org.richfaces.cdk.xmlconfig.FragmentParser;
-public class ProcessorBase implements CdkWorker {
+public class ProcessorBase {
- private CdkContext context;
+ @Inject
+ private ComponentLibrary library;
+
+ @Inject
+ private SourceUtils sourceUtils;
+
+ @Inject
+ private NamingConventions namingConventions;
+
+ @Inject
+ private FragmentParser fragmentParser;
+
/**
* <p class="changed_added_4_0"></p>
+ * @return the fragmentParser
+ */
+ public FragmentParser getFragmentParser() {
+ return this.fragmentParser;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the sourceUtils
+ */
+ public SourceUtils getSourceUtils() {
+ return this.sourceUtils;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the namingConventions
+ */
+ public NamingConventions getNamingConventions() {
+ return this.namingConventions;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
* @param component
* @param icon
*/
@@ -33,25 +73,13 @@
}
public ComponentLibrary getLibrary() {
- return getContext().getLibrary();
+ return library;
}
- @Override
- public void init(CdkContext context) {
- this.context=context;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the context
- */
- protected CdkContext getContext() {
- return context;
- }
protected void setDescription(TypeElement element, DescriptionGroup component) {
- SourceUtils sourceUtils = getContext().getWorker(SourceUtils.class);
// JavaDoc comments
component.setDescription(sourceUtils.getDocComment(element));
@@ -68,4 +96,8 @@
}
}
+ protected Map<String, Property> parseProperties(String attributesConfig) {
+ return getFragmentParser().parseProperties(CdkEntityResolver.URN_ATTRIBUTES
+attributesConfig+".xml");
+ }
+
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/RendererProcessor.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -22,13 +22,11 @@
package org.richfaces.cdk.apt;
import java.lang.annotation.Annotation;
-import java.util.Map;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.NamingConventions;
import org.richfaces.cdk.annotations.Component;
import org.richfaces.cdk.annotations.DisplayName;
import org.richfaces.cdk.annotations.EventName;
@@ -38,8 +36,6 @@
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.model.RendererModel;
-import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
-import org.richfaces.cdk.xmlconfig.FragmentParser;
/**
* @author akolonitsky
@@ -73,11 +69,6 @@
return componentElement.getAnnotation(Component.class).value();
}
- private NamingConventions getNamingConventions() {
- return getContext().getWorker(NamingConventions.class);
- }
-
-
private void setRendererProperties(TypeElement componentElement, RendererModel
renderer)
throws CdkException {
@@ -96,7 +87,7 @@
private void setRendererDescription(TypeElement componentElement, RendererModel
component) {
- SourceUtils sourceUtils = getContext().getWorker(SourceUtils.class);
+ SourceUtils sourceUtils = getSourceUtils();
// JavaDoc comments
component.setDescription(sourceUtils.getDocComment(componentElement));
@@ -122,7 +113,7 @@
renderer.setFamily(family.value());
} else {
// static final COMPONENT_FAMILY string constant.
- Object value =
getContext().getWorker(SourceUtils.class).getConstant(rendererElement,
"COMPONENT_FAMILY");
+ Object value = getSourceUtils().getConstant(rendererElement,
"COMPONENT_FAMILY");
if (null != value) {
renderer.setFamily(value.toString());
}
@@ -170,10 +161,6 @@
// }
// }
- private Map<String, Property> parseProperties(String attributesConfig) {
- return
getContext().getWorker(FragmentParser.class).parseProperties(CdkEntityResolver.URN_ATTRIBUTES
+attributesConfig+".xml");
- }
-
private void setBehaviorEvent(Property attribute, EventName eventName) {
if (null != eventName) {
org.richfaces.cdk.model.EventName event = new
org.richfaces.cdk.model.EventName();
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/apt/SourceUtils.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -39,8 +39,6 @@
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkWorker;
import org.richfaces.cdk.model.InvalidNameException;
import org.richfaces.cdk.util.PropertyUtils;
@@ -52,7 +50,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class SourceUtils implements CdkWorker {
+public class SourceUtils {
@@ -66,22 +64,22 @@
}
- private CdkContext context;
- private final ProcessingEnvironment processingEnv;
- private final RoundEnvironment roundEnvironment;
+ private ProcessingEnvironment processingEnv;
+ private RoundEnvironment roundEnvironment;
- public SourceUtils(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv) {
+ public void setup(ProcessingEnvironment processingEnv, RoundEnvironment roundEnv) {
this.processingEnv = processingEnv;
this.roundEnvironment = roundEnv;
}
+ public void release() {
+ this.processingEnv = null;
+ this.roundEnvironment = null;
+ }
+
/* (non-Javadoc)
* @see org.richfaces.cdk.CdkWorker#init(org.richfaces.cdk.CdkContext)
*/
- @Override
- public void init(CdkContext context) {
- this.context = context;
- }
/**
* <p class="changed_added_4_0">
* Get all classes annotated with particular annotation.
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -23,10 +23,12 @@
package org.richfaces.cdk.freemarker;
-import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
+import javax.inject.Inject;
+
+import org.richfaces.cdk.Logger;
+
import freemarker.template.Configuration;
-import org.richfaces.cdk.CdkContext;
+import freemarker.template.ObjectWrapper;
/**
* <p class="changed_added_4_0"></p>
@@ -34,21 +36,22 @@
* @author asmirnov(a)exadel.com
*/
public class CdkConfiguration extends Configuration {
+
private static final String TEMPLATES = "/META-INF/templates";
- private final CdkContext context;
+ private final Logger log;
- public CdkConfiguration(CdkContext context) {
+ @Inject
+ public CdkConfiguration(ObjectWrapper wrapper,Logger log) {
super();
- this.context = context;
+ this.log = log;
// TODO set proper template loader.
- setClassForTemplateLoading(context.getClass(), TEMPLATES);
+ setClassForTemplateLoading(this.getClass(), TEMPLATES);
- // TODO create an object wrapper for library model.
- setObjectWrapper(new LibraryModelWrapper());
+ setObjectWrapper(wrapper);
// Add context variables
- this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
+// this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
}
/**
@@ -56,7 +59,4 @@
*
* @return the context
*/
- protected CdkContext getContext() {
- return context;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMakerModule.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMakerModule.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMakerModule.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -25,6 +25,9 @@
import com.google.inject.AbstractModule;
+import freemarker.template.Configuration;
+import freemarker.template.ObjectWrapper;
+
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -37,8 +40,8 @@
*/
@Override
protected void configure() {
- // TODO Auto-generated method stub
-
+ bind(Configuration.class).to(CdkConfiguration.class);
+ bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -25,21 +25,27 @@
package org.richfaces.cdk.freemarker;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-import org.richfaces.cdk.CdkContext;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
import org.richfaces.cdk.OutputType;
+import org.richfaces.cdk.StandardOutputFolders;
+import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.LibraryVisitor;
import org.richfaces.cdk.model.Trackable;
import org.richfaces.cdk.model.Visitable;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
/**
* <p class="changed_added_4_0">Base class for all output file buildes
that use FreeMarker as template engine.</p>
@@ -47,15 +53,21 @@
*
*/
public abstract class FreeMarkerRenderer<C extends Visitable, P> implements
CdkWriter, LibraryVisitor<Boolean, P> {
- private Configuration configuration;
- private CdkContext context;
- private Template template;
- @Override
- public void init(CdkContext context) {
- this.context = context;
- this.configuration = new CdkConfiguration(context);
+ private final Configuration configuration;
+ private final Template template;
+
+ private final ComponentLibrary library;
+
+ private final FileManager output;
+
+ @Inject
+ public FreeMarkerRenderer(Configuration configuration,ComponentLibrary library,
FileManager output) {
+ this.configuration = configuration;
+ this.library = library;
+ this.output = output;
+
try {
template = configuration.getTemplate(getTemplateName());
} catch (IOException e) {
@@ -65,7 +77,7 @@
@Override
public void render() throws CdkException {
- context.getLibrary().accept(this, getVisitorParameter());
+ library.accept(this, getVisitorParameter());
}
private P getVisitorParameter() {
@@ -109,9 +121,8 @@
lastModified = trackuble.lastModified();
}
- File sourceOutput = getContext().createOutputFile(getOutputType(),
getOutputFile(c), lastModified);
-
try {
+ File sourceOutput = output.createFile(getOutputFile(c), lastModified);
return new FileWriter(sourceOutput);
} catch (IOException e) {
throw new CdkException(e);
@@ -123,14 +134,4 @@
protected abstract boolean isMyComponent(Visitable c);
protected abstract String getTemplateName();
-
- protected abstract OutputType getOutputType();
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the context
- */
- protected CdkContext getContext() {
- return context;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -37,6 +37,7 @@
*
*/
public class LibraryModelWrapper extends BeansWrapper implements ObjectWrapper {
+
public LibraryModelWrapper() {
super();
setStrict(true);
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -22,14 +22,21 @@
package org.richfaces.cdk.freemarker;
+import java.io.File;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
import org.richfaces.cdk.OutputType;
+import org.richfaces.cdk.StandardOutputFolders;
import org.richfaces.cdk.StandardOutputs;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ValidatorModel;
import org.richfaces.cdk.model.Visitable;
-import java.io.File;
+import freemarker.template.Configuration;
/**
* @author akolonitsky
@@ -37,6 +44,11 @@
*/
public class ValidatorTaglibGenerator extends FreeMarkerRenderer<ValidatorModel,
ComponentLibrary>{
+ @Inject
+ public ValidatorTaglibGenerator(Configuration configuration, ComponentLibrary
library, @OutputFolder(StandardOutputFolders.RESOURCES)FileManager output) {
+ super(configuration, library, output);
+ }
+
@Override
protected String getOutputFile(ValidatorModel validatorModel) throws CdkException {
return validatorModel.getValidatorClass().getName().replace('.',
File.separatorChar) + "-taglib.xml";
@@ -51,9 +63,4 @@
protected String getTemplateName() {
return "taglib/validator.ftl";
}
-
- @Override
- protected OutputType getOutputType() {
- return StandardOutputs.TAG_LIBRARY;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -22,17 +22,21 @@
package org.richfaces.cdk.generate.java;
+import java.io.File;
+
+import javax.inject.Inject;
+
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
+import org.richfaces.cdk.StandardOutputFolders;
+import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.Visitable;
-import org.richfaces.cdk.model.BehaviorModel;
-import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
-import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.OutputType;
-import org.richfaces.cdk.StandardOutputs;
-import java.io.File;
+import freemarker.template.Configuration;
/**
* @author akolonitsky
@@ -44,9 +48,9 @@
* (non-Javadoc)
* @see org.richfaces.cdk.CdkWriter#init(org.richfaces.cdk.CdkContext)
*/
- @Override
- public void init(CdkContext context) {
- super.init(context);
+ @Inject
+ public BehaviorClassGenerator(Configuration configuration, ComponentLibrary library,
@OutputFolder(StandardOutputFolders.JAVA_CLASSES) FileManager output) {
+ super(configuration, library, output);
}
@Override
@@ -68,8 +72,4 @@
return "behavior.ftl";
}
- @Override
- protected OutputType getOutputType() {
- return StandardOutputs.BEHAVIOR_CLASSES;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -25,17 +25,21 @@
package org.richfaces.cdk.generate.java;
-import org.richfaces.cdk.CdkContext;
+import java.io.File;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.OutputType;
-import org.richfaces.cdk.StandardOutputs;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
+import org.richfaces.cdk.StandardOutputFolders;
import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
-import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.Visitable;
-import java.io.File;
+import freemarker.template.Configuration;
/**
* <p class="changed_added_4_0"></p>
@@ -48,9 +52,9 @@
* (non-Javadoc)
* @see org.richfaces.cdk.CdkWriter#init(org.richfaces.cdk.CdkContext)
*/
- @Override
- public void init(CdkContext context) {
- super.init(context);
+ @Inject
+ public ComponentClassGenerator(Configuration configuration, ComponentLibrary library,
@OutputFolder(StandardOutputFolders.JAVA_CLASSES) FileManager output) {
+ super(configuration, library, output);
}
@Override
@@ -71,9 +75,4 @@
protected String getTemplateName() {
return "component.ftl";
}
-
- @Override
- protected OutputType getOutputType() {
- return StandardOutputs.COMPONENT_CLASSES;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -22,28 +22,33 @@
package org.richfaces.cdk.generate.java;
-import org.richfaces.cdk.CdkContext;
+import java.io.File;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.OutputType;
-import org.richfaces.cdk.StandardOutputs;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
+import org.richfaces.cdk.StandardOutputFolders;
import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
import org.richfaces.cdk.model.Visitable;
-import java.io.File;
+import freemarker.template.Configuration;
/**
* @author akolonitsky
* @since Jan 20, 2010
*/
public class ConverterClassGenerator extends FreeMarkerRenderer<ConverterModel,
ComponentLibrary> implements CdkWriter {
- @Override
- public void init(CdkContext context) {
- super.init(context);
- }
+ @Inject
+ public ConverterClassGenerator(Configuration configuration, ComponentLibrary library,
@OutputFolder(StandardOutputFolders.JAVA_CLASSES) FileManager output) {
+ super(configuration, library, output);
+ }
+
@Override
protected boolean isMyComponent(Visitable visitable) {
if (visitable instanceof ConverterModel) {
@@ -62,9 +67,4 @@
protected String getTemplateName() {
return "converter.ftl";
}
-
- @Override
- protected OutputType getOutputType() {
- return StandardOutputs.CONVERTER_CLASSES;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -22,26 +22,33 @@
package org.richfaces.cdk.generate.java;
-import org.richfaces.cdk.CdkContext;
+import java.io.File;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
import org.richfaces.cdk.OutputType;
+import org.richfaces.cdk.StandardOutputFolders;
import org.richfaces.cdk.StandardOutputs;
import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ValidatorModel;
import org.richfaces.cdk.model.Visitable;
-import java.io.File;
+import freemarker.template.Configuration;
/**
* @author akolonitsky
* @since Jan 15, 2010
*/
public class ValidatorClassGenerator extends FreeMarkerRenderer<ValidatorModel,
ComponentLibrary> implements CdkWriter {
- @Override
- public void init(CdkContext context) {
- super.init(context);
+
+ @Inject
+ public ValidatorClassGenerator(Configuration configuration, ComponentLibrary library,
@OutputFolder(StandardOutputFolders.JAVA_CLASSES) FileManager output) {
+ super(configuration, library, output);
}
@Override
@@ -62,9 +69,4 @@
protected String getTemplateName() {
return "validator.ftl";
}
-
- @Override
- protected OutputType getOutputType() {
- return StandardOutputs.VALIDATOR_CLASSES;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -38,6 +38,7 @@
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
import javax.faces.render.Renderer;
+import javax.inject.Inject;
import javax.xml.namespace.QName;
import org.richfaces.builder.model.Argument;
@@ -49,7 +50,6 @@
import org.richfaces.builder.model.MethodBodyStatementsContainer;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
-import org.richfaces.cdk.LoggerFactory;
import org.richfaces.cdk.attributes.Attribute;
import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/CdkEntityResolver.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -23,14 +23,6 @@
package org.richfaces.cdk.xmlconfig;
-import com.google.common.collect.ImmutableMap;
-import org.richfaces.cdk.CdkContext;
-import org.richfaces.cdk.SourceType;
-import org.richfaces.cdk.StandardSources;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.EntityResolver2;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@@ -38,6 +30,18 @@
import java.io.InputStream;
import java.net.URI;
+import javax.inject.Inject;
+
+import org.richfaces.cdk.CdkClassLoader;
+import org.richfaces.cdk.Source;
+import org.richfaces.cdk.SourceType;
+import org.richfaces.cdk.StandardSources;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.EntityResolver2;
+
+import com.google.common.collect.ImmutableMap;
+
/**
* <p class="changed_added_4_0">
* That class resolves entities used by CDK ( standard JSF schemas, extensions,
@@ -87,11 +91,13 @@
"http://richfaces.org/cdk/xhtml-el.xsd",
URN_SYSTEM + "/xhtml-el.xsd").build();
- private final CdkContext context;
- public CdkEntityResolver(CdkContext context) {
- this.context = context;
- }
+ @Inject
+ private CdkClassLoader loader;
+ @Inject @Source(StandardSources.FACES_CONFIG_FOLDERS)
+ private Iterable<File> facesConfigFolders;
+ @Inject @Source(StandardSources.TEMPLATE_FOLDERS)
+ private Iterable<File> rendererTemplatesFolders;
/*
* (non-Javadoc)
@@ -178,7 +184,7 @@
// Project resources
String path = systemIdInternal.substring(URN_RESOURCE.length());
- InputStream inputStream =
getContext().getLoader().getResourceAsStream(RESOURCE_PREFIX + path);
+ InputStream inputStream = loader.getResourceAsStream(RESOURCE_PREFIX +
path);
if (null != inputStream) {
entity = new InputSource(inputStream);
@@ -189,7 +195,7 @@
// project classloader.
String path = systemIdInternal.substring(URN_ATTRIBUTES.length());
// Project classpath has precedence
- InputStream inputStream =
getContext().getLoader().getResourceAsStream(ATTRIBUTES_PREFIX + path);
+ InputStream inputStream = loader.getResourceAsStream(ATTRIBUTES_PREFIX +
path);
if (null == inputStream) {
inputStream =
getClass().getClassLoader().getResourceAsStream(ATTRIBUTES_PREFIX + path);
}
@@ -201,13 +207,13 @@
// Config folder.
String path = systemIdInternal.substring(URN_CONFIG.length());
- entity = getProjectInputSource(StandardSources.FACES_CONFIGS, path);
+ entity = getProjectInputSource(facesConfigFolders, path);
} else if (systemIdInternal.startsWith(URN_TEMPLATES)) {
// Templates folder.
String path = systemIdInternal.substring(URN_TEMPLATES.length());
- entity = getProjectInputSource(StandardSources.RENDERER_TEMPLATES, path);
+ entity = getProjectInputSource(rendererTemplatesFolders, path);
}
if (null != entity) {
@@ -217,8 +223,8 @@
return entity;
}
- protected InputSource getProjectInputSource(SourceType type, String path) throws
FileNotFoundException {
- Iterable<File> folders = getContext().getSourceFolders(type);
+ protected InputSource getProjectInputSource(Iterable<File> folders, String
path) throws FileNotFoundException {
+
InputSource entity = null;
for (File folder : folders) {
@@ -238,13 +244,4 @@
return entity;
}
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the context
- */
- public CdkContext getContext() {
- return context;
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -27,9 +27,13 @@
import java.io.File;
-import org.richfaces.cdk.CdkContext;
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.OutputFolder;
+import org.richfaces.cdk.StandardOutputFolders;
import org.richfaces.cdk.StandardOutputs;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.xmlconfig.model.FacesConfigAdapter;
@@ -47,19 +51,16 @@
+ ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION;
private static final String FACES_CONFIG_XML =
"META-INF/faces-config.xml";
- private CdkContext context;
- private JAXBBinding jaxbBinding;
+ @Inject
+ private JAXB jaxbBinding;
+ @Inject
+ private ComponentLibrary library;
+ @Inject @OutputFolder(StandardOutputFolders.RESOURCES)
+ private FileManager outputFileManager;
+
private FacesConfigAdapter libraryAdapter;
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.cdk.CdkWriter#init(org.richfaces.cdk.CdkContext)
- */
- @Override
- public void init(CdkContext context) {
- this.context = context;
- jaxbBinding = context.getWorker(JAXBBinding.class);
+ public FacesConfigGenerator() {
libraryAdapter = new FacesConfigAdapter();
}
@@ -73,24 +74,19 @@
@Override
public void render() throws CdkException {
- ComponentLibrary library = context.getLibrary();
// TODO - check modification time.
- File facesConfigXml = context.createOutputFile(StandardOutputs.FACES_CONFIG,
FACES_CONFIG_XML,
- library.lastModified());
+ try {
+ File facesConfigXml = outputFileManager.createFile(FACES_CONFIG_XML,
library.lastModified());
- if (null != facesConfigXml) {
- try {
-
- // TODO - transform output to strip prefixes from faces-config
- // namespace.
+ if (null != facesConfigXml) {
jaxbBinding.marshal(facesConfigXml, FACES_SCHEMA_LOCATION,
libraryAdapter.marshal(library));
- } catch (Exception e) {
- if (e instanceof CdkException) {
- throw(CdkException) e;
- } else {
- throw new CdkException(e);
- }
}
+ } catch (Exception e) {
+ if (e instanceof CdkException) {
+ throw (CdkException) e;
+ } else {
+ throw new CdkException(e);
+ }
}
}
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -23,16 +23,18 @@
package org.richfaces.cdk.xmlconfig;
-import org.richfaces.cdk.CdkContext;
+import java.io.File;
+
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.ModelBuilder;
+import org.richfaces.cdk.Source;
import org.richfaces.cdk.StandardSources;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.xmlconfig.model.FacesConfigAdapter;
import org.richfaces.cdk.xmlconfig.model.FacesConfigBean;
-import java.io.File;
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -44,18 +46,13 @@
private static final FacesConfigAdapter ADAPTER = new FacesConfigAdapter();
- private CdkContext context;
- private JAXBBinding jaxbBinding;
+ @Inject
+ private JAXB jaxbBinding;
+ @Inject
+ private ComponentLibrary library;
+ @Inject @Source(StandardSources.FACES_CONFIGS)
+ private Iterable<File> configFiles;
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @return the context
- */
- public CdkContext getContext() {
- return context;
- }
/*
* (non-Javadoc)
@@ -64,11 +61,9 @@
*/
@Override
public void build() throws CdkException {
- ComponentLibrary library = context.getLibrary();
-
- Iterable<File> sources =
context.getSources(StandardSources.FACES_CONFIGS);
- if (null != sources) {
- for (File file : sources) {
+
+ if (null != configFiles) {
+ for (File file : configFiles) {
FacesConfigBean unmarshal = unmarshalFacesConfig(file);
if (null != unmarshal) {
ComponentLibrary facesConfig = ADAPTER.unmarshal(unmarshal);
@@ -90,15 +85,4 @@
protected FacesConfigBean unmarshalFacesConfig(File file) throws CdkException {
return jaxbBinding.unmarshal(file, ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION,
FacesConfigBean.class);
}
-
- /*
- * (non-Javadoc)
- *
- * @see org.richfaces.cdk.ModelBuilder#init(org.richfaces.cdk.CdkContext)
- */
- @Override
- public void init(CdkContext context) {
- this.context = context;
- jaxbBinding = context.getWorker(JAXBBinding.class);
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -21,73 +21,56 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.xmlconfig;
import java.util.Collections;
import java.util.Map;
-import org.richfaces.cdk.CdkContext;
+import javax.inject.Inject;
+
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkWorker;
-import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.xmlconfig.model.ComponentAdapter;
import org.richfaces.cdk.xmlconfig.model.Fragment;
/**
* <p class="changed_added_4_0">
- * That class parses xml document with fragment of faces-config ( eg, standard
- * component attributes )
+ * That class parses xml document with fragment of faces-config ( eg, standard component
attributes )
* </p>
- *
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
-public class FragmentParser implements CdkWorker {
- private CdkContext context;
+public class FragmentParser {
+
private ComponentAdapter adapter;
+ private final JAXB binding;
- public FragmentParser() {}
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param context
- */
- public void init(CdkContext context) {
+ @Inject
+ public FragmentParser(JAXB binding) {
+ this.binding = binding;
this.adapter = new ComponentAdapter();
- this.context = context;
}
/**
* <p class="changed_added_4_0">
* Parses faces-config.xml fragment with component/renderer properties.
* </p>
- *
+ *
* @param url
* @return
*/
public Map<String, Property> parseProperties(String url) throws CdkException {
String schemaLocation = ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION;
Class<Fragment> bindClass = Fragment.class;
- Fragment unmarshal = getBinding().unmarshal(url, schemaLocation, bindClass);
- if(null != unmarshal ){
+ Fragment unmarshal = binding.unmarshal(url, schemaLocation, bindClass);
+ if (null != unmarshal) {
ComponentModel component = adapter.unmarshal(unmarshal);
return component.getAttributes();
} else {
- return Collections.<String, Property>emptyMap();
+ return Collections.<String, Property> emptyMap();
}
}
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the binding
- */
- protected JAXBBinding getBinding() {
- return context.getWorker(JAXBBinding.class);
- }
}
Modified:
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
===================================================================
---
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-01-28
22:28:32 UTC (rev 16379)
+++
root/cdk/branches/guice/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-01-29
01:31:27 UTC (rev 16380)
@@ -39,6 +39,7 @@
import java.net.URISyntaxException;
import java.util.Collection;
+import javax.inject.Inject;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
@@ -51,14 +52,13 @@
import javax.xml.transform.stream.StreamResult;
import org.apache.cocoon.pipeline.component.sax.XIncludeTransformer;
-import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkWorker;
import org.richfaces.cdk.model.ConfigExtension;
import org.richfaces.cdk.model.Extensible;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+import org.xml.sax.ext.EntityResolver2;
import org.xml.sax.helpers.XMLReaderFactory;
import com.google.common.collect.ImmutableSet;
@@ -70,12 +70,12 @@
* @author asmirnov(a)exadel.com
*
*/
-public class JAXBBinding implements CdkWorker, JAXB {
+public class JAXBBinding implements JAXB {
private static final FacesConfigNamespacePreffixMapper PREFFIX_MAPPER = new
FacesConfigNamespacePreffixMapper();
private static final ImmutableSet<String> IGNORE_PROPERTIES =
ImmutableSet.of("class", "extension");
- private CdkContext context;
- private CdkEntityResolver resolver;
+ @Inject
+ private EntityResolver2 resolver;
public JAXBBinding() { }
@@ -85,10 +85,6 @@
*
* @param context
*/
- public void init(CdkContext context) {
- this.context = context;
- this.resolver = new CdkEntityResolver(context);
- }
/* (non-Javadoc)
* @see org.richfaces.cdk.xmlconfig.JAXB#unmarshal(java.io.File, java.lang.String,
java.lang.Class)
@@ -112,7 +108,12 @@
*/
public <T> T unmarshal(String url, String schemaLocation, Class<T>
bindClass) throws CdkException {
try {
- InputSource inputSource = resolver.resolveSystemId(url);
+ InputSource inputSource;
+ try {
+ inputSource = resolver.resolveEntity(null, url);
+ } catch (SAXException e) {
+ inputSource = null;
+ }
if (null == inputSource) {
inputSource = new InputSource(url);
@@ -121,7 +122,7 @@
T unmarshal = unmarshal(schemaLocation, bindClass, inputSource);
return unmarshal;
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
throw new CdkException("XML file not found", e);
}
}