Author: alexsmirnov
Date: 2010-07-22 19:30:41 -0400 (Thu, 22 Jul 2010)
New Revision: 18207
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/MethodSignature.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/XhtmlElSchemaProvider.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
Log:
work in progress
https://jira.jboss.org/browse/RF-8907
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/AttributesProcessorImpl.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -1,15 +1,10 @@
package org.richfaces.cdk.apt.processors;
+import java.io.FileNotFoundException;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
import java.util.Set;
-import javax.lang.model.element.AnnotationMirror;
-import javax.lang.model.element.AnnotationValue;
-import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.MirroredTypeException;
import javax.lang.model.type.MirroredTypesException;
@@ -25,6 +20,7 @@
import org.richfaces.cdk.apt.SourceUtils.SuperTypeVisitor;
import org.richfaces.cdk.model.BeanModelBase;
import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.MethodSignature;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.util.Strings;
import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
@@ -35,12 +31,19 @@
import com.google.inject.Inject;
import com.google.inject.Provider;
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
public class AttributesProcessorImpl implements AttributesProcessor {
- private static final String SIGNATURE_NONE_CLASS_NAME =
Signature.NONE.class.getName().replace('$', '.');
+ private static final ClassName SIGNATURE_NONE_CLASS_NAME =
ClassName.get(Signature.NONE.class);
private static final String STRING_NAME = String.class.getName();
-
+
@Inject
private Logger log;
@@ -51,13 +54,16 @@
private final FragmentParser parser;
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @param descriptionProcessor
* @param utilsProvider
* @param parser
*/
@Inject
- public AttributesProcessorImpl(DescriptionProcessor descriptionProcessor,
Provider<SourceUtils> utilsProvider, FragmentParser parser) {
+ public AttributesProcessorImpl(DescriptionProcessor descriptionProcessor,
Provider<SourceUtils> utilsProvider,
+ FragmentParser parser) {
this.descriptionProcessor = descriptionProcessor;
this.utilsProvider = utilsProvider;
this.parser = parser;
@@ -87,7 +93,8 @@
attribute.setReadOnly(attributeAnnotarion.readOnly());
attribute.setGenerate(attributeAnnotarion.generate() ||
!beanProperty.isExists());
- descriptionProcessor.processDescription(attribute,
attributeAnnotarion.description(), beanProperty.getDocComment());
+ descriptionProcessor.processDescription(attribute,
attributeAnnotarion.description(), beanProperty
+ .getDocComment());
setDefaultValue(attribute, attributeAnnotarion);
@@ -97,21 +104,8 @@
}
// MethodExpression call signature.
- AnnotationValue signatureMirror = null;
- List<? extends AnnotationMirror> mirrors =
beanProperty.getAnnotationMirrors();
- for (AnnotationMirror mirror : mirrors) {
- if
(Attribute.class.getName().equals(mirror.getAnnotationType().toString())) {
- for (Map.Entry<? extends ExecutableElement, ? extends
AnnotationValue> entry : mirror.getElementValues().entrySet()) {
- Name simpleName = entry.getKey().getSimpleName();
- if ("signature".equals(simpleName.toString())) {
- signatureMirror = entry.getValue();
- }
- }
+ attribute.setSignature(getSignature(attributeAnnotarion.signature()));
- }
- }
- attribute.setSignature(getSignature(attributeAnnotarion.signature(),
signatureMirror));
-
for (EventName event : attributeAnnotarion.events()) {
setBehaviorEvent(attribute, event);
}
@@ -153,7 +147,6 @@
} else if (isInstace(char.class, typeName)) {
return "Character.MIN_VALUE";
}
-
return null;
}
@@ -161,63 +154,35 @@
return byteClass.getSimpleName().equals(typeName);
}
- private List<ClassName> getSignature(Signature signature, AnnotationValue
signatureMirror) {
+ private MethodSignature getSignature(Signature signature) {
- String returnType;
+ ClassName returnType;
+
try {
- returnType = signature.returnType().getName();
+ returnType = ClassName.get(signature.returnType());
} catch (MirroredTypeException e) {
TypeMirror returnTypeMirror = e.getTypeMirror();
- returnType = returnTypeMirror.toString();
+ returnType = ClassName.get(returnTypeMirror.toString());
}
- if (signature != null && !SIGNATURE_NONE_CLASS_NAME.equals(returnType))
{
- return getSignatureParams(signature, signatureMirror);
- // signature parameters always should be replaced.
- // TODO - set method return type.
-
+ if (!SIGNATURE_NONE_CLASS_NAME.equals(returnType)) {
+ MethodSignature methodSignature = new MethodSignature();
+ methodSignature.setParameters(getSignatureParams(signature));
+ return methodSignature;
}
- return Collections.emptyList();
+ return null;
}
- private List<ClassName> getSignatureParams(Signature signature, AnnotationValue
signatureMirror) {
+ private List<ClassName> getSignatureParams(Signature signature) {
List<ClassName> parameters = Lists.newArrayList();
try {
for (Class<?> parameterType : signature.parameters()) {
- parameters.add(new ClassName(parameterType.getName()));
+ parameters.add(ClassName.get(parameterType));
}
} catch (MirroredTypeException e) {
- AnnotationValue params = signatureMirror.accept(new
EmptyAnnotationValueVisitor<AnnotationValue>() {
- @Override
- public AnnotationValue visitAnnotation(AnnotationMirror a, Object o) {
- for (Map.Entry<? extends ExecutableElement, ? extends
AnnotationValue> entry : a.getElementValues().entrySet()) {
- if
("parameters".equals(entry.getKey().getSimpleName().toString())) {
- return entry.getValue();
- }
- }
- return null;
- }
- }, null);
-
- List<? extends AnnotationValue> o = params.accept(new
EmptyAnnotationValueVisitor<List<? extends AnnotationValue>>(){
- @Override
- public List<? extends AnnotationValue> visitArray(List<? extends
AnnotationValue> vals, Object o) {
- return vals;
- }
- }, null);
-
- for (AnnotationValue annotationValue : o) {
- parameters.add(annotationValue.accept(new
EmptyAnnotationValueVisitor<ClassName>() {
- @Override
- public ClassName visitType(TypeMirror t, Object o) {
- return new ClassName(t.toString());
- }
- }, null));
- }
-// TypeMirror parameterType = e.getTypeMirror();
-// parameters.add(new ClassName(parameterType.toString()));
+ parameters.add(ClassName.get(e.getTypeMirror().toString()));
} catch (MirroredTypesException e) {
for (TypeMirror parameterType : e.getTypeMirrors()) {
parameters.add(new ClassName(parameterType.toString()));
@@ -225,10 +190,8 @@
}
return parameters;
- // signature parameters always should be replaced.
- // TODO - set method return type.
}
-
+
private void setBehaviorEvent(PropertyBase attribute, EventName eventName) {
if (null != eventName) {
org.richfaces.cdk.model.EventName event = new
org.richfaces.cdk.model.EventName();
@@ -238,7 +201,7 @@
attribute.getEventNames().add(event);
}
}
-
+
@Override
public void processType(final BeanModelBase component, TypeElement element) throws
CdkException {
log.debug("AttributesProcessorImpl.processType");
@@ -249,32 +212,32 @@
log.debug(" -> sourceUtils.visitSupertypes...");
SourceUtils sourceUtils = getSourceUtils();
sourceUtils.visitSupertypes(element, new SuperTypeVisitor() {
-
+
@Override
public void visit(TypeMirror type) {
+ String uri = type.toString() + ".xml";
try {
log.debug(" -> visit - " + type.toString());
- component.getAttributes().addAll(
- parseProperties(type.toString() + ".xml"));
+ component.getAttributes().addAll(parseProperties(uri));
} catch (CdkException e) {
- // TODO - log errors ?
+ log.error(e);
+ } catch (FileNotFoundException e) {
+ log.debug("No properties description found at "+uri);
}
}
});
-
log.debug(" -- Process Java files.");
Set<BeanProperty> properties = Sets.newHashSet();
properties.addAll(sourceUtils.getBeanPropertiesAnnotatedWith(Attribute.class,
element));
properties.addAll(sourceUtils.getAbstractBeanProperties(element));
- // TODO - encapsulate attribute builder into utility class.
for (BeanProperty beanProperty : properties) {
processAttribute(beanProperty,
component.getOrCreateAttribute(beanProperty.getName()));
}
}
- private Collection<? extends PropertyBase> parseProperties(String uri) {
+ private Collection<? extends PropertyBase> parseProperties(String uri) throws
FileNotFoundException {
return parser.parseProperties(CdkEntityResolver.URN_ATTRIBUTES + uri);
}
@@ -282,15 +245,16 @@
return utilsProvider.get();
}
-
@Override
- public void processXmlFragment(BeanModelBase component, String ...attributesConfig)
{
+ public void processXmlFragment(BeanModelBase component, String... attributesConfig)
{
// Process all files from @Jsf.. attributes property.
for (String attributes : attributesConfig) {
try {
component.getAttributes().addAll(parseProperties(attributes));
} catch (CdkException e) {
- // TODO - log errors ?
+ log.error(e);
+ } catch (FileNotFoundException e) {
+ log.debug("No properties description found at "+attributes);
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassName.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ClassName.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -73,9 +73,7 @@
* @param cl
*/
public ClassName(Class<?> cl) {
-
- // TODO get information directly from class.
- this(cl.getName());
+ this(cl.getName().replace('$', '.'));
}
/**
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/MethodSignature.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/MethodSignature.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/MethodSignature.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -0,0 +1,85 @@
+/*
+ * $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.model;
+
+import java.io.Serializable;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+import com.google.common.collect.Lists;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+@SuppressWarnings("serial")
+@XmlType(name = "signature", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+(a)XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
+public class MethodSignature implements Serializable {
+
+ private ClassName returnType = ClassName.get(Void.class);
+
+ private List<ClassName> parameters = Lists.newArrayList();
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the returnType
+ */
+ @XmlElement(name = "return-type", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public ClassName getReturnType() {
+ return this.returnType;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param returnType the returnType to set
+ */
+ public void setReturnType(ClassName returnType) {
+ this.returnType = returnType;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the parameters
+ */
+ @XmlElement(name = "param", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public List<ClassName> getParameters() {
+ return this.parameters;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param parameters the parameters to set
+ */
+ public void setParameters(List<ClassName> parameters) {
+ this.parameters = parameters;
+ }
+
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/MethodSignature.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/PropertyBase.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -22,12 +22,10 @@
package org.richfaces.cdk.model;
-import java.util.List;
import java.util.Set;
import org.richfaces.cdk.util.ComparatorUtils;
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
@@ -50,7 +48,7 @@
private boolean passThrough = false;
private Set<EventName> eventNames = Sets.newLinkedHashSet();
- private List<ClassName> signature = Lists.newArrayList();
+ private MethodSignature signature ;
private String defaultValue;
@@ -276,7 +274,7 @@
* @return the signature
*/
@Merge(true)
- public List<ClassName> getSignature() {
+ public MethodSignature getSignature() {
return signature;
}
@@ -285,7 +283,7 @@
*
* @param signature the signature to set
*/
- public void setSignature(List<ClassName> signature) {
+ public void setSignature(MethodSignature signature) {
this.signature = signature;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -24,6 +24,7 @@
package org.richfaces.cdk.templatecompiler;
import java.io.File;
+import java.io.FileNotFoundException;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
@@ -42,6 +43,7 @@
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.MethodSignature;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.PropertyModel;
import org.richfaces.cdk.model.RenderKitModel;
@@ -69,7 +71,7 @@
public class RendererTemplateParser implements ModelBuilder {
private static final Pattern PARAMETERS_STRING_PATTERN =
- Pattern.compile("\\( ( [^\\)]* ) \\) \\s*$", Pattern.COMMENTS);
+ Pattern.compile("^(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)$",
Pattern.COMMENTS);
private static final Pattern COMMA_SEPARATED_PATTERN =
Pattern.compile("\\s*,\\s*", Pattern.COMMENTS);
@@ -121,28 +123,29 @@
return result;
}
- private List<ClassName> parseSignature(String signatureString) {
+ private MethodSignature parseSignature(String signatureString) {
- List<ClassName> result = Lists.newArrayList();
+ List<ClassName> parameters = Lists.newArrayList();
+ MethodSignature signature = new MethodSignature();
if (!Strings.isEmpty(signatureString)) {
Matcher parametersStringMatcher =
PARAMETERS_STRING_PATTERN.matcher(signatureString);
if (!parametersStringMatcher.find()) {
- // TODO - handle exception
throw new IllegalArgumentException(MessageFormat.format("Signature
string {0} cannot be parsed!",
signatureString));
}
-
- String parametersString = parametersStringMatcher.group(1);
+
signature.setReturnType(ClassName.parseName(parametersStringMatcher.group(1)));
+ String parametersString = parametersStringMatcher.group(3);
if (parametersString.trim().length() != 0) {
- String[] parameters = COMMA_SEPARATED_PATTERN.split(parametersString);
- for (String parameter : parameters) {
+ String[] parameterStrings =
COMMA_SEPARATED_PATTERN.split(parametersString);
+ for (String parameter : parameterStrings) {
String trimmedParameter = parameter.trim();
- result.add(ClassName.parseName(trimmedParameter));
+ parameters.add(ClassName.parseName(trimmedParameter));
}
+ signature.setParameters(parameters);
}
}
- return result;
+ return signature;
}
/*
@@ -160,7 +163,7 @@
}
}
- public void build(File file, RendererModel rendererModel) {
+ public void build(File file, RendererModel rendererModel) throws CdkException {
log.debug("RendererTemplateParser.build");
final String absolutePath = file.getAbsolutePath();
log.debug(" - file = " + absolutePath);
@@ -183,9 +186,7 @@
}
Template template = parseTemplate(file);
-
template.setTemplatePath(absolutePath);
-
mergeTemplateIntoModel(template, rendererModel);
}
@@ -212,9 +213,14 @@
if (attributesImports != null) {
for (ImportAttributes attributesImport : attributesImports) {
String importURI = attributesImport.getSource();
- Collection<PropertyBase> properties =
fragmentParser.parseProperties(importURI);
- if (properties != null) {
- renderer.getAttributes().addAll(properties);
+ Collection<PropertyBase> properties;
+ try {
+ properties = fragmentParser.parseProperties(importURI);
+ if (properties != null) {
+ renderer.getAttributes().addAll(properties);
+ }
+ } catch (FileNotFoundException e) {
+ throw new CdkException("File for import not found", e);
}
}
}
@@ -253,8 +259,8 @@
rendererProperty.setRequired(templateAttribute.isRequired());
- List<ClassName> parsedSignature =
parseSignature(templateAttribute.getMethodSignature());
- rendererProperty.getSignature().addAll(parsedSignature);
+ MethodSignature parsedSignature =
parseSignature(templateAttribute.getMethodSignature());
+ rendererProperty.setSignature(parsedSignature);
rendererProperty.setType(templateAttribute.getType());
return rendererProperty;
@@ -277,7 +283,11 @@
}
protected Template parseTemplate(File file) throws CdkException {
- return jaxbBinding.unmarshal(file,
"http://richfaces.org/cdk/cdk-template.xsd", Template.class);
+ try {
+ return jaxbBinding.unmarshal(file,
"http://richfaces.org/cdk/cdk-template.xsd", Template.class);
+ } catch (FileNotFoundException e) {
+ throw new CdkException("Template file not found " +
file.getAbsolutePath(), e);
+ }
}
public NamingConventions getNamingConventions() {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/XhtmlElSchemaProvider.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/XhtmlElSchemaProvider.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/XhtmlElSchemaProvider.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -3,6 +3,9 @@
*/
package org.richfaces.cdk.templatecompiler;
+import java.io.FileNotFoundException;
+
+import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.attributes.Schema;
import org.richfaces.cdk.attributes.SchemaSet;
import org.richfaces.cdk.templatecompiler.model.Template;
@@ -26,7 +29,12 @@
@Override
public Schema get() {
- SchemaSet schemaSet =
jaxbBinding.unmarshal("urn:attributes:xhtml-el.xml", null, SchemaSet.class);
+ SchemaSet schemaSet;
+ try {
+ schemaSet = jaxbBinding.unmarshal("urn:attributes:xhtml-el.xml",
null, SchemaSet.class);
+ } catch (FileNotFoundException e) {
+ throw new CdkException(e);
+ }
return schemaSet.getSchemas().get(Template.XHTML_EL_NAMESPACE);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -24,9 +24,11 @@
package org.richfaces.cdk.xmlconfig;
import java.io.File;
+import java.io.FileNotFoundException;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.Logger;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.Source;
import org.richfaces.cdk.Sources;
@@ -49,6 +51,9 @@
private static final FacesConfigAdapter ADAPTER = new FacesConfigAdapter();
@Inject
+ private Logger log;
+
+ @Inject
private JAXB jaxbBinding;
@Inject
@@ -66,35 +71,39 @@
@Override
public void build() throws CdkException {
for (File file : configFiles.getFiles()) {
- FacesConfigBean unmarshal = unmarshalFacesConfig(file);
- if (null != unmarshal) {
- ComponentLibrary facesConfig = ADAPTER.unmarshal(unmarshal);
- library.getComponents().addAll(facesConfig.getComponents());
- library.getRenderKits().addAll(facesConfig.getRenderKits());
- library.getConverters().addAll(facesConfig.getConverters());
- library.getValidators().addAll(facesConfig.getValidators());
- library.getBehaviors().addAll(facesConfig.getBehaviors());
- library.getFunctions().addAll(facesConfig.getFunctions());
- library.getEvents().addAll(facesConfig.getEvents());
- if (null != unmarshal.getMetadataComplete()) {
- library.setMetadataComplete(unmarshal.getMetadataComplete());
- }
-
library.getExtension().getExtensions().addAll(facesConfig.getExtension().getExtensions());
- if (null != facesConfig.getTaglib()) {
- if (null == library.getTaglib()) {
- library.setTaglib(facesConfig.getTaglib());
- } else {
- JavaUtils.copyProperties(facesConfig.getTaglib(),
library.getTaglib());
+ try {
+ FacesConfigBean unmarshal = unmarshalFacesConfig(file);
+ if (null != unmarshal) {
+ ComponentLibrary facesConfig = ADAPTER.unmarshal(unmarshal);
+ library.getComponents().addAll(facesConfig.getComponents());
+ library.getRenderKits().addAll(facesConfig.getRenderKits());
+ library.getConverters().addAll(facesConfig.getConverters());
+ library.getValidators().addAll(facesConfig.getValidators());
+ library.getBehaviors().addAll(facesConfig.getBehaviors());
+ library.getFunctions().addAll(facesConfig.getFunctions());
+ library.getEvents().addAll(facesConfig.getEvents());
+ if (null != unmarshal.getMetadataComplete()) {
+ library.setMetadataComplete(unmarshal.getMetadataComplete());
}
+
library.getExtension().getExtensions().addAll(facesConfig.getExtension().getExtensions());
+ if (null != facesConfig.getTaglib()) {
+ if (null == library.getTaglib()) {
+ library.setTaglib(facesConfig.getTaglib());
+ } else {
+ JavaUtils.copyProperties(facesConfig.getTaglib(),
library.getTaglib());
+ }
+ }
+ if (null != facesConfig.getPrefix()) {
+ library.setPrefix(facesConfig.getPrefix());
+ }
}
- if (null != facesConfig.getPrefix()) {
- library.setPrefix(facesConfig.getPrefix());
- }
+ } catch (FileNotFoundException e) {
+ log.error("faces-config not found", e);
}
}
}
- protected FacesConfigBean unmarshalFacesConfig(File file) throws CdkException {
+ protected FacesConfigBean unmarshalFacesConfig(File file) throws CdkException,
FileNotFoundException {
return jaxbBinding.unmarshal(file, ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION,
FacesConfigBean.class);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -23,6 +23,7 @@
package org.richfaces.cdk.xmlconfig;
+import java.io.FileNotFoundException;
import java.util.Collection;
import java.util.Collections;
@@ -62,7 +63,7 @@
* @param url
* @return
*/
- public Collection<PropertyBase> parseProperties(String url) throws CdkException
{
+ public Collection<PropertyBase> parseProperties(String url) throws
CdkException, FileNotFoundException {
String schemaLocation = ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION;
Class<Fragment> bindClass = Fragment.class;
Fragment unmarshal = binding.unmarshal(url, schemaLocation, bindClass);
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXB.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -1,6 +1,7 @@
package org.richfaces.cdk.xmlconfig;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.Writer;
import javax.xml.transform.Result;
@@ -9,9 +10,9 @@
public interface JAXB {
- public abstract <T> T unmarshal(File file, String schemaLocation,
Class<T> bindClass) throws CdkException;
+ public abstract <T> T unmarshal(File file, String schemaLocation,
Class<T> bindClass) throws CdkException,FileNotFoundException;
- public abstract <T> T unmarshal(String url, String schemaLocation,
Class<T> bindClass) throws CdkException;
+ public abstract <T> T unmarshal(String url, String schemaLocation,
Class<T> bindClass) throws CdkException,FileNotFoundException;
public abstract <T> void marshal(Writer output, String schemaLocation, T model)
throws CdkException;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/JAXBBinding.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -21,8 +21,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.xmlconfig;
import java.io.File;
@@ -62,9 +60,9 @@
/**
* <p class="changed_added_4_0">
* </p>
- *
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
public class JAXBBinding implements JAXB {
public static final ImmutableSet<String> IGNORE_PROPERTIES =
ImmutableSet.of("class", "extension");
@@ -72,36 +70,38 @@
@Inject
private EntityResolver2 resolver;
-
+
@Inject
private Logger log;
+ public JAXBBinding() {
+ }
- public JAXBBinding() { }
-
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.richfaces.cdk.xmlconfig.JAXB#unmarshal(java.io.File, java.lang.String,
java.lang.Class)
*/
@Override
- public <T> T unmarshal(File file, String schemaLocation, Class<T>
bindClass) throws CdkException {
- try {
- InputSource input = new InputSource(new FileInputStream(file));
+ public <T> T unmarshal(File file, String schemaLocation, Class<T>
bindClass) throws CdkException,
+ FileNotFoundException {
+ InputSource input = new InputSource(new FileInputStream(file));
- input.setSystemId(file.toURI().toString());
+ input.setSystemId(file.toURI().toString());
- T unmarshal = unmarshal(schemaLocation, bindClass, input);
+ T unmarshal = unmarshal(schemaLocation, bindClass, input);
- return unmarshal;
- } catch (FileNotFoundException e) {
- throw new CdkException("XML file not found", e);
- }
+ return unmarshal;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.richfaces.cdk.xmlconfig.JAXB#unmarshal(java.lang.String,
java.lang.String, java.lang.Class)
*/
@Override
- public <T> T unmarshal(String url, String schemaLocation, Class<T>
bindClass) throws CdkException {
+ public <T> T unmarshal(String url, String schemaLocation, Class<T>
bindClass) throws CdkException,
+ FileNotFoundException {
try {
InputSource inputSource;
try {
@@ -118,12 +118,12 @@
return unmarshal;
} catch (IOException e) {
- throw new CdkException("XML file not found", e);
+ throw new FileNotFoundException("XML file not found at " + url);
}
}
@SuppressWarnings("unchecked")
- //TODO nick - schemaLocation is unused
+ // TODO nick - schemaLocation is unused
<T> T unmarshal(String schemaLocation, Class<T> bindClass, InputSource
inputSource) throws CdkException {
T unmarshal = null;
@@ -175,7 +175,9 @@
return unmarshal;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.richfaces.cdk.xmlconfig.JAXB#marshal(java.io.File, java.lang.String, T)
*/
@Override
@@ -193,7 +195,9 @@
}
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.richfaces.cdk.xmlconfig.JAXB#marshal(javax.xml.transform.Result,
java.lang.String, T)
*/
@Override
@@ -205,7 +209,7 @@
marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
// TODO - let writer to define additional schemes.
-// marshaller.setProperty("jaxb.schemaLocation", Boolean.TRUE);
+ // marshaller.setProperty("jaxb.schemaLocation", Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
if (null != schemaLocation) {
@@ -227,7 +231,7 @@
* <p class="changed_added_4_0">
* Close input source after parsing.
* </p>
- *
+ *
* @param source
*/
private void closeSource(Source source) {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBase.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBase.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -23,19 +23,16 @@
package org.richfaces.cdk.xmlconfig.model;
-import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConfigExtension;
import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.MethodSignature;
-import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
@@ -139,7 +136,7 @@
public static class PropertyExtension extends ConfigExtension {
private Boolean passThrough;
private Set<EventName> eventNames = Sets.newLinkedHashSet();
- private List<ClassName> signature = Lists.newArrayList();
+ private MethodSignature signature ;
private String aliasFor ;
private Boolean generate;
private Boolean hidden;
@@ -285,10 +282,8 @@
*
* @return the signature
*/
- @XmlElementWrapper(name = "signature", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
- @XmlElement(name = "param", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
- @XmlJavaTypeAdapter(ClassAdapter.class)
- public List<ClassName> getSignature() {
+ @XmlElement(name = "signature", namespace =
ComponentLibrary.CDK_EXTENSIONS_NAMESPACE)
+ public MethodSignature getSignature() {
return signature;
}
@@ -297,7 +292,7 @@
*
* @param signature the signature to set
*/
- public void setSignature(List<ClassName> signature) {
+ public void setSignature(MethodSignature signature) {
this.signature = signature;
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/processors/AttributesProcessorTest.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -105,7 +105,7 @@
}
@Test
- public void testProcessXmlFragment() {
+ public void testProcessXmlFragment() throws Exception {
BeanModelBase bean = new BeanModelBase();
Fragment fragment = new Fragment();
PropertyModel propertyModel = new PropertyModel();
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -43,6 +43,7 @@
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.FacesId;
+import org.richfaces.cdk.model.MethodSignature;
import org.richfaces.cdk.model.PropertyBase;
import com.google.inject.Inject;
@@ -86,7 +87,9 @@
attribute.setType(new ClassName(MethodExpression.class));
attribute.setGenerate(true);
attribute.setBindingAttribute(true);
- attribute.setSignature(Arrays.asList(new ClassName(String.class), new
ClassName(Integer.class)));
+ MethodSignature signature = new MethodSignature();
+ signature.setParameters(Arrays.asList(new ClassName(String.class), new
ClassName(Integer.class)));
+ attribute.setSignature(signature);
attribute = component.getOrCreateAttribute("id");
attribute.setType(new ClassName(String.class));
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
-import java.util.List;
import java.util.Set;
import javax.faces.event.ActionEvent;
@@ -48,6 +47,7 @@
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.FacesId;
+import org.richfaces.cdk.model.MethodSignature;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
@@ -95,9 +95,8 @@
}
private void assertNoSignature(PropertyBase property) {
- List<ClassName> signature = property.getSignature();
- assertNotNull(signature);
- assertTrue(signature.isEmpty());
+ MethodSignature signature = property.getSignature();
+ assertNull(signature);
}
private void assertNotRequired(PropertyBase property) {
@@ -127,7 +126,9 @@
assertNotNull(actionProperty);
assertNoEventNames(actionProperty);
- assertEquals(0, actionProperty.getSignature().size());
+ assertNotNull(actionProperty.getSignature());
+ assertEquals(0, actionProperty.getSignature().getParameters().size());
+ assertEquals(String.class.getName(),
actionProperty.getSignature().getReturnType());
}
/**
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-07-22
21:32:57 UTC (rev 18206)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-07-22
23:30:41 UTC (rev 18207)
@@ -124,7 +124,7 @@
assertTrue(property.isPassThrough());
assertTrue(property.isRequired());
- List<ClassName> signature = property.getSignature();
+ List<ClassName> signature = property.getSignature().getParameters();
assertEquals(2, signature.size());