Last active
May 17, 2018 11:08
-
-
Save aino-prashant/072516fd16278c4083dafb608e96bbc6 to your computer and use it in GitHub Desktop.
Issue related to Provider TypeKey .GeneratedAltDynamicEntityPojoMarkerImpl is the generated class (line No 93)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.appops.altshared.shared.altcore.altentity.type; | |
import java.io.Serializable; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.logging.Level; | |
import org.appops.altshared.client.binding.AppOpsCommonGinjector; | |
import org.appops.altshared.shared.InstanceProvider; | |
import org.appops.altshared.shared.PojoMarker; | |
import org.appops.altshared.shared.altcore.altentity.AltEntity; | |
import org.appops.altshared.shared.altcore.altentity.type.AltDynamicEntity; | |
import org.appops.altshared.shared.altcore.altentity.type.AltType; | |
import org.appops.altshared.shared.altcore.annotations.NoDeepCopy; | |
import org.appops.altshared.shared.altcore.annotations.Worker; | |
import org.appops.altshared.shared.jsonizer.base.AltJsonizerException; | |
import org.appops.altshared.shared.jsonizer.base.Constants; | |
import org.appops.altshared.shared.jsonizer.base.CustomSourceTypeKey; | |
import org.appops.altshared.shared.jsonizer.base.InstanceRegistry; | |
import org.appops.altshared.shared.jsonizer.base.JsonCollection; | |
import org.appops.altshared.shared.jsonizer.base.ManageInstanceRegistry; | |
import org.appops.altshared.shared.jsonizer.base.ProviderTypeKey; | |
import org.appops.altshared.shared.jsonizer.base.TypeKey; | |
import org.appops.altshared.shared.jsonizer.base.TypedAs; | |
import org.appops.altshared.shared.sync.IntrinsicChange; | |
import org.appops.altshared.shared.sync.PojoMarkerChange; | |
import org.appops.altshared.shared.sync.SyncChange; | |
import org.appops.jsonizer.client.base.DeepCopy; | |
import org.appops.jsonizer.client.base.ManagePojo; | |
import org.appops.jsonizer.client.base.ObjectPeer; | |
import org.appops.jsonizer.client.base.PojoMarkerImplInstantiator; | |
import org.appops.jsonizer.client.base.TypeInfo; | |
import org.appops.jsonizer.client.base.TypeKeyFactory; | |
import org.appops.jsonizer.client.base.Utils; | |
import org.appops.jsonizer.client.binding.JsonizerGinjector; | |
import org.appops.jsonizer.client.impls.BasePojoMarkerImpl; | |
import org.appops.jsonizer.client.impls.PojoMarkerImplInstantiatorRegistry; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListAddElementChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListClearChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListRemoveChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyCollectionChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyHashMapChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyHashSetChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyLinkedListAddElementChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyPojoMarkerChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyTreeMapChangeEvent; | |
import com.google.gwt.core.client.GWT; | |
import com.google.gwt.core.client.JavaScriptObject; | |
import com.google.gwt.event.shared.SimpleEventBus; | |
import com.google.gwt.json.client.JSONObject; | |
public class GeneratedAltDynamicEntityPojoMarkerImpl extends | |
org.appops.altshared.shared.altcore.altentity.type.AltDynamicEntity implements | |
org.appops.jsonizer.client.base.Jsonizer, java.io.Serializable, | |
org.appops.jsonizer.client.base.JsonizerTypeInfo, org.appops.jsonizer.client.base.ManagePojo, | |
org.appops.jsonizer.client.base.ObjectPeer, org.appops.altshared.shared.jsonizer.base.ManageInstanceRegistry, | |
org.appops.altshared.shared.sync.SyncInternal, | |
org.appops.sync.client.eventconfiguration.handlers.ApplyPojoMarkerChangeEventHandler, | |
org.appops.sync.client.eventconfiguration.handlers.ApplyCollectonModifiedEventHandler, | |
org.appops.jsonizer.client.PojoMarkerHelper, org.appops.jsonizer.client.base.DeepCopy, | |
org.appops.jsonizer.client.base.ManageCopy, org.appops.jsonizer.client.base.Selector, | |
org.appops.altshared.shared.jsonizer.base.HasReferrer { | |
private BasePojoMarkerImpl _impl = JsonizerGinjector.INSTANCE.getBasePojoMarkerImpl(); | |
private static HashMap<String, TypeKey> typeMap = new HashMap<String, TypeKey>(); | |
private SimpleEventBus eventBus = null; | |
private HashMap<String, TypeInfo> typeInfoMap = null; | |
private HashMap<Object, Object> deepCopyMap = null; | |
public GeneratedAltDynamicEntityPojoMarkerImpl() { | |
_impl.setTypeMap(typeMap); | |
_impl.setPojoMarkerImpl(this); | |
_impl.setPojomarkerKey("org.appops.altshared.shared.altcore.altentity.type.AltDynamicEntity"); | |
this.setInstanceProvider(); | |
generateTypeInfoMap(); | |
} | |
static { | |
typeMap.put( | |
"propertymap", | |
new CustomSourceTypeKey(TypedAs.FIXED, "java.util.HashMap", "type", new ArrayList<TypeKey>(Arrays | |
.asList(new TypeKey(TypedAs.FIXED, "java.lang.String"), new TypeKey(TypedAs.VARIANT, | |
"java.io.Serializable"))))); | |
typeMap.put("isdirty", TypeKeyFactory.getTypeKey("boolean")); | |
typeMap.put("ispartial", TypeKeyFactory.getTypeKey("boolean")); | |
typeMap.put("isautotyped", TypeKeyFactory.getTypeKey("boolean")); | |
ArrayList<TypeKey> arrProviderTypeKeys = new ArrayList<TypeKey>(); | |
TypeKey propertyKeyTypeKey = new TypeKey(TypedAs.FIXED, String.class.getCanonicalName()); | |
TypeKey propertyValTypeKey = new TypeKey(TypedAs.FIXED, String.class.getCanonicalName()); | |
arrProviderTypeKeys.add(propertyKeyTypeKey); | |
arrProviderTypeKeys.add(propertyValTypeKey); | |
typeMap.put("type", new ProviderTypeKey("typename", AppOpsCommonGinjector.INSTANCE.getTypeProvider(), | |
TypedAs.VARIANT, "org.appops.altshared.shared.altcore.altentity.type.AltType", arrProviderTypeKeys)); | |
String pojoMarkerKey = ""; | |
pojoMarkerKey = "org.appops.altshared.shared.altcore.altentity.type.AltDynamicEntity"; | |
PojoMarkerImplInstantiatorRegistry.get().registerInstantiator(pojoMarkerKey, | |
new PojoMarkerImplInstantiator<AltDynamicEntity>() { | |
@Override | |
public AltDynamicEntity createInstance() { | |
return GWT.create(AltDynamicEntity.class); | |
} | |
}); | |
} | |
@Worker | |
public void setInstanceProvider() { | |
super.setInstanceProvider((InstanceProvider) GWT.create(InstanceProvider.class)); | |
} | |
public Serializable getSuperValue(String propName) { | |
switch (propName) { | |
case "propertymap": | |
return (Serializable) super.getPropertyMap(); | |
case "isdirty": | |
return (Serializable) super.getIsDirty(); | |
case "ispartial": | |
return (Serializable) super.getIsPartial(); | |
case "isautotyped": | |
return (Serializable) super.getIsAutoTyped(); | |
case "type": | |
return (Serializable) super.getType(); | |
default: | |
return null; | |
} | |
} | |
@Worker | |
public void setSuperValue(String propName, Object value) { | |
switch (propName) { | |
case "isdirty": | |
super.setIsDirty((boolean) value); | |
break; | |
case "propertymap": | |
super.setPropertyMap((java.util.HashMap) value); | |
break; | |
case "ispartial": | |
super.setIsPartial((boolean) value); | |
break; | |
case "type": | |
super.setType((org.appops.altshared.shared.altcore.altentity.type.AltType) value); | |
break; | |
case "isautotyped": | |
super.setIsAutoTyped((boolean) value); | |
break; | |
default: | |
_impl.getLogger().log(Level.SEVERE, "property with name " + propName + "does not exists"); | |
break; | |
} | |
} | |
public Serializable getPropertyInternal(String propName) { | |
Serializable value = _impl.getProperty(propName); | |
if (!Utils.isNullOrEmptyValue(value)) { | |
if (value instanceof ManagePojo && ((ManagePojo) value).getEventBus() == null && this.getEventBus() != null) | |
((ManagePojo) value).setEventBus(this.getEventBus()); | |
return value; | |
} else | |
return getSuperValue(propName); | |
} | |
public Serializable getCollectionPropertyInternal(String propName) { | |
Serializable value = _impl.getProperty(propName); | |
if (!Utils.isNullOrEmptyValue(value)) { | |
if (value instanceof ManagePojo && ((ManagePojo) value).getEventBus() == null && this.getEventBus() != null) | |
((ManagePojo) value).setEventBus(this.getEventBus()); | |
((ManagePojo) value).setRegistrationKey(((ManagePojo) value).getRegistrationKey()); | |
((ManagePojo) value).setPropertyValue(propName, null, false); | |
return value; | |
} else { | |
Serializable superValue = getSuperValue(propName); | |
if (superValue == null && value != null) { | |
superValue = value; | |
} | |
return superValue; | |
} | |
} | |
@Override | |
public void setIsDirty(boolean value) { | |
setPropertyValue("isdirty", value, false); | |
} | |
@Override | |
public java.util.HashMap getPropertyMap() { | |
return (java.util.HashMap) getCollectionPropertyInternal("propertymap"); | |
} | |
@Override | |
public boolean getIsDirty() { | |
return (boolean) getPropertyInternal("isdirty"); | |
} | |
@Override | |
public boolean getIsPartial() { | |
return (boolean) getPropertyInternal("ispartial"); | |
} | |
@Override | |
public void setPropertyMap(java.util.HashMap map) { | |
setPropertyValue("propertymap", map, false); | |
} | |
@Override | |
public void setIsPartial(boolean partial) { | |
setPropertyValue("ispartial", partial, false); | |
} | |
@Override | |
public boolean getIsAutoTyped() { | |
return (boolean) getPropertyInternal("isautotyped"); | |
} | |
@Override | |
public void setType(org.appops.altshared.shared.altcore.altentity.type.AltType type) { | |
setPropertyValue("type", type, false); | |
} | |
@Override | |
public org.appops.altshared.shared.altcore.altentity.type.AltType getType() { | |
return (org.appops.altshared.shared.altcore.altentity.type.AltType) getPropertyInternal("type"); | |
} | |
@Override | |
public void setIsAutoTyped(boolean b) { | |
setPropertyValue("isautotyped", b, false); | |
} | |
public String getPropertyTypeName(String propName) { | |
return typeMap.get(propName).getTypeName(); | |
} | |
@Override | |
@Worker | |
public String toJson(Object jsValue) { | |
return _impl.toJson(jsValue); | |
} | |
@Override | |
public PojoMarker fromJson(JavaScriptObject jsValue) { | |
PojoMarker result = null; | |
result = _impl.fromJson(jsValue); | |
if (result != null) | |
return result; | |
return this; | |
} | |
@Override | |
@Worker | |
public HashMap<String, TypeKey> getPropertyTypeMap() { | |
return typeMap; | |
} | |
private void setInternalPropertyValue(String propName, Object value, boolean isDeepCopy) { | |
if (_impl != null && isDeepCopy) { | |
_impl.setProperty(propName, (Serializable) value, isDeepCopy); | |
} | |
if (value != null) { | |
setSuperValue(propName, value); | |
} | |
if (_impl != null && !isDeepCopy) { | |
SyncChange change = null; | |
change = fireChangeEvent(propName, value); | |
if (change != null && change instanceof ObjectPeer) { | |
getPeer().put(propName, ((ObjectPeer) change).getPeer().get("changevalue")); | |
_impl.populatePropertyValueMap(propName, (Serializable) value); | |
addReferrer(value); | |
} else { | |
_impl.setProperty(propName, (Serializable) value); | |
} | |
} | |
} | |
@Worker | |
public void setPropertyValue(String propName, Object value, boolean isDeepCopy) { | |
if (isDeepCopy) { | |
if (getDeepCopyMap().containsKey(value) && getDeepCopyMap().get(value) != null) { | |
value = getDeepCopyMap().get(value); | |
} | |
} | |
SyncChange change = null; | |
switch (propName) { | |
case "isdirty": | |
setInternalPropertyValue(propName, value, isDeepCopy); | |
break; | |
case "propertymap": | |
setInternalPropertyValue(propName, value, isDeepCopy); | |
break; | |
case "ispartial": | |
setInternalPropertyValue(propName, value, isDeepCopy); | |
break; | |
case "type": | |
setInternalPropertyValue(propName, value, isDeepCopy); | |
break; | |
case "isautotyped": | |
setInternalPropertyValue(propName, value, isDeepCopy); | |
break; | |
default: | |
_impl.getLogger().log(Level.SEVERE, "property with name " + propName + "does not exists"); | |
break; | |
} | |
} | |
@Override | |
@Worker | |
public Serializable getPropertyValue(String propName) { | |
Serializable result; | |
switch (propName) { | |
case "propertymap": | |
return (Serializable) getPropertyMap(); | |
case "isdirty": | |
return (Serializable) getIsDirty(); | |
case "ispartial": | |
return (Serializable) getIsPartial(); | |
case "isautotyped": | |
return (Serializable) getIsAutoTyped(); | |
case "type": | |
return (Serializable) getType(); | |
default: | |
return null; | |
} | |
} | |
@Worker | |
public void setRegistrationKey(Serializable instanceRegistrationKey) { | |
_impl.setProperty(Constants.REGISTRATIONKEY, instanceRegistrationKey); | |
} | |
@Worker | |
public Serializable getRegistrationKey() { | |
return _impl.getProperty(Constants.REGISTRATIONKEY); | |
} | |
@Worker | |
@Override | |
public void setInstanceRegistry(InstanceRegistry instanceRegistry, boolean setDeep) { | |
_impl.setInstanceRegistry(instanceRegistry, false); | |
if (setDeep) | |
_impl.updateInstanceRegistry(instanceRegistry, setDeep, (PojoMarker) this); | |
} | |
@Worker | |
public InstanceRegistry getInstanceRegistry() { | |
return _impl.getInstanceRegistry(); | |
} | |
@Worker | |
@Override | |
public void setEventBus(SimpleEventBus eventBus) { | |
Serializable result = null; | |
if (((ManagePojo) this).getEventBus() == null) { | |
this.eventBus = (SimpleEventBus) eventBus; | |
this.eventBus.addHandler(ApplyPojoMarkerChangeEvent.TYPE, this); | |
this.eventBus.addHandler(ApplyCollectionChangeEvent.TYPE, this); | |
_impl.prepareInstanceRegistry((Serializable) this); | |
for (String propName : getPropertyTypeMap().keySet()) { | |
result = _impl.getProperty(propName); | |
if (Utils.isNullOrEmptyValue(result)) | |
result = getSuperValue(propName); | |
if (result instanceof ManagePojo) { | |
if (this.getInstanceRegistry() != null) { | |
((ManageInstanceRegistry) result).setInstanceRegistry(this.getInstanceRegistry(), false); | |
} | |
if (result instanceof JsonCollection) { | |
((JsonCollection) result).setParentPojoMarker(this); | |
if (((ManagePojo) result).getRegistrationKey() == null) | |
((ManagePojo) result).setRegistrationKey(this.getInstanceRegistry().getRegistrationKey( | |
result)); | |
else | |
((ManagePojo) result).setRegistrationKey(((ManagePojo) result).getRegistrationKey()); | |
((ManagePojo) result).setPropertyValue(propName, result, false); | |
} | |
((ManagePojo) result).setEventBus(eventBus); | |
} | |
} | |
} | |
} | |
@Worker | |
@Override | |
public SimpleEventBus getEventBus() { | |
return eventBus; | |
} | |
@Override | |
@Worker | |
public void onApplyPojoMarkerChange(ApplyPojoMarkerChangeEvent event) { | |
SyncChange change = event.getEventData(); | |
if (((ManagePojo) this).getRegistrationKey().equals(change.getParentInstanceId())) { | |
String propName = change.getPropertyName(); | |
Serializable changedValue = null; | |
if (change instanceof IntrinsicChange) { | |
changedValue = ((IntrinsicChange) change).getChangeValue(); | |
} else if (change instanceof PojoMarkerChange) { | |
changedValue = ((PojoMarkerChange) change).getChangeValue(); | |
} | |
_impl.setSynced(true); | |
setPropertyValue(propName, changedValue, false); | |
} | |
} | |
@Override | |
@Worker | |
public void onApplyArrayListAddElementChange(ApplyArrayListAddElementChangeEvent event) { | |
_impl.onApplyArrayListAddElementChange(event); | |
} | |
@Worker | |
@Override | |
public void onApplyHashMapChnage(ApplyHashMapChangeEvent event) { | |
_impl.onApplyHashMapChange(event); | |
} | |
@Override | |
@Worker | |
public void onApplyTreeMapChnage(ApplyTreeMapChangeEvent event) { | |
_impl.onApplyTreeMapChange(event); | |
} | |
@Override | |
@Worker | |
public void onApplyHashSetChnage(ApplyHashSetChangeEvent event) { | |
_impl.onApplyHashSetChange(event); | |
} | |
@Override | |
@Worker | |
public void onApplyArrayListClearChange(ApplyArrayListClearChangeEvent event) { | |
_impl.onApplyArrayListClearChange(event); | |
} | |
@Override | |
@Worker | |
public void onApplyArrayListRemoveElementChange(ApplyArrayListRemoveChangeEvent event) { | |
_impl.onApplyArrayListRemoveElementChange(event); | |
} | |
@Override | |
@Worker | |
public void onApplyLinkedListAddElementChangeEvent(ApplyLinkedListAddElementChangeEvent event) { | |
_impl.onApplyLinkedListAddElementChangeEvent(event); | |
} | |
@Override | |
@Worker | |
public void setGuid(String guid) { | |
_impl.setProperty(Constants.GUID, (Serializable) guid); | |
} | |
@Override | |
@Worker | |
public String getGuid() { | |
return (String) _impl.getProperty(Constants.GUID); | |
} | |
@Worker | |
private void generateTypeInfoMap() { | |
HashMap<String, TypeInfo> propTypeInfo = new HashMap<String, TypeInfo>(); | |
TypeInfo typeInfo = null; | |
typeInfo = new TypeInfo(); | |
typeInfo.addPropertyAnnotationDetail("org.appops.altshared.shared.altcore.annotations.UseTypeSource", | |
"sourceName", "type"); | |
propTypeInfo.put("propertymap", typeInfo); | |
typeInfo = new TypeInfo(); | |
propTypeInfo.put("id", typeInfo); | |
typeInfo = new TypeInfo(); | |
propTypeInfo.put("idtype", typeInfo); | |
typeInfo = new TypeInfo(); | |
propTypeInfo.put("instanceprovider", typeInfo); | |
typeInfo = new TypeInfo(); | |
propTypeInfo.put("property", typeInfo); | |
typeInfo = new TypeInfo(); | |
typeInfo.addPropertyAnnotationDetail("org.appops.altshared.shared.altcore.annotations.UseProvider", | |
"propertyKey", "typename"); | |
typeInfo.addPropertyAnnotationDetail("org.appops.altshared.shared.altcore.annotations.UseProvider", | |
"providerClazz", "interface org.appops.altshared.shared.altentities.core.types.TypeProvider"); | |
propTypeInfo.put("type", typeInfo); | |
setTypeInfoMap(propTypeInfo); | |
} | |
@Override | |
@Worker | |
public TypeInfo getTypeInfo(String propName) { | |
return typeInfoMap.get(propName); | |
} | |
@Worker | |
public void setTypeInfoMap(HashMap<String, TypeInfo> typeInfo) { | |
this.typeInfoMap = typeInfo; | |
} | |
@Override | |
@Worker | |
public PojoMarker toPojoMarker(AltEntity entity) { | |
HashMap<String, Serializable> propertyMap = entity.getPropertyMap(); | |
for (String propName : propertyMap.keySet()) { | |
Object propValue = propertyMap.get(propName); | |
if (propValue instanceof AltEntity) | |
propValue = getEntityConverted((AltEntity) propValue); | |
setPropertyValue(propName, propValue, false); | |
} | |
return this; | |
} | |
public Serializable getEntityConverted(AltEntity entity) { | |
AltType entityType = entity.getType(); | |
String typeName = entityType.getTypeName(); | |
if (PojoMarkerImplInstantiatorRegistry.get().isRegistered(typeName)) { | |
return JsonizerGinjector.INSTANCE.getJsonizerParser().toPojoMarker(entity); | |
} | |
return null; | |
} | |
@Worker | |
public Serializable removeInstanceFromInstanceRegistry(Serializable value) { | |
return _impl.removeInstanceFromInstanceRegistry(value); | |
} | |
@Worker | |
@Override | |
public Object createDeepCopy() { | |
Object object = deepCopy(); | |
setDeepCopyMap(null); | |
return object; | |
} | |
@Worker | |
@Override | |
public Object deepCopy() { | |
try { | |
PojoMarker pojomarker = null; | |
if (deepCopyMap == null) { | |
deepCopyMap = new HashMap<Object, Object>(); | |
setDeepCopyMap(deepCopyMap); | |
} | |
if (deepCopyMap.containsKey(this) && deepCopyMap.get(this) != null) { | |
return this; | |
} | |
pojomarker = (AltDynamicEntity) createNewInstance(); | |
Serializable result = null; | |
Object obj = null; | |
result = (Serializable) getPropertyMap(); | |
if (result != null) { | |
if (result instanceof DeepCopy) { | |
((DeepCopy) result).setDeepCopyMap(getDeepCopyMap()); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), NoDeepCopy.class)) { | |
((ManagePojo) pojomarker).setPropertyValue("propertymap", result, true); | |
} else { | |
obj = ((DeepCopy) result).deepCopy(); | |
((ManagePojo) pojomarker).setPropertyValue("propertymap", obj, true); | |
} | |
} else { | |
((ManagePojo) pojomarker).setPropertyValue("propertymap", result, true); | |
} | |
} | |
result = (Serializable) getIsDirty(); | |
if (result != null) { | |
if (result instanceof DeepCopy) { | |
((DeepCopy) result).setDeepCopyMap(getDeepCopyMap()); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), NoDeepCopy.class)) { | |
((ManagePojo) pojomarker).setPropertyValue("isdirty", result, true); | |
} else { | |
obj = ((DeepCopy) result).deepCopy(); | |
((ManagePojo) pojomarker).setPropertyValue("isdirty", obj, true); | |
} | |
} else { | |
((ManagePojo) pojomarker).setPropertyValue("isdirty", result, true); | |
} | |
} | |
result = (Serializable) getIsPartial(); | |
if (result != null) { | |
if (result instanceof DeepCopy) { | |
((DeepCopy) result).setDeepCopyMap(getDeepCopyMap()); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), NoDeepCopy.class)) { | |
((ManagePojo) pojomarker).setPropertyValue("ispartial", result, true); | |
} else { | |
obj = ((DeepCopy) result).deepCopy(); | |
((ManagePojo) pojomarker).setPropertyValue("ispartial", obj, true); | |
} | |
} else { | |
((ManagePojo) pojomarker).setPropertyValue("ispartial", result, true); | |
} | |
} | |
result = (Serializable) getIsAutoTyped(); | |
if (result != null) { | |
if (result instanceof DeepCopy) { | |
((DeepCopy) result).setDeepCopyMap(getDeepCopyMap()); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), NoDeepCopy.class)) { | |
((ManagePojo) pojomarker).setPropertyValue("isautotyped", result, true); | |
} else { | |
obj = ((DeepCopy) result).deepCopy(); | |
((ManagePojo) pojomarker).setPropertyValue("isautotyped", obj, true); | |
} | |
} else { | |
((ManagePojo) pojomarker).setPropertyValue("isautotyped", result, true); | |
} | |
} | |
result = (Serializable) getType(); | |
if (result != null) { | |
if (result instanceof DeepCopy) { | |
((DeepCopy) result).setDeepCopyMap(getDeepCopyMap()); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), NoDeepCopy.class)) { | |
((ManagePojo) pojomarker).setPropertyValue("type", result, true); | |
} else { | |
obj = ((DeepCopy) result).deepCopy(); | |
((ManagePojo) pojomarker).setPropertyValue("type", obj, true); | |
} | |
} else { | |
((ManagePojo) pojomarker).setPropertyValue("type", result, true); | |
} | |
} | |
return pojomarker; | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: createDeepCopy() :: " + e); | |
} | |
} | |
@Worker | |
public PojoMarker createNewInstance() { | |
PojoMarker pojomarker = GWT.create(AltDynamicEntity.class); | |
getDeepCopyMap().put(this, pojomarker); | |
((DeepCopy) pojomarker).setDeepCopyMap(getDeepCopyMap()); | |
return pojomarker; | |
} | |
@Worker | |
@Override | |
public JSONObject getPeer() { | |
if (_impl instanceof org.appops.jsonizer.client.impls.JSBasePojoMarkerImpl) | |
return ((org.appops.jsonizer.client.impls.JSBasePojoMarkerImpl) _impl).getJsonObject(); | |
return null; | |
} | |
@Worker | |
@Override | |
public void setPeer(JSONObject jsonObject) { | |
if (_impl instanceof org.appops.jsonizer.client.impls.JSBasePojoMarkerImpl) | |
((org.appops.jsonizer.client.impls.JSBasePojoMarkerImpl) _impl).setJsonObject(jsonObject, true); | |
} | |
@Override | |
public HashMap<Object, Object> getDeepCopyMap() { | |
return deepCopyMap; | |
} | |
@Override | |
public void setDeepCopyMap(HashMap<Object, Object> deepCopyMap) { | |
this.deepCopyMap = deepCopyMap; | |
} | |
@Override | |
public void addReferrer(Object ref) { | |
_impl.addReferrer(ref); | |
} | |
@Override | |
public void removeAllReferences() { | |
_impl.removeAllReferences(); | |
} | |
@Override | |
public String getSelectorId() { | |
return _impl.getSelectorId(); | |
} | |
@Override | |
public String getSelectorPattern() { | |
return _impl.getSelectorPattern(); | |
} | |
public SyncChange fireChangeEvent(String propName, Object value) { | |
SyncChange change = null; | |
if (!_impl.isSynced()) { | |
if (getEventBus() != null) { | |
change = _impl.prepareAndFireEvent(propName, value); | |
} | |
} | |
return change; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.appops.jsonizer.client.impls; | |
import java.io.Serializable; | |
import java.util.HashMap; | |
import java.util.logging.Logger; | |
import org.appops.altshared.shared.PojoMarker; | |
import org.appops.altshared.shared.altcore.altentity.AltJsonException; | |
import org.appops.altshared.shared.altcore.altentity.Primitive; | |
import org.appops.altshared.shared.altcore.annotations.DependentDelete; | |
import org.appops.altshared.shared.altcore.annotations.SelectorLevel; | |
import org.appops.altshared.shared.altcore.annotations.Worker; | |
import org.appops.altshared.shared.altentities.core.types.TypeProvider; | |
import org.appops.altshared.shared.annotation.JsonTopMost; | |
import org.appops.altshared.shared.jsonizer.base.AltJsonizerException; | |
import org.appops.altshared.shared.jsonizer.base.ClientInstanceRegistry; | |
import org.appops.altshared.shared.jsonizer.base.CollectionTypeKey; | |
import org.appops.altshared.shared.jsonizer.base.Constants; | |
import org.appops.altshared.shared.jsonizer.base.CustomSourceTypeKey; | |
import org.appops.altshared.shared.jsonizer.base.HasCollectionReferrer; | |
import org.appops.altshared.shared.jsonizer.base.InstanceRegistry; | |
import org.appops.altshared.shared.jsonizer.base.JsonCollection; | |
import org.appops.altshared.shared.jsonizer.base.ManageInstanceRegistry; | |
import org.appops.altshared.shared.jsonizer.base.ProviderTypeKey; | |
import org.appops.altshared.shared.jsonizer.base.SupportTypeSource; | |
import org.appops.altshared.shared.jsonizer.base.TypeKey; | |
import org.appops.altshared.shared.jsonizer.base.TypeSource; | |
import org.appops.altshared.shared.jsonizer.base.TypedAs; | |
import org.appops.altshared.shared.sync.ArrayListChange; | |
import org.appops.altshared.shared.sync.HashMapAddElementChange; | |
import org.appops.altshared.shared.sync.HashMapChange; | |
import org.appops.altshared.shared.sync.HashMapClearChange; | |
import org.appops.altshared.shared.sync.HashMapRemoveElementChange; | |
import org.appops.altshared.shared.sync.HashSetAddElementChange; | |
import org.appops.altshared.shared.sync.HashSetChange; | |
import org.appops.altshared.shared.sync.HashSetClearChange; | |
import org.appops.altshared.shared.sync.HashSetRemoveElementChange; | |
import org.appops.altshared.shared.sync.IntrinsicChange; | |
import org.appops.altshared.shared.sync.LinkedListChange; | |
import org.appops.altshared.shared.sync.PojoMarkerChange; | |
import org.appops.altshared.shared.sync.SyncChange; | |
import org.appops.altshared.shared.sync.TreeMapAddElementChange; | |
import org.appops.altshared.shared.sync.TreeMapChange; | |
import org.appops.altshared.shared.sync.TreeMapClearChange; | |
import org.appops.altshared.shared.sync.TreeMapRemoveElementChange; | |
import org.appops.jsonizer.client.base.ClassInfo; | |
import org.appops.jsonizer.client.base.JSONObjectUtil; | |
import org.appops.jsonizer.client.base.ManagePojo; | |
import org.appops.jsonizer.client.base.ObjectPeer; | |
import org.appops.jsonizer.client.base.Selector; | |
import org.appops.jsonizer.client.base.SelectorId; | |
import org.appops.jsonizer.client.base.Utils; | |
import org.appops.jsonizer.client.binding.JsonizerGinjector; | |
import org.appops.jsonizer.client.customcollection.JsonArrayList; | |
import org.appops.jsonizer.client.customcollection.JsonHashMap; | |
import org.appops.jsonizer.client.customcollection.JsonHashSet; | |
import org.appops.jsonizer.client.customcollection.JsonLinkedList; | |
import org.appops.jsonizer.client.customcollection.JsonTreeMap; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListAddElementChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListClearChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyArrayListRemoveChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyHashMapChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyHashSetChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyLinkedListAddElementChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.ApplyTreeMapChangeEvent; | |
import org.appops.sync.client.eventconfiguration.event.PojoMarkerModifiedEvent; | |
import com.google.common.base.Preconditions; | |
import com.google.gwt.core.client.JavaScriptObject; | |
import com.google.gwt.core.shared.GWT; | |
import com.google.gwt.json.client.JSONObject; | |
import com.google.gwt.json.client.JSONString; | |
import com.google.gwt.json.client.JSONValue; | |
import com.google.inject.Inject; | |
/** | |
* @author [email protected] | |
* @Responisibility: A Java script based implementation for {@link BasePojoMarkerImpl} to use {@link JSONObject} based | |
* parsing. | |
* @Created-On: 28-Dec-2016 | |
*/ | |
public class JSBasePojoMarkerImpl extends BasePojoMarkerImpl { | |
private JsonizerParser jsonizerParser; | |
private JSONObject jsonObject; | |
private Logger logger = Logger.getLogger(this.getClass().getCanonicalName()); | |
private JavaScriptObject jsvalue; | |
private Utils utils; | |
// private HashMap<Object, Object> deepCopyMap = null; | |
private String parentSelector; | |
public JSBasePojoMarkerImpl() { | |
} | |
public JsonizerParser getJsonizerParser() { | |
return jsonizerParser; | |
} | |
@Inject | |
public void setJsonizerParser(JsonizerParser jsonizerParser) { | |
this.jsonizerParser = jsonizerParser; | |
} | |
/** | |
* An overridden method to provide an appropriate property value from {@link JSONObject} instance. | |
*/ | |
@Override | |
public Serializable getProperty(String propName) { | |
Serializable result = null; | |
try { | |
TypeKey typeKey = getTypeMap().get(propName); | |
if (super.isPropertyPresent(propName)) { | |
result = super.getProperty(propName); | |
if (typeKey instanceof ProviderTypeKey && result instanceof HashMap) { | |
return getFromProvider((ProviderTypeKey) typeKey, (HashMap) result); | |
} else { | |
return result; | |
} | |
} | |
JSONValue jsonValue = getJsonObject().get(propName); | |
if (jsonValue != null) { | |
if (typeKey instanceof ProviderTypeKey && jsonValue.isObject() != null) { | |
Serializable propertyVal = JSONObjectUtil.convertToSerializable(HashMap.class.getCanonicalName(), | |
jsonValue.isObject(), getInstanceRegistry()); | |
if (propertyVal instanceof HashMap) | |
result = getFromProvider((ProviderTypeKey) typeKey, (HashMap) propertyVal); | |
else { | |
return propertyVal; | |
} | |
} else { | |
String typeName = getTypeName(typeKey, jsonValue, propName); | |
result = JSONObjectUtil.convertToSerializable(typeName, jsonValue, getInstanceRegistry()); | |
} | |
} | |
if (result != null) { | |
if (typeKey instanceof CollectionTypeKey && result instanceof JsonCollection) { | |
((JsonCollection) result).setCollectionTypeKey((CollectionTypeKey) typeKey); | |
} | |
if (result instanceof ManagePojo && getInstanceRegistry() != null) { | |
((ManageInstanceRegistry) result).setInstanceRegistry(getInstanceRegistry(), true); | |
} | |
if (typeKey instanceof CustomSourceTypeKey && result instanceof SupportTypeSource) { | |
setCustomSource((SupportTypeSource) result, (CustomSourceTypeKey) typeKey); | |
} | |
super.setProperty(propName, result); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: getProperty() :: " + e); | |
} | |
return result; | |
} | |
private Serializable getFromProvider(ProviderTypeKey typeKey, HashMap providerKeyMap) { | |
ProviderTypeKey providerTypeKey = typeKey; | |
String propertyKeyName = providerTypeKey.getPropertyKey(); | |
String propertyKeyValue = String.valueOf(providerKeyMap.get(propertyKeyName)); | |
Object providerObject = providerTypeKey.getProvider(); | |
if (providerObject instanceof TypeProvider) { | |
return ((TypeProvider) providerObject).getTypeByName(propertyKeyValue); | |
} | |
return null; | |
} | |
private void setCustomSource(SupportTypeSource supportTypeSource, CustomSourceTypeKey typeKey) { | |
try { | |
String sourceName = typeKey.getSourceName(); | |
Serializable source = getProperty(sourceName); | |
if (source instanceof TypeSource) { | |
supportTypeSource.setTypeSource((TypeSource) source); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException("JSBasePojoMarkerImpl :: setCustomSource() :: " + e); | |
} | |
} | |
private String getTypeName(TypeKey typeKey, JSONValue jsonValue, String propName) { | |
String typeName = ""; | |
try { | |
if (typeKey != null) { | |
if (TypedAs.VARIANT.equals(typeKey.getTypedAs())) { | |
if (jsonValue.isObject() != null | |
&& !jsonValue.isObject().containsKey(Constants.INSTANCE_REGISTRY_TYPE_KEY)) { | |
JSONObject jsonObject = (JSONObject) jsonValue; | |
JSONValue typeNameJSValue = jsonObject.get(Constants.TYPE_KEY); | |
typeName = typeNameJSValue.isString().stringValue(); | |
} | |
} else { | |
typeName = getTypeMap().get(propName).getTypeName(); | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException("JSBasePojoMarkerImpl :: getTypeName() :: " + e); | |
} | |
return typeName; | |
} | |
@Override | |
public void populatePropertyValueMap(String propName, Serializable propValue) { | |
try { | |
super.getPropertyValueMap().put(propName, propValue); | |
} catch (Exception e) { | |
throw new AltJsonException(getClass().getSimpleName() + " :: "); | |
} | |
} | |
/** | |
* An overridden method to set an appropriate property value to {@link JSONObject} instance. | |
*/ | |
@Override | |
public void setProperty(String propName, Serializable propValue) { | |
try { | |
if (propValue != null && getTypeMap().containsKey(propName)) { | |
TypeKey typeKey = getTypeMap().get(propName); | |
if (typeKey instanceof ProviderTypeKey && propValue instanceof ManagePojo) { | |
addObjectHavingCustomProvider(propName, (ManagePojo) propValue, (ProviderTypeKey) typeKey); | |
} else if (propValue instanceof ObjectPeer) { | |
if (typeKey instanceof CustomSourceTypeKey && propValue instanceof SupportTypeSource) { | |
setCustomSource((SupportTypeSource) propValue, (CustomSourceTypeKey) typeKey); | |
} | |
if (typeKey instanceof CollectionTypeKey && propValue instanceof JsonCollection) { | |
((JsonCollection) propValue).setCollectionTypeKey((CollectionTypeKey) typeKey); | |
} | |
if (this.getInstanceRegistry() != null) { | |
if (propValue instanceof ManageInstanceRegistry | |
&& ((ManageInstanceRegistry) propValue).getInstanceRegistry() != null | |
&& this.getInstanceRegistry().isInstanceRegistered((propValue))) { | |
ManageInstanceRegistry manageInstanceRegistry = ((ManageInstanceRegistry) propValue); | |
InstanceRegistry instanceRegistry = manageInstanceRegistry.getInstanceRegistry(); | |
Serializable registrationKey = instanceRegistry.getRegistrationKey(manageInstanceRegistry); | |
JSONObject registeredJSObject = new JSONObject(); | |
String registrationKeyJsonValue = registrationKey.getClass().getCanonicalName(); | |
JSONValue jsonValueForInstanceRegistrationKey = JSONObjectUtil.convertToJSONValue( | |
registrationKeyJsonValue, registrationKey); | |
registeredJSObject.put(Constants.INSTANCE_REGISTRY_TYPE_KEY, | |
jsonValueForInstanceRegistrationKey); | |
getJsonObject().put(propName, registeredJSObject); | |
} else if (propValue instanceof ObjectPeer) { | |
if (propValue instanceof ManagePojo) | |
((ManageInstanceRegistry) propValue).setInstanceRegistry(getInstanceRegistry(), true); | |
ObjectPeer objectPeer = ((ObjectPeer) propValue); | |
getJsonObject().put(propName, objectPeer.getPeer()); | |
} | |
} | |
super.setProperty(propName, propValue); | |
} else { | |
JSONValue jsonValue = JSONObjectUtil.convertToJSONValue(typeKey.getTypeName(), propValue); | |
getJsonObject().put(propName, jsonValue); | |
super.setProperty(propName, propValue); | |
} | |
if (getInstanceRegistry() != null) { | |
if (propValue instanceof PojoMarker) { | |
addReferrer(propValue); | |
} | |
} | |
} else if (propValue == null) { | |
getJsonObject().put(propName, null); | |
super.setProperty(propName, propValue); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException("JSBasePojoMarkerImpl :: setProperty() :: " + e); | |
} | |
} | |
@Override | |
public void addReferrer(Object propValue) { | |
try { | |
JavaScriptObject jsObject = null; | |
JavaScriptObject currentPeerReferrerRegistry = Utils.createCurrentPeerReferrerRegistry( | |
jsonObject.toString(), jsObject); | |
JSONObject newRefObject = new JSONObject(currentPeerReferrerRegistry); | |
for (String key : newRefObject.keySet()) { | |
((ClientInstanceRegistry) getInstanceRegistry()).getReferrerRegistry().put(key, newRefObject.get(key)); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: addReferrer() :: " + e); | |
} | |
} | |
private void addObjectHavingCustomProvider(String propName, ManagePojo propValue, ProviderTypeKey typeKey) { | |
try { | |
HashMap<String, String> providerKeyMap = GWT.create(HashMap.class); | |
String val = String.valueOf(propValue.getPropertyValue(typeKey.getPropertyKey())); | |
providerKeyMap.put(typeKey.getPropertyKey(), val); | |
getPropertyValueMap().put(propName, providerKeyMap); | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: addObjectHavingCustomProvider() :: " | |
+ e); | |
} | |
} | |
@Override | |
public void setProperty(String propName, Serializable propValue, boolean deepCopy) { | |
try { | |
super.setProperty(propName, propValue); | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: setProperty() :: " + e); | |
} | |
} | |
public void updatePeerWithDollarFour(ManageInstanceRegistry manageInstanceRegistry, String propName) { | |
try { | |
InstanceRegistry instanceRegistry = manageInstanceRegistry.getInstanceRegistry(); | |
Serializable registrationKey = instanceRegistry.getRegistrationKey(manageInstanceRegistry); | |
JSONObject registeredJSObject = new JSONObject(); | |
String registrationKeyJsonValue = registrationKey.getClass().getCanonicalName(); | |
JSONValue jsonValueForInstanceRegistrationKey = JSONObjectUtil.convertToJSONValue(registrationKeyJsonValue, | |
registrationKey); | |
registeredJSObject.put(Constants.INSTANCE_REGISTRY_TYPE_KEY, jsonValueForInstanceRegistrationKey); | |
getJsonObject().put(propName, registeredJSObject); | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: updatePeerWithDollorFour() :: " + e); | |
} | |
} | |
@Override | |
public void updateInstanceRegistry(InstanceRegistry instanceRegistry, boolean deepSet, PojoMarker pojoMarker) { | |
try { | |
/** | |
* if instance is not registered | |
*/ | |
if (!(instanceRegistry.isInstanceRegistered(pojoMarker))) { | |
Serializable regKey = ((ManagePojo) pojoMarker).getRegistrationKey(); | |
if (regKey != null && !String.valueOf(regKey).isEmpty()) { | |
instanceRegistry.registerInstanceWithKey(regKey, pojoMarker); | |
} else { | |
regKey = instanceRegistry.registerInstance(pojoMarker); | |
((ManagePojo) pojoMarker).setRegistrationKey(regKey); | |
} | |
((ManageInstanceRegistry) pojoMarker).setInstanceRegistry(instanceRegistry, false); | |
if (deepSet) { | |
/** | |
* Update json object when topmost pojomarker object don't have instance registry. | |
*/ | |
updateJsonObject(instanceRegistry, pojoMarker, deepSet); | |
} | |
} | |
/** | |
* if registration key is not set | |
*/ | |
if (((ManagePojo) pojoMarker).getRegistrationKey() == null | |
|| String.valueOf(((ManagePojo) pojoMarker).getRegistrationKey()).isEmpty()) { | |
((ManagePojo) pojoMarker).setRegistrationKey(instanceRegistry.getRegistrationKey(pojoMarker)); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: updateInstanceRegistry() :: " + e); | |
} | |
} | |
public void updateJsonObject(InstanceRegistry instanceRegistry, PojoMarker pojoMarker, boolean deepSet) { | |
try { | |
for (String key : getPropertyValueMap().keySet()) { | |
TypeKey typeKey = getTypeMap().get(key); | |
Serializable objProp = getPropertyValueMap().get(key); | |
if (instanceRegistry != null) { | |
if (objProp instanceof ObjectPeer) { | |
if (instanceRegistry.isInstanceRegistered(objProp)) { | |
Serializable registrationKey = instanceRegistry.getRegistrationKey(objProp); | |
JSONObject registeredJSObject = new JSONObject(); | |
String registrationKeyValue = registrationKey.getClass().getCanonicalName(); | |
JSONValue jsonValueForInstanceRegistrationKey = JSONObjectUtil.convertToJSONValue( | |
registrationKeyValue, registrationKey); | |
registeredJSObject.put(Constants.INSTANCE_REGISTRY_TYPE_KEY, | |
jsonValueForInstanceRegistrationKey); | |
getJsonObject().put(key, registeredJSObject); | |
} else { | |
JSONObject tempJsonObject = null; | |
ManageInstanceRegistry manageInstanceRegistry = (ManageInstanceRegistry) objProp; | |
if (manageInstanceRegistry.getInstanceRegistry() == null | |
/*|| managePojo.getInstanceRegistry().equals(instanceRegistry)*/) { | |
manageInstanceRegistry.setInstanceRegistry(instanceRegistry, deepSet); | |
} else if (!manageInstanceRegistry.getInstanceRegistry().equals(instanceRegistry) | |
&& manageInstanceRegistry.getInstanceRegistry() == null && instanceRegistry != null) { | |
tempJsonObject = new JSONObject(); | |
tempJsonObject.put(Constants.INSTANCE_REGISTRY_TYPE_KEY, | |
(JSONValue) instanceRegistry.getRegistrationKey(objProp)); | |
getJsonObject().put(key, tempJsonObject); | |
} | |
if (tempJsonObject == null) | |
getJsonObject().put(key, ((ObjectPeer) objProp).getPeer()); | |
} | |
} else { | |
getJsonObject().put(key, JSONObjectUtil.convertToJSONValue(typeKey.getTypeName(), objProp)); | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException("JSBasePojoMarkerImpl :: updateInstanceRegistry() :: " + e); | |
} | |
} | |
@Override | |
protected void populatePropertyMap(JavaScriptObject jsValue) { | |
setJsonObject(JSONObjectUtil.createJSONObject(jsValue), true); | |
} | |
@Override | |
public String createJsonString(Object obj) { | |
return stringify(getJsonObject().getJavaScriptObject()); | |
} | |
private native String stringify(JavaScriptObject javaScriptObject) /*-{ | |
return JSON.stringify(javaScriptObject); | |
}-*/; | |
public JSONObject getJsonObject() { | |
if (jsonObject == null) { | |
setJsonObject(JSONObjectUtil.createJSONObject(null), false); | |
} | |
return jsonObject; | |
} | |
public void setJsonObject(JSONObject jsonObject, boolean clearAndSet) { | |
if (clearAndSet) { | |
getPropertyValueMap().clear(); | |
} | |
jsonObject.put(Constants.TYPE_KEY, new JSONString(getPojomarkerKey())); | |
this.jsonObject = jsonObject; | |
} | |
@Override | |
public void registerTopMostObject(PojoMarker pojoMarker) { | |
try { | |
if (!(getInstanceRegistry().isInstanceRegistered(pojoMarker))) { | |
Serializable regKey = ((ManagePojo) pojoMarker).getRegistrationKey(); | |
if (regKey != null && !String.valueOf(regKey).isEmpty()) { | |
getInstanceRegistry().registerInstanceWithKey(regKey, pojoMarker); | |
} else { | |
regKey = getInstanceRegistry().registerInstance(pojoMarker); | |
((ManagePojo) pojoMarker).setRegistrationKey(regKey); | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException("JSBasePojoMarkerImpl :: registerTopMostObject() :: " + e); | |
} | |
} | |
@Override | |
public void removeAllReferences() { | |
try { | |
PojoMarker pojoMarker = getPojoMarkerImpl(); | |
Preconditions.checkNotNull(((ManageInstanceRegistry) pojoMarker).getInstanceRegistry(), getClass() | |
.getName() + " :: removeAllReferences() :: Instance registry can not be null."); | |
ClientInstanceRegistry clientInstanceRegistry = (ClientInstanceRegistry) ((ManageInstanceRegistry) pojoMarker) | |
.getInstanceRegistry(); | |
String regKey = (String) ((ManagePojo) pojoMarker).getRegistrationKey(); | |
JSONObject referrerList = clientInstanceRegistry.getReferrerList(regKey); | |
removeEachReferrence(referrerList); | |
removeInstanceFromInstanceRegistry(pojoMarker); | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + ":: removeAllReferences() :: " + e); | |
} | |
} | |
@Worker | |
public Serializable removeInstanceFromInstanceRegistry(Serializable value) { | |
try { | |
if (value instanceof ManagePojo) { | |
Serializable regKey = ((ManagePojo) value).getRegistrationKey(); | |
if (getInstanceRegistry().isInstanceRegistered(value)) { | |
value = (Serializable) getInstanceRegistry().getRegisteredInstance(regKey); | |
getInstanceRegistry().removeInstanceFromRegistry(regKey); | |
return value; | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + ":: removeInstanceFromRegistry() :: " + e); | |
} | |
return value; | |
} | |
public boolean removeEachReferrence(JSONObject referrerList) { | |
try { | |
if (referrerList.isObject() != null) { | |
for (String regKeyEle : referrerList.keySet()) { | |
JSONObject typeMap = referrerList.get(regKeyEle).isObject(); | |
for (String typeName : typeMap.keySet()) { | |
if (getInstanceRegistry().isInstanceKeyRegistered(regKeyEle, typeName)) { | |
Serializable result = (Serializable) getInstanceRegistry().getRegisteredInstance(regKeyEle); | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
result.getClass().getSuperclass(), DependentDelete.class)) { | |
JSONObject wrapperReferrerList = ((ClientInstanceRegistry) getInstanceRegistry()) | |
.getReferrerList(regKeyEle); | |
removeEachReferrence(wrapperReferrerList); | |
} | |
JSONObject propMap = typeMap.get(typeName).isObject(); | |
for (String propName : propMap.keySet()) { | |
if (result instanceof JsonCollection) { | |
// set instance registry to referrer | |
((ManageInstanceRegistry) result).setInstanceRegistry((this).getInstanceRegistry(), | |
false); | |
((HasCollectionReferrer) result).removeAllReferences(propMap.get(propName) | |
.isObject()); | |
} else | |
((ObjectPeer) result).getPeer().put(propName, null); | |
break; | |
} | |
} | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: removeEachReferrence() :: " + e); | |
} | |
return false; | |
} | |
@Override | |
public ManagePojo deepCopy() { | |
try { | |
PojoMarker pojoMarker = getPojoMarkerImpl(); | |
((ManageInstanceRegistry) getPojoMarkerImpl()).setInstanceRegistry(null, false); | |
String json = JsonizerGinjector.INSTANCE.getJsonizerParser().toJson(pojoMarker); | |
Object result = JsonizerGinjector.INSTANCE.getJsonizerParser().parse(json); | |
return (ManagePojo) result; | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: deepCopy() :: " + e); | |
} | |
} | |
@Override | |
public String getSelectorId() { | |
try { | |
ClassInfo classInfoProvider = JsonizerGinjector.INSTANCE.getClassInfoProvider(); | |
String prop = (String) classInfoProvider.getClassAnnotationPropertyValue(getPojoMarkerImpl().getClass() | |
.getSuperclass(), SelectorId.class, "selectorId"); | |
if (prop != null) | |
return (String) ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(prop); | |
return null; | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getSimpleName() + " :: getSelectorId() :: " + e); | |
} | |
} | |
@Override | |
public String getSelectorPattern() { | |
try { | |
String selectorId = ""; | |
createParentSelector(getPojoMarkerImpl(), selectorId); | |
if (getParentSelector() != null) { | |
return (getSelectorId() + getParentSelector()).trim(); | |
} else { | |
return getSelectorId(); | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: getSelectorPattern() :: " + e); | |
} finally { | |
setParentSelector(null); | |
} | |
} | |
public Object createParentSelector(Object obj, String selectorId) { | |
try { | |
if (!JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent(obj.getClass().getSuperclass(), | |
JsonTopMost.class)) { | |
Object parentObj = getParentRegKey(obj); | |
if (parentObj != null && !(parentObj instanceof JsonCollection) && obj != null | |
&& !(obj instanceof JsonCollection)) { | |
if (JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
parentObj.getClass().getSuperclass(), SelectorLevel.class) | |
&& JsonizerGinjector.INSTANCE.getClassInfoProvider().isAnnotationPresent( | |
obj.getClass().getSuperclass(), SelectorLevel.class)) { | |
if (parentObj != null) { | |
ClassInfo classInfoProvider = JsonizerGinjector.INSTANCE.getClassInfoProvider(); | |
Object parentLevelObj = classInfoProvider.getClassAnnotationPropertyValue(parentObj | |
.getClass().getSuperclass(), SelectorLevel.class, "level"); | |
int parentLevel = Integer.parseInt((parentLevelObj.toString())); | |
Object childObj = obj; | |
Object childLevelObj = classInfoProvider.getClassAnnotationPropertyValue(childObj | |
.getClass().getSuperclass(), SelectorLevel.class, "level"); | |
int childLevel = Integer.parseInt((childLevelObj.toString())); | |
if (childLevel > parentLevel) { | |
parentObj = createParentSelector(parentObj, getParentSelectorId(selectorId, parentObj)); | |
} | |
} | |
}// expecting wrong selector pattern,add @SelectorLevel annotation on slim. | |
else if (parentObj != null) { | |
parentObj = createParentSelector(parentObj, getParentSelectorId(selectorId, parentObj)); | |
} | |
} else if (parentObj != null) { | |
parentObj = createParentSelector(parentObj, getParentSelectorId(selectorId, parentObj)); | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: createParentSelector() :: " + e); | |
} | |
return obj; | |
} | |
public String getParentSelectorId(String selectorId, Object parentObj) { | |
try { | |
if (parentObj != null && !(parentObj instanceof JsonCollection)) { | |
if (((Selector) parentObj).getSelectorId() != null) { | |
selectorId = selectorId + ">" + ((Selector) parentObj).getSelectorId(); | |
setParentSelector(selectorId); | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: getParentSelectorId() :: " + e); | |
} | |
return selectorId; | |
} | |
public Object getParentRegKey(Object obj) { | |
try { | |
ClientInstanceRegistry clientInstanceRegistry = (ClientInstanceRegistry) ((ManageInstanceRegistry) obj) | |
.getInstanceRegistry(); | |
String key = (String) ((ManagePojo) obj).getRegistrationKey(); | |
JSONObject referrer = clientInstanceRegistry.getReferrerList(key); | |
boolean isActualResult = false; | |
for (String regKeyEle : referrer.keySet()) { | |
JSONObject typeMap = referrer.get(regKeyEle).isObject(); | |
for (String typeName : typeMap.keySet()) { | |
JSONObject propMap = typeMap.get(typeName).isObject(); | |
for (String iterable_element : propMap.keySet()) { | |
JSONObject result = propMap.get(iterable_element).isObject(); | |
if (result.keySet().contains(Constants.VALUE_REF)) { | |
if (result.get(Constants.VALUE).isObject().keySet().contains(Constants.REGISTRATIONKEY)) { | |
String valueResult = result.get(Constants.VALUE).isObject() | |
.get(Constants.REGISTRATIONKEY).toString().replaceAll("^\"|\"$", ""); | |
if (valueResult.equals(key)) { | |
isActualResult = true; | |
} | |
} | |
} else if (result.keySet().contains(Constants.KEY_REF)) { | |
if (result.get(Constants.KEY).isObject().keySet().contains(Constants.REGISTRATIONKEY)) { | |
String keyResult = result.get(Constants.KEY).isObject().get(Constants.REGISTRATIONKEY) | |
.toString().replaceAll("^\"|\"$", ""); | |
if (keyResult.equals(key)) { | |
isActualResult = true; | |
} | |
} | |
} | |
if (result.keySet().contains(Constants.REGISTRATIONKEY)) { | |
String temp = result.get(Constants.REGISTRATIONKEY).toString().replaceAll("^\"|\"$", ""); | |
if (temp.equals(key)) { | |
return clientInstanceRegistry.getRegisteredInstance(regKeyEle); | |
} | |
} | |
if (isActualResult) { | |
Object resObject = clientInstanceRegistry.getRegisteredInstance(regKeyEle); | |
if (resObject != null) { | |
if (resObject instanceof JsonCollection) { | |
return getParentRegKey(resObject); | |
} else { | |
return resObject; | |
} | |
} | |
} | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonException(getClass() + " :: getParent() +" + e); | |
} | |
return null; | |
} | |
public JavaScriptObject getJsvalue() { | |
return jsvalue; | |
} | |
public void setJsvalue(JavaScriptObject jsvalue) { | |
this.jsvalue = jsvalue; | |
} | |
@Override | |
public Utils getUtils() { | |
return utils; | |
} | |
@Override | |
@Inject | |
public void setUtils(Utils utils) { | |
this.utils = utils; | |
} | |
public String getParentSelector() { | |
return parentSelector; | |
} | |
public void setParentSelector(String parentSelector) { | |
this.parentSelector = parentSelector; | |
} | |
// optimized writer code | |
@Override | |
@Worker | |
public SyncChange prepareAndFireEvent(String propname, Object value) { | |
try { | |
Serializable typeName = getTypeMap().get(propname).getTypeName(); | |
GWT.log("======== " + propname + " ======= " + value); | |
if (Primitive.isIntrinsic(getTypeMap().get(propname).getTypeName())) { | |
IntrinsicChange intrinsicChange = GWT.create(IntrinsicChange.class); | |
Object oldValue = getProperty(propname); | |
intrinsicChange.setParentInstanceId(getInstanceRegistry().getRegistrationKey(getPojoMarkerImpl())); | |
intrinsicChange.setPropertyName(propname); | |
intrinsicChange.setChangeValue((Serializable) value); | |
intrinsicChange.setOldValue(oldValue); | |
((SyncChange) intrinsicChange).setResource(getPojoMarkerImpl()); | |
PojoMarkerModifiedEvent event = new PojoMarkerModifiedEvent(intrinsicChange); | |
((ManagePojo) getPojoMarkerImpl()).getEventBus().fireEvent(event); | |
return intrinsicChange; | |
} else if (value instanceof PojoMarker) { | |
PojoMarkerChange pojoMarkerChange = GWT.create(PojoMarkerChange.class); | |
Object oldValue = getProperty(propname); | |
pojoMarkerChange.setInstanceRegistry(getInstanceRegistry(), false); | |
pojoMarkerChange.setParentInstanceId(getInstanceRegistry().getRegistrationKey(getPojoMarkerImpl())); | |
pojoMarkerChange.setPropertyName(propname); | |
pojoMarkerChange.setChangeValue((PojoMarker) value); | |
pojoMarkerChange.setOldValue(oldValue); | |
pojoMarkerChange.setResource(getPojoMarkerImpl()); | |
PojoMarkerModifiedEvent event = new PojoMarkerModifiedEvent(pojoMarkerChange); | |
((ManagePojo) getPojoMarkerImpl()).getEventBus().fireEvent(event); | |
if (value instanceof ManagePojo && ((ManagePojo) getPojoMarkerImpl()).getEventBus() != null) { | |
if (((ManagePojo) value).getEventBus() == null) { | |
((ManagePojo) value).setEventBus(((ManagePojo) getPojoMarkerImpl()).getEventBus()); | |
} | |
} | |
return pojoMarkerChange; | |
} else if (!(typeName instanceof CollectionTypeKey) && value == null) { | |
PojoMarkerChange pojoMarkerChange = GWT.create(PojoMarkerChange.class); | |
Object oldValue = getProperty(propname); | |
pojoMarkerChange.setInstanceRegistry(getInstanceRegistry(), false); | |
pojoMarkerChange.setParentInstanceId(getInstanceRegistry().getRegistrationKey(getPojoMarkerImpl())); | |
pojoMarkerChange.setPropertyName(propname); | |
pojoMarkerChange.setChangeValue((PojoMarker) value); | |
pojoMarkerChange.setOldValue(oldValue); | |
pojoMarkerChange.setResource(getPojoMarkerImpl()); | |
PojoMarkerModifiedEvent event = new PojoMarkerModifiedEvent(pojoMarkerChange); | |
((ManagePojo) getPojoMarkerImpl()).getEventBus().fireEvent(event); | |
if (value instanceof ManagePojo && ((ManagePojo) getPojoMarkerImpl()).getEventBus() != null) { | |
if (((ManagePojo) value).getEventBus() == null) { | |
((ManagePojo) value).setEventBus(((ManagePojo) getPojoMarkerImpl()).getEventBus()); | |
} | |
} | |
return pojoMarkerChange; | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: prepareAndFireEvent :: " + e); | |
} | |
return null; | |
} | |
@Override | |
public void prepareInstanceRegistry(Serializable propertyValue) { | |
try { | |
if (propertyValue instanceof PojoMarker) { | |
if (!(getInstanceRegistry().isInstanceRegistered(propertyValue))) { | |
Serializable regKey = ((ManagePojo) propertyValue).getRegistrationKey(); | |
if (getInstanceRegistry().isInstanceKeyRegistered(regKey, null)) { | |
getInstanceRegistry().registerInstanceWithKey(regKey, propertyValue); | |
} else { | |
regKey = getInstanceRegistry().registerInstance(propertyValue); | |
((ManagePojo) propertyValue).setRegistrationKey(regKey); | |
} | |
((ManageInstanceRegistry) propertyValue).setInstanceRegistry(getInstanceRegistry(), false); | |
((ManagePojo) propertyValue).setEventBus(((ManagePojo) getPojoMarkerImpl()).getEventBus()); | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: prepareInstanceRegistry() :: " + e); | |
} | |
} | |
// /////////////// | |
@Override | |
public void onApplyArrayListAddElementChange(ApplyArrayListAddElementChangeEvent event) { | |
Serializable value = null; | |
ArrayListChange change = (ArrayListChange) event.getSyncChange(); | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
value = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (value instanceof JsonArrayList) { | |
((JsonArrayList) value).setSync(true); | |
((JsonArrayList) value).add(change.getChangeValue()); | |
} | |
} | |
} | |
@Override | |
public void onApplyHashMapChange(ApplyHashMapChangeEvent event) { | |
try { | |
Serializable result = null; | |
Serializable valueChanged = null; | |
Serializable keyChanged = null; | |
HashMapChange change = null; | |
if (event.getSyncChange() instanceof HashMapChange) { | |
change = (HashMapChange) event.getSyncChange(); | |
valueChanged = change.getKey(); | |
keyChanged = change.getChangeValue(); | |
} | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
result = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (result instanceof JsonHashMap) { | |
((JsonHashMap) result).setSync(true); | |
if (change instanceof HashMapClearChange) { | |
((JsonHashMap) result).clear(); | |
} else if (change instanceof HashMapAddElementChange) { | |
if (valueChanged != null && keyChanged != null) { | |
((JsonHashMap) result).put(keyChanged, valueChanged); | |
} | |
} else if (change instanceof HashMapRemoveElementChange) { | |
valueChanged = removeInstanceFromInstanceRegistry(valueChanged); | |
keyChanged = removeInstanceFromInstanceRegistry(valueChanged); | |
((JsonHashMap) result).remove(keyChanged); | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: onApplyHashMapAddElementChange() ::" | |
+ e); | |
} | |
} | |
@Override | |
public void onApplyTreeMapChange(ApplyTreeMapChangeEvent event) { | |
try { | |
Serializable result = null; | |
Serializable valueChanged = null; | |
Serializable keyChanged = null; | |
TreeMapChange change = null; | |
if (event.getSyncChange() instanceof TreeMapChange) { | |
change = (TreeMapChange) event.getSyncChange(); | |
keyChanged = change.getKey(); | |
valueChanged = change.getChangeValue(); | |
} | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
result = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (result instanceof JsonTreeMap) { | |
((JsonTreeMap) result).setSync(true); | |
if (change instanceof TreeMapClearChange) { | |
((JsonTreeMap) result).clear(); | |
} else if (change instanceof TreeMapAddElementChange) { | |
if (valueChanged != null && keyChanged != null) { | |
((JsonTreeMap) result).put(keyChanged, valueChanged); | |
} | |
} else if (change instanceof TreeMapRemoveElementChange) { | |
valueChanged = removeInstanceFromInstanceRegistry(valueChanged); | |
keyChanged = removeInstanceFromInstanceRegistry(valueChanged); | |
((JsonTreeMap) result).remove(keyChanged); | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: onApplyTreeMapChange() ::" + e); | |
} | |
} | |
@Override | |
public void onApplyHashSetChange(ApplyHashSetChangeEvent event) { | |
try { | |
Serializable result = null; | |
Serializable valueChanged = null; | |
HashSetChange change = null; | |
if (event.getSyncChange() instanceof HashSetChange) { | |
change = (HashSetChange) event.getSyncChange(); | |
valueChanged = change.getChangeValue(); | |
} | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
// result = this.getPropertyValue(change.getPropertyName()); | |
result = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (result instanceof JsonHashSet) { | |
((JsonHashSet) result).setSync(true); | |
if (change instanceof HashSetClearChange) { | |
((JsonHashSet) result).clear(); | |
} else if (change instanceof HashSetAddElementChange) { | |
if (valueChanged != null) { | |
((JsonHashSet) result).add(valueChanged); | |
} | |
} else if (change instanceof HashSetRemoveElementChange) { | |
valueChanged = removeInstanceFromInstanceRegistry(valueChanged); | |
((JsonHashSet) result).remove(valueChanged); | |
} | |
} | |
} | |
} catch (Exception e) { | |
throw new AltJsonizerException(getClass().getCanonicalName() + " :: onApplyHashSetChange() ::" + e); | |
} | |
} | |
@Override | |
public void onApplyArrayListClearChange(ApplyArrayListClearChangeEvent event) { | |
Serializable value = null; | |
ArrayListChange change = (ArrayListChange) event.getSyncChange(); | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
value = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (value instanceof JsonArrayList) { | |
((JsonArrayList) value).setSync(true); | |
((JsonArrayList) value).clear(); | |
} | |
} | |
} | |
@Override | |
public void onApplyArrayListRemoveElementChange(ApplyArrayListRemoveChangeEvent event) { | |
Serializable value = null; | |
ArrayListChange change = (ArrayListChange) event.getSyncChange(); | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
value = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (value instanceof JsonArrayList) { | |
value = value; | |
((JsonArrayList) value).setSync(true); | |
((JsonArrayList) value).remove(change.getChangeValue()); | |
} | |
} | |
} | |
@Override | |
public void onApplyLinkedListAddElementChangeEvent(ApplyLinkedListAddElementChangeEvent event) { | |
Serializable value; | |
LinkedListChange change = (LinkedListChange) event.getSyncChange(); | |
if (change.getParentInstanceId().equals(((ManagePojo) getPojoMarkerImpl()).getRegistrationKey())) { | |
value = ((ManagePojo) getPojoMarkerImpl()).getPropertyValue(change.getPropertyName()); | |
if (value instanceof JsonLinkedList) { | |
((JsonLinkedList) value).setSync(true); | |
((JsonLinkedList) value).add(change.getChangeValue()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment