001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.axis2.dataretrieval;
021:
022: import org.apache.axiom.om.OMAttribute;
023: import org.apache.axiom.om.OMElement;
024:
025: import javax.xml.namespace.QName;
026:
027: /**
028: * This represents the service data for a dialect and identifier if specified.
029: * Basically, the Data element defined in the ServiceData.xml packaged in
030: * a Web Service's achieve file.
031: */
032:
033: public class ServiceData {
034: OMElement data;
035:
036: String identifier;
037:
038: String dialect;
039:
040: String fileName;
041:
042: /**
043: * Constructor
044: *
045: * @param in_data an Data element in the ServiceData.
046: */
047:
048: public ServiceData(OMElement in_data) {
049: data = in_data;
050: identifier = getAttributeValue(DRConstants.SERVICE_DATA.IDENTIFIER);
051: dialect = getAttributeValue(DRConstants.SERVICE_DATA.DIALECT);
052: fileName = getAttributeValue(DRConstants.SERVICE_DATA.FILE);
053: }
054:
055: public String getAttributeValue(String qName) {
056:
057: String value = null;
058: OMAttribute attribute = data.getAttribute(new QName(qName));
059: if (attribute != null) {
060: value = attribute.getAttributeValue();
061: }
062:
063: return value;
064:
065: }
066:
067: // return identifier for this Data element
068: public String getIdentifier() {
069: return identifier;
070: }
071:
072: // return dialect for this Data element
073: public String getDialect() {
074: return dialect;
075: }
076:
077: // return the Data ELement
078: public OMElement getOMData() {
079: return data;
080: }
081:
082: // Get URL from data Element
083: public String getURL() {
084:
085: String urlValue = null;
086: OMElement url = data.getFirstChildWithName(new QName(
087: DRConstants.SERVICE_DATA.URL));
088: if (url != null) {
089: urlValue = url.getText();
090: }
091:
092: return urlValue;
093: }
094:
095: // Get ENDPOINT_REFERENCE from Data Element
096: public OMElement getEndpointReference() {
097: OMElement epr = data.getFirstChildWithName(new QName(
098: DRConstants.SERVICE_DATA.ENDPOINT_REFERENCE));
099: return epr;
100: }
101:
102: // Load the file content of the file specified in the file attribute
103: // in the data element.
104: public OMElement getFileContent(ClassLoader classloader)
105: throws DataRetrievalException {
106:
107: OMElement metaElement = null;
108: if (fileName != null) {
109: DataRetrievalUtil util = DataRetrievalUtil.getInstance();
110:
111: metaElement = util.buildOM(classloader, fileName);
112: }
113: return metaElement;
114: }
115: }
|