OK I will respond to this ... just haivng access and time issues for past 2 days ... not ignored.

Cheers,
Alex

On Thu, Feb 2, 2012 at 10:10 PM, Emmanuel Lecharny <elecharny@gmail.com> wrote:
Hi guys,

today, we had a long discussion with Pierre-Arnaud about AT, schema and pathetic state of the planet. The last problem, we can't solve...

For the former issues, which has been raised when we started to try to extend the API to allow a user to add new Schema elements locally, we think that we must modify the current data structure for schema objects.

Here are a few brain dump and some examples :

First, the SchemaManager will only manage immutable SchemaObjects (ie, here, AttributeType), as there is no reason to allow someone to pull a SchemaObject from the SchemaManager and to modify it on the fly. That would be destructive for the sc hemaManager user, as it may impact other users.

Now, for Studio, being able to pull an AT from teh SM, modify this AT and inject it back to the SM is useful.

We then discussed about Mutable and Immutable schema objects, and how they can help us solving this issue.

If a user want to modify an existing SchemaObject pulled from the SchemaManager must first make it mutable :

AttributeType attributeType = schemaManager.getAttributeType( "2.5.4.11" );
MutableAttributeType mat = new MutableAttributeType( attributeType );

In this case, the resulting instance is a copy of the initial immutable object.

In order to be able to implement such a proposal, the following hierarchy could be enough :


  (SchemaObject)<-------------------(MutableSchemaObject)
        o                                     ^
        |                                     |
{AbstractSchemaObject}                         |
        ^                                     |
        |                                     |
  [AttributeType]<------------------[MutableAttributeType]



where (III) are interfaces, {AAA} are abstract classes and [CCC] are normal classes.

The base implementation is :

o (SchemaObject) expose all the SO getters.
o (MutableSchemaObject) interface expose the SO setters.
o {AbstractSchemaObject} implements the the SO getters
o [AttributeType] implements the AttributeType getters
o [MutableAttributeType] implements the AttributeType setters

(see an exemple at the end of this mail)

With those classes and interface, it's possible to hide the setters for a user manipulating an AT he got from the SchemaManager, but this user has the possibility to modify this AT by wrapping it into a new MutableAT.

In order to create new SchemaObject, a user can :

1) create a MutableSchemaObject, and get its immutable copy :

MutableAttributeType mutableAT = new MutableAttributeType();
mutableAT.setXXX( yyy );
...
AttributeType attributeType = new AttributeType( mutableAT );

2) create a new AttributeType using the RFC notation :

AttributeType attributeType = new AttributeType( "( 2.5.4.58 NAME 'attributeCertificateAttribute' DESC 'attribute certificate use ;binary' SYNTAX 1.3.6.1.4.1.1466.115.121.1.8 )" );

In any case, everything stored in the SchemaManager must be immutable.


public interface SchemaObject
{
   int getValue();
}

public abstract class AbstractSchemaObject implements SchemaObject
{
   // Protected to hide it from the user but modifiable by a MutableAT instance
   protected int value;

   protected AbstractSchemaObject( int value )
   {
       this.value = value;
   }

   public int getValue()
   {
       return value;
   }
}

public class AttributeType extends AbstractSchemaObject
{
   // This is protected to be modifable by a MutableAT instance
   protected String descr;

   public AttributeType()
   {
       super( 1 );
       descr = "Test";
   }

   // A constructor creating an immutable AT from a MutableAT
   public AttributeType( MutableAttributeType attributeType )
   {
       super( attributeType.getValue() );

       descr = attributeType.getDescr();
   }

   public String getDescr()
   {
       return descr;
   }
}


public interface MutableSchemaObject
{
   void setValue( int value );
}


public class MutableAttributeType extends AttributeType implements MutableSchemaObject
{
   public MutableAttributeType()
   {
   }

   // A constructor creating a MutableAT from an AT
   public MutableAttributeType( AttributeType attributeType )
   {
       super();

       value = attributeType.getValue();
       descr = attributeType.getDescr();
   }

   public void setValue( int value )
   {
       this.value = value;
   }

   public void setDescr( String descr )
   {
       this.descr = descr;
   }
}


Thoughts ?

--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com




--
Best Regards,
-- Alex