directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r496618 [2/5] - in /directory/sandbox/triplesec-jacc2: ./ admin-api2/ admin-api2/src/ admin-api2/src/main/java/org/safehaus/triplesec/admin/ admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/ admin-api2/src/main/java/org/safehaus/tr...
Date Tue, 16 Jan 2007 08:24:50 GMT
Modified: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Profile.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Profile.java?view=diff&rev=496618&r1=496616&r2=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Profile.java (original)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Profile.java Tue Jan 16 00:24:45 2007
@@ -20,108 +20,168 @@
 package org.safehaus.triplesec.admin;
 
 
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
 import java.util.Set;
+import java.util.Collection;
 
-import org.safehaus.triplesec.admin.dao.ProfileDao;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
 
+import org.safehaus.triplesec.admin.persistence.PersistenceCapable;
+import org.safehaus.triplesec.admin.persistence.StateManager;
+import org.safehaus.triplesec.admin.persistence.SimpleRdn;
+import org.safehaus.triplesec.admin.persistence.SingleValuedField;
+import org.safehaus.triplesec.admin.persistence.MultiValuedField;
+import org.safehaus.triplesec.admin.persistence.State;
+import org.safehaus.triplesec.admin.persistence.ReferenceMapField;
 
-public class Profile extends AdministeredEntity
+
+public class Profile implements PersistenceCapable
 {
-    private final ProfileDao dao;
-    private final Set grants;
-    private final Set denials;
-    private final Set roles;
-    private final String id;
-    private final String user;
-    private final String description;
-    private final String applicationName;
-    private final boolean disabled;
-    
-    
-    public Profile( String creatorsName, Date createTimestamp, ProfileDao dao, String applicationName, 
-        String id, String user, String description, Set grants, Set denials, Set roles )
+
+    public static final String[] attrs = new String[] {Constants.PROFILEID_ID,
+            Constants.DESCRIPTION_ID,
+            Constants.ROLES_ID,
+            Constants.GRANTS_ID,
+            Constants.DENIALS_ID,
+            Constants.SAFEHAUS_DISABLED_ID,
+            Constants.USER_ID};
+
+    private static final int PROFILEID_INDEX = 0;
+    private static final int DESCRIPTION_INDEX = 1;
+    private static final int ROLES_INDEX = 2;
+    private static final int GRANTS_INDEX = 3;
+    private static final int DENIALS_INDEX = 4;
+    private static final int DISABLED_INDEX = 5;
+    private static final int USERID_INDEX = 6;
+
+    private final StateManager stateManager;
+
+    public Profile()
+    {
+        stateManager = new StateManager( this );
+        stateManager.setRdn( new SimpleRdn( Constants.PROFILEID_ID, null, "ou=profiles" ) );
+        stateManager.addField( new SingleValuedField<String>( Constants.DESCRIPTION_ID, null ) );
+        stateManager.addField( new ReferenceMapField<Role>( Constants.ROLES_ID ) );
+        stateManager.addField( new ReferenceMapField<Permission>( Constants.GRANTS_ID ) );
+        stateManager.addField( new ReferenceMapField<Permission>( Constants.DENIALS_ID ) );
+        stateManager.addField( new SingleValuedField<Boolean>( Constants.SAFEHAUS_DISABLED_ID, null ) );
+        stateManager.addField( new SingleValuedField<String>( Constants.USER_ID, null ) );
+
+        stateManager.setState( State.EMPTY );
+
+    }
+
+    public Profile(  String profileId, String description,
+            Set grants, Set denials, Set roles, boolean disabled, String user )
     {
-        this( creatorsName, createTimestamp, null, null, dao, applicationName, id, 
-            user, description, grants, denials, roles, false );
+        this(  );
+
+        stateManager.setStringValue( PROFILEID_INDEX, profileId);
+        stateManager.setStringValue( DESCRIPTION_INDEX, description);
+        stateManager.setStringValue( USERID_INDEX, user);
     }
-    
-    
-    public Profile( String creatorsName, Date createTimestamp, String modifiersName, Date modifyTimestamp, 
-        ProfileDao dao, String applicationName, String id, String user, String description, 
-        Set grants, Set denials, Set roles, boolean disabled )
+
+
+
+
+    public String getProfileId()
     {
-        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp );
-        this.dao = dao;
-        this.applicationName = applicationName;
-        this.id = id;
-        this.user = user;
-        this.grants = new HashSet( grants );
-        this.denials = new HashSet( denials );
-        this.roles = new HashSet( roles );
-        this.description = description;
-        this.disabled = disabled;
+        return stateManager.getId( );
     }
-    
-    
-    public Set getGrants()
+
+    public void setProfileId(String profileId) {
+        stateManager.setId( profileId);
+    }
+
+
+    public Collection<Role> getRoles()
     {
-        return Collections.unmodifiableSet( grants );
+        return stateManager.getReferenceMapField( ROLES_INDEX ).getCurrentValues();
     }
 
+    public void addRole( Role role )
+    {
+        stateManager.getReferenceMapField( ROLES_INDEX ).addValue( role );
+    }
 
-    public Set getDenials()
+    public void removeRole( Role role )
     {
-        return Collections.unmodifiableSet( denials );
+        stateManager.getReferenceMapField( ROLES_INDEX ).removeValue( role );
     }
 
+    public Collection<Permission> getGrants()
+    {
+        return stateManager.getReferenceMapField( GRANTS_INDEX ).getCurrentValues();
+    }
 
-    public Set getRoles()
+    public void addGrant( Permission permission )
     {
-        return Collections.unmodifiableSet( roles );
+        stateManager.getReferenceMapField( GRANTS_INDEX ).addValue( permission );
     }
 
+    public void removeGrant( Permission permission )
+    {
+        stateManager.getReferenceMapField( GRANTS_INDEX ).removeValue( permission );
+    }
 
-    public String getId()
+    public Collection<Permission> getDenials()
     {
-        return id;
+        return stateManager.getReferenceMapField( DENIALS_INDEX ).getCurrentValues();
     }
 
+    public void addDenial( Permission permission )
+    {
+        stateManager.getReferenceMapField( DENIALS_INDEX ).addValue( permission );
+    }
 
