[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/importers/metamodel ...
Christian Bauer
christian at hibernate.org
Mon Aug 27 18:22:29 EDT 2007
User: cbauer
Date: 07/08/27 18:22:29
Added: examples/wiki/src/main/org/jboss/seam/wiki/core/importers/metamodel
Importer.java AbstractImporter.java
ImporterRegistry.java
Log:
New file importer infrastructure plus first Zip/Jar file importer
Revision Changes Path
1.1 date: 2007/08/27 22:22:29; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/importers/metamodel/Importer.java
Index: Importer.java
===================================================================
package org.jboss.seam.wiki.core.importers.metamodel;
import org.jboss.seam.wiki.core.importers.annotations.FileImporter;
import org.jboss.seam.annotations.Name;
public class Importer implements Comparable {
private Class clazz;
private String componentName;
private String[] handledMimeTypes;
private String[] handledExtensions;
private String description;
public Importer(Class<?> clazz) {
this.clazz = clazz;
this.componentName = clazz.getAnnotation(Name.class).value();
this.handledMimeTypes = clazz.getAnnotation(FileImporter.class).handledMimeTypes();
this.handledExtensions = clazz.getAnnotation(FileImporter.class).handledExtensions();
this.description = clazz.getAnnotation(FileImporter.class).description();
}
public Class getClazz() {
return clazz;
}
public String getComponentName() {
return componentName;
}
public String[] getHandledMimeTypes() {
return handledMimeTypes;
}
public String[] getHandledExtensions() {
return handledExtensions;
}
public String getDescription() {
return description;
}
public String toString() {
return "importer class: " + getClazz().getName() + " mime type: " + getHandledMimeTypes() + " extension: " + getHandledExtensions();
}
public int compareTo(Object o) {
Importer other = (Importer)o;
return this.getDescription().compareTo(other.getDescription());
}
}
1.1 date: 2007/08/27 22:22:29; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/importers/metamodel/AbstractImporter.java
Index: AbstractImporter.java
===================================================================
package org.jboss.seam.wiki.core.importers.metamodel;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.ScopeType;
import org.jboss.seam.faces.FacesMessages;
import org.jboss.seam.wiki.core.model.File;
import javax.persistence.EntityManager;
import java.util.Set;
@Scope(ScopeType.APPLICATION)
public abstract class AbstractImporter {
@Observer("Importers.addImporter")
public void add(Set<AbstractImporter> importerComponents) {
importerComponents.add(this);
}
protected FacesMessages getFacesMessages() {
return FacesMessages.instance();
}
public abstract boolean handleImport(EntityManager em, File file);
}
1.1 date: 2007/08/27 22:22:29; author: cbauer; state: Exp;jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/importers/metamodel/ImporterRegistry.java
Index: ImporterRegistry.java
===================================================================
package org.jboss.seam.wiki.core.importers.metamodel;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.ScopeType;
import org.jboss.seam.wiki.core.importers.annotations.FileImporter;
import org.jboss.seam.core.Events;
import org.jboss.seam.log.Log;
import java.util.*;
@Name("importerRegistry")
@Scope(ScopeType.APPLICATION)
public class ImporterRegistry {
@Logger
static Log log;
Map<String, Importer> importersByName = new HashMap<String, Importer>();
List<Importer> importers = new ArrayList<Importer>();
@Observer("Wiki.started")
public void scanForFileImporters() {
log.debug("initializing file importer registry");
importers.clear();
importersByName.clear();
// Fire an event and let all listeners add themself into the given collection
Set<AbstractImporter> importerComponents = new HashSet<AbstractImporter>();
Events.instance().raiseEvent("Importers.addImporter", importerComponents);
log.debug("found file importer components: " + importerComponents.size());
for (AbstractImporter importerComponent : importerComponents) {
if (importerComponent.getClass().isAnnotationPresent(FileImporter.class)) {
Importer importer = new Importer(importerComponent.getClass());
importers.add(importer);
importersByName.put(importer.getComponentName(), importer);
}
}
log.debug("added file importers to registry: " + importers.size());
// Sort entities
Collections.sort(importers);
if (log.isTraceEnabled()) {
for (Importer importer : importers) {
log.trace(importer);
}
}
}
public Map<String, Importer> getImportersByName() {
return importersByName;
}
public List<Importer> getImporters() {
return importers;
}
}
More information about the jboss-cvs-commits
mailing list