001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.xml.xpath.ext.metadata;
021:
022: import java.util.Collections;
023: import java.util.List;
024:
025: /**
026: * Describes an argument (parameter) of a method or operation.
027: *
028: * @author nk160297
029: */
030: public final class ArgumentDescriptor implements AbstractArgument {
031:
032: private XPathType mType;
033: private int mMinOccurs;
034: private int mMaxOccurs;
035: private String mDescription;
036: private List<XPathType> mCanBeAssignedFrom;
037:
038: public static final List<XPathType> NOT_ASSIGNABLE = Collections
039: .emptyList();
040:
041: public static final List<XPathType> NODE_SET_ASSIGNABLE = Collections
042: .singletonList(XPathType.NODE_SET_TYPE);
043:
044: public ArgumentDescriptor(XPathType type, boolean isMandatory,
045: boolean isRepeated, List<XPathType> canBeAssignedFrom) {
046: mType = type;
047: mMinOccurs = isMandatory ? 1 : 0;
048: mMaxOccurs = isRepeated ? Integer.MAX_VALUE : 1;
049: mCanBeAssignedFrom = canBeAssignedFrom;
050: }
051:
052: public ArgumentDescriptor(XPathType type, int minCount,
053: int maxCount, String description,
054: List<XPathType> canBeAssignedFrom) {
055: mType = type;
056: mMinOccurs = minCount;
057: mMaxOccurs = maxCount;
058: mDescription = description;
059: mCanBeAssignedFrom = canBeAssignedFrom;
060: }
061:
062: public XPathType getArgumentType() {
063: return mType;
064: }
065:
066: public String getDescription() {
067: return mDescription;
068: }
069:
070: public boolean isMandatory() {
071: return mMinOccurs > 0;
072: }
073:
074: public boolean isRepeated() {
075: return mMaxOccurs > 1;
076: }
077:
078: public int getMinOccurs() {
079: return mMinOccurs;
080: }
081:
082: public int getMaxOccurs() {
083: return mMaxOccurs;
084: }
085:
086: /**
087: * Null value means any type.
088: */
089: public List<XPathType> canBeAssignedFromTypes() {
090: return mCanBeAssignedFrom;
091: }
092:
093: //==========================================================================
094:
095: /**
096: * Predefined instances of argument descriptor.
097: * They are immutable so can be used like constants.
098: */
099: public interface Predefined {
100: List<XPathType> NOT_ASSIGNABLE = Collections.emptyList();
101:
102: List<XPathType> NODE_SET_ASSIGNABLE = Collections
103: .singletonList(XPathType.NODE_SET_TYPE);
104:
105: //---------------------------------------------------------
106:
107: ArgumentDescriptor ANY_TYPE = new ArgumentDescriptor(
108: XPathType.ANY_TYPE, true, false, null);
109:
110: ArgumentDescriptor OPTIONAL_ANY_TYPE = new ArgumentDescriptor(
111: XPathType.ANY_TYPE, false, false, null);
112:
113: ArgumentDescriptor SIMPLE_BOOLEAN = new ArgumentDescriptor(
114: XPathType.BOOLEAN_TYPE, true, false, null);
115:
116: ArgumentDescriptor SIMPLE_STRING = new ArgumentDescriptor(
117: XPathType.STRING_TYPE, true, false, null);
118:
119: ArgumentDescriptor OPTIONAL_STRING = new ArgumentDescriptor(
120: XPathType.STRING_TYPE, false, false, null);
121:
122: ArgumentDescriptor REPEATED_STRING_2MIN = new ArgumentDescriptor(
123: XPathType.STRING_TYPE, 2, Integer.MAX_VALUE, null, null);
124:
125: ArgumentDescriptor SIMPLE_NUMBER = new ArgumentDescriptor(
126: XPathType.NUMBER_TYPE, true, false, null);
127:
128: ArgumentDescriptor OPTIONAL_NUMBER = new ArgumentDescriptor(
129: XPathType.NUMBER_TYPE, false, false, null);
130:
131: ArgumentDescriptor REPEATED_NUMBER_2MIN = new ArgumentDescriptor(
132: XPathType.NUMBER_TYPE, 2, Integer.MAX_VALUE, null, null);
133:
134: ArgumentDescriptor SIMPLE_NODE = new ArgumentDescriptor(
135: XPathType.NODE_TYPE, true, false, NODE_SET_ASSIGNABLE);
136:
137: ArgumentDescriptor OPTIONAL_NODE = new ArgumentDescriptor(
138: XPathType.NODE_TYPE, false, false, NODE_SET_ASSIGNABLE);
139:
140: ArgumentDescriptor SIMPLE_NODE_SET = new ArgumentDescriptor(
141: XPathType.NODE_SET_TYPE, true, false, NOT_ASSIGNABLE);
142:
143: ArgumentDescriptor REPEATED_NODE_SET_2MIN = new ArgumentDescriptor(
144: XPathType.NODE_SET_TYPE, 2, Integer.MAX_VALUE, null,
145: NOT_ASSIGNABLE);
146: }
147:
148: }
|