KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > xs > impl > XSKeyRefImpl


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */

17 package org.apache.ws.jaxme.xs.impl;
18
19 import org.apache.ws.jaxme.xs.XPathMatcher;
20 import org.apache.ws.jaxme.xs.XSAnnotation;
21 import org.apache.ws.jaxme.xs.XSElement;
22 import org.apache.ws.jaxme.xs.XSElementOrAttrRef;
23 import org.apache.ws.jaxme.xs.XSIdentityConstraint;
24 import org.apache.ws.jaxme.xs.XSKeyRef;
25 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
26 import org.apache.ws.jaxme.xs.xml.XsEKeyref;
27 import org.xml.sax.SAXException JavaDoc;
28
29 /**
30  * Default implementation of the XSKeyRef.
31  *
32  * @author <a HREF="mailto:mrck1996@yahoo.co.uk">Chris Kirk</a>
33  */

34 public class XSKeyRefImpl extends XSOpenAttrsImpl
35   implements XSKeyRef
36 {
37   private XSAnnotation[] annotations;
38   private String JavaDoc name;
39   private XSIdentityConstraint identityConstraint;
40   private XsEKeyref keyRef;
41   private XSElementOrAttrRef[][] matchCriteria;
42
43   protected XSKeyRefImpl( XSElement pParent, XsEKeyref keyRef )
44     throws SAXException
45   {
46     super( pParent, keyRef );
47
48     this.annotations = getXSSchema().getXSObjectFactory().newXSAnnotations(
49       this,
50       keyRef.getAnnotation()
51     );
52
53     this.name = keyRef.getName().getValue();
54     this.keyRef = keyRef;
55   }
56
57   public XSAnnotation[] getAnnotations() {
58     return annotations;
59   }
60
61   /**
62    * @see XSKeyRef#getName
63    */

64   public String JavaDoc getName() {
65     return name;
66   }
67
68   /**
69    * @see XSKeyRef#getIdentityConstraint
70    */

71   public XSIdentityConstraint getIdentityConstraint() {
72     return identityConstraint;
73   }
74
75   /**
76    * @see XSKeyRef#getMatchCriteria
77    */

78   public XSElementOrAttrRef[][] getMatchCriteria() {
79     return matchCriteria;
80   }
81
82   public void validate() throws SAXException {
83     validateAllIn( annotations );
84
85     String JavaDoc referredIdentity = keyRef.getRefer().getLocalName();
86     identityConstraint = (XSIdentityConstraint) getXSSchema().getIdentityConstraints().get(
87       referredIdentity
88     );
89
90     if ( identityConstraint == null ) {
91       throw new LocSAXException(
92         "Unknown identity constraint: " + referredIdentity,
93         keyRef.getLocator()
94       );
95     }
96
97     matchCriteria = XPathMatcher.match(
98       keyRef,
99       (XSElement) getParentObject()
100     );
101   }
102 }
103
Popular Tags