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

📄 complextype.java

📁 这是个爬虫和lucece相结合最好了
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (this instanceof ModuleType) {                data = settings.addComplexType(this);            }        }        return data;    }    /* (non-Javadoc)     * @see javax.management.DynamicMBean#getAttributes(java.lang.String[])     */    public AttributeList getAttributes(String[] name) {        return null;    }    /* (non-Javadoc)     * @see javax.management.DynamicMBean#setAttributes(javax.management.AttributeList)     */    public AttributeList setAttributes(AttributeList attributes) {        return null;    }    /* (non-Javadoc)     * @see javax.management.DynamicMBean#invoke(java.lang.String, java.lang.Object[], java.lang.String[])     */    public Object invoke(String arg0, Object[] arg1, String[] arg2)        throws MBeanException, ReflectionException {        throw new ReflectionException(            new NoSuchMethodException("No methods to invoke."));    }    /* (non-Javadoc)     * @see javax.management.DynamicMBean#getMBeanInfo()     */    public MBeanInfo getMBeanInfo() {        return getMBeanInfo(globalSettings());    }    public MBeanInfo getMBeanInfo(Object context) {        MBeanAttributeInfoIterator it = getAttributeInfoIterator(context);        MBeanAttributeInfo[] attributes = new MBeanAttributeInfo[it.size()];        int index = 0;        while(it.hasNext()) {            attributes[index++] = (MBeanAttributeInfo) it.next();        }        MBeanInfo info =            new MBeanInfo(getClass().getName(), getDescription(), attributes,                null, null, null);        return info;    }    /** Get the effective Attribute info for an element of this type from     * a settings object.     *     * @param settings the settings object for which the Attribute info is     *        effective.     * @param name the name of the element to get the attribute for.     * @return the attribute info     */    public MBeanAttributeInfo getAttributeInfo(CrawlerSettings settings,            String name) {        MBeanAttributeInfo info = null;        Context context = new Context(settings, null);        DataContainer data = getDataContainerRecursive(context);        while (data != null && info == null) {            info = data.getAttributeInfo(name);            if (info == null) {                context.settings = data.getSettings().getParent();                data = getDataContainerRecursive(context);            }        }        return info;    }    /** Get the Attribute info for an element of this type from the global     * settings.     *     * @param name the name of the element to get the attribute for.     * @return the attribute info     */    public MBeanAttributeInfo getAttributeInfo(String name) {        return getAttributeInfo(globalSettings(), name);    }    /** Get the description of this type     *     * The description should be suitable for showing in a user interface.     *     * @return this type's description     */    public String getDescription() {        return description;    }    /** Get the parent of this ComplexType.     *     * @return the parent of this ComplexType.     */    public ComplexType getParent() {        return parent;    }    /** Set the description of this ComplexType     *     * The description should be suitable for showing in a user interface.     *     * @param string the description to set for this type.     */    public void setDescription(String string) {        description = string;    }    /* (non-Javadoc)     * @see org.archive.crawler.settings.Type#getDefaultValue()     */    public Object getDefaultValue() {        return this;    }    /** Add a new attribute to the definition of this ComplexType.     *     * This method can only be called before the ComplexType has been     * initialized. This usally means that this method is available for     * constructors of subclasses of this class.     *     * @param type the type to add.     * @return the newly added type.     */    public Type addElementToDefinition(Type type) {        if (isInitialized()) {            throw new IllegalStateException(                    "Elements should only be added to definition in the " +                    "constructor.");        }        if (definitionMap.containsKey(type.getName())) {            definition.remove(definitionMap.remove(type.getName()));        }                    definition.add(type);        definitionMap.put(type.getName(), type);        return type;    }    /** Get an element definition from this complex type.     *     * This method can only be called before the ComplexType has been     * initialized. This usally means that this method is available for     * constructors of subclasses of this class.     *     * @param name name of element to get.     * @return the requested element or null if non existent.     */    public Type getElementFromDefinition(String name) {        if (isInitialized()) {            throw new IllegalStateException(                    "Elements definition can only be accessed in the " +                    "constructor.");        }        return (Type) definitionMap.get(name);    }        /**     * This method can only be called before the ComplexType has been     * initialized. This usually means that this method is available for     * constructors of subclasses of this class.     * @param name Name of element to remove.     * @return Element removed.     */    protected Type removeElementFromDefinition(final String name) {        if (isInitialized()) {            throw new IllegalStateException(                "Elements definition can only be removed in constructor.");        }        Object removedObj = this.definitionMap.remove(name);        if (removedObj != null) {            this.definition.remove(removedObj);        }        return (Type)removedObj;    }     /** This method can be overridden in subclasses to do local     * initialisation.     *     * This method is run before the class has been updated with     * information from settings files. That implies that if you     * call getAttribute inside this method you will only get the     * default values.     *     * @param settings the CrawlerSettings object for which this     *        complex type is defined.     */    public void earlyInitialize(CrawlerSettings settings) {    }    /** Returns true if this ComplexType is initialized.     *     * @return true if this ComplexType is initialized.     */    public boolean isInitialized() {        return initialized;    }    public Object[] getLegalValues() {        return null;    }    /** Returns this object.     *     * This method is implemented to be able to treat the ComplexType as an     * subclass of {@link javax.management.Attribute}.     *     * @return this object.     * @see javax.management.Attribute#getValue()     */    public Object getValue() {        return this;    }    class Context {        CrawlerSettings settings;        UURI uri;        Context() {            settings = null;            uri = null;        }        Context(CrawlerSettings settings, UURI uri) {            this.settings = settings;            this.uri = uri;        }    }    /** Get an Iterator over all the attributes in this ComplexType.    *    * @param context the context for which this set of attributes are valid.    * @return an iterator over all the attributes in this map.    */   public Iterator iterator(Object context) {       return new AttributeIterator(context);   }   /** Get an Iterator over all the MBeanAttributeInfo in this ComplexType.   *   * @param context the context for which this set of MBeanAttributeInfo are valid.   * @return an iterator over all the MBeanAttributeInfo in this map.   */   public MBeanAttributeInfoIterator getAttributeInfoIterator(Object context) {       return new MBeanAttributeInfoIterator(context);   }   /**    * Iterator over all attributes in a ComplexType.    *    * @author John Erik Halse    */   private class AttributeIterator implements Iterator {       private Context context;       private Stack<Iterator<MBeanAttributeInfo>> attributeStack        = new Stack<Iterator<MBeanAttributeInfo>>();       private Iterator currentIterator;       public AttributeIterator(Object ctxt) {           this.context = getSettingsFromObject(ctxt);           Context c = new Context(context.settings, context.uri);           DataContainer data = getDataContainerRecursive(c);           while (data != null) {               this.attributeStack.push(data.getLocalAttributeInfoList().                   iterator());               c.settings = data.getSettings().getParent();               data = getDataContainerRecursive(c);           }           this.currentIterator = (Iterator) this.attributeStack.pop();       }       public boolean hasNext() {           if (this.currentIterator.hasNext()) {               return true;           }           if (this.attributeStack.isEmpty()) {               return false;           }           this.currentIterator = (Iterator) this.attributeStack.pop();           return this.currentIterator.hasNext();       }       public Object next() {           hasNext();           try {               MBeanAttributeInfo attInfo = (MBeanAttributeInfo) this.currentIterator.next();               Object attr = getAttribute(this.context, attInfo.getName());               if (!(attr instanceof Attribute)) {                   attr = new Attribute(attInfo.getName(), attr);               }               return attr;           } catch (AttributeNotFoundException e) {               // This should never happen               e.printStackTrace();               return null;           }       }       public void remove() {           throw new UnsupportedOperationException();       }   }   /**    * Iterator over all MBeanAttributeInfo for this ComplexType    *    * @author John Erik Halse    */   public class MBeanAttributeInfoIterator implements Iterator {       private Context context;       private Stack<Iterator<MBeanAttributeInfo>> attributeStack        = new Stack<Iterator<MBeanAttributeInfo>>();       private Iterator currentIterator;       private int attributeCount = 0;       public MBeanAttributeInfoIterator(Object ctxt) {           this.context = getSettingsFromObject(ctxt);           //Stack attributeStack = new Stack();           //           DataContainer data = getDataContainerRecursive(context);           while (data != null) {               attributeStack.push(data.getLocalAttributeInfoList().iterator());               attributeCount += data.getLocalAttributeInfoList().size();               context.settings = data.getSettings().getParent();               data = getDataContainerRecursive(context);           }           this.currentIterator = (Iterator) this.attributeStack.pop();       }       public boolean hasNext() {            if (this.currentIterator.hasNext()) {                return true;            }            if (this.attributeStack.isEmpty()) {                return false;            }            this.currentIterator = (Iterator)this.attributeStack.pop();            return this.currentIterator.hasNext();        }       public Object next() {           hasNext();           MBeanAttributeInfo attInfo = (MBeanAttributeInfo) this.currentIterator.next();           return attInfo;       }       public void remove() {           throw new UnsupportedOperationException();       }       public int size() {           return attributeCount;       }   }      @Override   public String toString() {       // In 1.6, toString goes into infinite loop.  Default implementation is       // return getName() + '=' + getValue() but this class returns itself       // for a value on which we do a toString... and around we go.  Short       // circuit it here.       return getName() + ": " +           getClass().getName() + "@" + Integer.toHexString(hashCode());   }}

⌨️ 快捷键说明

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