Skip to content

Commit

Permalink
Apply targetDir with var
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Mar 20, 2012
2 parents a514ae6 + fe5cc50 commit 7d00465
Show file tree
Hide file tree
Showing 17 changed files with 1,508 additions and 890 deletions.
1,612 changes: 787 additions & 825 deletions scaffold-faces/src/main/java/org/jboss/forge/scaffold/faces/FacesScaffold.java

Large diffs are not rendered by default.

Expand Up @@ -23,6 +23,7 @@

import org.jboss.forge.env.Configuration;
import org.jboss.forge.project.Project;
import org.jboss.forge.scaffold.faces.util.AnnotationLookup;
import org.metawidget.config.impl.BaseConfigReader;

/**
Expand All @@ -42,12 +43,15 @@ public class ForgeConfigReader

private static final String PROJECT_ELEMENT_NAME = "forgeProject";

private static final String ANNOTATION_LOOKUP = "annotationLookup";

//
// Private members
//

private Configuration config;
private Project project;
private AnnotationLookup annotationLookup;

//
// Constructor
Expand All @@ -57,6 +61,7 @@ public ForgeConfigReader(Configuration config, Project project)
{
this.config = config;
this.project = project;
this.annotationLookup = new AnnotationLookup(project);
}

//
Expand All @@ -66,7 +71,7 @@ public ForgeConfigReader(Configuration config, Project project)
@Override
protected boolean isNative(String name)
{
if (PROJECT_ELEMENT_NAME.equals(name))
if (PROJECT_ELEMENT_NAME.equals(name) || ANNOTATION_LOOKUP.equals(name))
{
return true;
}
Expand All @@ -86,6 +91,9 @@ protected Object createNative(String name, Class<?> namespace, String recordedTe
{
return this.project;
}
if (ANNOTATION_LOOKUP.equals(name)) {
return this.annotationLookup;
}

if(CONFIG_ELEMENT_NAME.equals(name))
{
Expand All @@ -94,4 +102,5 @@ protected Object createNative(String name, Class<?> namespace, String recordedTe

return super.createNative(name, namespace, recordedText);
}

}
Expand Up @@ -37,6 +37,16 @@ public final class ForgeInspectionResultConstants

public static final String ONE_TO_ONE = "one-to-one";

public static final String PRIMARY_KEY = "primary-key";

public static final String PRIMARY_KEY_NOT_GENERATED = "primary-key-not-generated";

public static final String ENTITY_PRIMARY_KEY = "entity-primary-key";

public static final String REVERSE_PRIMARY_KEY = "reverse-primary-key";

public static final String REVERSE_PRIMARY_KEY_TYPE = "reverse-primary-key-type";

//
// Private constructor
//
Expand Down
Expand Up @@ -21,22 +21,20 @@
*/
package org.jboss.forge.scaffold.faces.metawidget.inspector;

import org.jboss.forge.scaffold.faces.util.AnnotationLookup;
import static org.jboss.forge.scaffold.faces.metawidget.inspector.ForgeInspectionResultConstants.*;
import static org.metawidget.inspector.InspectionResultConstants.*;
import static org.metawidget.inspector.faces.StaticFacesInspectionResultConstants.*;

import java.util.List;
import java.util.Map;

import javax.persistence.Embedded;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.*;

import org.jboss.forge.parser.java.EnumConstant;
import org.jboss.forge.parser.java.JavaEnum;
import org.jboss.forge.scaffold.faces.metawidget.inspector.propertystyle.ForgePropertyStyle.ForgeProperty;
import org.jboss.solder.logging.Logger;
import org.metawidget.inspector.impl.BaseObjectInspector;
import org.metawidget.inspector.impl.BaseObjectInspectorConfig;
import org.metawidget.inspector.impl.propertystyle.Property;
Expand All @@ -50,83 +48,128 @@
*
* @author Richard Kennard
*/

public class ForgeInspector
extends BaseObjectInspector
{
extends BaseObjectInspector {

ForgeInspectorConfig config;
Logger log = Logger.getLogger(getClass());

//
// Constructor
//

public ForgeInspector()
{
this(new BaseObjectInspectorConfig());
public ForgeInspector() {
super(new BaseObjectInspectorConfig());
}

public ForgeInspector(BaseObjectInspectorConfig config)
{
public ForgeInspector(ForgeInspectorConfig config) {
super(config);
this.config = config;
}

//
// Protected methods
//

@Override
protected Map<String, String> inspectProperty(Property property)
throws Exception
{
throws Exception {
Map<String, String> attributes = CollectionUtils.newHashMap();

// OneToOne

if (property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(Embedded.class))
{
if (property.isAnnotationPresent(OneToOne.class) || property.isAnnotationPresent(Embedded.class)) {

attributes.put(ONE_TO_ONE, TRUE);
}

// ManyToOne

if (property.isAnnotationPresent(ManyToOne.class))
{
attributes
.put(FACES_LOOKUP,
StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property
.getType())) + "Bean.all"));

attributes
.put(FACES_CONVERTER_ID,
StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property
.getType())) + "Bean.converter"));
if (property.isAnnotationPresent(ManyToOne.class)) {
attributes.put(FACES_LOOKUP,
StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property.getType())) + "Bean.all"));

