Helper to convert StreamConfig into Stream Configuration Impl.

@param config The StreamConfig
@return New instance of StreamConfiguration Impl.
438932
public static final StreamConfiguration encode(final StreamConfig config) {
        Preconditions.checkNotNull(config, "config");
        return StreamConfiguration.builder()
                .scalingPolicy(encode(config.getScalingPolicy()))
                .retentionPolicy(encode(config.getRetentionPolicy()))
                .build();
    }
1072039
@Override
	public void configure(Configuration config) {
		super.configure(config);

		if (configured) {
			return;
		}
		
		final String fieldDelimStr = config.getString(FIELD_DELIMITER_PARAMETER, null);
		if (fieldDelimStr != null) {
			if (fieldDelimStr.length() != 1) {
				throw new IllegalArgumentException("Invalid configuration for CsvInputFormat: " +
						"Field delimiter must be a single character");
			} else {
				setFieldDelimiter(fieldDelimStr.charAt(0));
			}
		}
		
		// read number of field configured via configuration
		int numConfigFields = config.getInteger(NUM_FIELDS_PARAMETER, -1);
		if (numConfigFields != -1) {
			if (numConfigFields <= 0) {
				throw new IllegalConfigurationException("The number of fields for the CsvInputFormat is invalid.");
			}
			
			if (getNumberOfNonNullFields() > 0) {
				throw new IllegalConfigurationException("Mixing configuration via instance parameters and config parameters is not possible.");
			}
		
			int[] textPosIdx = new int[numConfigFields];
			boolean anyTextPosSet = false;
			boolean allTextPosSet = true;
			int maxTextPos = -1;
			
			// parse text positions
			for (int i = 0; i < numConfigFields; i++) {
				int pos = config.getInteger(TEXT_POSITION_PARAMETER_PREFIX + i, -1);
				if (pos == -1) {
					allTextPosSet = false;
					textPosIdx[i] = i;
					maxTextPos = i;
				} else {
					anyTextPosSet = true;
					textPosIdx[i] = pos;
					maxTextPos = pos > maxTextPos ? pos : maxTextPos;
				}
			}
			// check if either none or all text positions have been set
			if (anyTextPosSet && !allTextPosSet) {
				throw new IllegalArgumentException("Invalid configuration for CsvInputFormat: " +
						"Not all text positions set");
			}
			
			// init the array of types to be set. unify the types from the config 
			// with the types array set on the instance
			
			// make sure we have a sufficiently large types array
			@SuppressWarnings("unchecked")
			Class<? extends Value>[] types = (Class<? extends Value>[]) new Class[maxTextPos+1];
			int[] targetPos = new int[maxTextPos+1];
			
			// set the fields
			for (int i = 0; i < numConfigFields; i++) {
				int pos = textPosIdx[i];
				
				Class<? extends Value> clazz = config.getClass(FIELD_TYPE_PARAMETER_PREFIX + i, null).asSubclass(Value.class);
				if (clazz == null) {
					throw new IllegalConfigurationException("Invalid configuration for CsvInputFormat: " +
						"No field parser class for parameter " + i);
				}
				
				types[pos] = clazz;
				targetPos[pos] = i;
			}
			
			// update the field types
			setFieldTypes(types);
			
			// make a dense target pos array
			this.targetPositions = new int[numConfigFields];
			for (int i = 0, k = 0; i < targetPos.length; i++) {
				if (types[i] != null) {
					this.targetPositions[k++] = targetPos[i];
				}
			}
		}
		else {
			// not configured via config parameters
			if (this.targetPositions.length == 0) {
				this.targetPositions = new int[getNumberOfNonNullFields()];
				for (int i = 0; i < this.targetPositions.length; i++) {
					this.targetPositions[i] = i;
				}
			}
		}
		
		if (getNumberOfNonNullFields() == 0) {
			throw new IllegalConfigurationException("No fields configured in the CsvInputFormat.");
		}

		this.configured = true;
	}
788003
private static JCorsConfig loadFromFileStream(InputStream fileStream) {

		try {

			JAXBContext context = JAXBContext.newInstance(ConfigBuilder.class);
			
			Unmarshaller unmarshaller = context.createUnmarshaller();
			unmarshaller.setSchema(loadXmlSchema());

			ConfigBuilder configBuilder = (ConfigBuilder) unmarshaller.unmarshal(fileStream);
			Constraint.ensureNotNull(configBuilder, "It was not possible to get a valid configuration builder instance");

			return configBuilder.buildConfig();

		} catch (Exception e) {

			log.error("Failed loading configuration file", e);
			return null;
		}

	}
317338
public static Set<Policy> policies(Config config) {
    BasicSettings settings = new BasicSettings(config);
    return settings.admission().stream().map(admission ->
      new SegmentedLruPolicy(admission, config)
    ).collect(toSet());
  }
774320
public static ThorntailConfigurationBuilder create(Configuration config)
    {
        ThorntailConfigurationBuilder builder = new ThorntailConfigurationBuilder();

        ConfigurationElement propertiesElem = null;
        try
        {
            propertiesElem = config.getConfigurationElement("properties");
        }
        catch (RuntimeException e)
        {
            // Do nothing
        }
        if (propertiesElem != null)
        {
            Map<String, String> properties = new TreeMap<>();
            propertiesElem.getChildren().stream()
                        .filter(ConfigurationElement.class::isInstance)
                        .map(ConfigurationElement.class::cast)
                        .forEach(elem -> properties.put(elem.getName(), elem.getText()));
            builder.properties(properties);
        }
        return builder;
    }
929669
public static void reconfigure(InputStream config) {
        if (CONTEXT == null) {
            log.warn("当前日志上下文不是logback，不能使用该配置器重新配置");
            return;
        }
        reconfigure(config, CONTEXT);
    }
263321
@SuppressWarnings("unchecked")
    @Override
    public T readConfig(String filePath) throws ConfigurationException {
        XStream xstream = new XStream(new StaxDriver());
        xstream.alias("configuration", clazz);
        return (T) xstream.fromXML(new File(filePath));
    }
272897
public Config build() throws ConfigException {
		if (properties != null) {
			Config config = new Config("properties");
			config.setProperties(properties);
			return config;
		}

		try {
			Loader loader = new Loader();

			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser parser = factory.newSAXParser();
			XMLReader reader = parser.getXMLReader();
			reader.setContentHandler(loader);
			reader.parse(new InputSource(xmlStream));

			return loader.getConfig();
		} catch (Exception e) {
			throw new ConfigException(e);
		}
	}
809667
public static ImmutableConfig copyOf(Config config) {
        if (config instanceof ImmutableConfig) {
            return (ImmutableConfig) config;
        } else {
            return new ImmutableConfig(config);
        }
    }
853174
public static Properties format(Config config) {
        Properties properties = new Properties();
        writeConfig("", config, properties);
        return properties;
    }
