Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sapphire » ValueProperty bind to XML text
ValueProperty bind to XML text [message #1033041] Wed, 03 April 2013 19:51 Go to next message
Max Larsson is currently offline Max LarssonFriend
Messages: 5
Registered: April 2013
Junior Member
Hi,

i'm struggling all day to achieve the following. I have the following interface:

@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" )
    ValueProperty PROP_CLASSCONSTRAINT = new ValueProperty( TYPE, "Class" );

    ReferenceValue<JavaTypeName,JavaType> getClassConstraint();
    void setClassConstraint( String value );
    void setClassConstraint( JavaTypeName value );
}


The output which i get is the following:

<constrain type="biz.facilityboss.core.api.dependency.ClassConstrain">
  <Class>Whatever Java Type selected</Class>
</constrain>


But what i want is the following:

<constrain type="biz.facilityboss.core.api.dependency.ClassConstrain">whatever Java Type selected</constrain>


To write the PROP_CLASSCONSTRAINT without it surrounding element, just its value.
Is that possible?

best regards

Max Larsson

Re: ValueProperty bind to XML text [message #1033101 is a reply to message #1033041] Wed, 03 April 2013 21:17 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 952
Registered: July 2009
Senior Member
Use @XmlBinding( path = "" ) for the ClassConstraint property.

- Konstantin
Re: ValueProperty bind to XML text [message #1033384 is a reply to message #1033101] Thu, 04 April 2013 07:25 Go to previous messageGo to next message
Max Larsson is currently offline Max LarssonFriend
Messages: 5
Registered: April 2013
Junior Member
I tried that before and just now, and does not work.

So i think might relate to how the interface ClassConstraint is
used by another interface Dependency

@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();
}


Because their i use @XmlListBinding( path = "" ), which works.
Re: ValueProperty bind to XML text [message #1033818 is a reply to message #1033384] Thu, 04 April 2013 17:23 Go to previous messageGo to next message
Konstantin Komissarchik is currently offline Konstantin KomissarchikFriend
Messages: 952
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
Re: ValueProperty bind to XML text [message #1033824 is a reply to message #1033818] Thu, 04 April 2013 17:30 Go to previous message
Max Larsson is currently offline Max LarssonFriend
Messages: 5
Registered: April 2013
Junior Member
Hi,

thanks a lot, it works now. I remember to have read about the thing
to name the PROP_ correctly. But i wasn't aware that it even covers
the second parameter of ValueProperty.

best regards

Max
Previous Topic:ReferenceValue target object property in EL
Next Topic:How to hide outline from SapphireEditorForXml?
Goto Forum:
  


Current Time: Wed Nov 26 14:25:34 GMT 2014

Powered by FUDForum. Page generated in 0.05657 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software