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.0.1, implemented by the Trust@HsH
   * research group at the Hochschule Hannover.
   * %%
   * Copyright (C) 2010 - 2014 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.messages;
  
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  import org.w3c.dom.Node;
  
  import util.DomHelpers;
Provides access to Request associated classes.

Author(s):
aw
Since:
0.1.4
  
  public final class Requests {
  
  	private static Map<Class<? extends Request>, RequestHandler<? extends Request>>
  
  	@SuppressWarnings("deprecation")
  
  	// Not to be instanced
  	private Requests() { }
  
  	private static void initializeDefaultHandlers() {
  
  		 = new HashMap<Class<? extends Request>,
  			RequestHandler<? extends Request>>();
  
  	}

Register a custom request handler.

Parameters:
rh
 
 	public static void registerRequestHandler(RequestHandler<? extends Requestrh) {
 		if (rh == null) {
 			throw new NullPointerException("rh is null");
 		}
 
 		if (rh.handles() == null) {
 			throw new NullPointerException("rh.handles() returns null");
 		}
 
 		if ( == null) {
 		}
 
 			throw new RuntimeException("RequestHandler already registered for "
 					+ rh.handles());
 		}
 
 	}
 
 	public static RequestHandler<? extends RequestgetHandlerFor(Request req) {
 
 		if ( == null) {
 		}
 
 		for (Entry<Class<? extends Request>,
 				RequestHandler<? extends Request>> entry : .entrySet()) {
 			if (entry.getKey().isInstance(req)) {
 				return entry.getValue();
 			}
 		}
 
 		return null;
 	}


Deprecated:
Don't use. Will be gone soon.
Returns:
 
 	public static RequestFactory getRequestFactory() {
 		if ( == null) {
 		}
 
 	}
 
 	// REQUEST CREATION
 	
Create an empty PublishRequest

Returns:
the new PublishRequest
 
 	public static PublishRequest createPublishReq() {
 		return new PublishRequestImpl();
 	}

Create a new PublishRequest that contains the given PublishElement

Parameters:
el the PublishElement that is added to the new PublishRequest
Returns:
the new PublishRequest
 
 		if (el == null) {
 			throw new NullPointerException("el is not allowed to be null");
 		}
 
 		return ret;
 	}


Create a new PublishRequest that contains the given list of PublishElement instances.

Parameters:
list the list of PublishElement instances that are added to the new PublishRequest
Returns:
the new PublishRequest
 
 	public static PublishRequest createPublishReq(List<PublishElementlist) {
 		if (list == null) {
 			throw new NullPointerException("list is not allowed to be null");
 		}
 
 		for (PublishElement el : list) {
 		}
 
 		return ret;
 	}
 
 	public static NewSessionRequest createNewSessionReq() {
 		return new NewSessionRequestImpl();
 	}
 
 	public static EndSessionRequest createEndSessionReq() {
 		return new EndSessionRequestImpl();
 	}
 
 		return new RenewSessionRequestImpl();
 	}
 
 		return new PurgePublisherRequestImpl();
 	}
 
 	public static PollRequest createPollReq() {
 		return new PollRequestImpl();
 	}

Create an empty SubscribeRequest

Returns:
the new SubscribeRequest instance
 
 	public static SubscribeRequest createSubscribeReq() {
 		return new SubscribeRequestImpl();
 	}

Create a SubscribeRequest with one SubscribeElement.

Parameters:
el the SubscribeElement that is added to the new SubscribeRequest. This can either be SubscribeUpdate or SubscribeDelete.
Returns:
the new SubscribeRequest
 
 		if (el == null) {
 			throw new NullPointerException("el is not allowed to be null");
 		}
 
 		return ret;
 	}

Create a SubscribeRequest with a list of SubscribeElement instances.

Parameters:
list the list of SubscribeElement instances that are added to the new SubscribeRequest. The SubscribeElement instances are either SubscribeUpdate or SubscribeDelete instances.
Returns:
the new SubscribeRequest
 
 		if (list == null) {
 			throw new NullPointerException("list is not allowed to be null");
 		}
 
 		for (SubscribeElement el : list) {
 		}
 
 		return ret;
 	}

