Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
GRANITE DATA SERVICES
Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
This file is part of Granite Data Services.
Granite Data Services is free software; you can redistribute it and/or modify
it under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
Granite Data Services is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
for more details.
You should have received a copy of the GNU Library General Public License
along with this library; if not, see .
*/
package org.granite.tide;
import java.io.Serializable;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;
import org.granite.context.GraniteContext;
import org.granite.logging.Logger;
import org.granite.messaging.amf.io.util.ClassGetter;
import org.granite.messaging.amf.io.util.DefaultClassGetter;
import org.granite.messaging.amf.io.util.externalizer.annotation.ExternalizedBean;
import org.granite.messaging.service.ServiceException;
import org.granite.messaging.service.ServiceInvocationContext;
import org.granite.tide.async.AsyncPublisher;
import org.granite.tide.data.DataMergeContext;
import org.granite.tide.data.DataMergeContext.CacheKey;
import org.granite.util.ArrayUtil;
/**
* @author William DRAI
*/
public abstract class TideServiceContext implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(TideServiceContext.class);
protected static final Object[] EMPTY_ARGS = new Object[0];
public static final String COMPONENT_ATTR = "__TIDE_COMPONENT__";
public static final String COMPONENT_CLASS_ATTR = "__TIDE_COMPONENT_CLASS__";
private String sessionId = null;
public TideServiceContext() throws ServiceException {
}
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public void initCall() {
}
public Object adjustInvokee(Object instance, String componentName, Set> componentClasses) {
return instance;
}
public Object[] beforeMethodSearch(Object instance, String methodName, Object[] args) {
return new Object[] { args[2], args[3] };
}
public abstract Object findComponent(String componentName, Class> componentClass);
public abstract Set> findComponentClasses(String componentName, Class> componentClass);
public abstract void prepareCall(ServiceInvocationContext context, IInvocationCall call, String componentName, Class> componentClass);
public abstract IInvocationResult postCall(ServiceInvocationContext context, Object result, String componentName, Class> componentClass);
public void postCallFault(ServiceInvocationContext context, Throwable t, String componentName, Class> componentClass) {
}
protected abstract AsyncPublisher getAsyncPublisher();
public void sendEvent(String componentName, Class> componentClass) {
AsyncPublisher publisher = getAsyncPublisher();
if (publisher != null) {
IInvocationResult eventResult = postCall(null, null, componentName, componentClass);
publisher.publishMessage(sessionId, eventResult);
}
}
/**
* Create a TidePersistenceManager
*
* @param create create if not existent (can be false for use in entity merge)
* @return a PersistenceContextManager
*/
protected abstract TidePersistenceManager getTidePersistenceManager(boolean create);
public Object mergeExternal(Object obj, Object previous) {
TidePersistenceManager pm = getTidePersistenceManager(false);
ClassGetter classGetter = GraniteContext.getCurrentInstance().getGraniteConfig().getClassGetter();
return mergeExternal(pm, classGetter, obj, previous, null, null);
}
@SuppressWarnings("unchecked")
protected Object mergeExternal(TidePersistenceManager pm, ClassGetter classGetter, Object obj, Object previous, Object owner, String propertyName) {
if (obj == null)
return null;
if (pm == null)
return obj;
if (!classGetter.isInitialized(owner, propertyName, obj)) {
if (previous != null)
return previous;
return obj;
}
Map