attributes.put(FACES_CONVERTER_ID,
StaticFacesUtils.wrapExpression(StringUtils.decapitalize(ClassUtils.getSimpleName(property.getType())) + "Bean.converter"));
}

// OneToMany and ManyToMany

if (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToMany.class))
{
if (property.isAnnotationPresent(OneToMany.class) || property.isAnnotationPresent(ManyToMany.class)) {
attributes.put(N_TO_MANY, TRUE);
}

// Enums

if ( property instanceof ForgeProperty ) {
if (property instanceof ForgeProperty) {

List<EnumConstant<JavaEnum>> enumConstants = ((ForgeProperty) property).getEnumConstants();

if (enumConstants != null)
{
if (enumConstants != null) {
List<String> lookup = CollectionUtils.newArrayList();

for (EnumConstant<JavaEnum> anEnum : enumConstants)
{
for (EnumConstant<JavaEnum> anEnum : enumConstants) {
lookup.add(anEnum.getName());
}

attributes.put(LOOKUP, CollectionUtils.toString(lookup));
}
}

// do @Id specific handling
if (null != property.getAnnotation(Id.class)) {
attributes.put(PRIMARY_KEY, property.getName());

if (null != property.getAnnotation(GeneratedValue.class)) {
attributes.put(PRIMARY_KEY_NOT_GENERATED, FALSE);
} else {
attributes.put(PRIMARY_KEY_NOT_GENERATED, TRUE);
}
}

if (null != property.getAnnotation(ManyToOne.class)) {
attributes.put(REVERSE_PRIMARY_KEY_TYPE, property.getType());
}

if (attributes.containsKey(PRIMARY_KEY) && !TRUE.equals(attributes.get(PRIMARY_KEY_NOT_GENERATED))) {
// if primary key is not generated it cannot be hidden in view
attributes.remove(HIDDEN);
attributes.put(REQUIRED, TRUE);
}

if (config != null && config.getAnnotationLookup() != null) {
final AnnotationLookup annotationLookup = config.getAnnotationLookup();

if (attributes.containsKey(REVERSE_PRIMARY_KEY_TYPE) && null != annotationLookup) {
try {
final String reverseKey = annotationLookup.getFieldName(Id.class, attributes.get(REVERSE_PRIMARY_KEY_TYPE));
attributes.put(REVERSE_PRIMARY_KEY, reverseKey);
} catch (Exception e) {
throw new RuntimeException("cannot resolve reverse primary key", e);
}
}
}

return attributes;
}

@Override
protected Map<String, String> inspectEntity(String declaredClass, String actualClass) throws Exception {
Map<String,String> attributes = CollectionUtils.newHashMap();
Map<String,String> superMap = super.inspectEntity(declaredClass, actualClass);
if (superMap != null)
attributes.putAll(superMap);

if (config != null && config.getAnnotationLookup() != null) {
final AnnotationLookup annotationLookup = config.getAnnotationLookup();

try {
final String primaryKey = annotationLookup.getFieldName(Id.class, declaredClass);
attributes.put(PRIMARY_KEY, primaryKey);
} catch (Exception e) {
log.debug("cannot resolve primary key for class "+declaredClass, e);
}
}
return attributes;
}


}
@@ -0,0 +1,65 @@
/*
* JBoss, Home of Professional Open Source
* Copyright 2011, Red Hat, Inc., and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software 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 software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.forge.scaffold.faces.metawidget.inspector;

import org.jboss.forge.project.Project;
import org.jboss.forge.scaffold.faces.util.AnnotationLookup;
import org.metawidget.config.iface.NeedsResourceResolver;
import org.metawidget.config.iface.ResourceResolver;
import org.metawidget.inspector.impl.BaseObjectInspectorConfig;

/**
*
* @author Thomas Frühbeck
*/
public class ForgeInspectorConfig extends BaseObjectInspectorConfig implements NeedsResourceResolver {

ResourceResolver resolver;
Project project;
AnnotationLookup annotationLookup;

@Override
public void setResourceResolver(ResourceResolver resourceResolver) {
this.resolver = resourceResolver;
}

public ResourceResolver getResolver() {
return resolver;
}

public void setProject(Project project) {
this.project = project;
}

public Project getProject() {
return project;
}

public void setAnnotationLookup(AnnotationLookup annotationLookup) {
this.annotationLookup = annotationLookup;
}

public AnnotationLookup getAnnotationLookup() {
return annotationLookup;
}

}

0 comments on commit 7d00465

Please sign in to comment.