+    public void removeDenial( Permission permission )
+    {
+        stateManager.getReferenceMapField( DENIALS_INDEX ).removeValue( permission );
+    }
     public String getUser()
     {
-        return user;
+        return stateManager.getStringValue( USERID_INDEX);
+    }
+
+    public void setUser(String user) {
+        stateManager.setStringValue( USERID_INDEX, user);
     }
 
 
     public String getDescription()
     {
-        return description;
+        return stateManager.getStringValue( DESCRIPTION_INDEX);
+    }
+
+    public void setDescription(String description) {
+        stateManager.setStringValue( DESCRIPTION_INDEX, description);
     }
 
 
-    public String getApplicationName()
+    public boolean isDisabled()
     {
-        return applicationName;
+        return ((SingleValuedField<Boolean>)stateManager.getField( DISABLED_INDEX)).getCurrentValue();
+    }
+
+    public void setDisabled(boolean disabled) {
+        ((SingleValuedField<Boolean>)stateManager.getField( DISABLED_INDEX)).setValue( disabled);
     }
-    
-    
-    public ProfileModifier modifier()
+
+
+    public StateManager getStateManager()
     {
-        return new ProfileModifier( dao, this );
+        return stateManager;
     }
 
-    
-    public boolean isDisabled()
+    public Attributes getAttributes()
     {
-        return disabled;
+        return new BasicAttributes( Constants.OBJECT_CLASS_ID, Constants.POLICY_PROFILE_OC, true );
     }
-    
-    
-    public String toString()
+
+    public void parentSet( StateManager parentSm )
     {
-        return id;
+        stateManager.getReferenceMapField( ROLES_INDEX ).setBackingMap( parentSm.getChildMap(  Application.ROLES_INDEX) );
+        stateManager.getReferenceMapField( GRANTS_INDEX ).setBackingMap( parentSm.getChildMap(  Application.PERMISSIONS_INDEX) );
+        stateManager.getReferenceMapField( DENIALS_INDEX ).setBackingMap( parentSm.getChildMap(  Application.PERMISSIONS_INDEX) );
     }
 }

Modified: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Role.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Role.java?view=diff&rev=496618&r1=496616&r2=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Role.java (original)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/Role.java Tue Jan 16 00:24:45 2007
@@ -20,79 +20,119 @@
 package org.safehaus.triplesec.admin;
 
 
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.Collection;
 
-import org.safehaus.triplesec.admin.dao.RoleDao;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
 
+import org.safehaus.triplesec.admin.persistence.StateManager;
+import org.safehaus.triplesec.admin.persistence.PersistenceCapable;
+import org.safehaus.triplesec.admin.persistence.SimpleRdn;
+import org.safehaus.triplesec.admin.persistence.SingleValuedField;
+import org.safehaus.triplesec.admin.persistence.State;
+import org.safehaus.triplesec.admin.persistence.ReferenceMapField;
+import org.safehaus.triplesec.admin.persistence.ChildMap;
 
-public class Role extends AdministeredEntity
+
+public class Role implements PersistenceCapable
 {
-    private final RoleDao dao;
-    private final String applicationName;
-    private final String name;
-    private final Set grants;
-    private final Set denials;
-    private final String description;
 
-    
-    public Role(String creatorsName, Date createTimestamp, RoleDao dao, String applicationName,
-            String name, String description, Set grants, Set denials)
+    public static final String[] attrs = new String[] {Constants.ROLE_NAME_ID,
+            Constants.DESCRIPTION_ID,
+            Constants.GRANTS_ID,
+            Constants.DENIALS_ID};
+
+    private static final int ROLENAME_INDEX = 0;
+    private static final int DESCRIPTION_INDEX = 1;
+    private static final int GRANTS_INDEX = 2;
+    private static final int DENIALS_INDEX = 3;
+
+    private final StateManager<Role> stateManager;
+
+    public Role()
     {
-        this( creatorsName, createTimestamp, null, null, dao, applicationName, name, description, grants, denials);
+        stateManager = new StateManager<Role>( this );
+
+        stateManager.setRdn( new SimpleRdn( Constants.ROLE_NAME_ID, null, "ou=roles" ) );
+        stateManager.addField( new SingleValuedField<String>( Constants.DESCRIPTION_ID, null ) );
+        stateManager.addField( new ReferenceMapField<Permission>( Constants.GRANTS_ID ) );
+        stateManager.addField( new ReferenceMapField<Permission>( Constants.DENIALS_ID ) );
+
+        stateManager.setState( State.EMPTY );
     }
-    
-    
-    public Role(String creatorsName, Date createTimestamp, String modifiersName, Date modifyTimestamp,
-            RoleDao dao, String applicationName, String name, String description, Set grants, Set denials)
+
+
+    public Role( String roleName, String description )
     {
-        super( creatorsName, createTimestamp, modifiersName, modifyTimestamp );
-        this.dao = dao;
-        this.applicationName = applicationName;
-        this.name = name;
-        this.description = description;
-        this.grants = new HashSet( grants );
-        this.denials = new HashSet( denials );
+        this();
+        stateManager.setStringValue( ROLENAME_INDEX, roleName );
+        stateManager.setStringValue( DESCRIPTION_INDEX, description );
     }
 
 
-    public Set getGrants()
+    public String getRoleName()
     {
-        return Collections.unmodifiableSet( grants );
+        return stateManager.getId();
     }
 
-    public Set getDenials() {
-        return Collections.unmodifiableSet( denials );
+    public void setRoleName( String roleName )
+    {
+        stateManager.setId( roleName );
     }
 
-    public String getName()
+    public String getDescription()
     {
-        return name;
+        return stateManager.getStringValue( DESCRIPTION_INDEX );
     }
 
+    public void setDescription( String description )
+    {
+        stateManager.setStringValue( DESCRIPTION_INDEX, description );
+    }
 
-    public String getDescription()
+    public Collection<Permission> getGrants()
     {
-        return description;
+        return stateManager.getReferenceMapField( GRANTS_INDEX ).getCurrentValues();
     }
 
+    public void addGrant( Permission permission )
+    {
+        stateManager.getReferenceMapField( GRANTS_INDEX ).addValue( permission );
+    }
 
-    public String getApplicationName()
+    public void removeGrant( Permission permission )
     {
-        return applicationName;
+        stateManager.getReferenceMapField( GRANTS_INDEX ).removeValue( permission );
     }
-    
-    
-    public RoleModifier modifier()
+
+    public Collection<Permission> getDenials()
+    {
+        return stateManager.getReferenceMapField( DENIALS_INDEX ).getCurrentValues();
+    }
+
+    public void addDenial( Permission permission )
+    {
+        stateManager.getReferenceMapField( DENIALS_INDEX ).addValue( permission );
+    }
+
+    public void removeDenial( Permission permission )
     {
-        return new RoleModifier( dao, this );
+        stateManager.getReferenceMapField( DENIALS_INDEX ).removeValue( permission );
     }
-    
-    
-    public String toString()
+
+    public StateManager getStateManager()
+    {
+        return stateManager;
+    }
+
+    public Attributes getAttributes()
+    {
+        return new BasicAttributes( Constants.OBJECT_CLASS_ID, Constants.POLICY_ROLE_OC, true );
+    }
+
+    public void parentSet( StateManager parentSm )
     {
-        return name;
+        stateManager.getReferenceMapField( GRANTS_INDEX ).setBackingMap( parentSm.getChildMap(  Application.PERMISSIONS_INDEX) );
+        stateManager.getReferenceMapField( DENIALS_INDEX ).setBackingMap( parentSm.getChildMap(  Application.PERMISSIONS_INDEX) );
     }
 }

Modified: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/TriplesecAdmin.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/TriplesecAdmin.java?view=diff&rev=496618&r1=496616&r2=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/TriplesecAdmin.java (original)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/TriplesecAdmin.java Tue Jan 16 00:24:45 2007
@@ -21,184 +21,172 @@
 
 
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
 
-import org.safehaus.triplesec.admin.dao.ApplicationDao;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.InitialLdapContext;
+import javax.naming.NamingException;
+
 import org.safehaus.triplesec.admin.dao.DaoFactory;
 import org.safehaus.triplesec.admin.dao.ExternalUserDao;
 import org.safehaus.triplesec.admin.dao.GroupDao;
 import org.safehaus.triplesec.admin.dao.HauskeysUserDao;
 import org.safehaus.triplesec.admin.dao.LocalUserDao;
-import org.safehaus.triplesec.admin.dao.PermissionDao;
-import org.safehaus.triplesec.admin.dao.ProfileDao;
-import org.safehaus.triplesec.admin.dao.RoleDao;
 import org.safehaus.triplesec.admin.dao.UserDao;
+import org.safehaus.triplesec.admin.persistence.EntityManager;
+import org.safehaus.triplesec.admin.persistence.EntityManagerImpl;
+
 
- 
 public class TriplesecAdmin
 {
+
+    private EntityManager entityManager;
+    /**
+     * path to app, e.g. appName=mockApplication,ou=applications for apps that are sub-apps of mockApplication.
+     * for top level apps, ou=applications
+     */
+    private String appDn;
     private DaoFactory factory;
-    private ApplicationDao applicationDao;
-    private RoleDao roleDao;
-    private ProfileDao profileDao;
-    private PermissionDao permissionDao;
     private GroupDao groupDao;
     private ExternalUserDao externalUserDao;
     private LocalUserDao localUserDao;
     private HauskeysUserDao hauskeysUserDao;
     private UserDao userDao;
-    
-    
+
+
+    public TriplesecAdmin( EntityManager entityManager, String appDn )
+    {
+        this.entityManager = entityManager;
+        this.appDn = appDn;
+    }
+
+    /**
+     *
+     * @param dirContext
+     * @param rootDn "realm", e.g. dc=example,dc=com
+     */
+    public TriplesecAdmin( DirContext dirContext, String rootDn, String appDn)
+    {
+        this(new EntityManagerImpl(dirContext, rootDn), appDn);
+    }
+
     public TriplesecAdmin( Properties props ) throws DataAccessException
     {
+        String rootDn = ( String ) props.remove("org.apache.directory.triplesec.admin.RootDn");
+        appDn = ( String ) props.remove("org.apache.directory.triplesec.admin.AppDn");
+        DirContext dirContext = null;
+        try
+        {
+            dirContext = new InitialLdapContext( props, null );
+        } catch ( NamingException e )
+        {
+            throw new DataAccessException( "Could not construct DirContext", e);
+        }
+        entityManager = new EntityManagerImpl(dirContext, rootDn);
         factory = DaoFactory.createInstance( props );
-        applicationDao = factory.getApplicationDao();
-        permissionDao = factory.getPermissionDao();
-        roleDao = factory.getRoleDao();
-        profileDao = factory.getProfileDao();
         groupDao = factory.getGroupDao();
         externalUserDao = factory.getExternalUserDao();
         localUserDao = factory.getLocalUserDao();
         hauskeysUserDao = factory.getHauskeysUserDao();
         userDao = factory.getUserDao();
     }
-    
-    
+
+
+    public EntityManager getEntityManager()
+    {
+        return entityManager;
+    }
+
+
     // -----------------------------------------------------------------------
     // User & Respective Modifier Read Operations
     // -----------------------------------------------------------------------
-    
-    
+
+
     public ExternalUserModifier newExternalUser( String id, String referral )
     {
         return new ExternalUserModifier( externalUserDao, id, referral );
     }
-    
-    
+
+
     public LocalUserModifier newLocalUser( String id, String firstName, String lastName, String password )
     {
         return new LocalUserModifier( localUserDao, id, firstName, lastName, password );
     }
-    
-    
+
+
     public HauskeysUserModifier newHauskeysUser( String id, String firstName, String lastName, String password )
     {
         return new HauskeysUserModifier( hauskeysUserDao, id, firstName, lastName, password );
     }
-    
-    
+
+
     public User getUser( String id ) throws DataAccessException
     {
         return userDao.load( id );
     }
-    
-    
+
+
     public boolean hasUser( String id ) throws DataAccessException
     {
         return userDao.hasUser( id );
     }
-    
-    
+
+
     public String getRandomUniqueActivationKey() throws DataAccessException
     {
         return userDao.getRandomUniqueActivationKey();
     }
-    
-    
+
+
     // -----------------------------------------------------------------------
     // Application and ApplicationModifier Read Operations
     // -----------------------------------------------------------------------
-    
-    
-    public ApplicationModifier newApplication( String appRdn )
-    {
-        return new ApplicationModifier( applicationDao, appRdn, 
-            permissionDao, roleDao, profileDao );
-    }
-    
-    
+
+
+
     public Application getApplication( String name ) throws DataAccessException
     {
-        return applicationDao.load( name );
+        String appRdn = getAppRdn(name);
+        return entityManager.find( Application.class, null, appRdn );
     }
-    
-    
-    public boolean hasApplication( String name ) throws DataAccessException
+
+    private String getAppRdn( String name )
     {
-        return applicationDao.has( name );
+        StringBuffer buf = new StringBuffer( );
+        buf.append("appName=").append(name).append(",");
+        buf.append(appDn);
+        return buf.toString();
     }
-    
 
     // -----------------------------------------------------------------------
     // Group and GroupModifier Read Operations
     // -----------------------------------------------------------------------
-    
-    
+
+
     public GroupModifier newGroup( String name, String member )
     {
         Set members = new HashSet();
         members.add( member );
         return new GroupModifier( groupDao, name, members );
     }
-    
-    
-    public GroupModifier newGroup( String name, Set members )
-    {
-        return new GroupModifier( groupDao, name, members );
-    }
-    
-    
-    public Group getGroup( String name ) throws DataAccessException
-    {
-        return groupDao.load( name );
-    }
-
-    
-    // -----------------------------------------------------------------------
-    // Iterator Access
-    // -----------------------------------------------------------------------
-
-    
-    public Iterator groupIterator() throws DataAccessException
-    {
-        return new ReadOnlyIterator( groupDao.iterator() );
-    }
-
 
-    public Iterator applicationIterator() throws DataAccessException
-    {
-        return new ReadOnlyIterator( applicationDao.applicationIterator() );
-    }
-
-
-    public Iterator externalUserIterator() throws DataAccessException
-    {
-        return new ReadOnlyIterator( externalUserDao.iterator() );
-    }
 
-
-    public Iterator localUserIterator() throws DataAccessException
+    public GroupModifier newGroup( String name, Set members )
     {
-        return new ReadOnlyIterator( localUserDao.iterator() );
+        return new GroupModifier( groupDao, name, members );
     }
 
 
-    public Iterator hauskeysUserIterator() throws DataAccessException
-    {
-        return new ReadOnlyIterator( hauskeysUserDao.iterator() );
-    }
-    
-    
-    public Iterator userIterator() throws DataAccessException
+    public Group getGroup( String name ) throws DataAccessException
     {
-        return userDao.iterator();
+        return groupDao.load( name );
     }
 
-
     public void close()
     {
+        entityManager.close();
         factory.close();
     }
 }

Modified: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/DaoFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/DaoFactory.java?view=diff&rev=496618&r1=496616&r2=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/DaoFactory.java (original)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/DaoFactory.java Tue Jan 16 00:24:45 2007
@@ -140,13 +140,13 @@
     }
     
     
-    public abstract PermissionDao getPermissionDao() throws DataAccessException;
+//    public abstract PermissionDao getPermissionDao() throws DataAccessException;
     
-    public abstract ApplicationDao getApplicationDao() throws DataAccessException;
+//    public abstract ApplicationDao getApplicationDao() throws DataAccessException;
 
-    public abstract RoleDao getRoleDao() throws DataAccessException;
+//    public abstract RoleDao getRoleDao() throws DataAccessException;
 
-    public abstract ProfileDao getProfileDao() throws DataAccessException;
+//    public abstract ProfileDao getProfileDao() throws DataAccessException;
 
     public abstract GroupDao getGroupDao() throws DataAccessException;
 

Modified: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/ldap/LdapDaoFactory.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/ldap/LdapDaoFactory.java?view=diff&rev=496618&r1=496616&r2=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/ldap/LdapDaoFactory.java (original)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/dao/ldap/LdapDaoFactory.java Tue Jan 16 00:24:45 2007
@@ -27,15 +27,11 @@
 import javax.naming.ldap.InitialLdapContext;
 
 import org.safehaus.triplesec.admin.DataAccessException;
-import org.safehaus.triplesec.admin.dao.ApplicationDao;
 import org.safehaus.triplesec.admin.dao.DaoFactory;
 import org.safehaus.triplesec.admin.dao.ExternalUserDao;
 import org.safehaus.triplesec.admin.dao.GroupDao;
 import org.safehaus.triplesec.admin.dao.HauskeysUserDao;
 import org.safehaus.triplesec.admin.dao.LocalUserDao;
-import org.safehaus.triplesec.admin.dao.PermissionDao;
-import org.safehaus.triplesec.admin.dao.ProfileDao;
-import org.safehaus.triplesec.admin.dao.RoleDao;
 import org.safehaus.triplesec.admin.dao.UserDao;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -62,28 +58,28 @@
     }
     
     
-    public PermissionDao getPermissionDao() throws DataAccessException
-    {
-        return new LdapPermissionDao( ctx );
-    }
-    
-    
-    public ApplicationDao getApplicationDao() throws DataAccessException
-    {
-        return new LdapApplicationDao( ctx, getPermissionDao(), getRoleDao(), getProfileDao() );
-    }
-
-    
-    public RoleDao getRoleDao() throws DataAccessException
-    {
-        return new LdapRoleDao( ctx ); 
-    }
-
-    
-    public ProfileDao getProfileDao() throws DataAccessException
-    {
-        return new LdapProfileDao( ctx ); 
-    }
+//    public PermissionDao getPermissionDao() throws DataAccessException
+//    {
+//        return new LdapPermissionDao( ctx );
+//    }
+//
+//
+//    public ApplicationDao getApplicationDao() throws DataAccessException
+//    {
+//        return new LdapApplicationDao( ctx, getPermissionDao(), getRoleDao(), getProfileDao() );
+//    }
+//
+//
+//    public RoleDao getRoleDao() throws DataAccessException
+//    {
+//        return new LdapRoleDao( ctx );
+//    }
+//
+//
+//    public ProfileDao getProfileDao() throws DataAccessException
+//    {
+//        return new LdapProfileDao( ctx );
+//    }
 
 
     public GroupDao getGroupDao() throws DataAccessException

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface ChangeListener<T extends PersistenceCapable>
+{
+    void changed(String oldId, String newId, T t);
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChangeListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+import java.util.HashMap;
+
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+import javax.naming.directory.Attributes;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ChildMap<T extends PersistenceCapable> implements Map<String, T>, ChangeListener<T>
+{
+    private final Map<String, T> map = new HashMap<String, T>();
+    private final PersistenceCapable parent;
+    private Class<T> pcClass;
+    private String rdn;
+    private SearchControls controls;
+    private String filter;
+
+    public ChildMap( PersistenceCapable parent, Class<T> pcClass, String rdn, SearchControls controls, String query )
+    {
+        this.parent = parent;
+        this.pcClass = pcClass;
+        this.rdn = rdn;
+        this.controls = controls;
+        this.filter = query;
+        if (parent.getStateManager().getEntityManager() != null) {
+            load();
+        }
+    }
+
+    public void load()
+    {
+        EntityManagerImpl em = parent.getStateManager().getEntityManager();
+        DirContext ctx = em.getDirContext();
+        StringBuffer buf = new StringBuffer(rdn).append(",");
+        buf = parent.getStateManager().getNewName( buf );
+        String name = buf.toString();
+        try
+        {
+            for (NamingEnumeration ne = ctx.search( name, filter, controls) ; ne.hasMoreElements(); ) {
+                SearchResult result = ( SearchResult ) ne.nextElement();
+                Attributes attrs = result.getAttributes();
+                String dn = result.getName();
+                String pcRdn = dn + "," + rdn;
+                T pc = pcClass.newInstance();
+                StateManager<T> sm = pc.getStateManager();
+                sm.load( em, parent.getStateManager(), pcRdn, attrs);
+                String key = sm.getId();
+                map.put(key, (T)pc);
+                sm.addListener( this );
+            }
+        } catch ( NamingException e )
+        {
+            throw new PCException( e);
+        } catch ( InstantiationException e )
+        {
+            throw new PCException( e);
+        } catch ( IllegalAccessException e )
+        {
+            throw new PCException( e);
+        }
+    }
+
+    public int size()
+    {
+        return map.size();
+    }
+
+    public boolean isEmpty()
+    {
+        return map.isEmpty();
+    }
+
+    public boolean containsKey( Object key )
+    {
+        return map.containsKey( key );
+    }
+
+    public boolean containsValue( Object value )
+    {
+        return map.containsValue( value );
+    }
+
+    public T get( Object key )
+    {
+        return map.get( key );
+    }
+
+    public T put( String key, T value )
+    {
+        //TODo probably wrong
+        if ( value.getStateManager().getState() != State.EMPTY )
+        {
+            throw new PCException( "you can only add empty elements, not: " + value.getStateManager().getState() );
+        }
+        T old = map.put( key, value );
+        EntityManager em = parent.getStateManager().getEntityManager();
+        if ( em != null )
+        {
+            if ( old == null )
+            {
+                em.persist( value, parent );
+            } else
+            {
+                //TODO more is needed to merge old values???
+                value.getStateManager().setState( State.DIRTY );
+            }
+        }
+        value.getStateManager().addListener( this);
+        return old;
+    }
+
+    public T remove( Object key )
+    {
+        T old = map.remove( key );
+        if ( old != null )
+        {
+            old.getStateManager().setState( State.DELETED );
+            old.getStateManager().removeListener( this);
+        }
+        return old;
+    }
+
+    public void putAll( Map<? extends String, ? extends T> t )
+    {
+        for ( Entry<? extends String, ? extends T> e : t.entrySet() )
+        {
+            String key = e.getKey();
+            T value = e.getValue();
+            put( key, value );
+        }
+    }
+
+    public void clear()
+    {
+        for ( T value : map.values() )
+        {
+            value.getStateManager().setState( State.DELETED );
+        }
+        map.clear();
+    }
+
+    public Set<String> keySet()
+    {
+        return map.keySet();
+    }
+
+    public Collection<T> values()
+    {
+        return map.values();
+    }
+
+    public Set<Entry<String, T>> entrySet()
+    {
+        return map.entrySet();
+    }
+
+    public void commit( ) throws NamingException
+    {
+        for (T t: map.values())
+        {
+            t.getStateManager().commit();
+        }
+    }
+
+    public void changed( String oldId, String newId, T t )
+    {
+        T oldT = map.remove( oldId);
+        if (t != oldT) {
+            throw new PCException("Mismatch, found object " + oldT + " expected " + t);
+        }
+        map.put(newId, t);
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ChildMap.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.Attribute;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class ConstantRdn implements Rdn
+{
+    private final String rdn;
+
+    public ConstantRdn( String rdn )
+    {
+        this.rdn = rdn;
+    }
+
+    public StringBuffer getOriginalName( StringBuffer buf )
+    {
+        buf.append( rdn );
+        return buf;
+    }
+
+    public StringBuffer getNewName( StringBuffer buf )
+    {
+        return getOriginalName( buf );
+    }
+
+    public boolean hasNewName()
+    {
+        return false;
+    }
+
+    public String getCurrentValue()
+    {
+        throw new PCException("ConstantRdn has no defined Id");
+    }
+
+    public boolean setValue( String newId )
+    {
+        throw new PCException("ConstantRdn has no defined Id");
+    }
+
+    public String getId()
+    {
+        throw new PCException( "Constant Rdn has no id");
+    }
+
+    public ModificationItem getModificationItem()
+    {
+        throw new PCException( "Constant Rdn has no modification items");
+    }
+
+    public Attribute getCurrentAttribute()
+    {
+        throw new PCException( "Constant Rdn has no attributes");
+    }
+
+    public void committed()
+    {
+        throw new PCException( "Constant Rdn cant commit");
+    }
+
+    public void load( Attribute attr )
+    {
+        throw new PCException( "Constant Rdn cant load");
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ConstantRdn.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface EntityManager
+{
+    void persist( PersistenceCapable pc, PersistenceCapable parentPc );
+
+//    <T> T merge(T t);
+
+    void remove(PersistenceCapable pc);
+
+    <T extends PersistenceCapable> T find(Class<T> aClass, PersistenceCapable parent, String dn);
+
+//    <T> T getReference(java.lang.Class<T> aClass, java.lang.Object object);
+
+    void flush();
+
+    void refresh(PersistenceCapable pc);
+
+    void clear();
+
+//    boolean contains(java.lang.Object object);
+
+    Query createQuery(String appRdn);
+
+    void close();
+
+    boolean isOpen();
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.DirContext;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class EntityManagerImpl implements EntityManager
+{
+    private final DirContext dirContext;
+    private boolean open = true;
+    private final StateManager rootSm;
+
+    private final Map<String, PersistenceCapable> pcs = new HashMap<String, PersistenceCapable>();
+    private final Map<Class, Map<String, Object>> dirty = new HashMap<Class, Map<String, Object>>();
+
+    public EntityManagerImpl( DirContext dirContext, String rootDn )
+    {
+        this.dirContext = dirContext;
+        ConstantRdn rdn = new ConstantRdn( rootDn );
+        rootSm = new RootStateManager( rdn );
+    }
+
+    public void persist( PersistenceCapable pc, PersistenceCapable parentPc )
+    {
+        StateManager sm = pc.getStateManager();
+        if ( sm.getState() != State.EMPTY )
+        {
+            throw new IllegalStateException( "State should be EMPTY to persist, not " + sm.getState() );
+        }
+        sm.setState( State.NEW );
+        sm.setEntityManager( this );
+        sm.setParent( parentPc == null ? null : parentPc.getStateManager() );
+        Class cl = pc.getClass();
+        Map<String, Object> pcs = dirty.get( pc.getClass() );
+        if ( pcs == null )
+        {
+            pcs = new HashMap<String, Object>();
+            dirty.put( cl, pcs );
+        }
+        pcs.put( sm.getNewName(), pc );
+    }
+
+    public void remove( PersistenceCapable pc )
+    {
+        StateManager sm = pc.getStateManager();
+        switch ( sm.getState() )
+        {
+            case EMPTY:
+                return;
+            case NEW:
+                sm.setState( State.EMPTY );
+                break;
+            case CLEAN:
+            case DIRTY:
+                sm.setState( State.DELETED );
+                break;
+            case DELETED:
+                return;
+            default:
+                throw new PCException( "Unknown change in State enumeraion, state: " + sm.getState() );
+
+        }
+        Map<String, Object> pcs = dirty.get( pc.getClass() );
+        if ( pcs != null )
+        {
+            pcs.remove( sm.getNewName() );
+        }
+    }
+
+    public <T extends PersistenceCapable> T find( Class<T> aClass, PersistenceCapable parent, String rdn )
+    {
+        String dn;
+        if ( parent == null )
+        {
+            dn = rdn;
+        } else
+        {
+            StringBuffer buf = new StringBuffer( rdn ).append( "," );
+            dn = parent.getStateManager().getNewName( buf ).toString();
+        }
+        try
+        {
+            Attributes attrs = dirContext.getAttributes( dn );
+            T pc = aClass.newInstance();
+            StateManager sm = pc.getStateManager();
+            sm.load( this, parent == null ? null : parent.getStateManager(), rdn, attrs );
+            return pc;
+        } catch ( NamingException e )
+        {
+            throw new PCException( e );
+        } catch ( InstantiationException e )
+        {
+            throw new PCException( e );
+        } catch ( IllegalAccessException e )
+        {
+            throw new PCException( e );
+        }
+    }
+
+    public void flush()
+    {
+    }
+
+    public void refresh( PersistenceCapable pc )
+    {
+    }
+
+    public void clear()
+    {
+        dirty.clear();
+    }
+
+    public Query createQuery( String appRdn )
+    {
+        return null;
+    }
+
+    public void close()
+    {
+        try
+        {
+            dirContext.close();
+        } catch ( NamingException e )
+        {
+            throw new RuntimeException( e );
+        } finally
+        {
+            open = false;
+        }
+
+    }
+
+    public boolean isOpen()
+    {
+        return open;
+    }
+
+    public DirContext getDirContext()
+    {
+        return dirContext;
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/EntityManagerImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.Attribute;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface Field
+{
+    String getId();
+    
+    ModificationItem getModificationItem();
+
+    Attribute getCurrentAttribute();
+
+    void committed();
+
+    void load( Attribute attr );
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Field.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import javax.naming.directory.DirContext;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.SchemaViolationException;
+import javax.naming.NamingException;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class HiddenChild
+{
+
+    private final String rdn;
+    private final Attributes attrs;
+
+    public HiddenChild( String rdn, Attributes attrs )
+    {
+        this.rdn = rdn;
+        this.attrs = attrs;
+    }
+
+    public void create( StateManager parent )
+    {
+        DirContext ctx = parent.getEntityManager().getDirContext();
+        String fullName = getFullName( parent );
+        try
+        {
+            ctx.createSubcontext( fullName, attrs );
+        } catch ( NamingException e )
+        {
+            throw new PCException( "Could not create hidden child context", e );
+        }
+
+    }
+
+    public void destroy( StateManager parent )
+    {
+        DirContext ctx = parent.getEntityManager().getDirContext();
+        String fullName = getFullName( parent );
+        try
+        {
+            ctx.destroySubcontext( fullName );
+        } catch ( SchemaViolationException e )
+        {
+            throw new PCException( "Could not delete " + fullName + ", something under it still exists and is in use", e );
+        } catch ( NamingException e )
+        {
+            throw new PCException(e);
+        }
+    }
+
+    private String getFullName( StateManager parent )
+    {
+        StringBuffer buf = new StringBuffer( rdn ).append( "," );
+        buf = parent.getNewName( buf );
+        return buf.toString();
+    }
+
+
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/HiddenChild.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/MultiValuedField.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/MultiValuedField.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/MultiValuedField.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/MultiValuedField.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,194 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.persistence;
+
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+
+public class MultiValuedField <T> implements Field
+{
+    private final String id;
+    private final Set<T> initial;
+    private final Set<T> added;
+    private final Set<T> deleted;
+    private final Set<T> current;
+
+
+    public MultiValuedField( String id, Set<T> initial )
+    {
+        this.id = id;
+        this.initial = initial == null? new HashSet<T>(): new HashSet<T>( initial ) ;
+        this.current = new HashSet<T>( this.initial );
+        this.deleted = new HashSet<T>();
+        this.added = new HashSet<T>();
+    }
+
+
+    public boolean addValue( T value )
+    {
+        // if we have the value then exit and return false
+        if ( current.contains( value ) )
+        {
+            return false;
+        }
+
+        // if the value is not present but was deleted before then undelete it
+        if ( deleted.contains( value ) )
+        {
+            deleted.remove( value );
+        }
+        // if value was not deleted before then add to added
+        else
+        {
+            added.add( value );
+        }
+
+        return current.add( value );
+    }
+
+
+    public boolean removeValue( T value )
+    {
+        // if we don't have the value then return false
+        if ( ! current.contains( value ) )
+        {
+            return false;
+        }
+
+        // if the value was added before then we unadd it 
+        if ( added.contains( value ) )
+        {
+            added.remove( value );
+        }
+        // if the value was not added before then we delete it
+        else
+        {
+            deleted.add( value );
+        }
+
+        return current.remove( value );
+    }
+
+
+    public boolean isUpdateNeeded()
+    {
+        return added.size() + deleted.size() > 0;
+    }
+
+
+    public Set<T> getInitialValues()
+    {
+        return initial;
+    }
+
+
+    public Set<T> getCurrentValues()
+    {
+        return Collections.unmodifiableSet( current );
+    }
+
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public ModificationItem getModificationItem()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return null;
+        }
+
+        BasicAttribute attr = new BasicAttribute( id );
+        if ( added.size() == 0 && deleted.size() > 0 )
+        {
+            for ( Object aDeleted : deleted )
+            {
+                attr.add( aDeleted );
+            }
+            return new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+        }
+
+        if ( added.size() > 0 && deleted.size() == 0 )
+        {
+            for ( Object anAdded : added )
+            {
+                attr.add( anAdded );
+            }
+            return new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
+        }
+
+        for ( Object aCurrent : current )
+        {
+            attr.add( aCurrent );
+        }
+        return new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    }
+
+    public Attribute getCurrentAttribute()
+    {
+        if ( !isUpdateNeeded() )
+        {
+            return null;
+        }
+        BasicAttribute attr = new BasicAttribute( id );
+        for ( T aCurrent : current )
+        {
+            attr.add( aCurrent );
+        }
+        return attr;
+    }
+
+    public void committed()
+    {
+        initial.clear();
+        initial.addAll( current );
+    }
+
+    public void load( Attribute attr )
+    {
+        initial.clear();
+        added.clear();
+        deleted.clear();
+        current.clear();
+        for (int i = 0; i < attr.size(); i++) {
+            try
+            {
+                T obj = ( T ) attr.get(i);
+                initial.add(obj);
+                current.add(obj);
+            } catch ( NamingException e )
+            {
+                throw new PCException( "Could not fetch attr value", e);
+            }
+        }
+
+    }
+}

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class PCException extends RuntimeException
+{
+    public PCException()
+    {
+    }
+
+    public PCException( String message )
+    {
+        super( message );
+    }
+
+    public PCException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+    public PCException( Throwable cause )
+    {
+        super( cause );
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PCException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import javax.naming.directory.Attributes;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface PersistenceCapable<T extends PersistenceCapable>
+{
+    StateManager<T> getStateManager();
+
+    Attributes getAttributes();
+
+    void parentSet(StateManager parentSm);
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/PersistenceCapable.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface Query
+{
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Query.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public interface Rdn extends Field
+{
+
+    StringBuffer getOriginalName(StringBuffer buf);
+    StringBuffer getNewName(StringBuffer buf);
+    boolean hasNewName();
+    String getCurrentValue();
+
+    boolean setValue( String newId );
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/Rdn.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Collection;
+
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+
+public class ReferenceMapField<T extends PersistenceCapable> implements Field, ChangeListener<T>
+{
+    private final String id;
+    private ChildMap<T> backingMap;
+    private final Map<String, T> initial;
+    private final Map<String, T> added;
+    private final Map<String, T> deleted;
+    private final Map<String, T> current;
+
+
+    public ReferenceMapField( String id )
+    {
+        this.id = id;
+        this.initial = new HashMap<String, T>();
+        this.current = new HashMap<String, T>( this.initial );
+        this.deleted = new HashMap<String, T>();
+        this.added = new HashMap<String, T>();
+    }
+
+    public void setBackingMap( ChildMap<T> backingMap )
+    {
+        this.backingMap = backingMap;
+    }
+
+    public boolean addKey( String key )
+    {
+        T t = backingMap.get( key );
+        return addValue( t );
+    }
+
+    public boolean addValue( T t )
+    {
+        String key = t.getStateManager().getId();
+        // if we have the value then exit and return false
+        if ( current.containsKey( key ) )
+        {
+            return false;
+        }
+        // if the value is not present but was deleted before then undelete it
+        if ( deleted.containsKey( key ) )
+        {
+            deleted.remove( key );
+        }
+        // if value was not deleted before then add to added
+        else
+        {
+            added.put( key, t );
+        }
+
+        return current.put( key, t ) != null;
+    }
+
+
+    public boolean removeKey( String key )
+    {
+        T t = backingMap.get( key );
+        return removeValue( t );
+    }
+
+    public boolean removeValue( T t )
+    {
+        String key = t.getStateManager().getId();
+        // if we don't have the value then return false
+        if ( ! current.containsKey( key ) )
+        {
+            return false;
+        }
+
+        // if the value was added before then we unadd it
+        if ( added.containsKey( key ) )
+        {
+            added.remove( key );
+        }
+        // if the value was not added before then we delete it
+        else
+        {
+            deleted.put( key, t );
+        }
+
+        return current.remove( key ) != null;
+    }
+
+
+    public boolean isUpdateNeeded()
+    {
+        return added.size() + deleted.size() > 0;
+    }
+
+
+    public Set<String> getInitialKeys()
+    {
+        return Collections.unmodifiableSet( initial.keySet() );
+    }
+
+
+    public Set<String> getCurrentKeys()
+    {
+        return Collections.unmodifiableSet( current.keySet() );
+    }
+
+    public Collection<T> getCurrentValues()
+    {
+        return current.values();
+    }
+
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public ModificationItem getModificationItem()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return null;
+        }
+
+        BasicAttribute attr = new BasicAttribute( id );
+        if ( added.size() == 0 && deleted.size() > 0 )
+        {
+            for ( String aDeleted : deleted.keySet() )
+            {
+                attr.add( aDeleted );
+            }
+            return new ModificationItem( DirContext.REMOVE_ATTRIBUTE, attr );
+        }
+
+        if ( added.size() > 0 && deleted.size() == 0 )
+        {
+            for ( String anAdded : added.keySet() )
+            {
+                attr.add( anAdded );
+            }
+            return new ModificationItem( DirContext.ADD_ATTRIBUTE, attr );
+        }
+
+        for ( String aCurrent : current.keySet() )
+        {
+            attr.add( aCurrent );
+        }
+        return new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attr );
+    }
+
+    public Attribute getCurrentAttribute()
+    {
+        if ( !isUpdateNeeded() )
+        {
+            return null;
+        }
+        BasicAttribute attr = new BasicAttribute( id );
+        for ( String aCurrent : current.keySet() )
+        {
+            attr.add( aCurrent );
+        }
+        return attr;
+    }
+
+    public void committed()
+    {
+        initial.clear();
+        initial.putAll( current );
+        added.clear();
+        deleted.clear();
+    }
+
+    public void load( Attribute attr )
+    {
+        initial.clear();
+        added.clear();
+        deleted.clear();
+        current.clear();
+        for ( int i = 0; i < attr.size(); i++ )
+        {
+            try
+            {
+                String key = ( String ) attr.get( i );
+                T t = backingMap.get( key );
+                initial.put( key, t );
+                current.put( key, t );
+            } catch ( NamingException e )
+            {
+                throw new PCException( "Could not fetch attr value", e );
+            }
+        }
+
+    }
+
+    public void changed( String oldId, String newId, T t )
+    {
+        if ( removeKey( oldId ) )
+        {
+            addValue( t );
+        }
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/ReferenceMapField.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class RootStateManager extends StateManager
+{
+    public RootStateManager( ConstantRdn rdn )
+    {
+        super( rdn );
+    }
+
+    public void setParent( StateManager parent )
+    {
+    }
+
+    public synchronized int addField( Field field )
+    {
+        throw new PCException( "can't add fields to root");
+    }
+
+    public void setRdn( Rdn rdn )
+    {
+    }
+
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/RootStateManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.safehaus.triplesec.admin.persistence;
+
+/**
+ * @version $Rev:$ $Date:$
+ */
+public class SimpleRdn extends SingleValuedField<String> implements Rdn
+{
+
+    private final String parentRdn;
+
+    public SimpleRdn( String id, String initial, String parentRdn )
+    {
+        super( id, initial );
+        this.parentRdn = parentRdn;
+    }
+
+    public StringBuffer getOriginalName( StringBuffer buf )
+    {
+        buf.append(getId()).append("=").append(getInitialValue());
+        if ( parentRdn != null )
+        {
+            buf.append(",").append(parentRdn);
+        }
+        return buf;
+    }
+
+    public StringBuffer getNewName( StringBuffer buf )
+    {
+        buf.append(getId()).append("=").append(getCurrentValue());
+        if ( parentRdn != null )
+        {
+            buf.append(",").append(parentRdn);
+        }
+        return buf;
+    }
+
+    public boolean hasNewName()
+    {
+        return isUpdateNeeded();
+    }
+}

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SimpleRdn.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SingleValuedField.java
URL: http://svn.apache.org/viewvc/directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SingleValuedField.java?view=auto&rev=496618
==============================================================================
--- directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SingleValuedField.java (added)
+++ directory/sandbox/triplesec-jacc2/admin-api2/src/main/java/org/safehaus/triplesec/admin/persistence/SingleValuedField.java Tue Jan 16 00:24:45 2007
@@ -0,0 +1,143 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.safehaus.triplesec.admin.persistence;
+
+
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.ModificationItem;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+
+import org.safehaus.triplesec.admin.persistence.Field;
+
+
+public class SingleValuedField<T> implements Field
+{
+    private final String id;
+    private T initial;
+    private T current;
+
+
+    public SingleValuedField( String id, T initial )
+    {
+        this.id = id;
+        this.initial = initial;
+        this.current = initial;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public T getInitialValue()
+    {
+        return initial;
+    }
+
+
+    public T getCurrentValue()
+    {
+        return current;
+    }
+
+
+    public boolean isUpdateNeeded()
+    {
+        if ( initial != null )
+        {
+            return ! initial.equals( current );
+        }
+
+        return current != null;
+    }
+
+
+    public boolean setValue( T value )
+    {
+        if ( current != null && current.equals( value ) )
+        {
+            return false;
+        }
+
+        // ignore replacing null with emtpy string which causes unnecesary noise
+        if ( current == null && ( value == null || ( value instanceof String && ( ( String ) value ).length() == 0 ) ) )
+        {
+            return false;
+        }
+
+        current = value;
+        return true;
+    }
+
+
+    public ModificationItem getModificationItem()
+    {
+        if ( initial == current )
+        {
+            return null;
+        }
+
+        if ( initial == null )
+        {
+            return new ModificationItem( DirContext.ADD_ATTRIBUTE, new BasicAttribute( id, current ) );
+        }
+
+        if ( current == null )
+        {
+            return new ModificationItem( DirContext.REMOVE_ATTRIBUTE, new BasicAttribute( id ) );
+        }
+
+        if ( ! initial.equals( current ) )
+        {
+            return new ModificationItem( DirContext.REPLACE_ATTRIBUTE, new BasicAttribute( id, current ) );
+        }
+
+        return null;
+    }
+
+    public Attribute getCurrentAttribute()
+    {
+        if ( ! isUpdateNeeded() )
+        {
+            return null;
+        }
+        return new BasicAttribute( id, current );
+    }
+
+    public void committed()
+    {
+        initial = current;
+    }
+
+    public void load( Attribute attr )
+    {
+        try
+        {
+            initial = (T) attr.get();
+        } catch ( NamingException e )
+        {
+            throw new PCException("Failed to load attribute", e);
+        }
+        current = initial;
+    }
+
+}



Mime
View raw message