KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > forrest > sourcetype > XmlSchemaRule


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

17 package org.apache.forrest.sourcetype;
18
19 import org.apache.avalon.framework.configuration.Configuration;
20 import org.apache.avalon.framework.configuration.ConfigurationException;
21
22 /**
23  * A Rule which checks the value of the xsi:schemaLocation and xsi:noNamespaceSchemaLocation
24  * attributes.
25  */

26 public class XmlSchemaRule implements SourceTypeRule
27 {
28     protected String JavaDoc schemaLocation;
29     protected String JavaDoc noNamespaceSchemaLocation;
30
31     public void configure(Configuration configuration) throws ConfigurationException
32     {
33         schemaLocation = configuration.getAttribute("schema-location", null);
34         noNamespaceSchemaLocation = configuration.getAttribute("no-namespace-schema-location", null);
35         if (schemaLocation == null && noNamespaceSchemaLocation == null)
36             throw new ConfigurationException("Missing schema-location and/or no-namespace-schema-location attribute on w3c-xml-schema element at " + configuration.getLocation());
37     }
38
39     public boolean matches(SourceInfo sourceInfo)
40     {
41         if (schemaLocation != null && noNamespaceSchemaLocation != null
42                 && schemaLocation.equals(sourceInfo.getXsiSchemaLocation())
43                 && noNamespaceSchemaLocation.equals(sourceInfo.getXsiNoNamespaceSchemaLocation()))
44             return true;
45         else if (schemaLocation != null && noNamespaceSchemaLocation == null && schemaLocation.equals(sourceInfo.getXsiSchemaLocation()))
46             return true;
47         else if (schemaLocation == null && noNamespaceSchemaLocation != null && noNamespaceSchemaLocation.equals(sourceInfo.getXsiNoNamespaceSchemaLocation()))
48             return true;
49         else
50             return false;
51     }
52
53 }
54
Popular Tags