891019
private WsByteBufferPoolManager createBufferManager(Map<String, Object> config) {
        WsBBConfigException configError = null;
        Object oClass = config.get("class");
        if (null != oClass && oClass instanceof String) {
            // bundle is specifying a custom class
            String className = (String) oClass;
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Pool class: " + className);
            }
            config.remove("class");
            Class<?> clazz = null;
            try {
                // ClassLoader cl = Thread.currentThread().getContextClassLoader();
                ClassLoader cl = ByteBufferConfiguration.class.getClassLoader();
                if (null != cl) {
                    clazz = cl.loadClass(className);
                }
            } catch (Exception e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(this, tc, "Class load failed using loader: " + e);
                }
                try {
                    clazz = Class.forName(className,
                                          true,
                                          Thread.currentThread().getContextClassLoader());
                } catch (Exception e2) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(this, tc, "Class load failed using Class.forName: " + e2);
                    }
                }
            }

            if (null != clazz) {
                try {
                    Constructor<?> c = clazz.getConstructor(new Class[] { Map.class });
                    return (WsByteBufferPoolManager) c.newInstance(new Object[] { config });
                } catch (Exception e) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(this, tc, "New instance of class " + clazz + " failed: " + e.getCause());
                    }
                    if (e.getCause() instanceof WsBBConfigException) {
                        configError = (WsBBConfigException) e.getCause();
                    }
                }
            }
        }

        // try the default class with the configuration (assuming that
        // config did not previously fail)
        if (null == configError) {
            try {
                return new WsByteBufferPoolManagerImpl(directByteBufferHelper, config);
            } catch (WsBBConfigException e) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                    Tr.event(this, tc, "Error in configuration: " + e);
                }
            }
        }
        // if we failed to create the manager by now, it was due to bad
        // configuration
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(this, tc, "Using default pool class with default config");
        }
        try {
            return new WsByteBufferPoolManagerImpl(directByteBufferHelper);
        } catch (WsBBConfigException e) {
            // shouldn't be possible with default config...
            FFDCFilter.processException(e, getClass().getName() + ".createBufferManager", "2");
            if (TraceComponent.isAnyTracingEnabled() && tc.isEventEnabled()) {
                Tr.event(this, tc, "Failure to create buffer manager: " + e);
            }
            return null;
        }
    }
1360723
@Override
  public StreamImpl stream()
    throws IOException
  {
    if (_streamImpl == null) {
      _streamImpl = new SocketStream();
    }

    _streamImpl.init(_s);

    return _streamImpl;
  }
334515
public static BESecurityConfig fromStream(InputStream in) throws Exception {

        BESecurityConfig config = new BESecurityConfig();

        // instantiate DOM
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(false);
        factory.setValidating(false);
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(in);
        Element root = doc.getDocumentElement();

        // set default role configuration
        DefaultRoleConfig defaultRoleConfig = new DefaultRoleConfig();
        setValuesFromElement(defaultRoleConfig, root);
        config.setDefaultConfig(defaultRoleConfig);

        // get all child config nodes for repeated use
        NodeList nodes = root.getElementsByTagName(_CONFIG);

        // parse and add all explicitly configured sdef configurations
        // while also parsing fedoraInternalCall-1 and setting appropriate vals
        for (int i = 0; i < nodes.getLength(); i++) {
            Element e = (Element) nodes.item(i);
            String role = e.getAttribute(_ROLE);
            if (role.indexOf(":") != -1 && role.indexOf("/") == -1) {
                ServiceDeploymentRoleConfig sDepRoleConfig =
                        new ServiceDeploymentRoleConfig(defaultRoleConfig, role);
                setValuesFromElement(sDepRoleConfig, e);
                config.getServiceDeploymentConfigs().put(role, sDepRoleConfig);
            } else if (role.equals(_INTERNAL_PREFIX + "1")) {
                config.setInternalSSL(getBoolean(e, _CALLSSL));
                config.setInternalBasicAuth(getBoolean(e, _CALLBASICAUTH));
                config.setInternalUsername(getString(e, _CALLUSERNAME));
                config.setInternalPassword(getString(e, _CALLPASSWORD));
                config.setInternalIPList(getStringArray(e, _IPLIST));
            }
        }

        // finally, parse and add all configured methods, first adding
        // a blank sdef role configuration if needed
        for (int i = 0; i < nodes.getLength(); i++) {
            Element e = (Element) nodes.item(i);
            String[] parts = e.getAttribute(_ROLE).split("/");
            if (parts.length == 2) {
                String sDepPID = parts[0];
                String methodName = parts[1];
                ServiceDeploymentRoleConfig sDepRoleConfig =
                        config.getServiceDeploymentConfigs().get(sDepPID);
                if (sDepRoleConfig == null) {
                    sDepRoleConfig =
                            new ServiceDeploymentRoleConfig(defaultRoleConfig, sDepPID);
                    config.getServiceDeploymentConfigs().put(sDepPID, sDepRoleConfig);
                }
                MethodRoleConfig methodRoleConfig =
                        new MethodRoleConfig(sDepRoleConfig, methodName);
                setValuesFromElement(methodRoleConfig, e);
                sDepRoleConfig.getMethodConfigs().put(methodName,
                                                       methodRoleConfig);
            }
        }

        return config;
    }
