Re: OSUser and Hibernate: couple of questions

Konstantin Priblouda <[email protected]>
Newsgroups gmane.comp.java.open-symphony.devel
Message-ID <[email protected]>
--- Ilja <[email protected]> wrote:
> Thanks,
> 
> Can you give me directions on how to use propertyset
> to store other
> user-information? I'm desperately looking on how to
> do it, osuser seems
> to be perfect and if this is possible it would be
> awsome
> 
> And how do you instantly save a user with all his
> information directly?
> Without first saving only a username, now you have
> to save it first and
> then update it....
>

Of course I have first to create  my user/group, 
and then save properties there.



That's my 2 methods allowing
marshalling/unmarschalling of generic java bean into
user / group properties
( Entity happens to be base interface for bothz user &
group ). You owe me a beer :) 
---%<------------------
   /**
     * populate bean with properties from entity
     *
     * @param entity                        
Description of Parameter
     * @param bean                          
Description of Parameter
     * @exception IllegalAccessException    
Description of Exception
     * @exception InvocationTargetException 
Description of Exception
     */
    public static void populateBean(Entity entity,
Object bean) throws IllegalAccessException,
InvocationTargetException {
        PropertySet properties =
entity.getPropertySet();
        BeanIntrospectorPropertySet beanSet = new
BeanIntrospectorPropertySet();
        beanSet.setBean(bean);

        _log.debug("looking for properties starting
with: " + bean.getClass().getName());
        Collection keys =
properties.getKeys(bean.getClass().getName());
        int offset =
bean.getClass().getName().length() + 1;

        String key;
        for (Iterator iter = keys.iterator();
iter.hasNext(); ) {
            key = (String) iter.next();
            if (_log.isDebugEnabled()) {
                _log.debug("setting property : " +
key.substring(offset));
            }
           
beanSet.setAsActualType(key.substring(offset),
properties.getAsActualType(key));
        }

    }


    /**
     * save properties for this entity
     *
     * @param entity                         entity to
associate data with
     * @param bean                           bean
holding those properties
     * @exception IllegalAccessException    
Description of Exception
     * @exception InvocationTargetException 
Description of Exception
     * @exception NoSuchMethodException     
Description of Exception
     */
    public static void saveBean(Entity entity, Object
bean) throws IllegalAccessException,
        InvocationTargetException,
NoSuchMethodException {
        PropertySet property =
entity.getPropertySet();
        BeanIntrospectorPropertySet beanSet = new
BeanIntrospectorPropertySet();
        beanSet.setBean(bean);

        String prefix = bean.getClass().getName() +
".";

        for (Iterator ii =
property.getKeys(prefix).iterator(); ii.hasNext(); ) {
            property.remove((String) ii.next());
        }
        String key;
        String newKey;
        for (Iterator iter =
beanSet.getKeys().iterator(); iter.hasNext(); ) {
            key = (String) iter.next();

            if (!beanSet.isSettable(key)) {
                continue;
            }
            if (_log.isDebugEnabled()) {
                _log.debug("property " + key + " is
settable. saving it");
            }
            newKey = prefix + key;

            Object obj = beanSet.getAsActualType(key);

            if (property.exists(newKey)) {
                _log.debug("property exists, remove it
first");
                property.remove(newKey);
            }
            if (obj != null) {
                // need saving only if not null
                _log.debug("really saving...");
                property.setAsActualType(newKey, obj);
            }

        }
    }

---%<----------------


=====
----[ Konstantin Pribluda ( ko5tik ) ]----------------
Zu Verstärkung meines Teams suche ich ab Sofort einen
Softwareentwickler[In] für die Festanstellung. 
Arbeitsort: Mainz 
Skills:  Programieren, Kentnisse in OpenSource-Bereich
----[ http://www.pribluda.de ]------------------------

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.