Package org.dmd.util.exceptions

Examples of org.dmd.util.exceptions.ResultException


                 
//                  DebugInfo.debug(this.getJavaClass());
        }
            }
            catch(Exception e){
              ResultException ex = new ResultException(e);
              ex.result.addResult(Result.FATAL,"Couldn't load Java class: " + this.getJavaClass());
                ex.result.lastResult().moreMessages(e.getMessage());
                ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
                throw(ex);
            }
        }

        if (genobjclass != null){
          if (this.getClassType() == ClassTypeEnum.ABSTRACT){
              ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Can't instantiate an ABSTRACT class: " + this.getObjectName());
                throw(ex);
            }
            else{
                try{
//                    rc = (DmwWrapperBase) genobjclass.newInstance();
                    rc = (DmwWrapper) genobjclass.newInstance();
                }
                catch(Exception e){
                  ResultException ex = new ResultException(e);
                  ex.result.addResult(Result.FATAL,"Couldn't instantiate Java class: " + this.getJavaClass());
                  ex.result.lastResult().moreMessages("This may be because the class doesn't have a constructor that takes no arguments.");
                  ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
                  throw(ex);
                }
View Full Code Here


//                 
//                  DebugInfo.debug(DebugInfo.getCurrentStack());
        }
            }
            catch(Exception e){
              ResultException ex = new ResultException();
              ex.result.addResult(Result.FATAL,"Couldn't load Java class: " + this.getJavaClass());
                ex.result.lastResult().moreMessages(e.getMessage());
                ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
                throw(ex);
            }
        }

        if (dmoClass != null){
          if (this.getClassType() == ClassTypeEnum.ABSTRACT){
              ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Can't instantiate an ABSTRACT class: " + this.getObjectName());
                throw(ex);
            }
            else{
                try{
                    rc = (DmcObject) dmoClass.newInstance();
                }
                catch(Exception e){
                  ResultException ex = new ResultException();
                  ex.result.addResult(Result.FATAL,"Couldn't instantiate Java class: " + this.getJavaClass());
                  ex.result.lastResult().moreMessages("This may be because the class doesn't have a constructor that takes no arguments.");
                  ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
                  throw(ex);
                }
View Full Code Here

     * @param imports where we'll add the required imports.
     * @param uco the rule data object.
     * @throws ResultException
     */
    public void addImportsForAdditionalAttributes(SchemaManager sm, ImportManager imports, DmcUncheckedObject uco) throws ResultException{
      ResultException ex = null;
     
      Iterator<String> attrNames = uco.getAttributeNames();
      if (attrNames != null){
        while(attrNames.hasNext()){
          String    name = attrNames.next();
          StringName   attr = new StringName(name);
          if (!isAllowedAttribute(attr)){
            if (getClassType() == ClassTypeEnum.EXTENSIBLE){
              // Add the appropriate import for the attribute's type
              AttributeDefinition ad = sm.isAttribute(name);
             
              if (ad == null){
                  if (ex == null)
                    ex = new ResultException();
                  ex.addError("The " + attr + " attribute is not defined, but used in " + uco.getConstructionClass());
                  setExceptionLocation(ex,uco);
              }
              else
                imports.addImport(ad.getTypeImport(), "Support for addition of " + name + " values to the extensible " + uco.getConstructionClass() + " class");
            }
            else{
              if (ex == null)
                ex = new ResultException();
              ex.addError("The " + attr + " attribute is not valid for class " + uco.getConstructionClass());
              setExceptionLocation(ex,uco);
            }
          }
        }
      }
View Full Code Here

//   
//    return(root);
//  }
 
  void resolveReferences() throws ResultException {
    ResultException  errors  = null;
    for(HierarchicObject ho : cache.data.values()){
      DebugInfo.debug(ho.getFQN().getNameString())
      try {
        ho.resolveReferences(this);
       
        if (!setFileAndLine){
          // Remove the file and line number if not required
          ho.remFile();
          ho.remLineNumber();
        }
      } catch (DmcValueExceptionSet e) {
       
        if (errors == null)
          errors = new ResultException();
       
        errors.addError("Couldn't resolve references in object: " + " " + ho.getFQN());
        errors.setLocationInfo(ho.getFile(), ho.getLineNumber());
       
        for(DmcValueException dve : e.getExceptions()){
          errors.moreMessages(dve.getMessage());
        }
       
      }
    }
   
View Full Code Here

    try {
      currObj = (HierarchicObject) factory.createWrapper(uco);
     
      DebugInfo.debug("Loaded:\n\n" + currObj.toOIF(15));
    } catch (ClassNotFoundException e) {
      ResultException ex = new ResultException("Unknown object class: " + uco.classes.get(0));
      ex.result.lastResult().fileName(infile);
      ex.result.lastResult().lineNumber(lineNumber);
      throw(ex);
    }
    catch (ResultException ex){
      ex.setLocationInfo(infile, lineNumber);
      throw(ex);
    }
   
    // We always set the file and line info in case we need it for error reporting,
    // but we strip it out in resolveReferences() if it's not required
    currObj.setLineNumber(lineNumber);
    currObj.setFile(infile);

    if (currObj.getFQN() == null){
      ResultException ex = new ResultException();
      ex.addError("Missing FQN for object.");
      ex.setLocationInfo(currObj.getFile(), currObj.getLineNumber());
      throw(ex);
    }
   
    fqn = currObj.getFQN();
   
    if (currObj.getFQN().getParentName() != null)
      parentFqn = currObj.getFQN().getParentName();
   
    if (parentFqn == null){
      // We have a top level object
      currObj.setParentObject(null);
      cache.addObject(currObj);
    }
    else{
      if (cache.find(fqn) == null){
        parentEntry = cache.find(parentFqn);
     
        if (parentEntry == null){
          ResultException ex = new ResultException();
          ex.addError("Missing parent: " + parentFqn + " for object: " + fqn);
          ex.setLocationInfo(currObj.getFile(), currObj.getLineNumber());
          throw(ex);
        }
        else{
          newEntry = currObj;
          newEntry.setParentObject(parentEntry);
         
          cache.addObject(currObj);
        }
      }
      else{
        ResultException ex = new ResultException();
        ex.addError("Duplicate FQN: " + fqn);
        ex.setLocationInfo(currObj.getFile(), currObj.getLineNumber());
        throw(ex);
      }
   
      System.out.println("HierarchyParser read:\n" + newEntry.getFQN());
     
View Full Code Here

        SchemaDefinition    currSchema = null;
        String            currFile = null;
        SchemaDefinition    nativeSchema = null;
       
        if (config == null){
          ResultException ex = new ResultException();
          ex.addError("The specified schema couldn't be found: " + schemaName);
          throw(ex);
        }
       
        location = config.getLatestVersion();
       
View Full Code Here

        SchemaDefinition    newSchema           = null;
        String              currFile            = null;
        String         srcFile       = "";
        // Determine if we have a valid class
        if ((cd = allSchema.isClass((String)uco.classes.get(0))) == null){
          ResultException ex = new ResultException();

            ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(0));
            ex.result.lastResult().lineNumber(uco.lineNumber);
            ex.result.lastResult().fileName(infile);
            throw(ex);
        }
        else{
          try {
            if (uco.classes.get(0).equals(MetaSchema._SchemaDefinition.getName())){
              // Okay, a bit of cheating to handle schema extensions - since the
              // schema extensions are defined in schemas themselves, those schemas
              // have to be loaded before we attempt to resolve the schema extension
              // AUX class. So, we let the schema manager know that we're loading
              // a new schema with just the unchecked object.
              allSchema.schemaPreAdd(uco);
            }
           
            // If we're underneath a standard eclipse project, we ignore everything before
            // the /src folder name.
        int srcloc = infile.indexOf("/src");
        srcFile = "";
        if (srcloc != -1)
          srcFile = infile.substring(srcloc);
        else
          srcFile = infile;

        // More interesting hand waving to handle rule instances. For most of the
            // objects that are found in schema definitions everything can be handled
            // in the usual way i.e. for ClassDefinitions, AttributeDefinitions,
            // RuleDefinitions etc. all of those classes are defined as part of the
            // meta schema and we have loaded the MetaSchemaAG. This means that we
            // can use the dmwfactory to instantiate these objects. However, for
            // instances of RuleDefinition, we're dealing with objects that are read
            // from the schema definition files and not using the loaded schemas. In
            // that case, we don't have all the information required to instantiate
            // objects.
        //
        // Rule data objects are stored against the schema for processing once
        // all schemas have been read.
            ClassDefinition checkClass = allSchema.isClass(uco.classes.get(0));
            if (checkClass != null){
              if (checkClass.getRuleDefinition() != null){
                uco.addValue(MetaDMSAG.__lineNumber.name, lineNumber + "");
                uco.addValue(MetaDMSAG.__file.name, srcFile);
                uco.addValue(MetaDMSAG.__definedIn.name, schemaLoading.getName().getNameString());
               
                schemaLoading.addParsedRule(uco);
               
                return;
              }
            }
           
            DmwWrapper newObj = dmwfactory.createWrapper(uco);
            newDef     = null;

          newDef = (DmsDefinition) newObj;
          newDef.setFile(srcFile);
          newDef.setLineNumber(lineNumber);
       
//        DmvDMSAG.__dmvAllowedAttributes.execute(newDef.getDMO());
       
        // NOTE: We used to be able to resolve objects as we went, but, because
        // we now generate the TypeDefinitions for object references internally,
        // we run into issues with attributes (which are loaded first) referring
        // to classes that aren't yet defined. So, we have to do our object resolution
        // in a second pass.
       
        // TODO: Apply rules to the object
//          DebugInfo.debug("APPLYING RULES");
         
        ruleManager.executeAttributeValidation(newDef.getDmcObject());
        ruleManager.executeObjectValidation(newDef.getDmcObject());
       
      } catch (ResultException e) {
        e.result.lastResult().fileName(infile);
        e.result.lastResult().lineNumber(lineNumber);
        throw(e);
      } catch (DmcValueException e) {
        ResultException ex = new ResultException(e.getMessage());
        ex.result.lastResult().fileName(infile);
        ex.result.lastResult().lineNumber(lineNumber);
        throw(ex);
      } catch (ClassCastException e){
        ResultException ex = new ResultException();
        ex.addError("Invalid object in a schema definition: " + uco.classes.get(0));
        ex.result.lastResult().moreMessages(e.getMessage());
        ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
              ex.result.lastResult().lineNumber(uco.lineNumber);
              ex.result.lastResult().fileName(infile);
        throw(ex);
      } catch (ClassNotFoundException e) {
        ResultException ex = new ResultException();
        ex.addError(e.getMessage());
        ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
        throw(ex);
      } catch(DmcRuleExceptionSet e){
        e.source(new SourceInfo(srcFile, lineNumber + ""));
        throw(e);
      }
         
            if (cd.getObjectName().getNameString().compareTo("SchemaDefinition") == 0)
                isSchema = true;

            if (schemaLoading == null){
                // We're not loading a schema, so this had better be a new schema
                // object - if not, we complain and return false
                if (isSchema == true){
                    // This is a new schema, so indicate that we're loading one
                    schemaLoading = (SchemaDefinition)newDef;
                   
                    schemaStack.push(schemaLoading);
                   
                    if ((dependsOnSchemas = schemaLoading.getDependsOn()) != null){
                        // This schema depends on others, make a recursive call to load them

                        // Hold on to the current schema
                        currSchema = schemaLoading;

                        // Reset the global schema pointer for now
                        schemaLoading = null;

                        while(dependsOnSchemas.hasNext()){
                            depSchema = dependsOnSchemas.next();
//DebugInfo.debug("Reading dependsOn: " + depSchema);
//if (depSchema.equals("dmv"))
//  DebugInfo.debugWithTrace("Parsing DMV");

                          ConfigVersion  config    = finder.getConfig(depSchema);
                          ConfigLocation  location  = null;
                           
                            if (config == null){
                              ResultException ex = new ResultException();
                              ex.addError("Couldn't find schema: " + depSchema + " on which schema: " + currSchema.getObjectName() + " depends.");
                              throw(ex);
                            }

                            location = config.getLatestVersion();
                           
                            currFile = location.getFileName();
                           
                            if (loadedFiles.containsKey(currFile) == false){
                                // Only load the schema if we haven't already parsed it
                                if ( (newSchema = this.parseSchemaInternal(depSchema)) == null){
                                  ResultException ex = new ResultException();
                                  ex.result.addResult(Result.FATAL,"Failed to parse schema: " + depSchema);
                                    throw(ex);
                                }

                                currSchema.addDependsOnRef(newSchema);

                                // Now reset schemaLoading to be null once more to
                                // mask the schema that we just read
                                schemaLoading = null;
                            }
                            else{
                                // We've already loaded this file, but we still
                                // need to update the dependsOnRef
                              // System.out.println("Adding ref to previously parsed schema: " + ((SchemaDefinition)loadedFiles.get(currFile)).getName());
                                currSchema.addDependsOnRef(loadedFiles.get(currFile));
                            }
                        }

                        // Switch back to the schema at this level of parsing
                        schemaLoading = currSchema;
//DebugInfo.debug("Switching back to : " + schemaLoading.getName());

            allSchema.schemaBeingLoaded(schemaLoading);
                    }

//                    // We let the SchemaManager know that we're loading a new schema.
//                    // This gives it the opportunity to notify its schema extensions
//                    // that this is happening.
//                    allSchema.schemaBeingLoaded(schemaLoading);

                    if ((defFiles = schemaLoading.getDefFiles()) != null){
                      ConfigLocation location = finder.getConfig(schemaLoading.getName().getNameString()).getLatestVersion();
                     
                        // And now load the files associated with this schema
                        while(defFiles.hasNext()){
                          if (location.isFromJAR())
                            currFile = "/" + location.getDirectory() + "/" + defFiles.next();
                          else
                            currFile = location.getDirectory() + File.separator + defFiles.next();
//                            currFile = schemaDir + File.separator + defFiles.next();
//DebugInfo.debug("Reading def file: " + currFile);

                            if (!terseV){
                              if (location.isFromJAR())
                                System.out.println("      Reading " + currFile + " - from " + location.getJarFilename());
                              else
                                System.out.println("      Reading " + currFile);
                            }
                           
                            if (location.isFromJAR()){
                              defParser.parseFile(currFile,true);
                            }
                            else{
                              defParser.parseFile(currFile);
                            }
                        }
                    }
                }

            }
            else{
                // We're currently loading a schema, so if this object is another
                // schema, things are screwy. Complain and return false.
                if (isSchema == true){
                  ResultException ex = new ResultException();
                  ex.result.addResult(Result.FATAL,"Already loading schema: " + schemaLoading.getObjectName());
                  ex.result.lastResult().moreMessages("This may have occurred because you have two schema definitions in the same file.");
                  ex.result.lastResult().fileName(infile);
                  throw(ex);
                }
View Full Code Here

    AttributeDefinition  ad  = null;
    ClassDefinition    cd  = schema.cdef(uco.getConstructionClass());
    Class<?>      dmoClass;
   
    if (cd == null){
          ResultException ex = new ResultException();
            ex.result.addResult(Result.ERROR,"Unknown class: " + uco.getConstructionClass());
            ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
            throw(ex);
    }

        if (cd.getClassType() == ClassTypeEnum.ABSTRACT){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.ERROR,"Can't instantiate an ABSTRACT class: " + cd.getDmoImport());
            ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
            throw(ex);         
        }

        try{
          synchronized (this) {
              dmoClass = Class.forName(cd.getDmoImport());
      }
        }
        catch(Exception e){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.FATAL,"Couldn't load Java class: " + cd.getDmoImport());
            ex.result.lastResult().moreMessages(e.getMessage());
            ex.result.lastResult().moreMessages(DebugInfo.extractTheStack(e));
            throw(ex);
        }
       
        try{
          dmo = (DmcObject) dmoClass.newInstance();
        }
        catch(Exception e){
          ResultException ex = new ResultException();
          ex.result.addResult(Result.FATAL,"Couldn't instantiate Java class: " + cd.getDmoImport());
          ex.result.lastResult().moreMessages("This may be because the class doesn't have a constructor that takes no arguments.");
          ex.result.lastResult().moreMessages(DebugInfo.getCurrentStack());
          throw(ex);
        }
       
   
    // Add the object class
    DmcTypeClassDefinitionREFMV cref = new DmcTypeClassDefinitionREFMV();
    cref.add(cd.getObjectName());
   
    // And add any auxiliary classes if we have them
    for(int i=1; i<uco.classes.size(); i++){
      if ((cd = schema.isClass((String)uco.classes.get(i))) == null){
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(i));
              throw(ex);
      }
      cref.add(cd.getObjectName());
//      dmo.add("objectClass", cref);
    }
   
    dmo.add(DmcObject.__objectClass, cref);
   
    Iterator<String> names = uco.getAttributeNames();
    while(names.hasNext()){
      String n = names.next();
      ad = schema.adef(n);
     
      if (ad == null){
            ResultException ex = new ResultException();
              ex.result.addResult(Result.ERROR,"Unknown attribute: " + n);
              throw(ex);
      }
     
      DmcAttributeInfo ai = dmo.getAttributeInfo(n);
View Full Code Here

      while(rules.hasNext()){
        DmcUncheckedObject rule = rules.next();
        ClassDefinition ruleDataCD = sm.isClass(rule.getConstructionClass());
       
        if (ruleDataCD == null){
          ResultException ex = new ResultException();
          ex.addError("Unknown rule data class. For Rule instance: \n" + rule.toOIF());
          throw(ex);
        }
        manager.addImport(ruleDataCD.getDmoImport(), "To instantiate " + rule.getConstructionClass() + " rule data");
        manager.addImport(ruleDataCD.getRuleDefinition().getRuleDefinitionImport(), "To instantiate rules of this type");
       
View Full Code Here

      multiValued = false;
      isReference  = false;
      isEnumType  = false;
     
      if (attrDef == null){
        ResultException ex = new ResultException();
        ex.addError("Unknown attribute: " + attrName);
        ex.result.lastResult().fileName("metaSchema.dms");
        ex.result.lastResult().lineNumber(obj.lineNumber);
        throw(ex);
      }
     
View Full Code Here

TOP

Related Classes of org.dmd.util.exceptions.ResultException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.