From 9833a542bb75c2008c71809e4fdfebc41e67fb46 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 10 Nov 2009 19:18:51 +0000 Subject: Move the SDO folder as new trunk for SDO sub project git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834610 13f79535-47bb-0310-9956-ffa450edef68 --- .../sdo/codegen/JavaInterfaceGenerator.java | 179 +++++++++++++++++++++ 1 file changed, 179 insertions(+) create mode 100644 sdo-java/trunk/impl/src/main/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGenerator.java (limited to 'sdo-java/trunk/impl/src/main/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGenerator.java') diff --git a/sdo-java/trunk/impl/src/main/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGenerator.java b/sdo-java/trunk/impl/src/main/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGenerator.java new file mode 100644 index 0000000000..dc88a0d60d --- /dev/null +++ b/sdo-java/trunk/impl/src/main/java/org/apache/tuscany/sdo/codegen/JavaInterfaceGenerator.java @@ -0,0 +1,179 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ +package org.apache.tuscany.sdo.codegen; + +import java.io.PrintWriter; +import java.util.List; + +import commonj.sdo.Property; +import commonj.sdo.Type; + +import org.apache.tuscany.sdo.SDOTypeVisitor; + +/** + * Implementation of a generator that will output the source code for a Java interface + * that corresponds to the SDO Type's static properties. + * + * @version $Rev$ $Date$ + */ +public class JavaInterfaceGenerator implements SDOTypeVisitor { + + private static String canonicalize(String className) { + if (className == null) { + return ""; + } + if (className.charAt(0) != '[') { // if not array + return className; + } + // process array + boolean invalidClassName = false; + int nestLevel = 1; + StringBuffer sb = new StringBuffer(); + try { + while (className.charAt(nestLevel) == '[') { + nestLevel++; + } + char typeChar = className.charAt(nestLevel); + int end = nestLevel; + switch (typeChar) { + case 'L': + end = className.length() - 1; + if (className.charAt(end) != ';') { + invalidClassName = true; + } else { + sb.append(className.substring(nestLevel+1, end)); + } + break; + case 'Z': + sb.append("boolean"); + break; + case 'B': + sb.append("byte"); + break; + case 'C': + sb.append("char"); + break; + case 'D': + sb.append("double"); + break; + case 'F': + sb.append("float"); + break; + case 'I': + sb.append("int"); + break; + case 'J': + sb.append("long"); + break; + case 'S': + sb.append("short"); + break; + default: + invalidClassName = true; + break; + } + if (end != (className.length() - 1)) { + invalidClassName = true; // we have not used all the characters + } else { + for (int i=0; i