📄 extensionprofile.java
字号:
/* Copyright (c) 2006 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package com.google.gdata.data;import com.google.gdata.util.common.base.Pair;import com.google.gdata.util.common.xml.XmlWriter;import com.google.gdata.util.Namespaces;import com.google.gdata.util.ParseException;import com.google.gdata.util.ServiceConfigurationException;import com.google.gdata.util.XmlParser;import org.xml.sax.Attributes;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;import java.util.TreeSet;import org.xml.sax.Attributes;import com.google.gdata.util.common.base.Pair;import com.google.gdata.util.common.xml.XmlWriter;import com.google.gdata.util.common.xml.XmlWriter.Attribute;import com.google.gdata.util.common.xml.XmlWriter.Namespace;import com.google.gdata.util.Namespaces;import com.google.gdata.util.ParseException;import com.google.gdata.util.ServiceConfigurationException;import com.google.gdata.util.XmlParser;/** * Specifies a complete extension profile for an extended GData schema. * A profile is a set of allowed extensions for each type together with * additional properties. * <p> * For example, Calendar might allow {@code <gd:who>} within {@code * <atom:feed>}, and {@code <gd:when>}, {@code <gd:who>}, and {@code * <gd:where>} within {@code <atom:entry>}. * * * */public class ExtensionProfile { /** Set of previously declared Kind.Adaptor classes. */ private HashSet<Class<Kind.Adaptor>> declared = new HashSet<Class<Kind.Adaptor>>(); /** * Adds the extension declarations associated with an {@link KindAdaptor} * instance, if the declaring class has not already added to this * profile. The method is optimized to reduce the overhead of declaring * the same adaptor type multiple times within the same profile. */ public void addDeclarations(Kind.Adaptor adaptor) { Class adaptorClass = adaptor.getClass(); if (!declared.contains(adaptorClass)) { adaptor.declareExtensions(this); declared.add(adaptorClass); } } /** * Specifies that type {@code extendedType} can contain an extension * described by {@code extDescription}. */ public synchronized void declare(Class<? extends ExtensionPoint> extendedType, ExtensionDescription extDescription) { ExtensionPoint.Manifest manifest = getOrCreateManifest(extendedType); Pair<String, String> extensionQName = new Pair(extDescription.getNamespace().getUri(), extDescription.getLocalName()); manifest.supportedExtensions.put(extensionQName, extDescription); profile.put(extendedType, manifest); nsDecls = null; } /** * Declares that {@code extDesc} defines a feed extension. */ public synchronized void declareFeedExtension(ExtensionDescription extDesc) { declare(BaseFeed.class, extDesc); } /** * Declares that {@code extClass} defines an entry extension. */ public synchronized void declareFeedExtension( Class<? extends Extension> extClass) { declare(BaseFeed.class, ExtensionDescription.getDefaultDescription(extClass)); } /** * Declares that {@code extDesc} defines an entry extension. */ public synchronized void declareEntryExtension(ExtensionDescription extDesc) { declare(BaseEntry.class, extDesc); } /** * Declares that {@code extClass} defines an entry extension. */ public synchronized void declareEntryExtension( Class<? extends Extension> extClass) { declare(BaseEntry.class, ExtensionDescription.getDefaultDescription(extClass)); } /** Specifies that type {@code extendedType} can contain arbitrary XML. */ public synchronized void declareArbitraryXmlExtension( Class extendedType) { ExtensionPoint.Manifest manifest = getOrCreateManifest(extendedType); manifest.arbitraryXml = true; profile.put(extendedType, manifest); nsDecls = null; } /** Specifies additional top-level namespace declarations. */ public synchronized void declareAdditionalNamespace(XmlWriter.Namespace ns) { additionalNamespaces.add(ns); } /** Specifies the type of feeds nested within {@code <gd:feedLink>}. */ public synchronized void declareFeedLinkProfile(ExtensionProfile extProfile) { feedLinkProfile = extProfile; nsDecls = null; } /** Retrieves the type of feeds nested within {@code <gd:feedLink>}. */ public synchronized ExtensionProfile getFeedLinkProfile() { return feedLinkProfile; } /** Specifies the type of entries nested within {@code <gd:entryLink>}. */ public synchronized void declareEntryLinkProfile(ExtensionProfile extProfile) { entryLinkProfile = extProfile; nsDecls = null; } /** Retrieves the type of entries nested within {@code <gd:entryLink>}. */ public synchronized ExtensionProfile getEntryLinkProfile() { return entryLinkProfile; } /** * Retrieves an extension manifest for a specific class (or one of * its superclasses) or {@code null} if not specified. */ public ExtensionPoint.Manifest getManifest(Class extendedType) { ExtensionPoint.Manifest manifest = null; while (extendedType != null) { manifest = profile.get(extendedType); if (manifest != null) return manifest; extendedType = extendedType.getSuperclass(); } return null; } /** Retrieves a collection of all namespaces used by this profile. */ public synchronized Collection<XmlWriter.Namespace> getNamespaceDecls() { if (nsDecls == null) { nsDecls = computeNamespaceDecls(); } return nsDecls; } /** Internal storage for the profile. */ private final Map<Class, ExtensionPoint.Manifest> profile = new HashMap<Class, ExtensionPoint.Manifest>(); /** Additional namespaces. */ private Collection<XmlWriter.Namespace> additionalNamespaces = new ArrayList<XmlWriter.Namespace>(); /** Nested feed link profile. */ private ExtensionProfile feedLinkProfile; /** Nested entry link profile. */ private ExtensionProfile entryLinkProfile; /** Namespace declarations cache. */ private Collection<XmlWriter.Namespace> nsDecls = null; /** Profile supports auto-extension declaration */ private boolean isAutoExtending = false; public void setAutoExtending(boolean v) { isAutoExtending = v; } public boolean isAutoExtending() { return isAutoExtending; } /** Internal helper routine. */ private ExtensionPoint.Manifest getOrCreateManifest(Class extendedType) { ExtensionPoint.Manifest manifest = getManifest(extendedType); if (manifest != null) { return manifest; } else { return new ExtensionPoint.Manifest(); } } private synchronized Collection<XmlWriter.Namespace> computeNamespaceDecls() { HashSet<XmlWriter.Namespace> result = new HashSet<XmlWriter.Namespace>(); result.addAll(additionalNamespaces); for (ExtensionPoint.Manifest manifest: profile.values()) { result.addAll(manifest.getNamespaceDecls()); } if (feedLinkProfile != null) { result.addAll(feedLinkProfile.computeNamespaceDecls()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -