⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extensionprofile.java

📁 google的gdata api包
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    // a precise match then return it.    ExtensionManifest manifest = getManifest(extendedType);    if (manifest != null && manifest.extendedType == extendedType) {        return manifest;    }    ExtensionManifest newManifest = new ExtensionManifest(extendedType);    // Compute the list of manifests for supertypes.  Do this using a stack,    // so we can process them in reverse order (from the deepest superclass    // to the closest).    Stack<ExtensionManifest> superManifests = new Stack<ExtensionManifest>();    while (manifest != null) {      superManifests.push(manifest);      manifest = getManifest(manifest.extendedType.getSuperclass());    }    // Propagate declarations from any superclass that is already in the    // extension profile, and set up an association from the super manifest    // to the subclass one so future declarations will propagate.    while (!superManifests.empty()) {      ExtensionManifest superManifest = superManifests.pop();      newManifest.supportedExtensions.putAll(          superManifest.supportedExtensions);      newManifest.arbitraryXml = superManifest.arbitraryXml;      superManifest.subclassManifests.add(newManifest);    }    // Look for any existing profile types that extend the newly added    // one and set up a relationship mapping so future declarations on this    // manifest will be propagated    for(Map.Entry<Class, ExtensionManifest> profileMapping :        profile.entrySet()) {      if (extendedType.isAssignableFrom(profileMapping.getKey())) {        newManifest.subclassManifests.add(profileMapping.getValue());      }    }    return newManifest;  }  private synchronized Collection<XmlWriter.Namespace> computeNamespaceDecls() {    HashSet<XmlWriter.Namespace> result = new HashSet<XmlWriter.Namespace>();    result.addAll(additionalNamespaces);    for (ExtensionManifest manifest: profile.values()) {      result.addAll(manifest.getNamespaceDecls());    }    if (feedLinkProfile != null) {      result.addAll(feedLinkProfile.computeNamespaceDecls());    }    if (entryLinkProfile != null) {      result.addAll(entryLinkProfile.computeNamespaceDecls());    }    return Collections.unmodifiableSet(result);  }  /**   * Reads the ExtensionProfile XML format.   */  public class Handler extends XmlParser.ElementHandler {    private ExtensionProfile configProfile;    private ClassLoader configLoader;    private List<XmlWriter.Namespace> namespaces =              new ArrayList<XmlWriter.Namespace>();    public Handler(ExtensionProfile configProfile, ClassLoader configLoader)        throws IOException {      this.configProfile = configProfile;      this.configLoader = configLoader;    }    public void validate() throws ServiceConfigurationException {    }    public void processEndElement() throws ParseException {      try {        validate();      } catch (ServiceConfigurationException e) {        throw new ParseException(e);      }    }    public XmlParser.ElementHandler getChildHandler(String namespace,                                                    String localName,                                                    Attributes attrs)        throws ParseException, IOException {      if (namespace.equals(Namespaces.gdataConfig)) {        if (localName.equals("namespaceDescription")) {          String alias = attrs.getValue("", "alias");          if (alias == null) {            throw new ParseException(                      "NamespaceDescription alias attribute is missing");          }          String uri = attrs.getValue("", "uri");          if (uri == null) {            throw new ParseException(                      "NamespaceDescription uri attribute is missing");          }          XmlWriter.Namespace declaredNs = new XmlWriter.Namespace(alias, uri);          namespaces.add(declaredNs);          declareAdditionalNamespace(declaredNs);          return new XmlParser.ElementHandler();        } else if (localName.equals("extensionPoint")) {          return new ExtensionPointHandler(configProfile, configLoader,                                           namespaces, attrs);        }      }      return super.getChildHandler(namespace, localName, attrs);    }  }  /**   * Reads the ExtensionPoint XML format   */  public class ExtensionPointHandler extends XmlParser.ElementHandler {    private ExtensionProfile configProfile;    private ClassLoader configLoader;    private Class<? extends ExtensionPoint> extensionPoint;    private boolean arbitraryXml;    private List<ExtensionDescription> extDescriptions =      new ArrayList<ExtensionDescription>();    private List<XmlWriter.Namespace> namespaces;    public ExtensionPointHandler(ExtensionProfile configProfile,                                 ClassLoader configLoader,                                 List<XmlWriter.Namespace> namespaces,                                 Attributes attrs)        throws ParseException, IOException {      this.configProfile = configProfile;      this.configLoader = configLoader;      this.namespaces = namespaces;      String extendedClassName = attrs.getValue("", "extendedClass");      if (extendedClassName == null) {        throw new ParseException(                    "ExtensionPoint extendedClass attribute is missing");      }      Class loadedClass;      try {        loadedClass = configLoader.loadClass(extendedClassName);      } catch (ClassNotFoundException e) {        throw new ParseException("Unable to load ExtensionPoint class", e);      }      if (!ExtensionPoint.class.isAssignableFrom(loadedClass)) {        throw new ParseException(                    "Extended classes must extend ExtensionPoint");      }      extensionPoint = extensionPointClass(loadedClass);      String arbitraryXmlAttr = attrs.getValue("", "arbitraryXml");      if (arbitraryXmlAttr != null) {        if (arbitraryXmlAttr.equals("true") || arbitraryXmlAttr.equals("1")) {          arbitraryXml = true;        } else if (arbitraryXmlAttr.equals("false") ||                   arbitraryXmlAttr.equals("0")) {          arbitraryXml = false;        } else {          throw new ParseException("Invalid value for arbitaryXml: " +                                   arbitraryXml);        }      }    }    public void processEndElement() throws ParseException {      if (arbitraryXml) {        declareArbitraryXmlExtension(extensionPoint);      }      for (ExtensionDescription extDescription: extDescriptions) {        declare(extensionPoint, extDescription);      }    }    public XmlParser.ElementHandler getChildHandler(String namespace,                                                    String localName,                                                    Attributes attrs)        throws ParseException, IOException {      if (namespace.equals(Namespaces.gdataConfig)) {        if (localName.equals("extensionDescription")) {          ExtensionDescription extDescription = new ExtensionDescription();          extDescriptions.add(extDescription);          return extDescription.new Handler(configProfile, configLoader,                                            namespaces, attrs);        }      }      return super.getChildHandler(namespace, localName, attrs);    }  }  /**   * Parses XML in the ExtensionProfile format.   *   * @param   configProfile   *            Extension profile description configuration extensions.   *   * @param   classLoader   *            ClassLoader to load extension classes   *   * @param   stream   *            InputStream from which to read the description   */  public void parseConfig(ExtensionProfile configProfile,                          ClassLoader classLoader,                          InputStream stream) throws IOException,                                                   ParseException {    Handler handler = new Handler(configProfile, classLoader);    new XmlParser().parse(stream, handler, Namespaces.gdataConfig,                          "extensionProfile");  }  /**   * Generates XML in the external config format.   *   * @param   w   *          Output writer.   *   * @param   extProfile   *          Extension profile.   *   * @throws  IOException   */  public void generateConfig(XmlWriter w,                             ExtensionProfile extProfile) throws IOException {    w.startElement(Namespaces.gdataConfigNs, "extensionProfile", null, nsDecls);    for (XmlWriter.Namespace namespace : additionalNamespaces) {      List<Attribute> nsAttrs = new ArrayList<Attribute>();      nsAttrs.add(new Attribute("alias", namespace.getAlias()));      nsAttrs.add(new Attribute("uri", namespace.getUri()));      w.simpleElement(Namespaces.gdataConfigNs, "namespaceDescription",                      nsAttrs, null);    }    //    // Get a list of the extended classes sorted by class name    //    TreeSet<Class> extensionSet = new TreeSet<Class>(        new Comparator<Class>() {          public int compare(Class c1, Class c2) {            return c1.getName().compareTo(c2.getName());          }          public boolean equals(Comparator c) {            return this.getClass().equals(c.getClass());          }        });    for (Class extensionPoint : profile.keySet()) {      extensionSet.add(extensionPoint);    }    for (Class extensionPoint : extensionSet) {      ExtensionManifest  manifest = profile.get(extensionPoint);      List<Attribute> ptAttrs = new ArrayList<Attribute>();      ptAttrs.add(new Attribute("extendedClass", extensionPoint.getName()));      ptAttrs.add(new Attribute("arbitraryXml", manifest.arbitraryXml));      w.startElement(Namespaces.gdataConfigNs, "extensionPoint", ptAttrs, null);      // Create an ordered list of the descriptions in this profile      TreeSet<ExtensionDescription> descSet =        new TreeSet<ExtensionDescription>();      for (ExtensionDescription extDescription :           manifest.getSupportedExtensions().values()) {        descSet.add(extDescription);      }      // Now output based upon the ordered list      for (ExtensionDescription extDescription : descSet) {        extDescription.generateConfig(w, extProfile);      }      w.endElement(Namespaces.gdataConfigNs, "extensionPoint");    }    w.endElement(Namespaces.gdataConfigNs, "extensionProfile");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -