Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2d4be328fe5609c1cac6ad590beb91ccf8859a2f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*******************************************************************************
 * Copyright (c) 2006, 2007 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the terms of
 * the Eclipse Public License v1.0, which accompanies this distribution and is available at
 * http://www.eclipse.org/legal/epl-v10.html.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.core.internal.mappings;

import java.util.StringTokenizer;

public class RelationshipMappingTools
{	
	public static boolean targetEntityIsValid(String targetEntity) {
		if (targetEntity == null) {
			return true;
		}
		// balance is # of name tokens - # of period tokens seen so far
		// initially 0; finally 1; should never drop < 0 or > 1
		int balance = 0;
		for (StringTokenizer t = new StringTokenizer(targetEntity, ".", true); t.hasMoreTokens();) {
			String s = t.nextToken();
			if (s.indexOf('.') >= 0) {
				// this is a delimiter
				if (s.length() > 1) {
					// too many periods in a row
					return false;
				}
				balance--;
				if (balance < 0) {
					return false;
				}
			} else {
				// this is an identifier segment
				balance++;
			}
		}
		return (balance == 1);
	}
}

Back to the top