1 17 18 package org.objectweb.jac.aspects.naming; 19 20 import org.apache.log4j.Logger; 21 import org.objectweb.jac.core.*; 22 import org.objectweb.jac.core.Naming; 23 import org.objectweb.jac.core.dist.*; 24 import org.objectweb.jac.util.*; 25 import org.objectweb.jac.util.ExtArrays; 26 27 35 36 public class BindingAC extends AspectComponent { 37 38 static Logger logger = Logger.getLogger("naming"); 39 static Logger loggerSerial = Logger.getLogger("serialization"); 40 41 59 60 public Wrappee whenDeserialized(SerializedJacObject orgObject, 61 Wrappee finalObject) { 62 63 String name = (String )orgObject.getACInfos("naming"); 64 loggerSerial.debug("binding "+orgObject+"(name = "+name+")"); 65 if (name != null) { 66 Object newFinal = NameRepository.get().getObject(name); 67 if (newFinal != null) { 68 loggerSerial.debug(name+" exists on the site ("+newFinal+")"); 69 if(!name.equals(NameRepository.get().getName(finalObject))) { 70 loggerSerial.debug("deleting "+finalObject); 71 ObjectRepository.delete(finalObject); 72 } 73 loggerSerial.debug("replacing with "+newFinal); 74 finalObject = (Wrappee)newFinal; 75 } else { 76 if (orgObject.isForwarder()) { 77 loggerSerial.debug("is forwarder"); 78 Wrapping.wrapAll( 79 ((Wrappee)finalObject), 80 null, 81 new BindingWrapper(this, name)); 82 } else { 83 loggerSerial.debug("is new object"); 84 ((ACManager)ACManager.get()).whenRemoteInstantiation( 87 (Wrappee)finalObject, 88 name); 89 } 90 } 91 } 92 return finalObject; 93 } 94 95 105 106 public Wrappee whenSerialized(Wrappee orgObject, 107 SerializedJacObject finalObject) { 108 if (orgObject.getClass().getName().startsWith("org.objectweb.jac.lib.java.util")) { 109 return orgObject; 110 } 111 112 NameRepository nr = (NameRepository)NameRepository.get(); 113 if (Wrapping.isExtendedBy(orgObject, null, BindingWrapper.class)) { 114 String name = 116 (String )Wrapping.invokeRoleMethod(orgObject, 117 "getLogicalName", 118 ExtArrays.emptyObjectArray); 119 if (name != null) { 120 finalObject.setACInfos("naming", name); 122 } 123 } 124 return orgObject; 125 } 126 127 public void whenObjectMiss(String name) { 128 logger.debug("object miss in name repository: "+name); 129 if (name.equals(Naming.PARSER_NAME)) { 130 Parser acParser = new ParserImpl(); 131 String crName = DistdClassLoader.classRepositoryName; 132 if (crName != null) { 134 logger.debug("Create stub for "+Naming.PARSER_NAME+" on "+crName); 135 RemoteRef rr = RemoteContainer.resolve(crName).bindTo(Naming.PARSER_NAME); 136 Wrapping.wrapAll(((Wrappee)acParser),null, 137 new StubWrapper(this,rr)); 138 } else { 139 logger.debug("No stub for "+Naming.PARSER_NAME); 140 } 141 attrdef(BaseProgramListener.FOUND_OBJECT, acParser); 142 } else { 143 attrdef(BaseProgramListener.FOUND_OBJECT, null); 144 } 145 } 146 } 147 | Popular Tags |