Package nexj.core.meta

Examples of nexj.core.meta.Metadata


      {
         if (mq.getConnectionFactory() == null)
         {
            if (nContainer == J2EEUtil.TEEE)
            {
               Metadata metadata = mq.getType().getMetadata();
               String sDataDir = ((metadata.isTestEnvironment()) ? "test/" : "") +
                  DATA_DIR_PATTERN.matcher(metadata.getNamespace()).replaceAll("-");
               String sBrokerName = SysUtil.NAMESPACE + "-amq-broker";
               String sBrokerURL = null;
              
               if (metadata.isDistributed())
               {
                  sBrokerURL = "peer://" + SysUtil.NAMESPACE + "-peerGroup-" +
                     GUIDUtil.generateGUID().toString() + "/" + sBrokerName;
               }
               else
               {
                  sBrokerURL = "vm://" + sBrokerName;
               }

               Properties jmsConnFactoryProps = new Properties();
              
               jmsConnFactoryProps.setProperty("brokerURL", sBrokerURL);
               jmsConnFactoryProps.setProperty("dataDirectory", sDataDir);

               if (metadata.isTestEnvironment())
               {
                  jmsConnFactoryProps.setProperty("test", "true");
               }
              
               return PropertyUtil.toString(jmsConnFactoryProps);              
View Full Code Here


         String sDerivedMessageName = tobj.getClassName();
         CompositeMessagePart referencedPart = ((CompositeMessagePartRef)composite).getRefPart();

         if (!StringUtil.isEmpty(sDerivedMessageName))
         {
            Metadata metadata = context.getMetadata();
            Message derivedMessage = metadata.getMessage(sDerivedMessageName);
            Message baseMessage = metadata.getMessage(referencedPart.getRoot().getName());

            Message.validatePolymorphism(baseMessage, derivedMessage, composite);

            return derivedMessage.getRoot();
         }
View Full Code Here

   /**
    * @see nexj.core.runtime.InvocationContextAware#setInvocationContext(nexj.core.runtime.InvocationContext)
    */
   public void setInvocationContext(InvocationContext context)
   {
      Metadata metadata = context.getMetadata();
      Properties properties = new Properties();

      setProperty(properties,
                  BinaryStreamCipherDispatcher.CIPHER_SCHEME_PROPERTY,
                  BinaryStreamCipherDispatcher.SCHEME_MASTER);

      // @see MasterPasswordStreamCipher.MASTER_PASSWORD_PROPERTY
      setProperty(properties, "cipher.master.password", metadata.getDataPassword());

      if (m_dispatcher == null)
      {
         m_dispatcher = new BinaryStreamCipherDispatcher();
      }
View Full Code Here

         context.initialize(null);
         context.setSecure(false);
         nCookie = Logger.pushContext(context.getPrincipal().getName());

         Metadata metadata = context.getMetadata();

         context.getTransactionManager().setTransactionTimeout(86400);
         context.beginTransaction();

         for (Iterator dataSourceItr = metadata.getDataSourceIterator(); dataSourceItr.hasNext();)
         {
            DataSource dataSource = (DataSource)dataSourceItr.next();

            if (dataSource.isEnabled() && dataSource.getComponent() != null)
            {
               for (Iterator fragmentItr = dataSource.getFragmentIterator(); fragmentItr.hasNext();)
               {
                  DataSourceFragment fragment = (DataSourceFragment)fragmentItr.next();
                  String sFragment = (fragment.getName() == null) ? "" : fragment.getName();

                  context.setFragmentName(sFragment);

                  SchemaVersion version = ((PersistenceAdapter)dataSource.getComponent()
                     .getInstance(context)).getVersion(dataSource.getSchema());

                  if (version != null)
                  {
                     if (!metadata.getNamespace().equals(version.getNamespace()))
                     {
                        throw new PersistenceException("err.persistence.storageNamespace",
                           new Object[]{version.getNamespace(), dataSource.getName(),
                              sFragment, metadata.getNamespace()});
                     }

                     if (!metadata.getVersion().equals(version.getVersion()))
                     {
                        throw new PersistenceException("err.persistence.storageVersion",
                           new Object[]{version.getVersion(), dataSource.getName(),
                           sFragment, metadata.getVersion(), metadata.getNamespace()});
                     }
                  }
               }
            }
         }

         context.setFragmentName(null);

         s_logger.debug("Persistent storage versions OK");

         Metaclass upgrade = metadata.findMetaclass("SysUpgrade");

         if (upgrade != null)
         {
            if (m_sUser != null && m_sUser.length() != 0)
            {
View Full Code Here

      catch (Exception e)
      {
         throw new ServletException(ObjUtil.getMessage(e), e);
      }

      Metadata metadata = Repository.getMetadata();

      for (Enumeration enm = getInitParameterNames(); enm.hasMoreElements();)
      {
         String sName = (String)enm.nextElement();
         String sComponentName = getInitParameter(sName);

         if (!StringUtil.isEmpty(sComponentName))
         {
            // Fail init() if component does not exist
           metadata.getComponent(sComponentName);

            if (sName.equals("*"))
            {
               m_sDefaultServerName = sComponentName;
            }
View Full Code Here

            context.initialize(null);
            context.setSecure(false);
            context.setPartitioned(false);
            nCookie = Logger.pushContext(context.getPrincipal().getName());

            Metadata metadata = context.getMetadata();
            Metaclass timerClass = metadata.getMetaclass("SysTimer");
            Pair attributes =
               new Pair(Symbol.define("next"),
               new Pair(Symbol.define("start"),
               new Pair(Symbol.define("period"),
               new Pair(Symbol.define("principal"),
View Full Code Here

      {
         sChannel = sPath.substring(1, i);
         sPath = sPath.substring(i);
      }

      Metadata metadata = m_context.getMetadata();
      Channel channel = metadata.getChannel(sChannel);

      if (!(channel instanceof HTTPChannel) || !channel.isReceivable())
      {
         throw new RPCException("err.rpc.http.notReceiver", new Object[]{sChannel});
      }
View Full Code Here

         if (request.getTimeZone() != null)
         {
            m_context.setTimeZone(request.getTimeZone());
         }

         Metadata metadata = m_context.getMetadata();

         if (request.getNamespace() != null && metadata.getNamespace() != null)
         {
            if (!metadata.getNamespace().equals(request.getNamespace()))
            {
               throw new RequestVersionException("err.rpc.requestNamespace",
                  new Object[]{metadata.getNamespace(), request.getNamespace()});
            }

            if (!metadata.getVersion().equals(request.getVersion()))
            {
               throw new RequestVersionException("err.rpc.requestVersion",
                  new Object[]{metadata.getVersion(), request.getVersion()});
            }
         }

         UnitOfWork uow = m_context.initUnitOfWork();

         uow.checkLicense();

         if (m_interceptor != null && m_interceptor.isEnabled(m_context))
         {
            m_interceptor.interceptRequest(request);
         }

         if (request.isAsync())
         {
            if (request.isCommit())
            {
               if (s_logger.isDebugEnabled() && !bStealth)
               {
                  s_logger.debug("Asynchronous request - forwarding to " + UnitOfWork.SYSTEM_QUEUE);
               }

               TransferObject properties = new TransferObject(1);

               properties.setValue(JMSSender.USER, m_context.getPrincipal().getName());
               uow.addMessage(UnitOfWork.SYSTEM_QUEUE, request, properties, -1, -1, false);
               m_context.complete(true);
            }

            Response response = new Response();

            if (s_logger.isDumpEnabled() && !bStealth)
            {
               s_logger.dump(response);
            }

            return response;
         }

         m_context.setAudited(false);

         boolean bTransient = !request.isCommit();

         uow.setTransient(bTransient);

         // Add to the unit of work the classes to track
         int nFilterCount = request.getFilterCount();
         boolean bInstanceFilter = false;

         for (int i = 0; i < nFilterCount; ++i)
         {
            TransferObject tobj = request.getFilter(i);

            if (tobj == null || tobj.getClassName() == null)
            {
               throw new RequestException("err.rpc.filterTO");
            }

            m_context.track(metadata.getMetaclass(tobj.getClassName()));

            if (!bInstanceFilter)
            {
               bInstanceFilter = tobj.hasValue("instances");
            }
         }

         int nInvocationCount = request.getInvocationCount();
         Lookup identityMap = new HashTab(nInvocationCount << 1);
         Lookup eventMap = new HashTab(nInvocationCount);
         Event[] eventArray = new Event[nInvocationCount];

         argArray = new Object[nInvocationCount][];
         InstanceFactory instanceFactory = new InstanceFactory(identityMap,
            new ArrayList(nInvocationCount << 3), InstanceFactory.STATE | InstanceFactory.PRE,
            m_context);

         // Instantiate the request objects
         for (int i = 0; i < nInvocationCount; ++i)
         {
            Request.Invocation invocation = request.getInvocation(i);
            TransferObject tobj = invocation.getObject();
            String sEventName = invocation.getEventName();

            if (sEventName == null)
            {
               sEventName = tobj.getEventName();
            }

            if (tobj == null || tobj.getClassName() == null || sEventName == null)
            {
               throw new RequestException("err.rpc.requestTO");
            }

            m_context.setTransient(bTransient);

            Object[] arguments = invocation.getArguments();
            Metaclass metaclass = metadata.getMetaclass(tobj.getClassName());
            Selector selector = metaclass.getSelector(sEventName);
            Member member;
            int nArgCount;

            if (arguments != null)
            {
               nArgCount = arguments.length;
               member = selector.getMember(nArgCount);

               if (member.isStatic() && tobj.getValueCount() != 0)
               {
                  throw new RequestException("err.rpc.requestTO");
               }
            }
            else
            {
               nArgCount = tobj.getValueCount();
               member = selector.findMember(0);

               if (member == null || member.isStatic())
               {
                  member = selector.getMember(nArgCount);

                  if (!member.isStatic())
                  {
                     throw new RequestException("err.rpc.argCount",
                        new Object[]{member.getName(), metaclass.getName()});
                  }
               }
               else
               {
                  nArgCount = 0;
               }
            }

            if (member.isAttribute())
            {
               throw new RequestException("err.rpc.attributeInvocation",
                  new Object[]{member.getName(), metaclass.getName()});
            }

            if (m_context.isProtected() && member.getVisibility() != Metaclass.PUBLIC)
            {
               throw new SecurityViolationException("err.rpc.eventVisibility",
                  new Object[]{member.getName(), metaclass.getName()});
            }

            Event event = (Event)member;
            Object[] args = new Object[nArgCount + 1];

            if (arguments != null)
            {
               for (int k = 0; k < nArgCount; ++k)
               {
                  args[k + 1] = instanceFactory.instantiate(arguments[k]);
               }
            }

            if (event.isStatic())
            {
               args[0] = metaclass;

               if (arguments == null)
               {
                  int nEventArgCount = event.getArgumentCount();

                  if (event.isVarArg())
                  {
                     --nEventArgCount;
                  }

                  for (int k = 0; k < nEventArgCount; ++k)
                  {
                     args[k + 1] = instanceFactory.instantiate(tobj.getValue(event.getArgument(k).getName()));
                  }

                  if (event.isVarArg())
                  {
                     int nArg = nEventArgCount;

                     for (PropertyIterator itr = tobj.getIterator(); itr.hasNext();)
                     {
                        itr.next();

                        Argument arg = event.findArgument(itr.getName());

                        if (arg == null || arg == event.getArgument(nEventArgCount))
                        {
                           args[++nArg] = new Pair(Symbol.define(itr.getName()), instanceFactory.instantiate(itr.getValue()));
                        }
                     }
                  }
               }

               // Allow auditing of static events
               identityMap.put(tobj, null);
            }
            else
            {
               args[0] = instanceFactory.instantiate(tobj);
            }

            eventArray[i] = event;
            argArray[i] = args;
            eventMap.put(tobj, event);
         }

         Lookup diffMap = null;

         // Instantiate the transfer objects from the instance filters
         if (bInstanceFilter)
         {
            diffMap = new HashTab();

            for (int i = 0; i < nFilterCount; ++i)
            {
               m_context.setTransient(bTransient);

               TransferObject tobj = request.getFilter(i);
               Object instances = tobj.findValue("instances");

               if (instances != null)
               {
                  List instanceList = (List)instances;
                  int nCount = instanceList.size();

                  for (int k = 0; k < nCount; ++k)
                  {
                     tobj = (TransferObject)instanceList.get(k);

                     Instance inst = instanceFactory.instantiate(tobj);

                     instanceList.set(k, inst);

                     if (inst != null)
                     {
                        diffMap.put(inst, tobj);
                     }
                  }
               }
            }
         }

         instanceFactory.complete();
         instanceFactory = null;
         GenericServer.auditRequest(identityMap, eventMap, m_context);
         identityMap = null;

         Object[] resultArray = new Object[nInvocationCount << 1];

         // Unset the pending event flag on the request argument instances
         for (int i = 0; i < nInvocationCount; ++i)
         {
            Object[] args = argArray[i];
            Object obj = args[0];

            if (obj instanceof Instance)
            {
               Instance instance = (Instance)obj;

               if (args.length == 1 && eventArray[i].getName().equals(instance.getPendingEventName()))
               {
                  resultArray[i << 1] = instance;
               }

               instance.suspendEvent();
            }
         }

         m_context.setTransient(false);
         uow.invokePendingEvents(false, false);

         // Invoke the events and accumulate the results
         for (int i = 0; i < nInvocationCount; ++i)
         {
            TransferObject tobj = request.getObject(i);
            Event event = eventArray[i];
            Pair attributes = EMPTY_PAIR;
            Object[] args = argArray[i];
            Object obj = args[0];
            int nAttrIndex = -1;

            m_context.setTransient(event.isTransient(bTransient));

            if (event.getArgumentCount() != 0)
            {
               Argument arg = event.findArgument("attributes");

               if (arg != null)
               {
                  nAttrIndex = arg.getOrdinal() + 1;

                  Object value = args[nAttrIndex];

                  attributes = (value instanceof Pair) ? (Pair)value : null;
               }
            }

            if (nAttrIndex < 0)
            {
               Object value = tobj.findValue("attributes", EMPTY_PAIR);

               if (value != EMPTY_PAIR)
               {
                  nAttrIndex = 0;
                  attributes =  (Pair)value;
               }
            }

            if (event.isStatic() && m_context.isProtected() && m_context.isSecure())
            {
               Metaclass metaclass = event.getMetaclass();
               Argument result = event.getResult();

               if (result != null && !result.getType().isPrimitive())
               {
                  metaclass = (Metaclass)result.getType();
               }

               if (nAttrIndex > 0)
               {
                  Pair security = metaclass.checkReadAccess(attributes, m_context.getPrivilegeSet());
  
                  if (security != null)
                  {
                     args[nAttrIndex] = Pair.nconc(security, attributes);
                  }
               }

               metaclass.checkExpressionAccess(findArg(event, "where", args, tobj),  m_context.getPrivilegeSet());
               metaclass.checkOrderByAccess(findArg(event, "orderBy", args, tobj), m_context.getPrivilegeSet());
            }

            boolean bInvoked = false;
            boolean bDeleted = false;

            m_context.setUnitOfWork(uow);
            m_context.setTransient(event.isTransient(bTransient));

            if (obj instanceof Instance)
            {
               Instance instance = (Instance)obj;
               UnitOfWork instanceUOW = instance.getUnitOfWork();

               // Use the instance UoW
               if (!event.isStatic() && instanceUOW != null && instanceUOW != uow)
               {
                  m_context.setUnitOfWork(instanceUOW);
               }

               bInvoked = instance.invokeSuspendedEvent();
               bDeleted = (instance.getState() == Instance.DELETED);

               if (nAttrIndex <= 0)
               {
                  Attribute attribute = instance.getMetaclass().findAttribute("attributes");

                  if (attribute != null && !attribute.isStatic())
                  {
                     attributes = (Pair)instance.getValue(attribute.getOrdinal());
                  }
               }
            }

            if (resultArray[i << 1] == null)
            {
               if (!bDeleted)
               {
                  resultArray[i << 1] = event.invoke(args, m_context.getMachine());
               }
            }
            else
            {
               if (!bInvoked && !bDeleted)
               {
                  event.invoke(args, m_context.getMachine());
               }

               eventArray[i] = null;
            }

            resultArray[(i << 1) + 1] = attributes;
         }

         // Pre-commit all units of work in the context
         for (int i = m_context.getUnitOfWorkCount() - 1; i >= 0; i--)
         {
            UnitOfWork work = m_context.getUnitOfWork(i);

            m_context.setUnitOfWork(work);

            if (work.isTransient())
            {
               work.invokePendingEvents(true, false);
               work.computeHiddenness();
               work.accumulateChanges();
            }
            else
            {
               work.commit(false);
            }
         }

         m_context.setUnitOfWork(uow);

         // Transfer the results into the response object.
         // This is done as a separate step after the commit
         // so that the objects are in the correct state (e.g. with OIDs).
         Response response = new Response();

         identityMap = new HashTab();

         for (int i = 0; i < nInvocationCount; ++i)
         {
            Object result = resultArray[i << 1];
            Pair attributes = request.getInvocation(i).getAttributes();
            int nTF = RPCUtil.TF_HIDDEN;
           
            if (attributes == null)
            {
               attributes = (Pair)resultArray[(i << 1) + 1];

               if (attributes == EMPTY_PAIR)
               {
                  attributes = null;
                  nTF |= RPCUtil.TF_READABLE;
               }
            }
            else if (m_context.isProtected() && m_context.isSecure())
            {
               if (result instanceof Instance)
               {
                  Instance instance = (Instance)result;

                  instance.invoke("load", Pair.nconc(instance.getMetaclass()
                     .checkReadAccess(attributes, m_context.getPrivilegeSet()), attributes));
               }
               else if (result instanceof InstanceList)
               {
                  InstanceList list = (InstanceList)result;
                  Lookup classMap = new HashTab(4);

                  for (int k = 0, n = list.size(); k < n; ++k)
                  {
                     Instance instance = list.getInstance(k);
                     Metaclass metaclass = instance.getMetaclass();
                     Pair all = (Pair)classMap.get(metaclass);

                     if (all == null)
                     {
                        all = Pair.nconc(metaclass.checkReadAccess(
                           attributes, m_context.getPrivilegeSet()), attributes);

                        classMap.put(metaclass, all);
                     }

                     instance.invoke("load", all);
                  }
               }

               nTF |= RPCUtil.TF_READABLE;
            }

            response.addResult(RPCUtil.transfer(result, attributes,
               (eventArray[i] == null) ? diffMap : null, identityMap, nTF));
         }

         // Apply the change filters
         for (int i = 0; i < nFilterCount; ++i)
         {
            TransferObject tobj = request.getFilter(i);
            Metaclass metaclass = metadata.getMetaclass(tobj.getClassName());
            Lookup map = m_context.getClassChangeMap(metaclass);
            Object instances = tobj.findValue("instances");
            Pair attributes = (Pair)tobj.findValue("attributes");
            Pair all = attributes;
            List eventList = new ArrayList();
View Full Code Here

         UnitOfWork oldUOW = m_invocationContext.getUnitOfWork();
         UnitOfWork uow = m_invocationContext.createUnitOfWork();

         try
         {
            Metadata metadata = m_invocationContext.getMetadata();
            Instance queue = (Instance)metadata.getMetaclass("SysQueue").invoke("getQueue", new Object[]{sQueueName});

            queue.invoke("send", new Object[]{col});
            uow.commit(true);
         }
         catch (Throwable t)
View Full Code Here

    * Verifies that the request uses the correct authentication. Override in
    * subclasses to provide custom security checks.
    */
   protected void verifyAuthentication()
   {
      Metadata metadata = Repository.getMetadata();

      if (m_bRPCServer)
      {
         // Allows client certificates unless authProtocol=="certificate" and authRPC==false
         verifyCertificateCredentials(
            (metadata.getAuthenticationProtocol() == Metadata.AUTH_PROTOCOL_CERTIFICATE)
            ? ((m_bRPCEnabled) ? m_trust : null) : m_trust,
            m_bRPCEnabled
         );
      }
      else
      {
         // Allows client certificate only if authProtocol=="certificate"
         verifyCertificateCredentials(
            (metadata.getAuthenticationProtocol() == Metadata.AUTH_PROTOCOL_CERTIFICATE) ? m_trust : null,
            (metadata.getAuthenticationProtocol() != Metadata.AUTH_PROTOCOL_CERTIFICATE)
         );
      }

      if (!isAnonEnabled() && HTTPUtil.isAnonymousRequest(m_request, metadata))
      {
View Full Code Here

TOP

Related Classes of nexj.core.meta.Metadata

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.