Create a SearchRequest with default values. You need to set at least the start de.hshannover.f4.trust.ifmapj.identifier.Identifier with SearchHolder.setStartIdentifier(de.hshannover.f4.trust.ifmapj.identifier.Identifier) afterwards!

Returns:
the new SearchRequest instance
 
 	public static SearchRequest createSearchReq() {
 		return new SearchRequestImpl(new SearchHolderImpl());
 	}

Create a new SearchRequest in order to perform an IF-MAP search.

Parameters:
matchLinks the match-links filter (null means match-all, an empty java.lang.String means match-nothing)
maxDepth max-depth of the search (default is left out) types (for example 'identity,device')
maxSize max-size of search result (default is left out)
resultFilter the result-filter filter (null means match-all, an empty java.lang.String means match-nothing)
start the start de.hshannover.f4.trust.ifmapj.identifier.Identifier
Returns:
the new SearchRequest instance
 
 	public static SearchRequest createSearchReq(String matchLinksInteger maxDepth,
 			String termIdentsInteger maxSizeString resultFilterIdentifier start) {
 		fillSearchHolder(srmatchLinksmaxDepthtermIdentsmaxSizeresultFilterstart);
 		return sr;
 	}
 
 	private static void fillSearchHolder(SearchHolder holderString matchLinks,
 			Integer maxDepthString termIdentsInteger maxSize,
 			String resultFilterIdentifier start) {
 		holder.setMatchLinksFilter(matchLinks);
 		holder.setMaxDepth(maxDepth);
 		holder.setTerminalIdentifierTypes(termIdents);
 		holder.setMaxSize(maxSize);
 		holder.setResultFilter(resultFilter);
 		holder.setStartIdentifier(start);
 	}

Returns:
the new PublishUpdate instance
 
 	public static PublishUpdate createPublishUpdate() {
 		return new PublishUpdateImpl();
 	}

Create a new PublishUpdate instance that is used to publish metadata to an de.hshannover.f4.trust.ifmapj.identifier.Identifier. The MetadataLifetime of the new metadata is set to MetadataLifetime.session.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
md the metadata that shall be published
Returns:
the new PublishUpdate instance
 
 	public static PublishUpdate createPublishUpdate(Identifier i1Document md) {
 	}

Create a new PublishUpdate instance that is used to publish metadata on an de.hshannover.f4.trust.ifmapj.identifier.Identifier with a specific MetadataLifetime.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
md the metadata that shall be published
lifetime the lifetime of the new metadata
Returns:
the new PublishUpdate instance
 
 			MetadataLifetime lifetime) {
 		return createPublishUpdate(i1nullmdlifetime);
 	}

Create a new PublishUpdate instance that is used to publish metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances. The MetadataLifetime of the new metadata is set to MetadataLifetime.session.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
md the metadata that shall be published
Returns:
the new PublishUpdate instance
 
 			Document md) {
 		return createPublishUpdate(i1i2md.);
 	}

Create a new PublishUpdate instance that is used to publish metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances with a specific MetadataLifetime.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
md the metadata that shall be published
lifetime the lifetime of the new metadata
Returns:
the new PublishUpdate instance
 
 			Document mdMetadataLifetime lifetime) {
 		if (md == null) {
 			throw new NullPointerException("md not allowed to be null");
 		}
 
 		List<Documentlist = new ArrayList<Document>(1);
 		list.add(md);
 
 		return createPublishUpdate(i1i2listlifetime);
 	}

Create a new PublishUpdate instance that is used to publish a list of metadata instances with a specific MetadataLifetime.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
mdlist a list of metadata objects
lifetime the lifetime of the new metadata
Returns:
the new PublishUpdate instance
 
 			Collection<DocumentmdlistMetadataLifetime lifetime) {
 		return createPublishUpdate(i1nullmdlistlifetime);
 	}

Create a new PublishUpdate instance that is used to publish a list of metadata instances. The MetadataLifetime of the new metadata is set to MetadataLifetime.session.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
mdlist a list of metadata objects
Returns:
the new PublishUpdate instance
 
 			Collection<Documentmdlist) {
 		return createPublishUpdate(i1nullmdlist);
 	}

Create a new PublishUpdate instance that is used to publish a list of metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances. The MetadataLifetime of the new metadata is set to MetadataLifetime.session.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
mdlist a list of metadata objects
Returns:
the new PublishUpdate instance
 
 			Collection<Documentmdlist) {
 		return createPublishUpdate(i1i2mdlist.);
 	}

Create a new PublishUpdate instance that is used to publish a list of metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances with a specific MetadataLifetime.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
mdlist a list of metadata objects
lifetime the lifetime of the new metadata
Returns:
the new PublishUpdate instance
 
 			Collection<DocumentmdlistMetadataLifetime lifetime) {
 		if (mdlist == null) {
 			throw new NullPointerException("mdlist not allowed to be null");
 		}
 		fillMetadataHolder(pui1i2mdlist);
 		pu.setLifeTime(lifetime);
 		return pu;
 	}

Create a new, empty PublishNotify instance.

Returns:
the new PublishNotify instance
 
 	public static PublishNotify createPublishNotify() {
 		return new PublishNotifyImpl();
 	}

Create a new PublishNotify instance that is used to publish metadata to an de.hshannover.f4.trust.ifmapj.identifier.Identifier.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
md the metadata that shall be published
Returns:
the new PublishNotify instance
 
 	public static PublishNotify createPublishNotify(Identifier i1Document md) {
 		return createPublishNotify(i1nullmd);
 	}

Create a new PublishNotify instance that is used to publish a list of metadata instances.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier to which the given metadata is published to
mdlist a list of metadata objects
Returns:
the new PublishNotify instance
 
 			Collection<Documentmdlist) {
 		return createPublishNotify(i1nullmdlist);
 	}

Create a new PublishNotify instance that is used to publish metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
md the metadata that shall be published
Returns:
the new PublishNotify instance
 
 			Document md) {
 
 		if (md == null) {
 			throw new NullPointerException("md is null");
 		}
 
 		List<Documentmdlist = new ArrayList<Document>(1);
 		mdlist.add(md);
 
 		return createPublishNotify(i1i2mdlist);
 	}

Create a new PublishNotify instance that is used to publish a list of metadata on a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances. The MetadataLifetime of the new metadata is set to MetadataLifetime.session.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
mdlist a list of metadata objects
Returns:
the new PublishNotify instance
 
 			Collection<Documentmdlist) {
 
 		if (mdlist == null) {
 			throw new NullPointerException("mdlist is null");
 		}
 
 		fillMetadataHolder(pni1i2mdlist);
 		return pn;
 	}
 
 	private static void fillMetadataHolder(MetadataHolder holderIdentifier i1,
 			Identifier i2Collection<Documentmdlist) {
 
 		fillIdentifierHolder(holderi1i2);
 
 		if (mdlist != null) {
 			for (Document md : mdlist) {
 				holder.addMetadata(md);
 			}
 		}
 	}
 
 	private static void fillIdentifierHolder(IdentifierHolder holderIdentifier i1,
 			Identifier i2) {
 		holder.setIdentifier1(i1);
 		holder.setIdentifier2(i2);
 	}

Create a new, empty PublishDelete instance.

Returns:
the new PublishDelete instance
 
 	public static PublishDelete createPublishDelete() {
 		return new PublishDeleteImpl();
 	}

Create a new PublishDelete instance for a specific de.hshannover.f4.trust.ifmapj.identifier.Identifier in order to delete all of its metadata.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier that is the target of the delete request
Returns:
the new PublishDelete instance
 
 	public static PublishDelete createPublishDelete(Identifier i1) {
 		return createPublishDelete(i1, (Stringnull);
 	}

Create a new PublishDelete instance for a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances in order to delete all metadata of the link.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
Returns:
the new PublishDelete instance
 
 	public static PublishDelete createPublishDelete(Identifier i1Identifier i2) {
 		return createPublishDelete(i1i2null);
 	}

Create a new PublishDelete instance for a specific de.hshannover.f4.trust.ifmapj.identifier.Identifier in order to delete its metadata that matches the given filter.

Parameters:
i1 the de.hshannover.f4.trust.ifmapj.identifier.Identifier that is the target of the delete request
filter a filter that expresses the metadata that shall be deleted
Returns:
the new PublishDelete instance
 
 	public static PublishDelete createPublishDelete(Identifier i1String filter) {
 		return createPublishDelete(i1nullfilter);
 	}

Create a new PublishDelete instance for a link between two de.hshannover.f4.trust.ifmapj.identifier.Identifier instances in order to delete its metadata that matches the given filter.

Parameters:
i1 the first de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
i2 the second de.hshannover.f4.trust.ifmapj.identifier.Identifier of the link
filter a filter that expresses the metadata that shall be deleted
Returns:
the new PublishDelete instance
 
 			String filter) {
 		fillIdentifierHolder(pdi1i2);
 		pd.setFilter(filter);
 		return pd;
 	}

 
 	public static SubscribeUpdate createSubscribeUpdate() {
 		return new SubscribeUpdateImpl(new SearchHolderImpl());
 	}

Create a SubscribeUpdate instance with the given parameters.

Parameters:
name the name of the subscription
matchLinks the match-links filter (null means match-all, an empty java.lang.String means match-nothing)
maxDepth max-depth of the search (default is left out) types (for example 'identity,device')
maxSize max-size of search result (default is left out)
resultFilter the result-filter filter (null means match-all, an empty java.lang.String means match-nothing)
start the start de.hshannover.f4.trust.ifmapj.identifier.Identifier
Returns:
the new SubscribeUpdate instance
 
 			String matchLinksInteger maxDepthString termIdents,
 			Integer maxSizeString resultFilterIdentifier start) {
 		fillSearchHolder(sumatchLinksmaxDepthtermIdentsmaxSizeresultFilterstart);
 		su.setName(name);
 		return su;
 	}

Create a SubscribeDelete instance with default values. You need to set the name with SubscribeElement.setName(java.lang.String) afterwards!

Returns:
the new SubscribeDelete instance
 
 	public static SubscribeDelete createSubscribeDelete() {
 		return new SubscribeDeleteImpl();
 	}

Create a new SubscribeDelete instance with the given name.

Parameters:
name the name of the subscription that shall be deleted on the MAPS.
Returns:
the new SubscribeDelete instance
 
 	public static SubscribeDelete createSubscribeDelete(String name) {
 		sd.setName(name);
 		return sd;
 	}

