Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * #%L
   * =====================================================
   *   _____                _     ____  _   _       _   _
   *  |_   _|_ __ _   _ ___| |_  / __ \| | | | ___ | | | |
   *    | | | '__| | | / __| __|/ / _` | |_| |/ __|| |_| |
   *    | | | |  | |_| \__ \ |_| | (_| |  _  |\__ \|  _  |
   *    |_| |_|   \__,_|___/\__|\ \__,_|_| |_||___/|_| |_|
   *                             \____/
  * 
  * =====================================================
  * 
  * Hochschule Hannover
  * (University of Applied Sciences and Arts, Hannover)
  * Faculty IV, Dept. of Computer Science
  * Ricklinger Stadtweg 118, 30459 Hannover, Germany
  * 
  * Email: trust@f4-i.fh-hannover.de
  * Website: http://trust.f4.hs-hannover.de/
  * 
  * This file is part of ifmapj, version 2.3.0, implemented by the Trust@HsH
  * research group at the Hochschule Hannover.
  * %%
  * Copyright (C) 2010 - 2015 Trust@HsH
  * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  *      http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * #L%
  */
 package de.hshannover.f4.trust.ifmapj.metadata;
 
 
 
Abstract base class for metadata factories. Provides methods to create Document objects.

Author(s):
Bastian Hellmann
 
 public abstract class IfmapMetadataFactory {
 
 
 	public IfmapMetadataFactory() {
 		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 		dbf.setNamespaceAware(true);
 		try {
 		} catch (ParserConfigurationException e) {
 			IfmapJLog.error("Could not get DocumentBuilder instance ["
 					+ e.getMessage() + "]");
 			throw new RuntimeException(e);
 		}
 	}

Creates a metadata document with a single element and given namespace information.

Parameters:
namespaceUri URI of the namespace of the metadata document
namespacePrefix prefix of the namespace of the metadata document
name value of the root element of the metadata document
cardinality the cardinality of the metadata document
Returns:
a org.w3c.dom.Document instance representing the metadata object
 
 	protected Document createSingleElementDocument(String namespaceUriString namespacePrefixString name,
 			Cardinality cardinality) {
 		String qualifiedName = namespacePrefix
 				+ ":" + name;
 		Element e = doc.createElementNS(namespaceUriqualifiedName);
 		e.setAttributeNS(null"ifmap-cardinality"cardinality.toString());
 		doc.appendChild(e);
 		return doc;
 	}

Helper to create a new element with name elName and append it to the org.w3c.dom.Element given by parent if the given value is non-null. The new org.w3c.dom.Element will have org.w3c.dom.Text node containing value.

Parameters:
doc org.w3c.dom.Document where parent is located in
parent where to append the new element
elName the name of the new element.
value the value of the org.w3c.dom.Text node appended to the new element, using toString() on the object.
	protected void appendTextElementIfNotNull(Document docElement parent,
			String elNameObject value) {
		if (value == null) {
			return;
		}
		createAndAppendTextElementCheckNull(docparentelNamevalue);
	}

Helper to create a new element with name elName and append it to the org.w3c.dom.Element given by parent. The new org.w3c.dom.Element will have org.w3c.dom.Text node containing value.

Parameters:
doc org.w3c.dom.Document where parent is located in
parent where to append the new element
elName the name of the new element.
value the value of the org.w3c.dom.Text node appended to the new element, using toString() on the object. is null
Returns:
the new org.w3c.dom.Element
			String elNameObject value) {
		if (doc == null
				|| parent == null || elName == null) {
			throw new NullPointerException("bad parameters given");
		}
		if (value == null) {
			throw new NullPointerException("null is not allowed for "
elName
" in " + doc.getFirstChild().getLocalName());
		}
		String valueStr = value.toString();
		if (valueStr == null) {
			throw new NullPointerException("null-string not allowed for "
elName
" in " + doc.getFirstChild().getLocalName());
		}
		Element child = createAndAppendElement(docparentelName);
		Text txtcElement = doc.createTextNode(valueStr);
		child.appendChild(txtcElement);
		return child;
	}

Helper to create an org.w3c.dom.Element without a namespace in org.w3c.dom.Document doc and append it to the org.w3c.dom.Element given by parent.

Parameters:
doc the target org.w3c.dom.Document
parent the parent org.w3c.dom.Element
elName the name of the new org.w3c.dom.Element
Returns:
the new org.w3c.dom.Element
	protected Element createAndAppendElement(Document docElement parentString elName) {
		Element el = doc.createElementNS(nullelName);
		parent.appendChild(el);
		return el;
	}

Helper to create an org.w3c.dom.Element without a namespace in org.w3c.dom.Document doc and append it to the org.w3c.dom.Element given by parent. Further, add all attributes to the newly created org.w3c.dom.Element specified by attrList.

Parameters:
doc the target org.w3c.dom.Document
parent the parent org.w3c.dom.Element
elName the name of the new org.w3c.dom.Element
attrList name value pairs of attributes
Returns:
the new org.w3c.dom.Element
			String elNameString... attrList) {
		if (attrList.length % 2 != 0) {
			throw new RuntimeException("Bad attrList length");
		}
		Element el = createAndAppendElement(docparentelName);
		for (int i = 0; i < attrList.lengthi += 2) {
			el.setAttributeNS(nullattrList[i], attrList[i + 1]);
		}
		return el;
	}
New to GrepCode? Check out our FAQ X