IIOMetadataFormatImpl.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /* IIOMetadataFormatImpl.java --
  2. Copyright (C) 2004 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.imageio.metadata;
  32. import org.w3c.dom.Attr;
  33. import org.w3c.dom.Element;
  34. import org.w3c.dom.NamedNodeMap;
  35. import org.w3c.dom.NodeList;
  36. import org.w3c.dom.TypeInfo;
  37. import java.util.ArrayList;
  38. import java.util.HashMap;
  39. import java.util.Map;
  40. import java.util.List;
  41. import java.util.Locale;
  42. import java.util.ResourceBundle;
  43. import java.util.MissingResourceException;
  44. import javax.imageio.ImageTypeSpecifier;
  45. public abstract class IIOMetadataFormatImpl implements IIOMetadataFormat
  46. {
  47. /**
  48. * The standard metadata format name constant set to
  49. * "javax_imageio_1.0".
  50. */
  51. public static final String standardMetadataFormatName = "javax_imageio_1.0";
  52. private String rootName;
  53. // These maps assume that each element name is unique.
  54. private Map nodes = new HashMap();
  55. // A mapping from element name to child policy.
  56. private Map childPolicies = new HashMap();
  57. // A mapping from element name to the permissible number of
  58. // children. Values in this map are length-two integer arrays; the
  59. // first index is the minimum bound, the second index is the maximum
  60. // bound.
  61. private Map childRanges = new HashMap();
  62. private String resourceBaseName;
  63. // Package-private so that it may be used in IIOMetadataNode.
  64. static class IIOMetadataNodeAttr extends IIOMetadataNode
  65. implements Attr
  66. {
  67. protected Element owner;
  68. protected String name;
  69. protected int dataType;
  70. protected boolean required;
  71. protected String defaultValue;
  72. public IIOMetadataNodeAttr (Element owner,
  73. String name,
  74. String defaultValue)
  75. {
  76. this (owner, name, IIOMetadataFormat.DATATYPE_STRING,
  77. true, defaultValue);
  78. }
  79. public IIOMetadataNodeAttr (Element owner,
  80. String name,
  81. int dataType,
  82. boolean required,
  83. String defaultValue)
  84. {
  85. this.owner = owner;
  86. this.name = name;
  87. this.dataType = dataType;
  88. this.required = required;
  89. this.defaultValue = defaultValue;
  90. }
  91. public String getName ()
  92. {
  93. return name;
  94. }
  95. public Element getOwnerElement ()
  96. {
  97. return owner;
  98. }
  99. public int getDataType ()
  100. {
  101. return dataType;
  102. }
  103. public TypeInfo getSchemaTypeInfo ()
  104. {
  105. return null;
  106. }
  107. public boolean getSpecified ()
  108. {
  109. return false;
  110. }
  111. public String getValue ()
  112. {
  113. return defaultValue;
  114. }
  115. public boolean isId()
  116. {
  117. return false;
  118. }
  119. public void setValue (String value)
  120. {
  121. }
  122. // new methods
  123. public boolean isRequired ()
  124. {
  125. return required;
  126. }
  127. }
  128. private class IIOMetadataNodeAttrEnumerated extends IIOMetadataNodeAttr
  129. {
  130. protected List enumeratedValues;
  131. public IIOMetadataNodeAttrEnumerated (Element owner,
  132. String name,
  133. int dataType,
  134. boolean required,
  135. String defaultValue,
  136. List enumeratedValues)
  137. {
  138. super (owner, name, dataType, required, defaultValue);
  139. this.enumeratedValues = new ArrayList (enumeratedValues);
  140. }
  141. public Object[] getEnumerations ()
  142. {
  143. return enumeratedValues.toArray ();
  144. }
  145. }
  146. private class IIOMetadataNodeAttrBounded extends IIOMetadataNodeAttr
  147. {
  148. protected String minValue;
  149. protected String maxValue;
  150. protected boolean minInclusive;
  151. protected boolean maxInclusive;
  152. public IIOMetadataNodeAttrBounded (Element owner,
  153. String name,
  154. int dataType,
  155. boolean required,
  156. String defaultValue,
  157. String minValue,
  158. String maxValue,
  159. boolean minInclusive,
  160. boolean maxInclusive)
  161. {
  162. super (owner, name, dataType, required, defaultValue);
  163. this.minValue = minValue;
  164. this.maxValue = maxValue;
  165. this.minInclusive = minInclusive;
  166. this.maxInclusive = maxInclusive;
  167. }
  168. public String getMinValue ()
  169. {
  170. return minValue;
  171. }
  172. public String getMaxValue ()
  173. {
  174. return maxValue;
  175. }
  176. }
  177. private class IIOMetadataNodeAttrList extends IIOMetadataNodeAttr
  178. {
  179. protected int listMinLength;
  180. protected int listMaxLength;
  181. public IIOMetadataNodeAttrList (Element owner,
  182. String name,
  183. int dataType,
  184. boolean required,
  185. int listMinLength,
  186. int listMaxLength)
  187. {
  188. super (owner, name, dataType, required, null);
  189. this.listMinLength = listMinLength;
  190. this.listMaxLength = listMaxLength;
  191. }
  192. public int getListMinLength ()
  193. {
  194. return listMinLength;
  195. }
  196. public int getListMaxLength ()
  197. {
  198. return listMaxLength;
  199. }
  200. }
  201. private class NodeObject
  202. {
  203. protected Element owner;
  204. protected Class classType;
  205. protected boolean required;
  206. protected Object defaultValue;
  207. protected int valueType;
  208. public NodeObject (Element owner,
  209. Class classType,
  210. boolean required,
  211. Object defaultValue)
  212. {
  213. this.owner = owner;
  214. this.classType = classType;
  215. this.required = required;
  216. this.defaultValue = defaultValue;
  217. valueType = IIOMetadataFormat.VALUE_ARBITRARY;
  218. }
  219. public int getValueType ()
  220. {
  221. return valueType;
  222. }
  223. public Class getClassType ()
  224. {
  225. return classType;
  226. }
  227. public Element getOwnerElement ()
  228. {
  229. return owner;
  230. }
  231. public Object getDefaultValue ()
  232. {
  233. return defaultValue;
  234. }
  235. public boolean isRequired ()
  236. {
  237. return required;
  238. }
  239. }
  240. private class NodeObjectEnumerated extends NodeObject
  241. {
  242. protected List enumeratedValues;
  243. public NodeObjectEnumerated (Element owner,
  244. Class classType,
  245. boolean required,
  246. Object defaultValue,
  247. List enumeratedValues)
  248. {
  249. super (owner, classType, false, defaultValue);
  250. this.enumeratedValues = enumeratedValues;
  251. valueType = IIOMetadataFormat.VALUE_ENUMERATION;
  252. }
  253. public Object[] getEnumerations ()
  254. {
  255. return enumeratedValues.toArray();
  256. }
  257. }
  258. private class NodeObjectBounded extends NodeObject
  259. {
  260. protected Comparable minValue;
  261. protected Comparable maxValue;
  262. protected boolean minInclusive;
  263. protected boolean maxInclusive;
  264. public NodeObjectBounded (Element owner,
  265. Class classType,
  266. Object defaultValue,
  267. Comparable minValue,
  268. Comparable maxValue,
  269. boolean minInclusive,
  270. boolean maxInclusive)
  271. {
  272. super (owner, classType, false, defaultValue);
  273. this.minValue = minValue;
  274. this.maxValue = maxValue;
  275. this.minInclusive = minInclusive;
  276. this.maxInclusive = maxInclusive;
  277. if (minInclusive)
  278. {
  279. if (maxInclusive)
  280. valueType = IIOMetadataFormat.VALUE_RANGE_MIN_MAX_INCLUSIVE;
  281. else
  282. valueType = IIOMetadataFormat.VALUE_RANGE_MIN_INCLUSIVE;
  283. }
  284. else
  285. {
  286. if (maxInclusive)
  287. valueType = IIOMetadataFormat.VALUE_RANGE_MAX_INCLUSIVE;
  288. else
  289. valueType = IIOMetadataFormat.VALUE_RANGE;
  290. }
  291. }
  292. public Comparable getMinValue ()
  293. {
  294. return minValue;
  295. }
  296. public Comparable getMaxValue ()
  297. {
  298. return maxValue;
  299. }
  300. }
  301. private class NodeObjectArray extends NodeObject
  302. {
  303. protected Integer arrayMinLength;
  304. protected Integer arrayMaxLength;
  305. public NodeObjectArray (Element owner,
  306. Class classType,
  307. int arrayMinLength,
  308. int arrayMaxLength)
  309. {
  310. super (owner, classType, false, null);
  311. this.arrayMinLength = new Integer (arrayMinLength);
  312. this.arrayMaxLength = new Integer (arrayMaxLength);
  313. valueType = IIOMetadataFormat.VALUE_LIST;
  314. }
  315. public Comparable getArrayMinLength ()
  316. {
  317. return arrayMinLength;
  318. }
  319. public Comparable getArrayMaxLength ()
  320. {
  321. return arrayMaxLength;
  322. }
  323. }
  324. /**
  325. * Construct a blank IIOMetadataFormatImpl with the given root name
  326. * and child policy.
  327. *
  328. * @param rootName the root element name
  329. * @param childPolicy the child policy of the root element
  330. *
  331. * @exception IllegalArgumentException if rootName is null
  332. * @exception IllegalArgumentException if childPolicy is
  333. * CHILD_POLICY_REPEAT or if childPolicy is not a CHILD_POLICY
  334. * constant
  335. */
  336. public IIOMetadataFormatImpl (String rootName, int childPolicy)
  337. {
  338. if (rootName == null)
  339. throw new IllegalArgumentException ("null argument");
  340. if (childPolicy < IIOMetadataFormat.CHILD_POLICY_ALL
  341. || childPolicy > IIOMetadataFormat.CHILD_POLICY_SOME
  342. || childPolicy == IIOMetadataFormat.CHILD_POLICY_REPEAT)
  343. throw new IllegalArgumentException ("wrong child policy");
  344. nodes.put (rootName, new IIOMetadataNode (rootName));
  345. childPolicies.put (rootName, new Integer (childPolicy));
  346. this.rootName = rootName;
  347. }
  348. /**
  349. * Construct a blank IIOMetadataFormatImpl with the given root name,
  350. * a child policy of CHILD_POLICY_REPEAT and the given minimum and
  351. * maximum limits on the number of root element children.
  352. *
  353. * @param rootName the root element name
  354. * @param minChildren the minimum number of children that this node
  355. * can have
  356. * @param maxChildren the maximum number of children that this node
  357. * can have
  358. *
  359. * @exception IllegalArgumentException if rootName is null
  360. * @exception IllegalArgumentException if minChildren is less than
  361. * zero or greater than maxChildren
  362. */
  363. public IIOMetadataFormatImpl (String rootName,
  364. int minChildren,
  365. int maxChildren)
  366. {
  367. if (rootName == null)
  368. throw new IllegalArgumentException ("null argument");
  369. if (minChildren < 0 || maxChildren < minChildren)
  370. throw new IllegalArgumentException ("invalid min or max children argument");
  371. nodes.put (rootName, new IIOMetadataNode (rootName));
  372. childPolicies.put (rootName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
  373. childRanges.put (rootName, new int [] { minChildren, maxChildren });
  374. this.rootName = rootName;
  375. }
  376. protected void addAttribute (String elementName,
  377. String attrName,
  378. int dataType,
  379. boolean required,
  380. String defaultValue)
  381. {
  382. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  383. node.setAttributeNode (new IIOMetadataNodeAttr (node,
  384. attrName,
  385. dataType,
  386. required,
  387. defaultValue));
  388. }
  389. protected void addAttribute (String elementName,
  390. String attrName,
  391. int dataType,
  392. boolean required,
  393. String defaultValue,
  394. List<String> enumeratedValues)
  395. {
  396. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  397. node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
  398. attrName,
  399. dataType,
  400. required,
  401. defaultValue,
  402. enumeratedValues));
  403. }
  404. protected void addAttribute (String elementName,
  405. String attrName,
  406. int dataType,
  407. boolean required,
  408. String defaultValue,
  409. String minValue,
  410. String maxValue,
  411. boolean minInclusive,
  412. boolean maxInclusive)
  413. {
  414. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  415. node.setAttributeNode (new IIOMetadataNodeAttrBounded (node,
  416. attrName,
  417. dataType,
  418. required,
  419. defaultValue,
  420. minValue,
  421. maxValue,
  422. minInclusive,
  423. maxInclusive));
  424. }
  425. protected void addAttribute (String elementName,
  426. String attrName,
  427. int dataType,
  428. boolean required,
  429. int listMinLength,
  430. int listMaxLength)
  431. {
  432. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  433. node.setAttributeNode (new IIOMetadataNodeAttrList (node,
  434. attrName,
  435. dataType,
  436. required,
  437. listMinLength,
  438. listMaxLength));
  439. }
  440. protected void addBooleanAttribute (String elementName,
  441. String attrName,
  442. boolean hasDefaultValue,
  443. boolean defaultValue)
  444. {
  445. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  446. List enumeratedValues = new ArrayList();
  447. enumeratedValues.add ("TRUE");
  448. enumeratedValues.add ("FALSE");
  449. node.setAttributeNode (new IIOMetadataNodeAttrEnumerated (node,
  450. attrName,
  451. IIOMetadataFormat.DATATYPE_BOOLEAN,
  452. hasDefaultValue,
  453. defaultValue ? "TRUE" : "FALSE",
  454. enumeratedValues));
  455. }
  456. protected void addChildElement (String elementName, String parentName)
  457. {
  458. IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);
  459. node.appendChild (new IIOMetadataNode (elementName));
  460. childPolicies.put (elementName, new Integer (IIOMetadataFormat.CHILD_POLICY_REPEAT));
  461. }
  462. protected void addElement (String elementName, String parentName, int childPolicy)
  463. {
  464. IIOMetadataNode node = (IIOMetadataNode) nodes.get (parentName);
  465. node.appendChild (new IIOMetadataNode (elementName));
  466. childPolicies.put (elementName, new Integer (childPolicy));
  467. }
  468. protected void addElement (String elementName, String parentName,
  469. int minChildren, int maxChildren)
  470. {
  471. addChildElement (elementName, parentName);
  472. childRanges.put (elementName, new int [] { minChildren, maxChildren });
  473. }
  474. private void addNodeObject (IIOMetadataNode node, NodeObject o)
  475. {
  476. node.setUserObject (o);
  477. }
  478. private NodeObject getNodeObject (IIOMetadataNode node)
  479. {
  480. return (NodeObject) node.getUserObject ();
  481. }
  482. private void removeNodeObject (IIOMetadataNode node)
  483. {
  484. node.setUserObject (null);
  485. }
  486. protected <T> void addObjectValue (String elementName, Class<T> classType,
  487. boolean required, T defaultValue)
  488. {
  489. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  490. addNodeObject (node, new NodeObject (node,
  491. classType,
  492. required,
  493. defaultValue));
  494. }
  495. protected <T> void addObjectValue (String elementName, Class<T> classType,
  496. boolean required, T defaultValue,
  497. List<? extends T> enumeratedValues)
  498. {
  499. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  500. addNodeObject (node, new NodeObjectEnumerated (node,
  501. classType,
  502. required,
  503. defaultValue,
  504. enumeratedValues));
  505. }
  506. protected <T extends Object & Comparable<? super T>>
  507. void addObjectValue (String elementName, Class<T> classType,
  508. T defaultValue,
  509. Comparable<? super T> minValue,
  510. Comparable<? super T> maxValue,
  511. boolean minInclusive,
  512. boolean maxInclusive)
  513. {
  514. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  515. addNodeObject (node, new NodeObjectBounded (node,
  516. classType,
  517. defaultValue,
  518. minValue,
  519. maxValue,
  520. minInclusive,
  521. maxInclusive));
  522. }
  523. protected void addObjectValue (String elementName, Class<?> classType,
  524. int arrayMinLength, int arrayMaxLength)
  525. {
  526. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  527. addNodeObject (node, new NodeObjectArray (node,
  528. classType,
  529. arrayMinLength,
  530. arrayMaxLength));
  531. }
  532. public String getRootName ()
  533. {
  534. return rootName;
  535. }
  536. protected String getResourceBaseName ()
  537. {
  538. return resourceBaseName;
  539. }
  540. public static IIOMetadataFormat getStandardFormatInstance ()
  541. {
  542. // FIXME: populate this with the standard metadata format
  543. return new IIOMetadataFormatImpl (standardMetadataFormatName,
  544. IIOMetadataFormat.CHILD_POLICY_ALL)
  545. {
  546. public boolean canNodeAppear (String elementName,
  547. ImageTypeSpecifier specifier)
  548. {
  549. return true;
  550. }
  551. };
  552. }
  553. public abstract boolean canNodeAppear (String elementName,
  554. ImageTypeSpecifier specifier);
  555. protected void removeAttribute (String elementName,
  556. String attrName)
  557. {
  558. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  559. node.removeAttribute (attrName);
  560. }
  561. protected void removeElement (String elementName)
  562. {
  563. nodes.remove (elementName);
  564. }
  565. protected void removeObjectValue (String elementName)
  566. {
  567. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  568. removeNodeObject (node);
  569. }
  570. protected void setResourceBaseName (String resourceBaseName)
  571. {
  572. this.resourceBaseName = resourceBaseName;
  573. }
  574. public int getAttributeDataType (String elementName, String attrName)
  575. {
  576. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  577. IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
  578. return attr.getDataType ();
  579. }
  580. public String getAttributeDefaultValue (String elementName, String attrName)
  581. {
  582. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  583. IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
  584. return attr.getValue();
  585. }
  586. public String getAttributeDescription (String elementName, String attrName, Locale locale)
  587. {
  588. return getDescription (elementName + "/" + attrName, locale);
  589. }
  590. public String[] getAttributeEnumerations (String elementName, String attrName)
  591. {
  592. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  593. IIOMetadataNodeAttrEnumerated attr =
  594. (IIOMetadataNodeAttrEnumerated) node.getAttributeNode (attrName);
  595. Object[] attrEnums = attr.getEnumerations();
  596. String[] attrNames = new String[attrEnums.length];
  597. for (int i = 0; i < attrEnums.length; i++)
  598. {
  599. attrNames[i] = (String) attrEnums[i];
  600. }
  601. return attrNames;
  602. }
  603. public int getAttributeListMaxLength (String elementName, String attrName)
  604. {
  605. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  606. IIOMetadataNodeAttrList attr =
  607. (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
  608. return attr.getListMaxLength();
  609. }
  610. public int getAttributeListMinLength (String elementName, String attrName)
  611. {
  612. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  613. IIOMetadataNodeAttrList attr =
  614. (IIOMetadataNodeAttrList) node.getAttributeNode (attrName);
  615. return attr.getListMinLength();
  616. }
  617. public String getAttributeMaxValue (String elementName, String attrName)
  618. {
  619. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  620. IIOMetadataNodeAttrBounded attr =
  621. (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
  622. return attr.getMaxValue();
  623. }
  624. public String getAttributeMinValue (String elementName, String attrName)
  625. {
  626. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  627. IIOMetadataNodeAttrBounded attr =
  628. (IIOMetadataNodeAttrBounded) node.getAttributeNode (attrName);
  629. return attr.getMinValue();
  630. }
  631. public String[] getAttributeNames (String elementName)
  632. {
  633. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  634. NamedNodeMap attrNodes = node.getAttributes();
  635. String[] attrNames = new String[attrNodes.getLength()];
  636. for (int i = 0; i < attrNodes.getLength(); i++)
  637. {
  638. attrNames[i] = attrNodes.item (i).getLocalName();
  639. }
  640. return attrNames;
  641. }
  642. public int getAttributeValueType (String elementName, String attrName)
  643. {
  644. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  645. IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) node.getAttributeNode (attrName);
  646. return attr.getDataType();
  647. }
  648. public String[] getChildNames (String elementName)
  649. {
  650. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  651. NodeList childNodes = node.getChildNodes();
  652. String[] childNames = new String[childNodes.getLength()];
  653. for (int i = 0; i < childNodes.getLength(); i++)
  654. {
  655. childNames[i] = childNodes.item (i).getLocalName();
  656. }
  657. return childNames;
  658. }
  659. public int getChildPolicy (String elementName)
  660. {
  661. return ((Integer) childPolicies.get (elementName)).intValue();
  662. }
  663. private String getDescription (String resourceName, Locale locale)
  664. {
  665. if (resourceBaseName == null)
  666. return null;
  667. Locale l = locale;
  668. if (l == null)
  669. l = Locale.getDefault();
  670. ResourceBundle bundle = ResourceBundle.getBundle (resourceBaseName, locale);
  671. String desc = null;
  672. if (bundle == null)
  673. {
  674. try
  675. {
  676. desc = bundle.getString (resourceName);
  677. }
  678. catch (MissingResourceException e)
  679. {
  680. desc = null;
  681. }
  682. }
  683. return desc;
  684. }
  685. public String getElementDescription (String elementName, Locale locale)
  686. {
  687. return getDescription (elementName, locale);
  688. }
  689. public int getElementMaxChildren (String elementName)
  690. {
  691. return ((int[]) childRanges.get (elementName))[1];
  692. }
  693. public int getElementMinChildren (String elementName)
  694. {
  695. return ((int[]) childRanges.get (elementName))[0];
  696. }
  697. public int getObjectArrayMaxLength (String elementName)
  698. {
  699. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  700. return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMaxLength ()).intValue();
  701. }
  702. public int getObjectArrayMinLength (String elementName)
  703. {
  704. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  705. return ((Integer) ((NodeObjectArray) getNodeObject (node)).getArrayMinLength ()).intValue();
  706. }
  707. public Class<?> getObjectClass (String elementName)
  708. {
  709. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  710. return getNodeObject (node).getClassType ();
  711. }
  712. public Object getObjectDefaultValue (String elementName)
  713. {
  714. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  715. return getNodeObject (node).getDefaultValue ();
  716. }
  717. public Object[] getObjectEnumerations (String elementName)
  718. {
  719. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  720. return ((NodeObjectEnumerated) getNodeObject (node)).getEnumerations ();
  721. }
  722. public Comparable<?> getObjectMaxValue (String elementName)
  723. {
  724. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  725. return ((NodeObjectBounded) getNodeObject (node)).getMaxValue ();
  726. }
  727. public Comparable<?> getObjectMinValue (String elementName)
  728. {
  729. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  730. return ((NodeObjectBounded) getNodeObject (node)).getMinValue ();
  731. }
  732. public int getObjectValueType (String elementName)
  733. {
  734. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  735. NodeObject n = getNodeObject (node);
  736. if (n == null)
  737. return IIOMetadataFormat.VALUE_NONE;
  738. else
  739. return n.getValueType ();
  740. }
  741. public boolean isAttributeRequired (String elementName, String attrName)
  742. {
  743. IIOMetadataNode node = (IIOMetadataNode) nodes.get (elementName);
  744. return ((IIOMetadataNodeAttr) node.getAttributeNode (attrName)).isRequired();
  745. }
  746. }