flex-messaging-common-1.0

16:35:49.984 INFO  jd.cli.Main - Decompiling flex-messaging-common-1.0.jar
package flex.messaging.config;

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XPathClientConfigurationParser
  extends ClientConfigurationParser
{
  private XPath xpath;
  
  protected void initializeExpressionQuery()
  {
    xpath = XPathFactory.newInstance().newXPath();
  }
  
  protected Node selectSingleNode(Node source, String expression)
  {
    try
    {
      return (Node)xpath.evaluate(expression, source, XPathConstants.NODE);
    }
    catch (XPathExpressionException expressionException)
    {
      throw wrapException(expressionException);
    }
  }
  
  protected NodeList selectNodeList(Node source, String expression)
  {
    try
    {
      return (NodeList)xpath.evaluate(expression, source, XPathConstants.NODESET);
    }
    catch (XPathExpressionException expressionException)
    {
      throw wrapException(expressionException);
    }
  }
  
  protected Object evaluateExpression(Node source, String expression)
  {
    try
    {
      return xpath.evaluate(expression, source, XPathConstants.STRING);
    }
    catch (XPathExpressionException expressionException)
    {
      throw wrapException(expressionException);
    }
  }
  
  private ConfigurationException wrapException(XPathExpressionException exception)
  {
    ConfigurationException result = new ConfigurationException();
    result.setDetails(10101);
    result.setRootCause(exception);
    return result;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.XPathClientConfigurationParser
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package flex.graphics;

import java.util.HashMap;
import java.util.Map;

public class ImageSnapshot
  extends HashMap
{
  private static final long serialVersionUID = 7914317354403674061L;
  private Map properties;
  private String contentType;
  private byte[] data;
  private int height;
  private int width;
  
  public String getContentType()
  {
    return contentType;
  }
  
  public void setContentType(String value)
  {
    contentType = value;
  }
  
  public byte[] getData()
  {
    return data;
  }
  
  public void setData(byte[] value)
  {
    data = value;
  }
  
  public int getHeight()
  {
    return height;
  }
  
  public void setHeight(int value)
  {
    height = value;
  }
  
  public Map getProperties()
  {
    return properties;
  }
  
  public void setProperties(Map value)
  {
    properties = value;
  }
  
  public int getWidth()
  {
    return width;
  }
  
  public void setWidth(int value)
  {
    width = value;
  }
}

/* Location:
 * Qualified Name:     flex.graphics.ImageSnapshot
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging;

import flex.messaging.util.PropertyStringResourceLoader;
import flex.messaging.util.ResourceLoader;
import java.util.Locale;

public class LocalizedException
  extends RuntimeException
{
  protected transient ResourceLoader resourceLoader;
  protected int number;
  protected String message;
  protected String details;
  protected Throwable rootCause;
  private static final long serialVersionUID = 7980539484335065853L;
  
  public LocalizedException() {}
  
  public LocalizedException(ResourceLoader resourceLoader)
  {
    this.resourceLoader = resourceLoader;
  }
  
  public String getDetails()
  {
    return details;
  }
  
  public void setDetails(String details)
  {
    this.details = details;
  }
  
  public void setMessage(int number)
  {
    setMessage(number, null, null, null);
  }
  
  public void setMessage(int number, Locale locale)
  {
    setMessage(number, null, locale, null);
  }
  
  public void setMessage(int number, Object[] arguments)
  {
    setMessage(number, null, null, arguments);
  }
  
  public void setMessage(int number, String variant)
  {
    setMessage(number, variant, null, null);
  }
  
  public void setMessage(int number, String variant, Locale locale)
  {
    setMessage(number, variant, locale, null);
  }
  
  public void setMessage(int number, String variant, Object[] arguments)
  {
    setMessage(number, variant, null, arguments);
  }
  
  public void setMessage(int number, String variant, Locale locale, Object[] arguments)
  {
    setNumber(number);
    ResourceLoader resources = getResourceLoader();
    setMessage(resources.getString(generateFullKey(number, variant), locale, arguments));
  }
  
  public String getMessage()
  {
    return message;
  }
  
  public void setMessage(String message)
  {
    this.message = message;
  }
  
  public void setNumber(int number)
  {
    this.number = number;
  }
  
  public int getNumber()
  {
    return number;
  }
  
  public void setDetails(int number)
  {
    setDetails(number, null, null, null);
  }
  
  public void setDetails(int number, String variant)
  {
    setDetails(number, variant, null, null);
  }
  
  public void setDetails(int number, String variant, Locale locale)
  {
    setDetails(number, variant, locale, null);
  }
  
  public void setDetails(int number, String variant, Object[] arguments)
  {
    setDetails(number, variant, null, arguments);
  }
  
  public void setDetails(int number, String variant, Locale locale, Object[] arguments)
  {
    setNumber(number);
    ResourceLoader resources = getResourceLoader();
    setDetails(resources.getString(generateDetailsKey(number, variant), locale, arguments));
  }
  
  public Throwable getRootCause()
  {
    return rootCause;
  }
  
  public void setRootCause(Throwable cause)
  {
    rootCause = cause;
    
    initCause(cause);
  }
  
  protected ResourceLoader getResourceLoader()
  {
    if (resourceLoader == null) {
      resourceLoader = new PropertyStringResourceLoader();
    }
    return resourceLoader;
  }
  
  private String generateFullKey(int number, String variant)
  {
    return variant != null ? number + "-" + variant : String.valueOf(number);
  }
  
  private String generateDetailsKey(int number, String variant)
  {
    return generateFullKey(number, variant) + "-details";
  }
  
  public String toString()
  {
    String result = super.toString();
    if (details != null)
    {
      StringBuffer buffer = new StringBuffer(result);
      if (!result.endsWith(".")) {
        buffer.append(".");
      }
      buffer.append(' ').append(details);
      result = buffer.toString();
    }
    return result;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.LocalizedException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

import flex.messaging.util.FileUtils;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public abstract class AbstractConfigurationParser
  implements ConfigurationParser, ConfigurationConstants
{
  protected ServicesConfiguration config;
  protected DocumentBuilder docBuilder;
  protected ConfigurationFileResolver fileResolver;
  protected TokenReplacer tokenReplacer;
  private Map fileByDocument = new HashMap();
  
  protected AbstractConfigurationParser()
  {
    initializeDocumentBuilder();
    tokenReplacer = new TokenReplacer();
  }
  
  public void parse(String path, ConfigurationFileResolver fileResolver, ServicesConfiguration config)
  {
    this.config = config;
    this.fileResolver = fileResolver;
    Document doc = loadDocument(path, fileResolver.getConfigurationFile(path));
    initializeExpressionQuery();
    parseTopLevelConfig(doc);
  }
  
  public void reportTokens()
  {
    tokenReplacer.reportTokens();
  }
  
  protected void initializeDocumentBuilder()
  {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setIgnoringComments(true);
    factory.setIgnoringElementContentWhitespace(true);
    try
    {
      docBuilder = factory.newDocumentBuilder();
    }
    catch (ParserConfigurationException ex)
    {
      ConfigurationException e = new ConfigurationException();
      e.setMessage(10100);
      e.setRootCause(ex);
      throw e;
    }
  }
  
  protected Document loadDocument(String path, InputStream in)
  {
    try
    {
      if (!in.markSupported()) {
        in = new BufferedInputStream(in);
      }
      String encoding = FileUtils.consumeBOM(in, null);
      Document doc;
      Document doc;
      if (("UTF-8".equals(encoding)) || ("UTF-16".equals(encoding)))
      {
        InputSource inputSource = new InputSource(in);
        inputSource.setEncoding(encoding);
        doc = docBuilder.parse(inputSource);
      }
      else
      {
        doc = docBuilder.parse(in);
      }
      addFileByDocument(path, doc);
      doc.getDocumentElement().normalize();
      return doc;
    }
    catch (SAXParseException ex)
    {
      Integer line = new Integer(ex.getLineNumber());
      Integer col = new Integer(ex.getColumnNumber());
      String message = ex.getMessage();
      
      ConfigurationException e = new ConfigurationException();
      e.setMessage(10102, new Object[] { line, col, message });
      e.setRootCause(ex);
      throw e;
    }
    catch (SAXException ex)
    {
      ConfigurationException e = new ConfigurationException();
      e.setMessage(ex.getMessage());
      e.setRootCause(ex);
      throw e;
    }
    catch (IOException ex)
    {
      ConfigurationException e = new ConfigurationException();
      e.setMessage(ex.getMessage());
      e.setRootCause(ex);
      throw e;
    }
  }
  
  protected void addFileByDocument(String path, Node node)
  {
    String shortPath = path;
    if ((shortPath != null) && ((shortPath.indexOf("/") != -1) || (shortPath.indexOf("\\") != -1)))
    {
      int start = 0;
      start = shortPath.lastIndexOf("/");
      if (start == -1) {
        start = shortPath.lastIndexOf("\\");
      }
      shortPath = path.substring(start + 1);
    }
    fileByDocument.put(node, shortPath);
  }
  
  protected String getSourceFileOf(Node node)
  {
    return (String)fileByDocument.get(node.getOwnerDocument());
  }
  
  protected abstract void parseTopLevelConfig(Document paramDocument);
  
  protected abstract void initializeExpressionQuery();
  
  protected abstract Node selectSingleNode(Node paramNode, String paramString);
  
  protected abstract NodeList selectNodeList(Node paramNode, String paramString);
  
  protected abstract Object evaluateExpression(Node paramNode, String paramString);
  
  public ConfigMap properties(NodeList properties)
  {
    return properties(properties, "uknown file");
  }
  
  public ConfigMap properties(NodeList properties, String sourceFileName)
  {
    int length = properties.getLength();
    ConfigMap map = new ConfigMap(length);
    for (int p = 0; p < length; p++)
    {
      Node prop = properties.item(p);
      String propName = prop.getNodeName();
      if (propName != null)
      {
        propName = propName.trim();
        if (prop.getNodeType() == 1)
        {
          NodeList attributes = selectNodeList(prop, "@*");
          NodeList children = selectNodeList(prop, "*");
          if ((children.getLength() > 0) || (attributes.getLength() > 0))
          {
            ConfigMap childMap = new ConfigMap();
            if (children.getLength() > 0) {
              childMap.addProperties(properties(children, sourceFileName));
            }
            if (attributes.getLength() > 0) {
              childMap.addProperties(properties(attributes, sourceFileName));
            }
            map.addProperty(propName, childMap);
          }
          else
          {
            tokenReplacer.replaceToken(prop, sourceFileName);
            String propValue = evaluateExpression(prop, ".").toString();
            map.addProperty(propName, propValue);
          }
        }
        else
        {
          tokenReplacer.replaceToken(prop, sourceFileName);
          map.addProperty(propName, prop.getNodeValue());
        }
      }
    }
    return map;
  }
  
  public String getAttributeOrChildElement(Node node, String name)
  {
    String attr = evaluateExpression(node, "@" + name).toString().trim();
    if (attr.length() == 0) {
      attr = evaluateExpression(node, name).toString().trim();
    }
    return attr;
  }
  
  public void allowedChildElements(Node node, String[] allowed)
  {
    NodeList children = selectNodeList(node, "*");
    
    String unexpected = unexpected(children, allowed);
    if (unexpected != null)
    {
      ConfigurationException ex = new ConfigurationException();
      Object[] args = { unexpected, node.getNodeName(), getSourceFilename(node) };
      ex.setMessage(10106, args);
      throw ex;
    }
    NodeList textNodes = selectNodeList(node, "text()");
    for (int i = 0; i < textNodes.getLength(); i++)
    {
      String text = evaluateExpression(textNodes.item(i), ".").toString().trim();
      if (text.length() > 0)
      {
        ConfigurationException ex = new ConfigurationException();
        Object[] args = { text, node.getNodeName(), getSourceFilename(node) };
        ex.setMessage(11104, args);
        throw ex;
      }
    }
  }
  
  public void allowedAttributes(Node node, String[] allowed)
  {
    NodeList attributes = selectNodeList(node, "@*");
    String unexpectedAttribute = unexpected(attributes, allowed);
    if (unexpectedAttribute != null)
    {
      ConfigurationException ex = new ConfigurationException();
      Object[] args = { unexpectedAttribute, node.getNodeName(), getSourceFilename(node) };
      
      ex.setMessage(10107, args);
      throw ex;
    }
  }
  
  private String getSourceFilename(Node node)
  {
    return getSourceFileOf(node);
  }
  
  public void allowedAttributesOrElements(Node node, String[] allowed)
  {
    allowedAttributes(node, allowed);
    allowedChildElements(node, allowed);
  }
  
  public void requiredAttributesOrElements(Node node, String[] required)
  {
    String nodeName = node.getNodeName();
    NodeList attributes = selectNodeList(node, "@*");
    
    List list = new ArrayList();
    for (int i = 0; i < required.length; i++) {
      list.add(required[i]);
    }
    String missingAttribute = null;
    do
    {
      missingAttribute = required(attributes, list);
      if (missingAttribute != null)
      {
        Node child = selectSingleNode(node, missingAttribute);
        if (child != null)
        {
          list.remove(missingAttribute);
        }
        else
        {
          ConfigurationException ex = new ConfigurationException();
          ex.setMessage(10105, new Object[] { missingAttribute, nodeName });
          throw ex;
        }
      }
    } while ((missingAttribute != null) && (list.size() > 0));
  }
  
  public void requiredChildElements(Node node, String[] required)
  {
    String nodeName = node.getNodeName();
    NodeList children = selectNodeList(node, "*");
    
    List list = new ArrayList();
    for (int i = 0; i < required.length; i++) {
      list.add(required[i]);
    }
    String missing = required(children, list);
    if (missing != null)
    {
      ConfigurationException ex = new ConfigurationException();
      ex.setMessage(10104, new Object[] { missing, nodeName });
      throw ex;
    }
  }
  
  public String unexpected(NodeList attributes, String[] allowed)
  {
    for (int i = 0; i < attributes.getLength(); i++)
    {
      Node attrib = attributes.item(i);
      String attribName = attrib.getNodeName();
      boolean match = false;
      for (int j = 0; j < allowed.length; j++)
      {
        String a = allowed[j];
        if (a.equals(attribName))
        {
          match = true;
          break;
        }
      }
      if (!match) {
        return attribName;
      }
      tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
    }
    return null;
  }
  
  public String required(NodeList attributes, List required)
  {
    for (int i = 0; i < required.size(); i++)
    {
      boolean found = false;
      String req = (String)required.get(i);
      
      Node attrib = null;
      for (int j = 0; j < attributes.getLength(); j++)
      {
        attrib = attributes.item(j);
        String attribName = attrib.getNodeName();
        if (req.equals(attribName))
        {
          found = true;
          break;
        }
      }
      if (!found) {
        return req;
      }
      tokenReplacer.replaceToken(attrib, getSourceFilename(attrib));
    }
    return null;
  }
  
  public static boolean isValidID(String id)
  {
    if (id != null) {
      if ((id.length() > 0) && (id.length() < 256))
      {
        char[] chars = id.toCharArray();
        for (int i = 0; i < chars.length; i++)
        {
          char c = chars[i];
          if (",;:".indexOf(c) != -1) {
            return false;
          }
        }
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.AbstractConfigurationParser
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

public class AdapterSettings
  extends PropertiesSettings
{
  private final String id;
  private String sourceFile;
  private String className;
  private boolean defaultAdapter;
  
  public AdapterSettings(String id)
  {
    this.id = id;
  }
  
  public String getId()
  {
    return id;
  }
  
  public String getClassName()
  {
    return className;
  }
  
  public void setClassName(String name)
  {
    className = name;
  }
  
  public boolean isDefault()
  {
    return defaultAdapter;
  }
  
  public void setDefault(boolean b)
  {
    defaultAdapter = b;
  }
  
  String getSourceFile()
  {
    return sourceFile;
  }
  
  void setSourceFile(String file)
  {
    sourceFile = file;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.AdapterSettings
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

import javax.xml.transform.TransformerException;
import org.apache.xpath.CachedXPathAPI;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class ApacheXPathClientConfigurationParser
  extends ClientConfigurationParser
{
  private CachedXPathAPI xpath;
  
  protected void initializeExpressionQuery()
  {
    xpath = new CachedXPathAPI();
  }
  
  protected Node selectSingleNode(Node source, String expression)
  {
    try
    {
      return xpath.selectSingleNode(source, expression);
    }
    catch (TransformerException transformerException)
    {
      throw wrapException(transformerException);
    }
  }
  
  protected NodeList selectNodeList(Node source, String expression)
  {
    try
    {
      return xpath.selectNodeList(source, expression);
    }
    catch (TransformerException transformerException)
    {
      throw wrapException(transformerException);
    }
  }
  
  protected Object evaluateExpression(Node source, String expression)
  {
    try
    {
      return xpath.eval(source, expression);
    }
    catch (TransformerException transformerException)
    {
      throw wrapException(transformerException);
    }
  }
  
  private ConfigurationException wrapException(TransformerException exception)
  {
    ConfigurationException result = new ConfigurationException();
    result.setDetails(10101);
    result.setRootCause(exception);
    return result;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.ApacheXPathClientConfigurationParser
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

import flex.messaging.util.StringUtils;

public class ChannelSettings
  extends PropertiesSettings
{
  protected String id;
  protected boolean remote;
  protected String serverId;
  private String sourceFile;
  protected SecurityConstraint constraint;
  protected String uri;
  protected int port;
  protected String endpointType;
  protected String clientType;
  protected String parsedUri;
  protected boolean contextParsed;
  protected String parsedClientUri;
  protected boolean clientContextParsed;
  
  public ChannelSettings(String id)
  {
    this.id = id;
  }
  
  public String getId()
  {
    return id;
  }
  
  public boolean isRemote()
  {
    return remote;
  }
  
  public void setRemote(boolean value)
  {
    remote = value;
  }
  
  public String getServerId()
  {
    return serverId;
  }
  
  public void setServerId(String value)
  {
    serverId = value;
  }
  
  public String getClientType()
  {
    return clientType;
  }
  
  public void setClientType(String type)
  {
    clientType = type;
  }
  
  String getSourceFile()
  {
    return sourceFile;
  }
  
  void setSourceFile(String sourceFile)
  {
    this.sourceFile = sourceFile;
  }
  
  public int getPort()
  {
    return port;
  }
  
  public String getUri()
  {
    return uri;
  }
  
  public void setUri(String uri)
  {
    this.uri = uri;
    port = parsePort(this, uri);
    contextParsed = false;
    clientContextParsed = false;
  }
  
  public String getClientParsedUri(String contextPath)
  {
    if (!clientContextParsed) {
      parseClientUri(this, contextPath);
    }
    return parsedClientUri;
  }
  
  public String getEndpointType()
  {
    return endpointType;
  }
  
  public void setEndpointType(String type)
  {
    endpointType = type;
  }
  
  public SecurityConstraint getConstraint()
  {
    return constraint;
  }
  
  public void setConstraint(SecurityConstraint constraint)
  {
    this.constraint = constraint;
  }
  
  private static void parseClientUri(ChannelSettings cs, String contextPath)
  {
    if (!clientContextParsed)
    {
      String channelEndpoint = cs.getUri().trim();
      
      channelEndpoint = StringUtils.substitute(channelEndpoint, "{context-root}", "{context.root}");
      if ((contextPath == null) && (channelEndpoint.indexOf("{context.root}") != -1))
      {
        ConfigurationException e = new ConfigurationException();
        e.setMessage(11120, new Object[] { cs.getId() });
        throw e;
      }
      if ((contextPath != null) && (!contextPath.startsWith("/"))) {
        contextPath = "/" + contextPath;
      }
      if (channelEndpoint.indexOf("/{context.root}") != -1)
      {
        if (("/".equals(contextPath)) && (!"/{context.root}".equals(channelEndpoint))) {
          contextPath = "";
        }
        channelEndpoint = StringUtils.substitute(channelEndpoint, "/{context.root}", contextPath);
      }
      else
      {
        if (("/".equals(contextPath)) && (!"{context.root}".equals(channelEndpoint))) {
          contextPath = "";
        }
        channelEndpoint = StringUtils.substitute(channelEndpoint, "{context.root}", contextPath);
      }
      parsedClientUri = channelEndpoint;
      clientContextParsed = true;
    }
  }
  
  private static int parsePort(ChannelSettings cs, String url)
  {
    int port = 0;
    
    int start = url.indexOf(":/");
    if (start > 0)
    {
      start += 3;
      int end = url.indexOf('/', start);
      
      String snp = end == -1 ? url.substring(start) : url.substring(start, end);
      
      int delim = snp.indexOf("]");
      delim = delim > -1 ? snp.indexOf(":", delim) : snp.indexOf(":");
      if (delim > 0) {
        try
        {
          int p = Integer.parseInt(snp.substring(delim + 1));
          if (p > 0) {
            port = p;
          }
        }
        catch (Throwable t) {}
      }
    }
    return port;
  }
  
  public static String removeTokens(String url)
  {
    String channelEndpoint = url.toLowerCase().trim();
    if ((channelEndpoint.startsWith("http://")) || (channelEndpoint.startsWith("https://")) || (channelEndpoint.startsWith("rtmp://")) || (channelEndpoint.startsWith("rtmps://")))
    {
      int nextSlash = channelEndpoint.indexOf('/', 8);
      if ((nextSlash > 0) && (nextSlash != channelEndpoint.length() - 1)) {
        channelEndpoint = channelEndpoint.substring(nextSlash);
      }
    }
    channelEndpoint = StringUtils.substitute(channelEndpoint, "{context-root}", "{context.root}");
    if (channelEndpoint.startsWith("{context.root}")) {
      channelEndpoint = channelEndpoint.substring("{context.root}".length());
    } else if (channelEndpoint.startsWith("/{context.root}")) {
      channelEndpoint = channelEndpoint.substring("/{context.root}".length());
    }
    if (channelEndpoint.endsWith("/")) {
      channelEndpoint = channelEndpoint.substring(0, channelEndpoint.length() - 1);
    }
    return channelEndpoint;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.ChannelSettings
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class ClientConfiguration
  implements ServicesConfiguration
{
  protected final Map channelSettings;
  protected final List defaultChannels;
  protected final List serviceSettings;
  protected LoggingSettings loggingSettings;
  protected Map configPaths;
  protected final Map clusterSettings;
  
  public ClientConfiguration()
  {
    channelSettings = new HashMap();
    defaultChannels = new ArrayList(4);
    clusterSettings = new HashMap();
    serviceSettings = new ArrayList();
    configPaths = new HashMap();
  }
  
  public void addChannelSettings(String id, ChannelSettings settings)
  {
    channelSettings.put(id, settings);
  }
  
  public ChannelSettings getChannelSettings(String ref)
  {
    return (ChannelSettings)channelSettings.get(ref);
  }
  
  public Map getAllChannelSettings()
  {
    return channelSettings;
  }
  
  public void addDefaultChannel(String id)
  {
    defaultChannels.add(id);
  }
  
  public List getDefaultChannels()
  {
    return defaultChannels;
  }
  
  public void addServiceSettings(ServiceSettings settings)
  {
    serviceSettings.add(settings);
  }
  
  public ServiceSettings getServiceSettings(String serviceType)
  {
    for (Iterator iter = this.serviceSettings.iterator(); iter.hasNext();)
    {
      ServiceSettings serviceSettings = (ServiceSettings)iter.next();
      if (serviceSettings.getId().equals(serviceType)) {
        return serviceSettings;
      }
    }
    return null;
  }
  
  public List getAllServiceSettings()
  {
    return serviceSettings;
  }
  
  public void addClusterSettings(ClusterSettings settings)
  {
    Iterator it;
    if (settings.isDefault()) {
      for (it = clusterSettings.values().iterator(); it.hasNext();)
      {
        ClusterSettings cs = (ClusterSettings)it.next();
        if (cs.isDefault())
        {
          ConfigurationException cx = new ConfigurationException();
          cx.setMessage(10214, new Object[] { settings.getClusterName(), cs.getClusterName() });
          throw cx;
        }
      }
    }
    if (clusterSettings.containsKey(settings.getClusterName()))
    {
      ConfigurationException cx = new ConfigurationException();
      cx.setMessage(10206, new Object[] { settings.getClusterName() });
      throw cx;
    }
    clusterSettings.put(settings.getClusterName(), settings);
  }
  
  public ClusterSettings getClusterSettings(String clusterId)
  {
    for (Iterator it = clusterSettings.values().iterator(); it.hasNext();)
    {
      ClusterSettings cs = (ClusterSettings)it.next();
      if (cs.getClusterName() == clusterId) {
        return cs;
      }
      if ((cs.getClusterName() != null) && (cs.getClusterName().equals(clusterId))) {
        return cs;
      }
    }
    return null;
  }
  
  public ClusterSettings getDefaultCluster()
  {
    for (Iterator it = clusterSettings.values().iterator(); it.hasNext();)
    {
      ClusterSettings cs = (ClusterSettings)it.next();
      if (cs.isDefault()) {
        return cs;
      }
    }
    return null;
  }
  
  public void setLoggingSettings(LoggingSettings settings)
  {
    loggingSettings = settings;
  }
  
  public LoggingSettings getLoggingSettings()
  {
    return loggingSettings;
  }
  
  public void addConfigPath(String path, long modified)
  {
    configPaths.put(path, new Long(modified));
  }
  
  public Map getConfigPaths()
  {
    return configPaths;
  }
}

/* Location:
 * Qualified Name:     flex.messaging.config.ClientConfiguration
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package flex.messaging.config;

import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public abstract class ClientConfigurationParser
  extends AbstractConfigurationParser
{
  protected void parseTopLevelConfig(Document doc)
  {
    Node root = selectSingleNode(doc, "/services-config");
    if (root != null)
    {
      allowedChildElements(root, SERVICES_CONFIG_CHILDREN);
      
      channelsSection(root);
      
      services(root);
      
      clusters(root);
    }
  }
  
  private void channelsSection(Node root)
  {
    Node channelsNode = selectSingleNode(root, "channels");
    if (channelsNode != null)
    {
      allowedAttributesOrElements(channelsNode, CHANNELS_CHILDREN);
      
      NodeList channels = selectNodeList(channelsNode, "channel-definition");
      for (int i = 0; i < channels.getLength(); i++)
      {
        Node channel = channels.item(i);
        channelDefinition(channel);
      }
    }
  }
  
  private void channelDefinition(Node channel)
  {
    requiredAttributesOrElements(channel, CHANNEL_DEFINITION_REQ_CHILDREN);
    allowedAttributesOrElements(channel, CHANNEL_DEFINITION_CHILDREN);
    
    String id = getAttributeOrChildElement(channel, "id").trim();
    if (isValidID(id))
    {
      if (config.getChannelSettings(id) != null)
      {
        ConfigurationException e = new ConfigurationException();
        e.setMessage(11127, new Object[] { id });
        throw e;
      }
      ChannelSettings channelSettings = new ChannelSettings(id);
      
      String clientType = getAttributeOrChildElement(channel, "class");
      channelSettings.setClientType(clientType);
      
      Node endpoint = selectSingleNode(channel, "endpoint");
      if (endpoint != null)
      {
        allowedAttributesOrElements(endpoint, ENDPOINT_CHILDREN);
        
        String uri = getAttributeOrChildElement(endpoint, "url");
        if ((uri == null) || ("".equals(uri))) {
          uri = getAttributeOrChildElement(endpoint, "uri");
        }
        channelSettings.setUri(uri);
        
        config.addChannelSettings(id, channelSettings);
      }
      NodeList properties = selectNodeList(channel, "properties/polling-enabled");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/polling-interval-millis");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/piggybacking-enabled");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/login-after-disconnect");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/serialization");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        ConfigMap serialization = map.getPropertyAsMap("serialization", null);
        if (serialization != null)
        {
          String enableSmallMessages = serialization.getProperty("enable-small-messages");
          if (enableSmallMessages != null)
          {
            ConfigMap clientMap = new ConfigMap();
            clientMap.addProperty("enable-small-messages", enableSmallMessages);
            channelSettings.addProperty("serialization", clientMap);
          }
        }
      }
      properties = selectNodeList(channel, "properties/record-message-sizes");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/record-message-times");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/polling-interval-seconds");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
      properties = selectNodeList(channel, "properties/connect-timeout-seconds");
      if (properties.getLength() > 0)
      {
        ConfigMap map = properties(properties, getSourceFileOf(channel));
        channelSettings.addProperties(map);
      }
    }
    else
    {
      ConfigurationException ex = new ConfigurationException();
      ex.setMessage(10110, new Object[] { "channel-definition", id });
      String details = "An id must be non-empty and not contain any list delimiter characters, i.e. commas, semi-colons or colons.";
      ex.setDetails(details);
      throw ex;
    }
  }
  
  private void services(Node root)
  {
    Node servicesNode = selectSingleNode(root, "services");
    if (servicesNode != null)
    {
      allowedChildElements(servicesNode, SERVICES_CHILDREN);
      
      Node defaultChannels = selectSingleNode(servicesNode, "default-channels");
      if (defaultChannels != null)
      {
        allowedChildElements(defaultChannels, DEFAULT_CHANNELS_CHILDREN);
        NodeList channels = selectNodeList(defaultChannels, "channel");
        for (int c = 0; c < channels.getLength(); c++)
        {
          Node chan = channels.item(c);
          allowedAttributes(chan, new String[] { "ref" });
          defaultChannel(chan);
        }
      }
      NodeList services = selectNodeList(servicesNode, "service-include");
      for (int i = 0; i < services.getLength(); i++)
      {
        Node service = services.item(i);
        serviceInclude(service);
      }
      services = selectNodeList(servicesNode, "service");
      for (int i = 0; i < services.getLength(); i++)
      {
        Node service = services.item(i);
        service(service);
      }
    }
  }
  
  private void clusters(Node root)
  {
    Node clusteringNode = selectSingleNode(root, "clusters");
    if (clusteringNode != null)
    {
      allowedAttributesOrElements(clusteringNode, CLUSTERING_CHILDREN);
      
      NodeList clusters = selectNodeList(clusteringNode, "cluster");
      for (int i = 0; i < clusters.getLength(); i++)
      {
        Node cluster = clusters.item(i);
        requiredAttributesOrElements(cluster, CLUSTER_DEFINITION_CHILDREN);
        String clusterName = getAttributeOrChildElement(cluster, "id");
        if (isValidID(clusterName))
        {
          String propsFileName = getAttributeOrChildElement(cluster, "properties");
          ClusterSettings clusterSettings = new ClusterSettings();
          clusterSettings.setClusterName(clusterName);
          clusterSettings.setPropsFileName(propsFileName);
          String defaultValue = getAttributeOrChildElement(cluster, "default");
          if ((defaultValue != null) && (defaultValue.length() > 0)) {
            if (defaultValue.equalsIgnoreCase("true"))
            {
              clusterSettings.setDefault(true);
            }
            else if (!defaultValue.equalsIgnoreCase("false"))
            {
              ConfigurationException e = new ConfigurationException();
              e.setMessage(10215, new Object[] { clusterName, defaultValue });
              throw e;
            }
          }
          String ulb = getAttributeOrChildElement(cluster, "url-load-balancing");
          if ((ulb != null) && (ulb.length() > 0)) {
            if (ulb.equalsIgnoreCase("false"))
            {
              clusterSettings.setURLLoadBalancing(false);
            }
            else if (!ulb.equalsIgnoreCase("true"))
            {
              ConfigurationException e = new ConfigurationException();
              e.setMessage(10216, new Object[] { clusterName, ulb });
              throw e;
            }
          }
          ((ClientConfiguration)config).addClusterSettings(clusterSettings);
        }
      }
    }
  }
  
  private void serviceInclude(Node serviceInclude)
  {
    requiredAttributesOrElements(serviceInclude, SERVICE_INCLUDE_CHILDREN);
    
    String src = getAttributeOrChildElement(serviceInclude, "file-path");
    if (src.length() > 0)
    {
      Document doc = loadDocument(src, fileResolver.getIncludedFile(src));
      if ((fileResolver instanceof LocalFileResolver))
      {
        LocalFileResolver local = (LocalFileResolver)fileResolver;
        ((ClientConfiguration)config).addConfigPath(local.getIncludedPath(src), local.getIncludedLastModified(src));
      }
      doc.getDocumentElement().normalize();
      
      Node service = selectSingleNode(doc, "/service");
      if (service != null)
      {
        service(service);
        fileResolver.popIncludedFile();
      }
      else
      {
        ConfigurationException ex = new ConfigurationException();
        ex.setMessage(10112, new Object[] { "service" });
        throw ex;
      }
    }
  }
  
  private void service(Node service)
  {
    requiredAttributesOrElements(service, SERVICE_REQ_CHILDREN);
    allowedAttributesOrElements(service, SERVICE_CHILDREN);
    
    String id = getAttributeOrChildElement(service, "id");
    if (isValidID(id))
    {
      ServiceSettings serviceSettings = config.getServiceSettings(id);
      if (serviceSettings == null)
      {
        serviceSettings = new ServiceSettings(id);
        
        NodeList properties = selectNodeList(service, "properties/*");
        if (properties.getLength() > 0)
        {
          ConfigMap map = properties(properties, getSourceFileOf(service));
          serviceSettings.addProperties(map);
        }
        config.addServiceSettings(serviceSettings);
      }
      else
      {
        ConfigurationException e = new ConfigurationException();
        e.setMessage(10113, new Object[] { id });
        throw e;
      }
      Node defaultChannels = selectSingleNode(service, "default-channels");
      Iterator iter;
      if (defaultChannels != null)
      {
        allowedChildElements(defaultChannels, DEFAULT_CHANNELS_CHILDREN);
        NodeList channels = selectNodeList(defaultChannels, "channel");
        for (int c = 0; c < channels.getLength(); c++)
        {
          Node chan = channels.item(c);
          allowedAttributes(chan, new String[] { "ref" });
          defaultChannel(chan, serviceSettings);
        }
      }
      else if (config.getDefaultChannels().size() > 0)
      {
        for (iter = config.getDefaultChannels().iterator(); iter.hasNext();)
        {
          String channelId = (String)iter.next();
          ChannelSettings channel = config.getChannelSettings(channelId);
          serviceSettings.addDefaultChannel(channel);
        }
      }
      
1 2 3 4 5

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd