jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AElsher...@idc.com
Subject Re: Jackrabbit Observation with Spring
Date Thu, 04 Feb 2010 13:27:33 GMT
Hi Alexander,

Thank you very much for replying. Here I provide more details:

Here're the java classes:
-------------------------------------

public class ListenerProperties {
        private EventListener eventListener;
        private int eventTypes;
        private String absPath;
        private boolean isDeep;
        private String[] uuid;
        private String[] nodeTypeName;
        private boolean noLocal;
        //setters.. and getters..
}
**********************************************************
public interface XListener extends EventListener {
        ListenerProperties getListenerProperties();
}
**********************************************************
public class NodeAddedListener implements XListener {
        @Override
        public ListenerProperties getListenerProperties() {
                ListenerProperties listenerProperites = new 
ListenerProperties();
                listenerProperites.setEventListener(this);
                listenerProperites.setEventTypes(Event.NODE_ADDED);
                listenerProperites.setAbsPath("/");
                listenerProperites.setDeep(true);
                listenerProperites.setUuid(null);
                listenerProperites.setNodeTypeName(null);
                listenerProperites.setNoLocal(false);
                return listenerProperites;
        }
        @Override
        public void onEvent(EventIterator arg0) {
                System.out.println(" *************************");
                System.out.println("            ** New node created **");
                System.out.println(" *************************");
        }
}
**********************************************************
public class ListenerRegistrar {
        @Resource  private JcrTemplate jcrTemplate;
        private Set<XListener> listeners;
 
        public ListenerRegistrar(Set<XListener> listeners){
                this.listeners = listeners;
        }
 
        @PostConstruct
        public void register(){
                jcrTemplate.execute(new JcrCallback() {
            public Object doInJcr(final Session session) throws 
RepositoryException {
                ObservationManager observationManager =
                    session.getWorkspace().getObservationManager();
                for(XListener listener : listeners){
                                ListenerProperties listenerProperties = 
listener.getListenerProperties();
 
observationManager.addEventListener(listenerProperties.getEventListener(),
 listenerProperties.getEventTypes(), listenerProperties.getAbsPath(),
 listenerProperties.isDeep(), listenerProperties.getUuid(),
 listenerProperties.getNodeTypeName(), listenerProperties.isNoLocal());
                        }
                                // FYI Alexander, here I even tried to 
call observationManager.getRegisteredEventListeners().getSize(), thought
                                // maybe it's a session issue, then it 
always returned -1
                return null;
            }
        });
        }
}
**********************************************************
And I added the following to the applicationContext.xml:
---------------------------------------------------------------------------------

        <bean id="listenerRegistrar" 
                class="events.ListenerRegistrar">
                <constructor-arg>
                        <set>
                                <ref bean="nodeAddedListener"/>
                        </set>
                </constructor-arg>
        </bean>
 
        <bean id="nodeAddedListener"    class="events.NodeAddedListener"/>

**********************************************************


 
I used OCM to CRUD the items.
so I have MyItem object as following:

@Configurable
@Node(jcrMixinTypes = "mix:versionable")
public class MyItem {
        @NotNull @Field (path = true) private String path;
        @Field (uuid = true) private String uuid;
        @Field private String body;
        // setters and getters..
}
**********************************************************
@Repository
public class OcmBioRepositoryImpl implements OcmBioRepository {

        @Resource private JcrTemplate jcrTemplate;
        private Mapper mapper;
 
        @PostConstruct
        private void initializeMapper(){
                List<Class> classes = new ArrayList<Class>();
                classes.add(MyItem.class);
                this.mapper = new AnnotationMapperImpl(classes);
        }
 
        public void insert(final MyItem myItem){
                jcrTemplate.execute(new JcrCallback() {
            public Object doInJcr(final Session session) throws 
RepositoryException {
                ObjectContentManager ocm = new 
ObjectContentManagerImpl(session, mapper);
                ocm.insert(myItem);
                        ocm.save();
                        return null;
            }
        });
        }

 
***************************************************************************************

        Hope this is helpfull.
 
        Thank you in advance


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message