|
|
|
Re: ValueProperty bind to XML text [message #1033818 is a reply to message #1033384] |
Thu, 04 April 2013 17:23 |
Konstantin Komissarchik Messages: 1077 Registered: July 2009 |
Senior Member |
|
|
It looks like the issue causing this not to work is the declaration of ClassConstraint property. In particular, the name given in the ValueProperty constructor does not match the name of the field holding ValueProperty instance, so none of the annotations are found by the framework.
Actual:
ValueProperty PROP_CLASSCONSTRAINT = new ValueProperty( TYPE, "Class" );
ReferenceValue<JavaTypeName,JavaType> getClassConstraint();
void setClassConstraint( String value );
void setClassConstraint( JavaTypeName value );
Correct:
ValueProperty PROP_CLASS_CONSTRAINT = new ValueProperty( TYPE, "ClassConstraint" );
ReferenceValue<JavaTypeName,JavaType> getClassConstraint();
void setClassConstraint( String value );
void setClassConstraint( JavaTypeName value );
Here is the full test case that shows this working once the above issue is corrected:
public final class ForumTestCase extends SapphireTestCase
{
@GenerateImpl
@XmlBinding( path = "constrain" )
public interface ClassConstraint extends IModelElement
{
ModelElementType TYPE = new ModelElementType( ClassConstraint.class );
@ReadOnly
@InitialValue( text = "biz.facilityboss.core.api.dependency.ClassConstrain" )
@XmlBinding( path = "@type" )
ValueProperty PROP_TYPE = new ValueProperty( TYPE, "Type" );
Value<String> getType();
void setType( String value );
@Required
@MustExist
@Type( base = JavaTypeName.class )
@Reference( target = JavaType.class )
@JavaTypeConstraint( kind = { JavaTypeKind.INTERFACE, JavaTypeKind.CLASS }, type = "biz.facilityboss.core.api.IService" )
@XmlBinding( path = "" )
ValueProperty PROP_CLASS_CONSTRAINT = new ValueProperty( TYPE, "ClassConstraint" );
ReferenceValue<JavaTypeName,JavaType> getClassConstraint();
void setClassConstraint( String value );
void setClassConstraint( JavaTypeName value );
}
@GenerateImpl
@XmlBinding( path = "dependency" )
public interface Dependency extends IModelElement
{
ModelElementType TYPE = new ModelElementType( Dependency.class );
@Label( standard = "Identifier" )
@Required
@MustExist
@XmlBinding( path = "@identifier" )
ValueProperty PROP_IDENTIFIER = new ValueProperty( TYPE, "Identifier" );
Value<String> getIdentifier();
void setIdentifier( String value );
@Type( base = ClassConstraint.class )
@XmlListBinding( path = "" )
ListProperty PROP_CONSTRAINTS = new ListProperty( TYPE,"Constraints" );
ModelElementList<ClassConstraint> getConstraints();
}
private ForumTestCase( final String name )
{
super( name );
}
public static Test suite()
{
final TestSuite suite = new TestSuite();
suite.setName( "ForumTestCase" );
suite.addTest( new ForumTestCase( "test" ) );
return suite;
}
public void test() throws Exception
{
final ByteArrayResourceStore byteArrayResourceStore = new ByteArrayResourceStore();
final XmlResourceStore xmlResourceStore = new XmlResourceStore( byteArrayResourceStore );
final Dependency dep = Dependency.TYPE.instantiate( new RootXmlResource( xmlResourceStore ) );
dep.setIdentifier( "123" );
final ClassConstraint constraint = dep.getConstraints().insert();
constraint.setClassConstraint( "org.something.ExampleClass" );
dep.resource().save();
final String actual = new String( byteArrayResourceStore.getContents(), "UTF-8" );
System.err.println( actual );
}
}
The test case prints out the following output:
<?xml version="1.0" encoding="UTF-8"?>
<dependency identifier="123">
<constrain type="biz.facilityboss.core.api.dependency.ClassConstrain">org.something.ExampleClass</constrain>
</dependency>
Thanks,
- Konstantin
|
|
|
|
Powered by
FUDForum. Page generated in 0.03728 seconds