Coverage Report - org.deduced.generator.java.JavaNamingUtilities
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaNamingUtilities
97%
287/295
90%
111/122
2
 
 1  
 /**
 2  
  *    Copyright 2005-2011 Steve McDuff d-duff@users.sourceforge.net
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package org.deduced.generator.java;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Arrays;
 21  
 import java.util.LinkedList;
 22  
 import java.util.List;
 23  
 import java.util.logging.Level;
 24  
 import java.util.logging.Logger;
 25  
 
 26  
 import org.apache.commons.collections.list.TreeList;
 27  
 import org.apache.commons.lang.StringEscapeUtils;
 28  
 import org.apache.commons.lang.StringUtils;
 29  
 import org.deduced.BasicTypes;
 30  
 import org.deduced.DeducedModelLayer;
 31  
 import org.deduced.DeducedSchemaLayer;
 32  
 import org.deduced.DeducedUtilities;
 33  
 import org.deduced.OrderedPropertyListType;
 34  
 import org.deduced.OrderedPropertyListTypeHolder;
 35  
 import org.deduced.OrderingPropertyCollectionType;
 36  
 import org.deduced.OrderingPropertyCollectionTypeHolder;
 37  
 import org.deduced.PropertyCollection;
 38  
 import org.deduced.PropertyCollectionListInstance;
 39  
 import org.deduced.PropertyCollectionListInstanceHolder;
 40  
 import org.deduced.PropertyCollectionType;
 41  
 import org.deduced.PropertyCollectionTypeHolder;
 42  
 import org.deduced.PropertyInstance;
 43  
 import org.deduced.PropertyInstanceHolder;
 44  
 import org.deduced.PropertyList;
 45  
 import org.deduced.PropertyMap;
 46  
 import org.deduced.PropertyPackage;
 47  
 import org.deduced.PropertyType;
 48  
 import org.deduced.PropertyTypeHolder;
 49  
 import org.deduced.generator.StringAdjuster;
 50  
 import org.deduced.implementation.DeducedSchemaLayerImplementation;
 51  
 import org.deduced.implementation.EnumerationPropertyTypeImplementation;
 52  
 import org.deduced.implementation.OrderedPropertyListTypeImplementation;
 53  
 import org.deduced.implementation.OrderingPropertyCollectionTypeImplementation;
 54  
 import org.deduced.implementation.PropertyCollectionListInstanceImplementation;
 55  
 import org.deduced.implementation.PropertyCollectionTypeImplementation;
 56  
 import org.deduced.implementation.PropertyInstanceImplementation;
 57  
 import org.deduced.implementation.PropertyPackageImplementation;
 58  
 import org.deduced.rule.DeductionRuleLibrary;
 59  
 import org.deduced.utilities.FileUtilities;
 60  
 import org.deduced.validation.model.NullableValidationModel;
 61  
 
 62  
 /**
 63  
  * Class used to host utility methods when generating Java classes
 64  
  * 
 65  
  * @author Steve McDuff
 66  
  */
 67  2
 public class JavaNamingUtilities
 68  
 {
 69  
 
 70  
         /**
 71  
          * Logger
 72  
          */
 73  1
         private static final Logger LOGGER = Logger
 74  
                 .getLogger(JavaNamingUtilities.class.getName());
 75  
 
 76  
         /**
 77  
          * singleton reference used to pass as a variable to velocity
 78  
          */
 79  1
         public static final JavaNamingUtilities DEFAULT = new JavaNamingUtilities();
 80  
 
 81  
         /**
 82  
          * utility class to adjust method names
 83  
          */
 84  1
         private static final StringAdjuster METHOD_NAME_ADJUSTER =
 85  
                 new StringAdjuster();
 86  
         /**
 87  
          * utility class to adjust member names
 88  
          */
 89  1
         private static final StringAdjuster MEMBER_NAME_ADJUSTER =
 90  
                 new StringAdjuster();
 91  
         /**
 92  
          * utility class to adjust package names
 93  
          */
 94  1
         private static final StringAdjuster PACKAGE_NAME_ADJUSTER =
 95  
                 new StringAdjuster();
 96  
         /**
 97  
          * utility class to adjust class names
 98  
          */
 99  1
         private static final StringAdjuster CLASS_NAME_ADJUSTER =
 100  
                 new StringAdjuster();
 101  
         /**
 102  
          * utility class to adjust static variable names
 103  
          */
 104  1
         private static final StringAdjuster STATIC_NAME_ADJUSTER =
 105  
                 new StringAdjuster();
 106  
 
 107  
         /**
 108  
          * package separator
 109  
          */
 110  
         public static final String PACKAGE_SEPARATOR = "."; //$NON-NLS-1$
 111  
 
 112  
         /**
 113  
          * prefix for getter method
 114  
          */
 115  
         public static final String GETTER_PREFIX = "get "; //$NON-NLS-1$
 116  
 
 117  
         /**
 118  
          * prefix for boolean getter method
 119  
          */
 120  
         public static final String BOOLEAN_GETTER_PREFIX = "is "; //$NON-NLS-1$
 121  
 
 122  
         /**
 123  
          * prefix for setter method
 124  
          */
 125  
         public static final String SETTER_PREFIX = "set "; //$NON-NLS-1$
 126  
 
 127  
         /**
 128  
          * suffix for property collection types
 129  
          */
 130  
         public static final String TYPE_SUFFIX = " Type"; //$NON-NLS-1$
 131  
 
 132  
         /**
 133  
          * suffix for the key list variable
 134  
          */
 135  
         public static final String KEY_LIST_SUFFIX = " key list"; //$NON-NLS-1$
 136  
 
 137  
         /**
 138  
          * suffix for a property instance
 139  
          */
 140  
         public static final String INSTANCE_SUFFIX = " instance"; //$NON-NLS-1$
 141  
 
 142  
         /**
 143  
          * suffix for a property instance
 144  
          */
 145  
         public static final String LITERAL_SUFFIX = " literal"; //$NON-NLS-1$
 146  
 
 147  
         /**
 148  
          * suffix for a type implementation class name
 149  
          */
 150  
         public static final String IMPLEMENTATION_SUFFIX = " implementation"; //$NON-NLS-1$
 151  
 
 152  
         /**
 153  
          * code used to initialize the string adjusters
 154  
          */
 155  
         static
 156  
         {
 157  1
                 CLASS_NAME_ADJUSTER.setFirstLetterOfEachWordUpperCase(true);
 158  1
                 CLASS_NAME_ADJUSTER.setUpperCaseFirstLetter(true);
 159  1
                 CLASS_NAME_ADJUSTER.setWhiteSpaceReplaceString(""); //$NON-NLS-1$
 160  1
                 CLASS_NAME_ADJUSTER.setAcceptingOnlyBaseCharacters(true);
 161  
 
 162  1
                 STATIC_NAME_ADJUSTER.setAllInUpperCase(true);
 163  1
                 STATIC_NAME_ADJUSTER.setWhiteSpaceReplaceString("_"); //$NON-NLS-1$
 164  1
                 STATIC_NAME_ADJUSTER.setAcceptingOnlyBaseCharacters(true);
 165  
 
 166  1
                 PACKAGE_NAME_ADJUSTER.setAllInLowerCase(true);
 167  1
                 PACKAGE_NAME_ADJUSTER.setWhiteSpaceReplaceString(""); //$NON-NLS-1$
 168  1
                 PACKAGE_NAME_ADJUSTER.setAcceptingOnlyBaseCharacters(true);
 169  
 
 170  1
                 METHOD_NAME_ADJUSTER.setFirstLetterOfEachWordUpperCase(true);
 171  1
                 METHOD_NAME_ADJUSTER.setLowerCaseFirstLetter(true);
 172  1
                 METHOD_NAME_ADJUSTER.setWhiteSpaceReplaceString(""); //$NON-NLS-1$
 173  1
                 METHOD_NAME_ADJUSTER.setAcceptingOnlyBaseCharacters(true);
 174  
 
 175  1
                 MEMBER_NAME_ADJUSTER.setFirstLetterOfEachWordUpperCase(true);
 176  1
                 MEMBER_NAME_ADJUSTER.setLowerCaseFirstLetter(true);
 177  1
                 MEMBER_NAME_ADJUSTER.setWhiteSpaceReplaceString(""); //$NON-NLS-1$
 178  1
                 MEMBER_NAME_ADJUSTER.setAcceptingOnlyBaseCharacters(true);
 179  
 
 180  1
         }
 181  
 
 182  
         /**
 183  
          * get a java interface name from a type
 184  
          * 
 185  
          * @param type the type containing a name property
 186  
          * @return the java class name associated with it
 187  
          */
 188  
         public static String getInterfaceName(
 189  
                 PropertyCollection<?, ?> type)
 190  
         {
 191  153
                 return getClassName(DeducedUtilities.getCollectionName(type));
 192  
         }
 193  
 
 194  
         /**
 195  
          * get a java implementation name from a type
 196  
          * 
 197  
          * @param type the type containing a name property
 198  
          * @return the java class name associated with it
 199  
          */
 200  
         public static String getImplementationName(
 201  
                 PropertyCollection<?, ?> type)
 202  
         {
 203  107
                 return getClassName(DeducedUtilities.getCollectionName(type)
 204  
                         + IMPLEMENTATION_SUFFIX);
 205  
         }
 206  
 
 207  
         /**
 208  
          * adjust a string to print a java class name
 209  
          * 
 210  
          * @param baseName the base name
 211  
          * @return the java class name
 212  
          */
 213  
         public static String getClassName(
 214  
                 String baseName)
 215  
         {
 216  326
                 return CLASS_NAME_ADJUSTER.adjustString(baseName);
 217  
         }
 218  
 
 219  
         /**
 220  
          * adjust a string to print a java class package declaration
 221  
          * 
 222  
          * @param packageName the package name name
 223  
          * @return the the package name declaration
 224  
          */
 225  
         public static String getPackageDeclaration(
 226  
                 String packageName)
 227  
         {
 228  14
                 String retVal = "";
 229  14
                 if (!StringUtils.isBlank(packageName))
 230  
                 {
 231  14
                         retVal = "package " + packageName + ";";
 232  
                 }
 233  14
                 return retVal;
 234  
         }
 235  
 
 236  
         /**
 237  
          * adjust a string to print a schema java class name
 238  
          * 
 239  
          * @param schemaName the base name
 240  
          * @return the java class name
 241  
          */
 242  
         public static String getSchemaClassName(
 243  
                 String schemaName)
 244  
         {
 245  60
                 String retVal = schemaName;
 246  60
                 int lastDotIndex = retVal.lastIndexOf('.');
 247  60
                 if (lastDotIndex != -1)
 248  
                 {
 249  14
                         int length = retVal.length();
 250  14
                         retVal = retVal.substring(lastDotIndex, length);
 251  
                 }
 252  60
                 retVal = getClassName(retVal);
 253  60
                 if (retVal.isEmpty())
 254  
                 {
 255  4
                         retVal = "DefaultSchemaClassName";
 256  
                 }
 257  
 
 258  60
                 return retVal;
 259  
         }
 260  
 
 261  
         /**
 262  
          * adjust a string to print a fully qualified schema java class name
 263  
          * 
 264  
          * @param schemaName the base name
 265  
          * @return the schema java class name
 266  
          */
 267  
         public static String getFullyQualifiedSchemaClassName(
 268  
                 String schemaName)
 269  
         {
 270  25
                 String className = getSchemaClassName(schemaName);
 271  25
                 String packageName = getSchemaPackageName(schemaName);
 272  25
                 String retVal = getFullyQualifiedJavaClassName(packageName, className);
 273  25
                 return retVal;
 274  
         }
 275  
 
 276  
         /**
 277  
          * get a fully qualified Java Class Name based on the package name and the
 278  
          * class name
 279  
          * 
 280  
          * @param packageName the package name
 281  
          * @param className the class name
 282  
          * @return the fully qualified java class name
 283  
          */
 284  
         public static String getFullyQualifiedJavaClassName(
 285  
                 String packageName, String className)
 286  
         {
 287  32
                 String retVal = className;
 288  32
                 if (!StringUtils.isBlank(packageName))
 289  
                 {
 290  30
                         retVal = packageName + PACKAGE_SEPARATOR + className;
 291  30
                         retVal = retVal.replaceAll("\\.\\.*", ".");
 292  30
                         retVal = retVal.replaceAll("^\\.*", "");
 293  
                 }
 294  32
                 return retVal;
 295  
         }
 296  
 
 297  
         /**
 298  
          * adjust a string to print a schema package name
 299  
          * 
 300  
          * @param schemaName the base name
 301  
          * @return the package name
 302  
          */
 303  
         public static String getSchemaPackageName(
 304  
                 String schemaName)
 305  
         {
 306  71
                 int lastDotIndex = schemaName.lastIndexOf('.');
 307  71
                 String retVal = "";
 308  71
                 if (lastDotIndex != -1)
 309  
                 {
 310  23
                         retVal = schemaName.substring(0, lastDotIndex);
 311  
                 }
 312  
 
 313  71
                 String[] packageSplit = retVal.split("\\.");
 314  190
                 for (int i = 0; i < packageSplit.length; i++)
 315  
                 {
 316  119
                         packageSplit[i] = getPackageName(packageSplit[i]);
 317  
                 }
 318  
 
 319  71
                 List<String> packageNameList = Arrays.asList(packageSplit);
 320  71
                 retVal =
 321  
                         concatenateStringListWithSeparatorSkipBlank(PACKAGE_SEPARATOR,
 322  
                                 packageNameList);
 323  
 
 324  71
                 if (StringUtils.isEmpty(retVal))
 325  
                 {
 326  
                         // use a default value
 327  48
                         retVal = "factory";
 328  
                 }
 329  
 
 330  71
                 return retVal;
 331  
         }
 332  
 
 333  
         /**
 334  
          * adjust a string to print a schema folder name
 335  
          * 
 336  
          * @param schemaName the base name
 337  
          * @return the folder name
 338  
          */
 339  
         public static String getSchemaFolderName(
 340  
                 String schemaName)
 341  
         {
 342  23
                 String retVal = getSchemaPackageName(schemaName);
 343  23
                 retVal = retVal.replace('.', '/');
 344  23
                 return retVal;
 345  
         }
 346  
 
 347  
         /**
 348  
          * adjust a string to print a static variable name
 349  
          * 
 350  
          * @param baseName the name to adjust
 351  
          * @return the static variable name
 352  
          */
 353  
         public static String getStaticVariableName(
 354  
                 String baseName)
 355  
         {
 356  324
                 return STATIC_NAME_ADJUSTER.adjustString(baseName);
 357  
         }
 358  
 
 359  
         /**
 360  
          * adjust a string to print a method name
 361  
          * 
 362  
          * @param baseName the name to adjust
 363  
          * @return the method name
 364  
          */
 365  
         public static String getMethodName(
 366  
                 String baseName)
 367  
         {
 368  209
                 return METHOD_NAME_ADJUSTER.adjustString(baseName);
 369  
         }
 370  
 
 371  
         /**
 372  
          * get the package name for the interface associated with a collection type
 373  
          * 
 374  
          * @param collectionType the collection type
 375  
          * 
 376  
          * @return the package name
 377  
          */
 378  
         public static String getInterfacePackageName(
 379  
                 PropertyCollection<?, ?> collectionType)
 380  
         {
 381  296
                 List<PropertyCollection<?, ?>> packageList =
 382  
                         getPackageListFromType(collectionType);
 383  
 
 384  296
                 return getPackageNameFromPackageList(packageList);
 385  
         }
 386  
 
 387  
         /**
 388  
          * get the package name from a package list
 389  
          * 
 390  
          * @param packageList the list of packages. Only the first package in the
 391  
          *            list is allowed to have a blank name. All other packages that
 392  
          *            have a blank name will trigger a IllegalArgumentException.
 393  
          * 
 394  
          * @return the package name. This value is never null. It will return a
 395  
          *         blank string "" if no inputs are specified.
 396  
          */
 397  
         public static String getPackageNameFromPackageList(
 398  
                 List<? extends PropertyCollection<?, ?>> packageList)
 399  
         {
 400  307
                 String packageSeparator = PACKAGE_SEPARATOR;
 401  
 
 402  307
                 return concatenatePackageNamesWithSeparator(packageList,
 403  
                         packageSeparator);
 404  
         }
 405  
 
 406  
         /**
 407  
          * concatenate package names with a separator between each package name
 408  
          * 
 409  
          * @param packageList the list of packages. Only the first package in the
 410  
          *            list is allowed to have a blank name. All other packages that
 411  
          *            have a blank name will trigger a IllegalArgumentException.
 412  
          * @param packageSeparator the separator
 413  
          * @return the concatenated name
 414  
          */
 415  
         private static String concatenatePackageNamesWithSeparator(
 416  
                 List<? extends PropertyCollection<?, ?>> packageList,
 417  
                 String packageSeparator)
 418  
         {
 419  440
                 List<String> nameList = new ArrayList<String>();
 420  
 
 421  440
                 if (packageList != null)
 422  
                 {
 423  439
                         for (PropertyCollection<?, ?> currentPackage : packageList)
 424  
                         {
 425  841
                                 nameList.add(getPackageNameFromPackage(currentPackage));
 426  
                         }
 427  
                 }
 428  
 
 429  440
                 return concatenateStringListWithSeparatorSkipBlank(packageSeparator,
 430  
                         nameList);
 431  
         }
 432  
 
 433  
         /**
 434  
          * concatenate String List With Separator Skip Blank
 435  
          * 
 436  
          * @param separator the separator to use
 437  
          * @param stringList the list of string to concatenate
 438  
          * @return the concatenated string
 439  
          */
 440  
         public static String concatenateStringListWithSeparatorSkipBlank(
 441  
                 String separator, List<String> stringList)
 442  
         {
 443  511
                 StringBuilder retVal = new StringBuilder();
 444  511
                 boolean first = true;
 445  511
                 for (String currentString : stringList)
 446  
                 {
 447  960
                         if (!StringUtils.isBlank(currentString))
 448  
                         {
 449  555
                                 if (first)
 450  
                                 {
 451  400
                                         first = false;
 452  
                                 }
 453  
                                 else
 454  
                                 {
 455  155
                                         retVal.append(separator);
 456  
                                 }
 457  
 
 458  555
                                 retVal.append(currentString);
 459  
                         }
 460  
                 }
 461  511
                 return retVal.toString();
 462  
         }
 463  
 
 464  
         /**
 465  
          * get the package name from a property package object
 466  
          * 
 467  
          * @param propertyPackage the property package
 468  
          * @return the name of this package only
 469  
          */
 470  
         public static String getPackageNameFromPackage(
 471  
                 PropertyCollection<?, ?> propertyPackage)
 472  
         {
 473  841
                 String packageName =
 474  
                         DeducedUtilities.getCollectionName(propertyPackage);
 475  841
                 return getPackageName(packageName);
 476  
         }
 477  
 
 478  
         /**
 479  
          * get an adjusted package name from a raw package name
 480  
          * 
 481  
          * @param nameToAdjust the package name to adjust
 482  
          * @return a valid java package name
 483  
          */
 484  
         public static String getPackageName(
 485  
                 String nameToAdjust)
 486  
         {
 487  960
                 String adjustedPackageName =
 488  
                         PACKAGE_NAME_ADJUSTER.adjustString(nameToAdjust);
 489  960
                 return adjustedPackageName;
 490  
         }
 491  
 
 492  
         /**
 493  
          * get the variable name used to reference a property package
 494  
          * 
 495  
          * @param propertyPackage the property package to reference
 496  
          * @return the variable name holding the package
 497  
          */
 498  
         public static String getPackageVariableName(
 499  
                 PropertyCollection<?, ?> propertyPackage)
 500  
         {
 501  133
                 List<PropertyCollection<?, ?>> packageList =
 502  
                         getParentPackageListFromPackage(propertyPackage);
 503  
 
 504  133
                 String concatenatedPackageName =
 505  
                         concatenatePackageNamesWithSeparator(packageList, " ");
 506  
 
 507  133
                 if (StringUtils.isBlank(concatenatedPackageName))
 508  
                 {
 509  50
                         concatenatedPackageName = "root";
 510  
                 }
 511  
 
 512  133
                 return STATIC_NAME_ADJUSTER.adjustString(concatenatedPackageName
 513  
                         + " package");
 514  
         }
 515  
 
 516  
         /**
 517  
          * get the ordered list of packages leading up to a property package
 518  
          * 
 519  
          * @param propertyPackage the property package to reach
 520  
          * @return the ordered list of property package objects
 521  
          */
 522  
         @SuppressWarnings("unchecked")
 523  
         public static List<PropertyCollection<?, ?>> getParentPackageListFromPackage(
 524  
                 PropertyCollection<?, ?> propertyPackage)
 525  
         {
 526  457
                 List<PropertyCollection<?, ?>> retVal = new TreeList();
 527  
 
 528  457
                 PropertyCollection<?, ?> parent = propertyPackage;
 529  
 
 530  1320
                 while (parent != null)
 531  
                 {
 532  1302
                         if (DeducedUtilities.isInstanceOf(parent.type(),
 533  
                                 PropertyPackage.PROPERTY_PACKAGE_TYPE
 534  
                                         .getPropertyCollectionType()))
 535  
                         {
 536  
                                 // found a package, add it to the list
 537  863
                                 retVal.add(0, parent);
 538  
                         }
 539  
                         else
 540  
                         {
 541  
                                 break;
 542  
                         }
 543  863
                         parent = parent.parent();
 544  863
                         if (parent != null)
 545  
                         {
 546  849
                                 parent = parent.parent();
 547  
                         }
 548  
                 }
 549  457
                 return retVal;
 550  
         }
 551  
 
 552  
         /**
 553  
          * get the ordered list of packages leading up to a property type
 554  
          * 
 555  
          * @param type the type
 556  
          * @return the ordered list of property package objects
 557  
          */
 558  
         public static List<PropertyCollection<?, ?>> getPackageListFromType(
 559  
                 PropertyCollection<?, ?> type)
 560  
         {
 561  304
                 PropertyCollection<?, ?> packageParent = type;
 562  
 
 563  304
                 if (packageParent != null)
 564  
                 {
 565  302
                         packageParent = packageParent.parent();
 566  
                 }
 567  
 
 568  304
                 if (packageParent != null)
 569  
                 {
 570  300
                         packageParent = packageParent.parent();
 571  
                 }
 572  
 
 573  304
                 return getParentPackageListFromPackage(packageParent);
 574  
         }
 575  
 
 576  
         /**
 577  
          * get an interface type holder variable name
 578  
          * 
 579  
          * @param collectionType the type
 580  
          * @return the type holder variable name
 581  
          */
 582  
         public static String getInterfaceTypeHolderName(
 583  
                 PropertyCollection<?, ?> collectionType)
 584  
         {
 585  86
                 if (collectionType == null)
 586  
                 {
 587  1
                         return null;
 588  
                 }
 589  85
                 return getStaticVariableName(DeducedUtilities
 590  
                         .getCollectionName(collectionType) + TYPE_SUFFIX);
 591  
         }
 592  
 
 593  
         /**
 594  
          * get a fully qualified type interface name with the package name and type
 595  
          * name.
 596  
          * 
 597  
          * @param collectionType the type
 598  
          * @return the fully qualified type interface name
 599  
          */
 600  
         public static String getFullyQualifiedTypeInterfaceName(
 601  
                 PropertyCollection<?, ?> collectionType)
 602  
         {
 603  126
                 String interfacePackageName = getInterfacePackageName(collectionType);
 604  126
                 String interfaceName = getInterfaceName(collectionType);
 605  126
                 String retVal =
 606  
                         extractFullyQualifiedJavaClassName(interfacePackageName,
 607  
                                 interfaceName);
 608  126
                 return retVal;
 609  
         }
 610  
 
 611  
         /**
 612  
          * extract a fully qualified java class name from a package and a class
 613  
          * name. If the package name is empty, then the returned name will still be
 614  
          * valid as the package name will not be included in the result
 615  
          * 
 616  
          * @param packageName the package name
 617  
          * @param className the class name
 618  
          * @return the fully qualified java class
 619  
          */
 620  
         private static String extractFullyQualifiedJavaClassName(
 621  
                 String packageName, String className)
 622  
         {
 623  207
                 String retVal = null;
 624  207
                 if (StringUtils.isBlank(packageName))
 625  
                 {
 626  1
                         retVal = className;
 627  
                 }
 628  
                 else
 629  
                 {
 630  206
                         retVal = packageName + PACKAGE_SEPARATOR + className;
 631  
                 }
 632  207
                 return retVal;
 633  
         }
 634  
 
 635  
         /**
 636  
          * get a fully qualified type implementation name with the package name and
 637  
          * type name.
 638  
          * 
 639  
          * @param collectionType the type
 640  
          * @return the fully qualified type implementation name
 641  
          */
 642  
         public static String getFullyQualifiedTypeImplementationName(
 643  
                 PropertyCollection<?, ?> collectionType)
 644  
         {
 645  98
                 String retVal = null;
 646  98
                 if (collectionType == PropertyList.PROPERTY_LIST_TYPE
 647  
                         .getPropertyCollectionType())
 648  
                 {
 649  17
                         retVal = PropertyList.class.getName();
 650  
                 }
 651  
                 else
 652  
                 {
 653  81
                         String implementationPackageName =
 654  
                                 getImplementationPackageName(collectionType);
 655  81
                         String implementationName = getImplementationName(collectionType);
 656  81
                         retVal =
 657  
                                 extractFullyQualifiedJavaClassName(implementationPackageName,
 658  
                                         implementationName);
 659  
                 }
 660  98
                 return retVal;
 661  
         }
 662  
 
 663  
         /**
 664  
          * return the list of all the direct parent associated with a types
 665  
          * 
 666  
          * @param collectionType the type
 667  
          * @return the list of parent types
 668  
          */
 669  
         @SuppressWarnings("unchecked")
 670  
         public static List<PropertyCollection<?, ?>> getPropertyCollectionTypeParentList(
 671  
                 PropertyCollection<?, ?> collectionType)
 672  
         {
 673  22
                 return PropertyCollectionTypeImplementation.getParentList(
 674  
                         collectionType).asValueList();
 675  
         }
 676  
 
 677  
         /**
 678  
          * return the ordering property collection type value instance
 679  
          * 
 680  
          * @param collectionType the type
 681  
          * @return the value instance, null if not applicable
 682  
          */
 683  
         @SuppressWarnings("unchecked")
 684  
         public static PropertyCollection<?, ?> getOrderingPropertyCollectionTypeValueInstance(
 685  
                 PropertyCollection<?, ?> collectionType)
 686  
         {
 687  8
                 return OrderingPropertyCollectionTypeImplementation
 688  
                         .getValueInstance(collectionType);
 689  
         }
 690  
 
 691  
         /**
 692  
          * return the ordering property collection type ordering instance
 693  
          * 
 694  
          * @param collectionType the type
 695  
          * @return the ordering instance, null if not applicable
 696  
          */
 697  
         @SuppressWarnings("unchecked")
 698  
         public static PropertyCollection<?, ?> getOrderingPropertyCollectionTypeOrderingInstance(
 699  
                 PropertyCollection<?, ?> collectionType)
 700  
         {
 701  8
                 return OrderingPropertyCollectionTypeImplementation
 702  
                         .getOrderingInstance(collectionType);
 703  
         }
 704  
 
 705  
         /**
 706  
          * return the list of property instance on a type
 707  
          * 
 708  
          * @param collectionType the type
 709  
          * @return the instance list
 710  
          */
 711  
         @SuppressWarnings("unchecked")
 712  
         public static List<PropertyCollection<?, ?>> getPropertyCollectionTypePropertyInstanceList(
 713  
                 PropertyCollection<?, ?> collectionType)
 714  
         {
 715  21
                 return PropertyCollectionTypeImplementation.getPropertyInstanceList(
 716  
                         collectionType).asValueList();
 717  
         }
 718  
 
 719  
         /**
 720  
          * return the Full Property Collection Type Property Collection List
 721  
          * Instance List
 722  
          * 
 723  
          * @param collectionType the type
 724  
          * @return the Property Collection List Instance List
 725  
          */
 726  
         @SuppressWarnings("unchecked")
 727  
         public static List<PropertyCollection<?, ?>> getFullPropertyCollectionTypePropertyCollectionListInstanceList(
 728  
                 PropertyCollection<?, ?> collectionType)
 729  
         {
 730  9
                 return DeductionRuleLibrary
 731  
                         .filter(
 732  
                                 getFullPropertyCollectionTypePropertyInstanceList(collectionType),
 733  
                                 DeductionRuleLibrary.not(DeductionRuleLibrary
 734  
                                         .instanceOf(PropertyCollectionListInstance.PROPERTY_COLLECTION_LIST_INSTANCE_TYPE
 735  
                                                 .getPropertyCollectionType())));
 736  
         }
 737  
 
 738  
         /**
 739  
          * return the Full Property Collection Type Property Instance List
 740  
          * 
 741  
          * @param collectionType the type
 742  
          * @return the Property Instance List
 743  
          */
 744  
         @SuppressWarnings("unchecked")
 745  
         public static List<PropertyCollection<?, ?>> getFullPropertyCollectionTypePropertyInstanceList(
 746  
                 PropertyCollection<?, ?> collectionType)
 747  
         {
 748  22
                 List<PropertyCollection<?, ?>> retVal =
 749  
                         new ArrayList<PropertyCollection<?, ?>>();
 750  
 
 751  22
                 List<PropertyCollection<?, ?>> fullPropertyCollectionTypeParentList =
 752  
                         getFullPropertyCollectionTypeParentList(collectionType);
 753  22
                 for (PropertyCollection<?, ?> currentType : fullPropertyCollectionTypeParentList)
 754  
                 {
 755  58
                         retVal.addAll(PropertyCollectionTypeImplementation
 756  
                                 .getPropertyInstanceList(currentType).asValueList());
 757  
                 }
 758  22
                 return retVal;
 759  
         }
 760  
 
 761  
         /**
 762  
          * This method will get a flat list of all the property collection types in
 763  
          * the parent hierarchy starting from the collectionType specified. No
 764  
          * duplicate types will be included.
 765  
          * 
 766  
          * @param collectionType the starting collection type
 767  
          * @return the list of all the collection types implemented by the current
 768  
          *         type.
 769  
          */
 770  
         public static List<PropertyCollection<?, ?>> getFullPropertyCollectionTypeParentList(
 771  
                 PropertyCollection<?, ?> collectionType)
 772  
         {
 773  24
                 List<PropertyCollection<?, ?>> retVal =
 774  
                         new ArrayList<PropertyCollection<?, ?>>();
 775  24
                 addTypeToList(collectionType, retVal);
 776  24
                 return retVal;
 777  
         }
 778  
 
 779  
         /**
 780  
          * Internal method to recursively add a type to a list of parent
 781  
          * 
 782  
          * @param collectionType they type to add
 783  
          * @param retVal the list to add the new type
 784  
          */
 785  
         private static void addTypeToList(
 786  
                 PropertyCollection<?, ?> collectionType,
 787  
                 List<PropertyCollection<?, ?>> retVal)
 788  
         {
 789  70
                 if (collectionType != null && !retVal.contains(collectionType))
 790  
                 {
 791  67
                         retVal.add(collectionType);
 792  67
                         List<?> parentList =
 793  
                                 PropertyCollectionTypeImplementation.getParentList(
 794  
                                         collectionType).asValueList();
 795  67
                         for (Object object : parentList)
 796  
                         {
 797  46
                                 addTypeToList((PropertyCollection<?, ?>) object, retVal);
 798  
                         }
 799  
                 }
 800  70
         }
 801  
 
 802  
         /**
 803  
          * test to see if the instance is actually a list
 804  
          * 
 805  
          * @param instance the instance
 806  
          * @return true if the instance is a list instance
 807  
          * @throws NullPointerException if the instance is null
 808  
          */
 809  
         public static boolean isListPropertyInstance(
 810  
                 PropertyCollection<?, ?> instance)
 811  
         {
 812  151
                 return DeducedUtilities
 813  
                         .isInstanceOf(
 814  
                                 instance.type(),
 815  
                                 PropertyCollectionListInstance.PROPERTY_COLLECTION_LIST_INSTANCE_TYPE
 816  
                                         .getPropertyCollectionType());
 817  
         }
 818  
 
 819  
         /**
 820  
          * get the variable name for the instance holder
 821  
          * 
 822  
          * @param instance the property instance
 823  
          * @return the property instance holder variable name
 824  
          */
 825  
         public static String getInstanceHolderVariableName(
 826  
                 PropertyCollection<?, ?> instance)
 827  
         {
 828  238
                 if (instance == null)
 829  
                 {
 830  1
                         return null;
 831  
                 }
 832  237
                 return getStaticVariableName(DeducedUtilities
 833  
                         .getCollectionName(instance) + INSTANCE_SUFFIX);
 834  
         }
 835  
 
 836  
         /**
 837  
          * get the variable name for the enumeration holder
 838  
          * 
 839  
          * @param instance the enumeration
 840  
          * @return the enumeration holder variable name
 841  
          */
 842  
         public static String getEnumerationHolderVariableName(
 843  
                 PropertyCollection<?, ?> instance)
 844  
         {
 845  0
                 if (instance == null)
 846  
                 {
 847  0
                         return null;
 848  
                 }
 849  0
                 return getStaticVariableName(DeducedUtilities
 850  
                         .getCollectionName(instance) + LITERAL_SUFFIX);
 851  
         }
 852  
 
 853  
         /**
 854  
          * get the instance member variable name
 855  
          * 
 856  
          * @param instance the instance
 857  
          * @return the instance member variable name
 858  
          */
 859  
         public static String getInstanceMemberVariableName(
 860  
                 PropertyCollection<?, ?> instance)
 861  
         {
 862  187
                 return getMemberName(DeducedUtilities.getCollectionName(instance));
 863  
         }
 864  
 
 865  
         /**
 866  
          * adjust a String to match the format required for
 867  
          * 
 868  
          * @param memberNameToAdjust the method name to adjust
 869  
          * @return the member name
 870  
          */
 871  
         public static String getMemberName(
 872  
                 String memberNameToAdjust)
 873  
         {
 874  190
                 return MEMBER_NAME_ADJUSTER.adjustString(memberNameToAdjust);
 875  
         }
 876  
 
 877  
         /**
 878  
          * get the fully qualified instance type name. If the type of the instance
 879  
          * is a basic type and the value can't be null, then a basic java type name
 880  
          * will be returned instead of the object wrapper. For property collection
 881  
          * types, the interface name is returned. For lists, an abstract
 882  
          * PropertyList will be used.
 883  
          * 
 884  
          * @param instance the property instance
 885  
          * @return the fully qualified instance type name
 886  
          */
 887  
         public static String getFullyQualifiedInstanceTypeName(
 888  
                 PropertyCollection<?, ?> instance)
 889  
         {
 890  129
                 PropertyCollection<?, ?> type =
 891  
                         PropertyInstanceImplementation.getInstanceType(instance);
 892  
 
 893  129
                 if (isInstanceTypeNative(instance))
 894  
                 {
 895  
                         // found basic non-nullable type
 896  1
                         Class<?> classFromType = BasicTypes.getNativeClassFromType(type);
 897  1
                         return classFromType.getCanonicalName();
 898  
                 }
 899  
 
 900  128
                 return getFullyQualifiedTypeName(type);
 901  
         }
 902  
 
 903  
         /**
 904  
          * check if the instance variable will be using a native type. Only
 905  
          * instances that reference a possibly native type that can't be set to null
 906  
          * will return true.
 907  
          * 
 908  
          * @param instance the property instance
 909  
          * @return true if the instance requires a native type
 910  
          */
 911  
         public static boolean isInstanceTypeNative(
 912  
                 PropertyCollection<?, ?> instance)
 913  
         {
 914  282
                 PropertyCollection<?, ?> propertyInstanceValidationModel =
 915  
                         PropertyInstanceImplementation.getValidationModel(instance);
 916  282
                 PropertyCollection<?, ?> type =
 917  
                         PropertyInstanceImplementation.getInstanceType(instance);
 918  282
                 Object nullValidKey =
 919  
                         NullableValidationModel.IS_NULL_VALID_INSTANCE.getKey();
 920  
 
 921  282
                 if (propertyInstanceValidationModel != null
 922  
                         && propertyInstanceValidationModel.containsKey(nullValidKey))
 923  
                 {
 924  58
                         Boolean isNullValid =
 925  
                                 (Boolean) propertyInstanceValidationModel
 926  
                                         .getPropertyValue(nullValidKey);
 927  
 
 928  58
                         if (isNullValid != null && !isNullValid.booleanValue())
 929  
                         {
 930  54
                                 return BasicTypes.isTypeNative(type);
 931  
                         }
 932  
                 }
 933  
 
 934  228
                 return false;
 935  
         }
 936  
 
 937  
         /**
 938  
          * debug
 939  
          * 
 940  
          * @param print string to print
 941  
          */
 942  
         public static void debug(
 943  
                 String print)
 944  
         {
 945  6
                 if (LOGGER.isLoggable(Level.FINEST))
 946  
                 {
 947  2
                         LOGGER.log(Level.FINEST, "Debug : " + print);
 948  
                 }
 949  6
         }
 950  
 
 951  
         /**
 952  
          * get the fully qualified type name. For property collection types, the
 953  
          * interface name is returned. For lists, an abstract PropertyList will be
 954  
          * used.
 955  
          * 
 956  
          * @param type the property type
 957  
          * @return the fully qualified type name
 958  
          */
 959  
         public static String getFullyQualifiedTypeName(
 960  
                 PropertyCollection<?, ?> type)
 961  
         {
 962  225
                 String returnValue = null;
 963  225
                 if (type.type() == PropertyType.PROPERTY_TYPE_TYPE
 964  
                         .getPropertyCollectionType())
 965  
                 {
 966  57
                         Class<?> classFromType = BasicTypes.getClassFromType(type);
 967  57
                         returnValue = classFromType.getCanonicalName();
 968  57
                 }
 969  160
                 else if (type == PropertyList.PROPERTY_LIST_TYPE
 970  
                         .getPropertyCollectionType())
 971  
                 {
 972  115
                         returnValue = PropertyList.class.getCanonicalName();
 973  
                 }
 974  45
                 else if (type == PropertyList.PROPERTY_COLLECTION_TYPE
 975  
                         .getPropertyCollectionType())
 976  
                 {
 977  3
                         returnValue = PropertyCollection.class.getCanonicalName();
 978  
                 }
 979  
                 else
 980  
                 {
 981  42
                         returnValue = getFullyQualifiedTypeInterfaceName(type);
 982  
                 }
 983  217
                 return returnValue;
 984  
         }
 985  
 
 986  
         /**
 987  
          * getPropertyInstanceInstanceType
 988  
          * 
 989  
          * @param instance the property instance
 990  
          * @return the instance type
 991  
          */
 992  
         public static PropertyCollection<?, ?> getPropertyInstanceInstanceType(
 993  
                 PropertyCollection<?, ?> instance)
 994  
         {
 995  136
                 return PropertyInstanceImplementation.getInstanceType(instance);
 996  
         }
 997  
 
 998  
         /**
 999  
          * get OrderedPropertyListType OrderingType
 1000  
          * 
 1001  
          * @param type the potential ordered property list type
 1002  
          * @return the ordering type
 1003  
          */
 1004  
         public static PropertyCollection<?, ?> getOrderedPropertyListTypeOrderingType(
 1005  
                 PropertyCollection<?, ?> type)
 1006  
         {
 1007  0
                 return OrderedPropertyListTypeImplementation.getOrderingType(type);
 1008  
         }
 1009  
 
 1010  
         /**
 1011  
          * get PropertyInstance IsReference
 1012  
          * 
 1013  
          * @param instance the property instance
 1014  
          * @return the reference flag
 1015  
          */
 1016  
         public static Boolean getPropertyInstanceIsReference(
 1017  
                 PropertyCollection<?, ?> instance)
 1018  
         {
 1019  144
                 return PropertyInstanceImplementation.isReference(instance);
 1020  
         }
 1021  
 
 1022  
         /**
 1023  
          * get PropertyCollectionListInstance ListFixedInstance
 1024  
          * 
 1025  
          * @param instance the property collection list instance
 1026  
          * @return the list fixed instance
 1027  
          */
 1028  
         public static PropertyCollection<?, ?> getPropertyCollectionListInstanceListFixedInstance(
 1029  
                 PropertyCollection<?, ?> instance)
 1030  
         {
 1031  16
                 return PropertyCollectionListInstanceImplementation
 1032  
                         .getListFixedInstance(instance);
 1033  
         }
 1034  
 
 1035  
         /**
 1036  
          * get EnumerationPropertyType EnumerationLiteralList
 1037  
          * 
 1038  
          * @param instance the property collection list instance
 1039  
          * @return the Enumeration Literal List
 1040  
          */
 1041  
         @SuppressWarnings("unchecked")
 1042  
         public static List<PropertyCollection<?, ?>> getEnumerationPropertyTypeEnumerationLiteralList(
 1043  
                 PropertyCollection<?, ?> instance)
 1044  
         {
 1045  20
                 PropertyCollection enumerationLiteralList =
 1046  
                         EnumerationPropertyTypeImplementation
 1047  
                                 .getEnumerationLiteralList(instance);
 1048  
 
 1049  20
                 if (enumerationLiteralList != null)
 1050  
                 {
 1051  0
                         return enumerationLiteralList.asValueList();
 1052  
                 }
 1053  
 
 1054  20
                 return new LinkedList<PropertyCollection<?, ?>>();
 1055  
         }
 1056  
 
 1057  
         /**
 1058  
          * get DeducedSchemaLayer RootPackage
 1059  
          * 
 1060  
          * @param instance the schema layer
 1061  
          * @return the root package
 1062  
          */
 1063  
         public static PropertyCollection<?, ?> getDeducedSchemaLayerRootPackage(
 1064  
                 PropertyCollection<?, ?> instance)
 1065  
         {
 1066  14
                 return DeducedSchemaLayerImplementation.getRootPackage(instance);
 1067  
         }
 1068  
 
 1069  
         /**
 1070  
          * get PropertyPackage PropertyPackageList
 1071  
          * 
 1072  
          * @param instance the package
 1073  
          * @return the package list
 1074  
          */
 1075  
         public static PropertyCollection<?, ?> getPropertyPackagePropertyPackageList(
 1076  
                 PropertyCollection<?, ?> instance)
 1077  
         {
 1078  20
                 return PropertyPackageImplementation.getPropertyPackageList(instance);
 1079  
         }
 1080  
 
 1081  
         /**
 1082  
          * get PropertyPackage PropertyTypeList
 1083  
          * 
 1084  
          * @param instance the package
 1085  
          * @return the type list
 1086  
          */
 1087  
         public static PropertyCollection<?, ?> getPropertyPackagePropertyTypeList(
 1088  
                 PropertyCollection<?, ?> instance)
 1089  
         {
 1090  20
                 return PropertyPackageImplementation.getPropertyTypeList(instance);
 1091  
         }
 1092  
 
 1093  
         /**
 1094  
          * get the string required to type cast a java.lang.Object to the required
 1095  
          * object type. This method will return an empty string if the type is
 1096  
          * already a java.lang.Object. For instance, for a
 1097  
          * deduced.PropertyCollection, this method will return the string
 1098  
          * "(deduced.PropertyCollection)"
 1099  
          * 
 1100  
          * @param type the type to cast the java.lang.Object from
 1101  
          * @return the cast string
 1102  
          */
 1103  
         public static String getTypeCastString(
 1104  
                 PropertyCollection<?, ?> type)
 1105  
         {
 1106  31
                 if (type == BasicTypes.OBJECT_TYPE.getPropertyType())
 1107  
                 {
 1108  1
                         return "";
 1109  
                 }
 1110  
 
 1111  30
                 return "(" + getFullyQualifiedTypeName(type) + ")";
 1112  
         }
 1113  
 
 1114  
         /**
 1115  
          * fetch the instance getter method name. Getter on boolean values will
 1116  
          * always be prefixed by "is". For instance, the getter on a boolean
 1117  
          * property called "boolean type allowed" will return
 1118  
          * "isBooleanTypeAllowed". For other types, the "get" prefix will be used
 1119  
          * such as "getBooleanTypeAllowed".
 1120  
          * 
 1121  
          * @param instance the instance
 1122  
          * @return the getter method name
 1123  
          */
 1124  
         public static String getInstanceGetterMethodName(
 1125  
                 PropertyCollection<?, ?> instance)
 1126  
         {
 1127  85
                 String prefix = GETTER_PREFIX;
 1128  85
                 PropertyCollection<?, ?> propertyInstanceInstanceType =
 1129  
                         PropertyInstanceImplementation.getInstanceType(instance);
 1130  85
                 String collectionName = DeducedUtilities.getCollectionName(instance);
 1131  
 
 1132  85
                 if (propertyInstanceInstanceType == BasicTypes.BOOLEAN_TYPE
 1133  
                         .getPropertyType())
 1134  
                 {
 1135  4
                         if (collectionName.toLowerCase().startsWith("is"))
 1136  
                         {
 1137  2
                                 prefix = "";
 1138  
                         }
 1139  
                         else
 1140  
                         {
 1141  2
                                 prefix = BOOLEAN_GETTER_PREFIX;
 1142  
                         }
 1143  
                 }
 1144  
 
 1145  85
                 return getMethodName(prefix + collectionName);
 1146  
         }
 1147  
 
 1148  
         /**
 1149  
          * fetch the instance setter method name. For instance, the setter on a
 1150  
          * boolean property called "boolean type allowed" will return
 1151  
          * "setBooleanTypeAllowed".
 1152  
          * 
 1153  
          * @param instance the instance
 1154  
          * @return the setter method name
 1155  
          */
 1156  
         public static String getInstanceSetterMethodName(
 1157  
                 PropertyCollection<?, ?> instance)
 1158  
         {
 1159  122
                 return getMethodName(SETTER_PREFIX
 1160  
                         + DeducedUtilities.getCollectionName(instance));
 1161  
         }
 1162  
 
 1163  
         /**
 1164  
          * get the package name for a property type implementation
 1165  
          * 
 1166  
          * @param type the property type
 1167  
          * @return the package name. For instance, the package name for
 1168  
          *         deduced.Property Collection Type will be "deduced.implementation"
 1169  
          */
 1170  
         public static String getImplementationPackageName(
 1171  
                 PropertyCollection<?, ?> type)
 1172  
         {
 1173  107
                 return getInterfacePackageName(type) + ".implementation";
 1174  
         }
 1175  
 
 1176  
         /**
 1177  
          * get the property collection type that owns a property instance
 1178  
          * 
 1179  
          * @param instance the property instance
 1180  
          * @return the property collection type that owns the instance
 1181  
          */
 1182  
         public static PropertyCollection<?, ?> getPropertyInstanceParentPropertyCollectionType(
 1183  
                 PropertyCollection<?, ?> instance)
 1184  
         {
 1185  27
                 PropertyCollection<?, ?> parent = instance;
 1186  27
                 PropertyCollectionType propertyCollectionType =
 1187  
                         PropertyCollectionType.PROPERTY_COLLECTION_TYPE_TYPE
 1188  
                                 .getPropertyCollectionType();
 1189  
                 while (parent != null
 1190  82
                         && !DeducedUtilities.isInstanceOf(parent.type(),
 1191  
                                 propertyCollectionType))
 1192  
                 {
 1193  55
                         parent = parent.parent();
 1194  
                 }
 1195  27
                 return parent;
 1196  
         }
 1197  
 
 1198  
         /**
 1199  
          * get the java interface file name
 1200  
          * 
 1201  
          * @param type the property collection type
 1202  
          * @return the interface file name
 1203  
          */
 1204  
         public static String getInterfaceFileName(
 1205  
                 PropertyCollection<?, ?> type)
 1206  
         {
 1207  13
                 return getInterfaceName(type) + ".java";
 1208  
         }
 1209  
 
 1210  
         /**
 1211  
          * get the java implementation file name
 1212  
          * 
 1213  
          * @param type the property collection type
 1214  
          * @return the implementation file name
 1215  
          */
 1216  
         public static String getImplementationFileName(
 1217  
                 PropertyCollection<?, ?> type)
 1218  
         {
 1219  13
                 return getImplementationName(type) + ".java";
 1220  
         }
 1221  
 
 1222  
         /**
 1223  
          * get the java interface folder name
 1224  
          * 
 1225  
          * @param type the property collection type
 1226  
          * @return the interface folder name
 1227  
          */
 1228  
         public static String getInterfaceFolderName(
 1229  
                 PropertyCollection<?, ?> type)
 1230  
         {
 1231  13
                 return getFolderNameFromPackageName(getInterfacePackageName(type));
 1232  
         }
 1233  
 
 1234  
         /**
 1235  
          * get the java implementation folder name
 1236  
          * 
 1237  
          * @param type the property collection type
 1238  
          * @return the implementation folder name
 1239  
          */
 1240  
         public static String getImplementationFolderName(
 1241  
                 PropertyCollection<?, ?> type)
 1242  
         {
 1243  
 
 1244  13
                 return getFolderNameFromPackageName(getImplementationPackageName(type));
 1245  
         }
 1246  
 
 1247  
         /**
 1248  
          * get a folder name based on a package name
 1249  
          * 
 1250  
          * @param packageName the package name
 1251  
          * @return the folder name
 1252  
          */
 1253  
         public static String getFolderNameFromPackageName(
 1254  
                 String packageName)
 1255  
         {
 1256  27
                 return packageName.replace(PACKAGE_SEPARATOR,
 1257  
                         FileUtilities.FOLDER_SEPARATOR);
 1258  
         }
 1259  
 
 1260  
         /**
 1261  
          * get the name of a type holder
 1262  
          * 
 1263  
          * @param type the type to refer to
 1264  
          * @return the fully qualified type holder name
 1265  
          */
 1266  
         public static String getFullyQualifiedTypeHolderName(
 1267  
                 PropertyCollection<?, ?> type)
 1268  
         {
 1269  106
                 String retVal = null;
 1270  106
                 if (type.type() == PropertyType.PROPERTY_TYPE_TYPE
 1271  
                         .getPropertyCollectionType())
 1272  
                 {
 1273  
                         // basic type found
 1274  12
                         String typeName = DeducedUtilities.getCollectionName(type);
 1275  12
                         String holderName =
 1276  
                                 STATIC_NAME_ADJUSTER.adjustString(typeName + TYPE_SUFFIX);
 1277  12
                         retVal = "org.deduced.BasicTypes." + holderName;
 1278  12
                 }
 1279  94
                 else if (type == PropertyMap.PROPERTY_MAP_TYPE.getPropertyType())
 1280  
                 {
 1281  1
                         retVal = "org.deduced.PropertyMap.PROPERTY_MAP_TYPE";
 1282  
                 }
 1283  93
                 else if (type == PropertyList.PROPERTY_LIST_TYPE.getPropertyType())
 1284  
                 {
 1285  33
                         retVal = "org.deduced.PropertyList.PROPERTY_LIST_TYPE";
 1286  
                 }
 1287  
                 else
 1288  
                 {
 1289  60
                         String interfaceName = getFullyQualifiedTypeInterfaceName(type);
 1290  60
                         String typeHolder = getInterfaceTypeHolderName(type);
 1291  60
                         retVal = interfaceName + PACKAGE_SEPARATOR + typeHolder;
 1292  
                 }
 1293  106
                 return retVal;
 1294  
         }
 1295  
 
 1296  
         /**
 1297  
          * get all the property collection type in a schema
 1298  
          * 
 1299  
          * @param schema the schema
 1300  
          * @return the list of property collection type
 1301  
          */
 1302  
         public static List<PropertyCollection<?, ?>> getPropertyCollectionTypeListFromSchema(
 1303  
                 PropertyCollection<?, ?> schema)
 1304  
         {
 1305  27
                 PropertyCollection<?, ?> rootPackage =
 1306  
                         (PropertyCollection<?, ?>) schema
 1307  
                                 .getPropertyValue(DeducedSchemaLayer.ROOT_PACKAGE_INSTANCE
 1308  
                                         .getKey());
 1309  
 
 1310  27
                 List<PropertyCollection<?, ?>> packageList =
 1311  
                         getRecursivePackageListFromPackage(rootPackage);
 1312  
 
 1313  27
                 List<PropertyCollection<?, ?>> retVal =
 1314  
                         new ArrayList<PropertyCollection<?, ?>>();
 1315  
 
 1316  27
                 for (PropertyCollection<?, ?> currentPackage : packageList)
 1317  
                 {
 1318  35
                         retVal
 1319  
                                 .addAll(getPropertyCollectionTypeListFromPackage(currentPackage));
 1320  
                 }
 1321  
 
 1322  27
                 return retVal;
 1323  
         }
 1324  
 
 1325  
         /**
 1326  
          * get the list of property collection type from a package
 1327  
          * 
 1328  
          * @param propertyPackage the package
 1329  
          * @return the list of property collection type
 1330  
          */
 1331  
         public static List<PropertyCollection<?, ?>> getPropertyCollectionTypeListFromPackage(
 1332  
                 PropertyCollection<?, ?> propertyPackage)
 1333  
         {
 1334  39
                 List<PropertyCollection<?, ?>> retVal =
 1335  
                         new ArrayList<PropertyCollection<?, ?>>();
 1336  
 
 1337  39
                 if (propertyPackage != null)
 1338  
                 {
 1339  39
                         PropertyCollection<?, ?> propertyPackagePropertyTypeList =
 1340  
                                 PropertyPackageImplementation
 1341  
                                         .getPropertyTypeList(propertyPackage);
 1342  
 
 1343  39
                         if (propertyPackagePropertyTypeList != null)
 1344  
                         {
 1345  39
                                 List<?> typeList =
 1346  
                                         propertyPackagePropertyTypeList.asValueList();
 1347  39
                                 for (Object object : typeList)
 1348  
                                 {
 1349  29
                                         PropertyCollection<?, ?> type =
 1350  
                                                 (PropertyCollection<?, ?>) object;
 1351  
 
 1352  29
                                         if (DeducedUtilities.isTypeCollection(type.type()))
 1353  
                                         {
 1354  25
                                                 retVal.add(type);
 1355  
                                         }
 1356  29
                                 }
 1357  
                         }
 1358  
                 }
 1359  
 
 1360  39
                 return retVal;
 1361  
         }
 1362  
 
 1363  
         /**
 1364  
          * get the recursive list of package from the specified package
 1365  
          * 
 1366  
          * @param propertyPackage the starting package
 1367  
          * @return the list of all the packages in the hierarchy, including the
 1368  
          *         starting package
 1369  
          */
 1370  
         public static List<PropertyCollection<?, ?>> getRecursivePackageListFromPackage(
 1371  
                 PropertyCollection<?, ?> propertyPackage)
 1372  
         {
 1373  43
                 List<PropertyCollection<?, ?>> retVal =
 1374  
                         new ArrayList<PropertyCollection<?, ?>>();
 1375  
 
 1376  43
                 internalGetRecursivePackageListFromPackage(propertyPackage, retVal);
 1377  
 
 1378  43
                 return retVal;
 1379  
         }
 1380  
 
 1381  
         /**
 1382  
          * internal method used recursively to browse a property package and add all
 1383  
          * it's child packages to the specified list
 1384  
          * 
 1385  
          * @param propertyPackage the specified package to recursively inspect
 1386  
          * @param retVal the list in which to add the child packages
 1387  
          */
 1388  
         private static void internalGetRecursivePackageListFromPackage(
 1389  
                 PropertyCollection<?, ?> propertyPackage,
 1390  
                 List<PropertyCollection<?, ?>> retVal)
 1391  
         {
 1392  68
                 if (propertyPackage != null)
 1393  
                 {
 1394  61
                         retVal.add(propertyPackage);
 1395  
 
 1396  61
                         PropertyCollection<?, ?> propertyPackagePropertyPackageList =
 1397  
                                 DeducedUtilities
 1398  
                                         .getPropertyPackagePropertyPackageList(propertyPackage);
 1399  
 
 1400  61
                         if (propertyPackagePropertyPackageList != null)
 1401  
                         {
 1402  61
                                 List<?> packageList =
 1403  
                                         propertyPackagePropertyPackageList.asValueList();
 1404  61
                                 for (Object object : packageList)
 1405  
                                 {
 1406  25
                                         internalGetRecursivePackageListFromPackage(
 1407  
                                                 (PropertyCollection<?, ?>) object, retVal);
 1408  
                                 }
 1409  
                         }
 1410  
                 }
 1411  68
         }
 1412  
 
 1413  
         /**
 1414  
          * get Schema Xml File Name
 1415  
          * 
 1416  
          * @param schemaName the schema name
 1417  
          * @return the schema xml file name with path
 1418  
          */
 1419  
         public static String getSchemaXmlFileName(
 1420  
                 String schemaName)
 1421  
         {
 1422  14
                 String retVal = getFullyQualifiedSchemaClassName(schemaName);
 1423  14
                 retVal = retVal.replace('.', '/');
 1424  14
                 retVal += ".xml";
 1425  14
                 return retVal;
 1426  
         }
 1427  
 
 1428  
         /**
 1429  
          * format a string so it can be printed in a java file
 1430  
          * 
 1431  
          * @param value the string to print
 1432  
          * @return the java file value
 1433  
          */
 1434  
         public static String getJavaString(
 1435  
                 String value)
 1436  
         {
 1437  77
                 if (value == null)
 1438  
                 {
 1439  17
                         return "null";
 1440  
                 }
 1441  
 
 1442  60
                 String retVal = StringEscapeUtils.escapeJava(value);
 1443  
 
 1444  60
                 retVal = "\"" + retVal + "\"";
 1445  60
                 return retVal;
 1446  
         }
 1447  
 
 1448  
         /**
 1449  
          * get the list of dependent schema
 1450  
          * 
 1451  
          * @param schema the schema from which to extract the dependent schema list
 1452  
          * @return the dependent schema list
 1453  
          */
 1454  
         @SuppressWarnings("unchecked")
 1455  
         public static List<PropertyCollection<?, ?>> getDependentSchemaList(
 1456  
                 PropertyCollection<?, ?> schema)
 1457  
         {
 1458  28
                 PropertyCollection<?, ?> dependentSchemaList =
 1459  
                         (PropertyCollection<?, ?>) schema
 1460  
                                 .getPropertyValue(DeducedSchemaLayer.DEPENDENT_SCHEMA_LIST_INSTANCE
 1461  
                                         .getKey());
 1462  
 
 1463  28
                 return (List<PropertyCollection<?, ?>>) dependentSchemaList
 1464  
                         .asValueList();
 1465  
         }
 1466  
 
 1467  
         /**
 1468  
          * get the list of schema from a model
 1469  
          * 
 1470  
          * @param model the model from which to extract the schema list
 1471  
          * @return the schema list
 1472  
          */
 1473  
         @SuppressWarnings("unchecked")
 1474  
         public static List<PropertyCollection<?, ?>> getModelSchemaList(
 1475  
                 PropertyCollection<?, ?> model)
 1476  
         {
 1477  14
                 PropertyCollection<?, ?> schemaList =
 1478  
                         (PropertyCollection<?, ?>) model
 1479  
                                 .getPropertyValue(DeducedModelLayer.SCHEMA_LIST_INSTANCE
 1480  
                                         .getKey());
 1481  
 
 1482  14
                 return (List<PropertyCollection<?, ?>>) schemaList.asValueList();
 1483  
         }
 1484  
 
 1485  
         /**
 1486  
          * remove the property list type from a type list
 1487  
          * 
 1488  
          * @param typeList the type list from which to remove the property list type
 1489  
          * @return the filtered type list
 1490  
          */
 1491  
         @SuppressWarnings("unchecked")
 1492  
         public static List<PropertyCollection<?, ?>> removePropertyListTypeFromList(
 1493  
                 List<PropertyCollection<?, ?>> typeList)
 1494  
         {
 1495  0
                 List<PropertyCollection<?, ?>> retVal =
 1496  
                         new ArrayList<PropertyCollection<?, ?>>(typeList);
 1497  
 
 1498  0
                 retVal.remove(PropertyList.PROPERTY_LIST_TYPE
 1499  
                         .getPropertyCollectionType());
 1500  
 
 1501  0
                 return retVal;
 1502  
         }
 1503  
 
 1504  
         /**
 1505  
          * get Holder Class Name
 1506  
          * 
 1507  
          * @param objectToHold the object to hold
 1508  
          * @return the object holder class name
 1509  
          */
 1510  
         public static String getHolderClassName(
 1511  
                 PropertyCollection<?, ?> objectToHold)
 1512  
         {
 1513  20
                 if (objectToHold == null)
 1514  
                 {
 1515  1
                         return null;
 1516  
                 }
 1517  
 
 1518  19
                 PropertyCollection<?, ?> type = objectToHold.type();
 1519  
 
 1520  19
                 String retVal = null;
 1521  
 
 1522  19
                 if (DeducedUtilities.isInstanceOf(type,
 1523  
                         OrderedPropertyListType.ORDERED_PROPERTY_LIST_TYPE_TYPE
 1524  
                                 .getPropertyCollectionType()))
 1525  
                 {
 1526  1
                         retVal = OrderedPropertyListTypeHolder.class.getName();
 1527  
                 }
 1528  18
                 else if (DeducedUtilities
 1529  
                         .isInstanceOf(
 1530  
                                 type,
 1531  
                                 OrderingPropertyCollectionType.ORDERING_PROPERTY_COLLECTION_TYPE_TYPE
 1532  
                                         .getPropertyCollectionType()))
 1533  
                 {
 1534  1
                         retVal = OrderingPropertyCollectionTypeHolder.class.getName();
 1535  
                 }
 1536  17
                 else if (DeducedUtilities.isInstanceOf(type,
 1537  
                         PropertyCollectionType.PROPERTY_COLLECTION_TYPE_TYPE
 1538  
                                 .getPropertyCollectionType()))
 1539  
                 {
 1540  13
                         retVal = PropertyCollectionTypeHolder.class.getName();
 1541  
                 }
 1542  4
                 else if (DeducedUtilities.isInstanceOf(type,
 1543  
                         PropertyType.PROPERTY_TYPE_TYPE.getPropertyCollectionType()))
 1544  
                 {
 1545  1
                         retVal = PropertyTypeHolder.class.getName();
 1546  
                 }
 1547  3
                 else if (DeducedUtilities
 1548  
                         .isInstanceOf(
 1549  
                                 type,
 1550  
                                 PropertyCollectionListInstance.PROPERTY_COLLECTION_LIST_INSTANCE_TYPE
 1551  
                                         .getPropertyCollectionType()))
 1552  
                 {
 1553  1
                         retVal = PropertyCollectionListInstanceHolder.class.getName();
 1554  
                 }
 1555  2
                 else if (DeducedUtilities
 1556  
                         .isInstanceOf(type, PropertyInstance.PROPERTY_INSTANCE_TYPE
 1557  
                                 .getPropertyCollectionType()))
 1558  
                 {
 1559  1
                         retVal = PropertyInstanceHolder.class.getName();
 1560  
                 }
 1561  
 
 1562  19
                 return retVal;
 1563  
         }
 1564  
 
 1565  
 }