Author: Alex.Kolonitsky
Date: 2010-01-14 11:08:21 -0500 (Thu, 14 Jan 2010)
New Revision: 16296
Added:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorAdapter.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml
Modified:
root/cdk/trunk/plugins/generator/pom.xml
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java
Log:
Added:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java
(rev 0)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,21 @@
+package org.richfaces.cdk.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+(a)Retention(RetentionPolicy.CLASS)
+(a)Target(ElementType.TYPE)
+@Inherited
+public @interface Validator {
+
+ public static final String NAME =
"org.richfaces.cdk.annotations.Validator";
+
+ public String id() default "";
+}
Modified: root/cdk/trunk/plugins/generator/pom.xml
===================================================================
--- root/cdk/trunk/plugins/generator/pom.xml 2010-01-14 15:46:34 UTC (rev 16295)
+++ root/cdk/trunk/plugins/generator/pom.xml 2010-01-14 16:08:21 UTC (rev 16296)
@@ -100,6 +100,13 @@
<version>4.6</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <scope>test</scope>
+ <version>1.2</version>
+ </dependency>
+
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/CdkProcessor.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -59,6 +59,7 @@
.of(ComponentProcessor.class,
FacesComponentProcessor.class,
BehaviorProcessor.class,
+ ValidatorProcessor.class,
ConverterProcessor.class);
/**
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -29,6 +29,7 @@
import org.richfaces.cdk.CdkProcessingException;
import org.richfaces.cdk.annotations.Converter;
import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.ClassDescription;
/**
* @author akolonitsky
@@ -40,10 +41,14 @@
@Override
public void process(TypeElement element) throws CdkProcessingException {
Converter converter = element.getAnnotation(Converter.class);
+
ConverterModel converterModel = new ConverterModel();
converterModel.setConverterId(converter.id());
converterModel.setConverterForClass(converter.forClass());
+ converterModel.setConverterClass(new
ClassDescription(element.getQualifiedName().toString()));
+
setDescription(element, converterModel);
+
getLibrary().getConverters().add(converterModel);
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,57 @@
+/**
+ * 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.apt;
+
+import org.richfaces.cdk.CdkProcessingException;
+import org.richfaces.cdk.annotations.Validator;
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.ValidatorModel;
+
+import javax.annotation.processing.SupportedAnnotationTypes;
+import javax.lang.model.element.TypeElement;
+import java.lang.annotation.Annotation;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
Validator.NAME})
+public class ValidatorProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
+
+ @Override
+ public void process(TypeElement element) throws CdkProcessingException {
+ Validator validator = element.getAnnotation(Validator.class);
+
+ ValidatorModel validatorModel = new ValidatorModel("my_validator", new
ClassDescription(Object.class));
+ validatorModel.setValidatorId(validator.id());
+ validatorModel.setValidatorClass(new
ClassDescription(element.getQualifiedName().toString()));
+
+ setDescription(element, validatorModel);
+
+ getLibrary().getValidators().add(validatorModel);
+ }
+
+ @Override
+ public Class<? extends Annotation> getProcessedAnnotation() {
+ return Validator.class;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -36,14 +36,14 @@
private String converterId;
- private Class<?> converterClass;
+ private ClassDescription converterClass;
private Class<?> converterForClass;
public ConverterModel() {
}
- public ConverterModel(String converterId, Class<?> converterClass) {
+ public ConverterModel(String converterId, ClassDescription converterClass) {
this.converterId = converterId;
this.converterClass = converterClass;
}
@@ -66,11 +66,11 @@
}
@Merge(false)
- public Class<?> getConverterClass() {
+ public ClassDescription getConverterClass() {
return converterClass;
}
- public void setConverterClass(Class<?> converterClass) {
+ public void setConverterClass(ClassDescription converterClass) {
this.converterClass = converterClass;
}
@@ -82,7 +82,6 @@
@Override
public void merge(ConverterModel other) {
ComponentLibrary.merge(this, other);
-
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -21,8 +21,6 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.model;
import org.richfaces.cdk.CdkException;
@@ -32,58 +30,47 @@
* @author asmirnov(a)exadel.com
*
*/
-@SuppressWarnings("serial")
-public class ValidatorModel implements ModelElement<ValidatorModel> {
- private Type type;
+public class ValidatorModel extends ModelElementBase implements
ModelElement<ValidatorModel> {
+ private static final long serialVersionUID = -6097027070372673266L;
- public ValidatorModel() {
+ private String validatorId;
+
+ private ClassDescription validatorClass;
+
+ public ValidatorModel(String validatorId, ClassDescription validatorClass) {
+ setValidatorId(validatorId);
+ setValidatorClass(validatorClass);
}
- /**
- * <p class="changed_added_4_0"></p>
- * @param type the type to set
- */
- public ValidatorModel(Type type) {
- this.type = type;
+ public String getValidatorId() {
+ return validatorId;
}
- @Override
- public <R, P> R accept(LibraryVisitor<R, P> visitor, P param) throws
CdkException {
- return visitor.visit(this, param);
+ public void setValidatorId(String validatorId) {
+ this.validatorId = validatorId;
}
- /*
- * (non-Javadoc)
- * @see org.richfaces.cdk.model.ModelElement#getType()
- */
- public Type getType() {
- return type;
+ @Merge(false)
+ public ClassDescription getValidatorClass() {
+ return validatorClass;
}
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param type the type to set
- */
- public void setType(Type type) {
- this.type = type;
+ public void setValidatorClass(ClassDescription validatorClass) {
+ this.validatorClass = validatorClass;
}
@Override
- public void merge(ValidatorModel other) {
+ public <R, P> R accept(LibraryVisitor<R, P> visitor, P param) throws
CdkException {
+ return visitor.visit(this, param);
+ }
- // TODO Auto-generated method stub
+ @Override
+ public void merge(ValidatorModel other) {
+ ComponentLibrary.merge(this, other);
}
@Override
public boolean same(ValidatorModel other) {
- return null != getType() && getType().equals(other.getType());
+ return null != getValidatorId() &&
getValidatorId().equals(other.getValidatorId());
}
-
- public static final class Type extends Key {
- public Type(String name) {
- super(name);
- }
- }
-
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/FacesConfigBean.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -37,6 +37,7 @@
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.Extensible;
import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.ValidatorModel;
import com.google.common.collect.Lists;
@@ -59,6 +60,10 @@
@XmlJavaTypeAdapter(ConverterAdapter.class)
private List<ConverterModel> converters = Lists.newArrayList();
+ @XmlElement(name = "validator", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
+ @XmlJavaTypeAdapter(ValidatorAdapter.class)
+ private List<ValidatorModel> validators = Lists.newArrayList();
+
@XmlAttribute
private String version = "2.0";
@@ -146,6 +151,14 @@
this.converters = converters;
}
+ public List<ValidatorModel> getValidators() {
+ return validators;
+ }
+
+ public void setValidators(List<ValidatorModel> validators) {
+ this.validators = validators;
+ }
+
/**
* <p class="changed_added_4_0"></p>
*
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorAdapter.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorAdapter.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorAdapter.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,41 @@
+/**
+ * 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.xmlconfig.model;
+
+import org.richfaces.cdk.model.ValidatorModel;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+public class ValidatorAdapter extends AdapterBase<ValidatorBean, ValidatorModel>{
+
+ @Override
+ protected Class<? extends ValidatorBean> getBeanClass(ValidatorModel model) {
+ return ValidatorBean.class;
+ }
+
+ @Override
+ protected Class<? extends ValidatorModel> getModelClass(ValidatorBean bean) {
+ return ValidatorModel.class;
+ }
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,94 @@
+/**
+ * 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.xmlconfig.model;
+
+import org.richfaces.cdk.model.ConfigExtension;
+import org.richfaces.cdk.model.ComponentLibrary;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import java.util.List;
+
+import com.google.common.collect.Lists;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+@XmlType(name = "faces-config-validatorType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
+ propOrder={"validatorId", "validatorClass",
"attributes", "extension"})
+(a)XmlJavaTypeAdapter(ValidatorAdapter.class)
+public class ValidatorBean extends ExtensibleBean<ValidatorBean.ValidatorExtension>
{
+
+ private String validatorId;
+
+ private String validatorClass;
+
+ private List<PropertyBase> attributes = Lists.newArrayList();
+
+ @XmlElement(name = "validator-id", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
+ public String getValidatorId() {
+ return validatorId;
+ }
+
+ public void setValidatorId(String validatorId) {
+ this.validatorId = validatorId;
+ }
+
+ @XmlElement(name = "validator-class", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
+ public String getValidatorClass() {
+ return validatorClass;
+ }
+
+ public void setValidatorClass(String validatorClass) {
+ this.validatorClass = validatorClass;
+ }
+
+
+ @XmlElements({
+ @XmlElement(name = "property", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = PropertyBean.class),
+ @XmlElement(name = "attribute", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = AttributeBean.class)
+ })
+ public List<PropertyBase> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<PropertyBase> property) {
+ this.attributes = property;
+ }
+
+ @Override
+ @XmlElement(name = "validator-extension", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
+ public ValidatorExtension getExtension() {
+ return super.getExtension();
+ }
+
+ @Override
+ public void setExtension(ValidatorExtension extension) {
+ super.setExtension(extension);
+ }
+
+ public static class ValidatorExtension extends ConfigExtension {
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/CdkTestBase.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -47,7 +47,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class CdkTestBase {
+public abstract class CdkTestBase {
protected Iterable<File> testSourceDirectory;
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JaxbTestBase.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -1,22 +1,14 @@
package org.richfaces.cdk.xmlconfig;
+import org.richfaces.cdk.CdkTestBase;
+
+import javax.xml.bind.JAXB;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
-import javax.xml.bind.JAXB;
-
-import org.junit.After;
-import org.junit.Before;
-import org.richfaces.cdk.CdkTestBase;
-
-public class JaxbTestBase extends CdkTestBase {
+public abstract class JaxbTestBase extends CdkTestBase {
protected static final String XML_PROLOG = "<?xml version=\"1.0\"
encoding=\"UTF-8\"?>\n";
- public JaxbTestBase() {
- super();
- }
-
-
protected <T> T unmarshal(Class<T> type, String src) {
StringBuilder xml = new StringBuilder(XML_PROLOG);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-01-14
15:46:34 UTC (rev 16295)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -22,12 +22,14 @@
package org.richfaces.cdk.xmlconfig.testmodel;
import org.junit.Test;
+import org.junit.Ignore;
import org.richfaces.cdk.CdkContextBase;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.ClassDescription;
import org.richfaces.cdk.xmlconfig.JAXBBinding;
import org.richfaces.cdk.xmlconfig.FacesConfigGenerator;
import org.richfaces.cdk.xmlconfig.JaxbTestBase;
@@ -40,37 +42,25 @@
* @author akolonitsky
* @since Jan 10, 2010
*/
-public class ConverterBeanTest extends JaxbTestBase {
+public class ConverterBeanTest extends ModelBeanTest {
@Test
public void testMarshalResultStringT() throws Exception {
- CdkContextBase contextBase = new CdkContextBase(createClassLoader());
- JAXBBinding jaxbBinding = new JAXBBinding();
-
- jaxbBinding.init(contextBase);
-
ComponentLibrary library = new ComponentLibrary();
- // add component
ComponentModel component = new ComponentModel( new
ComponentModel.Type("foo.bar"));
library.getComponents().add(component);
-
- // add render kit
RenderKitModel renderKit = library.addRenderKit("HTML");
-
- // add renderer
RendererModel renderer = new RendererModel(new
RendererModel.Type("foo.Renderer"));
renderKit.getRenderers().add(renderer);
-
- // add converter
- ConverterModel converterModel = new ConverterModel("my_converter",
Object.class);
+ ConverterModel converterModel = new ConverterModel("my_converter", new
ClassDescription(Object.class));
library.getConverters().add(converterModel);
- StringWriter writer = new StringWriter();
- StreamResult result = new StreamResult(writer);
- FacesConfigAdapter adapter = new FacesConfigAdapter();
+ // Jaxb marshaling
+ StringWriter facesConfig = generateFacesConfig(library);
- jaxbBinding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION,
adapter.marshal(library));
- System.out.println(writer.toString());
+ // Checks
+ checkXmlStructure(facesConfig);
+// validateXml(facesConfig);
}
}
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ModelBeanTest.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,94 @@
+/**
+ * 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.xmlconfig.testmodel;
+
+import org.richfaces.cdk.xmlconfig.JaxbTestBase;
+import org.richfaces.cdk.xmlconfig.JAXBBinding;
+import org.richfaces.cdk.xmlconfig.FacesConfigGenerator;
+import org.richfaces.cdk.xmlconfig.model.FacesConfigAdapter;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.CdkContextBase;
+import org.xml.sax.SAXException;
+import org.xml.sax.InputSource;
+import org.custommonkey.xmlunit.Validator;
+import org.custommonkey.xmlunit.Diff;
+import org.junit.Assert;
+
+import javax.xml.transform.stream.StreamResult;
+import java.io.StringWriter;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.MalformedURLException;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+public abstract class ModelBeanTest extends JaxbTestBase {
+
+ protected void validateXml(StringWriter facesConfig) throws SAXException {
+ InputSource is = new InputSource(facesConfig.toString());
+ Validator validator = new Validator(is);
+ validator.useXMLSchema(true);
+ File source = null;
+// try {
+// source = null; //new InputStream(new
URL(ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION));
+// } catch (MalformedURLException e) {
+// e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
+// }
+ if (source == null) {
+ return;
+ }
+ validator.setJAXP12SchemaSource(source);
+
+ validator.assertIsValid();
+ }
+
+ protected void checkXmlStructure(StringWriter writer) throws SAXException,
IOException {
+ Class<?> testClass = this.getClass();
+ InputStream expectedFacesConfigFile =
testClass.getResourceAsStream(testClass.getSimpleName() + ".xml");
+ if (expectedFacesConfigFile == null) {
+ return;
+ }
+
+ Diff xmlDiff = new Diff(
+ new StringReader(writer.toString()),
+ new InputStreamReader(expectedFacesConfigFile));
+
+ Assert.assertTrue("XML was not similar", xmlDiff.similar());
+ }
+
+ protected StringWriter generateFacesConfig(ComponentLibrary library) throws Exception
{
+ StringWriter writer = new StringWriter();
+ StreamResult result = new StreamResult(writer);
+
+ JAXBBinding jaxbBinding = new JAXBBinding();
+ jaxbBinding.init(new CdkContextBase(createClassLoader()));
+ jaxbBinding.marshal(result, FacesConfigGenerator.FACES_SCHEMA_LOCATION,
+ new FacesConfigAdapter().marshal(library));
+ return writer;
+ }
+}
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.java 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,53 @@
+/**
+ * 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.xmlconfig.testmodel;
+
+import org.junit.Test;
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ValidatorModel;
+
+import java.io.StringWriter;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+public class ValidatorBeanTest extends ModelBeanTest {
+
+ @Test
+ public void testMarshal() throws Exception {
+ ComponentLibrary library = new ComponentLibrary();
+
+ ValidatorModel validatorModel = new ValidatorModel("my_validator", new
ClassDescription(Object.class));
+ library.getValidators().add(validatorModel);
+
+ // Jaxb marshaling
+ StringWriter facesConfig = generateFacesConfig(library);
+
+ // Checks
+ checkXmlStructure(facesConfig);
+// validateXml(facesConfig);
+ }
+
+
+}
Added:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.xml 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<faces-config metadata-complete="false" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://richfaces.org/cdk/extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <component>
+ <component-type>foo.bar</component-type>
+ <component-extension>
+ <cdk:generate>false</cdk:generate>
+ </component-extension>
+ </component>
+ <converter>
+ <converter-id>my_converter</converter-id>
+ <converter-class>java.lang.Object</converter-class>
+ <converter-extension/>
+ </converter>
+ <faces-config-extension/>
+ <render-kit>
+ <render-kit-id>HTML</render-kit-id>
+ <renderer>
+ <renderer-type>foo.Renderer</renderer-type>
+ <renderer-extension>
+ <cdk:renders-children>false</cdk:renders-children>
+ </renderer-extension>
+ </renderer>
+ <render-kit-extension/>
+ </render-kit>
+</faces-config>
\ No newline at end of file
Added:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/xmlconfig/testmodel/ValidatorBeanTest.xml 2010-01-14
16:08:21 UTC (rev 16296)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
+<faces-config metadata-complete="false" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:cdk="http://richfaces.org/cdk/extensions"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <faces-config-extension/>
+ <validator>
+ <validator-id>my_validator</validator-id>
+ <validator-class>java.lang.Object</validator-class>
+ <validator-extension/>
+ </validator>
+</faces-config>
\ No newline at end of file