示例#1
0
        private static object NewInstance(Type type, HLAProxyAttribute proxyInfo, params object[] args)
        {
            // type == typeof(HLAobjectRoot) ||
            if (type.IsSubclassOf(typeof(HLAobjectRoot)))
            {
                object obj;

                /* 1. Creates a new object */
                if (args != null)
                {
                    obj = _generator.CreateClassProxy(type, new HLAProxySink2(), args);
                }
                else
                {
                    obj = _generator.CreateClassProxy(type, new HLAProxySink2());
                }

                /* 2. Sets-up properties for the new object */
                HLAobjectRoot objRoot = obj as HLAobjectRoot;

                //if (objRoot.OwnFederateAmbassador == null)
                //    return obj;

                // It is a true proxy for a remote object
                if (proxyInfo != null)
                {
                    objRoot.HLAprivilegeToDeleteObject_ = false;

                    objRoot.instanceHandle = new XRTIObjectInstanceHandle(proxyInfo.ObjectInstanceHandle);
                    objRoot.objectName     = proxyInfo.ObjectName;
                    objRoot.classHandle    = new XRTIObjectClassHandle(proxyInfo.ObjectClassHandle);
                }
                // It is a local object
                else
                {
                    objRoot.HLAprivilegeToDeleteObject_ = true;

                    objRoot.OwnFederate                  = HLAobjectRoot.DefaultFederate;
                    objRoot.OwnFederateAmbassador        = HLAobjectRoot.DefaultFederateAmbassador;
                    objRoot.OwnFederationExecutionHandle = HLAobjectRoot.DefaultFederationExecutionHandle;

                    objRoot.instanceHandle = new XRTIObjectInstanceHandle(((BaseAmbassador)objRoot.OwnFederateAmbassador).HandleCounter);
                    string className = obj.GetType().BaseType.Name;
                    objRoot.objectName = className + objRoot.InstanceHandle.ToString();
                }

                /* 3. Executes reflection process for aop engine */
                HLAProxySink2.ProcessConstruction(objRoot, type);

                /* 4. Warns to the creation listeners */
                foreach (IHLACreateObjectRootListener l in creationListeners)
                {
                    l.OnReceiveCreatedNewObject(obj);
                }

                // It is a local object
                if (proxyInfo == null)
                {
                    // COMMENT ANGEL: Permite enviar la modificación de propiedades que se produce en el constructor
                    objRoot.FlushAttributeValues(null);
                    objRoot.AutoFlushDisabled = false;
                }

                if (log.IsDebugEnabled)
                {
                    log.Debug("Created an instance of " + obj.GetType().BaseType.Name + " [" + objRoot.InstanceHandle + "]");
                }

                return(obj);
            }
            else
            {
                throw new Exception("Must be a subclass of HLAobjectRoot");
            }
        }