Examples of Context


Examples of org.apache.cocoon.environment.Context

  public TestBeanAction() {
  }

  public Map act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters param) throws java.lang.Exception {
      Request request = ObjectModelHelper.getRequest(objectModel);
      Context context = ObjectModelHelper.getContext(objectModel);
      if(context != null)
        request.setAttribute("Wale",new  TestBean("Wale in the big sea","context"));

      Session session =request.getSession(true);
      session.setAttribute("Mouse",new  TestBean("Liveing in the session","session"));
View Full Code Here

Examples of org.apache.commons.betwixt.expression.Context

            // process child elements
            for ( int i = 0, size = childDescriptors.length; i < size; i++ ) {
                if (childDescriptors[i] instanceof ElementDescriptor) {
                    // Element content
                    ElementDescriptor childDescriptor = (ElementDescriptor) childDescriptors[i];
                    Context childContext = context;
                    childContext.pushOptions(childDescriptor.getOptions());
                    Expression childExpression = childDescriptor.getContextExpression();
                    if ( childExpression != null ) {
                        Object childBean = childExpression.evaluate( context );
                        if ( childBean != null ) {
                            String qualifiedName = childDescriptor.getQualifiedName();
                            String namespaceUri = childDescriptor.getURI();
                            String localName = childDescriptor.getLocalName();
                            // XXXX: should we handle nulls better
                            if ( childBean instanceof Iterator ) {
                                for ( Iterator iter = (Iterator) childBean; iter.hasNext(); ) {
                                    Object object = iter.next();
                                    if (object == null) {
                                        continue;
                                    }
                                    writeBean(
                                            namespaceUri,
                                            localName,
                                            qualifiedName,
                                            object,
                                            childDescriptor,
                                            context );
                                }
                            } else {
                                writeBean(
                                            namespaceUri,
                                            localName,
                                            qualifiedName,
                                            childBean,
                                            childDescriptor,
                                            context );
                            }
                        }                   
                    } else {
                        writeElement(
                                    childDescriptor.getURI(),
                                    childDescriptor.getLocalName(),
                                    childDescriptor.getQualifiedName(),
                                    childDescriptor,
                                    childContext );
                    }
                    childContext.popOptions();
                } else {
                    // Mixed text content
                    // evaluate the body text
                    Expression expression = childDescriptors[i].getTextExpression();
                    if ( expression != null ) {
View Full Code Here

Examples of org.apache.commons.chain.Context

            logger.setLevel(Level.WARN);

            String uri = command.getOptionValue("cli");
            Repository repository = JcrUtils.getRepository(uri);

            Context context = new ContextBase();
            CommandHelper.setRepository(context, repository, uri);
            try {
                Session session = repository.login();
                CommandHelper.setSession(context, session);
                CommandHelper.setCurrentNode(context, session.getRootNode());
View Full Code Here

Examples of org.apache.commons.scxml.Context

            String expr = t.getCond();
            if (SCXMLHelper.isStringEmpty(expr)) {
                rslt = Boolean.TRUE;
            } else {
                try {
                    Context ctx = scInstance.getContext(t.getParent());
                    ctx.setLocal(NAMESPACES_KEY, t.getNamespaces());
                    rslt = scInstance.getEvaluator().evalCond(ctx,
                        t.getCond());
                    ctx.setLocal(NAMESPACES_KEY, null);
                } catch (SCXMLExpressionException e) {
                    rslt = Boolean.FALSE;
                    errRep.onError(ErrorConstants.EXPRESSION_ERROR, e
                            .getMessage(), t);
                }
View Full Code Here

Examples of org.apache.commons.scxml2.Context

            throw new InvokerException(ioe.getMessage(), ioe.getCause());
        } catch (XMLStreamException xse) {
            throw new InvokerException(xse.getMessage(), xse.getCause());
        }
        executor = new SCXMLExecutor(evaluator, new SimpleDispatcher(), new SimpleErrorReporter());
        Context rootCtx = evaluator.newContext(null);
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            rootCtx.setLocal(entry.getKey(), entry.getValue());
        }
        executor.setRootContext(rootCtx);
        try {
            executor.setStateMachine(scxml);
        }
View Full Code Here

Examples of org.apache.cxf.aegis.Context

        type.setTypeMapping(mapping);
        type.setSchemaType(new QName("urn:Bean", "bean"));

        // Test reading
        ElementReader reader = new ElementReader(getResourceAsStream("bean9.xml"));
        Context ctx = getContext();
        ctx.getGlobalContext().setReadXsiTypes(false);

        SimpleBean bean = (SimpleBean)type.readObject(reader, ctx);
        assertEquals("bleh", bean.getBleh());
        assertEquals("howdy", bean.getHowdy());
View Full Code Here

Examples of org.apache.derby.iapi.services.context.Context

    ContextManager previousCM = contextService.getCurrentContextManager();
    ContextManager cm = previousCM;
    Object instance;
    TopService ts = null;
    Context sb = null;


    try {


      synchronized (this) {

        if (inShutdown) {
          throw StandardException.newException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
        }

        for (int i = 1; i < services.size(); i++) {
          TopService ts2 = (TopService) services.get(i);
          if (ts2.isPotentialService(serviceKey)) {
            // if the service already exists then  just return null
            return null;
          }
        }


        Locale serviceLocale = null;
        if (create) {

         
          // always wrap the property set in an outer set.
          // this ensures that any random attributes from
          // a JDBC URL are not written into the service.properties
          // file (e.g. like user and password :-)
          properties = new Properties(properties);

          serviceLocale = setLocale(properties);

          properties.put(Property.SERVICE_PROTOCOL, factoryInterface);

          serviceName = provider.createServiceRoot(serviceName,
              Boolean.valueOf(properties.getProperty(Property.DELETE_ON_CREATE)).booleanValue());

          serviceKey = ProtocolKey.create(factoryInterface, serviceName);
        } else if (properties != null) {
          String serverLocaleDescription = properties.getProperty(Property.SERVICE_LOCALE);
          if ( serverLocaleDescription != null)
            serviceLocale = staticGetLocaleFromString(serverLocaleDescription);
        }

        ts = new TopService(this, serviceKey, provider, serviceLocale);
        services.add(ts);
      }

      if (SanityManager.DEBUG) {
        if (provider != null)
        {
          SanityManager.ASSERT(provider.getCanonicalServiceName(serviceName).equals(serviceName),
            "mismatched canonical names " + provider.getCanonicalServiceName(serviceName)
            + " != " + serviceName);
          SanityManager.ASSERT(serviceName.equals(serviceKey.getIdentifier()),
            "mismatched names " + serviceName + " != " + serviceKey.getIdentifier());
        }
      }


      if (properties != null) {

        // these properties must not be stored in the persistent properties,
        // otherwise moving databases from one directory to another
        // will not work. Thus they all have a fixed prefix

        // the root of the data
        properties.put(PersistentService.ROOT, serviceName);

        // the type of the service
        properties.put(PersistentService.TYPE, provider.getType());
      }

      if (SanityManager.DEBUG && reportOn) {
        dumpProperties("Service Properties: " + serviceKey.toString(), properties);
      }

      // push a new context manager
      if (previousCM == null) {
        cm = contextService.newContextManager();

        contextService.setCurrentContextManager(cm);
      }
      sb = new ServiceBootContext(cm);

      UpdateServiceProperties usProperties;
      Properties serviceProperties;


      //while doing restore from backup, we don't want service properties to be
      //updated until all the files are copied from backup.
      boolean inRestore = (properties !=null ?
                 properties.getProperty(Property.IN_RESTORE_FROM_BACKUP) != null:false);
     
      if ((provider != null) && (properties != null)) {
        // we need to track to see if the properties have
        // been updated or not. If the database is not created yet, we don't create the
        // services.properties file yet. We let the following if (create) statement do
        //that at the end of the database creation. After that, the changes in
        // services.properties file will be tracked by UpdateServiceProperties.
        usProperties = new UpdateServiceProperties(provider,
                               serviceName,
                               properties,
                               !(create || inRestore));
        serviceProperties = usProperties;
      } else {
        usProperties = null;
        serviceProperties = properties;
      }

      instance = ts.bootModule(create, null, serviceKey, serviceProperties);

      if (create || inRestore) {
        // remove all the in-memory properties
        provider.saveServiceProperties(serviceName, usProperties.getStorageFactory(),
            BaseMonitor.removeRuntimeProperties(properties), false);
        usProperties.setServiceBooted();
      }
           
            if (cm != previousCM) {
                //Assume database is not active. DERBY-4856 thread dump
                cm.cleanupOnError(StandardException.closeException(), false);
            }
           
    } catch (Throwable t) {

      StandardException se;
      // ensure that the severity will shutdown the service
      if ((t instanceof StandardException) && (((StandardException) t).getSeverity() == ExceptionSeverity.DATABASE_SEVERITY))
        se = (StandardException) t;
      else
        se = Monitor.exceptionStartingModule(t);

      if (cm != previousCM) {
                //Assume database is not active. DERBY-4856 thread dump
                cm.cleanupOnError(se, false);
      }

      if (ts != null) {
        ts.shutdown();
        synchronized (this) {
          services.remove(ts);
        }

        // Service root will only have been created if
        // ts is non-null.
        boolean deleteOnError = (properties !=null ?
                     properties.getProperty(Property.DELETE_ROOT_ON_ERROR) !=null:false);
        if (create || deleteOnError)
          provider.removeServiceRoot(serviceName);
      }


      Throwable nested = se.getCause();

      // never hide ThreadDeath
      if (nested instanceof ThreadDeath)
        throw (ThreadDeath) nested;

      throw se;

    } finally {
      if ((previousCM == cm) && (sb != null))
        sb.popMe();

      if (previousCM == null)
        contextService.resetCurrentContextManager(cm);
    }
View Full Code Here

Examples of org.apache.flex.forks.velocity.context.Context

            Writer writer = generator.getWriter(path, outputEncoding);
           
            // The generator and the output path should
            // be placed in the init context here and
            // not in the generator class itself.
            Context c = initControlContext();
           
            // Everything in the generator class should be
            // pulled out and placed in here. What the generator
            // class does can probably be added to the Velocity
            // class and the generator class can probably
            // be removed all together.
            populateInitialContext(c);
           
            // Feed all the options into the initial
            // control context so they are available
            // in the control/worker templates.
            if (contextProperties != null)
            {
                Iterator i = contextProperties.getKeys();
       
                while (i.hasNext())
                {
                    String property = (String) i.next();
                    String value = contextProperties.getString(property);
                   
                    // Now lets quickly check to see if what
                    // we have is numeric and try to put it
                    // into the context as an Integer.
                    try
                    {
                        c.put(property, new Integer(value));
                    }
                    catch (NumberFormatException nfe)
                    {
                        // Now we will try to place the value into
                        // the context as a boolean value if it
                        // maps to a valid boolean value.
                        String booleanString =
                            contextProperties.testBoolean(value);
                       
                        if (booleanString != null)
                        {   
                            c.put(property, new Boolean(booleanString));
                        }
                        else
                        {
                            // We are going to do something special
                            // for properties that have a "file.contents"
                            // suffix: for these properties will pull
                            // in the contents of the file and make
                            // them available in the context. So for
                            // a line like the following in a properties file:
                            //
                            // license.file.contents = license.txt
                            //
                            // We will pull in the contents of license.txt
                            // and make it available in the context as
                            // $license. This should make texen a little
                            // more flexible.
                            if (property.endsWith("file.contents"))
                            {
                                // We need to turn the license file from relative to
                                // absolute, and let Ant help :)
                                value = StringUtils.fileContentsToString(  
                                    project.resolveFile(value).getCanonicalPath());
                           
                                property = property.substring(
                                    0, property.indexOf("file.contents") - 1);
                            }
                       
                            c.put(property, value);
                        }
                    }
                }
            }
           
View Full Code Here

Examples of org.apache.flume.Context

  @Override
  public void configure(Context context) {
    serializerType = context.getString("serializer", "TEXT");
    serializerContext =
        new Context(context.getSubProperties(EventSerializer.CTX_PREFIX));
  }
View Full Code Here

Examples of org.apache.hadoop.hive.ql.Context

  }

  @Override
  public int execute(DriverContext driverContext) {

    Context ctx = driverContext.getCtx();
    boolean ctxCreated = false;

    try {
      if (ctx == null) {
        ctx = new Context(conf);
        ctxCreated = true;
      }

      // estimate number of reducers
      setNumberOfReducers();

      // auto-determine local mode if allowed
      if (!ctx.isLocalOnlyExecutionMode() &&
          conf.getBoolVar(HiveConf.ConfVars.LOCALMODEAUTO)) {

        if (inputSummary == null) {
          inputSummary = Utilities.getInputSummary(driverContext.getCtx(), work, null);
        }

        // at this point the number of reducers is precisely defined in the plan
        int numReducers = work.getNumReduceTasks();

        if (LOG.isDebugEnabled()) {
          LOG.debug("Task: " + getId() + ", Summary: " +
                    inputSummary.getLength() + "," + inputSummary.getFileCount() + ","
                    + numReducers);
        }

        String reason = MapRedTask.isEligibleForLocalMode(conf, inputSummary, numReducers);
        if (reason == null) {
          // clone configuration before modifying it on per-task basis
          cloneConf();
          conf.setVar(HiveConf.ConfVars.HADOOPJT, "local");
          console.printInfo("Selecting local mode for task: " + getId());
          this.setLocalMode(true);
        } else {
          console.printInfo("Cannot run job locally: " + reason);
          this.setLocalMode(false);
        }
      }

      runningViaChild =
        "local".equals(conf.getVar(HiveConf.ConfVars.HADOOPJT)) ||
        conf.getBoolVar(HiveConf.ConfVars.SUBMITVIACHILD);

      if(!runningViaChild) {
        // we are not running this mapred task via child jvm
        // so directly invoke ExecDriver
        return super.execute(driverContext);
      }

      // we need to edit the configuration to setup cmdline. clone it first
      cloneConf();

      // enable assertion
      String hadoopExec = conf.getVar(HiveConf.ConfVars.HADOOPBIN);
      String hiveJar = conf.getJar();

      String libJarsOption;
      String addedJars = getResourceFiles(conf, SessionState.ResourceType.JAR);
      conf.setVar(ConfVars.HIVEADDEDJARS, addedJars);
      String auxJars = conf.getAuxJars();
      // Put auxjars and addedjars together into libjars
      if (StringUtils.isEmpty(addedJars)) {
        if (StringUtils.isEmpty(auxJars)) {
          libJarsOption = " ";
        } else {
          libJarsOption = " -libjars " + auxJars + " ";
        }
      } else {
        if (StringUtils.isEmpty(auxJars)) {
          libJarsOption = " -libjars " + addedJars + " ";
        } else {
          libJarsOption = " -libjars " + addedJars + "," + auxJars + " ";
        }
      }
      // Generate the hiveConfArgs after potentially adding the jars
      String hiveConfArgs = generateCmdLine(conf);

      // write out the plan to a local file
      Path planPath = new Path(ctx.getLocalTmpFileURI(), "plan.xml");
      OutputStream out = FileSystem.getLocal(conf).create(planPath);
      MapredWork plan = getWork();
      LOG.info("Generating plan file " + planPath.toString());
      Utilities.serializeMapRedWork(plan, out);

      String isSilent = "true".equalsIgnoreCase(System
          .getProperty("test.silent")) ? "-nolog" : "";

      String jarCmd;
      if (ShimLoader.getHadoopShims().usesJobShell()) {
        jarCmd = libJarsOption + hiveJar + " " + ExecDriver.class.getName();
      } else {
        jarCmd = hiveJar + " " + ExecDriver.class.getName() + libJarsOption;
      }

      String cmdLine = hadoopExec + " jar " + jarCmd + " -plan "
          + planPath.toString() + " " + isSilent + " " + hiveConfArgs;

      String workDir = (new File(".")).getCanonicalPath();
      String files = getResourceFiles(conf, SessionState.ResourceType.FILE);
      if (!files.isEmpty()) {
        cmdLine = cmdLine + " -files " + files;

        workDir = (new Path(ctx.getLocalTmpFileURI())).toUri().getPath();

        if (! (new File(workDir)).mkdir()) {
          throw new IOException ("Cannot create tmp working dir: " + workDir);
        }

        for (String f: StringUtils.split(files, ',')) {
          Path p = new Path(f);
          String target = p.toUri().getPath();
          String link = workDir + Path.SEPARATOR + p.getName();
          if (FileUtil.symLink(target, link) != 0) {
            throw new IOException ("Cannot link to added file: " + target + " from: " + link);
          }
        }
      }

      LOG.info("Executing: " + cmdLine);
      Process executor = null;

      // Inherit Java system variables
      String hadoopOpts;
      StringBuilder sb = new StringBuilder();
      Properties p = System.getProperties();
      for (String element : HIVE_SYS_PROP) {
        if (p.containsKey(element)) {
          sb.append(" -D" + element + "=" + p.getProperty(element));
        }
      }
      hadoopOpts = sb.toString();
      // Inherit the environment variables
      String[] env;
      Map<String, String> variables = new HashMap(System.getenv());
      // The user can specify the hadoop memory

      if ("local".equals(conf.getVar(HiveConf.ConfVars.HADOOPJT))) {
        // if we are running in local mode - then the amount of memory used
        // by the child jvm can no longer default to the memory used by the
        // parent jvm
        int hadoopMem = conf.getIntVar(HiveConf.ConfVars.HIVEHADOOPMAXMEM);
        if (hadoopMem == 0) {
          // remove env var that would default child jvm to use parent's memory
          // as default. child jvm would use default memory for a hadoop client
          variables.remove(HADOOP_MEM_KEY);
        } else {
          // user specified the memory for local mode hadoop run
          variables.put(HADOOP_MEM_KEY, String.valueOf(hadoopMem));
        }
      } else {
        // nothing to do - we are not running in local mode - only submitting
        // the job via a child process. in this case it's appropriate that the
        // child jvm use the same memory as the parent jvm
      }

      if (variables.containsKey(HADOOP_OPTS_KEY)) {
        variables.put(HADOOP_OPTS_KEY, variables.get(HADOOP_OPTS_KEY)
            + hadoopOpts);
      } else {
        variables.put(HADOOP_OPTS_KEY, hadoopOpts);
      }
      env = new String[variables.size()];
      int pos = 0;
      for (Map.Entry<String, String> entry : variables.entrySet()) {
        String name = entry.getKey();
        String value = entry.getValue();
        env[pos++] = name + "=" + value;
      }
      // Run ExecDriver in another JVM
      executor = Runtime.getRuntime().exec(cmdLine, env, new File(workDir));

      StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(),
          null, System.out);
      StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(),
          null, System.err);

      outPrinter.start();
      errPrinter.start();

      int exitVal = executor.waitFor();

      if (exitVal != 0) {
        LOG.error("Execution failed with exit status: " + exitVal);
      } else {
        LOG.info("Execution completed successfully");
      }

      return exitVal;
    } catch (Exception e) {
      e.printStackTrace();
      LOG.error("Exception: " + e.getMessage());
      return (1);
    } finally {
      try {
        // creating the context can create a bunch of files. So make
        // sure to clear it out
        if(ctxCreated) {
          ctx.clear();
        }

      } catch (Exception e) {
        LOG.error("Exception: " + e.getMessage());
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.