This class provides helpers for custom request implementations. It's not a fixed API!
 
 	public static final class Helpers {
 
 		private Helpers() { }
 
 
 		public static String baseNsUri() {
 		}
 
 		public static void addSearchInfo(SearchHolder searchInfoDocument docElement to)
 				throws MarshalException {
 
 			Identifier id = searchInfo.getStartIdentifier();
 			String matchLinks = searchInfo.getMatchLinksFilter();
 			String resultFilter = searchInfo.getResultFilter();
 			Integer maxDepth = searchInfo.getMaxDepth();
 			Integer maxSize = searchInfo.getMaxSize();
 			String terminalIdentifiers = searchInfo.getTerminalIdentifierTypes();
 
 			if (id == null) {
 				throw new MarshalException("No start identifier");
 			}
 
 			addIdentifier(iddocto);
 
 			if (matchLinks != null) {
 						matchLinks);
 			}
 
 			if (resultFilter != null) {
 						resultFilter);
 			}
 
 			if (terminalIdentifiers != null) {
 						terminalIdentifiers);
 			}
 
 			if (maxDepth != null) {
 						maxDepth.toString());
 			}
 
 			if (maxSize != null) {
 						maxSize.toString());
 			}
 
 			DomHelpers.addXmlNamespaceDeclarations(searchInfoto);
 		}
 
 		public static void addIdentifiers(IdentifierHolder ihDocument docElement to)
 				throws MarshalException {
 
 			Identifier i1 = ih.getIdentifier1();
 			Identifier i2 = ih.getIdentifier2();
 
 			if (i1 == null && i2 == null) {
 				throw new MarshalException("IdentifierHolder with no Identifiers");
 			}
 
 			if (i1 != null) {
 				addIdentifier(i1docto);
 			}
 
 			if (i2 != null) {
 				addIdentifier(i2docto);
 			}
 		}
 
 		public static void addIdentifier(Identifier iDocument docElement to)
 				throws MarshalException {
 			to.appendChild(Identifiers.toElement(idoc));
 		}
 
 		public static void addSessionId(Element elRequest r)
 				throws MarshalException {
 
 			if (r.getSessionId() == null || r.getSessionId().length() == 0) {
 				throw new MarshalException("sessionId is null");
 			}
 
 		}
 
 		public static SearchResult parseSearchResult(Element sresType type)
 				throws UnmarshalException {
 			List<ResultItemritems = new ArrayList<ResultItem>();
 			String name = null;
 
 			List<ElementelementChildren = DomHelpers.getChildElements(sres);
 
 			if (elementChildren.size() == 0) {
 				throw new UnmarshalException("searchResult with no resultItems");
 			}
 
 			for (Element child : elementChildren) {
 				if (!DomHelpers.elementMatches(child.)) {
 					throw new UnmarshalException("Found non " + . + " element in "
 							+ "SearchResult: " + child.getLocalName());
 				}
 
 				ritems.add(parseResultItem(child));
 			}
 
 			/* check if a name is set */
 			name = name != null && name.length() > 0 ? name : null;
 
 			return new SearchResultImpl(ritemsnametype);
 		}
 
 		public static ResultItem parseResultItem(Element el)
 				throws UnmarshalException {
 			Identifier ident1 = null;
 			Identifier ident2 = null;
 			List<Documentmdlist = null;
 
 			List<ElementelementChildren = DomHelpers.getChildElements(el);
 
 			if (elementChildren.size() == 0) {
 				throw new UnmarshalException("No elements in resultItem found");
 			}
 
 			if (elementChildren.size() > 3) {
 				throw new UnmarshalException("Too many elements in resultItem "
 						+ "element (" + elementChildren.size() + ")");
 			}
 
 			for (Element child : elementChildren) {
 				Identifier tmp = Identifiers.tryFromElement(child);
 
 				// If there was no identifier maybe there is some metadata
 				if (tmp == null && DomHelpers.elementMatches(child.)) {
 
 					if (mdlist != null) {
 						throw new UnmarshalException("Multiple metadata elements " + " in resultItem found");
 					}
 
 					mdlist = parseMetadataList(child);
 				} else if (tmp == null) {
 					throw new UnmarshalException("Unexpected element in searchResult: "
 							+ child.getLocalName());
 				}
 
 				if (tmp != null && ident1 == null) {
 					ident1 = tmp;
 				} else if (tmp != null && ident2 == null) {
 					ident2 = tmp;
 				} else if (tmp != null) {
 					throw new UnmarshalException("Found > 2 identifiers in resultItem");
 				}
 			}
 
 			if (ident1 == null && ident2 == null) {
 				throw new UnmarshalException("No identifier found in searchResult");
 			}
 
 			/* in case there was no metadata element, create one */
 			if (mdlist == null) {
 				mdlist = new LinkedList<Document>();
 			}
 
 			return new ResultItemImpl(ident1ident2mdlist);
 		}
 
 		public static List<DocumentparseMetadataList(Element el)
 				throws UnmarshalException {
 
 			List<Documentret = new ArrayList<Document>();
 			List<ElementelementChildren = DomHelpers.getChildElements(el);
 
 			for (Element child : elementChildren) {
 				ret.add(DomHelpers.deepCopy(child));
 			}
 
 			return ret;
 		}
 
 				throws UnmarshalException {
 			String errCodeStr;
 			String errStr;
 			Element errStrElem = null;
 			IfmapErrorCode errCode = null;
 			String name = null;
 
 
 			errStrElem = DomHelpers.findElementInChildren(el,
 
 			errStr = errStrElem == null ? "IfmapJ: errorString not set" : errStrElem.getTextContent();
 
 			try {
 				errCode = IfmapErrorCode.valueOf(errCodeStr);
 			} catch (IllegalArgumentException e) {
 				throw new UnmarshalException("Invalid errorCode received: " + errCodeStr);
 			}
 
 			// There might be a name if this errorResult is located in a pollResult
 			}
 
 			return new IfmapErrorResult(errCodeerrStrname);
 		}
 
 		public static void checkSimpleResult(Element elString expected)
 			Element content = Helpers.getResponseContentErrorCheck(el);
 
 			if (!DomHelpers.elementMatches(contentexpected)) {
 				throw new UnmarshalException("Wrong Result. Expected " + expected + " got " + content.getLocalName());
 			}
 		}
 
 		public static Element getResponseContentErrorCheck(Element response)
 			Element content = getResponseContentNoErrorCheck(response);
 			checkForError(content);
 			return content;
 		}
 
 		public static Element getResponseContentNoErrorCheck(Element response)
 			List<Elementchildren = DomHelpers.getChildElements(response);
 
 			if (children.size() == 0) {
 				throw new UnmarshalException("No element in response element found");
 			}
 
 			if (children.size() > 1) {
 				throw new UnmarshalException("Too many elements in response element "
 						+ " found (" + children.size() + ")");
 			}
 
 			return children.get(0);
 		}
 
 		public static void checkForError(Element el)
 			if (DomHelpers.elementMatches(el.)) {
 				throw parseErrorResult(el);
 			}
 		}
 
 		public static void checkRequestType(Request reqRequestHandler<? extends Requestrh)
 				throws MarshalException {
 
 			Class<? extends Requestclazz = rh.handles();
 			if (!clazz.isInstance(req)) {
 				throw new MarshalException("Handler for requests of type "
 						+ rh.handles() + " got request of type " + req.getClass());
 			}
 		}
 	}
 
 }
 
 
 // REQUEST HANDLER IMPLEMENTATIONS
 
 
 	public Element toElement(Request reqDocument docthrows MarshalException {
 
 		Helpers.checkRequestType(reqthis);
 
 
 		Element ret = doc.createElementNS(Helpers.baseNsUri(),
 				DomHelpers.makeRequestFqName(
 
 		if (nsr.getMaxPollResultSize() != null) {
 			DomHelpers.addAttribute(ret,
 		}
 
 		return ret;
 	}
 
 
 		Element content = Helpers.getResponseContentErrorCheck(res);
 
 		String sId;
 		String pId;
 		String mprsStr;
 		Integer mprs = null;
 
 		if (!DomHelpers.elementMatches(content.)) {
 			throw new UnmarshalException("No newSession element found");
 		}
 
 
 		if (sId == null || sId.length() == 0) {
 			throw new UnmarshalException("No " + . + " found");
 		}
 
 		if (pId == null || pId.length() == 0) {
 			throw new UnmarshalException("No " + . + " found");
 		}
 
 		if (mprsStr != null && mprsStr.length() > 0) {
 			try {
 				mprs = Integer.parseInt(mprsStr);
 			} catch (NumberFormatException e) {
 				throw new UnmarshalException("Failed to parse " + "max-poll-result-size. Was: " + mprsStr);
 			}
 		}
 
 		return new NewSessionResultImpl(sIdpIdmprs);
 	}
 
		return NewSessionRequest.class;
	public Element toElement(Request reqDocument docthrows MarshalException {
		Helpers.checkRequestType(reqthis);
		Element ret = doc.createElementNS(Helpers.baseNsUri(),
		Helpers.addSessionId(retreq);
		return ret;
		return null;
		return EndSessionRequest.class;
	public Element toElement(Request reqDocument docthrows MarshalException {
		Helpers.checkRequestType(reqthis);
		String pId = ppr.getPublisherId();
		if (pId == null || pId.length() == 0) {
			throw new MarshalException("No ifmap-publisher-id for "
		Element ret = doc.createElementNS(Helpers.baseNsUri(),
		Helpers.addSessionId(retreq);
		return ret;
		return null;
	public Element toElement(Request reqDocument docthrows MarshalException {
		Helpers.checkRequestType(reqthis);
		Element ret = doc.createElementNS(Helpers.baseNsUri(),
		Helpers.addSessionId(retreq);
		return ret;
		return null;
		return RenewSessionRequest.class;
	public Element toElement(Request reqDocument docthrows MarshalException {
		Helpers.checkRequestType(reqthis);
		Element ret = doc.createElementNS(Helpers.baseNsUri(),
		Helpers.addSessionId(retreq);
		return ret;
		Element content = Helpers.getResponseContentNoErrorCheck(res);
		List<SearchResultsResults = new ArrayList<SearchResult>();
		Type curType;
		String curName;
		SearchResult curSearchResult;
		if (DomHelpers.elementMatches(content.)) {
			List<ElementelementChildren = DomHelpers.getChildElements(content);
			if (elementChildren.size() == 0) {
				throw new UnmarshalException("No result elements in pollResult");
			for (Element child : elementChildren) {
				curName = null;
				curType = resultType(child);
				if (curType != null) {
					curSearchResult = Helpers.parseSearchResult(childcurType);
					curName = curSearchResult.getName();
					sResults.add(curSearchResult);
else /* error result */ {
					IfmapErrorResult err = Helpers.parseErrorResult(child);
					curName = err.getName();
					errorResults.add(err);
				if (curName == null) {
					throw new UnmarshalException("No name set for result in pollResult");
else if (DomHelpers.elementMatches(content.)) {
			return new EndSessionException();
else {
			Helpers.checkForError(content);
			// if we get here, we didn't find a pollResult, no endSessionResult
			// and no errorResult so something is weird ;)
			throw new UnmarshalException("Bad poll response: " + content.getLocalName());
		return new PollResultImpl(sResultserrorResults);
	private Type resultType(Element childthrows UnmarshalException {
else if (DomHelpers.elementMatches(child.)) {
else if (DomHelpers.elementMatches(child.)) {
else if (DomHelpers.elementMatches(child.)) {
else if (DomHelpers.elementMatches(child.)) {
			return null;
else {
			throw new UnmarshalException("Unknown element in "
. + ": " + child.getLocalName());
	public Class<PollRequesthandles() {
		return PollRequest.class;
	public Element toElement(Request reqDocument docthrows MarshalException {
		Helpers.checkRequestType(reqthis);
		Element ret = doc.createElementNS(Helpers.baseNsUri(),
		addPublishElements(prdocret);
		Helpers.addSessionId(retreq);
		return ret;
	private void addPublishElements(PublishRequest prDocument docElement to)
		if (pr.getPublishElements().size() == 0) {
			throw new MarshalException("No publish elements");
		for (PublishElement pubEl : pr.getPublishElements()) {
			if (pubEl instanceof PublishUpdate) {
				PublishUpdate pu = (PublishUpdatepubEl;
				el = DomHelpers.createNonNsElement(doc,
				if (pu.getLifeTime() != null) {
					lifetime = pu.getLifeTime();
				DomHelpers.addAttribute(el,
						lifetime.toString());
else if (pubEl instanceof PublishDelete) {
				PublishDelete pd = (PublishDeletepubEl;
				el = DomHelpers.createNonNsElement(doc,
				if (pd.getFilter() != null) {
					DomHelpers.addAttribute(el,
				DomHelpers.addXmlNamespaceDeclarations(pdel);
else if (pubEl instanceof PublishNotify) {
				el = DomHelpers.createNonNsElement(doc,
else {
				throw new MarshalException("Unknown PublishElement Implementation");
			if (pubEl instanceof IdentifierHolder) {
				Helpers.addIdentifiers((IdentifierHolderpubEldocel);
else {
				throw new MarshalException("No IdentifierHoldingRequest?");
			if (pubEl instanceof MetadataHolder) {
				addMetadataList((MetadataHolderpubEldocel);