예제 #1
0
  /**
   * INTERNAL: For this Type generate classes
   *
   * @param packageName
   * @param nr
   */
  public void preInitialize(String packageName, List namespaceResolvers) {
    String instanceClassName = getInstanceClassName();
    if (null == instanceClassName) {
      if (null == packageName) {
        String uri = getURI();
        if (null == uri) {
          packageName = SDOUtil.getDefaultPackageName() + SDOConstants.JAVA_PACKAGE_NAME_SEPARATOR;
        } else {
          packageName =
              SDOUtil.getPackageNameFromURI(uri) + SDOConstants.JAVA_PACKAGE_NAME_SEPARATOR;
        }
      }

      // Verify and fix any Class name that does not conform to conventions
      // run the class name through the JAXB mangler
      String mangledClassName = SDOUtil.className(getName(), false, true, true);

      // we will not fix any type collision at this time as a result of class renaming
      // write fully qualified java class name
      StringBuffer fullClassName = new StringBuffer(packageName);
      fullClassName.append(mangledClassName);
      setInstanceClassName(fullClassName.toString());
    }
    AbstractSessionLog.getLog()
        .log(
            AbstractSessionLog.FINER, //
            "sdo_type_generation_processing_type", //
            new Object[] {Helper.getShortClassName(getClass()), getInstanceClassName()});

    initializeNamespaces(namespaceResolvers);
    getXmlDescriptor().setJavaClassName(getImplClassName());

    // See SDOResolvable enhancement
    String schemaContext = getName();
    if (getXmlDescriptor().getNamespaceResolver() != null) {
      String prefix = getXmlDescriptor().getNamespaceResolver().resolveNamespaceURI(getURI());
      if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) {
        schemaContext = prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + schemaContext;
      }
    }
    String schemaContextWithSlash = SDOConstants.SDO_XPATH_SEPARATOR_FRAGMENT + schemaContext;

    XMLSchemaReference schemaRef = new XMLSchemaClassPathReference();
    schemaRef.setSchemaContext(schemaContextWithSlash);
    schemaRef.setType(XMLSchemaReference.COMPLEX_TYPE);
    getXmlDescriptor().setSchemaReference(schemaRef);
  }
예제 #2
0
 /** Verify that the class is a valid instance class. */
 private boolean isValidInstanceClass(Class clazz) {
   if (isDataType) {
     return true;
   }
   if (!clazz.isInterface()) {
     return false;
   }
   for (Object object : this.getDeclaredProperties()) {
     SDOProperty sdoProperty = (SDOProperty) object;
     SDOType sdoPropertyType = sdoProperty.getType();
     if (!sdoPropertyType.isChangeSummaryType()) {
       String javaType = SDOUtil.getJavaTypeForProperty(sdoProperty);
       try {
         // Verify get method
         String getMethodName = SDOUtil.getMethodName(sdoProperty.getName(), javaType);
         PrivilegedAccessHelper.getPublicMethod(clazz, getMethodName, EMPTY_CLASS_ARRAY, false);
       } catch (NoSuchMethodException e) {
         // if the method isn't found and the type is boolean try looking for a "get" method
         // instead of an "is" method
         if (sdoPropertyType == SDOConstants.SDO_BOOLEAN
             || sdoPropertyType == SDOConstants.SDO_BOOLEANOBJECT) {
           try {
             String booleanGetterMethodName =
                 SDOUtil.getBooleanGetMethodName(sdoProperty.getName(), javaType);
             PrivilegedAccessHelper.getPublicMethod(
                 clazz, booleanGetterMethodName, EMPTY_CLASS_ARRAY, false);
           } catch (NoSuchMethodException e2) {
             return false;
           }
         } else {
           return false;
         }
       }
     }
   }
   return true;
 }