868257
protected Channel createChannel(ChannelData config) throws ChannelException   
   {
      if (tc.isEntryEnabled()) SibTr.entry(this, tc, "createChannel", config);
      
      Channel retChannel;
      if (config.isInbound())
      {
         if (tc.isDebugEnabled()) SibTr.debug(this, tc, "createChannel", "inbound");
         try
         {
            Class clazz = Class.forName(JFapChannelConstants.INBOUND_CHANNEL_CLASS);
            Constructor contruct = clazz.getConstructor(new Class[] 
                                                        {
                                                           ChannelFactoryData.class, 
                                                           ChannelData.class 
                                                        });
            retChannel = (Channel) contruct.newInstance(new Object[] 
                                                        { 
                                                           channelFactoryData, 
                                                           config 
                                                        });
         }
         catch (Exception e)
         {
            FFDCFilter.processException(e, 
                                        "com.ibm.ws.sib.jfapchannel.impl.JFapChannelFactory.createChannel",  
                                        JFapChannelConstants.JFAPCHANNELFACT_CREATECHANNEL_01,
                                        this);
            
            if (tc.isDebugEnabled()) SibTr.debug(this, tc, "Unable to instantiate inbound channel", e);

            // Rethrow as a channel exception
            throw new ChannelException(e);
         }
      }
      else
      {
         retChannel = new JFapChannelOutbound(channelFactoryData, config);
      }
      
      if (tc.isEntryEnabled()) SibTr.exit(this, tc, "createChannel", retChannel);
      return retChannel;
   }
302735
public static void addConfig(Config config) {
		if (config == null) {
			throw new IllegalArgumentException("Config can not be null");
		}
		if (configNameToConfig.containsKey(config.getName())) {
			throw new IllegalArgumentException("Config already exists: " + config.getName());
		}
		
		configNameToConfig.put(config.getName(), config);
		
		/** 
		 * Replace the main config if current config name is MAIN_CONFIG_NAME
		 */
		if (MAIN_CONFIG_NAME.equals(config.getName())) {
			DbKit.config = config;
			Db.init(DbKit.config.getName());
		}
		
		/**
		 * The configName may not be MAIN_CONFIG_NAME,
		 * the main config have to set the first comming Config if it is null
		 */
		if (DbKit.config == null) {
			DbKit.config = config;
			Db.init(DbKit.config.getName());
		}
	}
164735
private String installConfiguration(String configurationName, InputStream confFileInputStream){
		String outputPath;
		try {
			File confDir = new File(System.getProperty("java.io.tmpdir") + "/dstream_" + UUID.randomUUID());
			confDir.mkdirs();
			File executionConfig = new File(confDir, configurationName);
			executionConfig.deleteOnExit();
			FileOutputStream confFileOs = new FileOutputStream(executionConfig);

			Properties configurationProperties = new Properties();
			configurationProperties.load(confFileInputStream);
			configurationProperties.store(confFileOs, configurationName + " configuration");

			this.addToClassPath(confDir);

			outputPath = configurationProperties.containsKey(DStreamConstants.OUTPUT)
					? configurationProperties.getProperty(DStreamConstants.OUTPUT)
							: configurationName.split("\\.")[0] + "/out";
		}
		catch (Exception e) {
			throw new IllegalStateException("Failed to generate execution config", e);
		}
		return outputPath;
	}
1088023
public void setConfig(Configuration config) {
		if (config == null) {
			throw new IllegalArgumentException("Parameter config must not be null.");
		}
	    this.config = config;
	    this.loadFrom(config);
	}